# Anvil

> A classic low-poly blacksmith anvil with a flared base, pinched waist, polished face, step and conical horn, mounted on a sturdy tree-stump block. Optionally drop the stump or the forging hammer resting beside it. A must-have for forges, smithies and crafting stations in RPG and survival games.

![Anvil preview](https://codels.download/m/anvil.png)

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

## Facts

- Category: Props › Tools
- Size (W × H × D): 0.65 × 0.72 × 0.63 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 364 · Meshes: 18 · Materials: 7
- License: CC0-1.0 (Codels built-in)
- Tags: anvil, blacksmith, hammer, stump, low-poly, stylized, fantasy, medieval, viking, village, rpg, survival, interactable, prop, tool, metal, wood, game-ready, mobile-friendly, parametric, color-brown, color-gray, size-small, poly-low
- Page: https://codels.download/models/anvil

## Files

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

## Parameters

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

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `metal` | color | #rrggbb | #69707b | #69707b |
| `stump` | boolean | true \| false | true | true |
| `hammer` | boolean | true \| false | true | true |

## Parts

- stump (cylinder · bark)
- stumpTop (cylinder · wood)
- treeRing (cylinder · ring)
- root1 (group)
  - root (cylinder · bark)
- root2 (group)
  - root (cylinder · bark)
- root3 (group)
  - root (cylinder · bark)
- root4 (group)
  - root (cylinder · bark)
- base (extrude · iron)
- waist (extrude · iron)
- body (box · iron)
- face (box · face)
- hardyHole (box · dark)
- pritchelHole (cylinder · dark)
- step (box · iron)
- horn (cone · iron)
- hammer (group)
  - hammerParts (group)
    - handle (cylinder · handle)
    - head (box · iron)
    - striker (box · face)

## How to use

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

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

## Code

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

const deg = THREE.MathUtils.degToRad;

// Deterministic vertex displacement (organic low-poly look).
function jitter(geometry, amount, seed) {
  const pos = geometry.attributes.position;
  const h = (a, b, c, s) => {
    let x = Math.imul(a, 73856093) ^ Math.imul(b, 19349663) ^ Math.imul(c, 83492791) ^ Math.imul(s, 2654435761);
    x = Math.imul(x ^ (x >>> 16), 2246822507);
    x = Math.imul(x ^ (x >>> 13), 3266489909);
    return ((x ^ (x >>> 16)) >>> 0) / 4294967295 - 0.5;
  };
  for (let i = 0; i < pos.count; i++) {
    const x = pos.getX(i), y = pos.getY(i), z = pos.getZ(i);
    const qx = Math.round(x * 1000), qy = Math.round(y * 1000), qz = Math.round(z * 1000);
    pos.setXYZ(i, x + h(qx, qy, qz, seed) * 2 * amount, y + h(qx, qy, qz, seed + 1) * 2 * amount, z + h(qx, qy, qz, seed + 2) * 2 * amount);
  }
  pos.needsUpdate = true;
  geometry.computeVertexNormals();
  return geometry;
}

// 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);
}

export function createAnvil() {
  const root = new THREE.Group();
  root.name = 'Anvil';

  // Materials
  const ironMat = new THREE.MeshStandardMaterial({ name: 'iron', color: 0x69707b, roughness: 0.5, metalness: 0.35, flatShading: true });
  const faceMat = new THREE.MeshStandardMaterial({ name: 'face', color: 0x9ea8b9, roughness: 0.3, metalness: 0.45, flatShading: true });
  const darkMat = new THREE.MeshStandardMaterial({ name: 'dark', color: 0x1e1e22, roughness: 0.8, flatShading: true });
  const barkMat = new THREE.MeshStandardMaterial({ name: 'bark', color: 0x5a3d26, roughness: 1, flatShading: true });
  const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0xc79a62, roughness: 0.9, flatShading: true });
  const ringMat = new THREE.MeshStandardMaterial({ name: 'ring', color: 0xa77b48, roughness: 0.9, flatShading: true });
  const handleMat = new THREE.MeshStandardMaterial({ name: 'handle', color: 0x8b5a2b, roughness: 0.85, flatShading: true });

  // Shared geometries
  const cylinderGeo = new THREE.CylinderGeometry(0.022, 0.065, 0.17, 5);

  // Parts
  const stump = new THREE.Mesh(jitter(new THREE.CylinderGeometry(0.215, 0.24, 0.44, 9), 0.008, 4), barkMat);
  stump.name = 'stump';
  stump.position.set(0, 0.22, 0);
  root.add(stump);
  const stumpTop = new THREE.Mesh(new THREE.CylinderGeometry(0.205, 0.205, 0.016, 9), woodMat);
  stumpTop.name = 'stumpTop';
  stumpTop.position.set(0, 0.442, 0);
  stumpTop.rotation.set(0, deg(20), 0);
  root.add(stumpTop);
  const treeRing = new THREE.Mesh(new THREE.CylinderGeometry(0.13, 0.13, 0.004, 9), ringMat);
  treeRing.name = 'treeRing';
  treeRing.position.set(0, 0.452, 0);
  treeRing.rotation.set(0, deg(20), 0);
  root.add(treeRing);
  const root1 = new THREE.Group();
  root1.name = 'root1';
  root1.rotation.set(0, deg(25), 0);
  root.add(root1);
  const root2 = new THREE.Mesh(cylinderGeo, barkMat);
  root2.name = 'root';
  root2.position.set(0, 0.062, 0.2);
  root2.rotation.set(deg(116), 0, 0);
  root1.add(root2);
  const root22 = new THREE.Group();
  root22.name = 'root2';
  root22.rotation.set(0, deg(133), 0);
  root.add(root22);
  const root3 = new THREE.Mesh(cylinderGeo, barkMat);
  root3.name = 'root';
  root3.position.set(0, 0.062, 0.2);
  root3.rotation.set(deg(116), 0, 0);
  root22.add(root3);
  const root32 = new THREE.Group();
  root32.name = 'root3';
  root32.rotation.set(0, deg(205), 0);
  root.add(root32);
  const root4 = new THREE.Mesh(cylinderGeo, barkMat);
  root4.name = 'root';
  root4.position.set(0, 0.062, 0.2);
  root4.rotation.set(deg(116), 0, 0);
  root32.add(root4);
  const root42 = new THREE.Group();
  root42.name = 'root4';
  root42.rotation.set(0, deg(313), 0);
  root.add(root42);
  const root5 = new THREE.Mesh(cylinderGeo, barkMat);
  root5.name = 'root';
  root5.position.set(0, 0.062, 0.2);
  root5.rotation.set(deg(116), 0, 0);
  root42.add(root5);
  const base = new THREE.Mesh(extrude([[-0.21, 0], [0.19, 0], [0.19, 0.022], [0.13, 0.06], [-0.15, 0.06], [-0.21, 0.022]], 0.21), ironMat);
  base.name = 'base';
  base.position.set(0, 0.454, 0);
  root.add(base);
  const waist = new THREE.Mesh(extrude([[-0.14, 0], [0.12, 0], [0.08, 0.06], [0.1, 0.12], [-0.13, 0.12], [-0.1, 0.06]], 0.12), ironMat);
  waist.name = 'waist';
  waist.position.set(0, 0.512, 0);
  root.add(waist);
  const body = new THREE.Mesh(new THREE.BoxGeometry(0.37, 0.085, 0.145), ironMat);
  body.name = 'body';
  body.position.set(-0.035, 0.6665, 0);
  root.add(body);
  const face = new THREE.Mesh(new THREE.BoxGeometry(0.35, 0.006, 0.13), faceMat);
  face.name = 'face';
  face.position.set(-0.035, 0.71, 0);
  root.add(face);
  const hardyHole = new THREE.Mesh(new THREE.BoxGeometry(0.022, 0.003, 0.022), darkMat);
  hardyHole.name = 'hardyHole';
  hardyHole.position.set(-0.17, 0.7135, 0.02);
  root.add(hardyHole);
  const pritchelHole = new THREE.Mesh(new THREE.CylinderGeometry(0.009, 0.009, 0.003, 6), darkMat);
  pritchelHole.name = 'pritchelHole';
  pritchelHole.position.set(-0.13, 0.7135, 0.03);
  root.add(pritchelHole);
  const step = new THREE.Mesh(new THREE.BoxGeometry(0.07, 0.065, 0.12), ironMat);
  step.name = 'step';
  step.position.set(0.185, 0.6645, 0);
  root.add(step);
  const horn = new THREE.Mesh(new THREE.ConeGeometry(0.046, 0.2, 8), ironMat);
  horn.name = 'horn';
  horn.position.set(0.318, 0.666, 0);
  horn.rotation.set(0, 0, deg(-90));
  horn.scale.set(1, 0.85, 1);
  root.add(horn);
  const hammer = new THREE.Group();
  hammer.name = 'hammer';
  hammer.position.set(-0.13, 0.025, 0.35);
  hammer.rotation.set(0, deg(98), 0);
  root.add(hammer);
  const hammerParts = new THREE.Group();
  hammerParts.name = 'hammerParts';
  hammerParts.rotation.set(deg(90), deg(90), 0);
  hammer.add(hammerParts);
  const handle = new THREE.Mesh(new THREE.CylinderGeometry(0.014, 0.016, 0.36, 6), handleMat);
  handle.name = 'handle';
  handle.position.set(0, 0.18, 0);
  hammerParts.add(handle);
  const head = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.05, 0.13), ironMat);
  head.name = 'head';
  head.position.set(0, 0.37, 0.01);
  hammerParts.add(head);
  const striker = new THREE.Mesh(new THREE.BoxGeometry(0.056, 0.056, 0.012), faceMat);
  striker.name = 'striker';
  striker.position.set(0, 0.37, 0.081);
  hammerParts.add(striker);

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

export default createAnvil;
```

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