572 треуг.1,73 × 1,07 × 2,20 m
Использовать в коде
Ремикс в редактореbed.js · 140 строк
Самодостаточный ES-модуль — зависит только от three. Вызовите фабрику и добавьте группу в сцену.
/**
* Wooden Bed — Codels 3D model library
* License: CC0-1.0 · Units: meters · Y-up · Front: +Z · Origin: center of the base (y = 0)
* Triangles: 572 · Size (W × H × D): 1.73 × 1.07 × 2.20 m
*
* Usage:
* import { createBed } from './bed.js';
*
* const model = createBed();
* model.position.set(0, 0, 0);
* scene.add(model);
*/
import * as THREE from 'three';
const deg = THREE.MathUtils.degToRad;
// 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 createBed() {
const root = new THREE.Group();
root.name = 'Bed';
// Materials
const woodMat = new THREE.MeshStandardMaterial({ name: 'wood', color: 0x9c6236, roughness: 0.85, flatShading: true });
const woodDarkMat = new THREE.MeshStandardMaterial({ name: 'woodDark', color: 0x704727, roughness: 0.9, flatShading: true });
const mattressMat = new THREE.MeshStandardMaterial({ name: 'mattress', color: 0xe9e3d6, roughness: 1, flatShading: true });
const sheetMat = new THREE.MeshStandardMaterial({ name: 'sheet', color: 0xf6f2ea, roughness: 1, flatShading: true });
const blanketMat = new THREE.MeshStandardMaterial({ name: 'blanket', color: 0x3b609e, roughness: 1, flatShading: true });
const blanketDarkMat = new THREE.MeshStandardMaterial({ name: 'blanketDark', color: 0x2e4b7b, roughness: 1, flatShading: true });
// Shared geometries
const boxGeo = new THREE.BoxGeometry(0.085, 1.02, 0.085);
const boxGeo2 = new THREE.BoxGeometry(0.085, 0.62, 0.085);
const cylinderGeo = new THREE.CylinderGeometry(0.025, 0.0468, 0.05, 6);
const boxGeo3 = new THREE.BoxGeometry(0.05, 0.16, 2.105);
const extrudeGeo = extrude([[0.31, 0.12], [0.2895, 0.1695], [0.24, 0.19], [-0.24, 0.19], [-0.2895, 0.1695], [-0.31, 0.12], [-0.31, -0.12], [-0.2895, -0.1695], [-0.24, -0.19], [0.24, -0.19], [0.2895, -0.1695], [0.31, -0.12]], 0.07, [], [0.035, 0.03, 2]);
// Parts
const postHead = new THREE.Mesh(boxGeo, woodDarkMat);
postHead.name = 'postHead';
postHead.position.set(-0.8225, 0.51, -1.0525);
root.add(postHead);
const postFoot = new THREE.Mesh(boxGeo2, woodDarkMat);
postFoot.name = 'postFoot';
postFoot.position.set(-0.8225, 0.31, 1.0525);
root.add(postFoot);
const knob = new THREE.Mesh(cylinderGeo, woodDarkMat);
knob.name = 'knob';
knob.position.set(-0.8225, 1.045, -1.0525);
root.add(knob);
const knob2 = new THREE.Mesh(cylinderGeo, woodDarkMat);
knob2.name = 'knob';
knob2.position.set(-0.8225, 0.645, 1.0525);
root.add(knob2);
const sideRail = new THREE.Mesh(boxGeo3, woodMat);
sideRail.name = 'sideRail';
sideRail.position.set(-0.8, 0.25, 0);
root.add(sideRail);
const postHead2 = new THREE.Mesh(boxGeo, woodDarkMat);
postHead2.name = 'postHead';
postHead2.position.set(0.8225, 0.51, -1.0525);
root.add(postHead2);
const postFoot2 = new THREE.Mesh(boxGeo2, woodDarkMat);
postFoot2.name = 'postFoot';
postFoot2.position.set(0.8225, 0.31, 1.0525);
root.add(postFoot2);
const knob3 = new THREE.Mesh(cylinderGeo, woodDarkMat);
knob3.name = 'knob';
knob3.position.set(0.8225, 1.045, -1.0525);
root.add(knob3);
const knob4 = new THREE.Mesh(cylinderGeo, woodDarkMat);
knob4.name = 'knob';
knob4.position.set(0.8225, 0.645, 1.0525);
root.add(knob4);
const sideRail2 = new THREE.Mesh(boxGeo3, woodMat);
sideRail2.name = 'sideRail';
sideRail2.position.set(0.8, 0.25, 0);
root.add(sideRail2);
const headboard = new THREE.Mesh(extrude([[-0.79, 0], [-0.79, 0.5], [-0.5925, 0.5459], [-0.395, 0.5849], [-0.1975, 0.6109], [0, 0.62], [0.1975, 0.6109], [0.395, 0.5849], [0.5925, 0.5459], [0.79, 0.5], [0.79, 0]], 0.045), woodMat);
headboard.name = 'headboard';
headboard.position.set(0, 0.3, -1.0525);
root.add(headboard);
const headRail = new THREE.Mesh(new THREE.BoxGeometry(1.58, 0.05, 0.06), woodDarkMat);
headRail.name = 'headRail';
headRail.position.set(0, 0.295, -1.0525);
root.add(headRail);
const footboard = new THREE.Mesh(new THREE.BoxGeometry(1.58, 0.26, 0.04), woodMat);
footboard.name = 'footboard';
footboard.position.set(0, 0.4, 1.0525);
root.add(footboard);
const footRail = new THREE.Mesh(new THREE.BoxGeometry(1.6, 0.045, 0.065), woodDarkMat);
footRail.name = 'footRail';
footRail.position.set(0, 0.5525, 1.0525);
root.add(footRail);
const mattress = new THREE.Mesh(new THREE.BoxGeometry(1.5, 0.22, 2), mattressMat);
mattress.name = 'mattress';
mattress.position.set(0, 0.41, 0);
root.add(mattress);
const blanket = new THREE.Mesh(new THREE.BoxGeometry(1.55, 0.21, 1.42), blanketMat);
blanket.name = 'blanket';
blanket.position.set(0, 0.44, 0.31);
root.add(blanket);
const sheetFold = new THREE.Mesh(new THREE.BoxGeometry(1.56, 0.035, 0.12), sheetMat);
sheetFold.name = 'sheetFold';
sheetFold.position.set(0, 0.5495, -0.35);
root.add(sheetFold);
const blanketStripe = new THREE.Mesh(new THREE.BoxGeometry(1.556, 0.212, 0.08), blanketDarkMat);
blanketStripe.name = 'blanketStripe';
blanketStripe.position.set(0, 0.442, 0.77);
root.add(blanketStripe);
const pillow = new THREE.Mesh(extrudeGeo, sheetMat);
pillow.name = 'pillow';
pillow.position.set(-0.36, 0.575, -0.73);
pillow.rotation.set(deg(-78), 0, 0);
root.add(pillow);
const pillow2 = new THREE.Mesh(extrudeGeo, sheetMat);
pillow2.name = 'pillow';
pillow2.position.set(0.36, 0.575, -0.73);
pillow2.rotation.set(deg(-78), 0, 0);
root.add(pillow2);
root.traverse((o) => {
if (o.isMesh) {
o.castShadow = true;
o.receiveShadow = true;
}
});
return root;
}
export default createBed;
Оценки и комментарии
0 комментариев
Комментариев пока нет. Расскажите, как вы использовали эту модель или что можно улучшить.
Похожие модели
Та же категория или похожие теги









