Codels
784 三角面0.62 × 0.90 × 0.63 m

在代码中使用

在编辑器中改编
自包含的 ES 模块,仅依赖 three。调用工厂函数,然后把返回的 group 添加到场景中。
/**
 * Barrel — Codels 3D model library
 * 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;

评分与评论

—
暂无评分,快来抢先评分吧。
5
0
4
0
3
0
2
0
1
0

登录后即可评分和评论。

0 条评论

暂无评论。分享一下你是如何使用这个模型的,或者有哪些可以改进的地方。

相关模型

同一分类或相似标签