400 tris0,60 × 0,71 × 0,57 m
Utiliser dans le code
Remixer dans l’éditeursack.js · 84 lignes
Module ES autonome — ne dépend que de three. Appelez la fonction factory et ajoutez le groupe à votre scène.
/**
* Burlap Sack — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 400 · Size (W × H × D): 0.60 × 0.70 × 0.57 m
*
* Usage:
* import { createSack } from './sack.js';
*
* const model = createSack();
* 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;
}
// 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);
}
// 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 createSack() {
const root = new THREE.Group();
root.name = 'Sack';
// Materials
const fabricMat = new THREE.MeshStandardMaterial({ name: 'fabric', color: 0xa87f4a, roughness: 1, flatShading: true });
const ropeMat = new THREE.MeshStandardMaterial({ name: 'rope', color: 0x5a3d22, roughness: 0.95, flatShading: true });
// Parts
const sack1 = new THREE.Group();
sack1.name = 'sack1';
sack1.position.set(0, 0.0034, 0);
sack1.rotation.set(deg(1.1641), deg(20), deg(-0.582));
root.add(sack1);
const body = new THREE.Mesh(jitter(lathe([[0, 0.012], [0.1674, 0.012], [0.2623, 0.0445], [0.293, 0.1355], [0.279, 0.259], [0.2399, 0.376], [0.1674, 0.467], [0.0893, 0.532], [0.0558, 0.571], [0.0502, 0.597], [0.0893, 0.6295], [0.1172, 0.662], [0.0837, 0.6815], [0.0279, 0.6555], [0, 0.649]], 9), 0.0205, 3), fabricMat);
body.name = 'body';
body.scale.set(1.04, 1, 0.9597);
sack1.add(body);
const tie = new THREE.Mesh(new THREE.TorusGeometry(0.0698, 0.018, 5, 10), ropeMat);
tie.name = 'tie';
tie.position.set(0, 0.584, 0);
tie.rotation.set(deg(90), 0, 0);
sack1.add(tie);
const ropeEnd = new THREE.Mesh(tube([[0.0758, 0.584, 0.02], [0.1158, 0.534, 0.05], [0.1258, 0.454, 0.07]], 0.011, 6, 4), ropeMat);
ropeEnd.name = 'ropeEnd';
sack1.add(ropeEnd);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createSack;
Notes et commentaires
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









