# Barrel

> A classic bulging wooden barrel turned from a lathe profile, with faceted staves, four iron hoops and a recessed lid with a bung. Change the height for anything from a squat keg to a tall cask, or remove the lid to show the open interior. Great for taverns, docks, cellars and pirate ships.

![Barrel preview](https://codels.download/m/barrel.png)

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

## Facts

- Category: Props › Containers
- Size (W × H × D): 0.62 × 0.90 × 0.63 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 784 · Meshes: 8 · Materials: 3
- License: CC0-1.0 (Codels built-in)
- Tags: barrel, low-poly, stylized, medieval, nautical, pirate, western, village, rpg, survival, container, prop, metal, wood, round, game-ready, instancing-friendly, mobile-friendly, parametric, color-brown, color-gray, size-small, poly-low
- Page: https://codels.download/models/barrel

## Files

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

## Parameters

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

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `height` | number | 0.6 – 1.3 | 0.9 | 0.9 |
| `wood` | color | #rrggbb | #a8703c | #a8703c |
| `hoops` | color | #rrggbb | #55585e | #55585e |
| `lid` | boolean | true \| false | true | true |

## Parts

- body (lathe · wood)
- seam (box · dark)
- seam (box · dark)
- bung (cylinder · dark)
- hoopBottom (lathe · hoop)
- hoopLow (lathe · hoop)
- hoopHigh (lathe · hoop)
- hoopTop (lathe · hoop)

## How to use

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

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

## Code

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

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

export function createBarrel() {
  const root = new THREE.Group();
  root.name = 'Barrel';

  // Materials
  const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0xa8703c, roughness: 0.88, flatShading: true });
  const darkMat = new THREE.MeshStandardMaterial({ name: 'dark', color: 0x54381e, roughness: 0.95, flatShading: true });
  const hoopMat = new THREE.MeshStandardMaterial({ name: 'hoop', color: 0x55585e, roughness: 0.45, metalness: 0.55, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.4105, 0.004, 0.008);

  // Parts
  const body = new THREE.Mesh(lathe([[0, 0.03], [0.223, 0.03], [0.223, 0], [0.245, 0], [0.2734, 0.1125], [0.2938, 0.225], [0.3059, 0.3375], [0.31, 0.45], [0.3059, 0.5625], [0.2938, 0.675], [0.2734, 0.7875], [0.245, 0.9], [0.223, 0.9], [0.223, 0.87], [0, 0.87]], 14), woodMat);
  body.name = 'body';
  root.add(body);
  const seam = new THREE.Mesh(boxGeo, darkMat);
  seam.name = 'seam';
  seam.position.set(0, 0.872, -0.0743);
  root.add(seam);
  const seam2 = new THREE.Mesh(boxGeo, darkMat);
  seam2.name = 'seam';
  seam2.position.set(0, 0.872, 0.0743);
  root.add(seam2);
  const bung = new THREE.Mesh(new THREE.CylinderGeometry(0.028, 0.03, 0.016, 8), darkMat);
  bung.name = 'bung';
  bung.position.set(0.11, 0.878, 0.06);
  root.add(bung);
  const hoopBottom = new THREE.Mesh(lathe([[0.2545, 0.0495], [0.2705, 0.0495], [0.2825, 0.099], [0.2665, 0.099]], 14), hoopMat);
  hoopBottom.name = 'hoopBottom';
  root.add(hoopBottom);
  const hoopLow = new THREE.Mesh(lathe([[0.2972, 0.284], [0.3132, 0.284], [0.3172, 0.328], [0.3012, 0.328]], 14), hoopMat);
  hoopLow.name = 'hoopLow';
  root.add(hoopLow);
  const hoopHigh = new THREE.Mesh(lathe([[0.3012, 0.572], [0.3172, 0.572], [0.3132, 0.616], [0.2972, 0.616]], 14), hoopMat);
  hoopHigh.name = 'hoopHigh';
  root.add(hoopHigh);
  const hoopTop = new THREE.Mesh(lathe([[0.2665, 0.801], [0.2825, 0.801], [0.2705, 0.8505], [0.2545, 0.8505]], 14), hoopMat);
  hoopTop.name = 'hoopTop';
  root.add(hoopTop);

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

export default createBarrel;
```

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