# Carrot

> A crunchy low-poly carrot lying on its side: a faceted, slightly ridged orange root that tapers to a point, topped with a bunch of bright green leafy stalks. Real-world length by default (about 18 cm) and scalable for farm games, kitchens and cartoon pickups.

![Carrot preview](https://codels.download/m/carrot.png)

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

## Facts

- Category: Food & Drink › Fruits & Vegetables
- Size (W × H × D): 0.27 × 0.12 × 0.04 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 304 · Meshes: 7 · Materials: 4
- License: CC0-1.0 (Codels built-in)
- Tags: carrot, vegetable, cartoon, low-poly, stylized, farm, kitchen, garden, farming-sim, survival, collectible, food, pickup, prop, organic, game-ready, instancing-friendly, mobile-friendly, parametric, color-green, color-orange, size-tiny, poly-low
- Page: https://codels.download/models/carrot

## Files

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

## Parameters

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

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `length` | number | 0.1 – 0.6 | 0.18 | 0.18 |
| `color` | color | #rrggbb | #ee6c14 | #ee6c14 |
| `leaves` | boolean | true \| false | true | true |

## Parts

- carrot (group)
  - root (lathe · root)
  - crown (cylinder · crown)
  - leaf1 (cone · leafLight)
  - leaf2 (cone · leaf)
  - leaf3 (cone · leafLight)
  - leaf4 (cone · leaf)
  - leaf5 (cone · leafLight)

## How to use

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

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

## Code

```js
/**
 * Carrot — Codels 3D model library (https://codels.download/models/carrot)
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 304 · Size (W × H × D): 0.27 × 0.12 × 0.04 m
 *
 * Usage:
 *   import { createCarrot } from './carrot.js';
 *   
 *   const model = createCarrot();
 *   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);
}

export function createCarrot() {
  const root = new THREE.Group();
  root.name = 'Carrot';

  // Materials
  const rootMat = new THREE.MeshStandardMaterial({ name: 'root', color: 0xee6c14, roughness: 0.75, flatShading: true });
  const crownMat = new THREE.MeshStandardMaterial({ name: 'crown', color: 0x7a9a2c, roughness: 0.8, flatShading: true });
  const leafMat = new THREE.MeshStandardMaterial({ name: 'leaf', color: 0x3f9a2c, roughness: 0.75, flatShading: true });
  const leafLightMat = new THREE.MeshStandardMaterial({ name: 'leafLight', color: 0x62bf3f, roughness: 0.75, flatShading: true });

  // Parts
  const carrot = new THREE.Group();
  carrot.name = 'carrot';
  carrot.position.set(0.0893, 0, 0);
  carrot.rotation.set(0, 0, deg(-7.3524));
  carrot.scale.setScalar(0.18);
  root.add(carrot);
  const root2 = new THREE.Mesh(lathe([[0, 0], [0.02, 0.0775], [0.0342, 0.155], [0.0432, 0.2325], [0.0556, 0.31], [0.0618, 0.3875], [0.0739, 0.465], [0.0782, 0.5425], [0.0903, 0.62], [0.0932, 0.6975], [0.1056, 0.775], [0.1073, 0.8525], [0.12, 0.93], [0.11, 0.97], [0.06, 0.995], [0, 1]], 8), rootMat);
  root2.name = 'root';
  root2.rotation.set(0, 0, deg(90));
  carrot.add(root2);
  const crown = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.07, 0.05, 6), crownMat);
  crown.name = 'crown';
  crown.position.set(-1.01, 0, 0);
  crown.rotation.set(0, 0, deg(90));
  carrot.add(crown);
  const leaf1 = new THREE.Mesh(new THREE.ConeGeometry(0.085, 0.5, 4), leafLightMat);
  leaf1.name = 'leaf1';
  leaf1.position.set(-1.2512, 0.0842, 0.0443);
  leaf1.rotation.set(deg(27.7571), 0, deg(67.6427));
  leaf1.scale.set(1, 1, 0.35);
  carrot.add(leaf1);
  const leaf2 = new THREE.Mesh(new THREE.ConeGeometry(0.085, 0.56, 4), leafMat);
  leaf2.name = 'leaf2';
  leaf2.position.set(-1.2295, 0.1758, -0.0602);
  leaf2.rotation.set(deg(-18.894), 0, deg(48.4306));
  leaf2.scale.set(1, 1, 0.35);
  carrot.add(leaf2);
  const leaf3 = new THREE.Mesh(new THREE.ConeGeometry(0.085, 0.6, 4), leafLightMat);
  leaf3.name = 'leaf3';
  leaf3.position.set(-1.1785, 0.2536, 0.0239);
  leaf3.rotation.set(deg(5.389), 0, deg(31.8861));
  leaf3.scale.set(1, 1, 0.35);
  carrot.add(leaf3);
  const leaf4 = new THREE.Mesh(new THREE.ConeGeometry(0.085, 0.48, 4), leafMat);
  leaf4.name = 'leaf4';
  leaf4.position.set(-1.082, 0.2315, -0.012);
  leaf4.rotation.set(deg(-2.9632), 0, deg(14.9808));
  leaf4.scale.set(1, 1, 0.35);
  carrot.add(leaf4);
  const leaf5 = new THREE.Mesh(new THREE.ConeGeometry(0.085, 0.62, 4), leafLightMat);
  leaf5.name = 'leaf5';
  leaf5.position.set(-1.2884, 0.155, 0.0062);
  leaf5.rotation.set(deg(2.2906), 0, deg(59.9802));
  leaf5.scale.set(1, 1, 0.35);
  carrot.add(leaf5);

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

export default createCarrot;
```

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