Prompt specification
Build or customize the Three.js 3D scene "Shape-and-sauce classroom table" 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: Shape-and-sauce classroom table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shape-and-sauce-classroom-table-x0132
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Build a culinary exhibit with pasta shapes and colored sauce markers; compare surface grooves, cavities, and broad faces through qualitative coating demonstrations, avoiding unsupported performance rankings.
Working Three.js Starter (shape-and-sauce-classroom-table-x0132):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sauce, Meet Geometry — Culinary Voxel Exhibit</title>
<style>
:root {
--ink: #f5ead7;
--muted: #c4b5a4;
--panel: rgba(30, 23, 19, 0.82);
--line: rgba(255, 235, 205, 0.16);
--mint: #88dfcf;
--tomato: #ed4b3d;
--basil: #5aad70;
--cream: #f1d07d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #1c1613;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
color: inherit;
font: inherit;
}
#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;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: fixed;
top: 22px;
left: 22px;
width: min(410px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 18px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--mint);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-size: clamp(28px, 3vw, 43px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.brand p {
max-width: 345px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
position: fixed;
top: 22px;
right: 22px;
width: 238px;
padding: 16px;
border-radius: 16px;
}
.legend-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#selectionName {
color: var(--ink);
letter-spacing: 0;
text-transform: none;
}
.swatches {
display: grid;
gap: 7px;
}
.swatch {
display: flex;
align-items: center;
gap: 10px;
width: 100%;
padding: 8px 10px;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
transition:
border-color 160ms ease,
background 160ms ease,
transform 160ms ease;
}
.swatch:hover {
transform: translateX(-2px);
background: rgba(255, 255, 255, 0.065);
}
.swatch.active {
border-color: rgba(255, 255, 255, 0.28);
background: rgba(255, 255, 255, 0.09);
}
.swatch i {
width: 14px;
height: 14px;
flex: 0 0 auto;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}
.swatch span {
font-size: 12px;
font-weight: 650;
}
.legend-copy {
margin: 13px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.dock {
position: fixed;
bottom: 18px;
left: 50%;
width: min(1000px, calc(100vw - 36px));
transform: translateX(-50%);
padding: 12px;
border-radius: 19px;
}
.toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 2px 11px;
}
.toolbar-note {
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.toolbar-actions {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
}
.tool-button {
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: var(--ink);
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.tool-button:hover,
.tool-button.active {
border-color: rgba(136, 223, 207, 0.5);
background: rgba(136, 223, 207, 0.1);
}
.tool-button:active {
transform: translateY(1px);
}
.studies {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.study-card {
min-width: 0;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition:
border-color 180ms ease,
background 180ms ease,
transform 180ms ease;
}
.study-card:hover {
transform: translateY(-2px);
border-color: rgba(255, 255, 255, 0.25);
}
.study-card.active {
border-color: rgba(136, 223, 207, 0.7);
background: rgba(136, 223, 207, 0.09);
}
.study-meta {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
color: var(--mint);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.study-meta b {
display: inline-grid;
width: 20px;
height: 20px;
place-items: center;
border: 1px solid rgba(136, 223, 207, 0.4);
border-radius: 5px;
font-size: 10px;
}
.study-card h2 {
margin: 0 0 5px;
font-size: 15px;
font-weight: 680;
letter-spacing: -0.015em;
}
.study-copy {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.42;
}
.disclaimer {
margin: 9px 4px 0;
color: #aa9c8d;
font-size: 9.5px;
line-height: 1.35;
text-align: center;
}
.orbit-hint {
position: fixed;
bottom: 222px;
left: 50%;
transform: translateX(-50%);
padding: 7px 11px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 999px;
background: rgba(24, 18, 15, 0.56);
color: rgba(255, 255, 255, 0.65);
font-size: 10px;
pointer-events: none;
white-space: nowrap;
}
.world-label {
position: fixed;
z-index: 3;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(136, 223, 207, 0.34);
border-radius: 8px;
background: rgba(23, 19, 16, 0.78);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
color: var(--ink);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
}
.world-label span {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 4px;
background: var(--mint);
color: #18342f;
font-size: 10px;
letter-spacing: 0;
}
.world-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: linear-gradient(var(--mint), transparent);
content: "";
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 850px) {
.brand {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
padding: 14px 16px;
}
.brand p {
display: none;
}
.legend {
top: 12px;
right: 12px;
width: 185px;
padding: 12px;
}
.legend-copy {
display: none;
}
.dock {
bottom: 10px;
width: calc(100vw - 20px);
padding: 9px;
}
.toolbar-note {
display: none;
}
.toolbar-actions {
width: 100%;
justify-content: center;
}
.study-copy {
display: none;
}
.study-card {
padding: 10px;
}
.orbit-hint {
display: none;
}
}
@media (max-width: 570px) {
.brand {
width: calc(100vw - 24px);
}
.brand h1 {
font-size: 27px;
}
.legend {
top: 114px;
right: 12px;
width: 160px;
}
.swatch {
padding: 6px 8px;
}
.studies {
gap: 5px;
}
.study-card h2 {
font-size: 12px;
}
.study-meta {
font-size: 8px;
}
.disclaimer {
font-size: 8px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel culinary exhibit"></main>
<header class="brand panel">
<div class="eyebrow">Culinary form lab / field notes</div>
<h1>Sauce, meet geometry.</h1>
<p>
Three pasta forms show where colored sauce markers appear in channels,
near cavities, and across open faces.
</p>
</header>
<aside class="legend panel" aria-label="Sauce marker palette">
<div class="legend-heading">
Marker palette
<span id="selectionName">Tomato red</span>
</div>
<div class="swatches">
<button class="swatch active" data-sauce="tomato" aria-pressed="true">
<i style="background:#ed4b3d"></i>
<span>Tomato red</span>
</button>
<button class="swatch" data-sauce="basil" aria-pressed="false">
<i style="background:#5aad70"></i>
<span>Basil green</span>
</button>
<button class="swatch" data-sauce="cream" aria-pressed="false">
<i style="background:#f1d07d"></i>
<span>Golden cream</span>
</button>
</div>
<p class="legend-copy">
Select a color, then click a pasta surface to place a voxel marker.
</p>
</aside>
<div class="orbit-hint">
Drag to orbit · wheel to zoom · shift-drag to pan · click pasta to mark
</div>
<section class="dock panel" aria-label="Exhibit controls and comparisons">
<div class="toolbar">
<div class="toolbar-note">
A/B/C identify the three forms; they are not ranks.
</div>
<div class="toolbar-actions">
<button class="tool-button" id="overviewButton">Overview</button>
<button class="tool-button" id="replayButton">Replay markers</button>
<button class="tool-button active" id="guideButton" aria-pressed="true">
Guides on
</button>
</div>
</div>
<div class="studies">
<button class="study-card" data-focus="0" aria-label="Focus on grooved pasta">
<div class="study-meta"><b>A</b> Grooved exterior</div>
<h2>Surface grooves</h2>
<p class="study-copy">
A marker follows narrow channels and appears in broken, directional lines.
</p>
</button>
<button class="study-card" data-focus="1" aria-label="Focus on hollow pasta">
<div class="study-meta"><b>B</b> Open interior</div>
<h2>Cavity and mouth</h2>
<p class="study-copy">
A marker can sit near the opening or appear against an interior wall.
</p>
</button>
<button class="study-card" data-focus="2" aria-label="Focus on broad pasta">
<div class="study-meta"><b>C</b> Open plane</div>
<h2>Broad face</h2>
<p class="study-copy">
A marker reads as a wider, flatter patch when placed on an open surface.
</p>
</button>
</div>
<p class="disclaimer">
Qualitative placement demonstration only. This exhibit does not rank
adhesion, drainage, capacity, cooking quality, or overall performance.
</p>
</section>
<div class="world-label" id="labelA"><span>A</span>GROOVES</div>
<div class="world-label" id="labelB"><span>B</span>CAVITY</div>
<div class="world-label" id="labelC"><span>C</span>BROAD FACE</div>
<div id="status" class="sr-only" aria-live="polite"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Core scene
// ------------------------------------------------------------
const mount = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x1d1714);
scene.fog = new THREE.Fog(0x1d1714, 17, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
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",
"Voxel pasta exhibit. Drag to orbit and click pasta to add sauce markers."
);
mount.appendChild(renderer.domElement);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const tempMatrix = new THREE.Matrix4();
const tempQuaternion = new THREE.Quaternion();
const tempPosition = new THREE.Vector3();
const tempScale = new THREE.Vector3();
function addBox(parent, material, width, height, depth, x, y, z) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x211a17,
roughness: 0.92
}),
floorLine: new THREE.MeshBasicMaterial({
color: 0x4b3b31,
transparent: true,
opacity: 0.28
}),
wall: new THREE.MeshStandardMaterial({
color: 0x2a211d,
roughness: 0.95
}),
tileA: new THREE.MeshStandardMaterial({
color: 0x342923,
roughness: 0.88
}),
tileB: new THREE.MeshStandardMaterial({
color: 0x30251f,
roughness: 0.9
}),
pedestal: new THREE.MeshStandardMaterial({
color: 0x59483d,
roughness: 0.84
}),
pedestalTop: new THREE.MeshStandardMaterial({
color: 0x786253,
roughness: 0.72
}),
shelf: new THREE.MeshStandardMaterial({
color: 0x6b5140,
roughness: 0.8
}),
jar: new THREE.MeshStandardMaterial({
color: 0xd8c5a1,
roughness: 0.68
}),
guide: new THREE.MeshBasicMaterial({
color: 0x88dfcf,
transparent: true,
opacity: 0.68,
depthWrite: false
})
};
// Lighting
scene.add(new THREE.HemisphereLight(0xffe6c4, 0x33251f, 1.65));
const key = new THREE.DirectionalLight(0xffe5bd, 2.9);
key.position.set(-5, 10, 8);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 10;
key.shadow.camera.bottom = -8;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
key.shadow.bias = -0.0007;
scene.add(key);
scene.add(key.target);
const rim = new THREE.DirectionalLight(0x9fc8d4, 1.25);
rim.position.set(9, 5, -6);
scene.add(rim);
[-4.25, 0, 4.25].forEach((x, index) => {
const light = new THREE.PointLight(
index === 1 ? 0xffc785 : 0xffd5a1,
24,
8,
2
);
light.position.set(x, 4.2, 2.4);
scene.add(light);
});
// Gallery floor and tiled back wall
addBox(scene, materials.floor, 30, 0.4, 24, 0, -1, 0);
addBox(scene, materials.wall, 26, 8, 0.4, 0, 2.4, -7.1);
for (let x = -12; x <= 12; x += 2) {
addBox(scene, materials.floorLine, 0.018, 0.012, 22, x, -0.794, 0);
}
for (let z = -10; z <= 10; z += 2) {
addBox(scene, materials.floorLine, 28, 0.012, 0.018, 0, -0.793, z);
}
for (let row = 0; row < 5; row++) {
for (let col = 0; col < 13; col++) {
const tileMaterial = (row + col) % 2 ? materials.tileA : materials.tileB;
addBox(
scene,
tileMaterial,
1.86,
1.13,
0.07,
-11.5 + col * 1.93,
-0.15 + row * 1.2,
-6.86
);
}
}
// Voxel ingredient shelf
addBox(scene, materials.shelf, 8.5, 0.18, 0.7, 0, 4.65, -6.45);
const jarColors = [0xed4b3d, 0x5aad70, 0xf1d07d, 0x8a5b3d];
for (let i = 0; i < 4; i++) {
const x = -5.2 + i * 3.45;
const jarMaterial = new THREE.MeshStandardMaterial({
color: jarColors[i],
roughness: 0.65
});
addBox(scene, materials.jar, 0.58, 0.72, 0.58, x, 5.08, -6.43);
addBox(scene, jarMaterial, 0.43, 0.16, 0.43, x, 5.49, -6.43);
}
// ------------------------------------------------------------
// Pedestals and plaque textures
// ------------------------------------------------------------
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function makePlaqueTexture(letter, title) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRectPath(ctx, 8, 8, 496, 176, 24);
ctx.fillStyle = "rgba(28, 23, 19, 0.94)";
ctx.fill();
ctx.strokeStyle = "rgba(136, 223, 207, 0.48)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = "#88dfcf";
ctx.font = "800 64px system-ui, sans-serif";
ctx.fillText(letter, 35, 91);
ctx.fillStyle = "#f5ead7";
ctx.font = "750 34px system-ui, sans-serif";
ctx.fillText(title.toUpperCase(), 132, 87);
ctx.fillStyle = "rgba(245, 234, 215, 0.55)";
ctx.font = "500 20px system-ui, sans-serif";
ctx.fillText("QUALITATIVE SURFACE STUDY", 135, 125);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const exhibitNames = ["Grooves", "Cavity", "Broad Face"];
const exhibitXs = [-4.25, 0, 4.25];
const accentColors = [0xed4b3d, 0x8bd6c8, 0xf1d07d];
exhibitXs.forEach((x, index) => {
const pedestal = new THREE.Group();
pedestal.position.x = x;
scene.add(pedestal);
addBox(
pedestal,
materials.pedestal,
3.75,
0.78,
3.45,
0,
-0.42,
0
);
addBox(
pedestal,
materials.pedestalTop,
4,
0.16,
3.68,
0,
0.04,
0
);
const accent = new THREE.MeshStandardMaterial({
color: accentColors[index],
roughness: 0.6
});
addBox(
pedestal,
accent,
2.75,
0.07,
0.045,
0,
-0.47,
1.745
);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(1.85, 0.68),
new THREE.MeshBasicMaterial({
map: makePlaqueTexture("ABC"[index], exhibitNames[index]),
transparent: true,
depthWrite: false
})
);
plaque.position.set(0, -0.35, 1.76);
pedestal.add(plaque);
});
// ------------------------------------------------------------
// Voxel pasta construction
// ------------------------------------------------------------
const pastaMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.8,
metalness: 0
});
function createVoxelTube(options) {
const {
length = 3.1,
outer = 1.08,
inner = 0.51,
groove = 0.18,
sectors = 8,
phase = Math.PI / 8,
slant = 0,
hue = 0.105
} = options;
const spacing = 0.22;
const xCount = Math.floor(length / spacing);
const actualLength = xCount * spacing;
const gridRadius = Math.ceil(outer / spacing) + 1;
const descriptors = [];
for (let ix = 0; ix < xCount; ix++) {
const baseX = -actualLength / 2 + (ix + 0.5) * spacing;
for (let iy = -gridRadius; iy <= gridRadius; iy++) {
for (let iz = -gridRadius; iz <= gridRadius; iz++) {
const y = iy * spacing;
const z = iz * spacing;
const radius = Math.hypot(y, z);
const angle = Math.atan2(z, y);
const channel = Math.pow(
Math.max(0, -Math.cos(sectors * (angle - phase))),
10
);
const localOuter = outer - groove * channel;
if (radius < inner || radius > localOuter) {
continue;
}
const endDirection = baseX >= 0 ? 1 : -1;
const x = baseX + endDirection * (y / outer) * slant;
descriptors.push({ x, y, z, ix, iy, iz });
}
}
}
const mesh = new THREE.InstancedMesh(
unitBox,
pastaMaterial,
descriptors.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
const color = new THREE.Color();
descriptors.forEach((cell, index) => {
tempPosition.set(cell.x, cell.y, cell.z);
tempQuaternion.identity();
tempScale.set(
spacing * 0.97,
spacing * 0.97,
spacing * 0.97
);
tempMatrix.compose(tempPosition, tempQuaternion, tempScale);
mesh.setMatrixAt(index, tempMatrix);
const variation =
((cell.ix * 11 + cell.iy * 7 + cell.iz * 3) % 9) / 8;
color.setHSL(hue, 0.69, 0.64 + variation * 0.07);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
return { mesh, actualLength };
}
function broadHeight(x, z) {
return (
0.06 * Math.sin(x * 2.2) +
0.045 * Math.cos(z * 3.4) +
0.1 * Math.pow(Math.abs(x) / 1.72, 3)
);
}
function createBroadSheet() {
const xCount = 16;
const zCount = 10;
const spacing = 0.22;
const descriptors = [];
for (let ix = 0; ix < xCount; ix++) {
for (let iz = 0; iz < zCount; iz++) {
const x = (ix - (xCount - 1) / 2) * spacing;
const z = (iz - (zCount - 1) / 2) * spacing;
descriptors.push({ x, y: broadHeight(x, z), z, ix, iz });
}
}
const mesh = new THREE.InstancedMesh(
unitBox,
pastaMaterial,
descriptors.length
);
mesh.castShadow = true;
mesh.receiveShadow = true;
const color = new THREE.Color();
descriptors.forEach((cell, index) => {
tempPosition.set(cell.x, cell.y, cell.z);
tempQuaternion.identity();
tempScale.set(0.214, 0.13, 0.214);
tempMatrix.compose(tempPosition, tempQuaternion, tempScale);
mesh.setMatrixAt(index, tempMatrix);
const variation = ((cell.ix * 5 + cell.iz * 3) % 8) / 7;
color.setHSL(0.105, 0.62, 0.69 + variation * 0.055);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
return mesh;
}
const groupA = new THREE.Group();
groupA.position.set(-4.25, 1.25, 0);
groupA.rotation.y = -0.08;
scene.add(groupA);
const groupB = new THREE.Group();
groupB.position.set(0, 1.23, 0);
groupB.rotation.y = 0.14;
groupB.rotation.z = -0.055;
scene.add(groupB);
const groupC = new THREE.Group();
groupC.position.set(4.25, 0.42, 0);
groupC.rotation.y = -0.07;
scene.add(groupC);
const tubeA = createVoxelTube({
length: 3.12,
outer: 1.08,
inner: 0.5,
groove: 0.18,
sectors: 8,
phase: Math.PI / 8,
hue: 0.105
});
const tubeB = createVoxelTube({
length: 2.9,
outer: 0.91,
inner: 0.52,
groove: 0.075,
sectors: 6,
phase: Math.PI / 12,
slant: 0.55,
hue: 0.095
});
const broadSheet = createBroadSheet();
groupA.add(tubeA.mesh);
groupB.add(tubeB.mesh);
groupC.add(broadSheet);
const pastaGroups = [groupA, groupB, groupC];
const surfaceMeshes = [tubeA.mesh, tubeB.mesh, broadSheet];
surfaceMeshes.forEach((mesh, index) => {
mesh.userData.exhibitIndex = index;
});
// ------------------------------------------------------------
// Optional qualitative guide geometry
// ------------------------------------------------------------
function guideSegment(parent, from, to, thickness = 0.035) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(from, to)
.multiplyScalar(0.5);
const mesh = addBox(
parent,
materials.guide,
thickness,
thickness,
length,
midpoint.x,
midpoint.y,
midpoint.z
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
mesh.castShadow = false;
mesh.receiveShadow = false;
return mesh;
}
const guideGroups = [];
const guideA = new THREE.Group();
guideSegment(
guideA,
new THREE.Vector3(-1.35, 0.73, 0.73),
new THREE.Vector3(1.35, 0.73, 0.73),
0.04
);
groupA.add(guideA);
guideGroups.push(guideA);
const guideB = new THREE.Group();
const mouthX = tubeB.actualLength / 2 + 0.09;
addBox(guideB, materials.guide, 0.04, 0.045, 1.15, mouthX, 0.58, 0);
addBox(guideB, materials.guide, 0.04, 0.045, 1.15, mouthX, -0.58, 0);
addBox(guideB, materials.guide, 0.04, 1.15, 0.045, mouthX, 0, 0.58);
addBox(guideB, materials.guide, 0.04, 1.15, 0.045, mouthX, 0, -0.58);
groupB.add(guideB);
guideGroups.push(guideB);
const guideC = new THREE.Group();
const outlinePoints = [
new THREE.Vector3(-1.65, broadHeight(-1.65, -1) + 0.12, -1),
new THREE.Vector3(1.65, broadHeight(1.65, -1) + 0.12, -1),
new THREE.Vector3(1.65, broadHeight(1.65, 1) + 0.12, 1),
new THREE.Vector3(-1.65, broadHeight(-1.65, 1) + 0.12, 1),
new THREE.Vector3(-1.65, broadHeight(-1.65, -1) + 0.12, -1)
];
for (let i = 0; i < outlinePoints.length - 1; i++) {
const a = outlinePoints[i];
const b = outlinePoints[i + 1];
const segments = 9;
for (let segment = 0; segment < segments; segment++) {
const t0 = segment / segments;
const t1 = (segment + 1) / segments;
const p0 = a.clone().lerp(b, t0);
const p1 = a.clone().lerp(b, t1);
guideSegment(guideC, p0, p1, 0.035);
}
}
groupC.add(guideC);
guideGroups.push(guideC);
// ------------------------------------------------------------
// Sauce marker system
// ------------------------------------------------------------
const saucePalette = {
tomato: {
hex: 0xed4b3d,
label: "Tomato red"
},
basil: {
hex: 0x5aad70,
label: "Basil green"
},
cream: {
hex: 0xf1d07d,
label: "Golden cream"
}
};
const markerRoot = new THREE.Group();
scene.add(markerRoot);
const markerGeometry = new THREE.BoxGeometry(0.18, 0.18, 0.18);
const markerMaterials = {};
Object.entries(saucePalette).forEach(([key, value]) => {
markerMaterials[key] = new THREE.MeshStandardMaterial({
color: value.hex,
emissive: value.hex,
emissiveIntensity: 0.08,
roughness: 0.48,
metalness: 0
});
});
let markerRecords = [];
let selectedSauce = "tomato";
function addMarker(position, sauceKey, delay = 0) {
const group = new THREE.Group();
const mesh = new THREE.Mesh(
markerGeometry,
markerMaterials[sauceKey]
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
group.position.copy(position);
group.scale.setScalar(0.001);
markerRoot.add(group);
markerRecords.push({
group,
born: performance.now() + delay
});
}
function addLocalMarker(groupIndex, localPosition, sauceKey, delay = 0) {
const worldPosition = pastaGroups[groupIndex].localToWorld(
localPosition.clone()
);
addMarker(worldPosition, sauceKey, delay);
}
function resetMarkers() {
markerRoot.clear();
markerRecords = [];
}
function replayMarkers() {
resetMarkers();
scene.updateMatrixWorld(true);
const initialMarkers = [
[0, new THREE.Vector3(-1.12, 0.70, 0.70), "tomato"],
[0, new THREE.Vector3(-0.75, 0.70, 0.70), "tomato"],
[0, new THREE.Vector3(-0.37, 0.70, 0.70), "cream"],
[0, new THREE.Vector3(0.02, 0.70, 0.70), "tomato"],
[0, new THREE.Vector3(0.42, 0.70, 0.70), "basil"],
[0, new THREE.Vector3(0.82, 0.70, 0.70), "tomato"],
[1, new THREE.Vector3(1.58, 0.20, 0.32), "tomato"],
[1, new THREE.Vector3(1.37, 0.12, 0.18), "tomato"],
[1, new THREE.Vector3(1.70, 0.43, 0.36), "cream"],
[1, new THREE.Vector3(1.43, -0.35, 0.28), "basil"],
[2, new THREE.Vector3(-0.95, broadHeight(-0.95, -0.2) + 0.10, -0.2), "tomato"],
[2, new THREE.Vector3(-0.70, broadHeight(-0.70, -0.32) + 0.10, -0.32), "tomato"],
[2, new THREE.Vector3(-0.83, broadHeight(-0.83, 0.04) + 0.10, 0.04), "tomato"],
[2, new THREE.Vector3(-0.52, broadHeight(-0.52, -0.06) + 0.10, -0.06), "cream"],
[2, new THREE.Vector3(0.38, broadHeight(0.38, 0.32) + 0.10, 0.32), "basil"],
[2, new THREE.Vector3(0.62, broadHeight(0.62, 0.22) + 0.10, 0.22), "basil"],
[2, new THREE.Vector3(0.52, broadHeight(0.52, 0.48) + 0.10, 0.48), "cream"],
[2, new THREE.Vector3(1.02, broadHeight(1.02, -0.46) + 0.10, -0.46), "tomato"]
];
initialMarkers.forEach(([groupIndex, position, sauce], index) => {
addLocalMarker(groupIndex, position, sauce, index * 42);
});
setStatus("The qualitative marker demonstration has been replayed.");
}
// ------------------------------------------------------------
// Direct camera controls — no external control addon
// ------------------------------------------------------------
const controlsTarget = new THREE.Vector3(0, 1.15, 0);
const spherical = new THREE.Spherical();
let cameraTween = null;
function syncCamera() {
const offset = new THREE.Vector3().setFromSpherical(spherical);
camera.position.copy(controlsTarget).add(offset);
camera.lookAt(controlsTarget);
}
function setOverview() {
const narrow = window.innerWidth < 700;
const target = new THREE.Vector3(0, 1.15, 0);
const position = narrow
? new THREE.Vector3(10.5, 10, 25)
: new THREE.Vector3(9.4, 7.25, 16.3);
startCameraTween(position, target, 850);
setActiveCard(-1);
}
function startCameraTween(position, target, duration = 800) {
cameraTween = {
start: performance.now(),
duration,
fromPosition: camera.position.clone(),
toPosition: position.clone(),
fromTarget: controlsTarget.clone(),
toTarget: target.clone()
};
}
function focusExhibit(index) {
const narrow = window.innerWidth < 700;
const target = new THREE.Vector3(
exhibitXs[index],
index === 2 ? 0.56 : 1.2,
0
);
const offset = narrow
? new THREE.Vector3(5.8, 4.4, 8.8)
: new THREE.Vector3(4.8, 3.25, 6.7);
const position = target.clone().add(offset);
startCameraTween(position, target, 780);
setActiveCard(index);
setStatus(
`Focused on ${exhibitNames[index].toLowerCase()}. ${
[
"Observe how the marker follows recessed channels.",
"Observe the marker near the open mouth and interior wall.",
"Observe the marker as a wider patch on the open face."
][index]
}`
);
}
function setActiveCard(index) {
document.querySelectorAll(".study-card").forEach((card, i) => {
card.classList.toggle("active", i === index);
});
}
const canvas = renderer.domElement;
let pointerState = null;
canvas.addEventListener("pointerdown", (event) => {
cameraTween = null;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
pointerState = {
pointerId: event.pointerId,
lastX: event.clientX,
lastY: event.clientY,
moved: 0,
mode: event.button === 2 || event.shiftKey ? "pan" : "orbit"
};
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerState || event.pointerId !== pointerState.pointerId) {
return;
}
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
pointerState.moved += Math.abs(dx) + Math.abs(dy);
if (pointerState.mode === "orbit") {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.006,
0.22,
1.46
);
} else {
camera.updateMatrixWorld();
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrixWorld,
1
);
const scale = spherical.radius * 0.00125;
controlsTarget
.addScaledVector(right, -dx * scale)
.addScaledVector(up, dy * scale);
}
syncCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!pointerState || event.pointerId !== pointerState.pointerId) {
return;
}
const wasClick =
pointerState.mode === "orbit" && pointerState.moved < 7;
pointerState = null;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (wasClick) {
placeMarkerFromPointer(event);
}
});
canvas.addEventListener("pointercancel", () => {
pointerState = null;
canvas.classList.remove("dragging");
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween = null;
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
5.2,
29
);
syncCamera();
},
{ passive: false }
);
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
function placeMarkerFromPointer(event) {
const rect = canvas.getBoundingClientRect();
pointerNdc.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const hits = raycaster.intersectObjects(surfaceMeshes, false);
if (!hits.length) {
return;
}
const hit = hits[0];
const normal = hit.face.normal
.clone()
.transformDirection(hit.object.matrixWorld);
const position = hit.point.clone().addScaledVector(normal, 0.085);
addMarker(position, selectedSauce);
const label = exhibitNames[hit.object.userData.exhibitIndex];
setStatus(
`${saucePalette[selectedSauce].label} marker placed on ${label.toLowerCase()}.`
);
}
// ------------------------------------------------------------
// UI wiring
// ------------------------------------------------------------
function setStatus(message) {
document.getElementById("status").textContent = message;
}
document.querySelectorAll(".swatch").forEach((button) => {
button.addEventListener("click", () => {
selectedSauce = button.dataset.sauce;
document.querySelectorAll(".swatch").forEach((swatch) => {
const active = swatch === button;
swatch.classList.toggle("active", active);
swatch.setAttribute("aria-pressed", String(active));
});
document.getElementById("selectionName").textContent =
saucePalette[selectedSauce].label;
});
});
document.querySelectorAll(".study-card").forEach((card) => {
card.addEventListener("click", () => {
focusExhibit(Number(card.dataset.focus));
});
});
document.getElementById("overviewButton").addEventListener("click", setOverview);
document.getElementById("replayButton").addEventListener("click", replayMarkers);
const guideButton = document.getElementById("guideButton");
let guidesVisible = true;
guideButton.addEventListener("click", () => {
guidesVisible = !guidesVisible;
guideGroups.forEach((guide) => {
guide.visible = guidesVisible;
});
guideButton.classList.toggle("active", guidesVisible);
guideButton.setAttribute("aria-pressed", String(guidesVisible));
guideButton.textContent = guidesVisible ? "Guides on" : "Guides off";
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) {
return;
}
if (event.key === "1") focusExhibit(0);
if (event.key === "2") focusExhibit(1);
if (event.key === "3") focusExhibit(2);
if (event.key.toLowerCase() === "r") replayMarkers();
if (event.key.toLowerCase() === "g") guideButton.click();
if (event.key === "0" || event.key.toLowerCase() === "o") {
setOverview();
}
});
// ------------------------------------------------------------
// Projected world labels
// ------------------------------------------------------------
const labelData = [
{
element: document.getElementById("labelA"),
group: groupA,
anchor: new THREE.Vector3(0, 1.55, 0)
},
{
element: document.getElementById("labelB"),
group: groupB,
anchor: new THREE.Vector3(0, 1.55, 0)
},
{
element: document.getElementById("labelC"),
group: groupC,
anchor: new THREE.Vector3(0, 0.75, -0.75)
}
];
function updateWorldLabels() {
labelData.forEach((label) => {
const world = label.anchor
.clone()
.applyMatrix4(label.group.matrixWorld)
.project(camera);
const visible = world.z > -1 && world.z < 1;
label.element.style.visibility = visible ? "visible" : "hidden";
if (!visible) {
return;
}
const x = (world.x * 0.5 + 0.5) * window.innerWidth;
const y = (-world.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.fov = window.innerWidth < 700 ? 48 : 38;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
if (window.innerWidth < 700) {
controlsTarget.set(0, 1.15, 0);
camera.position.set(10.5, 10, 25);
} else {
controlsTarget.set(0, 1.15, 0);
camera.position.set(9.4, 7.25, 16.3);
}
spherical.setFromVector3(
camera.position.clone().sub(controlsTarget)
);
syncCamera();
scene.updateMatrixWorld(true);
replayMarkers();
function animate(now) {
requestAnimationFrame(animate);
if (cameraTween) {
const rawProgress = THREE.MathUtils.clamp(
(now - cameraTween.start) / cameraTween.duration,
0,
1
);
const eased =
rawProgress < 0.5
? 4 * rawProgress * rawProgress * rawProgress
: 1 -
Math.pow(-2 * rawProgress + 2, 3) / 2;
camera.position.lerpVectors(
cameraTween.fromPosition,
cameraTween.toPosition,
eased
);
controlsTarget.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
camera.lookAt(controlsTarget);
if (rawProgress >= 1) {
spherical.setFromVector3(
camera.position.clone().sub(controlsTarget)
);
cameraTween = null;
}
} else {
syncCamera();
}
markerRecords.forEach((record) => {
const progress = THREE.MathUtils.clamp(
(now - record.born) / 320,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
record.group.scale.setScalar(Math.max(0.001, eased));
});
camera.updateMatrixWorld();
scene.updateMatrixWorld();
updateWorldLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```