Codels
696 三角面0.15 × 0.19 × 0.06 m

在代码中使用

在编辑器中改编
自包含的 ES 模块,仅依赖 three。调用工厂函数,然后把返回的 group 添加到场景中。
/**
 * Gem Ring — Codels 3D model library
 * License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the model (it floats — pickups, planets)
 * Triangles: 696 · Size (W × H × D): 0.15 × 0.19 × 0.06 m
 *
 * Usage:
 *   import { createRing } from './ring.js';
 *   
 *   const model = createRing();
 *   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 createRing() {
  const root = new THREE.Group();
  root.name = 'Ring';

  // Materials
  const metalMat = new THREE.MeshStandardMaterial({ name: 'metal', color: 0xf2c14e, roughness: 0.25, metalness: 0.9, flatShading: true });
  const gemMat = new THREE.MeshStandardMaterial({ name: 'gem', color: 0xd81e47, roughness: 0.1, metalness: 0.1, emissive: 0xd81e47, emissiveIntensity: 0.25, flatShading: true });
  const diamondMat = new THREE.MeshStandardMaterial({ name: 'diamond', color: 0xeef8ff, roughness: 0.05, metalness: 0.1, emissive: 0xcfe8ff, emissiveIntensity: 0.25, flatShading: true });

  // Shared geometries
  const cylinderGeo = new THREE.CylinderGeometry(0.0032, 0.004, 0.026, 5);
  const sphereGeo = new THREE.SphereGeometry(0.0042, 5, 4);
  const octahedronGeo = new THREE.OctahedronGeometry(0.009, 0);

  // Parts
  const ring = new THREE.Group();
  ring.name = 'ring';
  ring.position.set(0, -0.0183, 0);
  ring.scale.setScalar(0.9868);
  root.add(ring);
  const band = new THREE.Mesh(new THREE.TorusGeometry(0.065, 0.011, 6, 28), metalMat);
  band.name = 'band';
  band.scale.set(1, 1, 1.45);
  ring.add(band);
  const setting = new THREE.Mesh(new THREE.CylinderGeometry(0.024, 0.012, 0.022, 8), metalMat);
  setting.name = 'setting';
  setting.position.set(0, 0.082, 0);
  setting.rotation.set(0, deg(22.5), 0);
  ring.add(setting);
  const bezel = new THREE.Mesh(new THREE.CylinderGeometry(0.026, 0.026, 0.004, 8), metalMat);
  bezel.name = 'bezel';
  bezel.position.set(0, 0.093, 0);
  bezel.rotation.set(0, deg(22.5), 0);
  ring.add(bezel);
  const gem = new THREE.Mesh(lathe([[0, -0.024], [0.03, -0.002], [0.03, 0.002], [0.026, 0.009], [0.018, 0.0135], [0, 0.0135]], 8), gemMat);
  gem.name = 'gem';
  gem.position.set(0, 0.099, 0);
  gem.rotation.set(0, deg(22.5), 0);
  ring.add(gem);
  const prong1 = new THREE.Mesh(cylinderGeo, metalMat);
  prong1.name = 'prong1';
  prong1.position.set(0.0191, 0.095, 0.0191);
  prong1.rotation.set(deg(-4.8328), deg(-0.2041), deg(4.8328));
  ring.add(prong1);
  const prongTip1 = new THREE.Mesh(sphereGeo, metalMat);
  prongTip1.name = 'prongTip1';
  prongTip1.position.set(0.018, 0.107, 0.018);
  ring.add(prongTip1);
  const prong2 = new THREE.Mesh(cylinderGeo, metalMat);
  prong2.name = 'prong2';
  prong2.position.set(0.0191, 0.095, -0.0191);
  prong2.rotation.set(deg(4.8328), deg(0.2041), deg(4.8328));
  ring.add(prong2);
  const prongTip2 = new THREE.Mesh(sphereGeo, metalMat);
  prongTip2.name = 'prongTip2';
  prongTip2.position.set(0.018, 0.107, -0.018);
  ring.add(prongTip2);
  const prong3 = new THREE.Mesh(cylinderGeo, metalMat);
  prong3.name = 'prong3';
  prong3.position.set(-0.0191, 0.095, -0.0191);
  prong3.rotation.set(deg(4.8328), deg(-0.2041), deg(-4.8328));
  ring.add(prong3);
  const prongTip3 = new THREE.Mesh(sphereGeo, metalMat);
  prongTip3.name = 'prongTip3';
  prongTip3.position.set(-0.018, 0.107, -0.018);
  ring.add(prongTip3);
  const prong4 = new THREE.Mesh(cylinderGeo, metalMat);
  prong4.name = 'prong4';
  prong4.position.set(-0.0191, 0.095, 0.0191);
  prong4.rotation.set(deg(-4.8328), deg(0.2041), deg(-4.8328));
  ring.add(prong4);
  const prongTip4 = new THREE.Mesh(sphereGeo, metalMat);
  prongTip4.name = 'prongTip4';
  prongTip4.position.set(-0.018, 0.107, 0.018);
  ring.add(prongTip4);
  const accentR = new THREE.Mesh(octahedronGeo, diamondMat);
  accentR.name = 'accentR';
  accentR.position.set(0.0377, 0.0603, 0.0104);
  accentR.rotation.set(0, 0, deg(-32));
  accentR.scale.set(1, 1, 0.6);
  ring.add(accentR);
  const accentL = new THREE.Mesh(octahedronGeo, diamondMat);
  accentL.name = 'accentL';
  accentL.position.set(-0.0377, 0.0603, 0.0104);
  accentL.rotation.set(0, 0, deg(32));
  accentL.scale.set(1, 1, 0.6);
  ring.add(accentL);

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

export default createRing;

评分与评论

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

登录后即可评分和评论。

0 条评论

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

相关模型

同一分类或相似标签