# Sword

> A stylized low-poly sword standing upright (blade up, pommel resting on the ground, about 1 m long). Switch between a knightly arming sword, a broad sword with a fuller and wheel pommel, or a curved katana; tweak blade length and metal colors. Great as a hero weapon, loot drop or wall decoration in fantasy RPGs.

![Sword preview](https://codels.download/m/sword.png)

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

## Facts

- Category: Items & Weapons › Weapons
- Size (W × H × D): 0.29 × 1.03 × 0.06 m — units are meters, +Y up, front faces +Z
- Origin: center of the base (y = 0)
- Triangles: 468 · Meshes: 14 · Materials: 4
- License: CC0-1.0 (Codels built-in)
- Tags: katana, knight, sword, low-poly, stylized, fantasy, japanese, medieval, adventure, roguelike, rpg, collectible, hero-asset, weapon, metal, game-ready, mobile-friendly, parametric, color-blue, color-brown, color-orange, size-medium, poly-low
- Page: https://codels.download/models/sword

## Files

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

## Parameters

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

| Param | Type | Range / options | Default | Current |
|---|---|---|---|---|
| `style` | select | knight \| broad \| katana | knight | knight |
| `bladeLength` | number | 0.45 – 1.1 | 0.75 | 0.75 |
| `blade` | color | #rrggbb | #d9e1ea | #d9e1ea |
| `hilt` | color | #rrggbb | #d0a24a | #d0a24a |

## Parts

- pommel (sphere · hilt)
- pommelNeck (cylinder · hilt)
- grip (cylinder · grip)
- wrap1 (cylinder · wrap)
- wrap2 (cylinder · wrap)
- wrap3 (cylinder · wrap)
- wrap4 (cylinder · wrap)
- wrap5 (cylinder · wrap)
- wrap6 (cylinder · wrap)
- guard (box · hilt)
- guardEndR (sphere · hilt)
- guardEndL (sphere · hilt)
- guardCenter (box · hilt)
- blade (extrude · blade)

## How to use

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

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

## Code

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

export function createSword() {
  const root = new THREE.Group();
  root.name = 'Sword';

  // Materials
  const bladeMat = new THREE.MeshStandardMaterial({ name: 'blade', color: 0xd9e1ea, roughness: 0.3, metalness: 0.7, flatShading: true });
  const hiltMat = new THREE.MeshStandardMaterial({ name: 'hilt', color: 0xd0a24a, roughness: 0.35, metalness: 0.75, flatShading: true });
  const gripMat = new THREE.MeshStandardMaterial({ name: 'grip', color: 0x6b4226, roughness: 0.85, flatShading: true });
  const wrapMat = new THREE.MeshStandardMaterial({ name: 'wrap', color: 0x3f2516, roughness: 0.9, flatShading: true });

  // Shared geometries
  const cylinderGeo = new THREE.CylinderGeometry(0.0205, 0.0205, 0.01, 8);
  const sphereGeo = new THREE.SphereGeometry(0.02, 6, 4);

  // Parts
  const pommel = new THREE.Mesh(new THREE.SphereGeometry(0.038, 8, 6), hiltMat);
  pommel.name = 'pommel';
  pommel.position.set(0, 0.035, 0);
  pommel.scale.set(1, 0.92, 0.78);
  root.add(pommel);
  const pommelNeck = new THREE.Mesh(new THREE.CylinderGeometry(0.016, 0.022, 0.02, 8), hiltMat);
  pommelNeck.name = 'pommelNeck';
  pommelNeck.position.set(0, 0.072, 0);
  root.add(pommelNeck);
  const grip = new THREE.Mesh(new THREE.CylinderGeometry(0.0185, 0.0175, 0.16, 8), gripMat);
  grip.name = 'grip';
  grip.position.set(0, 0.158, 0);
  root.add(grip);
  const wrap1 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap1.name = 'wrap1';
  wrap1.position.set(0, 0.0913, 0);
  wrap1.rotation.set(0, 0, deg(16));
  root.add(wrap1);
  const wrap2 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap2.name = 'wrap2';
  wrap2.position.set(0, 0.118, 0);
  wrap2.rotation.set(0, 0, deg(16));
  root.add(wrap2);
  const wrap3 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap3.name = 'wrap3';
  wrap3.position.set(0, 0.1447, 0);
  wrap3.rotation.set(0, 0, deg(16));
  root.add(wrap3);
  const wrap4 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap4.name = 'wrap4';
  wrap4.position.set(0, 0.1713, 0);
  wrap4.rotation.set(0, 0, deg(16));
  root.add(wrap4);
  const wrap5 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap5.name = 'wrap5';
  wrap5.position.set(0, 0.198, 0);
  wrap5.rotation.set(0, 0, deg(16));
  root.add(wrap5);
  const wrap6 = new THREE.Mesh(cylinderGeo, wrapMat);
  wrap6.name = 'wrap6';
  wrap6.position.set(0, 0.2247, 0);
  wrap6.rotation.set(0, 0, deg(16));
  root.add(wrap6);
  const guard = new THREE.Mesh(new THREE.BoxGeometry(0.24, 0.0289, 0.04), hiltMat);
  guard.name = 'guard';
  guard.position.set(0, 0.255, 0);
  root.add(guard);
  const guardEndR = new THREE.Mesh(sphereGeo, hiltMat);
  guardEndR.name = 'guardEndR';
  guardEndR.position.set(0.125, 0.255, 0);
  root.add(guardEndR);
  const guardEndL = new THREE.Mesh(sphereGeo, hiltMat);
  guardEndL.name = 'guardEndL';
  guardEndL.position.set(-0.125, 0.255, 0);
  root.add(guardEndL);
  const guardCenter = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.05, 0.048), hiltMat);
  guardCenter.name = 'guardCenter';
  guardCenter.position.set(0, 0.255, 0);
  guardCenter.rotation.set(0, 0, deg(45));
  root.add(guardCenter);
  const blade = new THREE.Mesh(extrude([[-0.013, 0], [0.013, 0], [0.007, 0.615], [0, 0.7284], [-0.007, 0.615]], 0.001, [], [0.0045, 0.018, 1]), bladeMat);
  blade.name = 'blade';
  blade.position.set(0, 0.273, 0);
  root.add(blade);

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

export default createSword;
```

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