Prompt specification
Build or customize the Three.js 3D scene "Insulated crate layer section" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Insulated crate layer section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/insulated-crate-layer-section-x1041
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows an insulated produce crate. Model a produce crate with inner tray, insulation layer, and outer shell; include a symbolic temperature tag while keeping the layered construction easy to inspect. Voxel style.
Working Three.js Starter (insulated-crate-layer-section-x1041):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Insulated Produce Crate — Voxel Study</title>
<style>
:root {
--ink: #17343a;
--muted: #6c7e7d;
--paper: rgba(250, 252, 248, 0.88);
--line: rgba(31, 73, 76, 0.14);
--teal: #246f72;
--foam: #e9d88a;
--tray: #d96f4b;
--cyan: #41c7d4;
--green: #76a967;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 35% 35%, #f8faf6 0%, #e8efeb 45%, #dce6e2 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#app {
position: relative;
width: 100%;
height: 100%;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hero {
position: absolute;
z-index: 4;
top: 30px;
left: 34px;
max-width: 470px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: #52706f;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.pulse {
width: 7px;
height: 7px;
border-radius: 50%;
background: #4fb75f;
box-shadow: 0 0 0 4px rgba(79, 183, 95, 0.13);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 800;
}
.hero p {
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
position: absolute;
z-index: 6;
top: 26px;
right: 26px;
width: 306px;
max-height: calc(100vh - 52px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.74);
border-radius: 22px;
background: var(--paper);
box-shadow:
0 18px 50px rgba(35, 62, 59, 0.13),
inset 0 0 0 1px var(--line);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.panel::-webkit-scrollbar { width: 5px; }
.panel::-webkit-scrollbar-thumb {
background: rgba(35, 72, 73, 0.18);
border-radius: 8px;
}
.panel-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.panel-title {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.text-button {
border: 0;
padding: 4px 0;
color: #5c7675;
background: transparent;
cursor: pointer;
font-size: 11px;
font-weight: 700;
}
.text-button:hover { color: var(--teal); }
.explode-button {
width: 100%;
display: grid;
grid-template-columns: 30px 1fr auto;
align-items: center;
gap: 10px;
min-height: 52px;
padding: 8px 12px;
color: var(--ink);
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.65);
cursor: pointer;
text-align: left;
transition: 160ms ease;
}
.explode-button:hover {
border-color: rgba(36, 111, 114, 0.35);
transform: translateY(-1px);
}
.explode-button[aria-pressed="true"] {
color: white;
border-color: var(--teal);
background: var(--teal);
box-shadow: 0 8px 18px rgba(36, 111, 114, 0.2);
}
.explode-icon {
width: 28px;
height: 28px;
display: grid;
place-items: center;
border-radius: 8px;
color: var(--teal);
background: #e5efec;
font-size: 18px;
font-weight: 800;
}
.explode-button[aria-pressed="true"] .explode-icon {
color: white;
background: rgba(255, 255, 255, 0.16);
}
.button-copy strong {
display: block;
font-size: 12px;
font-weight: 800;
}
.button-copy small {
display: block;
margin-top: 2px;
opacity: 0.62;
font-size: 10px;
}
kbd {
min-width: 23px;
padding: 4px 6px;
border: 1px solid rgba(30, 63, 65, 0.16);
border-bottom-width: 2px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.65);
font-family: inherit;
font-size: 9px;
text-align: center;
}
.explode-button[aria-pressed="true"] kbd {
border-color: rgba(255, 255, 255, 0.24);
background: rgba(255, 255, 255, 0.12);
}
.range-wrap {
display: flex;
align-items: center;
gap: 10px;
padding: 11px 3px 15px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
flex: 1;
height: 4px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--teal) 0%,
var(--teal) var(--value, 0%),
#dbe4e1 var(--value, 0%),
#dbe4e1 100%
);
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--teal);
box-shadow: 0 1px 5px rgba(23, 52, 58, 0.25);
cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
width: 9px;
height: 9px;
border: 3px solid white;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 1px 5px rgba(23, 52, 58, 0.25);
cursor: pointer;
}
.section-label {
margin: 4px 0 8px;
color: #71817f;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.layer-list {
display: grid;
gap: 6px;
}
.layer-button {
width: 100%;
display: grid;
grid-template-columns: 13px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 9px;
border: 1px solid transparent;
border-radius: 11px;
color: var(--ink);
background: transparent;
cursor: pointer;
text-align: left;
transition: 150ms ease;
}
.layer-button:hover {
background: rgba(255, 255, 255, 0.7);
border-color: var(--line);
}
.layer-button[aria-pressed="true"] {
background: white;
border-color: rgba(36, 111, 114, 0.28);
box-shadow: 0 4px 14px rgba(41, 70, 68, 0.07);
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.shell { background: var(--teal); }
.swatch.foam { background: var(--foam); }
.swatch.tray { background: var(--tray); }
.layer-button strong {
display: block;
font-size: 11px;
font-weight: 800;
}
.layer-button small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.layer-number {
color: #9aa8a5;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.temperature {
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 10px;
margin-top: 15px;
padding: 12px;
border: 1px solid rgba(65, 199, 212, 0.22);
border-radius: 14px;
background: linear-gradient(135deg, rgba(230, 249, 249, 0.9), rgba(255, 255, 255, 0.7));
}
.snowflake {
width: 36px;
height: 36px;
display: grid;
place-items: center;
border-radius: 10px;
color: #159aa7;
background: rgba(65, 199, 212, 0.13);
font-size: 24px;
}
.temperature strong {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 17px;
letter-spacing: -0.04em;
}
.temperature small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.stable {
padding: 5px 7px;
border-radius: 99px;
color: #3e8548;
background: rgba(100, 171, 100, 0.13);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.08em;
}
.focus-status {
min-height: 14px;
margin: 9px 2px 0;
color: #8a9895;
font-size: 9px;
text-align: center;
}
#leaders {
position: absolute;
z-index: 3;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
}
#leaders line {
stroke-width: 1;
stroke-dasharray: 3 4;
opacity: 0;
transition: opacity 160ms ease;
}
.scene-label {
position: absolute;
z-index: 4;
top: 0;
left: 0;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-left: 3px solid var(--teal);
border-radius: 7px;
background: rgba(250, 252, 248, 0.88);
box-shadow: 0 6px 18px rgba(27, 58, 57, 0.12);
pointer-events: none;
opacity: 0;
transition: opacity 160ms ease;
white-space: nowrap;
}
.scene-label strong {
display: block;
color: var(--ink);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
}
#label-foam { border-left-color: var(--foam); }
#label-tray { border-left-color: var(--tray); }
.hint {
position: absolute;
z-index: 4;
left: 34px;
bottom: 28px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 10px;
color: #617674;
background: rgba(250, 252, 248, 0.72);
backdrop-filter: blur(10px);
pointer-events: none;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
}
.hint b {
color: var(--teal);
font-weight: 900;
}
.corner-note {
position: absolute;
z-index: 4;
right: 30px;
bottom: 28px;
color: rgba(31, 69, 71, 0.46);
pointer-events: none;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
.hero p { display: none; }
.eyebrow { font-size: 8px; }
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 39vh;
padding: 13px;
border-radius: 17px;
}
.panel-head,
.section-label,
.focus-status { display: none; }
.explode-button { min-height: 44px; }
.range-wrap { padding-bottom: 10px; }
.layer-list {
grid-template-columns: repeat(3, 1fr);
gap: 4px;
}
.layer-button {
grid-template-columns: 10px 1fr;
gap: 6px;
padding: 8px 6px;
}
.layer-button small,
.layer-number { display: none; }
.temperature {
margin-top: 8px;
padding: 8px 10px;
}
.hint {
display: none;
}
.corner-note {
right: 16px;
bottom: calc(39vh + 24px);
font-size: 7px;
}
}
</style>
</head>
<body>
<main id="app">
<canvas id="scene" aria-label="Interactive voxel model of an insulated produce crate"></canvas>
<header class="hero">
<div class="eyebrow"><span class="pulse"></span>Cold-chain module / 04</div>
<h1>Insulated<br />produce crate</h1>
<p>Three-layer thermal packaging, opened for inspection.</p>
</header>
<aside class="panel" aria-label="Crate controls">
<div class="panel-head">
<span class="panel-title">Assembly</span>
<button class="text-button" id="reset" type="button">Reset view</button>
</div>
<button class="explode-button" id="explode" type="button" aria-pressed="false">
<span class="explode-icon">↔</span>
<span class="button-copy">
<strong>Exploded view</strong>
<small>Separate the thermal envelope</small>
</span>
<kbd>E</kbd>
</button>
<div class="range-wrap">
<span>0</span>
<input id="explode-range" type="range" min="0" max="100" value="0"
aria-label="Exploded view amount" />
<span>100</span>
</div>
<div class="section-label">Select a construction layer</div>
<div class="layer-list">
<button class="layer-button" data-layer="shell" type="button" aria-pressed="false">
<span class="swatch shell"></span>
<span>
<strong>Outer shell</strong>
<small>Impact-resistant polymer skin</small>
</span>
<span class="layer-number">01</span>
</button>
<button class="layer-button" data-layer="foam" type="button" aria-pressed="false">
<span class="swatch foam"></span>
<span>
<strong>Insulation</strong>
<small>Segmented thermal core</small>
</span>
<span class="layer-number">02</span>
</button>
<button class="layer-button" data-layer="tray" type="button" aria-pressed="false">
<span class="swatch tray"></span>
<span>
<strong>Inner tray</strong>
<small>Washable compartment liner</small>
</span>
<span class="layer-number">03</span>
</button>
</div>
<div class="temperature">
<div class="snowflake">❄</div>
<div>
<strong>4°C</strong>
<small>Target hold temperature</small>
</div>
<div class="stable">STABLE</div>
</div>
<div class="focus-status" id="focus-status" aria-live="polite">All layers visible</div>
</aside>
<svg id="leaders" aria-hidden="true">
<line id="line-shell"></line>
<line id="line-foam"></line>
<line id="line-tray"></line>
</svg>
<div class="scene-label" id="label-shell">
<strong>01 / Outer shell</strong>
<small>Protective structure</small>
</div>
<div class="scene-label" id="label-foam">
<strong>02 / Insulation</strong>
<small>Thermal barrier</small>
</div>
<div class="scene-label" id="label-tray">
<strong>03 / Inner tray</strong>
<small>Produce compartments</small>
</div>
<div class="hint"><b>DRAG</b> rotate <span>·</span> <b>SCROLL</b> zoom <span>·</span> <b>CLICK</b> inspect</div>
<div class="corner-note">Voxel study / thermal envelope</div>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0xe8efeb, 0);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe4ece8, 24, 48);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const controls = {
target: new THREE.Vector3(0.65, 0.95, 0),
yaw: 0.66,
pitch: 0.62,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xf8fff8, 0x78908a, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff8df, 3.1);
keyLight.position.set(8, 13, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 38;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8ddce3, 1.25);
rimLight.position.set(-8, 7, -8);
scene.add(rimLight);
const fillLight = new THREE.DirectionalLight(0xffffff, 0.7);
fillLight.position.set(-5, 4, 8);
scene.add(fillLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
const materials = {
shell: standard(0x246f72),
shellLight: standard(0x3f8585),
shellDark: standard(0x174f55),
foam: standard(0xe7d77d),
foamLight: standard(0xf2e7a6),
foamDark: standard(0xcdb95f),
tray: standard(0xd66d49),
trayLight: standard(0xed8b61),
trayDark: standard(0xa94f39),
carrot: standard(0xf39a28),
carrotLight: standard(0xffb13e),
green: standard(0x57984c),
greenLight: standard(0x79b85f),
greenDark: standard(0x37733f),
tomato: standard(0xdc4f43),
tomatoLight: standard(0xf06a54),
potato: standard(0xc9a56d),
potatoLight: standard(0xe1c28d),
rivet: standard(0xbad7d3, { metalness: 0.18, roughness: 0.55 })
};
const layerMaterials = {
shell: [
materials.shell,
materials.shellLight,
materials.shellDark,
materials.rivet
],
foam: [
materials.foam,
materials.foamLight,
materials.foamDark
],
tray: [
materials.tray,
materials.trayLight,
materials.trayDark
],
produce: [
materials.carrot,
materials.carrotLight,
materials.green,
materials.greenLight,
materials.greenDark,
materials.tomato,
materials.tomatoLight,
materials.potato,
materials.potatoLight
]
};
const pickMeshes = [];
function addBox(parent, size, position, material, layer) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.layer = layer;
parent.add(mesh);
pickMeshes.push(mesh);
return mesh;
}
function makeGroup(parent, name) {
const group = new THREE.Group();
group.name = name;
parent.add(group);
return group;
}
const crate = makeGroup(scene, "Insulated produce crate");
const outerShell = makeGroup(crate, "01 Outer shell");
const insulation = makeGroup(crate, "02 Insulation");
const innerTray = makeGroup(crate, "03 Inner tray");
const produce = makeGroup(crate, "Mixed produce");
// -------------------------------------------------------------------
// Outer shell: segmented voxel panels with open front for inspection.
// -------------------------------------------------------------------
const outerBase = makeGroup(outerShell, "Outer base");
const outerBack = makeGroup(outerShell, "Outer back");
const outerFront = makeGroup(outerShell, "Outer front");
const outerLeft = makeGroup(outerShell, "Outer left");
const outerRight = makeGroup(outerShell, "Outer right");
outerBase.position.set(0, 0, 0);
outerBack.position.set(0, 0, -2.66);
outerFront.position.set(0, 0, 2.66);
outerLeft.position.set(-3.63, 0, 0);
outerRight.position.set(3.63, 0, 0);
for (let i = 0; i < 8; i++) {
addBox(
outerBase,
[0.88, 0.34, 5.34],
[-3.36 + i * 0.96, 0.17, 0],
i % 3 === 0 ? materials.shellLight : materials.shell,
"shell"
);
}
// Feet keep the voxel crate grounded.
for (const x of [-2.7, 0, 2.7]) {
for (const z of [-2.15, 2.15]) {
addBox(
outerBase,
[0.52, 0.38, 0.52],
[x, -0.19, z],
materials.shellDark,
"shell"
);
}
}
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 8; col++) {
addBox(
outerBack,
[0.88, 0.48, 0.34],
[-3.36 + col * 0.96, 0.47 + row * 0.56, 0],
(row + col) % 4 === 0 ? materials.shellLight : materials.shell,
"shell"
);
}
}
for (let col = 0; col < 8; col++) {
addBox(
outerFront,
[0.88, 0.78, 0.34],
[-3.36 + col * 0.96, 0.58, 0],
col % 3 === 1 ? materials.shellLight : materials.shell,
"shell"
);
}
for (const side of [outerLeft, outerRight]) {
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 6; col++) {
addBox(
side,
[0.34, 0.48, 0.86],
[0, 0.47 + row * 0.56, -2.38 + col * 0.95],
(row + col) % 4 === 1 ? materials.shellLight : materials.shell,
"shell"
);
}
}
}
// Four independently exploding corner posts.
const cornerPosts = [];
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const corner = makeGroup(outerShell, "Voxel corner post");
corner.position.set(sx * 3.58, 0, sz * 2.57);
addBox(
corner,
[0.43, 3.08, 0.43],
[0, 1.49, 0],
materials.shellDark,
"shell"
);
addBox(
corner,
[0.49, 0.18, 0.49],
[0, 3.02, 0],
materials.shellLight,
"shell"
);
cornerPosts.push({
group: corner,
vector: new THREE.Vector3(sx * 1.72, 0, sz * 1.72)
});
}
}
// Physical temperature tag, including a pixel-style snowflake.
function createTagTexture() {
const tagCanvas = document.createElement("canvas");
tagCanvas.width = 512;
tagCanvas.height = 256;
const ctx = tagCanvas.getContext("2d");
ctx.fillStyle = "#f7f6ed";
ctx.fillRect(0, 0, 512, 256);
ctx.fillStyle = "#246f72";
ctx.fillRect(0, 0, 18, 256);
ctx.fillStyle = "#d7e7e3";
ctx.fillRect(18, 0, 5, 256);
ctx.strokeStyle = "#1bb0bd";
ctx.lineWidth = 15;
ctx.lineCap = "square";
const cx = 104;
const cy = 128;
const radius = 65;
for (let i = 0; i < 3; i++) {
const angle = (Math.PI / 3) * i;
const dx = Math.cos(angle) * radius;
const dy = Math.sin(angle) * radius;
ctx.beginPath();
ctx.moveTo(cx - dx, cy - dy);
ctx.lineTo(cx + dx, cy + dy);
ctx.stroke();
}
for (let i = 0; i < 6; i++) {
const angle = (Math.PI / 3) * i;
const dx = Math.cos(angle) * radius;
const dy = Math.sin(angle) * radius;
const bx = cx + dx * 0.68;
const by = cy + dy * 0.68;
ctx.beginPath();
ctx.moveTo(bx, by);
ctx.lineTo(bx + Math.cos(angle + 0.9) * 23, by + Math.sin(angle + 0.9) * 23);
ctx.moveTo(bx, by);
ctx.lineTo(bx + Math.cos(angle - 0.9) * 23, by + Math.sin(angle - 0.9) * 23);
ctx.stroke();
}
ctx.fillStyle = "#17343a";
ctx.font = "900 92px ui-monospace, monospace";
ctx.fillText("4°C", 190, 151);
ctx.fillStyle = "#70827f";
ctx.font = "800 28px sans-serif";
ctx.fillText("COLD HOLD", 194, 207);
const texture = new THREE.CanvasTexture(tagCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearMipmapLinearFilter;
return texture;
}
const tagGroup = makeGroup(outerFront, "Temperature tag");
tagGroup.position.set(0.15, 0.78, 0.27);
addBox(
tagGroup,
[2.68, 1.24, 0.12],
[0, 0, 0],
materials.shellLight,
"shell"
);
const tagMaterial = new THREE.MeshBasicMaterial({
map: createTagTexture(),
toneMapped: false
});
layerMaterials.shell.push(tagMaterial);
const tagFace = new THREE.Mesh(new THREE.PlaneGeometry(2.5, 1.13), tagMaterial);
tagFace.position.set(0, 0, 0.067);
tagFace.userData.layer = "shell";
tagGroup.add(tagFace);
pickMeshes.push(tagFace);
for (const x of [-1.18, 1.18]) {
addBox(
tagGroup,
[0.10, 0.10, 0.08],
[x, 0, 0.08],
materials.rivet,
"shell"
);
}
// -------------------------------------------------------------------
// Thermal insulation: individually segmented foam blocks.
// -------------------------------------------------------------------
const foamBottom = makeGroup(insulation, "Foam floor");
const foamBack = makeGroup(insulation, "Foam back");
const foamFront = makeGroup(insulation, "Foam front");
const foamLeft = makeGroup(insulation, "Foam left");
const foamRight = makeGroup(insulation, "Foam right");
foamBack.position.z = -2.30;
foamFront.position.z = 2.30;
foamLeft.position.x = -3.19;
foamRight.position.x = 3.19;
for (let ix = 0; ix < 8; ix++) {
for (let iz = 0; iz < 6; iz++) {
addBox(
foamBottom,
[0.86, 0.31, 0.63],
[-3.01 + ix * 0.86, 0.43, -1.72 + iz * 0.69],
(ix + iz) % 3 === 0 ? materials.foamLight : materials.foam,
"foam"
);
}
}
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 8; col++) {
addBox(
foamBack,
[0.86, 0.49, 0.31],
[-3.01 + col * 0.86, 0.67 + row * 0.56, 0],
(row + col) % 4 === 0 ? materials.foamLight : materials.foam,
"foam"
);
}
}
for (let col = 0; col < 8; col++) {
addBox(
foamFront,
[0.86, 0.62, 0.31],
[-3.01 + col * 0.86, 0.62, 0],
col % 3 === 0 ? materials.foamLight : materials.foam,
"foam"
);
}
for (const side of [foamLeft, foamRight]) {
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 5; col++) {
addBox(
side,
[0.31, 0.49, 0.82],
[0, 0.67 + row * 0.56, -1.72 + col * 0.86],
(row + col) % 3 === 1 ? materials.foamLight : materials.foam,
"foam"
);
}
}
}
// -------------------------------------------------------------------
// Inner tray: raised washable liner with four produce compartments.
// -------------------------------------------------------------------
addBox(
innerTray,
[6.12, 0.18, 4.12],
[0, 0.64, 0],
materials.trayDark,
"tray"
);
addBox(
innerTray,
[6.18, 0.66, 0.16],
[0, 1.05, -2.01],
materials.tray,
"tray"
);
addBox(
innerTray,
[6.18, 0.66, 0.16],
[0, 1.05, 2.01],
materials.tray,
"tray"
);
for (const x of [-3.03, 3.03]) {
addBox(
innerTray,
[0.16, 0.66, 4.02],
[x, 1.05, 0],
materials.tray,
"tray"
);
}
addBox(
innerTray,
[0.13, 0.61, 3.98],
[0, 1.02, 0],
materials.trayLight,
"tray"
);
addBox(
innerTray,
[5.96, 0.61, 0.13],
[0, 1.02, 0],
materials.trayLight,
"tray"
);
// Bright tray rim makes the construction easy to read.
for (const z of [-2.04, 2.04]) {
addBox(
innerTray,
[6.32, 0.10, 0.22],
[0, 1.39, z],
materials.trayLight,
"tray"
);
}
for (const x of [-3.07, 3.07]) {
addBox(
innerTray,
[0.22, 0.10, 4.05],
[x, 1.39, 0],
materials.trayLight,
"tray"
);
}
// -------------------------------------------------------------------
// Produce: block-built carrots, tomatoes, leafy greens and potatoes.
// -------------------------------------------------------------------
function addCarrot(x, z, index) {
const carrot = makeGroup(produce, "Voxel carrot");
carrot.position.set(x, 0, z);
carrot.rotation.y = (index - 2) * 0.09;
for (let s = 0; s < 4; s++) {
const width = 0.25 - s * 0.035;
addBox(
carrot,
[width, width, 0.35],
[0, 1.02, -0.17 + s * 0.33],
s === 0 ? materials.carrotLight : materials.carrot,
"produce"
);
}
for (const leafX of [-0.09, 0.09]) {
addBox(
carrot,
[0.12, 0.13, 0.31],
[leafX, 1.05, -0.56],
materials.green,
"produce"
);
}
addBox(
carrot,
[0.11, 0.13, 0.25],
[0, 1.06, -0.46],
materials.greenLight,
"produce"
);
}
for (let i = 0; i < 5; i++) {
addCarrot(-2.35 + i * 0.43, -1.12 + (i % 2) * 0.28, i);
}
const tomatoPositions = [
[0.92, -1.47],
[1.64, -1.40],
[2.31, -1.45],
[1.29, -0.76],
[2.00, -0.72]
];
tomatoPositions.forEach(([x, z], i) => {
addBox(
produce,
[0.59, 0.55, 0.59],
[x, 1.10, z],
i % 2 ? materials.tomato : materials.tomatoLight,
"produce"
);
addBox(
produce,
[0.24, 0.12, 0.24],
[x, 1.41, z],
materials.greenDark,
"produce"
);
});
const greens = [
[-2.24, 1.38, 1.00],
[-1.76, 1.48, 1.10],
[-1.25, 1.36, 1.03],
[-2.05, 1.86, 0.91],
[-1.52, 1.91, 0.98],
[-0.98, 1.72, 0.92]
];
greens.forEach(([x, y, z], i) => {
addBox(
produce,
[0.53, 0.45, 0.50],
[x, y, z],
i % 2 ? materials.green : materials.greenLight,
"produce"
);
});
const potatoes = [
[0.98, 1.31],
[1.65, 1.38],
[2.28, 1.30],
[1.20, 1.88],
[1.89, 1.87]
];
potatoes.forEach(([x, z], i) => {
addBox(
produce,
[0.53, 0.39, 0.49],
[x, 1.00, z],
i % 2 ? materials.potato : materials.potatoLight,
"produce"
);
});
// -------------------------------------------------------------------
// Ground and subtle grid.
// -------------------------------------------------------------------
const groundMaterial = standard(0xdde7e1, { roughness: 1 });
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(36, 36, 0xc4d1cc, 0xd2ddd8);
grid.position.y = -0.382;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// -------------------------------------------------------------------
// Exploded view and layer focus.
// -------------------------------------------------------------------
let explosion = 0;
let explosionTarget = 0;
let focusedLayer = null;
const explodeButton = document.querySelector("#explode");
const explodeRange = document.querySelector("#explode-range");
const focusStatus = document.querySelector("#focus-status");
const layerButtons = [...document.querySelectorAll(".layer-button")];
function updateExplosionUI() {
const active = explosionTarget > 0.5;
explodeButton.setAttribute("aria-pressed", String(active));
explodeRange.value = String(Math.round(explosionTarget * 100));
explodeRange.style.setProperty(
"--value",
`${Math.round(explosionTarget * 100)}%`
);
}
function toggleExplosion() {
explosionTarget = explosionTarget > 0.5 ? 0 : 1;
updateExplosionUI();
}
explodeButton.addEventListener("click", toggleExplosion);
explodeRange.addEventListener("input", (event) => {
explosionTarget = Number(event.target.value) / 100;
updateExplosionUI();
});
function setFocus(layer) {
focusedLayer = focusedLayer === layer ? null : layer;
for (const [key, mats] of Object.entries(layerMaterials)) {
for (const material of mats) {
let opacity = 1;
if (focusedLayer) {
if (key === focusedLayer) opacity = 1;
else if (key === "produce") opacity = 0.42;
else opacity = 0.14;
}
material.opacity = opacity;
material.transparent = opacity < 0.99;
material.depthWrite = opacity > 0.9;
material.needsUpdate = true;
if (material.emissive) {
material.emissive.setHex(
focusedLayer === key ? 0x143b3c : 0x000000
);
material.emissiveIntensity = focusedLayer === key ? 0.22 : 0;
}
}
}
layerButtons.forEach((button) => {
button.setAttribute(
"aria-pressed",
String(button.dataset.layer === focusedLayer)
);
});
if (!focusedLayer) {
focusStatus.textContent = "All layers visible";
} else {
const names = {
shell: "Outer shell isolated",
foam: "Thermal insulation isolated",
tray: "Inner tray isolated"
};
focusStatus.textContent = names[focusedLayer];
}
}
layerButtons.forEach((button) => {
button.addEventListener("click", () => setFocus(button.dataset.layer));
});
function applyExplosion(amount) {
outerBack.position.z = -2.66 - amount * 1.76;
outerFront.position.z = 2.66 + amount * 1.76;
outerLeft.position.x = -3.63 - amount * 1.76;
outerRight.position.x = 3.63 + amount * 1.76;
foamBack.position.z = -2.30 - amount * 1.00;
foamFront.position.z = 2.30 + amount * 1.00;
foamLeft.position.x = -3.19 - amount * 1.00;
foamRight.position.x = 3.19 + amount * 1.00;
foamBottom.position.y = -amount * 0.25;
for (const corner of cornerPosts) {
corner.group.position.x = corner.vector.x * amount;
corner.group.position.z = corner.vector.z * amount;
}
}
// -------------------------------------------------------------------
// Manual camera controls — no external controls addon.
// -------------------------------------------------------------------
function updateCamera() {
const distance = 20;
const horizontal = Math.cos(controls.pitch) * distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
}
function resetView() {
controls.yaw = 0.66;
controls.pitch = 0.62;
controls.zoom = 1;
explosionTarget = 0;
focusedLayer = null;
setFocus(null);
updateExplosionUI();
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.75
);
},
{ passive: false }
);
const pointers = new Map();
let dragPointer = null;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
let pinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
canvas.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
dragPointer = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragDistance = 0;
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
dragDistance = 100;
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const nextDistance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance > 0) {
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * (nextDistance / pinchDistance),
0.68,
1.75
);
}
pinchDistance = nextDistance;
return;
}
if (event.pointerId !== dragPointer) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.005,
0.24,
1.16
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
canvas.addEventListener("pointerup", (event) => {
const wasClick = pointers.size === 1 && dragDistance < 6;
pointers.delete(event.pointerId);
if (wasClick) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
const layer = hits[0].object.userData.layer;
if (layer === "produce") setFocus("tray");
else if (layer) setFocus(layer);
}
}
if (pointers.size === 0) dragPointer = null;
});
canvas.addEventListener("pointercancel", (event) => {
pointers.delete(event.pointerId);
dragPointer = null;
});
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "e") toggleExplosion();
if (event.key === "Escape") setFocus(null);
if (event.key.toLowerCase() === "r") resetView();
});
// -------------------------------------------------------------------
// Projected construction labels.
// -------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#label-shell"),
line: document.querySelector("#line-shell"),
anchor: () => outerRight.localToWorld(new THREE.Vector3(0, 2.15, -0.4)),
color: "#246f72",
offset: { x: 65, y: -32 }
},
{
element: document.querySelector("#label-foam"),
line: document.querySelector("#line-foam"),
anchor: () => foamRight.localToWorld(new THREE.Vector3(0, 2.28, -1.0)),
color: "#b69d47",
offset: { x: 82, y: -68 }
},
{
element: document.querySelector("#label-tray"),
line: document.querySelector("#line-tray"),
anchor: () => innerTray.localToWorld(new THREE.Vector3(2.65, 1.35, 1.45)),
color: "#d66d49",
offset: { x: 62, y: 42 }
}
];
function updateLabels() {
const width = app.clientWidth;
const height = app.clientHeight;
const visible = explosion > 0.16;
for (const label of labelDefinitions) {
if (!visible) {
label.element.style.opacity = "0";
label.line.style.opacity = "0";
continue;
}
const projected = label.anchor().project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const lx = x + label.offset.x;
const ly = y + label.offset.y;
label.element.style.opacity = "1";
label.element.style.transform =
`translate(${lx}px, ${ly}px) translate(-50%, -50%)`;
label.line.setAttribute("x1", x);
label.line.setAttribute("y1", y);
label.line.setAttribute("x2", lx);
label.line.setAttribute("y2", ly);
label.line.setAttribute("stroke", label.color);
label.line.style.opacity = "0.72";
}
}
// -------------------------------------------------------------------
// Responsive renderer.
// -------------------------------------------------------------------
function resize() {
const width = app.clientWidth;
const height = app.clientHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
const halfHeight = Math.max(5.25, 7.25 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
const leaders = document.querySelector("#leaders");
leaders.setAttribute("viewBox", `0 0 ${width} ${height}`);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Initial material state.
setFocus(null);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
explosion = THREE.MathUtils.damp(
explosion,
explosionTarget,
7.5,
dt
);
applyExplosion(explosion);
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```