Prompt specification
Build or customize the Three.js 3D scene "Nested grain measures beside a scoop" 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: Nested grain measures beside a scoop
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nested-grain-measures-beside-a-scoop-x2373
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring medieval grain measures. Display three wooden grain measures with visibly different capacities and a shared scoop. Label volumes as an invented teaching system rather than universal medieval standards. Stylized solid forms.
Working Three.js Starter (nested-grain-measures-beside-a-scoop-x2373):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Granary Lesson — Medieval Grain Measures</title>
<style>
:root {
--ink: #30251e;
--muted: #75685b;
--parchment: #eee3cc;
--paper: rgba(248, 239, 219, 0.91);
--line: rgba(73, 51, 35, 0.22);
--gold: #b77b2e;
--wood: #704a30;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9ceb9;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
body {
overscroll-behavior: none;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.wash {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 35%, rgba(55, 35, 20, 0.09) 100%),
linear-gradient(180deg, rgba(255, 249, 232, 0.12), transparent 30%);
z-index: 2;
}
header {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
max-width: 430px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: #73563c;
font: 700 11px/1.2 system-ui, sans-serif;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 31px;
height: 2px;
background: var(--gold);
}
h1 {
margin: 0;
font-size: clamp(29px, 3.5vw, 48px);
line-height: 0.98;
font-weight: 500;
letter-spacing: -0.035em;
text-shadow: 0 1px rgba(255, 255, 255, 0.45);
}
.subtitle {
max-width: 360px;
margin: 12px 0 0;
color: #5e5145;
font: 400 14px/1.45 system-ui, sans-serif;
}
.scale-card {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
width: 210px;
padding: 15px 16px 13px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 10px 35px rgba(58, 38, 24, 0.1);
backdrop-filter: blur(9px);
}
.scale-card h2 {
margin: 0 0 4px;
font-size: 15px;
font-weight: 600;
}
.scale-card .made-up {
margin-bottom: 10px;
color: #966128;
font: 700 9px/1.3 system-ui, sans-serif;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.scale-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 8px;
padding: 6px 0;
border-top: 1px solid rgba(75, 53, 37, 0.1);
font: 500 12px/1.2 system-ui, sans-serif;
}
.scale-row i {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.65);
}
.scale-row strong {
font-family: Georgia, serif;
font-size: 15px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
overflow: hidden;
}
.object-label {
position: absolute;
min-width: 108px;
padding: 9px 12px 10px;
transform: translate(-50%, -100%);
border: 1px solid rgba(72, 48, 30, 0.25);
border-radius: 3px;
background: rgba(248, 239, 220, 0.93);
box-shadow: 0 8px 22px rgba(50, 31, 18, 0.14);
text-align: center;
transition: opacity 120ms ease;
}
.object-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 24px;
background: linear-gradient(rgba(72, 48, 30, 0.6), transparent);
}
.object-label .index {
display: block;
margin-bottom: 2px;
color: #7c674f;
font: 700 8px/1.2 system-ui, sans-serif;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.object-label strong {
display: block;
color: #3d2a1e;
font-size: 24px;
font-weight: 500;
line-height: 1;
}
.object-label strong em {
color: #986126;
font: 700 10px/1 system-ui, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.object-label.scoop-label {
min-width: 124px;
padding: 7px 11px;
}
.object-label.scoop-label strong {
font-size: 15px;
}
.object-label.scoop-label::after {
height: 15px;
}
.notice {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 6;
width: min(680px, calc(100% - 32px));
padding: 12px 17px;
transform: translateX(-50%);
border: 1px solid rgba(73, 51, 35, 0.23);
border-left: 4px solid var(--gold);
border-radius: 3px;
background: rgba(247, 237, 215, 0.94);
box-shadow: 0 10px 35px rgba(50, 31, 18, 0.14);
text-align: center;
backdrop-filter: blur(8px);
}
.notice strong {
font-size: 12px;
letter-spacing: 0.04em;
}
.notice span {
display: block;
margin-top: 3px;
color: #6f6254;
font: 400 11px/1.35 system-ui, sans-serif;
}
.help {
position: fixed;
left: 25px;
bottom: 24px;
z-index: 5;
color: rgba(55, 42, 32, 0.72);
font: 500 10px/1.35 system-ui, sans-serif;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 15px;
left: 16px;
max-width: calc(100% - 32px);
}
h1 {
font-size: 28px;
}
.subtitle {
display: none;
}
.scale-card {
top: 91px;
right: 13px;
width: 153px;
padding: 10px 11px;
}
.scale-card h2 {
font-size: 13px;
}
.scale-card .made-up {
font-size: 8px;
}
.scale-row {
padding: 4px 0;
font-size: 10px;
}
.scale-row strong {
font-size: 13px;
}
.object-label {
min-width: 86px;
padding: 7px 9px;
}
.object-label strong {
font-size: 19px;
}
.help {
display: none;
}
.notice {
bottom: 12px;
padding: 10px 12px;
}
.notice strong {
font-size: 10px;
}
.notice span {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="wash"></div>
<header>
<div class="eyebrow">A medieval-inspired study</div>
<h1>The Granary Lesson</h1>
<p class="subtitle">
Three wooden grain measures, one shared scoop, and a deliberately invented
teaching scale for comparing relative capacity.
</p>
</header>
<aside class="scale-card" aria-label="Invented teaching volume scale">
<h2>Teaching scale</h2>
<div class="made-up">Invented for this scene</div>
<div class="scale-row" style="--dot:#b27a35">
<i></i><span>Small measure</span><strong>2 TU</strong>
</div>
<div class="scale-row" style="--dot:#9a612e">
<i></i><span>Middle measure</span><strong>5 TU</strong>
</div>
<div class="scale-row" style="--dot:#76503a">
<i></i><span>Large measure</span><strong>11 TU</strong>
</div>
</aside>
<div id="labels" aria-hidden="true">
<div class="object-label" id="label-small">
<span class="index">I · Small</span>
<strong>2 <em>TU</em></strong>
</div>
<div class="object-label" id="label-middle">
<span class="index">II · Middle</span>
<strong>5 <em>TU</em></strong>
</div>
<div class="object-label" id="label-large">
<span class="index">III · Large</span>
<strong>11 <em>TU</em></strong>
</div>
<div class="object-label scoop-label" id="label-scoop">
<span class="index">Shared tool</span>
<strong>One grain scoop</strong>
</div>
</div>
<div class="notice" role="note">
<strong>INVENTED TEACHING UNITS (TU) — NOT HISTORICAL STANDARDS</strong>
<span>
These volumes are a fictional system for visual comparison only. The forms are
medieval-inspired, but the numbers are not universal medieval measures.
</span>
</div>
<div class="help">
DRAG TO ORBIT · SCROLL TO ZOOM<br>
DOUBLE-CLICK TO RESET
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const host = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Three wooden medieval-inspired grain measures of different sizes with a shared wooden scoop."
);
renderer.domElement.tabIndex = 0;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe2d7c2);
scene.fog = new THREE.Fog(0xe2d7c2, 15, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
// -------------------------------------------------------------------------
// Procedural textures — no external image assets
// -------------------------------------------------------------------------
let seed = 1976;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
function makeWoodTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#98633b";
ctx.fillRect(0, 0, 256, 256);
for (let x = 0; x < 256; x += 2) {
const light = random() > 0.5;
ctx.strokeStyle = light
? `rgba(238, 183, 111, ${0.035 + random() * 0.09})`
: `rgba(55, 28, 13, ${0.035 + random() * 0.10})`;
ctx.lineWidth = 1 + random() * 2.2;
ctx.beginPath();
ctx.moveTo(x, -10);
ctx.bezierCurveTo(
x + random() * 13 - 6,
58,
x + random() * 17 - 8,
164,
x + random() * 10 - 5,
266
);
ctx.stroke();
}
for (let i = 0; i < 150; i++) {
ctx.fillStyle = random() > 0.5
? "rgba(255, 220, 168, 0.08)"
: "rgba(49, 24, 11, 0.08)";
ctx.fillRect(
random() * 256,
random() * 256,
1 + random() * 4,
1 + random() * 11
);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(1.6, 1);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makeGrainTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#bd7d2e";
ctx.fillRect(0, 0, 256, 256);
for (let i = 0; i < 5200; i++) {
const colors = ["#e3b85c", "#d89a3d", "#9b5d20", "#f0c975", "#b87529"];
ctx.fillStyle = colors[Math.floor(random() * colors.length)];
ctx.globalAlpha = 0.55 + random() * 0.45;
const x = random() * 256;
const y = random() * 256;
ctx.beginPath();
ctx.ellipse(
x,
y,
0.7 + random() * 2.3,
0.4 + random() * 1.1,
random() * Math.PI,
0,
Math.PI * 2
);
ctx.fill();
}
ctx.globalAlpha = 1;
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.3, 2.3);
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function makePlaqueTexture(volume, sizeName) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 320;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#e7d3a6";
ctx.fillRect(0, 0, 512, 320);
ctx.strokeStyle = "#4e3424";
ctx.lineWidth = 12;
ctx.strokeRect(12, 12, 488, 296);
ctx.strokeStyle = "#9c6b37";
ctx.lineWidth = 3;
ctx.strokeRect(28, 28, 456, 264);
ctx.textAlign = "center";
ctx.fillStyle = "#765039";
ctx.font = "700 25px Georgia";
ctx.fillText("INVENTED SCALE", 256, 70);
ctx.fillStyle = "#3e291d";
ctx.font = "700 96px Georgia";
ctx.fillText(`${volume} TU`, 256, 183);
ctx.fillStyle = "#765039";
ctx.font = "600 28px Georgia";
ctx.fillText(sizeName.toUpperCase(), 256, 244);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const woodTexture = makeWoodTexture();
const grainTexture = makeGrainTexture();
const bodyMaterial = new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0xffffff,
roughness: 0.83,
metalness: 0,
flatShading: true
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
map: woodTexture,
color: 0x725039,
roughness: 0.9,
metalness: 0,
flatShading: true
});
const ironMaterial = new THREE.MeshStandardMaterial({
color: 0x4d4842,
roughness: 0.7,
metalness: 0.42,
flatShading: true
});
const grainMaterial = new THREE.MeshStandardMaterial({
map: grainTexture,
color: 0xffffff,
roughness: 1,
metalness: 0
});
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff3d8, 0x574333, 1.65));
const keyLight = new THREE.DirectionalLight(0xffebcb, 3.1);
keyLight.position.set(-5.5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xd9e4ed, 1.05);
fillLight.position.set(7, 5, -5);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffb85e, 18, 15, 2);
warmLight.position.set(-3, 4, 2);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Table and floor
// -------------------------------------------------------------------------
const tableTexture = woodTexture.clone();
tableTexture.repeat.set(4.5, 2.2);
tableTexture.needsUpdate = true;
const tableMaterial = new THREE.MeshStandardMaterial({
map: tableTexture,
color: 0xa17b5b,
roughness: 0.94,
metalness: 0
});
const table = new THREE.Group();
scene.add(table);
const tabletop = new THREE.Mesh(
new THREE.BoxGeometry(10, 0.28, 7.2),
tableMaterial
);
tabletop.position.y = -0.14;
tabletop.castShadow = true;
tabletop.receiveShadow = true;
table.add(tabletop);
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x3f2c22,
roughness: 1
});
for (let x = -4; x <= 4; x += 1) {
const groove = new THREE.Mesh(
new THREE.BoxGeometry(0.018, 0.008, 7.05),
grooveMaterial
);
groove.position.set(x, 0.006, 0);
table.add(groove);
}
const frontRail = new THREE.Mesh(
new THREE.BoxGeometry(10, 0.34, 0.18),
darkWoodMaterial
);
frontRail.position.set(0, -0.25, 3.51);
frontRail.castShadow = true;
table.add(frontRail);
const backRail = frontRail.clone();
backRail.position.z = -3.51;
table.add(backRail);
for (const x of [-4.35, 4.35]) {
for (const z of [-2.85, 2.85]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 1.24, 0.42),
darkWoodMaterial
);
leg.position.set(x, -0.89, z);
leg.castShadow = true;
leg.receiveShadow = true;
table.add(leg);
}
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0xb7aa95,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.53;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Grain measure construction
// -------------------------------------------------------------------------
const measures = [];
function createMeasure({
radius,
height,
position,
volume,
sizeName,
staveCount
}) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
const bottomY = 0.16;
// Thick faceted base.
const base = new THREE.Mesh(
new THREE.CylinderGeometry(
radius * 1.035,
radius * 1.085,
0.16,
16
),
darkWoodMaterial
);
base.position.y = 0.08;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
// Main solid wooden wall.
const body = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius * 0.98,
height,
16,
1,
true
),
bodyMaterial
);
body.position.y = bottomY + height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
// Dark inner wall makes the vessel read as open.
const inner = new THREE.Mesh(
new THREE.CylinderGeometry(
radius * 0.925,
radius * 0.91,
height * 0.95,
16,
1,
true
),
new THREE.MeshStandardMaterial({
color: 0x3f281b,
roughness: 1,
side: THREE.BackSide
})
);
inner.position.y = bottomY + height / 2;
group.add(inner);
// Vertical stave seams.
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0x553622,
roughness: 1
});
for (let i = 0; i < staveCount; i++) {
const angle = (i / staveCount) * Math.PI * 2;
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.026, height * 0.96, 0.025),
seamMaterial
);
seam.position.set(
Math.sin(angle) * (radius + 0.006),
bottomY + height / 2,
Math.cos(angle) * (radius + 0.006)
);
seam.rotation.y = angle;
group.add(seam);
}
// Heavy iron hoops.
const topHoop = new THREE.Mesh(
new THREE.TorusGeometry(radius - 0.018, 0.068, 6, 28),
ironMaterial
);
topHoop.rotation.x = Math.PI / 2;
topHoop.position.y = bottomY + height;
topHoop.castShadow = true;
group.add(topHoop);
const lowerHoop = new THREE.Mesh(
new THREE.TorusGeometry(radius - 0.015, 0.058, 6, 28),
ironMaterial
);
lowerHoop.rotation.x = Math.PI / 2;
lowerHoop.position.y = 0.27;
lowerHoop.castShadow = true;
group.add(lowerHoop);
const middleHoop = new THREE.Mesh(
new THREE.TorusGeometry(radius * 0.995, 0.035, 5, 28),
ironMaterial
);
middleHoop.rotation.x = Math.PI / 2;
middleHoop.position.y = bottomY + height * 0.31;
middleHoop.castShadow = true;
group.add(middleHoop);
// Grain surface just below the rim.
const grainY = bottomY + height - 0.11;
const grainDisc = new THREE.Mesh(
new THREE.CircleGeometry(radius * 0.89, 32),
grainMaterial
);
grainDisc.rotation.x = -Math.PI / 2;
grainDisc.position.y = grainY;
grainDisc.receiveShadow = true;
group.add(grainDisc);
// A shallow mound keeps the grain surface stylized rather than perfectly flat.
const mound = new THREE.Mesh(
new THREE.SphereGeometry(1, 16, 8),
grainMaterial
);
mound.scale.set(radius * 0.71, radius * 0.066, radius * 0.71);
mound.position.y = grainY - 0.025;
mound.castShadow = true;
mound.receiveShadow = true;
group.add(mound);
// A handful of larger grain kernels.
const kernelGeometry = new THREE.SphereGeometry(0.052, 6, 4);
for (let i = 0; i < 11; i++) {
const angle = random() * Math.PI * 2;
const radial = random() * 0.67;
const x = Math.cos(angle) * radius * radial;
const z = Math.sin(angle) * radius * radial;
const surface = Math.sqrt(Math.max(0, 1 - radial * radial)) * radius * 0.066;
const kernel = new THREE.Mesh(kernelGeometry, grainMaterial);
kernel.position.set(x, grainY + surface + 0.015, z);
kernel.scale.set(0.75, 0.43, 1.35);
kernel.rotation.y = random() * Math.PI;
kernel.castShadow = true;
group.add(kernel);
}
// Physical parchment plaque, also stating that the scale is invented.
const plaqueWidth = radius < 1 ? 0.68 : radius < 1.3 ? 0.76 : 0.84;
const plaqueHeight = plaqueWidth * 0.625;
const plaqueBack = new THREE.Mesh(
new THREE.BoxGeometry(plaqueWidth + 0.08, plaqueHeight + 0.08, 0.07),
darkWoodMaterial
);
plaqueBack.position.set(0, bottomY + height * 0.39, radius + 0.025);
plaqueBack.castShadow = true;
group.add(plaqueBack);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(plaqueWidth, plaqueHeight),
new THREE.MeshBasicMaterial({
map: makePlaqueTexture(volume, sizeName)
})
);
plaque.position.set(0, bottomY + height * 0.39, radius + 0.064);
group.add(plaque);
group.updateMatrixWorld(true);
const anchor = group.localToWorld(
new THREE.Vector3(0, bottomY + height + 0.38, 0)
);
const measure = {
group,
anchor,
volume,
sizeName
};
measures.push(measure);
return measure;
}
// Dimensions are scaled so the invented numbers also correspond to visibly
// different approximate internal volumes.
const small = createMeasure({
radius: 0.86,
height: 1.06,
position: new THREE.Vector3(-2.55, 0, 0.55),
volume: 2,
sizeName: "Small",
staveCount: 12
});
const middle = createMeasure({
radius: 1.17,
height: 1.44,
position: new THREE.Vector3(2.25, 0, 0.25),
volume: 5,
sizeName: "Middle",
staveCount: 14
});
const large = createMeasure({
radius: 1.52,
height: 1.87,
position: new THREE.Vector3(-0.1, 0, -2.45),
volume: 11,
sizeName: "Large",
staveCount: 16
});
// -------------------------------------------------------------------------
// Shared scoop
// -------------------------------------------------------------------------
const scoop = new THREE.Group();
scoop.position.set(0.25, 0.025, 2.25);
scoop.rotation.y = -0.27;
scene.add(scoop);
// A lathed shell creates a solid, open wooden bowl.
const scoopProfile = [
new THREE.Vector2(0.00, 0.00),
new THREE.Vector2(0.17, 0.015),
new THREE.Vector2(0.36, 0.09),
new THREE.Vector2(0.55, 0.25),
new THREE.Vector2(0.67, 0.47),
new THREE.Vector2(0.69, 0.56),
new THREE.Vector2(0.63, 0.59),
new THREE.Vector2(0.59, 0.48),
new THREE.Vector2(0.47, 0.29),
new THREE.Vector2(0.28, 0.14),
new THREE.Vector2(0.00, 0.10)
];
const scoopBowl = new THREE.Mesh(
new THREE.LatheGeometry(scoopProfile, 24),
bodyMaterial
);
scoopBowl.castShadow = true;
scoopBowl.receiveShadow = true;
scoop.add(scoopBowl);
// Grain resting inside the scoop.
const scoopGrain = new THREE.Mesh(
new THREE.SphereGeometry(1, 16, 8),
grainMaterial
);
scoopGrain.scale.set(0.47, 0.062, 0.47);
scoopGrain.position.y = 0.365;
scoopGrain.castShadow = true;
scoop.add(scoopGrain);
// Tapered-looking solid handle.
const handle = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.16, 1.58),
darkWoodMaterial
);
handle.position.set(0, 0.25, 1.27);
handle.rotation.x = -0.075;
handle.castShadow = true;
handle.receiveShadow = true;
scoop.add(handle);
const handleCollar = new THREE.Mesh(
new THREE.BoxGeometry(0.31, 0.22, 0.34),
bodyMaterial
);
handleCollar.position.set(0, 0.31, 0.62);
handleCollar.castShadow = true;
scoop.add(handleCollar);
const handleTip = new THREE.Mesh(
new THREE.BoxGeometry(0.27, 0.19, 0.25),
bodyMaterial
);
handleTip.position.set(0, 0.365, 2.03);
handleTip.rotation.x = -0.075;
handleTip.castShadow = true;
scoop.add(handleTip);
// A few spilled kernels near the scoop.
const spillGeometry = new THREE.SphereGeometry(0.055, 6, 4);
for (let i = 0; i < 18; i++) {
const kernel = new THREE.Mesh(spillGeometry, grainMaterial);
kernel.position.set(
-0.55 + random() * 1.65,
0.065,
2.65 + random() * 0.85
);
kernel.scale.set(0.72, 0.46, 1.38);
kernel.rotation.y = random() * Math.PI * 2;
kernel.castShadow = true;
scene.add(kernel);
}
scoop.updateMatrixWorld(true);
const scoopAnchor = scoop.localToWorld(
new THREE.Vector3(0.25, 0.72, 0.1)
);
// -------------------------------------------------------------------------
// Direct camera controls — no examples or addon modules
// -------------------------------------------------------------------------
const controls = {
yaw: 0.28,
targetYaw: 0.28,
pitch: 0.48,
targetPitch: 0.48,
distance: window.innerWidth < 700 ? 15.2 : 13.4,
targetDistance: window.innerWidth < 700 ? 15.2 : 13.4,
target: new THREE.Vector3(0, 0.72, 0.05)
};
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.targetYaw -= dx * 0.006;
controls.targetPitch = THREE.MathUtils.clamp(
controls.targetPitch + dy * 0.0045,
0.22,
0.78
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
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();
controls.targetDistance = THREE.MathUtils.clamp(
controls.targetDistance * Math.exp(event.deltaY * 0.001),
8.5,
19
);
},
{ passive: false }
);
function resetCamera() {
controls.targetYaw = 0.28;
controls.targetPitch = 0.48;
controls.targetDistance = window.innerWidth < 700 ? 15.2 : 13.4;
}
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "ArrowLeft":
controls.targetYaw += 0.09;
break;
case "ArrowRight":
controls.targetYaw -= 0.09;
break;
case "ArrowUp":
controls.targetPitch = THREE.MathUtils.clamp(
controls.targetPitch + 0.05,
0.22,
0.78
);
break;
case "ArrowDown":
controls.targetPitch = THREE.MathUtils.clamp(
controls.targetPitch - 0.05,
0.22,
0.78
);
break;
case "+":
case "=":
controls.targetDistance = Math.max(8.5, controls.targetDistance - 0.5);
break;
case "-":
controls.targetDistance = Math.min(19, controls.targetDistance + 0.5);
break;
case "r":
case "R":
resetCamera();
break;
}
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-small"),
anchor: small.anchor,
offsetX: -4,
offsetY: -3
},
{
element: document.getElementById("label-middle"),
anchor: middle.anchor,
offsetX: 7,
offsetY: -4
},
{
element: document.getElementById("label-large"),
anchor: large.anchor,
offsetX: 0,
offsetY: -9
},
{
element: document.getElementById("label-scoop"),
anchor: scoopAnchor,
offsetX: 8,
offsetY: 11
}
];
function updateLabel(label) {
const projected = label.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x + label.offsetX}px`;
label.element.style.top = `${y + label.offsetY}px`;
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.fov = aspect < 0.72 ? 52 : aspect < 1.1 ? 44 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
onResize();
function animate() {
requestAnimationFrame(animate);
const smoothing = 0.085;
controls.yaw = THREE.MathUtils.lerp(
controls.yaw,
controls.targetYaw,
smoothing
);
controls.pitch = THREE.MathUtils.lerp(
controls.pitch,
controls.targetPitch,
smoothing
);
controls.distance = THREE.MathUtils.lerp(
controls.distance,
controls.targetDistance,
smoothing
);
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
for (const label of labels) {
updateLabel(label);
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```