Prompt specification
Build or customize the Three.js 3D scene "Ripening observation tray" 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: Ripening observation tray
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/ripening-observation-tray-x0114
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: ripening observation tray. Place fruit samples beside dated cards and a time slider; show gradual color and firmness indicators as an illustrative biological process rather than guaranteed storage guidance. Return one self-contained HTML file.
Working Three.js Starter (ripening-observation-tray-x0114):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Ripening Observation Tray</title>
<style>
:root {
--ink: #263b37;
--muted: #65736f;
--accent: #2f8378;
--accent-dark: #225f58;
--warm: #e79a52;
--paper: rgba(249, 246, 238, 0.92);
--line: rgba(49, 77, 70, 0.15);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e3d8;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
.topbar {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
max-width: 620px;
padding: 15px 18px 14px;
border: 1px solid var(--line);
border-radius: 18px;
background: rgba(249, 246, 238, 0.78);
box-shadow: 0 12px 35px rgba(63, 67, 57, 0.08);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 5px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.3vw, 34px);
line-height: 1.04;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.badge, .view-button {
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 10px 28px rgba(63, 67, 57, 0.08);
backdrop-filter: blur(14px);
}
.badge {
padding: 11px 14px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.badge::before {
content: "";
display: inline-block;
width: 7px;
height: 7px;
margin-right: 8px;
border-radius: 50%;
background: var(--warm);
box-shadow: 0 0 0 4px rgba(231, 154, 82, 0.14);
}
.view-button {
padding: 10px 13px;
font-size: 11px;
font-weight: 700;
}
.view-button:hover { background: #fffdf7; }
.inspector {
position: fixed;
z-index: 5;
top: 132px;
right: 28px;
width: 260px;
padding: 16px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 15px 40px rgba(63, 67, 57, 0.1);
backdrop-filter: blur(16px);
}
.inspector-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
}
.cycle-button {
width: 25px;
height: 25px;
padding: 0;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.45);
color: var(--accent-dark);
font-size: 15px;
line-height: 1;
}
.sample-title {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
}
.sample-swatch {
width: 32px;
height: 32px;
flex: 0 0 auto;
border: 4px solid rgba(255,255,255,0.72);
border-radius: 10px;
background: #91aa4f;
box-shadow: 0 0 0 1px var(--line);
transition: background 160ms ease;
}
.sample-title strong {
display: block;
font-size: 14px;
letter-spacing: -0.02em;
}
.sample-title small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.08em;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.metric {
padding: 10px;
border: 1px solid rgba(49, 77, 70, 0.1);
border-radius: 11px;
background: rgba(255, 255, 255, 0.36);
}
.metric span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
}
.metric strong {
display: block;
margin: 4px 0 7px;
font-size: 18px;
letter-spacing: -0.04em;
}
.meter {
height: 5px;
overflow: hidden;
border-radius: 99px;
background: #dcd8cd;
}
.meter i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 120ms linear;
}
#colorBar { background: var(--warm); }
.stage-pill {
display: inline-block;
margin-top: 13px;
padding: 6px 9px;
border-radius: 999px;
background: rgba(47, 131, 120, 0.1);
color: var(--accent-dark);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.inspector p {
margin: 9px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.timeline {
position: fixed;
z-index: 6;
left: 50%;
bottom: 22px;
width: min(900px, calc(100% - 48px));
transform: translateX(-50%);
padding: 15px 17px 12px;
border: 1px solid var(--line);
border-radius: 20px;
background: rgba(249, 246, 238, 0.94);
box-shadow: 0 18px 50px rgba(63, 67, 57, 0.15);
backdrop-filter: blur(18px);
}
.timeline-main {
display: grid;
grid-template-columns: 145px 1fr auto;
align-items: center;
gap: 20px;
}
.date-block span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
}
.date-block strong {
display: block;
margin: 3px 0 2px;
font-size: 22px;
line-height: 1;
letter-spacing: -0.04em;
}
.date-block small {
color: var(--accent-dark);
font-size: 9px;
font-weight: 700;
}
.slider-block { min-width: 0; }
.slider-labels {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: var(--muted);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
}
input[type="range"] {
--pct: 45.7%;
width: 100%;
height: 8px;
margin: 0;
appearance: none;
-webkit-appearance: none;
border: 0;
border-radius: 999px;
outline: none;
background: linear-gradient(
90deg,
var(--accent) 0%,
var(--accent) var(--pct),
#d8d4c8 var(--pct),
#d8d4c8 100%
);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 22px;
height: 22px;
appearance: none;
-webkit-appearance: none;
border: 4px solid #f8f4eb;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 9px rgba(30, 67, 61, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
border: 4px solid #f8f4eb;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 2px 9px rgba(30, 67, 61, 0.3);
}
.transport {
display: flex;
gap: 7px;
}
.transport button {
height: 38px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255,255,255,0.52);
font-size: 11px;
font-weight: 750;
}
.transport #playButton {
min-width: 79px;
border-color: transparent;
background: var(--accent);
color: white;
}
.transport button:hover { filter: brightness(0.97); }
.timeline-note {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(49, 77, 70, 0.1);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
text-align: center;
}
.timeline-note strong { color: var(--ink); }
.hint {
position: fixed;
z-index: 4;
left: 28px;
bottom: 145px;
color: rgba(38, 59, 55, 0.62);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.fallback {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
padding: 30px;
background: #e9e3d8;
text-align: center;
}
.fallback[hidden] { display: none; }
@media (max-width: 760px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand {
padding: 12px 14px;
border-radius: 15px;
}
.subtitle { display: none; }
.badge { display: none; }
.view-button {
padding: 9px 11px;
white-space: nowrap;
}
.inspector {
top: 92px;
right: 14px;
width: 218px;
padding: 12px;
border-radius: 15px;
}
.inspector p { display: none; }
.sample-title { margin-bottom: 10px; }
.metric { padding: 8px; }
.timeline {
bottom: 12px;
width: calc(100% - 24px);
padding: 13px;
}
.timeline-main {
grid-template-columns: 1fr auto;
gap: 12px;
}
.slider-block {
grid-column: 1 / -1;
grid-row: 2;
}
.date-block strong { font-size: 19px; }
.hint { display: none; }
}
@media (max-width: 430px) {
.inspector {
top: auto;
right: 14px;
bottom: 178px;
width: 190px;
}
.inspector-head,
.sample-title,
.stage-pill { display: none; }
.metric-grid { gap: 7px; }
.metric strong { font-size: 15px; }
.timeline-note { font-size: 8px; }
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel observation tray. Drag to orbit, scroll to zoom, and click a fruit or card to select it."
></canvas>
<header class="topbar">
<div class="brand">
<p class="eyebrow">Voxel Biology / Observation 04</p>
<h1>Ripening observation tray</h1>
<p class="subtitle">
Follow stylized color development and loss of firmness across dated fruit samples.
</p>
</div>
<div class="top-actions">
<div class="badge">Illustrative biology</div>
<button class="view-button" id="resetView" type="button">Reset view</button>
</div>
</header>
<aside class="inspector" aria-live="polite">
<div class="inspector-head">
<span>Selected sample</span>
<button class="cycle-button" id="nextSample" type="button" title="Select next sample">↻</button>
</div>
<div class="sample-title">
<span class="sample-swatch" id="sampleSwatch"></span>
<div>
<strong id="sampleName">Gala apple</strong>
<small id="sampleCode">SAMPLE A-02</small>
</div>
</div>
<div class="metric-grid">
<div class="metric">
<span>COLOR CUE</span>
<strong id="colorValue">0%</strong>
<div class="meter"><i id="colorBar"></i></div>
</div>
<div class="metric">
<span>FIRMNESS CUE</span>
<strong id="firmnessValue">0%</strong>
<div class="meter"><i id="firmnessBar"></i></div>
</div>
</div>
<span class="stage-pill" id="stagePill">Early stage</span>
<p id="stageCopy">The modeled sample is still firm and its color change is minimal.</p>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Click a sample</div>
<section class="timeline" aria-label="Observation time controls">
<div class="timeline-main">
<div class="date-block">
<span>OBSERVATION DATE</span>
<strong id="dateLabel">15 JUN</strong>
<small id="dayLabel">ELAPSED DAY 3.2</small>
</div>
<div class="slider-block">
<div class="slider-labels">
<span>DAY 0</span>
<span>TIME SLIDER</span>
<span>DAY 7</span>
</div>
<input
id="timeSlider"
type="range"
min="0"
max="7"
step="0.01"
value="3.2"
aria-label="Elapsed observation day"
/>
</div>
<div class="transport">
<button id="playButton" type="button" aria-pressed="false">▶ Play</button>
<button id="resetDay" type="button" title="Return to day zero">Day 0</button>
</div>
</div>
<div class="timeline-note">
<strong>Illustrative process, not storage guidance.</strong>
Color and firmness cues do not guarantee ripeness, safety, shelf life, or storage needs.
</div>
</section>
<div class="fallback" id="fallback" hidden>
<div>
<h1>WebGL is required</h1>
<p>This observation tray needs a browser with WebGL enabled.</p>
</div>
</div>
<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.getElementById("scene");
const fallback = document.getElementById("fallback");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
} catch (error) {
fallback.hidden = false;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e3d8);
scene.fog = new THREE.Fog(0xe9e3d8, 24, 43);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const controls = {
radius: window.innerWidth < 700 ? 23 : 19.5,
theta: 0.28,
phi: 1.02,
target: new THREE.Vector3(0, 0.9, 0.35)
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x66756c, 1.55);
scene.add(hemi);
const ambient = new THREE.AmbientLight(0xffffff, 0.32);
scene.add(ambient);
const key = new THREE.DirectionalLight(0xfff0d5, 2.75);
key.position.set(-7, 13, 9);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -11;
key.shadow.camera.right = 11;
key.shadow.camera.top = 11;
key.shadow.camera.bottom = -11;
key.shadow.camera.near = 1;
key.shadow.camera.far = 35;
key.shadow.bias = -0.00035;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc7e0e3, 0.85);
fill.position.set(9, 7, -8);
scene.add(fill);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e3d8,
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(120, 120),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.07;
ground.receiveShadow = true;
scene.add(ground);
const trayMaterial = new THREE.MeshStandardMaterial({
color: 0x4e7469,
roughness: 0.76
});
const trayEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x35594f,
roughness: 0.72
});
const linerMaterial = new THREE.MeshStandardMaterial({
color: 0xe6ddc9,
roughness: 0.96
});
function box(width, height, depth, material, x, y, z, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Observation tray.
box(12.8, 0.34, 5.6, trayMaterial, 0, 0.11, 0);
box(12.8, 0.42, 0.18, trayEdgeMaterial, 0, 0.43, 2.7);
box(12.8, 0.42, 0.18, trayEdgeMaterial, 0, 0.43, -2.7);
box(0.18, 0.42, 5.4, trayEdgeMaterial, -6.3, 0.43, 0);
box(0.18, 0.42, 5.4, trayEdgeMaterial, 6.3, 0.43, 0);
for (const x of [-3, 0, 3]) {
box(0.12, 0.34, 5.15, trayEdgeMaterial, x, 0.39, 0);
}
for (const x of [-4.65, -1.55, 1.55, 4.65]) {
box(2.55, 0.045, 3.2, linerMaterial, x, 0.305, 0.08, false);
}
// Front plaque.
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 128;
const plaqueCtx = plaqueCanvas.getContext("2d");
plaqueCtx.fillStyle = "#35594f";
plaqueCtx.fillRect(0, 0, 1024, 128);
plaqueCtx.fillStyle = "#e8dfca";
plaqueCtx.textAlign = "center";
plaqueCtx.textBaseline = "middle";
plaqueCtx.font = "700 39px system-ui, sans-serif";
plaqueCtx.fillText("RIPENING OBSERVATION TRAY · MODEL 04", 512, 67);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(5.6, 0.7),
new THREE.MeshBasicMaterial({
map: plaqueTexture,
toneMapped: false
})
);
plaque.position.set(0, 0.43, 2.801);
scene.add(plaque);
// A physical voxel time rail mirrors the HTML slider.
const timeRailMaterial = new THREE.MeshStandardMaterial({
color: 0x405f56,
roughness: 0.8
});
box(6.5, 0.16, 0.78, timeRailMaterial, 0, 0.08, 3.28);
const timeTicks = [];
for (let i = 0; i <= 7; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0xaab8ae,
roughness: 0.82
});
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.16, 0.16, 0.22),
material
);
tick.position.set(-2.8 + i * 0.8, 0.22, 3.28);
tick.castShadow = true;
scene.add(tick);
timeTicks.push(tick);
}
const timeKnob = new THREE.Mesh(
new THREE.BoxGeometry(0.29, 0.29, 0.38),
new THREE.MeshStandardMaterial({
color: 0xe79a52,
roughness: 0.55,
emissive: 0x5d2f0e,
emissiveIntensity: 0.08
})
);
timeKnob.position.set(0, 0.37, 3.28);
timeKnob.castShadow = true;
scene.add(timeKnob);
const samples = [
{
code: "A-01",
name: "Emma apple",
kind: "APPLE",
cellX: -4.65,
rate: 0.92,
firmStart: 0.96,
firmnessDrop: 0.52,
path: ["#87a84b", "#dfc64b", "#d6643e"]
},
{
code: "A-02",
name: "Gala apple",
kind: "APPLE",
cellX: -1.55,
rate: 1.0,
firmStart: 0.91,
firmnessDrop: 0.57,
path: ["#77974a", "#e4b645", "#d84b42"]
},
{
code: "P-03",
name: "Conference pear",
kind: "PEAR",
cellX: 1.55,
rate: 0.87,
firmStart: 0.94,
firmnessDrop: 0.48,
path: ["#8aa94e", "#d2c44a", "#c69a43"]
},
{
code: "C-04",
name: "Citrus sample",
kind: "CITRUS",
cellX: 4.65,
rate: 0.78,
firmStart: 0.89,
firmnessDrop: 0.51,
path: ["#c8ad3e", "#ee9134", "#d96d2b"]
}
];
samples.forEach((sample) => {
sample.pathColors = sample.path.map((hex) => new THREE.Color(hex));
sample.stage = 0;
sample.firmness = sample.firmStart;
sample.color = new THREE.Color(sample.path[0]);
});
const voxelGeometry = new THREE.BoxGeometry(0.225, 0.225, 0.225);
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x6d4930,
roughness: 0.95
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x4f7c45,
roughness: 0.9
});
function createFruit(sample, index) {
const group = new THREE.Group();
group.position.set(sample.cellX - 0.55, 0.96, 0.48);
const shadeMaterials = [0.84, 0.96, 1.07].map((factor) => {
const material = new THREE.MeshStandardMaterial({
color: 0x87a84b,
roughness: 0.8,
metalness: 0
});
material.userData.factor = factor;
return material;
});
for (let y = -2; y <= 2; y++) {
for (let x = -2; x <= 2; x++) {
for (let z = -2; z <= 2; z++) {
let inside = false;
if (sample.kind === "APPLE") {
const radius =
(x * x) / 4.45 +
(z * z) / 4.05 +
(y * y) / 5.35;
inside = radius <= 1;
if (y === 2 && Math.abs(x) + Math.abs(z) > 2) inside = false;
if (y === -2 && Math.abs(x) + Math.abs(z) > 3) inside = false;
if (x === 0 && y === 2 && z === 0) inside = false;
} else if (sample.kind === "PEAR") {
const rx = y <= 0 ? 1.7 : 1.03 - Math.max(0, y - 1) * 0.35;
const rz = y <= 0 ? 1.55 : 0.94 - Math.max(0, y - 1) * 0.28;
inside =
(x * x) / (rx * rx) +
(z * z) / (rz * rz) <= 1;
if (y === 2) inside = false;
if (y === 1 && Math.abs(x) + Math.abs(z) > 2) inside = false;
} else {
const radius =
(x * x) / 4.25 +
(z * z) / 4.1 +
(y * y) / 4.7;
inside = radius <= 1;
if (Math.abs(y) === 2 && Math.abs(x) + Math.abs(z) > 3) inside = false;
}
if (!inside) continue;
const material =
shadeMaterials[
Math.abs(Math.floor(x + z + y)) % shadeMaterials.length
];
const voxel = new THREE.Mesh(voxelGeometry, material);
voxel.position.set(x * 0.225, y * 0.225, z * 0.225);
voxel.castShadow = true;
voxel.receiveShadow = true;
group.add(voxel);
}
}
}
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.32, 0.11),
stemMaterial
);
stem.position.set(0, 0.61, 0);
stem.castShadow = true;
group.add(stem);
const leaf = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.06, 0.16),
leafMaterial
);
leaf.position.set(0.19, 0.65, 0);
leaf.rotation.z = -0.24;
leaf.castShadow = true;
group.add(leaf);
const blushMaterial = new THREE.MeshStandardMaterial({
color: 0xbd3f39,
roughness: 0.86,
transparent: true,
opacity: 0
});
const blush = [];
if (sample.kind === "APPLE") {
const positions = [
[-0.30, 0.08, 0.42],
[0.18, 0.16, 0.43],
[0.36, -0.10, 0.31],
[-0.16, -0.23, 0.41],
[0.42, 0.20, 0.10]
];
for (const [x, y, z] of positions) {
const spot = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.13, 0.06),
blushMaterial
);
spot.position.set(x, y, z);
spot.castShadow = true;
group.add(spot);
blush.push(spot);
}
}
group.traverse((object) => {
object.userData.sampleIndex = index;
});
scene.add(group);
sample.fruit = { group, shadeMaterials, blushMaterial };
}
function createCard(sample, index) {
const group = new THREE.Group();
group.position.set(sample.cellX + 0.72, 1.0, -0.3);
group.rotation.x = -0.035;
const body = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 1.06, 0.08),
new THREE.MeshStandardMaterial({
color: 0xf5efe2,
roughness: 0.96
})
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const cardCanvas = document.createElement("canvas");
cardCanvas.width = 640;
cardCanvas.height = 420;
const ctx = cardCanvas.getContext("2d");
const texture = new THREE.CanvasTexture(cardCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 0.98),
new THREE.MeshBasicMaterial({
map: texture,
toneMapped: false
})
);
face.position.z = 0.047;
group.add(face);
const clip = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.11, 0.12),
new THREE.MeshStandardMaterial({
color: 0xc79b4e,
roughness: 0.45,
metalness: 0.25
})
);
clip.position.set(0, 0.55, 0.07);
clip.castShadow = true;
group.add(clip);
group.traverse((object) => {
object.userData.sampleIndex = index;
});
scene.add(group);
sample.card = { group, canvas: cardCanvas, ctx, texture };
}
samples.forEach((sample, index) => {
createFruit(sample, index);
createCard(sample, index);
});
// Voxel corner brackets show the selected fruit.
const selectionMaterial = new THREE.MeshStandardMaterial({
color: 0x2f8a7d,
emissive: 0x174c45,
emissiveIntensity: 0.45,
roughness: 0.45
});
const selectionMarker = new THREE.Group();
for (const x of [-0.66, 0.66]) {
for (const y of [-0.6, 0.6]) {
for (const z of [-0.53, 0.53]) {
const corner = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 0.08, 0.08),
selectionMaterial
);
corner.position.set(x, y, z);
selectionMarker.add(corner);
}
}
}
scene.add(selectionMarker);
const pickables = samples.flatMap((sample) => [
sample.fruit.group,
sample.card.group
]);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let selectedIndex = 1;
let day = Number(document.getElementById("timeSlider").value);
let playing = false;
const timeSlider = document.getElementById("timeSlider");
const playButton = document.getElementById("playButton");
const dateLabel = document.getElementById("dateLabel");
const dayLabel = document.getElementById("dayLabel");
const sampleName = document.getElementById("sampleName");
const sampleCode = document.getElementById("sampleCode");
const sampleSwatch = document.getElementById("sampleSwatch");
const colorValue = document.getElementById("colorValue");
const firmnessValue = document.getElementById("firmnessValue");
const colorBar = document.getElementById("colorBar");
const firmnessBar = document.getElementById("firmnessBar");
const stagePill = document.getElementById("stagePill");
const stageCopy = document.getElementById("stageCopy");
const clamp = THREE.MathUtils.clamp;
function formatDate(value) {
const date = new Date(Date.UTC(2025, 5, 12 + Math.floor(value)));
return date
.toLocaleDateString("en-GB", {
day: "2-digit",
month: "short",
timeZone: "UTC"
})
.toUpperCase();
}
function getSampleColor(sample, stage, target) {
if (stage <= 0.5) {
target.lerpColors(
sample.pathColors[0],
sample.pathColors[1],
stage * 2
);
} else {
target.lerpColors(
sample.pathColors[1],
sample.pathColors[2],
(stage - 0.5) * 2
);
}
return target;
}
function drawCard(sample, date) {
const ctx = sample.card.ctx;
const w = sample.card.canvas.width;
const h = sample.card.canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "#f7f1e4";
ctx.fillRect(0, 0, w, h);
ctx.save();
roundedRect(ctx, 12, 12, w - 24, h - 24, 18);
ctx.strokeStyle = "#d9cfbd";
ctx.lineWidth = 4;
ctx.stroke();
ctx.restore();
ctx.fillStyle = "#2f8378";
ctx.fillRect(12, 12, 15, h - 24);
ctx.fillStyle = "#728079";
ctx.font = "800 20px system-ui, sans-serif";
ctx.fillText("OBSERVATION / " + sample.code, 50, 49);
ctx.fillStyle = "#263b37";
ctx.font = "750 36px system-ui, sans-serif";
ctx.fillText(sample.name.toUpperCase(), 50, 92);
ctx.strokeStyle = "#d8cebd";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(50, 119);
ctx.lineTo(w - 43, 119);
ctx.stroke();
ctx.fillStyle = "#7a837e";
ctx.font = "800 18px system-ui, sans-serif";
ctx.fillText("CAPTURE DATE", 50, 158);
ctx.fillStyle = "#263b37";
ctx.font = "800 45px system-ui, sans-serif";
ctx.fillText(date, 50, 207);
ctx.fillStyle = "#2f8378";
ctx.font = "750 18px system-ui, sans-serif";
ctx.fillText("ELAPSED DAY " + day.toFixed(1), 50, 241);
const barX = 50;
const barW = w - 100;
ctx.fillStyle = "#7a837e";
ctx.font = "800 17px system-ui, sans-serif";
ctx.fillText("COLOR CUE", barX, 283);
ctx.fillStyle = "#ded6c7";
roundedRect(ctx, barX, 296, barW, 17, 8);
ctx.fill();
ctx.fillStyle = "#" + sample.color.getHexString();
roundedRect(
ctx,
barX,
296,
Math.max(6, barW * sample.stage),
17,
8
);
ctx.fill();
ctx.fillStyle = "#7a837e";
ctx.font = "800 17px system-ui, sans-serif";
ctx.fillText("FIRMNESS CUE", barX, 345);
ctx.fillStyle = "#ded6c7";
roundedRect(ctx, barX, 358, barW, 17, 8);
ctx.fill();
ctx.fillStyle = "#2f8378";
roundedRect(
ctx,
barX,
358,
Math.max(6, barW * sample.firmness),
17,
8
);
ctx.fill();
ctx.fillStyle = "#55645f";
ctx.font = "650 15px system-ui, sans-serif";
ctx.fillText(
Math.round(sample.stage * 100) + "%",
barX + barW - 46,
283
);
ctx.fillText(
Math.round(sample.firmness * 100) + "%",
barX + barW - 46,
345
);
sample.card.texture.needsUpdate = true;
}
function stageDescription(stage) {
if (stage < 0.25) {
return [
"Early stage",
"The modeled sample is still firm and its color change is minimal."
];
}
if (stage < 0.5) {
return [
"Color shifting",
"Color begins to change while the modeled firmness changes more slowly."
];
}
if (stage < 0.75) {
return [
"Softening",
"Color development is clear and the modeled tissue is beginning to soften."
];
}
return [
"Advanced ripeness",
"The sample shows advanced color change and reduced modeled firmness."
];
}
function updateSelected(sample) {
const [pill, copy] = stageDescription(sample.stage);
sampleName.textContent = sample.name;
sampleCode.textContent = "SAMPLE " + sample.code;
sampleSwatch.style.background = "#" + sample.color.getHexString();
colorValue.textContent = Math.round(sample.stage * 100) + "%";
firmnessValue.textContent = Math.round(sample.firmness * 100) + "%";
colorBar.style.width = Math.round(sample.stage * 100) + "%";
colorBar.style.background = "#" + sample.color.getHexString();
firmnessBar.style.width = Math.round(sample.firmness * 100) + "%";
stagePill.textContent = pill;
stageCopy.textContent = copy;
selectionMarker.position.set(
sample.fruit.group.position.x,
1.02,
sample.fruit.group.position.z
);
}
function updateScene() {
const date = formatDate(day);
for (const sample of samples) {
sample.stage = clamp((day / 7) * sample.rate, 0, 1);
sample.firmness = clamp(
sample.firmStart - sample.stage * sample.firmnessDrop,
0.25,
1
);
getSampleColor(sample, sample.stage, sample.color);
sample.shadeMaterials ??= [];
sample.fruit.shadeMaterials.forEach((material) => {
const factor = material.userData.factor;
material.color.setRGB(
sample.color.r * factor,
sample.color.g * factor,
sample.color.b * factor
);
});
if (sample.kind === "APPLE") {
sample.fruit.blushMaterial.opacity = clamp(
(sample.stage - 0.42) * 1.35,
0,
0.56
);
}
drawCard(sample, date);
}
const percentage = (day / 7) * 100;
timeSlider.value = day;
timeSlider.style.setProperty("--pct", percentage + "%");
timeSlider.setAttribute(
"aria-valuetext",
day.toFixed(1) + " elapsed days, " + date
);
dateLabel.textContent = date;
dayLabel.textContent = "ELAPSED DAY " + day.toFixed(1);
timeKnob.position.x = -2.8 + (day / 7) * 5.6;
timeTicks.forEach((tick, index) => {
const active = index <= day;
tick.material.color.set(active ? 0x3c9b88 : 0xaab8ae);
tick.material.emissive.set(active ? 0x174c45 : 0x000000);
tick.material.emissiveIntensity = active ? 0.18 : 0;
});
updateSelected(samples[selectedIndex]);
}
function setSelected(index) {
selectedIndex = (index + samples.length) % samples.length;
updateSelected(samples[selectedIndex]);
}
function pickSample(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object && object.userData.sampleIndex === undefined) {
object = object.parent;
}
return object ? object.userData.sampleIndex : null;
}
// Camera controls are implemented directly without external controls modules.
let dragging = false;
let dragMoved = 0;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = 0;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
dragMoved += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
controls.theta = clamp(controls.theta - dx * 0.005, -0.42, 1.02);
controls.phi = clamp(controls.phi + dy * 0.004, 0.67, 1.27);
updateCamera();
} else {
const hit = pickSample(event.clientX, event.clientY);
canvas.style.cursor = hit === null ? "grab" : "pointer";
}
});
canvas.addEventListener("pointerup", (event) => {
if (dragMoved < 6) {
const hit = pickSample(event.clientX, event.clientY);
if (hit !== null) setSelected(hit);
}
dragging = false;
canvas.style.cursor = "grab";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = clamp(
controls.radius + event.deltaY * 0.012,
13.5,
27
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta = clamp(controls.theta - 0.08, -0.42, 1.02);
break;
case "ArrowRight":
controls.theta = clamp(controls.theta + 0.08, -0.42, 1.02);
break;
case "ArrowUp":
controls.phi = clamp(controls.phi - 0.06, 0.67, 1.27);
break;
case "ArrowDown":
controls.phi = clamp(controls.phi + 0.06, 0.67, 1.27);
break;
case "+":
case "=":
controls.radius = clamp(controls.radius - 1, 13.5, 27);
break;
case "-":
controls.radius = clamp(controls.radius + 1, 13.5, 27);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
timeSlider.addEventListener("input", () => {
day = Number(timeSlider.value);
setPlaying(false);
updateScene();
});
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
playButton.setAttribute("aria-pressed", String(playing));
}
playButton.addEventListener("click", () => {
if (!playing && day >= 7) {
day = 0;
updateScene();
}
setPlaying(!playing);
});
document.getElementById("resetDay").addEventListener("click", () => {
day = 0;
setPlaying(false);
updateScene();
});
document.getElementById("nextSample").addEventListener("click", () => {
setSelected(selectedIndex + 1);
});
document.getElementById("resetView").addEventListener("click", () => {
controls.radius = window.innerWidth < 700 ? 23 : 19.5;
controls.theta = 0.28;
controls.phi = 1.02;
controls.target.set(0, 0.9, 0.35);
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width / height < 1 ? 52 : 38;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
resize();
updateScene();
let previousTime = performance.now();
let lastPlaybackUpdate = 0;
renderer.setAnimationLoop((now) => {
const delta = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing && now - lastPlaybackUpdate > 40) {
day = Math.min(7, day + delta * 0.45);
if (day >= 7) setPlaying(false);
updateScene();
lastPlaybackUpdate = now;
}
const pulse = 1 + Math.sin(now * 0.0025) * 0.012;
selectionMarker.scale.setScalar(pulse);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```