Prompt specification
Build or customize the Three.js 3D scene "Shared apartment kitchen reminders" 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: Shared apartment kitchen reminders
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shared-apartment-kitchen-reminders-x0035
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing refrigerator magnets. Build a kitchen corner with a notice-covered refrigerator, chore tokens, and shopping basket; animate one token moving from pending tasks into a finished column. Voxel style.
Working Three.js Starter (shared-apartment-kitchen-reminders-x0035):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Kitchen Corner</title>
<style>
:root {
--ink: #203c3a;
--cream: #fff9e9;
--coral: #ef705e;
--green: #4f9a78;
--panel: rgba(255, 249, 233, 0.91);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8e4dc;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 22px;
left: 24px;
z-index: 5;
pointer-events: none;
text-shadow: 0 2px 0 rgba(255, 255, 255, 0.45);
}
.eyebrow {
display: inline-block;
padding: 7px 10px;
border: 2px solid var(--ink);
background: var(--coral);
color: var(--cream);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
box-shadow: 4px 4px 0 rgba(32, 60, 58, 0.2);
}
.brand h1 {
margin: 10px 0 3px;
font-size: clamp(25px, 3.3vw, 48px);
line-height: 0.95;
letter-spacing: -0.045em;
}
.brand p {
margin: 8px 0 0;
font-size: 13px;
font-weight: 700;
opacity: 0.75;
}
.task-panel {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 6;
width: min(330px, calc(100vw - 48px));
padding: 17px;
border: 2px solid var(--ink);
background: var(--panel);
box-shadow: 7px 7px 0 rgba(32, 60, 58, 0.18);
backdrop-filter: blur(9px);
}
.task-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#taskState {
color: var(--coral);
}
#taskCount {
opacity: 0.55;
}
#taskName {
display: block;
margin: 10px 0 12px;
font-size: 21px;
line-height: 1.05;
letter-spacing: -0.025em;
}
.track {
height: 9px;
overflow: hidden;
border: 2px solid var(--ink);
background: #dfd7c6;
}
#taskProgress {
display: block;
width: 0%;
height: 100%;
background: var(--green);
transition: background 120ms linear;
}
#replayButton {
width: 100%;
margin-top: 13px;
padding: 10px 12px;
border: 2px solid var(--ink);
border-radius: 0;
background: var(--ink);
color: var(--cream);
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(32, 60, 58, 0.22);
transition: transform 100ms ease, box-shadow 100ms ease;
}
#replayButton:hover {
transform: translate(-1px, -1px);
box-shadow: 5px 5px 0 rgba(32, 60, 58, 0.22);
}
#replayButton:active {
transform: translate(2px, 2px);
box-shadow: 1px 1px 0 rgba(32, 60, 58, 0.22);
}
.controls {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
padding: 10px 13px;
border: 2px solid rgba(32, 60, 58, 0.7);
background: rgba(255, 249, 233, 0.78);
color: var(--ink);
font: 700 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
pointer-events: none;
backdrop-filter: blur(7px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #d8e4dc;
color: var(--ink);
font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.brand {
top: 14px;
left: 14px;
}
.brand p {
display: none;
}
.task-panel {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.controls {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="brand">
<div class="eyebrow">Voxel Pantry · No. 04</div>
<h1>Kitchen Corner</h1>
<p>Small reminders. Tiny victories.</p>
</header>
<section class="task-panel" aria-live="polite">
<div class="task-row">
<span id="taskState">In motion</span>
<span id="taskCount">2 / 4 done</span>
</div>
<strong id="taskName">Load the dishwasher</strong>
<div class="track" aria-hidden="true">
<span id="taskProgress"></span>
</div>
<button id="replayButton" type="button">↻ Replay magnet</button>
</section>
<aside class="controls">
Drag to orbit · Scroll to zoom<br />
Click the moving magnet · R to reset
</aside>
<div id="loading">Building the kitchen…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8e4dc);
scene.fog = new THREE.Fog(0xd8e4dc, 23, 40);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.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",
"Interactive voxel kitchen with a refrigerator, chore board, and shopping basket"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const controls = {
yaw: 0.63,
pitch: 0.49,
zoom: 1,
target: new THREE.Vector3(-0.2, 2.45, -0.35)
};
function updateCamera() {
const radius = 18;
const { yaw, pitch, zoom, target } = controls;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(12.8, 19.5 / aspect) / zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7df, 0x796b5e, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedc7, 3.15);
sun.position.set(-4.5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0xc9e9ff, 1.05);
coolFill.position.set(8, 6, -3);
scene.add(coolFill);
// -------------------------------------------------------------------------
// Materials and reusable geometry
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
}
const materials = {
floorBase: standard(0xb9aa91),
floorA: standard(0xf1e6d1),
floorB: standard(0xe3d7c0),
wall: standard(0xf0e6d4),
wallSide: standard(0xe7dac4),
trim: standard(0xfaf1df),
fridge: standard(0x9dc9c3, { roughness: 0.56 }),
fridgeDoor: standard(0xc2e1db, { roughness: 0.52 }),
fridgeEdge: standard(0x7eaaa6),
dark: standard(0x294441),
counter: standard(0xeacb94),
cabinet: standard(0x78a69a),
cabinetLight: standard(0x9ac0af),
wood: standard(0xb97b4c),
woodDark: standard(0x855638),
basket: standard(0xc58a53),
basketDark: standard(0x9b603b),
paper: standard(0xfff8df),
coral: standard(0xe9705d),
yellow: standard(0xe9bd4f),
teal: standard(0x4f9b87),
blue: standard(0x6098b5),
green: standard(0x69a45f),
red: standard(0xd95343),
milk: standard(0xf4f0df),
bread: standard(0xd7a261),
metal: standard(0xa8b3ad, { metalness: 0.35, roughness: 0.45 })
};
function box(parent, size, position, material, cast = true, receive = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addInstances(items, material) {
const mesh = new THREE.InstancedMesh(unitBox, material, items.length);
const dummy = new THREE.Object3D();
items.forEach((item, index) => {
dummy.position.set(...item.position);
dummy.scale.set(...item.size);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Canvas-generated textures
// -------------------------------------------------------------------------
function makeNoteTexture(text, accent = "#ef705e", background = "#fff8e5", ratio = 1) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = Math.max(128, Math.round(256 / ratio));
const ctx = canvas.getContext("2d");
const width = canvas.width;
const height = canvas.height;
const lines = text.split("\n");
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, width, 16);
ctx.strokeStyle = accent;
ctx.lineWidth = 8;
ctx.strokeRect(5, 5, width - 10, height - 10);
ctx.fillStyle = "#203c3a";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const fontSize = lines.length >= 4 ? 23 : lines.length === 3 ? 27 : 31;
const lineHeight = fontSize + 7;
const firstY = height / 2 - ((lines.length - 1) * lineHeight) / 2;
ctx.font = `800 ${fontSize}px ui-monospace, SFMono-Regular, Menlo, monospace`;
lines.forEach((line, index) => {
ctx.fillText(line, width / 2, firstY + index * lineHeight);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeBoardTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 474;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#efe6d3";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#294441";
ctx.lineWidth = 12;
ctx.strokeRect(7, 7, canvas.width - 14, canvas.height - 14);
ctx.fillStyle = "#294441";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "900 42px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("CHORE BOARD", 512, 55);
ctx.fillStyle = "#df725f";
ctx.fillRect(55, 93, 455, 58);
ctx.fillStyle = "#fff9e9";
ctx.font = "900 29px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.fillText("PENDING", 282, 123);
ctx.fillStyle = "#4f9979";
ctx.fillRect(585, 93, 382, 58);
ctx.fillText("FINISHED", 776, 123);
ctx.strokeStyle = "#b9ad96";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(552, 92);
ctx.lineTo(552, 440);
ctx.stroke();
const slots = [108, 290, 460, 654, 786, 934];
ctx.setLineDash([10, 9]);
ctx.strokeStyle = "#a99e88";
ctx.lineWidth = 4;
slots.forEach((x) => {
ctx.strokeRect(x - 65, 296, 130, 98);
});
ctx.setLineDash([]);
ctx.fillStyle = "#e9705d";
ctx.fillRect(485, 19, 20, 20);
ctx.fillStyle = "#e9bd4f";
ctx.fillRect(519, 19, 20, 20);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.magFilter = THREE.NearestFilter;
texture.minFilter = THREE.LinearMipmapLinearFilter;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function addNotice(parent, x, y, z, width, height, text, accent, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.rotation.z = rotation;
parent.add(group);
const texture = makeNoteTexture(
text,
accent,
"#fff8e5",
width / height
);
const paper = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture, toneMapped: false })
);
group.add(paper);
const magnetMaterial = standard(accent, { roughness: 0.5 });
box(
group,
[0.17, 0.17, 0.09],
[-width * 0.34, height * 0.38, 0.045],
magnetMaterial
);
return group;
}
// -------------------------------------------------------------------------
// Room shell and tiled floor
// -------------------------------------------------------------------------
box(scene, [16, 0.28, 13], [0, -0.18, 0.2], materials.floorBase, false, true);
const floorA = [];
const floorB = [];
for (let x = -7; x <= 7; x++) {
for (let z = -5.5; z <= 5.5; z++) {
const item = {
position: [x, -0.005, z],
size: [0.96, 0.07, 0.96]
};
if ((x + z) % 2 === 0) floorA.push(item);
else floorB.push(item);
}
}
addInstances(floorA, materials.floorA);
addInstances(floorB, materials.floorB);
box(scene, [16, 7.5, 0.3], [0, 3.65, -5.85], materials.wall);
box(scene, [0.3, 7.5, 13], [-7.85, 3.65, 0.15], materials.wallSide);
box(scene, [15.7, 0.18, 0.12], [0, 0.15, -5.64], materials.trim);
box(scene, [0.12, 0.18, 12.7], [-7.64, 0.15, 0.15], materials.trim);
// Voxel backsplash tiles.
const backsplashA = [];
const backsplashB = [];
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 17; col++) {
const item = {
position: [-2.4 + col * 0.58, 2.68 + row * 0.57, -5.665],
size: [0.54, 0.53, 0.06]
};
if ((row + col) % 2 === 0) backsplashA.push(item);
else backsplashB.push(item);
}
}
addInstances(backsplashA, standard(0xfaf2df));
addInstances(backsplashB, standard(0xe4d9c2));
// -------------------------------------------------------------------------
// Refrigerator
// -------------------------------------------------------------------------
box(scene, [2.7, 5.15, 2.15], [-4.85, 2.62, -4.48], materials.fridge);
box(scene, [2.82, 0.16, 2.23], [-4.85, 5.22, -4.48], materials.fridgeEdge);
box(scene, [2.48, 2.5, 0.14], [-4.85, 4.12, -3.34], materials.fridgeDoor);
box(scene, [2.48, 2.45, 0.14], [-4.85, 1.55, -3.34], materials.fridgeDoor);
box(scene, [2.5, 0.07, 0.08], [-4.85, 2.83, -3.22], materials.fridgeEdge);
box(scene, [0.11, 0.72, 0.13], [-3.84, 3.91, -3.19], materials.dark);
box(scene, [0.11, 0.72, 0.13], [-3.84, 1.78, -3.19], materials.dark);
box(scene, [0.18, 0.18, 0.2], [-5.83, 0.13, -3.62], materials.dark);
box(scene, [0.18, 0.18, 0.2], [-3.87, 0.13, -3.62], materials.dark);
addNotice(
scene,
-5.35,
4.35,
-3.22,
1.15,
1.32,
"GROCERY\nMILK + EGGS",
"#ef705e",
-0.045
);
addNotice(
scene,
-4.18,
3.68,
-3.215,
1.0,
1.02,
"CALL\nMOM",
"#e9bd4f",
0.045
);
addNotice(
scene,
-5.28,
1.78,
-3.215,
1.17,
1.12,
"LEAVE\nLATE",
"#4f9b87",
-0.035
);
addNotice(
scene,
-4.18,
1.25,
-3.215,
0.96,
0.76,
"PAY\nBILLS",
"#6098b5",
0.035
);
// Small individual refrigerator magnets.
box(scene, [0.22, 0.22, 0.12], [-4.73, 4.78, -3.17], materials.yellow);
box(scene, [0.18, 0.18, 0.12], [-4.45, 4.98, -3.17], materials.blue);
box(scene, [0.2, 0.2, 0.12], [-5.95, 2.45, -3.17], materials.teal);
// -------------------------------------------------------------------------
// Counter, cabinetry, sink, stove, and upper cabinets
// -------------------------------------------------------------------------
box(scene, [8.9, 2.05, 1.65], [2.05, 1.12, -4.68], materials.cabinet);
box(scene, [8.55, 0.18, 1.4], [2.05, 0.12, -4.75], materials.dark);
box(scene, [9.15, 0.18, 1.9], [2.05, 2.235, -4.63], materials.counter);
const cabinetXs = [-1.65, 0.65, 2.95, 5.25];
cabinetXs.forEach((x, index) => {
const color = index % 2 === 0 ? materials.cabinetLight : materials.cabinet;
box(scene, [1.9, 1.65, 0.08], [x, 1.18, -3.81], color);
box(scene, [0.55, 0.08, 0.11], [x, 1.72, -3.73], materials.dark);
});
// Square sink.
box(scene, [1.85, 0.045, 1.08], [-0.75, 2.35, -4.35], materials.dark, false, true);
box(scene, [1.95, 0.08, 0.10], [-0.75, 2.37, -4.88], materials.metal);
box(scene, [1.95, 0.08, 0.10], [-0.75, 2.37, -3.82], materials.metal);
box(scene, [0.10, 0.08, 1.05], [-1.69, 2.37, -4.35], materials.metal);
box(scene, [0.10, 0.08, 1.05], [0.19, 2.37, -4.35], materials.metal);
// Blocky faucet.
box(scene, [0.13, 0.72, 0.13], [-0.75, 2.72, -4.89], materials.metal);
box(scene, [0.13, 0.13, 0.56], [-0.75, 3.02, -4.62], materials.metal);
box(scene, [0.13, 0.32, 0.13], [-0.75, 2.88, -4.36], materials.metal);
// Stove and four voxel burners.
box(scene, [2.25, 0.09, 1.45], [4.65, 2.365, -4.35], materials.dark, false, true);
[-0.53, 0.53].forEach((dx) => {
[-0.34, 0.34].forEach((dz) => {
box(
scene,
[0.48, 0.025, 0.48],
[4.65 + dx, 2.425, -4.35 + dz],
materials.metal,
false,
true
);
});
});
[-0.65, -0.22, 0.22, 0.65].forEach((dx) => {
box(
scene,
[0.11, 0.08, 0.11],
[4.65 + dx, 2.45, -3.78],
materials.coral
);
});
// Upper cabinet.
box(scene, [1.55, 2.1, 0.75], [5.88, 4.75, -5.24], materials.cabinet);
box(scene, [0.73, 1.86, 0.08], [5.49, 4.75, -4.82], materials.cabinetLight);
box(scene, [0.73, 1.86, 0.08], [6.27, 4.75, -4.82], materials.cabinetLight);
box(scene, [0.07, 0.38, 0.11], [5.79, 4.65, -4.73], materials.dark);
box(scene, [0.07, 0.38, 0.11], [5.97, 4.65, -4.73], materials.dark);
// Small blocky plant.
box(scene, [0.55, 0.44, 0.55], [6.0, 2.56, -4.43], materials.coral);
box(scene, [0.62, 0.12, 0.62], [6.0, 2.82, -4.43], materials.woodDark);
box(scene, [0.2, 0.55, 0.2], [6.0, 3.13, -4.43], materials.dark);
box(scene, [0.48, 0.18, 0.3], [5.83, 3.32, -4.43], materials.green);
box(scene, [0.45, 0.18, 0.32], [6.18, 3.45, -4.43], materials.green);
box(scene, [0.25, 0.42, 0.25], [5.88, 3.65, -4.43], materials.teal);
// Mug.
box(scene, [0.43, 0.5, 0.43], [1.55, 2.6, -4.18], materials.paper);
box(scene, [0.13, 0.32, 0.13], [1.84, 2.62, -4.18], materials.paper);
box(scene, [0.13, 0.12, 0.13], [1.84, 2.78, -4.18], materials.paper);
box(scene, [0.13, 0.12, 0.13], [1.84, 2.46, -4.18], materials.paper);
// -------------------------------------------------------------------------
// Window on the side wall
// -------------------------------------------------------------------------
const glass = new THREE.Mesh(
new THREE.PlaneGeometry(2.72, 2.32),
new THREE.MeshBasicMaterial({ color: 0x91cbd3, toneMapped: false })
);
glass.rotation.y = Math.PI / 2;
glass.position.set(-7.68, 4.82, -1.48);
scene.add(glass);
box(scene, [0.18, 0.15, 2.95], [-7.62, 6.02, -1.48], materials.trim);
box(scene, [0.18, 0.15, 2.95], [-7.62, 3.62, -1.48], materials.trim);
box(scene, [0.18, 2.55, 0.15], [-7.62, 4.82, -2.88], materials.trim);
box(scene, [0.18, 2.55, 0.15], [-7.62, 4.82, -0.08], materials.trim);
box(scene, [0.18, 2.45, 0.11], [-7.59, 4.82, -1.48], materials.trim);
box(scene, [0.18, 0.11, 2.78], [-7.59, 4.82, -1.48], materials.trim);
// -------------------------------------------------------------------------
// Chore board and magnetic chore tokens
// -------------------------------------------------------------------------
box(scene, [5.4, 2.5, 0.18], [2.0, 4.55, -5.55], materials.wood);
const boardFace = new THREE.Mesh(
new THREE.PlaneGeometry(5.2, 2.28),
new THREE.MeshBasicMaterial({
map: makeBoardTexture(),
toneMapped: false
})
);
boardFace.position.set(2.0, 4.55, -5.447);
scene.add(boardFace);
function createToken(label, color) {
const group = new THREE.Group();
box(group, [0.72, 0.6, 0.12], [0, 0, 0], standard(color));
const texture = makeNoteTexture(label, "#ffffff", "#fff9e6", 1.4);
const face = new THREE.Mesh(
new THREE.PlaneGeometry(0.57, 0.4),
new THREE.MeshBasicMaterial({ map: texture, toneMapped: false })
);
face.position.z = 0.067;
group.add(face);
box(
group,
[0.14, 0.11, 0.13],
[0, 0.245, 0.085],
materials.dark
);
return group;
}
const pendingPosition = new THREE.Vector3(-0.02, 4.03, -5.34);
const finishedPosition = new THREE.Vector3(2.65, 4.03, -5.34);
const dogToken = createToken("DOG", 0xe9bd4f);
dogToken.position.set(0.88, 4.03, -5.34);
scene.add(dogToken);
const trashToken = createToken("TRASH", 0xef705e);
trashToken.position.set(1.7, 4.03, -5.34);
scene.add(trashToken);
const saltToken = createToken("SALT", 0x6098b5);
saltToken.position.set(3.4, 4.03, -5.34);
scene.add(saltToken);
const plantsToken = createToken("PLANTS", 0x4f9b87);
plantsToken.position.set(4.08, 4.03, -5.34);
scene.add(plantsToken);
const animatedToken = createToken("DISHES", 0xf0c95d);
animatedToken.position.copy(pendingPosition);
scene.add(animatedToken);
// -------------------------------------------------------------------------
// Shopping basket, rug, and groceries
// -------------------------------------------------------------------------
box(scene, [4.7, 0.05, 3.35], [4.0, 0.055, 2.0], standard(0xa8b89e), false, true);
box(scene, [4.25, 0.06, 2.9], [4.0, 0.082, 2.0], standard(0xd8c69d), false, true);
const basket = new THREE.Group();
basket.position.set(4.15, 0.105, 2.05);
basket.rotation.y = -0.14;
scene.add(basket);
box(basket, [2.62, 0.18, 1.78], [0, 0.13, 0], materials.basketDark);
// Front and back slats.
[-0.87, 0.87].forEach((z) => {
[0.43, 0.72, 1.01].forEach((y) => {
box(basket, [2.62, 0.12, 0.12], [0, y, z], materials.basket);
});
[-1.15, -0.78, -0.41, -0.04, 0.33, 0.70, 1.07].forEach((x) => {
box(basket, [0.11, 0.92, 0.11], [x, 0.67, z], materials.basket);
});
});
// Side slats.
[-1.25, 1.25].forEach((x) => {
[0.43, 0.72, 1.01].forEach((y) => {
box(basket, [0.12, 0.12, 1.7], [x, y, 0], materials.basket);
});
[-0.7, -0.35, 0, 0.35, 0.7].forEach((z) => {
box(basket, [0.11, 0.92, 0.11], [x, 0.67, z], materials.basket);
});
});
// Top rim.
box(basket, [2.72, 0.15, 0.15], [0, 1.11, -0.9], materials.basketDark);
box(basket, [2.72, 0.15, 0.15], [0, 1.11, 0.9], materials.basketDark);
box(basket, [0.15, 0.15, 1.82], [-1.28, 1.11, 0], materials.basketDark);
box(basket, [0.15, 0.15, 1.82], [1.28, 1.11, 0], materials.basketDark);
// Two squared-off basket handles.
[-0.95, 0.95].forEach((x) => {
box(basket, [0.11, 0.8, 0.11], [x, 1.46, -0.58], materials.basketDark);
box(basket, [0.11, 0.8, 0.11], [x, 1.46, 0.58], materials.basketDark);
box(basket, [0.11, 0.12, 1.28], [x, 1.82, 0], materials.basketDark);
});
// Milk carton.
box(basket, [0.58, 0.9, 0.58], [-0.58, 0.91, -0.12], materials.milk);
box(basket, [0.2, 0.13, 0.2], [-0.58, 1.42, -0.12], materials.blue);
box(basket, [0.44, 0.24, 0.025], [-0.58, 0.92, 0.181], materials.blue);
// Bread.
box(basket, [0.95, 0.48, 0.58], [0.43, 0.77, 0.13], materials.bread);
box(basket, [0.72, 0.05, 0.4], [0.43, 1.03, 0.13], materials.counter);
// Vegetables and apples.
box(basket, [0.34, 0.34, 0.34], [-0.08, 1.13, -0.35], materials.green);
box(basket, [0.32, 0.32, 0.32], [0.13, 1.18, -0.39], materials.green);
box(basket, [0.3, 0.3, 0.3], [0.35, 1.16, -0.4], materials.teal);
box(basket, [0.32, 0.32, 0.32], [0.78, 1.08, 0.25], materials.red);
box(basket, [0.3, 0.3, 0.3], [0.39, 1.12, 0.48], materials.red);
// -------------------------------------------------------------------------
// Chore-token animation
// -------------------------------------------------------------------------
const taskState = document.getElementById("taskState");
const taskCount = document.getElementById("taskCount");
const taskProgress = document.getElementById("taskProgress");
const replayButton = document.getElementById("replayButton");
const animationDuration = 1850;
let animationStart = performance.now() + 550;
let animationEnd = animationStart + animationDuration;
let animationRunning = true;
function replayChore() {
animatedToken.position.copy(pendingPosition);
animatedToken.rotation.set(0, 0, 0);
animatedToken.scale.set(1, 1, 1);
animationStart = performance.now() + 280;
animationEnd = animationStart + animationDuration;
animationRunning = true;
taskState.textContent = "Ready";
taskState.style.color = "#df725f";
taskCount.textContent = "2 / 4 done";
taskProgress.style.width = "0%";
}
replayButton.addEventListener("click", replayChore);
function updateChore(now) {
if (!animationRunning) return;
if (now < animationStart) {
taskState.textContent = "Ready";
taskState.style.color = "#df725f";
taskProgress.style.width = "0%";
return;
}
taskState.textContent = "In motion";
taskState.style.color = "#df725f";
const raw = THREE.MathUtils.clamp(
(now - animationStart) / animationDuration,
0,
1
);
const eased = raw * raw * (3 - 2 * raw);
const arc = Math.sin(Math.PI * eased);
animatedToken.position.x = THREE.MathUtils.lerp(
pendingPosition.x,
finishedPosition.x,
eased
);
animatedToken.position.y =
THREE.MathUtils.lerp(pendingPosition.y, finishedPosition.y, eased) +
arc * 0.64;
animatedToken.position.z =
THREE.MathUtils.lerp(pendingPosition.z, finishedPosition.z, eased) +
arc * 0.68;
animatedToken.rotation.y = arc * 0.3;
animatedToken.rotation.z = arc * 0.08;
const snap =
raw > 0.82
? 1 + Math.sin(((raw - 0.82) / 0.18) * Math.PI) * 0.075
: 1;
animatedToken.scale.set(snap, snap, snap);
taskProgress.style.width = `${raw * 100}%`;
if (raw >= 1) {
animationRunning = false;
animatedToken.position.copy(finishedPosition);
animatedToken.rotation.set(0, 0, 0);
animatedToken.scale.set(1, 1, 1);
taskState.textContent = "Finished";
taskState.style.color = "#4f9979";
taskCount.textContent = "3 / 4 done";
taskProgress.style.width = "100%";
}
}
// -------------------------------------------------------------------------
// Direct camera controls: drag, wheel, touch, keyboard, and token clicking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let pointerDown = false;
let pointerX = 0;
let pointerY = 0;
let dragDistance = 0;
function resetCamera() {
controls.yaw = 0.63;
controls.pitch = 0.49;
controls.zoom = 1;
updateCamera();
}
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerX = event.clientX;
pointerY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.23,
1.03
);
updateCamera();
});
function checkTokenClick(event) {
if (dragDistance > 6) return;
const rect = canvas.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 hits = raycaster.intersectObject(animatedToken, true);
if (hits.length) replayChore();
}
canvas.addEventListener("pointerup", (event) => {
checkTokenClick(event);
pointerDown = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.85
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
if (event.code === "Space") {
event.preventDefault();
replayChore();
}
});
function resize() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateCamera();
}
window.addEventListener("resize", resize);
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function frame(now) {
requestAnimationFrame(frame);
updateChore(now);
renderer.render(scene, camera);
}
requestAnimationFrame(frame);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
});
</script>
</body>
</html>
```