Codels
888 tris0,52 × 1,00 × 0,07 m

Utiliser dans le code

Remixer dans l’éditeur
Module ES autonome — ne dépend que de three. Appelez la fonction factory et ajoutez le groupe à votre scène.
/**
 * Battle Axe — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 888 · Size (W × H × D): 0.52 × 0.99 × 0.07 m
 *
 * Usage:
 *   import { createBattleAxe } from './battle-axe.js';
 *   
 *   const model = createBattleAxe();
 *   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 createBattleAxe() {
  const root = new THREE.Group();
  root.name = 'BattleAxe';

  // Materials
  const ironMat = new THREE.MeshStandardMaterial({ name: 'iron', color: 0x717a85, roughness: 0.45, metalness: 0.7, flatShading: true });
  const edgeMat = new THREE.MeshStandardMaterial({ name: 'edge', color: 0xdfe5ec, roughness: 0.3, metalness: 0.75, flatShading: true });
  const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0x7a4e2c, roughness: 0.85, flatShading: true });
  const leatherMat = new THREE.MeshStandardMaterial({ name: 'leather', color: 0x3d2617, roughness: 0.9, flatShading: true });

  // Shared geometries
  const cylinderGeo = new THREE.CylinderGeometry(0.0245, 0.0245, 0.016, 8);
  const boxGeo = new THREE.BoxGeometry(0.014, 0.1, 0.006);
  const sphereGeo = new THREE.SphereGeometry(0.01, 5, 3);

  // Parts
  const pommel = new THREE.Mesh(new THREE.CylinderGeometry(0.026, 0.03, 0.04, 8), ironMat);
  pommel.name = 'pommel';
  pommel.position.set(0, 0.02, 0);
  root.add(pommel);
  const pommelKnob = new THREE.Mesh(new THREE.SphereGeometry(0.02, 6, 4), ironMat);
  pommelKnob.name = 'pommelKnob';
  pommelKnob.position.set(0, 0.018, 0);
  pommelKnob.scale.set(1, 0.8, 1);
  root.add(pommelKnob);
  const haft = new THREE.Mesh(new THREE.CylinderGeometry(0.019, 0.022, 0.87, 8), woodMat);
  haft.name = 'haft';
  haft.position.set(0, 0.465, 0);
  root.add(haft);
  const wrap1 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap1.name = 'wrap1';
  wrap1.position.set(0, 0.06, 0);
  wrap1.rotation.set(0, 0, deg(14));
  root.add(wrap1);
  const wrap2 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap2.name = 'wrap2';
  wrap2.position.set(0, 0.086, 0);
  wrap2.rotation.set(0, 0, deg(14));
  root.add(wrap2);
  const wrap3 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap3.name = 'wrap3';
  wrap3.position.set(0, 0.112, 0);
  wrap3.rotation.set(0, 0, deg(14));
  root.add(wrap3);
  const wrap4 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap4.name = 'wrap4';
  wrap4.position.set(0, 0.138, 0);
  wrap4.rotation.set(0, 0, deg(14));
  root.add(wrap4);
  const wrap5 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap5.name = 'wrap5';
  wrap5.position.set(0, 0.164, 0);
  wrap5.rotation.set(0, 0, deg(14));
  root.add(wrap5);
  const wrap6 = new THREE.Mesh(cylinderGeo, leatherMat);
  wrap6.name = 'wrap6';
  wrap6.position.set(0, 0.19, 0);
  wrap6.rotation.set(0, 0, deg(14));
  root.add(wrap6);
  const socket = new THREE.Mesh(new THREE.BoxGeometry(0.066, 0.17, 0.05), ironMat);
  socket.name = 'socket';
  socket.position.set(0, 0.8, 0);
  root.add(socket);
  const collar = new THREE.Mesh(new THREE.CylinderGeometry(0.032, 0.032, 0.02, 8), ironMat);
  collar.name = 'collar';
  collar.position.set(0, 0.705, 0);
  root.add(collar);
  const spike = new THREE.Mesh(new THREE.ConeGeometry(0.024, 0.11, 4), ironMat);
  spike.name = 'spike';
  spike.position.set(0, 0.94, 0);
  spike.rotation.set(0, deg(45), 0);
  root.add(spike);
  const langetF = new THREE.Mesh(boxGeo, ironMat);
  langetF.name = 'langetF';
  langetF.position.set(0, 0.67, 0.0205);
  root.add(langetF);
  const langetB = new THREE.Mesh(boxGeo, ironMat);
  langetB.name = 'langetB';
  langetB.position.set(0, 0.67, -0.0205);
  root.add(langetB);
  const bladeR = new THREE.Mesh(extrude([[0.03, -0.05], [0.075, -0.038], [0.105, -0.065], [0.135, -0.1], [0.1638, -0.1263], [0.1942, -0.0901], [0.2134, -0.0469], [0.22, 0], [0.2134, 0.0469], [0.1942, 0.0901], [0.1638, 0.1263], [0.135, 0.1], [0.105, 0.065], [0.075, 0.038], [0.03, 0.05]], 0.014, [], [0.008, 0.006, 1]), ironMat);
  bladeR.name = 'bladeR';
  bladeR.position.set(0, 0.8, 0);
  root.add(bladeR);
  const edgeR = new THREE.Mesh(extrude([[0.1778, -0.1603], [0.2103, -0.1278], [0.2347, -0.089], [0.2499, -0.0456], [0.255, 0], [0.2499, 0.0456], [0.2347, 0.089], [0.2103, 0.1278], [0.1778, 0.1603], [0.1638, 0.1263], [0.1942, 0.0901], [0.2134, 0.0469], [0.22, 0], [0.2134, -0.0469], [0.1942, -0.0901], [0.1638, -0.1263]], 0.012, [], [0.004, 0.004, 1]), edgeMat);
  edgeR.name = 'edgeR';
  edgeR.position.set(0, 0.8, 0);
  root.add(edgeR);
  const bladeL = new THREE.Mesh(extrude([[-0.03, -0.05], [-0.075, -0.038], [-0.105, -0.065], [-0.135, -0.1], [-0.1638, -0.1263], [-0.1942, -0.0901], [-0.2134, -0.0469], [-0.22, 0], [-0.2134, 0.0469], [-0.1942, 0.0901], [-0.1638, 0.1263], [-0.135, 0.1], [-0.105, 0.065], [-0.075, 0.038], [-0.03, 0.05]], 0.014, [], [0.008, 0.006, 1]), ironMat);
  bladeL.name = 'bladeL';
  bladeL.position.set(0, 0.8, 0);
  root.add(bladeL);
  const edgeL = new THREE.Mesh(extrude([[-0.1778, -0.1603], [-0.2103, -0.1278], [-0.2347, -0.089], [-0.2499, -0.0456], [-0.255, 0], [-0.2499, 0.0456], [-0.2347, 0.089], [-0.2103, 0.1278], [-0.1778, 0.1603], [-0.1638, 0.1263], [-0.1942, 0.0901], [-0.2134, 0.0469], [-0.22, 0], [-0.2134, -0.0469], [-0.1942, -0.0901], [-0.1638, -0.1263]], 0.012, [], [0.004, 0.004, 1]), edgeMat);
  edgeL.name = 'edgeL';
  edgeL.position.set(0, 0.8, 0);
  root.add(edgeL);
  const rivetF = new THREE.Mesh(sphereGeo, edgeMat);
  rivetF.name = 'rivetF';
  rivetF.position.set(0, 0.84, 0.026);
  root.add(rivetF);
  const rivetB = new THREE.Mesh(sphereGeo, edgeMat);
  rivetB.name = 'rivetB';
  rivetB.position.set(0, 0.84, -0.026);
  root.add(rivetB);

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

export default createBattleAxe;

Notes et commentaires

—
Aucune note pour l’instant — soyez le premier.
5
0
4
0
3
0
2
0
1
0

Connectez-vous pour noter et commenter.

0 commentaire

Aucun commentaire pour l’instant. Dites comment vous avez utilisé ce modèle ou ce qui pourrait être amélioré.

Modèles similaires

Même catégorie ou étiquettes proches