# Pig

> A round-cheeked, toy-like low-poly pig with a big flat snout, floppy ears, stubby legs and a springy curly tail. Optional mud splotches for a muddier farm look. Head, legs and tail are pivoted groups ready for trotting and sniffing animations in farm sims and cozy games.

![Pig preview](https://codels.download/m/pig.png)

Multi-view sheet (3/4, front, side, top): https://codels.download/m/pig.sheet.png

## Facts

- Category: Characters › Animals
- Size (W × H × D): 0.50 × 0.87 × 1.07 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 532 · Meshes: 24 · Materials: 5
- License: CC0-1.0 (Codels built-in)
- Tags: livestock, pig, piglet, blocky, cartoon, low-poly, farm, grassland, village, farming-sim, party-game, animal, npc, game-ready, mobile-friendly, parametric, color-red, size-medium, poly-low
- Page: https://codels.download/models/pig

## Files

| Format | URL |
|---|---|
| three.js ES module (`createPig()`) | https://codels.download/m/pig.js |
| React Three Fiber component (`<Pig />`) | https://codels.download/m/pig.jsx |
| Instancing module (`createPigInstances(count, place)`, one draw call per material) | https://codels.download/m/pig.instanced.js |
| Standalone HTML demo | https://codels.download/m/pig.html |
| glTF binary | https://codels.download/m/pig.glb |
| glTF binary, Meshopt-compressed (2–3× smaller; GLTFLoader needs `setMeshoptDecoder(MeshoptDecoder)`) | https://codels.download/m/pig.glb?compress=meshopt |
| glTF JSON | https://codels.download/m/pig.gltf |
| OBJ (vertex colors) + MTL | https://codels.download/m/pig.obj · https://codels.download/m/pig.mtl |
| STL | https://codels.download/m/pig.stl |
| CodelSpec JSON | https://codels.download/m/pig.json |

## Parameters

Append them as query parameters to any URL above to get a customized variant (e.g. `?skin=...`).

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `skin` | color | #rrggbb | #f2919f | #f2919f |
| `mud` | boolean | true \| false | false | false |
| `size` | number | 0.6 – 1.4 | 1 | 1 |

## Parts

- pig (group)
  - legFL (group)
    - legFLUpper (box · skin)
    - legFLHoof (box · dark)
  - legFR (group)
    - legFRUpper (box · skin)
    - legFRHoof (box · dark)
  - legBL (group)
    - legBLUpper (box · skin)
    - legBLHoof (box · dark)
  - legBR (group)
    - legBRUpper (box · skin)
    - legBRHoof (box · dark)
  - body (group)
    - torso (box · skin)
  - tail (group)
    - tailCurl (tube · skin)
  - head (group)
    - skull (box · skin)
    - snout (box · snout)
    - nostrilL (box · dark)
    - nostrilR (box · dark)
    - eyeL (box · eye)
    - eyeShineL (box · shine)
    - eyeR (box · eye)
    - eyeShineR (box · shine)
    - cheekL (box · snout)
    - cheekR (box · snout)
    - earL (group)
      - earFlapL (extrude · skin)
      - earInL (extrude · snout)
    - earR (group)
      - earFlapR (extrude · skin)
      - earInR (extrude · snout)

## How to use

Save the code below as `pig.js`, then:

```js
import { createPig } from './pig.js';
const model = createPig();
scene.add(model);
```

## Code

```js
/**
 * Pig — Codels 3D model library (https://codels.download/models/pig)
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 532 · Size (W × H × D): 0.50 × 0.87 × 1.07 m
 *
 * Usage:
 *   import { createPig } from './pig.js';
 *   
 *   const model = createPig();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

// Extrude a 2D outline along Z (centered). bevel = [thickness, size, segments].
function extrude(outline, depth, holes = [], bevel = null) {
  const shape = new THREE.Shape(outline.map(([x, y]) => new THREE.Vector2(x, y)));
  for (const hole of holes) shape.holes.push(new THREE.Path(hole.map(([x, y]) => new THREE.Vector2(x, y))));
  const options = bevel
    ? { depth, bevelEnabled: true, bevelThickness: bevel[0], bevelSize: bevel[1], bevelSegments: bevel[2] }
    : { depth, bevelEnabled: false };
  return new THREE.ExtrudeGeometry(shape, options).translate(0, 0, -depth / 2);
}

// Tube along a smooth curve through the given points.
function tube(path, radius, tubularSegments, radialSegments, closed = false) {
  const curve = new THREE.CatmullRomCurve3(path.map(([x, y, z]) => new THREE.Vector3(x, y, z)), closed);
  return new THREE.TubeGeometry(curve, tubularSegments, radius, radialSegments, closed);
}

export function createPig() {
  const root = new THREE.Group();
  root.name = 'Pig';

  // Materials
  const skinMat = new THREE.MeshStandardMaterial({ name: 'skin', color: 0xf2919f, roughness: 0.8, flatShading: true });
  const snoutMat = new THREE.MeshStandardMaterial({ name: 'snout', color: 0xd07d89, roughness: 0.7, flatShading: true });
  const darkMat = new THREE.MeshStandardMaterial({ name: 'dark', color: 0x5a3438, roughness: 0.6, flatShading: true });
  const eyeMat = new THREE.MeshStandardMaterial({ name: 'eye', color: 0x1f1a1b, roughness: 0.4, flatShading: true });
  const shineMat = new THREE.MeshStandardMaterial({ name: 'shine', color: 0xffffff, roughness: 0.4, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.12, 0.16, 0.12);
  const boxGeo2 = new THREE.BoxGeometry(0.125, 0.04, 0.125);
  const boxGeo3 = new THREE.BoxGeometry(0.045, 0.07, 0.02);
  const boxGeo4 = new THREE.BoxGeometry(0.06, 0.07, 0.06);
  const boxGeo5 = new THREE.BoxGeometry(0.022, 0.022, 0.01);
  const boxGeo6 = new THREE.BoxGeometry(0.07, 0.035, 0.01);
  const extrudeGeo = extrude([[-0.085, 0], [0.085, 0], [0.055, 0.1], [0, 0.17], [-0.055, 0.1]], 0.035);
  const extrudeGeo2 = extrude([[-0.05, 0.02], [0.05, 0.02], [0.03, 0.08], [0, 0.125], [-0.03, 0.08]], 0.01);

  // Parts
  const pig = new THREE.Group();
  pig.name = 'pig';
  root.add(pig);
  const legFL = new THREE.Group();
  legFL.name = 'legFL';
  legFL.position.set(0.15, 0.2, 0.17);
  pig.add(legFL);
  const legFLUpper = new THREE.Mesh(boxGeo, skinMat);
  legFLUpper.name = 'legFLUpper';
  legFLUpper.position.set(0, -0.08, 0);
  legFL.add(legFLUpper);
  const legFLHoof = new THREE.Mesh(boxGeo2, darkMat);
  legFLHoof.name = 'legFLHoof';
  legFLHoof.position.set(0, -0.18, 0);
  legFL.add(legFLHoof);
  const legFR = new THREE.Group();
  legFR.name = 'legFR';
  legFR.position.set(-0.15, 0.2, 0.17);
  pig.add(legFR);
  const legFRUpper = new THREE.Mesh(boxGeo, skinMat);
  legFRUpper.name = 'legFRUpper';
  legFRUpper.position.set(0, -0.08, 0);
  legFR.add(legFRUpper);
  const legFRHoof = new THREE.Mesh(boxGeo2, darkMat);
  legFRHoof.name = 'legFRHoof';
  legFRHoof.position.set(0, -0.18, 0);
  legFR.add(legFRHoof);
  const legBL = new THREE.Group();
  legBL.name = 'legBL';
  legBL.position.set(0.15, 0.2, -0.18);
  pig.add(legBL);
  const legBLUpper = new THREE.Mesh(boxGeo, skinMat);
  legBLUpper.name = 'legBLUpper';
  legBLUpper.position.set(0, -0.08, 0);
  legBL.add(legBLUpper);
  const legBLHoof = new THREE.Mesh(boxGeo2, darkMat);
  legBLHoof.name = 'legBLHoof';
  legBLHoof.position.set(0, -0.18, 0);
  legBL.add(legBLHoof);
  const legBR = new THREE.Group();
  legBR.name = 'legBR';
  legBR.position.set(-0.15, 0.2, -0.18);
  pig.add(legBR);
  const legBRUpper = new THREE.Mesh(boxGeo, skinMat);
  legBRUpper.name = 'legBRUpper';
  legBRUpper.position.set(0, -0.08, 0);
  legBR.add(legBRUpper);
  const legBRHoof = new THREE.Mesh(boxGeo2, darkMat);
  legBRHoof.name = 'legBRHoof';
  legBRHoof.position.set(0, -0.18, 0);
  legBR.add(legBRHoof);
  const body = new THREE.Group();
  body.name = 'body';
  pig.add(body);
  const torso = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.4, 0.6), skinMat);
  torso.name = 'torso';
  torso.position.set(0, 0.36, 0);
  body.add(torso);
  const tail = new THREE.Group();
  tail.name = 'tail';
  tail.position.set(0, 0.46, -0.3);
  pig.add(tail);
  const tailCurl = new THREE.Mesh(tube([[0, 0, -0.015], [0.0448, 0.0246, -0.022], [0.0463, 0.0729, -0.029], [0.0062, 0.0981, -0.036], [-0.0364, 0.0775, -0.043], [-0.0432, 0.0314, -0.05], [-0.0108, 0.0014, -0.057], [0.0284, 0.0113, -0.064], [0.0389, 0.047, -0.071], [0.0139, 0.0727, -0.078], [-0.021, 0.0647, -0.085]], 0.018, 24, 5), skinMat);
  tailCurl.name = 'tailCurl';
  tail.add(tailCurl);
  const head = new THREE.Group();
  head.name = 'head';
  head.position.set(0, 0.44, 0.24);
  pig.add(head);
  const skull = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.44, 0.38), skinMat);
  skull.name = 'skull';
  skull.position.set(0, 0.08, 0.14);
  head.add(skull);
  const snout = new THREE.Mesh(new THREE.BoxGeometry(0.24, 0.16, 0.09), snoutMat);
  snout.name = 'snout';
  snout.position.set(0, 0.01, 0.37);
  head.add(snout);
  const nostrilL = new THREE.Mesh(boxGeo3, darkMat);
  nostrilL.name = 'nostrilL';
  nostrilL.position.set(0.05, 0.01, 0.42);
  head.add(nostrilL);
  const nostrilR = new THREE.Mesh(boxGeo3, darkMat);
  nostrilR.name = 'nostrilR';
  nostrilR.position.set(-0.05, 0.01, 0.42);
  head.add(nostrilR);
  const eyeL = new THREE.Mesh(boxGeo4, eyeMat);
  eyeL.name = 'eyeL';
  eyeL.position.set(0.2, 0.15, 0.305);
  head.add(eyeL);
  const eyeShineL = new THREE.Mesh(boxGeo5, shineMat);
  eyeShineL.name = 'eyeShineL';
  eyeShineL.position.set(0.21, 0.165, 0.34);
  head.add(eyeShineL);
  const eyeR = new THREE.Mesh(boxGeo4, eyeMat);
  eyeR.name = 'eyeR';
  eyeR.position.set(-0.2, 0.15, 0.305);
  head.add(eyeR);
  const eyeShineR = new THREE.Mesh(boxGeo5, shineMat);
  eyeShineR.name = 'eyeShineR';
  eyeShineR.position.set(-0.21, 0.165, 0.34);
  head.add(eyeShineR);
  const cheekL = new THREE.Mesh(boxGeo6, snoutMat);
  cheekL.name = 'cheekL';
  cheekL.position.set(0.2, 0.06, 0.3355);
  head.add(cheekL);
  const cheekR = new THREE.Mesh(boxGeo6, snoutMat);
  cheekR.name = 'cheekR';
  cheekR.position.set(-0.2, 0.06, 0.3355);
  head.add(cheekR);
  const earL = new THREE.Group();
  earL.name = 'earL';
  earL.position.set(0.16, 0.28, 0.09);
  earL.rotation.set(deg(28), 0, deg(-18));
  head.add(earL);
  const earFlapL = new THREE.Mesh(extrudeGeo, skinMat);
  earFlapL.name = 'earFlapL';
  earL.add(earFlapL);
  const earInL = new THREE.Mesh(extrudeGeo2, snoutMat);
  earInL.name = 'earInL';
  earInL.position.set(0, 0, 0.02);
  earL.add(earInL);
  const earR = new THREE.Group();
  earR.name = 'earR';
  earR.position.set(-0.16, 0.28, 0.09);
  earR.rotation.set(deg(28), 0, deg(18));
  head.add(earR);
  const earFlapR = new THREE.Mesh(extrudeGeo, skinMat);
  earFlapR.name = 'earFlapR';
  earR.add(earFlapR);
  const earInR = new THREE.Mesh(extrudeGeo2, snoutMat);
  earInR.name = 'earInR';
  earInR.position.set(0, 0, 0.02);
  earR.add(earInR);

  root.traverse((o) => {
    if (o.isMesh) {
      o.castShadow = true;
      o.receiveShadow = true;
    }
  });
  return root;
}

export default createPig;
```

---
Codels — 3D models as code for three.js. Search more: https://codels.download/api/v1/models?q=<query> · Guide: https://codels.download/llms.txt
