Codels
408 üçgen0,33 × 0,23 × 0,17 m
Bağımsız bir ES modülü — yalnızca three paketine bağımlıdır. Fabrika fonksiyonunu çağırıp dönen grubu sahnene ekle.
/**
 * Ammo Box — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
 * Triangles: 408 · Size (W × H × D): 0.33 × 0.23 × 0.17 m
 *
 * Usage:
 *   import { createAmmoBox } from './ammo-box.js';
 *   
 *   const model = createAmmoBox();
 *   model.position.set(0, 0, 0);
 *   scene.add(model);
 */
import * as THREE from 'three';

const deg = THREE.MathUtils.degToRad;

// Tube along a smooth curve through the given points.
function tube(path, radius, tubularSegments, radialSegments, closed = false) {
  const curve = new THREE.CatmullRomCurve3(path.map(([x, y, z]) => new THREE.Vector3(x, y, z)), closed);
  return new THREE.TubeGeometry(curve, tubularSegments, radius, radialSegments, closed);
}

export function createAmmoBox() {
  const root = new THREE.Group();
  root.name = 'AmmoBox';

  // Materials
  const paintMat = new THREE.MeshStandardMaterial({ name: 'paint', color: 0x5d6b3c, roughness: 0.6, metalness: 0.45, flatShading: true });
  const darkMat = new THREE.MeshStandardMaterial({ name: 'dark', color: 0x3b4428, roughness: 0.6, metalness: 0.5, flatShading: true });
  const steelMat = new THREE.MeshStandardMaterial({ name: 'steel', color: 0x8d949c, roughness: 0.4, metalness: 0.7, flatShading: true });
  const stencilMat = new THREE.MeshStandardMaterial({ name: 'stencil', color: 0xe3c34d, roughness: 0.7, flatShading: true });

  // Shared geometries
  const boxGeo = new THREE.BoxGeometry(0.3, 0.17, 0.008);
  const boxGeo2 = new THREE.BoxGeometry(0.008, 0.17, 0.134);
  const boxGeo3 = new THREE.BoxGeometry(0.258, 0.012, 0.006);
  const boxGeo4 = new THREE.BoxGeometry(0.032, 0.03, 0.006);
  const boxGeo5 = new THREE.BoxGeometry(0.022, 0.012, 0.022);

  // Parts
  const bottom = new THREE.Mesh(new THREE.BoxGeometry(0.3, 0.008, 0.15), paintMat);
  bottom.name = 'bottom';
  bottom.position.set(0, 0.004, 0);
  root.add(bottom);
  const wallFront = new THREE.Mesh(boxGeo, paintMat);
  wallFront.name = 'wallFront';
  wallFront.position.set(0, 0.085, 0.071);
  root.add(wallFront);
  const wallRight = new THREE.Mesh(boxGeo2, paintMat);
  wallRight.name = 'wallRight';
  wallRight.position.set(0.146, 0.085, 0);
  root.add(wallRight);
  const ribF1 = new THREE.Mesh(boxGeo3, paintMat);
  ribF1.name = 'ribF1';
  ribF1.position.set(0, 0.045, 0.077);
  root.add(ribF1);
  const ribF2 = new THREE.Mesh(boxGeo3, paintMat);
  ribF2.name = 'ribF2';
  ribF2.position.set(0, 0.095, 0.077);
  root.add(ribF2);
  const wallBack = new THREE.Mesh(boxGeo, paintMat);
  wallBack.name = 'wallBack';
  wallBack.position.set(0, 0.085, -0.071);
  root.add(wallBack);
  const wallLeft = new THREE.Mesh(boxGeo2, paintMat);
  wallLeft.name = 'wallLeft';
  wallLeft.position.set(-0.146, 0.085, 0);
  root.add(wallLeft);
  const ribB1 = new THREE.Mesh(boxGeo3, paintMat);
  ribB1.name = 'ribB1';
  ribB1.position.set(0, 0.045, -0.077);
  root.add(ribB1);
  const ribB2 = new THREE.Mesh(boxGeo3, paintMat);
  ribB2.name = 'ribB2';
  ribB2.position.set(0, 0.095, -0.077);
  root.add(ribB2);
  const stencilStripe = new THREE.Mesh(boxGeo3, stencilMat);
  stencilStripe.name = 'stencilStripe';
  stencilStripe.position.set(0, 0.12, 0.0775);
  root.add(stencilStripe);
  const stencilChar1 = new THREE.Mesh(boxGeo4, stencilMat);
  stencilChar1.name = 'stencilChar1';
  stencilChar1.position.set(-0.09, 0.07, 0.0775);
  root.add(stencilChar1);
  const stencilChar2 = new THREE.Mesh(boxGeo4, stencilMat);
  stencilChar2.name = 'stencilChar2';
  stencilChar2.position.set(-0.048, 0.07, 0.0775);
  root.add(stencilChar2);
  const stencilChar3 = new THREE.Mesh(boxGeo4, stencilMat);
  stencilChar3.name = 'stencilChar3';
  stencilChar3.position.set(-0.006, 0.07, 0.0775);
  root.add(stencilChar3);
  const stencilChar4 = new THREE.Mesh(boxGeo4, stencilMat);
  stencilChar4.name = 'stencilChar4';
  stencilChar4.position.set(0.036, 0.07, 0.0775);
  root.add(stencilChar4);
  const stencilCode = new THREE.Mesh(new THREE.BoxGeometry(0.07, 0.012, 0.006), stencilMat);
  stencilCode.name = 'stencilCode';
  stencilCode.position.set(0.085, 0.077, 0.0775);
  root.add(stencilCode);
  const stencilCode2 = new THREE.Mesh(new THREE.BoxGeometry(0.05, 0.012, 0.006), stencilMat);
  stencilCode2.name = 'stencilCode2';
  stencilCode2.position.set(0.075, 0.057, 0.0775);
  root.add(stencilCode2);
  const lid = new THREE.Group();
  lid.name = 'lid';
  lid.position.set(0, 0.17, -0.075);
  root.add(lid);
  const lidPlate = new THREE.Mesh(new THREE.BoxGeometry(0.312, 0.03, 0.162), paintMat);
  lidPlate.name = 'lidPlate';
  lidPlate.position.set(0, 0.015, 0.075);
  lid.add(lidPlate);
  const lidPanel = new THREE.Mesh(new THREE.BoxGeometry(0.26, 0.008, 0.11), darkMat);
  lidPanel.name = 'lidPanel';
  lidPanel.position.set(0, 0.033, 0.075);
  lid.add(lidPanel);
  const handle = new THREE.Mesh(tube([[-0.07, 0.038, 0.063], [-0.06, 0.046, 0.095], [0.06, 0.046, 0.095], [0.07, 0.038, 0.063]], 0.007, 12, 5), steelMat);
  handle.name = 'handle';
  lid.add(handle);
  const handleMountR = new THREE.Mesh(boxGeo5, steelMat);
  handleMountR.name = 'handleMountR';
  handleMountR.position.set(0.07, 0.036, 0.063);
  lid.add(handleMountR);
  const handleMountL = new THREE.Mesh(boxGeo5, steelMat);
  handleMountL.name = 'handleMountL';
  handleMountL.position.set(-0.07, 0.036, 0.063);
  lid.add(handleMountL);
  const hinge = new THREE.Mesh(new THREE.CylinderGeometry(0.008, 0.008, 0.27, 6), steelMat);
  hinge.name = 'hinge';
  hinge.position.set(0, 0.17, -0.079);
  hinge.rotation.set(0, 0, deg(90));
  root.add(hinge);
  const latchPlate = new THREE.Mesh(new THREE.BoxGeometry(0.008, 0.07, 0.06), steelMat);
  latchPlate.name = 'latchPlate';
  latchPlate.position.set(0.156, 0.145, 0);
  root.add(latchPlate);
  const latchLever = new THREE.Mesh(new THREE.BoxGeometry(0.01, 0.075, 0.022), steelMat);
  latchLever.name = 'latchLever';
  latchLever.position.set(0.164, 0.13, 0);
  root.add(latchLever);

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

export default createAmmoBox;

Puanlar ve yorumlar

—
Henüz puan yok — ilk puanı sen ver.
5
0
4
0
3
0
2
0
1
0

Puan vermek ve yorum yapmak için giriş yap.

0 yorum

Henüz yorum yok. Bu modeli nasıl kullandığını ya da neyin daha iyi olabileceğini paylaş.

Benzer modeller

Aynı kategori ya da benzer etiketler