# Hammer

> A low-poly hammer in two variants: a carpenter’s claw hammer with a polished round face, curved split claw and shaped wooden handle, or a heavy sledgehammer with an octagonal steel head and a wrapped long handle. Stand it upright on its head or lay it flat. Great for workshops, construction sites, smithies and crafting UIs.

![Hammer preview](https://codels.download/m/hammer.png)

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

## Facts

- Category: Props › Tools
- Size (W × H × D): 0.17 × 0.34 × 0.11 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 342 · Meshes: 8 · Materials: 3
- License: CC0-1.0 (Codels built-in)
- Tags: carpentry, claw-hammer, hammer, sledgehammer, workshop, low-poly, stylized, construction, industrial, medieval, village, rpg, survival, equipment, interactable, prop, tool, metal, wood, game-ready, mobile-friendly, parametric, color-gray, color-orange, size-small, poly-low
- Page: https://codels.download/models/hammer

## Files

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

## Parameters

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

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `type` | select | claw \| sledge | claw | claw |
| `pose` | select | upright \| flat | upright | upright |
| `metal` | color | #rrggbb | #7b828c | #7b828c |
| `handle` | color | #rrggbb | #b47a43 | #b47a43 |

## Parts

- hammer (group)
  - tool (group)
    - handle (lathe · wood)
    - eye (box · steel)
    - wedge (box · wood)
    - neck (cylinder · steel)
    - face (cylinder · polished)
    - clawRoot (extrude · steel)
    - clawProng (extrude · steel)
    - clawProng (extrude · steel)

## How to use

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

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

## Code

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

const deg = THREE.MathUtils.degToRad;

// Revolve a 2D profile [[radius, y], ...] around the Y axis.
function lathe(points, segments, phiStart = 0, phiLength = Math.PI * 2) {
  return new THREE.LatheGeometry(points.map(([x, y]) => new THREE.Vector2(x, y)), segments, phiStart, phiLength);
}

// 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 createHammer() {
  const root = new THREE.Group();
  root.name = 'Hammer';

  // Materials
  const steelMat = new THREE.MeshStandardMaterial({ name: 'steel', color: 0x7b828c, roughness: 0.42, metalness: 0.45, flatShading: true });
  const polishedMat = new THREE.MeshStandardMaterial({ name: 'polished', color: 0xa9aeb4, roughness: 0.25, metalness: 0.55, flatShading: true });
  const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0xb47a43, roughness: 0.75, flatShading: true });

  // Shared geometries
  const extrudeGeo = extrude([[-0.0446, 0.2955], [-0.0541, 0.2932], [-0.0635, 0.2898], [-0.0726, 0.2855], [-0.0813, 0.2801], [-0.0895, 0.2737], [-0.0971, 0.2664], [-0.1017, 0.2697], [-0.0959, 0.2793], [-0.089, 0.2884], [-0.0811, 0.2968], [-0.0722, 0.3045], [-0.0625, 0.3112], [-0.052, 0.317]], 0.009);

  // Parts
  const hammer = new THREE.Group();
  hammer.name = 'hammer';
  hammer.position.set(0, 0.002, 0);
  hammer.rotation.set(0, deg(30), 0);
  root.add(hammer);
  const tool = new THREE.Group();
  tool.name = 'tool';
  tool.position.set(0, 0.33, 0);
  tool.rotation.set(deg(180), 0, 0);
  hammer.add(tool);
  const handle = new THREE.Mesh(lathe([[0, -0.004], [0.015, -0.004], [0.018, 0.01], [0.018, 0.06], [0.015, 0.15], [0.0115, 0.25], [0.0125, 0.3], [0, 0.302]], 7), woodMat);
  handle.name = 'handle';
  handle.scale.set(1, 1, 0.72);
  tool.add(handle);
  const eye = new THREE.Mesh(new THREE.BoxGeometry(0.034, 0.048, 0.027), steelMat);
  eye.name = 'eye';
  eye.position.set(0, 0.304, 0);
  tool.add(eye);
  const wedge = new THREE.Mesh(new THREE.BoxGeometry(0.03, 0.006, 0.012), woodMat);
  wedge.name = 'wedge';
  wedge.position.set(0, 0.329, 0);
  tool.add(wedge);
  const neck = new THREE.Mesh(new THREE.CylinderGeometry(0.0135, 0.0115, 0.046, 8), steelMat);
  neck.name = 'neck';
  neck.position.set(0.039, 0.304, 0);
  neck.rotation.set(0, 0, deg(-90));
  tool.add(neck);
  const face = new THREE.Mesh(new THREE.CylinderGeometry(0.0145, 0.0165, 0.018, 8), polishedMat);
  face.name = 'face';
  face.position.set(0.07, 0.304, 0);
  face.rotation.set(0, 0, deg(-90));
  tool.add(face);
  const clawRoot = new THREE.Mesh(extrude([[-0.014, 0.296], [-0.0204, 0.2968], [-0.0269, 0.2971], [-0.0335, 0.2969], [-0.0401, 0.2962], [-0.0468, 0.2951], [-0.0534, 0.2934], [-0.0617, 0.3117], [-0.0545, 0.3158], [-0.0469, 0.3193], [-0.039, 0.3223], [-0.0309, 0.3248], [-0.0225, 0.3267], [-0.014, 0.328]], 0.024), steelMat);
  clawRoot.name = 'clawRoot';
  tool.add(clawRoot);
  const clawProng = new THREE.Mesh(extrudeGeo, steelMat);
  clawProng.name = 'clawProng';
  clawProng.position.set(0, 0, -0.0068);
  tool.add(clawProng);
  const clawProng2 = new THREE.Mesh(extrudeGeo, steelMat);
  clawProng2.name = 'clawProng';
  clawProng2.position.set(0, 0, 0.0068);
  tool.add(clawProng2);

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

export default createHammer;
```

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