1,2 k tris0,13 × 0,09 × 0,13 m
Utiliser dans le code
Remixer dans l’éditeurburger.js · 231 lignes
Module ES autonome — ne dépend que de three. Appelez la fonction factory et ajoutez le groupe à votre scène.
/**
* Burger — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 1,184 · Size (W × H × D): 0.13 × 0.09 × 0.13 m
*
* Usage:
* import { createBurger } from './burger.js';
*
* const model = createBurger();
* 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);
}
// 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 createBurger() {
const root = new THREE.Group();
root.name = 'Burger';
// Materials
const bunMat = new THREE.MeshStandardMaterial({ name: 'bun', color: 0xd98c3a, roughness: 0.6, flatShading: true });
const crumbMat = new THREE.MeshStandardMaterial({ name: 'crumb', color: 0xf0cf8e, roughness: 0.8, flatShading: true });
const pattyMat = new THREE.MeshStandardMaterial({ name: 'patty', color: 0x5b3220, roughness: 0.9, flatShading: true });
const cheeseMat = new THREE.MeshStandardMaterial({ name: 'cheese', color: 0xffc928, roughness: 0.45, flatShading: true });
const tomatoMat = new THREE.MeshStandardMaterial({ name: 'tomato', color: 0xe23a2e, roughness: 0.5, flatShading: true });
const lettuceMat = new THREE.MeshStandardMaterial({ name: 'lettuce', color: 0x74c24a, roughness: 0.7, flatShading: true });
const seedMat = new THREE.MeshStandardMaterial({ name: 'seed', color: 0xfbf0d2, roughness: 0.6, flatShading: true });
// Shared geometries
const sphereGeo = new THREE.SphereGeometry(0.034, 5, 3);
// Parts
const burger = new THREE.Group();
burger.name = 'burger';
burger.scale.setScalar(0.11);
root.add(burger);
const bottomBun = new THREE.Mesh(lathe([[0, 0], [0.42, 0], [0.48, 0.025], [0.5, 0.07], [0.49, 0.12], [0.47, 0.14], [0, 0.14]], 16), bunMat);
bottomBun.name = 'bottomBun';
burger.add(bottomBun);
const bottomCrumb = new THREE.Mesh(new THREE.CylinderGeometry(0.46, 0.46, 0.012, 16), crumbMat);
bottomCrumb.name = 'bottomCrumb';
bottomCrumb.position.set(0, 0.14, 0);
burger.add(bottomCrumb);
const patty1 = new THREE.Mesh(jitter(new THREE.CylinderGeometry(0.52, 0.52, 0.13, 14, 2), 0.012, 11), pattyMat);
patty1.name = 'patty1';
patty1.position.set(0, 0.207, 0);
burger.add(patty1);
const cheese1 = new THREE.Mesh(new THREE.CylinderGeometry(0.47, 0.68, 0.07, 4, 1), cheeseMat);
cheese1.name = 'cheese1';
cheese1.position.set(0, 0.26, 0);
cheese1.rotation.set(0, deg(45), 0);
burger.add(cheese1);
const tomato = new THREE.Mesh(new THREE.CylinderGeometry(0.48, 0.48, 0.055, 14), tomatoMat);
tomato.name = 'tomato';
tomato.position.set(0, 0.3205, 0);
burger.add(tomato);
const lettuce = new THREE.Mesh(jitter(extrude([[0.58, 0], [0.5086, 0.1081], [0.5299, 0.2359], [0.4207, 0.3056], [0.3881, 0.431], [0.26, 0.4503], [0.1792, 0.5516], [0.0544, 0.5172], [-0.0606, 0.5768], [-0.1607, 0.4945], [-0.29, 0.5023], [-0.3479, 0.3864], [-0.4692, 0.3409], [-0.475, 0.2115], [-0.5673, 0.1206], [-0.52, 0], [-0.5673, -0.1206], [-0.475, -0.2115], [-0.4692, -0.3409], [-0.3479, -0.3864], [-0.29, -0.5023], [-0.1607, -0.4945], [-0.0606, -0.5768], [0.0544, -0.5172], [0.1792, -0.5516], [0.26, -0.4503], [0.3881, -0.431], [0.4207, -0.3056], [0.5299, -0.2359], [0.5086, -0.1081]], 0.02), 0.022, 5), lettuceMat);
lettuce.name = 'lettuce';
lettuce.position.set(0, 0.353, 0);
lettuce.rotation.set(deg(-90), 0, 0);
burger.add(lettuce);
const topBun = new THREE.Mesh(lathe([[0, 0.368], [0.46, 0.368], [0.5, 0.408], [0.515, 0.468], [0.49, 0.568], [0.42, 0.668], [0.3, 0.738], [0.15, 0.773], [0, 0.783]], 16), bunMat);
topBun.name = 'topBun';
burger.add(topBun);
const seed1 = new THREE.Mesh(sphereGeo, seedMat);
seed1.name = 'seed1';
seed1.position.set(0.2936, 0.5507, -0.3977);
seed1.rotation.set(deg(-72.7377), 0, deg(-35.183));
seed1.scale.set(0.55, 0.4, 1);
burger.add(seed1);
const seed2 = new THREE.Mesh(sphereGeo, seedMat);
seed2.name = 'seed2';
seed2.position.set(0.2168, 0.5356, -0.4484);
seed2.rotation.set(deg(-74.4809), 0, deg(-24.9776));
seed2.scale.set(0.55, 0.4, 1);
burger.add(seed2);
const seed3 = new THREE.Mesh(sphereGeo, seedMat);
seed3.name = 'seed3';
seed3.position.set(-0.1434, 0.6898, -0.3547);
seed3.rotation.set(deg(-28.4054), 0, deg(10.8847));
seed3.scale.set(0.55, 0.4, 1);
burger.add(seed3);
const seed4 = new THREE.Mesh(sphereGeo, seedMat);
seed4.name = 'seed4';
seed4.position.set(0.4287, 0.5676, -0.2376);
seed4.rotation.set(deg(-62.7188), 0, deg(-58.0527));
seed4.scale.set(0.55, 0.4, 1);
burger.add(seed4);
const seed5 = new THREE.Mesh(sphereGeo, seedMat);
seed5.name = 'seed5';
seed5.position.set(-0.3362, 0.5327, -0.3685);
seed5.rotation.set(deg(-71.3036), 0, deg(40.8334));
seed5.scale.set(0.55, 0.4, 1);
burger.add(seed5);
const seed6 = new THREE.Mesh(sphereGeo, seedMat);
seed6.name = 'seed6';
seed6.position.set(-0.3365, 0.683, -0.2056);
seed6.rotation.set(deg(-16.9156), 0, deg(25.466));
seed6.scale.set(0.55, 0.4, 1);
burger.add(seed6);
const seed7 = new THREE.Mesh(sphereGeo, seedMat);
seed7.name = 'seed7';
seed7.position.set(0.4498, 0.5731, -0.1853);
seed7.rotation.set(deg(-28.549), 0, deg(-49.2438));
seed7.scale.set(0.55, 0.4, 1);
burger.add(seed7);
const seed8 = new THREE.Mesh(sphereGeo, seedMat);
seed8.name = 'seed8';
seed8.position.set(-0.0601, 0.5741, -0.482);
seed8.rotation.set(deg(-54.8004), 0, deg(5.8135));
seed8.scale.set(0.55, 0.4, 1);
burger.add(seed8);
const seed9 = new THREE.Mesh(sphereGeo, seedMat);
seed9.name = 'seed9';
seed9.position.set(-0.2814, 0.6681, 0.3115);
seed9.rotation.set(deg(23.4048), 0, deg(19.7423));
seed9.scale.set(0.55, 0.4, 1);
burger.add(seed9);
const seed10 = new THREE.Mesh(sphereGeo, seedMat);
seed10.name = 'seed10';
seed10.position.set(0.3515, 0.6399, -0.2641);
seed10.rotation.set(deg(-40.6357), 0, deg(-40.9148));
seed10.scale.set(0.55, 0.4, 1);
burger.add(seed10);
const seed11 = new THREE.Mesh(sphereGeo, seedMat);
seed11.name = 'seed11';
seed11.position.set(-0.3058, 0.7274, 0.0881);
seed11.rotation.set(deg(9.1791), 0, deg(28.957));
seed11.scale.set(0.55, 0.4, 1);
burger.add(seed11);
const seed12 = new THREE.Mesh(sphereGeo, seedMat);
seed12.name = 'seed12';
seed12.position.set(0.1161, 0.7295, 0.2923);
seed12.rotation.set(deg(28.463), 0, deg(-10.7211));
seed12.scale.set(0.55, 0.4, 1);
burger.add(seed12);
const seed13 = new THREE.Mesh(sphereGeo, seedMat);
seed13.name = 'seed13';
seed13.position.set(-0.2024, 0.6775, 0.3494);
seed13.rotation.set(deg(26.783), 0, deg(14.6289));
seed13.scale.set(0.55, 0.4, 1);
burger.add(seed13);
const seed14 = new THREE.Mesh(sphereGeo, seedMat);
seed14.name = 'seed14';
seed14.position.set(0.3595, 0.5107, -0.3537);
seed14.rotation.set(deg(-70.3786), 0, deg(-43.7589));
seed14.scale.set(0.55, 0.4, 1);
burger.add(seed14);
const seed15 = new THREE.Mesh(sphereGeo, seedMat);
seed15.name = 'seed15';
seed15.position.set(-0.4872, 0.5522, -0.0814);
seed15.rotation.set(deg(-33.4001), 0, deg(73.1112));
seed15.scale.set(0.55, 0.4, 1);
burger.add(seed15);
const seed16 = new THREE.Mesh(sphereGeo, seedMat);
seed16.name = 'seed16';
seed16.position.set(0.3989, 0.6289, 0.2024);
seed16.rotation.set(deg(32.8806), 0, deg(-46.933));
seed16.scale.set(0.55, 0.4, 1);
burger.add(seed16);
const seed17 = new THREE.Mesh(sphereGeo, seedMat);
seed17.name = 'seed17';
seed17.position.set(-0.0953, 0.7191, -0.3185);
seed17.rotation.set(deg(-29.1986), 0, deg(8.3053));
seed17.scale.set(0.55, 0.4, 1);
burger.add(seed17);
const seed18 = new THREE.Mesh(sphereGeo, seedMat);
seed18.name = 'seed18';
seed18.position.set(0.4496, 0.5502, 0.2058);
seed18.rotation.set(deg(59.0121), 0, deg(-61.8959));
seed18.scale.set(0.55, 0.4, 1);
burger.add(seed18);
const seed19 = new THREE.Mesh(sphereGeo, seedMat);
seed19.name = 'seed19';
seed19.position.set(-0.1643, 0.6275, 0.4172);
seed19.rotation.set(deg(53.0455), 0, deg(17.4663));
seed19.scale.set(0.55, 0.4, 1);
burger.add(seed19);
const seed20 = new THREE.Mesh(sphereGeo, seedMat);
seed20.name = 'seed20';
seed20.position.set(-0.1079, 0.6726, 0.3978);
seed20.rotation.set(deg(29.3792), 0, deg(7.5791));
seed20.scale.set(0.55, 0.4, 1);
burger.add(seed20);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createBurger;
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









