Prompt specification
Build or customize the Three.js 3D scene "Salad dressing comparison counter" 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: Salad dressing comparison counter
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/salad-dressing-comparison-counter-x0111
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts food emulsions. Arrange three dressing jars, ingredients, and salad bowls; show labeled simplified layered and dispersed states while users rotate each jar to inspect the droplet distribution. Stylized solid forms.
Working Three.js Starter (salad-dressing-comparison-counter-x0111):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Food Emulsions — Interactive Dressing Jars</title>
<style>
:root {
--ink: #24322c;
--muted: #69736c;
--paper: #f2eee4;
--panel: rgba(255, 253, 247, 0.84);
--line: rgba(36, 50, 44, 0.15);
--green: #47745c;
--oil: #e3a62f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage,
#labels {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels {
pointer-events: none;
overflow: hidden;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
max-width: 390px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4.5vw, 64px);
font-weight: 400;
line-height: 0.94;
letter-spacing: -0.055em;
}
header p {
max-width: 340px;
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.tools {
position: fixed;
top: 26px;
right: 28px;
z-index: 10;
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 9px 13px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
background: #fffdf7;
border-color: rgba(36, 50, 44, 0.35);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.legend {
position: fixed;
left: 30px;
bottom: 28px;
z-index: 5;
width: 188px;
padding: 15px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 8px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.oil {
background: #e6ae35;
}
.swatch.water {
background: #8dbb9d;
}
.swatch.coarse {
background: #dc8439;
}
.instruction {
position: fixed;
bottom: 28px;
left: 50%;
z-index: 6;
max-width: calc(100vw - 480px);
padding: 10px 16px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-align: center;
text-transform: uppercase;
transform: translateX(-50%);
backdrop-filter: blur(14px);
pointer-events: none;
white-space: nowrap;
}
.jar-label {
position: absolute;
display: grid;
grid-template-columns: 27px 1fr;
width: 166px;
padding: 9px 10px;
border: 1px solid rgba(36, 50, 44, 0.14);
border-radius: 13px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 0 8px 24px rgba(59, 61, 48, 0.09);
transform: translate(-50%, -100%);
transform-origin: center bottom;
cursor: pointer;
pointer-events: auto;
transition:
opacity 180ms ease,
border-color 180ms ease,
box-shadow 180ms ease;
backdrop-filter: blur(12px);
user-select: none;
}
.jar-label::after {
position: absolute;
bottom: -6px;
left: 50%;
width: 10px;
height: 10px;
border-right: 1px solid rgba(36, 50, 44, 0.14);
border-bottom: 1px solid rgba(36, 50, 44, 0.14);
background: rgba(255, 253, 247, 0.9);
content: "";
transform: translateX(-50%) rotate(45deg);
}
.jar-label:hover,
.jar-label.active {
border-color: rgba(71, 116, 92, 0.58);
box-shadow: 0 10px 30px rgba(59, 61, 48, 0.14);
}
.jar-number {
padding-top: 2px;
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
}
.jar-copy {
min-width: 0;
}
.jar-title {
display: flex;
align-items: center;
gap: 7px;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.jar-desc {
display: block;
overflow: hidden;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.3;
text-overflow: ellipsis;
white-space: nowrap;
}
.state-glyph {
width: 13px;
height: 13px;
flex: 0 0 auto;
border: 1px solid rgba(36, 50, 44, 0.15);
border-radius: 4px;
}
.state-glyph.layered {
background: linear-gradient(
to bottom,
#e6ae35 0 48%,
#8dbb9d 48% 100%
);
}
.state-glyph.dispersed {
background:
radial-gradient(circle at 25% 28%, #e0a22e 0 10%, transparent 11%),
radial-gradient(circle at 70% 22%, #e0a22e 0 8%, transparent 9%),
radial-gradient(circle at 35% 72%, #e0a22e 0 9%, transparent 10%),
radial-gradient(circle at 76% 68%, #e0a22e 0 10%, transparent 11%),
#dce9dc;
}
.state-glyph.coarse {
background:
radial-gradient(circle at 30% 35%, #dc8439 0 24%, transparent 25%),
radial-gradient(circle at 72% 67%, #dc8439 0 27%, transparent 28%),
#f3e1c7;
}
.scene-tag {
position: absolute;
padding: 6px 9px;
border-radius: 999px;
background: rgba(255, 253, 247, 0.72);
color: rgba(36, 50, 44, 0.65);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
transform: translate(-50%, -50%);
white-space: nowrap;
backdrop-filter: blur(8px);
pointer-events: none;
}
#labels.hidden {
opacity: 0;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: var(--paper);
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.out {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 19px;
left: 18px;
}
header p {
display: none;
}
h1 {
font-size: 36px;
}
.tools {
top: auto;
right: 16px;
bottom: 18px;
}
button {
padding: 8px 10px;
font-size: 8px;
}
.legend {
display: none;
}
.instruction {
bottom: 70px;
max-width: calc(100vw - 24px);
padding: 8px 12px;
font-size: 8px;
white-space: normal;
}
.jar-label {
width: 116px;
padding: 7px 8px;
grid-template-columns: 20px 1fr;
transform: translate(-50%, -100%) scale(0.82);
}
.jar-title {
gap: 5px;
font-size: 8px;
}
.jar-desc {
display: none;
}
.state-glyph {
width: 11px;
height: 11px;
}
.scene-tag {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels"></div>
<header>
<div class="eyebrow">Interactive specimen study</div>
<h1>Food<br>Emulsions</h1>
<p>
Three simplified dressing systems. Rotate each jar to inspect how
droplet size and distribution change the emulsion.
</p>
</header>
<nav class="tools" aria-label="Scene controls">
<button id="reset-jars" type="button">Reset jars</button>
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" type="button">Hide labels</button>
</nav>
<aside class="legend" aria-label="Phase legend">
<div class="legend-title">Phase key</div>
<div class="legend-row">
<span class="swatch oil"></span>
Oil-rich droplets
</div>
<div class="legend-row">
<span class="swatch water"></span>
Water-rich phase
</div>
<div class="legend-row">
<span class="swatch coarse"></span>
Coarse droplets
</div>
</aside>
<div class="instruction" id="instruction" aria-live="polite">
Drag a jar to rotate · Drag background to orbit · Scroll to zoom
</div>
<div id="loading">Preparing emulsion study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const labelsLayer = document.querySelector("#labels");
const instruction = document.querySelector("#instruction");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2eee4);
scene.fog = new THREE.Fog(0xf2eee4, 16, 31);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
stage.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional scene of three food-emulsion dressing jars"
);
renderer.domElement.tabIndex = 0;
const hemisphere = new THREE.HemisphereLight(
0xfffdf4,
0x8e927e,
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff5df, 3.15);
keyLight.position.set(6, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xd9ecff, 1.15);
fillLight.position.set(-7, 5, 3);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffddad, 0.85);
rimLight.position.set(1, 5, -8);
scene.add(rimLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.65,
metalness: 0,
...options
});
function addMesh(parent, geometry, material, position = [0, 0, 0]) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function () {
let t = (seed += 0x6d2b79f5);
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(83271);
const dropletGeometry = new THREE.SphereGeometry(1, 18, 12);
const leafGeometry = new THREE.SphereGeometry(1, 16, 10);
const hitTargets = [];
const jarGroups = [];
const jarAnchors = [];
const selectionRings = [];
const jarLabels = [];
const floorMaterial = standard(0xe8e3d7, { roughness: 0.94 });
const floor = addMesh(
scene,
new THREE.PlaneGeometry(40, 40),
floorMaterial,
[0, -0.025, 0]
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const platformMaterial = standard(0xf0eadc, { roughness: 0.86 });
const platform = addMesh(
scene,
new THREE.CylinderGeometry(5.75, 5.9, 0.17, 72),
platformMaterial,
[0, 0.075, -0.2]
);
platform.scale.z = 0.54;
platform.castShadow = false;
const platformEdge = addMesh(
scene,
new THREE.TorusGeometry(5.76, 0.025, 8, 96),
standard(0xb8aa8e, { roughness: 0.8 }),
[0, 0.155, -0.2]
);
platformEdge.rotation.x = Math.PI / 2;
platformEdge.scale.y = 0.54;
platformEdge.castShadow = false;
const dropletGold = standard(0xe5a82d, {
roughness: 0.32,
metalness: 0.02
});
const dropletOrange = standard(0xd9792e, {
roughness: 0.38,
metalness: 0
});
const dropletCream = standard(0xf1c35b, {
roughness: 0.3
});
function randomPoint(maxRadius) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random()) * maxRadius;
return [
Math.cos(angle) * radius,
Math.sin(angle) * radius
];
}
function addDroplet(parent, material, radius, x, y, z) {
const drop = addMesh(
parent,
dropletGeometry,
material,
[x, y, z]
);
drop.scale.setScalar(radius);
drop.renderOrder = 2;
return drop;
}
function makeGlassMaterial(tint) {
return new THREE.MeshPhysicalMaterial({
color: tint,
roughness: 0.12,
metalness: 0,
transparent: true,
opacity: 0.22,
side: THREE.DoubleSide,
depthWrite: false
});
}
const jarConfigs = [
{
number: "01",
title: "Layered",
description: "Two phases settled",
glyph: "layered",
x: -3.15,
z: -0.15,
accent: 0x496f59,
glass: 0xd7e9dc,
state: "layered"
},
{
number: "02",
title: "Dispersed",
description: "Fine droplets, even spread",
glyph: "dispersed",
x: 0,
z: 0.15,
accent: 0xb68432,
glass: 0xf1e3b9,
state: "dispersed"
},
{
number: "03",
title: "Coarse",
description: "Large droplets, slow settling",
glyph: "coarse",
x: 3.15,
z: -0.1,
accent: 0xa75f3c,
glass: 0xf0d6bc,
state: "coarse"
}
];
function makeJar(config, index) {
const group = new THREE.Group();
group.position.set(config.x, 0.17, config.z);
group.userData.index = index;
scene.add(group);
jarGroups.push(group);
const glassMaterial = makeGlassMaterial(config.glass);
const accentMaterial = standard(config.accent, {
roughness: 0.48,
metalness: 0.06
});
const body = addMesh(
group,
new THREE.CylinderGeometry(0.82, 0.82, 2.6, 48, 1, true),
glassMaterial,
[0, 1.55, 0]
);
body.castShadow = false;
body.renderOrder = 4;
const shoulder = addMesh(
group,
new THREE.CylinderGeometry(0.52, 0.82, 0.38, 48, 1, true),
glassMaterial,
[0, 3.04, 0]
);
shoulder.castShadow = false;
shoulder.renderOrder = 4;
const neck = addMesh(
group,
new THREE.CylinderGeometry(0.52, 0.52, 0.42, 48, 1, true),
glassMaterial,
[0, 3.44, 0]
);
neck.castShadow = false;
neck.renderOrder = 4;
addMesh(
group,
new THREE.CylinderGeometry(0.83, 0.83, 0.13, 48),
glassMaterial,
[0, 0.27, 0]
).renderOrder = 4;
addMesh(
group,
new THREE.CylinderGeometry(0.56, 0.56, 0.2, 48),
accentMaterial,
[0, 3.72, 0]
);
const capBand = addMesh(
group,
new THREE.TorusGeometry(0.555, 0.025, 10, 48),
standard(0xf3e5bd, { roughness: 0.45 }),
[0, 3.7, 0]
);
capBand.rotation.x = Math.PI / 2;
const bottomRim = addMesh(
group,
new THREE.TorusGeometry(0.82, 0.025, 10, 48),
accentMaterial,
[0, 0.34, 0]
);
bottomRim.rotation.x = Math.PI / 2;
const highlightMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.22,
depthWrite: false
});
for (let i = 0; i < 4; i++) {
const angle = 0.25 + i * Math.PI * 0.5;
const highlight = addMesh(
group,
new THREE.BoxGeometry(0.035, 1.72, 0.012),
highlightMaterial,
[Math.cos(angle) * 0.815, 1.63, Math.sin(angle) * 0.815]
);
highlight.rotation.y = -angle;
highlight.castShadow = false;
highlight.renderOrder = 5;
}
if (config.state === "layered") {
const lowerPhase = addMesh(
group,
new THREE.CylinderGeometry(0.705, 0.705, 0.79, 48),
standard(0x94bea0, {
transparent: true,
opacity: 0.74,
depthWrite: false,
roughness: 0.72
}),
[0, 0.74, 0]
);
lowerPhase.renderOrder = 1;
const upperPhase = addMesh(
group,
new THREE.CylinderGeometry(0.705, 0.705, 0.98, 48),
standard(0xe7b544, {
transparent: true,
opacity: 0.64,
depthWrite: false,
roughness: 0.6
}),
[0, 1.75, 0]
);
upperPhase.renderOrder = 1;
for (let i = 0; i < 25; i++) {
const [x, z] = randomPoint(0.58);
const band = i < 19 ? 1.17 : (random() > 0.5 ? 0.92 : 2.13);
const radius = 0.055 + random() * 0.055;
addDroplet(
group,
i % 3 === 0 ? dropletCream : dropletGold,
radius,
x,
band + (random() - 0.5) * 0.14,
z
);
}
} else if (config.state === "dispersed") {
const continuousPhase = addMesh(
group,
new THREE.CylinderGeometry(0.705, 0.705, 1.95, 48),
standard(0xd7e3c9, {
transparent: true,
opacity: 0.26,
depthWrite: false,
roughness: 0.75
}),
[0, 1.35, 0]
);
continuousPhase.renderOrder = 1;
for (let i = 0; i < 38; i++) {
const [x, z] = randomPoint(0.58);
const radius = 0.055 + random() * 0.055;
addDroplet(
group,
i % 5 === 0 ? dropletCream : dropletGold,
radius,
x,
0.53 + random() * 1.73,
z
);
}
} else {
const continuousPhase = addMesh(
group,
new THREE.CylinderGeometry(0.705, 0.705, 1.95, 48),
standard(0xead8b8, {
transparent: true,
opacity: 0.3,
depthWrite: false,
roughness: 0.72
}),
[0, 1.35, 0]
);
continuousPhase.renderOrder = 1;
for (let i = 0; i < 14; i++) {
const [x, z] = randomPoint(0.52);
const radius = 0.14 + random() * 0.075;
addDroplet(
group,
dropletOrange,
radius,
x,
0.58 + random() * 1.58,
z
);
}
}
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x47745c,
transparent: true,
opacity: 0.7
});
const ring = addMesh(
group,
new THREE.TorusGeometry(0.94, 0.025, 8, 64),
selectionMaterial,
[0, 0.04, 0]
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = false;
ring.visible = false;
selectionRings.push(ring);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false,
side: THREE.DoubleSide
});
const hitMesh = new THREE.Mesh(
new THREE.CylinderGeometry(0.9, 0.9, 3.75, 16),
hitMaterial
);
hitMesh.position.y = 1.95;
hitMesh.userData.jarIndex = index;
group.add(hitMesh);
hitTargets.push(hitMesh);
const anchor = new THREE.Object3D();
anchor.position.set(0, 4.18, 0);
group.add(anchor);
jarAnchors.push(anchor);
return group;
}
jarConfigs.forEach(makeJar);
const ceramicCream = standard(0xf3eee2, {
roughness: 0.7,
side: THREE.DoubleSide
});
const ceramicGreen = standard(0x879e86, {
roughness: 0.68,
side: THREE.DoubleSide
});
const leafGreen = standard(0x4d7a45, { roughness: 0.83 });
const leafLight = standard(0x7e9f54, { roughness: 0.85 });
const tomatoMaterial = standard(0xc9533b, { roughness: 0.45 });
const cucumberMaterial = standard(0x78a85b, { roughness: 0.67 });
const cucumberInner = standard(0xd5d99a, { roughness: 0.8 });
const stemMaterial = standard(0x47633c, { roughness: 0.9 });
function addLeaf(parent, position, scale, rotation, material = leafGreen) {
const leaf = addMesh(
parent,
leafGeometry,
material,
position
);
leaf.scale.set(scale[0], scale[1], scale[2]);
leaf.rotation.set(rotation[0], rotation[1], rotation[2]);
return leaf;
}
function addTomato(parent, position, radius = 0.18) {
const tomato = addMesh(
parent,
new THREE.SphereGeometry(radius, 20, 14),
tomatoMaterial,
position
);
tomato.scale.y = 0.9;
const stem = addMesh(
parent,
new THREE.CylinderGeometry(0.018, 0.025, 0.13, 8),
stemMaterial,
[position[0], position[1] + radius * 0.86, position[2]]
);
stem.rotation.z = 0.25;
return tomato;
}
function addCucumber(parent, position) {
const slice = addMesh(
parent,
new THREE.CylinderGeometry(0.17, 0.17, 0.065, 20),
cucumberMaterial,
position
);
addMesh(
parent,
new THREE.CylinderGeometry(0.135, 0.135, 0.068, 20),
cucumberInner,
[position[0], position[1] + 0.008, position[2]]
);
return slice;
}
function makeBowl(x, z, material, accent) {
const group = new THREE.Group();
group.position.set(x, 0.02, z);
scene.add(group);
const profile = [
new THREE.Vector2(0.06, 0),
new THREE.Vector2(0.55, 0.04),
new THREE.Vector2(0.92, 0.25),
new THREE.Vector2(1.16, 0.57),
new THREE.Vector2(1.12, 0.66),
new THREE.Vector2(1.04, 0.57),
new THREE.Vector2(0.82, 0.29),
new THREE.Vector2(0.45, 0.13),
new THREE.Vector2(0.06, 0.09)
];
const bowl = addMesh(
group,
new THREE.LatheGeometry(profile, 56),
material
);
bowl.receiveShadow = true;
const inner = addMesh(
group,
new THREE.LatheGeometry(profile, 56),
standard(accent, {
roughness: 0.78,
side: THREE.DoubleSide
}),
[0, 0.025, 0]
);
inner.scale.set(0.94, 0.93, 0.94);
const rim = addMesh(
group,
new THREE.TorusGeometry(1.115, 0.045, 12, 64),
material,
[0, 0.65, 0]
);
rim.rotation.x = Math.PI / 2;
const leafPositions = [
[-0.45, 0.44, -0.2, 0.24, 0.065, 0.4, 0.15, -0.4],
[0.15, 0.46, -0.34, 0.22, 0.06, 0.38, -0.2, 0.2],
[0.47, 0.43, -0.05, 0.25, 0.07, 0.42, 0.4, 0.5],
[-0.2, 0.48, 0.27, 0.23, 0.065, 0.4, 0.1, 1.0],
[0.38, 0.47, 0.31, 0.2, 0.055, 0.35, -0.15, 1.3],
[-0.58, 0.43, 0.2, 0.2, 0.055, 0.36, 0.55, 1.4]
];
leafPositions.forEach((p, i) => {
addLeaf(
group,
[p[0], p[1], p[2]],
[p[3], p[4], p[5]],
[p[6], p[7], p[8]],
i % 2 ? leafLight : leafGreen
);
});
addTomato(group, [-0.31, 0.67, 0.14], 0.19);
addTomato(group, [0.39, 0.66, -0.24], 0.17);
addTomato(group, [0.08, 0.68, 0.38], 0.16);
addCucumber(group, [-0.03, 0.7, -0.08]);
addCucumber(group, [0.52, 0.62, 0.18]);
addCucumber(group, [-0.61, 0.6, -0.04]);
const dressing = addMesh(
group,
new THREE.TorusGeometry(0.13, 0.024, 8, 32),
dropletGold,
[-0.18, 0.78, 0.05]
);
dressing.rotation.x = Math.PI / 2;
dressing.scale.set(1.55, 0.68, 1);
return group;
}
makeBowl(-2.55, 3.15, ceramicCream, 0xe6d8bd);
makeBowl(3.05, 3.35, ceramicGreen, 0xbdcaa8);
// Ingredient board.
const board = addMesh(
scene,
new THREE.CylinderGeometry(1.55, 1.55, 0.12, 56),
standard(0xa98258, { roughness: 0.86 }),
[4.75, 0.08, 2.35]
);
board.scale.set(1.05, 1, 0.72);
// Lemon and wedges.
const lemonGroup = new THREE.Group();
lemonGroup.position.set(-4.75, 0.63, 2.3);
lemonGroup.rotation.z = -0.28;
scene.add(lemonGroup);
const lemonMaterial = standard(0xe6bd31, { roughness: 0.67 });
const lemon = addMesh(
lemonGroup,
new THREE.SphereGeometry(0.68, 30, 20),
lemonMaterial
);
lemon.scale.set(1.15, 0.88, 0.92);
for (let i = 0; i < 7; i++) {
const angle = i * (Math.PI * 2 / 7);
const bump = addMesh(
lemonGroup,
new THREE.SphereGeometry(0.065, 10, 8),
lemonMaterial,
[
Math.cos(angle) * 0.64,
Math.sin(angle * 1.7) * 0.08,
Math.sin(angle) * 0.57
]
);
bump.scale.set(0.8, 0.8, 0.8);
}
const lemonTip = addMesh(
lemonGroup,
new THREE.ConeGeometry(0.075, 0.18, 12),
lemonMaterial,
[0.82, 0.02, 0]
);
lemonTip.rotation.z = -Math.PI / 2;
const wedgeMaterial = standard(0xf0c84c, { roughness: 0.72 });
for (let i = 0; i < 2; i++) {
const wedge = addMesh(
scene,
new THREE.CylinderGeometry(
0.43,
0.43,
0.075,
24,
1,
false,
i * Math.PI,
Math.PI / 2
),
wedgeMaterial,
[-4.15 + i * 0.34, 0.18, 3.15 - i * 0.22]
);
wedge.rotation.x = -Math.PI / 2;
wedge.rotation.z = i * 0.8;
}
// Avocado half.
const avocado = new THREE.Group();
avocado.position.set(4.65, 0.3, 2.18);
avocado.rotation.y = -0.4;
scene.add(avocado);
addMesh(
avocado,
new THREE.SphereGeometry(0.72, 28, 18),
standard(0x385a32, { roughness: 0.78 }),
[0, 0, 0]
).scale.set(0.78, 0.48, 1);
addMesh(
avocado,
new THREE.SphereGeometry(0.65, 28, 18),
standard(0xb8c56a, { roughness: 0.76 }),
[0, 0.28, 0]
).scale.set(0.69, 0.16, 0.86);
addMesh(
avocado,
new THREE.SphereGeometry(0.24, 20, 14),
standard(0x75452d, { roughness: 0.58 }),
[0, 0.43, 0.03]
);
// Loose herbs.
const herbGroup = new THREE.Group();
herbGroup.position.set(-0.55, 0.17, 2.75);
scene.add(herbGroup);
const herbData = [
[-0.3, 0.05, -0.1, 0.16, 0.045, 0.38, 0.1, 0.2, 0.4],
[0.18, 0.03, 0.2, 0.17, 0.045, 0.4, -0.15, -0.7, 0.2],
[0.35, 0.02, -0.25, 0.14, 0.04, 0.33, 0.1, 0.6, 0.1],
[-0.05, 0.02, 0.4, 0.15, 0.04, 0.35, 0.2, 1.1, 0.2]
];
herbData.forEach((p, i) => {
addLeaf(
herbGroup,
[p[0], p[1], p[2]],
[p[3], p[4], p[5]],
[p[6], p[7], p[8]],
i % 2 ? leafLight : leafGreen
);
});
// Small vinegar bottle.
const bottle = new THREE.Group();
bottle.position.set(5.05, 0.1, 0.65);
scene.add(bottle);
const amberGlass = new THREE.MeshPhysicalMaterial({
color: 0xa96f34,
roughness: 0.16,
transparent: true,
opacity: 0.62,
depthWrite: false
});
const bottleBody = addMesh(
bottle,
new THREE.CylinderGeometry(0.28, 0.31, 1.02, 32),
amberGlass,
[0, 0.57, 0]
);
bottleBody.castShadow = false;
addMesh(
bottle,
new THREE.CylinderGeometry(0.12, 0.17, 0.35, 24),
amberGlass,
[0, 1.24, 0]
).castShadow = false;
addMesh(
bottle,
new THREE.CylinderGeometry(0.15, 0.15, 0.18, 24),
standard(0x3e5847, { roughness: 0.55 }),
[0, 1.49, 0]
);
addMesh(
bottle,
new THREE.CylinderGeometry(0.312, 0.312, 0.42, 32),
standard(0xeee5d0, { roughness: 0.86 }),
[0, 0.6, 0]
);
// Small ingredient dish with salt.
const dish = new THREE.Group();
dish.position.set(1.2, 0.1, 2.55);
scene.add(dish);
addMesh(
dish,
new THREE.CylinderGeometry(0.52, 0.43, 0.23, 40),
ceramicCream,
[0, 0.12, 0]
);
addMesh(
dish,
new THREE.CylinderGeometry(0.38, 0.38, 0.04, 32),
standard(0xf4efe1, { roughness: 1 }),
[0, 0.25, 0]
);
// Projected scene tags.
const ingredientTag = document.createElement("div");
ingredientTag.className = "scene-tag";
ingredientTag.textContent = "Raw ingredients";
labelsLayer.appendChild(ingredientTag);
const saladTag = document.createElement("div");
saladTag.className = "scene-tag";
saladTag.textContent = "Salad assembly";
labelsLayer.appendChild(saladTag);
const ingredientAnchor = new THREE.Object3D();
ingredientAnchor.position.set(-4.45, 1.55, 2.5);
scene.add(ingredientAnchor);
const saladAnchor = new THREE.Object3D();
saladAnchor.position.set(0.3, 1.25, 3.55);
scene.add(saladAnchor);
jarConfigs.forEach((config, index) => {
const label = document.createElement("div");
label.className = "jar-label";
label.tabIndex = 0;
label.setAttribute("role", "button");
label.setAttribute(
"aria-label",
`${config.title} dressing jar. Drag horizontally to rotate.`
);
label.innerHTML = `
<span class="jar-number">${config.number}</span>
<span class="jar-copy">
<span class="jar-title">
<span class="state-glyph ${config.glyph}"></span>
${config.title}
</span>
<span class="jar-desc">${config.description}</span>
</span>
`;
const select = () => selectJar(index);
label.addEventListener("click", select);
label.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
select();
}
if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
event.preventDefault();
select();
const direction = event.key === "ArrowLeft" ? -1 : 1;
jarGroups[index].rotation.y += direction * 0.16;
}
});
labelsLayer.appendChild(label);
jarLabels.push(label);
});
let selectedJar = 0;
function selectJar(index) {
selectedJar = index;
jarLabels.forEach((label, i) => {
label.classList.toggle("active", i === index);
});
selectionRings.forEach((ring, i) => {
ring.visible = i === index;
});
const stateName = jarConfigs[index].title.toUpperCase();
instruction.textContent =
`Jar ${jarConfigs[index].number} selected · ${stateName} · Drag left / right to rotate`;
}
selectJar(0);
// Custom camera and direct-manipulation controls.
const cameraTarget = new THREE.Vector3(0, 1.35, -0.15);
let cameraAzimuth = 0.47;
let cameraPolar = 1.08;
let cameraRadius = 13.6;
let desiredAzimuth = cameraAzimuth;
let desiredPolar = cameraPolar;
let desiredRadius = cameraRadius;
function updateCamera() {
const portraitFactor = camera.aspect < 0.8 ? 1.2 : 1;
const radius = cameraRadius * portraitFactor;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPolar) * Math.sin(cameraAzimuth),
cameraTarget.y + radius * Math.cos(cameraPolar),
cameraTarget.z + radius * Math.sin(cameraPolar) * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let interactionMode = null;
let lastX = 0;
let lastY = 0;
let jarStartX = 0;
let jarStartY = 0;
let draggedJar = -1;
let hoveredJar = -1;
function jarAtPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(hitTargets, false);
return intersections.length
? intersections[0].object.userData.jarIndex
: -1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
const jarIndex = jarAtPointer(event);
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
if (jarIndex >= 0) {
interactionMode = "jar";
draggedJar = jarIndex;
selectJar(jarIndex);
jarStartX = jarGroups[jarIndex].rotation.x;
jarStartY = jarGroups[jarIndex].rotation.y;
renderer.domElement.style.cursor = "grabbing";
} else {
interactionMode = "camera";
renderer.domElement.style.cursor = "move";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!interactionMode) {
hoveredJar = jarAtPointer(event);
renderer.domElement.style.cursor = hoveredJar >= 0 ? "grab" : "default";
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (interactionMode === "jar" && draggedJar >= 0) {
const group = jarGroups[draggedJar];
group.rotation.y = jarStartY + dx * 0.012;
group.rotation.x = THREE.MathUtils.clamp(
jarStartX + dy * 0.005,
-0.28,
0.28
);
}
if (interactionMode === "camera") {
desiredAzimuth -= dx * 0.005;
desiredPolar = THREE.MathUtils.clamp(
desiredPolar - dy * 0.004,
0.62,
1.34
);
}
});
function endInteraction(event) {
interactionMode = null;
draggedJar = -1;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
renderer.domElement.style.cursor = hoveredJar >= 0 ? "grab" : "default";
}
renderer.domElement.addEventListener("pointerup", endInteraction);
renderer.domElement.addEventListener("pointercancel", endInteraction);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
desiredRadius = THREE.MathUtils.clamp(
desiredRadius + event.deltaY * 0.008,
8.5,
18
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", (event) => {
const index = jarAtPointer(event);
if (index >= 0) {
jarGroups[index].rotation.set(0, 0, 0);
selectJar(index);
}
});
function resetJars() {
jarGroups.forEach((group) => group.rotation.set(0, 0, 0));
selectJar(selectedJar);
}
function resetView() {
desiredAzimuth = 0.47;
desiredPolar = 1.08;
desiredRadius = 13.6;
instruction.textContent =
"Drag a jar to rotate · Drag background to orbit · Scroll to zoom";
}
document.querySelector("#reset-jars").addEventListener("click", resetJars);
document.querySelector("#reset-view").addEventListener("click", resetView);
const toggleLabelsButton = document.querySelector("#toggle-labels");
toggleLabelsButton.addEventListener("click", () => {
const hidden = labelsLayer.classList.toggle("hidden");
toggleLabelsButton.textContent = hidden ? "Show labels" : "Hide labels";
});
addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
if (event.shiftKey) {
resetView();
} else {
resetJars();
}
}
});
function projectElement(element, object) {
const worldPosition = new THREE.Vector3();
object.getWorldPosition(worldPosition);
worldPosition.project(camera);
const rect = renderer.domElement.getBoundingClientRect();
const visible = worldPosition.z >= -1 && worldPosition.z <= 1;
element.style.display = visible ? "" : "none";
element.style.left =
`${(worldPosition.x * 0.5 + 0.5) * rect.width}px`;
element.style.top =
`${(-worldPosition.y * 0.5 + 0.5) * rect.height}px`;
}
function updateLabels() {
jarLabels.forEach((label, index) => {
projectElement(label, jarAnchors[index]);
});
projectElement(ingredientTag, ingredientAnchor);
projectElement(saladTag, saladAnchor);
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.fov = innerWidth < 760 ? 46 : 36;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
updateCamera();
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.pow(0.001, delta);
cameraAzimuth += (desiredAzimuth - cameraAzimuth) * smoothing;
cameraPolar += (desiredPolar - cameraPolar) * smoothing;
cameraRadius += (desiredRadius - cameraRadius) * smoothing;
updateCamera();
const pulse = 1 + Math.sin(performance.now() * 0.003) * 0.025;
selectionRings.forEach((ring, index) => {
if (index === selectedJar) {
ring.scale.set(pulse, pulse, pulse);
ring.material.opacity = 0.58 + Math.sin(performance.now() * 0.003) * 0.13;
}
});
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("out");
});
</script>
</body>
</html>
```