448 ポリゴン0.08 × 0.10 × 0.08 m
コードで使う
エディターでリミックスorange.js · 90 行
自己完結型の ES モジュールで、依存先は three のみです。ファクトリー関数を呼び出し、返された group をシーンに追加してください。
/**
* Orange — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 448 · Size (W × H × D): 0.08 × 0.10 × 0.08 m
*
* Usage:
* import { createOrange } from './orange.js';
*
* const model = createOrange();
* model.position.set(0, 0, 0);
* scene.add(model);
*/
import * as THREE from 'three';
const deg = THREE.MathUtils.degToRad;
// Deterministic vertex displacement (organic low-poly look).
function jitter(geometry, amount, seed) {
const pos = geometry.attributes.position;
const h = (a, b, c, s) => {
let x = Math.imul(a, 73856093) ^ Math.imul(b, 19349663) ^ Math.imul(c, 83492791) ^ Math.imul(s, 2654435761);
x = Math.imul(x ^ (x >>> 16), 2246822507);
x = Math.imul(x ^ (x >>> 13), 3266489909);
return ((x ^ (x >>> 16)) >>> 0) / 4294967295 - 0.5;
};
for (let i = 0; i < pos.count; i++) {
const x = pos.getX(i), y = pos.getY(i), z = pos.getZ(i);
const qx = Math.round(x * 1000), qy = Math.round(y * 1000), qz = Math.round(z * 1000);
pos.setXYZ(i, x + h(qx, qy, qz, seed) * 2 * amount, y + h(qx, qy, qz, seed + 1) * 2 * amount, z + h(qx, qy, qz, seed + 2) * 2 * amount);
}
pos.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
// 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 createOrange() {
const root = new THREE.Group();
root.name = 'Orange';
// Materials
const peelMat = new THREE.MeshStandardMaterial({ name: 'peel', color: 0xf27a14, roughness: 0.55 });
const stemMat = new THREE.MeshStandardMaterial({ name: 'stem', color: 0x5d7a2a, roughness: 0.8, flatShading: true });
const leafMat = new THREE.MeshStandardMaterial({ name: 'leaf', color: 0x3f8a2c, roughness: 0.65, flatShading: true });
// Parts
const orange = new THREE.Group();
orange.name = 'orange';
orange.scale.setScalar(0.08);
root.add(orange);
const peel = new THREE.Mesh(jitter(new THREE.SphereGeometry(0.5, 16, 12), 0.008, 5), peelMat);
peel.name = 'peel';
peel.position.set(0, 0.47, 0);
peel.scale.set(1, 0.94, 1);
orange.add(peel);
const stemButton = new THREE.Mesh(new THREE.CylinderGeometry(0.045, 0.06, 0.03, 6), stemMat);
stemButton.name = 'stemButton';
stemButton.position.set(0, 0.943, 0);
orange.add(stemButton);
const stem = new THREE.Mesh(new THREE.CylinderGeometry(0.014, 0.018, 0.06, 5), stemMat);
stem.name = 'stem';
stem.position.set(0.004, 0.98, 0);
stem.rotation.set(0, 0, deg(-12));
orange.add(stem);
const leaf = new THREE.Mesh(extrude([[0, 0], [0.06, 0.0667], [0.12, 0.1068], [0.18, 0.1274], [0.24, 0.1274], [0.3, 0.1068], [0.36, 0.0667], [0.42, 0], [0.36, -0.0667], [0.3, -0.1068], [0.24, -0.1274], [0.18, -0.1274], [0.12, -0.1068], [0.06, -0.0667]], 0.014), leafMat);
leaf.name = 'leaf';
leaf.position.set(0.03, 0.97, 0.01);
leaf.rotation.set(deg(68.6623), deg(32.2205), deg(36.229));
orange.add(leaf);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createOrange;
評価とコメント
0 件のコメント
まだコメントはありません。このモデルの使い方や改善できる点を共有しましょう。
関連モデル
同じカテゴリまたは似たタグ









