Prompt specification
Build or customize the Three.js 3D scene "Tea tasting arrangement" 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: Tea tasting arrangement
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/tea-tasting-arrangement-x0159
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing tea infusion. Build a tray with three cups, timers, loose leaves, and teapot; an illustrative steeping-time slider changes color gradients without asserting specific flavor or health outcomes. Voxel style.
Working Three.js Starter (tea-tasting-arrangement-x0159):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="A voxel-style tea infusion study with three cups, timers, loose leaves, a teapot, and an illustrative color-time slider."
/>
<title>Infusion — A Voxel Tea Study</title>
<style>
:root {
--ink: #20322f;
--muted: #65706a;
--paper: #eee9dd;
--panel: rgba(247, 243, 232, 0.88);
--line: rgba(32, 50, 47, 0.17);
--green: #2f6f68;
--accent: #d97942;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e1d4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
display: block;
width: 100vw;
height: 100vh;
outline: none;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
#scene:focus-visible {
outline: 3px solid rgba(47, 111, 104, 0.7);
outline-offset: -4px;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.intro {
position: absolute;
top: 28px;
left: 30px;
width: min(360px, calc(100vw - 60px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 21px;
height: 7px;
background: var(--green);
content: "";
box-shadow: 8px 0 0 rgba(47, 111, 104, 0.35);
}
h1 {
margin: 0;
font-size: clamp(31px, 4vw, 55px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
h1 em {
color: var(--green);
font-family: Georgia, "Times New Roman", serif;
font-weight: 500;
}
.intro p {
max-width: 310px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.palette-card {
position: absolute;
top: 28px;
right: 30px;
width: 218px;
padding: 15px 16px 14px;
border: 1px solid var(--line);
border-radius: 3px;
background: var(--panel);
box-shadow: 0 14px 36px rgba(48, 54, 46, 0.08);
backdrop-filter: blur(12px);
}
.palette-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.palette-title span:last-child {
color: var(--muted);
font-weight: 600;
letter-spacing: 0.04em;
text-transform: none;
}
.palette-bar {
position: relative;
height: 13px;
border: 1px solid rgba(32, 50, 47, 0.13);
background:
linear-gradient(
90deg,
#d7bd72 0%,
#e1bb59 27%,
#c98231 53%,
#9d4829 76%,
#64292a 100%
);
}
.palette-marker {
position: absolute;
top: -5px;
left: 58%;
width: 3px;
height: 21px;
background: var(--ink);
box-shadow: 0 0 0 2px rgba(247, 243, 232, 0.9);
transform: translateX(-50%);
}
.palette-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.controls {
position: absolute;
right: 30px;
bottom: 28px;
left: 30px;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 22px 28px;
align-items: center;
max-width: 970px;
margin: 0 auto;
padding: 18px 20px 15px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(48, 54, 46, 0.11);
backdrop-filter: blur(15px);
pointer-events: auto;
}
.control-top {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 18px;
margin-bottom: 9px;
}
.control-top label {
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#time-output {
min-width: 72px;
color: var(--green);
font: 700 19px ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.range-wrap {
position: relative;
height: 25px;
}
input[type="range"] {
position: absolute;
inset: 0;
width: 100%;
height: 25px;
margin: 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 7px;
border-radius: 0;
background:
linear-gradient(
90deg,
#d7bd72 0%,
#e1bb59 27%,
#c98231 53%,
#9d4829 76%,
#64292a 100%
);
box-shadow: inset 0 0 0 1px rgba(32, 50, 47, 0.12);
}
input[type="range"]::-moz-range-track {
height: 7px;
border-radius: 0;
background:
linear-gradient(
90deg,
#d7bd72 0%,
#e1bb59 27%,
#c98231 53%,
#9d4829 76%,
#64292a 100%
);
box-shadow: inset 0 0 0 1px rgba(32, 50, 47, 0.12);
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 22px;
margin-top: -8px;
appearance: none;
border: 2px solid var(--ink);
border-radius: 1px;
background: #f8f3e7;
box-shadow: 3px 3px 0 rgba(32, 50, 47, 0.18);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 19px;
border: 2px solid var(--ink);
border-radius: 1px;
background: #f8f3e7;
box-shadow: 3px 3px 0 rgba(32, 50, 47, 0.18);
}
input[type="range"]:focus-visible {
outline: 2px solid var(--green);
outline-offset: 4px;
}
.range-scale {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: var(--muted);
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.buttons {
display: flex;
align-items: stretch;
gap: 7px;
align-self: stretch;
}
button {
min-width: 82px;
padding: 0 13px;
border: 1px solid rgba(32, 50, 47, 0.25);
border-radius: 2px;
background: transparent;
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition:
background 140ms ease,
color 140ms ease,
transform 140ms ease;
}
button:hover {
background: var(--ink);
color: #f7f2e7;
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 2px solid var(--green);
outline-offset: 2px;
}
#play {
border-color: var(--green);
background: var(--green);
color: #fff9e9;
}
#play:hover {
background: #245a54;
}
.control-note {
grid-column: 1 / -1;
margin: -7px 0 0;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.control-note strong {
color: var(--ink);
font-weight: 750;
}
.view-hint {
position: absolute;
right: 31px;
bottom: 153px;
color: rgba(32, 50, 47, 0.62);
font-size: 10px;
letter-spacing: 0.04em;
}
.fallback {
position: fixed;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: #e7e1d4;
color: var(--ink);
text-align: center;
z-index: 10;
}
.fallback strong {
display: block;
margin-bottom: 8px;
font-size: 22px;
}
@media (max-width: 760px) {
.intro {
top: 17px;
left: 17px;
}
.intro h1 {
font-size: 32px;
}
.intro p {
display: none;
}
.eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
.palette-card {
top: 17px;
right: 17px;
width: 145px;
padding: 11px;
}
.palette-title {
font-size: 8px;
}
.palette-title span:last-child {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: 1fr;
gap: 13px;
padding: 15px;
}
.buttons {
justify-content: flex-end;
}
button {
min-height: 35px;
}
.control-note {
margin-top: -1px;
}
.view-hint {
display: none;
}
}
@media (max-height: 620px) and (min-width: 761px) {
.intro p,
.view-hint {
display: none;
}
.controls {
bottom: 16px;
padding-top: 13px;
padding-bottom: 11px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel tea infusion scene. Drag to orbit, scroll to zoom, or use arrow keys."
></canvas>
<div class="ui">
<header class="intro">
<div class="eyebrow">Voxel study / No. 03</div>
<h1>Infusion,<br /><em>step by step.</em></h1>
<p>
Three cups, a block-built teapot, loose leaves, and three sample clocks.
Move the slider to explore an abstract color progression.
</p>
</header>
<aside class="palette-card" aria-label="Abstract palette legend">
<div class="palette-title">
<span>Abstract palette</span>
<span>visual only</span>
</div>
<div class="palette-bar">
<span class="palette-marker" id="palette-marker"></span>
</div>
<div class="palette-labels">
<span>pale</span>
<span>deep</span>
</div>
</aside>
<div class="view-hint">Drag to orbit · scroll to zoom · double-click to reset</div>
<section class="controls" aria-label="Infusion study controls">
<div>
<div class="control-top">
<label for="steep">Illustrative steeping time</label>
<output id="time-output" for="steep">03:28</output>
</div>
<div class="range-wrap">
<input
id="steep"
type="range"
min="0"
max="100"
step="0.1"
value="58"
aria-describedby="study-note"
/>
</div>
<div class="range-scale" aria-hidden="true">
<span>00:00</span>
<span>03:00</span>
<span>06:00</span>
</div>
</div>
<div class="buttons">
<button id="play" type="button">▶ Animate</button>
<button id="reset" type="button">↺ Reset</button>
<button id="view" type="button">⌖ View</button>
</div>
<p class="control-note" id="study-note">
<strong>Visual sequence only.</strong>
Colors and clocks do not indicate flavor, quality, safety, or health
outcomes. The three sample clocks advance at different visual rates.
</p>
</section>
</div>
<div class="fallback" id="fallback">
<div>
<strong>WebGL could not start.</strong>
Please open this file in a browser with hardware acceleration enabled.
</div>
</div>
<noscript>
<div class="fallback" style="display: grid">
<div>
<strong>JavaScript is required.</strong>
Enable JavaScript to view the interactive tea study.
</div>
</div>
</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const fallback = document.querySelector("#fallback");
const slider = document.querySelector("#steep");
const output = document.querySelector("#time-output");
const playButton = document.querySelector("#play");
const resetButton = document.querySelector("#reset");
const viewButton = document.querySelector("#view");
const paletteMarker = document.querySelector("#palette-marker");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
fallback.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e7e1d4");
scene.fog = new THREE.Fog("#e7e1d4", 24, 43);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.65, 0);
let cameraYaw = 0.42;
let cameraPitch = 0.62;
let cameraZoom = 1;
const hemisphere = new THREE.HemisphereLight("#fff6df", "#6d685d", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0d1", 3.1);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#bfd9d2", 0.85);
fill.position.set(9, 7, -8);
scene.add(fill);
const materialCache = new Map();
function standardMaterial(color, metalness = 0) {
const key = `${color}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: metalness > 0 ? 0.38 : 0.84,
metalness
})
);
}
return materialCache.get(key);
}
function box(parent, size, position, color, options = {}) {
const geometry = new THREE.BoxGeometry(...size);
const material =
options.material || standardMaterial(color, options.metalness || 0);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
if (options.rotation) {
mesh.rotation.set(...options.rotation);
}
parent.add(mesh);
return mesh;
}
function canvasTexture(width, height) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = width;
textureCanvas.height = height;
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return {
canvas: textureCanvas,
context: textureCanvas.getContext("2d"),
texture
};
}
function formatClock(totalSeconds) {
const seconds = Math.max(0, Math.floor(totalSeconds));
const minutes = Math.floor(seconds / 60);
const remainder = seconds % 60;
return `${String(minutes).padStart(2, "0")}:${String(remainder).padStart(2, "0")}`;
}
// ------------------------------------------------------------
// Table, tray, and voxel scenery
// ------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
box(
world,
[20, 0.65, 14],
[0, -0.58, 0],
"#d2cbb9",
{ castShadow: false }
);
box(
world,
[19.2, 0.12, 13.2],
[0, -0.22, 0],
"#ddd5c2",
{ castShadow: false }
);
box(
world,
[14, 0.42, 7.4],
[0, 0, 0],
"#654735",
{ metalness: 0.03 }
);
box(
world,
[13.35, 0.12, 6.78],
[0, 0.25, 0],
"#cdbb96"
);
box(
world,
[14, 0.34, 0.28],
[0, 0.38, -3.55],
"#76513a"
);
box(
world,
[14, 0.34, 0.28],
[0, 0.38, 3.55],
"#76513a"
);
box(
world,
[0.28, 0.34, 7.4],
[-6.86, 0.38, 0],
"#76513a"
);
box(
world,
[0.28, 0.34, 7.4],
[6.86, 0.38, 0],
"#76513a"
);
const cornerPositions = [
[-6.84, -3.53],
[6.84, -3.53],
[-6.84, 3.53],
[6.84, 3.53]
];
for (const [x, z] of cornerPositions) {
box(world, [0.42, 0.43, 0.42], [x, 0.41, z], "#b48a4f", {
metalness: 0.35
});
}
// ------------------------------------------------------------
// Teapot
// ------------------------------------------------------------
const teapot = new THREE.Group();
teapot.position.set(0, 0.29, -2.25);
world.add(teapot);
box(teapot, [2.25, 0.22, 1.55], [0, 0.11, 0], "#244f4c");
box(teapot, [2.45, 1.15, 1.75], [0, 0.75, 0], "#2f6f68");
box(teapot, [2.53, 0.13, 1.82], [0, 1.19, 0], "#c89b55", {
metalness: 0.38
});
box(teapot, [1.95, 0.35, 1.45], [0, 1.43, 0], "#397d74");
box(teapot, [1.75, 0.18, 1.25], [0, 1.69, 0], "#d1aa62", {
metalness: 0.42
});
box(teapot, [1.30, 0.16, 0.90], [0, 1.86, 0], "#e1be75", {
metalness: 0.42
});
box(teapot, [0.38, 0.28, 0.38], [0, 2.08, 0], "#315d57");
// Stepped spout.
box(teapot, [0.82, 0.56, 0.64], [-1.48, 0.76, 0], "#2f6f68");
box(teapot, [0.90, 0.43, 0.52], [-2.00, 1.00, 0], "#397d74");
box(teapot, [0.62, 0.34, 0.43], [-2.48, 1.22, 0], "#4a8a7f");
box(
teapot,
[0.18, 0.22, 0.34],
[-2.72, 1.28, 0],
"#183d3b",
{ castShadow: false }
);
// Block handle.
box(teapot, [0.88, 0.18, 0.30], [1.67, 1.35, 0], "#397d74");
box(teapot, [0.88, 0.18, 0.30], [1.67, 0.53, 0], "#397d74");
box(teapot, [0.20, 1.00, 0.30], [2.08, 0.94, 0], "#397d74");
// Small teapot badge.
{
const label = canvasTexture(512, 160);
const ctx = label.context;
ctx.clearRect(0, 0, 512, 160);
ctx.fillStyle = "#eee0b7";
ctx.fillRect(0, 0, 512, 160);
ctx.fillStyle = "#2f6f68";
ctx.fillRect(0, 0, 18, 160);
ctx.fillStyle = "#20322f";
ctx.font = "700 44px Georgia, serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("STEPPED TEA", 269, 65);
ctx.font = "600 21px monospace";
ctx.fillStyle = "#66736d";
ctx.fillText("VOXEL INFUSION / 03", 269, 112);
label.texture.needsUpdate = true;
const badge = new THREE.Mesh(
new THREE.PlaneGeometry(1.36, 0.42),
new THREE.MeshBasicMaterial({
map: label.texture,
toneMapped: false
})
);
badge.position.set(0, 0.82, 0.887);
teapot.add(badge);
}
// ------------------------------------------------------------
// Voxel cups and abstract liquid shader
// ------------------------------------------------------------
const liquidVertexShader = `
varying float vHeight;
void main() {
vHeight = position.y / 0.75 + 0.5;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const liquidFragmentShader = `
uniform vec3 uDeep;
uniform vec3 uLight;
uniform float uOpacity;
varying float vHeight;
void main() {
float height = clamp(vHeight, 0.0, 1.0);
float steppedHeight = floor(height * 8.0) / 8.0;
float blendedHeight = mix(height, steppedHeight, 0.28);
vec3 color = mix(
uDeep,
uLight,
smoothstep(0.0, 1.0, blendedHeight)
);
gl_FragColor = vec4(color, uOpacity);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`;
const paletteStops = [
{
p: 0,
deep: new THREE.Color("#d7bd72"),
light: new THREE.Color("#f0e1b3")
},
{
p: 0.27,
deep: new THREE.Color("#c47d31"),
light: new THREE.Color("#e5bd5d")
},
{
p: 0.54,
deep: new THREE.Color("#a34c29"),
light: new THREE.Color("#ca7435")
},
{
p: 0.77,
deep: new THREE.Color("#78322a"),
light: new THREE.Color("#a74b2e")
},
{
p: 1,
deep: new THREE.Color("#4f2528"),
light: new THREE.Color("#7d302d")
}
];
function samplePalette(amount, deepTarget, lightTarget) {
const t = THREE.MathUtils.clamp(amount, 0, 1);
for (let i = 0; i < paletteStops.length - 1; i++) {
const a = paletteStops[i];
const b = paletteStops[i + 1];
if (t <= b.p) {
const f = (t - a.p) / (b.p - a.p);
deepTarget.copy(a.deep).lerp(b.deep, f);
lightTarget.copy(a.light).lerp(b.light, f);
return;
}
}
deepTarget.copy(paletteStops.at(-1).deep);
lightTarget.copy(paletteStops.at(-1).light);
}
function makeCupLabel(letter, color) {
const label = canvasTexture(256, 128);
const ctx = label.context;
ctx.clearRect(0, 0, 256, 128);
ctx.fillStyle = "rgba(248, 242, 226, 0.94)";
ctx.fillRect(0, 0, 256, 128);
ctx.fillStyle = color;
ctx.fillRect(0, 0, 20, 128);
ctx.fillStyle = "#20322f";
ctx.font = "800 76px Georgia, serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(letter, 140, 69);
label.texture.needsUpdate = true;
return new THREE.Mesh(
new THREE.PlaneGeometry(0.43, 0.25),
new THREE.MeshBasicMaterial({
map: label.texture,
transparent: true,
toneMapped: false
})
);
}
function makeTimer(letter) {
const group = new THREE.Group();
box(group, [1.55, 0.28, 0.78], [0, 0.14, 0], "#263f3b");
box(group, [1.45, 0.62, 0.43], [0, 0.55, 0], "#36514b");
const timer = canvasTexture(512, 256);
const ctx = timer.context;
const draw = (time) => {
ctx.fillStyle = "#10201e";
ctx.fillRect(0, 0, 512, 256);
ctx.strokeStyle = "#6dc29c";
ctx.lineWidth = 8;
ctx.strokeRect(8, 8, 496, 240);
ctx.fillStyle = "#6dc29c";
ctx.font = "700 28px monospace";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.fillText(`SAMPLE ${letter}`, 32, 31);
ctx.fillStyle = "#e8ffe7";
ctx.font = "700 105px monospace";
ctx.fillText(time, 31, 87);
timer.texture.needsUpdate = true;
};
draw("00:00");
const screen = new THREE.Mesh(
new THREE.PlaneGeometry(1.25, 0.50),
new THREE.MeshBasicMaterial({
map: timer.texture,
toneMapped: false
})
);
screen.position.set(0, 0.57, 0.222);
group.add(screen);
return {
group,
draw,
lastTime: ""
};
}
const cups = [];
function createCup(x, letter, ceramicColor, handleDirection) {
const group = new THREE.Group();
group.position.set(x, 0.3, 1.42);
world.add(group);
// Square ceramic mug.
box(group, [1.43, 0.18, 1.43], [0, 0.10, 0], ceramicColor);
box(group, [1.35, 1.07, 0.16], [0, 0.70, 0.63], ceramicColor);
box(group, [1.35, 1.07, 0.16], [0, 0.70, -0.63], ceramicColor);
box(group, [0.16, 1.07, 1.10], [0.60, 0.70, 0], ceramicColor);
box(group, [0.16, 1.07, 1.10], [-0.60, 0.70, 0], ceramicColor);
// Pixel-stepped handle.
const h = handleDirection;
box(group, [0.18, 0.78, 0.34], [h * 1.01, 0.73, 0], ceramicColor);
box(group, [0.43, 0.16, 0.34], [h * 0.81, 0.43, 0], ceramicColor);
box(group, [0.43, 0.16, 0.34], [h * 0.81, 1.04, 0], ceramicColor);
const liquidMaterial = new THREE.ShaderMaterial({
uniforms: {
uDeep: { value: new THREE.Color("#d7bd72") },
uLight: { value: new THREE.Color("#f0e1b3") },
uOpacity: { value: 0.91 }
},
vertexShader: liquidVertexShader,
fragmentShader: liquidFragmentShader,
transparent: true,
depthWrite: false,
side: THREE.FrontSide
});
const liquid = new THREE.Mesh(
new THREE.BoxGeometry(1.02, 0.75, 1.02),
liquidMaterial
);
liquid.position.y = 0.84;
liquid.renderOrder = 2;
group.add(liquid);
// Small surface tiles give the liquid a hand-built voxel finish.
const surfaceTiles = [];
const tilePositions = [
[-0.24, 0.06, -0.18, 0.18],
[0.20, 0.20, 0.12, 0.13],
[-0.04, -0.25, 0.18, 0.11]
];
for (const [tx, tz, tw, td] of tilePositions) {
const tileMaterial = new THREE.MeshBasicMaterial({
color: "#f0e1b3",
transparent: true,
opacity: 0.48,
depthWrite: false,
toneMapped: false
});
const tile = box(
group,
[tw, 0.025, td],
[tx, 1.217, tz],
"#ffffff",
{
material: tileMaterial,
castShadow: false,
receiveShadow: false
}
);
tile.renderOrder = 3;
surfaceTiles.push(tile);
}
// Front sample badge.
const badge = makeCupLabel(letter, ceramicColor);
badge.position.set(0, 0.72, 0.717);
group.add(badge);
// Timer behind each cup.
const timer = makeTimer(letter);
timer.group.position.set(0, 0.02, -1.02);
group.add(timer.group);
// Square steam voxels.
const steam = [];
for (let i = 0; i < 5; i++) {
const size = 0.11 + i * 0.025;
const steamMaterial = new THREE.MeshLambertMaterial({
color: "#fff8e9",
transparent: true,
opacity: 0.10,
depthWrite: false
});
const puff = box(
group,
[size, size, size],
[
Math.sin(i * 2.4) * 0.18,
1.54 + i * 0.29,
Math.cos(i * 1.7) * 0.14
],
"#ffffff",
{
material: steamMaterial,
castShadow: false,
receiveShadow: false
}
);
puff.renderOrder = 4;
puff.userData.baseY = puff.position.y;
puff.userData.baseX = puff.position.x;
puff.userData.baseOpacity = 0.075 + (4 - i) * 0.012;
steam.push(puff);
}
cups.push({
group,
liquidMaterial,
surfaceTiles,
timer,
steam,
letter,
deep: new THREE.Color(),
light: new THREE.Color()
});
}
createCup(-3.75, "A", "#e6d5ad", -1);
createCup(0, "B", "#d6e0cf", 1);
createCup(3.75, "C", "#dcae8b", -1);
// ------------------------------------------------------------
// Loose voxel leaves
// ------------------------------------------------------------
let seed = 83;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const leafColors = ["#6f5931", "#80643a", "#5e5930", "#8a7042", "#4f5530"];
for (let i = 0; i < 42; i++) {
let x = -6.1 + random() * 12.2;
let z = -0.95 + random() * 3.55;
// Keep leaves from appearing inside the mugs.
for (const cupX of [-3.75, 0, 3.75]) {
if (Math.abs(x - cupX) < 0.85 && Math.abs(z - 1.42) < 0.85) {
z = 2.72;
}
}
const leaf = new THREE.Group();
leaf.position.set(x, 0.345, z);
leaf.rotation.y = random() * Math.PI * 2;
const color = leafColors[Math.floor(random() * leafColors.length)];
box(
leaf,
[0.32, 0.055, 0.16],
[0, 0, 0],
color,
{ rotation: [0, 0, (random() - 0.5) * 0.18] }
);
box(
leaf,
[0.055, 0.035, 0.29],
[0.19, -0.005, 0],
"#927344",
{ rotation: [0, random() * 0.8, 0] }
);
world.add(leaf);
}
// A concentrated pile beside the teapot.
for (let i = 0; i < 18; i++) {
const leaf = new THREE.Group();
const angle = random() * Math.PI * 2;
const radius = random() * 0.65;
leaf.position.set(
2.25 + Math.cos(angle) * radius,
0.355 + random() * 0.08,
-0.95 + Math.sin(angle) * radius * 0.55
);
leaf.rotation.set(
(random() - 0.5) * 0.3,
random() * Math.PI * 2,
(random() - 0.5) * 0.4
);
const color = leafColors[Math.floor(random() * leafColors.length)];
box(leaf, [0.38, 0.06, 0.18], [0, 0, 0], color);
box(leaf, [0.07, 0.04, 0.30], [0.23, 0, 0], "#8c7042");
world.add(leaf);
}
// ------------------------------------------------------------
// State and illustrative progression
// ------------------------------------------------------------
const state = {
value: Number(slider.value),
playing: false
};
function sampleClockForCup(index, sliderAmount) {
const seconds = [
sliderAmount * 360,
90 + sliderAmount * 420,
210 + sliderAmount * 480
];
return seconds[index];
}
function applySlider(value) {
state.value = THREE.MathUtils.clamp(value, 0, 100);
const sliderAmount = state.value / 100;
slider.value = state.value.toFixed(1);
output.value = formatClock(sliderAmount * 360);
output.textContent = output.value;
paletteMarker.style.left = `${state.value}%`;
const cupAmounts = [
sliderAmount,
THREE.MathUtils.clamp(sliderAmount * 0.78 + 0.08, 0, 1),
THREE.MathUtils.clamp(sliderAmount * 0.57 + 0.20, 0, 1)
];
cups.forEach((cup, index) => {
samplePalette(cupAmounts[index], cup.deep, cup.light);
cup.liquidMaterial.uniforms.uDeep.value.copy(cup.deep);
cup.liquidMaterial.uniforms.uLight.value.copy(cup.light);
for (const tile of cup.surfaceTiles) {
tile.material.color.copy(cup.light);
}
const clock = formatClock(sampleClockForCup(index, sliderAmount));
if (clock !== cup.timer.lastTime) {
cup.timer.draw(clock);
cup.timer.lastTime = clock;
}
});
}
slider.addEventListener("input", () => {
state.playing = false;
playButton.textContent = "▶ Animate";
applySlider(Number(slider.value));
});
playButton.addEventListener("click", () => {
if (!state.playing && state.value >= 99.9) {
applySlider(0);
}
state.playing = !state.playing;
playButton.textContent = state.playing ? "Ⅱ Pause" : "▶ Animate";
});
resetButton.addEventListener("click", () => {
state.playing = false;
playButton.textContent = "▶ Animate";
applySlider(0);
});
// ------------------------------------------------------------
// Direct camera controls — no external controls addon
// ------------------------------------------------------------
function resetCamera() {
cameraYaw = 0.42;
cameraPitch = 0.62;
cameraZoom = 1;
updateCamera();
}
viewButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const fitHeight = Math.max(9.7, 14.9 / aspect);
const viewHeight = fitHeight / cameraZoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
const radius = 20;
camera.position.set(
cameraTarget.x +
Math.sin(cameraYaw) * Math.cos(cameraPitch) * radius,
cameraTarget.y + Math.sin(cameraPitch) * radius,
cameraTarget.z +
Math.cos(cameraYaw) * Math.cos(cameraPitch) * radius
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.005,
0.28,
1.25
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(event.deltaY * 0.001),
0.68,
1.7
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraYaw += 0.08;
break;
case "ArrowRight":
cameraYaw -= 0.08;
break;
case "ArrowUp":
cameraPitch = Math.min(1.25, cameraPitch + 0.06);
break;
case "ArrowDown":
cameraPitch = Math.max(0.28, cameraPitch - 0.06);
break;
case "+":
case "=":
cameraZoom = Math.max(0.68, cameraZoom - 0.08);
break;
case "-":
cameraZoom = Math.min(1.7, cameraZoom + 0.08);
break;
case "Home":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (state.playing) {
const nextValue = state.value + delta * 4.3;
if (nextValue >= 100) {
applySlider(100);
state.playing = false;
playButton.textContent = "▶ Animate";
} else {
applySlider(nextValue);
}
}
cups.forEach((cup, cupIndex) => {
cup.steam.forEach((puff, index) => {
const phase = elapsed * 1.15 + index * 0.82 + cupIndex * 0.55;
puff.position.y =
puff.userData.baseY + Math.sin(phase) * 0.075;
puff.position.x =
puff.userData.baseX + Math.sin(phase * 0.73) * 0.065;
puff.rotation.y += delta * (0.12 + index * 0.025);
puff.material.opacity =
puff.userData.baseOpacity *
(0.74 + 0.26 * Math.sin(phase * 0.85));
});
cup.surfaceTiles.forEach((tile, index) => {
tile.material.opacity =
0.38 + 0.13 * Math.sin(elapsed * 1.3 + index + cupIndex);
});
});
renderer.render(scene, camera);
}
applySlider(state.value);
updateCamera();
animate();
</script>
</body>
</html>
```