Prompt specification
Build or customize the Three.js 3D scene "Greengrocer shelf rotation" 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: Greengrocer shelf rotation
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/greengrocer-shelf-rotation-x0115
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring fruit ripening. Build a produce display with dated crates and separate ripe-fruit baskets; animate stock rotating forward so earlier arrivals remain visible before newly delivered produce. Stylized solid forms.
Working Three.js Starter (greengrocer-shelf-rotation-x0115):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Ripening Room — Fruit Delivery Display</title>
<style>
:root {
--ink: #26382d;
--muted: #6e766c;
--paper: #f6f0e4;
--paper-strong: #fffaf0;
--line: rgba(38, 56, 45, 0.16);
--green: #486649;
--gold: #c89b45;
--red: #c85d45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 13px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.brand-mark {
position: relative;
width: 43px;
height: 43px;
border: 2px solid var(--ink);
border-radius: 50%;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 50%;
background: var(--red);
}
.brand-mark::before {
width: 13px;
height: 13px;
left: 8px;
top: 8px;
}
.brand-mark::after {
width: 10px;
height: 10px;
right: 7px;
bottom: 7px;
background: var(--gold);
}
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1;
letter-spacing: 0.18em;
font-weight: 800;
text-transform: uppercase;
}
.brand p {
margin: 7px 0 0;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.13em;
text-transform: uppercase;
color: var(--muted);
}
.display-panel {
position: absolute;
top: 24px;
right: 24px;
width: min(340px, calc(100vw - 48px));
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 18px;
background: rgba(248, 243, 232, 0.86);
box-shadow: 0 18px 60px rgba(55, 48, 36, 0.13);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.live {
display: inline-flex;
align-items: center;
gap: 6px;
}
.live::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #6f9b63;
box-shadow: 0 0 0 4px rgba(111, 155, 99, 0.13);
}
.on-display {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
align-items: end;
padding-bottom: 15px;
border-bottom: 1px solid var(--line);
}
.on-display strong {
display: block;
margin-top: 4px;
font-size: 29px;
line-height: 1;
letter-spacing: -0.04em;
}
.on-display small {
color: var(--muted);
font-size: 12px;
}
.lot-number {
padding: 8px 10px;
border-radius: 9px;
background: var(--ink);
color: white;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.timeline {
display: grid;
gap: 7px;
margin-top: 13px;
}
.timeline-row {
display: grid;
grid-template-columns: 58px 1fr auto;
align-items: center;
gap: 9px;
padding: 8px 9px;
border: 1px solid transparent;
border-radius: 10px;
transition: background 180ms ease, border-color 180ms ease;
}
.timeline-row.current {
border-color: rgba(72, 102, 73, 0.24);
background: rgba(72, 102, 73, 0.08);
}
.timeline-date {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
}
.timeline-name {
min-width: 0;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
color: var(--muted);
}
.progress-track {
height: 4px;
margin-top: 5px;
overflow: hidden;
border-radius: 10px;
background: rgba(38, 56, 45, 0.1);
}
.progress-fill {
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #829757, #d09b3f, #c85d45);
transition: width 300ms ease;
}
.timeline-stage {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.basket-counts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.basket-count {
padding: 9px 7px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.48);
text-align: center;
}
.basket-count span {
display: block;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.basket-count strong {
display: block;
margin-top: 3px;
font-size: 18px;
}
.controls {
position: absolute;
left: 26px;
bottom: 25px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
button {
border: 0;
border-radius: 12px;
padding: 12px 15px;
background: var(--ink);
color: #fffaf0;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 0 8px 22px rgba(38, 56, 45, 0.18);
transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
button:hover {
transform: translateY(-2px);
background: #35503b;
}
button:active {
transform: translateY(0);
}
button:disabled {
cursor: default;
opacity: 0.45;
transform: none;
}
button.secondary {
border: 1px solid rgba(38, 56, 45, 0.15);
background: rgba(248, 243, 232, 0.86);
color: var(--ink);
box-shadow: none;
}
.hint {
position: absolute;
right: 26px;
bottom: 28px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 10px;
background: rgba(248, 243, 232, 0.7);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
backdrop-filter: blur(10px);
}
.date-stamp {
position: absolute;
left: 27px;
top: 91px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.toast {
position: absolute;
left: 50%;
bottom: 30px;
padding: 12px 18px;
border-radius: 12px;
background: var(--paper-strong);
color: var(--ink);
box-shadow: 0 12px 40px rgba(42, 39, 31, 0.18);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity 220ms ease, transform 220ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 16px;
}
.date-stamp {
display: none;
}
.display-panel {
top: auto;
right: 12px;
bottom: 76px;
width: 230px;
padding: 12px;
border-radius: 14px;
}
.on-display strong {
font-size: 22px;
}
.timeline-row:nth-child(n + 4) {
display: none;
}
.controls {
left: 12px;
bottom: 14px;
}
button {
padding: 11px 12px;
font-size: 9px;
}
.hint {
display: none;
}
.basket-counts {
gap: 4px;
}
.basket-count {
padding: 6px 4px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>The Ripening Room</h1>
<p>Produce rotation & daily arrivals</p>
</div>
</header>
<div class="date-stamp" id="currentDate"></div>
<aside class="display-panel" aria-label="Produce arrival queue">
<div class="eyebrow">
<span>Arrival queue</span>
<span class="live">Live</span>
</div>
<div class="on-display">
<div>
<small>Currently at the front</small>
<strong id="frontDate">—</strong>
<small id="frontKind">Waiting for stock</small>
</div>
<div class="lot-number" id="frontLot">Lot —</div>
</div>
<div class="timeline" id="timeline"></div>
<div class="basket-counts">
<div class="basket-count">
<span>Apples</span>
<strong id="appleCount">0</strong>
</div>
<div class="basket-count">
<span>Citrus</span>
<strong id="orangeCount">0</strong>
</div>
<div class="basket-count">
<span>Pears</span>
<strong id="pearCount">0</strong>
</div>
</div>
</aside>
<div class="controls">
<button id="deliverButton" type="button">Deliver fresh crate</button>
<button id="autoButton" class="secondary" type="button">Auto: on</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div class="toast" id="toast" role="status" aria-live="polite"></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 mount = document.getElementById("scene");
const timelineElement = document.getElementById("timeline");
const deliverButton = document.getElementById("deliverButton");
const autoButton = document.getElementById("autoButton");
const toastElement = document.getElementById("toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e1d4);
scene.fog = new THREE.Fog(0xe8e1d4, 21, 39);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
70
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
mount.appendChild(renderer.domElement);
const clock = new THREE.Clock();
const SLOT_COUNT = 8;
const SLOT_STEP = (Math.PI * 2) / SLOT_COUNT;
const CRATE_RADIUS = 3.55;
const PLATFORM_X = -2.15;
const crates = [];
const transfers = [];
const baskets = {};
let crateSerial = 1;
let nextSlot = 0;
let targetTurntableRotation = 0;
let automaticDeliveries = true;
let autoElapsed = 0;
let uiElapsed = 0;
let toastTimer;
const kindOrder = ["apple", "orange", "pear", "apple", "orange", "pear"];
const fruitTypes = {
apple: {
name: "Apple",
green: new THREE.Color(0x789348),
ripe: new THREE.Color(0xd94e3d),
basket: "apple"
},
orange: {
name: "Citrus",
green: new THREE.Color(0x849b4d),
ripe: new THREE.Color(0xf08a28),
basket: "orange"
},
pear: {
name: "Pear",
green: new THREE.Color(0x879650),
ripe: new THREE.Color(0xd5b642),
basket: "pear"
}
};
const fruitGeometry = {
apple: new THREE.IcosahedronGeometry(0.3, 1),
orange: new THREE.DodecahedronGeometry(0.3, 0),
pearLower: new THREE.SphereGeometry(0.26, 8, 6),
pearUpper: new THREE.SphereGeometry(0.18, 8, 6)
};
const materialPalette = {
floor: new THREE.MeshStandardMaterial({
color: 0xded6c7,
roughness: 0.96
}),
wall: new THREE.MeshStandardMaterial({
color: 0xe7dfd1,
roughness: 1
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x6d4932,
roughness: 0.88
}),
wood: new THREE.MeshStandardMaterial({
color: 0xa8784e,
roughness: 0.9
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xc79862,
roughness: 0.88
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x765037,
roughness: 0.92
}),
brass: new THREE.MeshStandardMaterial({
color: 0xc39a4b,
roughness: 0.48,
metalness: 0.18
}),
basket: new THREE.MeshStandardMaterial({
color: 0xa97542,
roughness: 0.93
}),
basketDark: new THREE.MeshStandardMaterial({
color: 0x765035,
roughness: 0.96
}),
stem: new THREE.MeshStandardMaterial({
color: 0x58432d,
roughness: 1
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4f713c,
roughness: 1
})
};
function box(width, height, depth, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
radiusTop,
radiusBottom,
height,
segments,
x,
y,
z,
material,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function formatDate(date) {
return date
.toLocaleDateString("en-US", {
month: "short",
day: "2-digit"
})
.toUpperCase();
}
function dateWithYear(date) {
return date
.toLocaleDateString("en-US", {
month: "short",
day: "2-digit",
year: "numeric"
})
.toUpperCase();
}
function createCrateLabel(date, kind, serial) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f3ead7";
ctx.fillRect(0, 0, 512, 256);
ctx.strokeStyle = "#6a5038";
ctx.lineWidth = 12;
ctx.strokeRect(8, 8, 496, 240);
ctx.textAlign = "center";
ctx.fillStyle = "#6a5038";
ctx.font = "700 24px Arial, sans-serif";
ctx.fillText(`HARVEST LOT ${String(serial).padStart(2, "0")}`, 256, 48);
ctx.fillStyle = "#293a2f";
ctx.font = "800 72px Arial, sans-serif";
ctx.fillText(formatDate(date), 256, 135);
ctx.fillStyle = "#7a634d";
ctx.font = "700 27px Arial, sans-serif";
ctx.fillText(`${fruitTypes[kind].name.toUpperCase()} · FIELD FRESH`, 256, 198);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function createTextSprite(title, subtitle, background = "#304936") {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 180;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "rgba(255,255,255,.28)";
ctx.lineWidth = 5;
ctx.strokeRect(9, 9, canvas.width - 18, canvas.height - 18);
ctx.textAlign = "center";
ctx.fillStyle = "#fff9e9";
ctx.font = "800 48px Arial, sans-serif";
ctx.fillText(title, 320, 78);
ctx.fillStyle = "rgba(255,249,233,.74)";
ctx.font = "700 23px Arial, sans-serif";
ctx.fillText(subtitle, 320, 125);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.65, 0.75, 1);
sprite.renderOrder = 8;
return sprite;
}
function createWallSign() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 240;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#304936";
ctx.fillRect(0, 0, 1024, 240);
ctx.strokeStyle = "#c9a256";
ctx.lineWidth = 8;
ctx.strokeRect(15, 15, 994, 210);
ctx.textAlign = "center";
ctx.fillStyle = "#fff7df";
ctx.font = "800 72px Georgia, serif";
ctx.fillText("THE RIPENING ROOM", 512, 106);
ctx.fillStyle = "#d8c28e";
ctx.font = "700 25px Arial, sans-serif";
ctx.fillText("FRESH LOTS · DAILY HARVEST · ROTATING DISPLAY", 512, 168);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(6.7, 1.57),
new THREE.MeshBasicMaterial({ map: texture })
);
panel.position.set(PLATFORM_X, 5.55, -7.83);
scene.add(panel);
}
// Lighting and room.
const hemisphere = new THREE.HemisphereLight(0xfff6df, 0x7c8277, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5b6, 3.4);
sun.position.set(6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xdde8ef, 1.2);
fill.position.set(-8, 7, 4);
scene.add(fill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
materialPalette.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
const insetFloor = new THREE.Mesh(
new THREE.CircleGeometry(6.4, 64),
new THREE.MeshStandardMaterial({ color: 0xeee7da, roughness: 1 })
);
insetFloor.rotation.x = -Math.PI / 2;
insetFloor.position.set(PLATFORM_X, 0.002, 0);
insetFloor.receiveShadow = true;
scene.add(insetFloor);
box(28, 9, 0.28, 0, 4.45, -8.1, materialPalette.wall);
box(28, 0.16, 0.34, 0, 1.05, -7.92, materialPalette.woodDark);
createWallSign();
// Display platform.
cylinder(
4.3,
4.45,
0.42,
64,
PLATFORM_X,
0.22,
0,
materialPalette.darkWood
);
const turntable = new THREE.Group();
turntable.position.set(PLATFORM_X, 0.48, 0);
scene.add(turntable);
cylinder(4.13, 4.13, 0.16, 64, 0, 0, 0, materialPalette.woodLight, turntable);
for (let i = 0; i < SLOT_COUNT; i++) {
const angle = -i * SLOT_STEP;
const spoke = box(
0.12,
0.045,
3.75,
Math.sin(angle) * 2.0,
0.105,
Math.cos(angle) * 2.0,
materialPalette.wood,
turntable
);
spoke.rotation.y = angle;
}
cylinder(0.72, 0.72, 0.16, 32, 0, 0.14, 0, materialPalette.brass, turntable);
// Fixed brass marker indicates the front of the rotating display.
box(0.62, 0.07, 0.13, PLATFORM_X, 0.5, 4.36, materialPalette.brass);
const incomingSign = createTextSprite("FRESH ARRIVALS", "ENTER AT THE REAR");
incomingSign.position.set(PLATFORM_X, 1.8, -4.55);
incomingSign.scale.set(2.35, 0.66, 1);
scene.add(incomingSign);
// Separate low table for the ripe-fruit baskets.
box(3.55, 0.24, 6.0, 5.25, 0.14, 0, materialPalette.woodDark);
box(3.25, 0.08, 5.7, 5.25, 0.29, 0, materialPalette.woodLight);
function createBasket(type, x, z, label, subtitle) {
const group = new THREE.Group();
group.position.set(x, 0.34, z);
scene.add(group);
cylinder(0.78, 0.67, 0.14, 16, 0, 0.08, 0, materialPalette.basketDark, group);
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2;
const slat = box(
0.075,
0.9,
0.075,
Math.sin(angle) * 0.82,
0.56,
Math.cos(angle) * 0.82,
materialPalette.basket,
group
);
slat.rotation.y = angle;
slat.rotation.z = Math.sin(angle) * 0.08;
}
const ringHeights = [0.32, 0.62, 0.96];
const ringRadii = [0.81, 0.89, 0.97];
ringHeights.forEach((height, index) => {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(ringRadii[index], 0.055, 6, 32),
index === 2 ? materialPalette.basketDark : materialPalette.basket
);
ring.rotation.x = Math.PI / 2;
ring.position.y = height;
ring.castShadow = true;
group.add(ring);
});
const interior = cylinder(
0.72,
0.68,
0.12,
16,
0,
0.3,
0,
new THREE.MeshStandardMaterial({ color: 0x5f4934, roughness: 1 }),
group
);
interior.castShadow = false;
const sprite = createTextSprite(label, subtitle);
sprite.position.set(0, 1.57, 0);
group.add(sprite);
baskets[type] = {
group,
items: [],
sprite
};
}
createBasket("apple", 5.22, 2.05, "RIPE APPLES", "READY FOR MARKET");
createBasket("orange", 5.3, 0, "RIPE CITRUS", "READY FOR MARKET");
createBasket("pear", 5.22, -2.05, "RIPE PEARS", "READY FOR MARKET");
function createFruit(kind) {
const type = fruitTypes[kind];
const group = new THREE.Group();
const fruitMaterial = new THREE.MeshStandardMaterial({
color: type.green,
roughness: 0.77,
flatShading: true
});
if (kind === "apple") {
const body = new THREE.Mesh(fruitGeometry.apple, fruitMaterial);
body.scale.set(1, 0.94, 1);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const dimple = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 7, 5),
materialPalette.stem
);
dimple.scale.set(1, 0.35, 1);
dimple.position.y = 0.275;
group.add(dimple);
} else if (kind === "orange") {
const body = new THREE.Mesh(fruitGeometry.orange, fruitMaterial);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.028, 0.04, 0.13, 6),
materialPalette.stem
);
stem.position.y = 0.29;
group.add(stem);
} else {
const lower = new THREE.Mesh(fruitGeometry.pearLower, fruitMaterial);
lower.scale.set(0.95, 1.18, 0.9);
lower.position.y = -0.035;
lower.castShadow = true;
lower.receiveShadow = true;
group.add(lower);
const upper = new THREE.Mesh(fruitGeometry.pearUpper, fruitMaterial);
upper.scale.set(0.9, 1.12, 0.9);
upper.position.y = 0.205;
upper.castShadow = true;
upper.receiveShadow = true;
group.add(upper);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.035, 0.18, 6),
materialPalette.stem
);
stem.position.y = 0.43;
stem.rotation.z = -0.14;
group.add(stem);
}
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.09, 6, 4),
materialPalette.leaf
);
leaf.scale.set(1.45, 0.18, 0.58);
leaf.position.set(0.08, 0.33, 0);
leaf.rotation.z = 0.35;
group.add(leaf);
group.scale.setScalar(0.88);
return {
mesh: group,
material: fruitMaterial,
type,
kind,
state: "crate",
ripeness: 0,
phase: Math.random() * Math.PI * 2,
home: new THREE.Vector3()
};
}
function createCrate(date, kind, slot, initialRipeness = 0.08) {
const group = new THREE.Group();
const angle = -slot * SLOT_STEP;
group.position.set(
Math.sin(angle) * CRATE_RADIUS,
3.25,
Math.cos(angle) * CRATE_RADIUS
);
group.rotation.y = angle;
turntable.add(group);
box(2.05, 0.14, 1.55, 0, 0.08, 0, materialPalette.woodDark, group);
const postPositions = [
[-0.96, -0.7],
[0.96, -0.7],
[-0.96, 0.7],
[0.96, 0.7]
];
postPositions.forEach(([x, z]) => {
box(0.14, 1.13, 0.14, x, 0.61, z, materialPalette.woodDark, group);
});
[-0.72, 0.72].forEach((z) => {
box(1.92, 0.17, 0.11, 0, 0.28, z, materialPalette.wood, group);
box(1.92, 0.17, 0.11, 0, 1.01, z, materialPalette.woodLight, group);
});
[-0.97, 0.97].forEach((x) => {
[0.35, 0.67, 0.99].forEach((y, index) => {
box(
0.11,
0.22,
1.45,
x,
y,
0,
index === 1 ? materialPalette.woodLight : materialPalette.wood,
group
);
});
});
const labelTexture = createCrateLabel(date, kind, crateSerial);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(1.48, 0.74),
new THREE.MeshBasicMaterial({ map: labelTexture })
);
label.position.set(0, 0.66, 0.795);
group.add(label);
const fruitPositions = [
[-0.61, -0.34],
[0, -0.34],
[0.61, -0.34],
[-0.61, 0.28],
[0, 0.28],
[0.61, 0.28]
];
const fruits = fruitPositions.map(([x, z]) => {
const fruit = createFruit(kind);
fruit.mesh.position.set(x, 0.88, z);
fruit.home.copy(fruit.mesh.position);
fruit.ripeness = THREE.MathUtils.clamp(
initialRipeness + (Math.random() - 0.5) * 0.18,
0.03,
0.76
);
group.add(fruit.mesh);
return fruit;
});
const crate = {
group,
date,
kind,
slot,
fruits,
serial: crateSerial,
entrance: 0
};
crates.push(crate);
crateSerial++;
return crate;
}
function normalizedAngle(angle) {
return Math.atan2(Math.sin(angle), Math.cos(angle));
}
function crateWorldAngle(crate) {
return normalizedAngle(-crate.slot * SLOT_STEP + turntable.rotation.y);
}
function crateFrontness(crate) {
return Math.max(0, 1 - Math.abs(crateWorldAngle(crate)) / Math.PI);
}
function getFrontCrate() {
let front = null;
let smallestDistance = Infinity;
crates.forEach((crate) => {
const distance = Math.abs(crateWorldAngle(crate));
if (distance < smallestDistance) {
smallestDistance = distance;
front = crate;
}
});
return front;
}
function smoothRipeness(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updateFruitColor(fruit) {
const type = fruitTypes[fruit.kind];
const blend = smoothRipeness(fruit.ripeness);
fruit.material.color.copy(type.green).lerp(type.ripe, blend);
fruit.material.emissive.copy(type.ripe);
fruit.material.emissiveIntensity = blend * 0.055;
}
function beginBasketTransfer(fruit) {
const basket = baskets[fruitTypes[fruit.kind].basket];
const targetLocal = new THREE.Vector3(
(Math.random() - 0.5) * 1.0,
0.62 + Math.random() * 0.35,
(Math.random() - 0.5) * 1.0
);
basket.group.updateMatrixWorld(true);
const end = basket.group.localToWorld(targetLocal.clone());
scene.attach(fruit.mesh);
const start = fruit.mesh.position.clone();
const control = start.clone().lerp(end, 0.5);
control.y = Math.max(start.y, end.y) + 2.2;
fruit.state = "transfer";
transfers.push({
fruit,
start,
control,
end,
time: 0,
duration: 1.25 + Math.random() * 0.3
});
}
function finishBasketTransfer(transfer) {
const fruit = transfer.fruit;
const basket = baskets[fruitTypes[fruit.kind].basket];
basket.group.updateMatrixWorld(true);
basket.group.attach(fruit.mesh);
fruit.mesh.position.copy(basket.group.worldToLocal(transfer.end.clone()));
fruit.mesh.scale.setScalar(0.88);
fruit.state = "basket";
basket.items.push(fruit.mesh);
if (basket.items.length > 16) {
const oldest = basket.items.shift();
oldest.removeFromParent();
}
}
function updateFruitTransfers(dt) {
for (let i = transfers.length - 1; i >= 0; i--) {
const transfer = transfers[i];
transfer.time += dt;
const t = Math.min(transfer.time / transfer.duration, 1);
const u = 1 - t;
transfer.fruit.mesh.position
.copy(transfer.start)
.multiplyScalar(u * u)
.addScaledVector(transfer.control, 2 * u * t)
.addScaledVector(transfer.end, t * t);
transfer.fruit.mesh.rotation.y += dt * 3.2;
transfer.fruit.mesh.rotation.z = Math.sin(t * Math.PI) * 0.45;
if (t >= 1) {
finishBasketTransfer(transfer);
transfers.splice(i, 1);
}
}
}
function updateCrates(dt, time) {
crates.forEach((crate) => {
crate.entrance += dt;
const entrance = Math.min(crate.entrance / 1.15, 1);
const eased = 1 - Math.pow(1 - entrance, 3);
crate.group.position.y = 0.1 + 3.15 * (1 - eased);
const frontness = crateFrontness(crate);
crate.fruits.forEach((fruit) => {
if (fruit.state !== "crate") return;
const rate = 0.017 + Math.pow(frontness, 2) * 0.078;
fruit.ripeness = Math.min(1, fruit.ripeness + dt * rate);
updateFruitColor(fruit);
fruit.mesh.position.y =
fruit.home.y + Math.sin(time * 2.1 + fruit.phase) * 0.012;
fruit.mesh.rotation.y += dt * 0.08;
if (fruit.ripeness >= 1) {
beginBasketTransfer(fruit);
}
});
});
}
function addDelivery() {
if (crates.length >= SLOT_COUNT) {
showToast("The display is full — every lot remains visible");
return;
}
const date = new Date();
const kind = kindOrder[crates.length % kindOrder.length];
const slot = nextSlot;
nextSlot++;
createCrate(date, kind, slot, 0.07);
// The next oldest crate advances to the front; the new lot enters behind it.
targetTurntableRotation += SLOT_STEP;
showToast(`New ${fruitTypes[kind].name.toLowerCase()} lot received`);
updateUI();
}
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => {
toastElement.classList.remove("show");
}, 2300);
}
function updateUI() {
const front = getFrontCrate();
if (front) {
document.getElementById("frontDate").textContent = formatDate(front.date);
document.getElementById("frontKind").textContent =
`${fruitTypes[front.kind].name} · Harvest lot ${front.serial}`;
document.getElementById("frontLot").textContent =
`Lot ${String(front.serial).padStart(2, "0")}`;
}
timelineElement.innerHTML = crates
.map((crate) => {
const average =
crate.fruits.reduce((sum, fruit) => sum + fruit.ripeness, 0) /
crate.fruits.length;
const percent = Math.round(average * 100);
const stage =
average > 0.88 ? "Ready" : average > 0.48 ? "Ripening" : "Fresh";
const current = crate === front ? " current" : "";
return `
<div class="timeline-row${current}">
<div class="timeline-date">${formatDate(crate.date)}</div>
<div>
<div class="timeline-name">
${fruitTypes[crate.kind].name} · Lot ${String(crate.serial).padStart(2, "0")}
</div>
<div class="progress-track">
<div class="progress-fill" style="width:${percent}%"></div>
</div>
</div>
<div class="timeline-stage">${stage}</div>
</div>
`;
})
.join("");
document.getElementById("appleCount").textContent =
baskets.apple.items.length;
document.getElementById("orangeCount").textContent =
baskets.orange.items.length;
document.getElementById("pearCount").textContent =
baskets.pear.items.length;
const full = crates.length >= SLOT_COUNT;
deliverButton.disabled = full;
autoButton.disabled = full;
autoButton.textContent = full
? "Display full"
: `Auto: ${automaticDeliveries ? "on" : "off"}`;
}
deliverButton.addEventListener("click", addDelivery);
autoButton.addEventListener("click", () => {
if (crates.length >= SLOT_COUNT) return;
automaticDeliveries = !automaticDeliveries;
autoElapsed = 0;
updateUI();
});
// Initial stock: older arrivals are at the front, newest arrivals at the rear.
const today = new Date();
for (let i = 0; i < 5; i++) {
const date = new Date(today);
date.setDate(today.getDate() - (5 - i));
createCrate(date, kindOrder[i], i, 0.13 + i * 0.075);
}
nextSlot = 5;
document.getElementById("currentDate").textContent = dateWithYear(today);
// Custom orbit controls implemented without external addons.
const cameraTarget = new THREE.Vector3(-0.25, 1.35, 0);
const spherical = new THREE.Spherical(16.1, 1.16, 0.65);
const desiredSpherical = spherical.clone();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desiredSpherical.theta = THREE.MathUtils.clamp(
desiredSpherical.theta - deltaX * 0.005,
-1.15,
1.2
);
desiredSpherical.phi = THREE.MathUtils.clamp(
desiredSpherical.phi - deltaY * 0.0045,
0.62,
1.43
);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredSpherical.radius = THREE.MathUtils.clamp(
desiredSpherical.radius + event.deltaY * 0.012,
10.5,
23
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
desiredSpherical.set(16.1, 1.16, 0.65);
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
// Smoothly rotate the stock one position forward after each arrival.
turntable.rotation.y +=
(targetTurntableRotation - turntable.rotation.y) *
(1 - Math.exp(-dt * 2.8));
updateCrates(dt, time);
updateFruitTransfers(dt);
if (automaticDeliveries && crates.length < SLOT_COUNT) {
autoElapsed += dt;
if (autoElapsed >= 9.5) {
autoElapsed = 0;
addDelivery();
}
}
// Damped custom camera movement.
spherical.theta +=
(desiredSpherical.theta - spherical.theta) *
(1 - Math.exp(-dt * 10));
spherical.phi +=
(desiredSpherical.phi - spherical.phi) *
(1 - Math.exp(-dt * 10));
spherical.radius +=
(desiredSpherical.radius - spherical.radius) *
(1 - Math.exp(-dt * 8));
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
uiElapsed += dt;
if (uiElapsed > 0.25) {
uiElapsed = 0;
updateUI();
}
renderer.render(scene, camera);
}
updateUI();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```