Prompt specification
Build or customize the Three.js 3D scene "Dining Room With Varied Furniture Scales" 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: Dining Room With Varied Furniture Scales
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/dining-room-with-varied-furniture-scales-x3739
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts character poses relative to furniture scale. Build a small fictional dining room where characters use appropriately scaled seats and tables. Show incompatible pairings as visible geometry problems rather than silently distorting bodies. Voxel style.
Working Three.js Starter (dining-room-with-varied-furniture-scales-x3739):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Cannery — Dining Scale Lab</title>
<style>
:root {
--ink: #27313b;
--paper: rgba(255, 252, 244, 0.92);
--green: #2f8b72;
--red: #db4b4b;
--amber: #d99a25;
--line: rgba(39, 49, 59, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e1d5;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
#stage,
#annotations {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#annotations {
pointer-events: none;
overflow: hidden;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 34px rgba(43, 49, 53, 0.12);
backdrop-filter: blur(12px);
}
#title-card {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 16px 18px 14px;
}
.eyebrow {
margin-bottom: 7px;
color: #75808a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 25px);
line-height: 1.05;
letter-spacing: -0.04em;
text-transform: uppercase;
}
.subtitle {
margin: 9px 0 0;
max-width: 350px;
color: #59646d;
font-size: 11px;
line-height: 1.5;
}
.rig-lock {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 12px;
padding: 6px 8px;
border: 1px solid rgba(47, 139, 114, 0.28);
background: rgba(47, 139, 114, 0.09);
color: #236c59;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.04em;
}
.rig-lock::before {
width: 7px;
height: 7px;
background: var(--green);
content: "";
}
#tools {
top: 18px;
right: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
width: min(390px, calc(100vw - 36px));
}
button {
border: 1px solid rgba(39, 49, 59, 0.17);
border-radius: 0;
padding: 9px 11px;
background: rgba(255, 252, 244, 0.94);
color: var(--ink);
cursor: pointer;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
letter-spacing: 0.025em;
text-transform: uppercase;
transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(39, 49, 59, 0.38);
}
button[aria-pressed="true"] {
border-color: rgba(47, 139, 114, 0.5);
background: rgba(47, 139, 114, 0.12);
color: #236c59;
}
#views {
bottom: 18px;
left: 50%;
display: flex;
gap: 5px;
padding: 6px;
transform: translateX(-50%);
white-space: nowrap;
}
#views button {
border-color: transparent;
background: transparent;
}
#views button.active {
border-color: rgba(39, 49, 59, 0.18);
background: #fffaf0;
}
#legend {
bottom: 18px;
left: 18px;
display: grid;
gap: 7px;
padding: 11px 13px;
font-size: 10px;
line-height: 1.2;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
}
.swatch.green {
background: var(--green);
}
.swatch.red {
background: var(--red);
}
.swatch.amber {
background: var(--amber);
}
.hint {
color: #7a838b;
}
.annotation {
position: absolute;
width: max-content;
max-width: 245px;
padding: 9px 10px 8px;
transform: translate(-50%, -100%);
border: 1px solid rgba(39, 49, 59, 0.18);
background: rgba(255, 252, 244, 0.94);
box-shadow: 0 7px 18px rgba(40, 45, 49, 0.11);
font-size: 10px;
line-height: 1.35;
white-space: nowrap;
}
.annotation::after {
position: absolute;
bottom: -5px;
left: calc(50% - 4px);
width: 8px;
height: 8px;
border-right: 1px solid rgba(39, 49, 59, 0.18);
border-bottom: 1px solid rgba(39, 49, 59, 0.18);
background: rgba(255, 252, 244, 0.94);
content: "";
transform: rotate(45deg);
}
.annotation strong {
display: block;
margin-bottom: 3px;
font-size: 10px;
letter-spacing: 0.03em;
text-transform: uppercase;
}
.annotation.compatible {
border-left: 4px solid var(--green);
}
.annotation.problem {
border-left: 4px solid var(--red);
}
.annotation.warning {
border-left: 4px solid var(--amber);
}
.annotation.compatible strong {
color: #236c59;
}
.annotation.problem strong {
color: #b53434;
}
.annotation.warning strong {
color: #9a6710;
}
@media (max-width: 780px) {
#title-card {
width: 270px;
}
.subtitle {
display: none;
}
#tools {
top: auto;
bottom: 70px;
right: 12px;
width: auto;
}
#legend {
display: none;
}
#views {
bottom: 12px;
max-width: calc(100vw - 24px);
overflow-x: auto;
}
.annotation {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="annotations"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Fictional interior · scale study 04</div>
<h1>The Cannery Dining Room</h1>
<p class="subtitle">
Two compatible table-and-seat sets share the room with deliberately
incompatible furniture. The characters remain rigid; collisions are shown.
</p>
<div class="rig-lock">RIG LOCK · ADULT BODY DIMENSIONS NEVER RESIZED</div>
</section>
<section id="tools" class="panel">
<button id="guides" aria-pressed="true">Scale guides</button>
<button id="problems" aria-pressed="true">Collision markers</button>
<button id="reset">Reset view</button>
</section>
<nav id="views" class="panel" aria-label="Camera views">
<button class="active" data-view="all">Overview</button>
<button data-view="adult">Adult set</button>
<button data-view="child">Child set</button>
<button data-view="high">High table</button>
<button data-view="narrow">Narrow seat</button>
</nav>
<aside id="legend" class="panel">
<div class="legend-row"><span class="swatch green"></span>Compatible fit</div>
<div class="legend-row"><span class="swatch red"></span>Body / table interference</div>
<div class="legend-row"><span class="swatch amber"></span>Body / seat interference</div>
<div class="hint">Drag to orbit · wheel to zoom</div>
</aside>
<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 annotationLayer = document.querySelector("#annotations");
const scene = new THREE.Scene();
scene.background = new THREE.Color("#e8e1d5");
scene.fog = new THREE.Fog("#e8e1d5", 19, 31);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel dining room showing character and furniture scale"
);
stage.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight("#fff8e9", "#8d9a9b", 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff1d3", 3.4);
sun.position.set(7, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b8d8df", 1.0);
fill.position.set(-8, 5, 2);
scene.add(fill);
const material = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0.0,
flatShading: true,
...extra
});
const M = {
floor: material("#d9cfbd"),
wall: material("#f2eadb"),
trim: material("#52616a"),
rugGreen: material("#b8d0bd"),
rugGray: material("#c7c7c0"),
wood: material("#b98255"),
woodLight: material("#d4a56d"),
woodDark: material("#76513d"),
teal: material("#327f78"),
tealDark: material("#235e5b"),
coral: material("#d96855"),
red: material("#d34d46"),
yellow: material("#e2b54b"),
navy: material("#33465b"),
pants: material("#3a4651"),
skin1: material("#d99a72"),
skin2: material("#9f6049"),
hair1: material("#382b28"),
hair2: material("#c08b45"),
black: material("#24292d"),
white: material("#fff9e9"),
blue: material("#8eb7c5"),
green: material("#4f8262"),
glass: material("#9fc4ce", { roughness: 0.35 }),
redProblem: material("#db4b4b", { emissive: "#8e1717", emissiveIntensity: 0.15 }),
amberProblem: material("#d99a25", { emissive: "#704400", emissiveIntensity: 0.12 })
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function outlined(mesh, color = "#26323a", opacity = 0.25) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
})
);
mesh.add(edges);
return mesh;
}
function segment(a, b, width, depth, mat, parent) {
const direction = b.clone().sub(a);
const mesh = box(width, direction.length(), depth, mat, 0, 0, 0, parent);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeTable(x, z, width, depth, topY, topMaterial = M.woodLight) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(width, 0.12, depth, topMaterial, 0, topY - 0.06, 0, group);
outlined(group.children[0], "#684b38", 0.18);
const legHeight = topY - 0.12;
const lx = width / 2 - 0.13;
const lz = depth / 2 - 0.13;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.13,
legHeight,
0.13,
M.woodDark,
sx * lx,
legHeight / 2,
sz * lz,
group
);
}
}
box(width - 0.22, 0.11, 0.11, M.woodDark, 0, topY - 0.24, 0, group);
return group;
}
function makeChair(x, z, seatY, seatDepth, width = 0.58, color = M.teal) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(width, 0.12, seatDepth, color, 0, seatY - 0.06, 0, group);
outlined(group.children[0], "#34464d", 0.2);
const backHeight = seatY + 0.63;
const backHeightBox = backHeight - seatY;
box(
width,
backHeightBox,
0.11,
color,
0,
seatY + backHeightBox / 2,
-seatDepth / 2 - 0.035,
group
);
outlined(group.children[1], "#34464d", 0.2);
const legInsetX = Math.max(0.045, width / 2 - 0.055);
const legInsetZ = Math.max(0.045, seatDepth / 2 - 0.055);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(
0.075,
seatY,
0.075,
M.woodDark,
sx * legInsetX,
seatY / 2,
sz * legInsetZ,
group
);
}
}
return group;
}
function makePlate(x, y, z, size = 0.28) {
box(size, 0.025, size, M.white, x, y + 0.014, z);
box(size * 0.62, 0.028, size * 0.62, M.blue, x, y + 0.03, z);
}
function makeCup(x, y, z, color = M.coral) {
box(0.13, 0.19, 0.13, color, x, y + 0.095, z);
box(0.09, 0.015, 0.09, M.black, x, y + 0.195, z);
box(0.055, 0.055, 0.055, color, x + 0.09, y + 0.1, z);
}
function makeSeatedCharacter({
x,
z,
scale = 1,
seatY,
tableY,
handWorldZ,
shirt,
pants = M.pants,
skin,
hair
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const s = scale;
const pelvisY = seatY + 0.12 * s;
const pelvis = box(
0.42 * s,
0.20 * s,
0.31 * s,
pants,
0,
pelvisY,
0.02 * s,
group
);
outlined(pelvis, "#26323a", 0.18);
const torso = box(
0.44 * s,
0.56 * s,
0.30 * s,
shirt,
0,
pelvisY + 0.34 * s,
0.01 * s,
group
);
outlined(torso, "#26323a", 0.17);
box(
0.13 * s,
0.10 * s,
0.13 * s,
skin,
0,
pelvisY + 0.67 * s,
0.02 * s,
group
);
const headY = pelvisY + 0.86 * s;
box(
0.29 * s,
0.31 * s,
0.28 * s,
skin,
0,
headY,
0.025 * s,
group
);
box(
0.31 * s,
0.10 * s,
0.30 * s,
hair,
0,
headY + 0.145 * s,
0.018 * s,
group
);
for (const eyeX of [-0.065, 0.065]) {
box(
0.035 * s,
0.038 * s,
0.018 * s,
M.black,
eyeX * s,
headY + 0.02 * s,
0.174 * s,
group
);
}
for (const side of [-1, 1]) {
const hip = new THREE.Vector3(
side * 0.13 * s,
pelvisY - 0.005 * s,
0.025 * s
);
const knee = new THREE.Vector3(
side * 0.13 * s,
pelvisY - 0.02 * s,
0.42 * s
);
const ankle = new THREE.Vector3(
side * 0.13 * s,
0.11 * s,
0.43 * s
);
segment(hip, knee, 0.18 * s, 0.18 * s, pants, group);
segment(knee, ankle, 0.145 * s, 0.15 * s, pants, group);
box(
0.18 * s,
0.12 * s,
0.30 * s,
M.black,
ankle.x,
0.06 * s,
ankle.z + 0.075 * s,
group
);
}
const handLocalZ = handWorldZ - z;
const handY = tableY + 0.065;
for (const side of [-1, 1]) {
const shoulder = new THREE.Vector3(
side * 0.30 * s,
pelvisY + 0.55 * s,
0.03 * s
);
const elbow = new THREE.Vector3(
side * 0.30 * s,
(shoulder.y + handY) * 0.5 - 0.025 * s,
handLocalZ * 0.53
);
const hand = new THREE.Vector3(
side * 0.30 * s,
handY,
handLocalZ
);
segment(shoulder, elbow, 0.13 * s, 0.14 * s, shirt, group);
segment(elbow, hand, 0.11 * s, 0.12 * s, skin, group);
box(
0.13 * s,
0.10 * s,
0.14 * s,
skin,
hand.x,
hand.y,
hand.z,
group
);
}
return group;
}
function makePlant(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
box(0.54, 0.45, 0.54, M.coral, 0, 0.225, 0, group);
box(0.43, 0.07, 0.43, M.woodDark, 0, 0.47, 0, group);
box(0.09, 1.18, 0.09, M.woodDark, 0, 1.02, 0, group);
box(0.56, 0.25, 0.34, M.green, -0.20, 1.13, 0, group);
box(0.43, 0.23, 0.36, M.green, 0.25, 1.42, 0.04, group);
box(0.38, 0.22, 0.34, M.green, -0.08, 1.73, -0.02, group);
box(0.45, 0.22, 0.35, M.green, 0.18, 1.92, 0, group);
}
function makePendant(x, z, color = M.yellow) {
box(0.035, 0.72, 0.035, M.black, x, 3.14, z);
box(0.55, 0.22, 0.55, color, x, 2.72, z);
box(0.34, 0.035, 0.34, M.white, x, 2.595, z);
}
// Room shell: a front and right cutaway keeps the furniture readable.
box(14, 0.24, 10, M.floor, 0, -0.12, 0);
box(14, 3.65, 0.18, M.wall, 0, 1.825, -5);
box(0.18, 3.65, 10, M.wall, -7, 1.825, 0);
box(14, 0.13, 0.13, M.trim, 0, 0.09, -4.86);
box(0.13, 0.13, 10, M.trim, -6.86, 0.09, 0);
const gridPositions = [];
for (let x = -7; x <= 7; x++) {
gridPositions.push(x, 0.008, -5, x, 0.008, 5);
}
for (let z = -5; z <= 5; z++) {
gridPositions.push(-7, 0.008, z, 7, 0.008, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
scene.add(
new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: "#b8ad9d",
transparent: true,
opacity: 0.25
})
)
);
// Low rugs divide the compatible and incompatible test areas.
box(5.45, 0.026, 3.55, M.rugGreen, -2.0, 0.015, -0.55);
box(5.15, 0.026, 3.55, M.rugGray, 3.45, 0.015, -0.55);
// Compatible adult set: 76 cm table, 46 cm seat.
makeTable(-3.55, -0.55, 2.75, 1.65, 0.76);
makeChair(-3.55, -1.68, 0.46, 0.55, 0.60, M.teal);
const oppositeAdultChair = makeChair(
-3.55,
0.58,
0.46,
0.55,
0.60,
M.tealDark
);
oppositeAdultChair.rotation.y = Math.PI;
makeSeatedCharacter({
x: -3.55,
z: -1.68,
scale: 1,
seatY: 0.46,
tableY: 0.76,
handWorldZ: -1.295,
shirt: M.teal,
pants: M.navy,
skin: M.skin1,
hair: M.hair1
});
makePlate(-3.55, 0.76, -0.65, 0.34);
makeCup(-4.55, 0.76, -0.45, M.coral);
makeCup(-2.58, 0.76, -0.45, M.blue);
// Compatible child set: 52 cm table, 35 cm seat.
makeTable(-0.45, -0.68, 1.35, 1.0, 0.52, M.yellow);
makeChair(-0.45, -1.55, 0.35, 0.43, 0.43, M.coral);
const oppositeChildChair = makeChair(
-0.45,
0.19,
0.35,
0.43,
0.43,
M.coral
);
oppositeChildChair.rotation.y = Math.PI;
makeSeatedCharacter({
x: -0.45,
z: -1.55,
scale: 0.68,
seatY: 0.35,
tableY: 0.52,
handWorldZ: -1.14,
shirt: M.yellow,
pants: M.red,
skin: M.skin2,
hair: M.hair2
});
makePlate(-0.45, 0.52, -0.68, 0.22);
makeCup(-0.92, 0.52, -0.59, M.teal);
// Incompatible set A: 108 cm table clips the same adult torso.
makeTable(2.10, -0.42, 1.80, 2.00, 1.08, M.redProblem);
makeChair(2.10, -1.52, 0.46, 0.55, 0.60, M.teal);
makeSeatedCharacter({
x: 2.10,
z: -1.52,
scale: 1,
seatY: 0.46,
tableY: 1.08,
handWorldZ: -1.34,
shirt: M.teal,
pants: M.navy,
skin: M.skin1,
hair: M.hair1
});
// Incompatible set B: a 30 cm seat is narrower than the adult hips.
makeTable(4.75, -0.55, 1.55, 1.50, 0.76);
makeChair(4.75, -1.65, 0.46, 0.55, 0.30, M.amberProblem);
makeSeatedCharacter({
x: 4.75,
z: -1.65,
scale: 1,
seatY: 0.46,
tableY: 0.76,
handWorldZ: -1.22,
shirt: M.teal,
pants: M.navy,
skin: M.skin1,
hair: M.hair1
});
// Background furniture and voxel decor.
box(2.55, 0.82, 0.48, M.wood, 0.55, 0.41, -4.52);
box(2.67, 0.10, 0.56, M.woodDark, 0.55, 0.87, -4.52);
for (const x of [-0.25, 0.55, 1.35]) {
box(0.65, 0.56, 0.035, M.woodLight, x, 0.46, -4.265);
box(0.08, 0.04, 0.05, M.black, x, 0.47, -4.235);
}
function wallArt(x, y, z, color) {
box(1.65, 1.13, 0.08, M.woodDark, x, y, z);
box(1.48, 0.96, 0.035, M.white, x, y, z + 0.055);
box(0.43, 0.55, 0.025, color, x - 0.34, y + 0.07, z + 0.085);
box(0.46, 0.24, 0.025, M.blue, x + 0.31, y - 0.18, z + 0.09);
box(0.31, 0.31, 0.025, M.yellow, x + 0.31, y + 0.27, z + 0.095);
}
wallArt(-3.55, 2.15, -4.86, M.coral);
wallArt(3.20, 2.22, -4.86, M.teal);
// Window on the left cutaway wall.
box(0.08, 1.60, 1.90, M.woodDark, -6.84, 2.08, -1.70);
box(0.09, 1.37, 1.67, M.glass, -6.77, 2.08, -1.70);
box(0.12, 1.48, 0.07, M.white, -6.70, 2.08, -1.70);
box(0.12, 0.07, 1.78, M.white, -6.70, 2.08, -1.70);
box(0.30, 0.13, 2.05, M.white, -6.68, 1.22, -1.70);
makePlant(6.25, -3.85);
makePendant(-3.55, -0.55, M.yellow);
makePendant(-0.45, -0.68, M.teal);
makePendant(2.10, -0.42, M.coral);
// Collision volumes: intentionally visible and not used to alter bodies.
const collisionGroup = new THREE.Group();
scene.add(collisionGroup);
const collisionMeshes = [];
function collisionBox(size, position, color) {
const group = new THREE.Group();
group.position.copy(position);
const fillMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.29,
depthTest: false,
depthWrite: false
});
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
fillMaterial
);
mesh.renderOrder = 20;
group.add(mesh);
collisionMeshes.push(mesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
edges.renderOrder = 21;
group.add(edges);
collisionGroup.add(group);
return group;
}
collisionBox(
new THREE.Vector3(0.52, 0.42, 0.22),
new THREE.Vector3(2.10, 1.00, -1.395),
"#db4b4b"
);
collisionBox(
new THREE.Vector3(0.11, 0.23, 0.34),
new THREE.Vector3(4.545, 0.58, -1.65),
"#d99a25"
);
collisionBox(
new THREE.Vector3(0.11, 0.23, 0.34),
new THREE.Vector3(4.955, 0.58, -1.65),
"#d99a25"
);
// Small voxel "contact fragments" emphasize the actual intersections.
for (const [x, y, z] of [
[1.88, 1.04, -1.38],
[2.28, 0.94, -1.42],
[2.05, 1.17, -1.39]
]) {
const fragment = box(0.10, 0.10, 0.10, M.redProblem, x, y, z, collisionGroup);
fragment.castShadow = false;
}
// Scale guides.
const guideGroup = new THREE.Group();
scene.add(guideGroup);
function lineSegments(points, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
line.renderOrder = 12;
guideGroup.add(line);
return line;
}
function verticalMeasure(x, z, y0, y1, color = "#2f8b72") {
lineSegments(
[
new THREE.Vector3(x, y0, z),
new THREE.Vector3(x, y1, z),
new THREE.Vector3(x - 0.10, y0, z),
new THREE.Vector3(x + 0.10, y0, z),
new THREE.Vector3(x - 0.10, y1, z),
new THREE.Vector3(x + 0.10, y1, z)
],
color
);
}
function horizontalMeasure(x0, x1, y, z, color = "#2f8b72") {
lineSegments(
[
new THREE.Vector3(x0, y, z),
new THREE.Vector3(x1, y, z),
new THREE.Vector3(x0, y, z - 0.08),
new THREE.Vector3(x0, y, z + 0.08),
new THREE.Vector3(x1, y, z - 0.08),
new THREE.Vector3(x1, y, z + 0.08)
],
color
);
}
verticalMeasure(-5.20, -0.55, 0, 0.76);
verticalMeasure(-3.95, -1.68, 0, 0.46);
verticalMeasure(-1.37, -0.68, 0, 0.52);
verticalMeasure(-0.92, -1.55, 0, 0.35);
verticalMeasure(0.95, -0.42, 0, 1.08, "#db4b4b");
verticalMeasure(5.55, -1.65, 0, 0.46, "#d99a25");
// Expected and actual table heights at the incompatible high table.
horizontalMeasure(1.22, 2.98, 0.76, -1.43, "#2f8b72");
horizontalMeasure(1.22, 2.98, 1.08, -1.43, "#db4b4b");
// Expected and actual seat widths at the incompatible narrow seat.
horizontalMeasure(4.475, 5.025, 0.51, -1.65, "#2f8b72");
horizontalMeasure(4.60, 4.90, 0.51, -1.65, "#d99a25");
// Projected HTML annotations.
const annotations = [];
function addAnnotation({
anchor,
title,
detail,
type = "compatible",
offset = 0,
problem = false
}) {
const element = document.createElement("div");
element.className = `annotation ${type}`;
element.innerHTML = `<strong>${title}</strong>${detail}`;
annotationLayer.appendChild(element);
annotations.push({
element,
anchor: anchor.clone(),
offset,
problem
});
}
addAnnotation({
anchor: new THREE.Vector3(-3.55, 1.03, -0.55),
title: "Compatible · Adult set",
detail: "76 cm table / 46 cm seat"
});
addAnnotation({
anchor: new THREE.Vector3(-0.45, 0.86, -0.68),
title: "Compatible · Child set",
detail: "52 cm table / 35 cm seat"
});
addAnnotation({
anchor: new THREE.Vector3(2.10, 1.43, -0.42),
title: "Problem · Table +32 cm",
detail: "Tabletop intersects upper torso",
type: "problem",
offset: -4,
problem: true
});
addAnnotation({
anchor: new THREE.Vector3(4.75, 1.02, -1.65),
title: "Problem · Seat −25 cm",
detail: "Seat sides intersect adult hips",
type: "warning",
offset: 8,
problem: true
});
// Camera controls implemented directly, without addons.
const overviewRadius = innerWidth / innerHeight < 0.8 ? 22 : 15.8;
const desired = {
theta: 0.31,
phi: 0.91,
radius: overviewRadius,
target: new THREE.Vector3(0, 0.78, -0.45)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const views = {
all: {
theta: 0.31,
phi: 0.91,
radius: overviewRadius,
target: [0, 0.78, -0.45]
},
adult: {
theta: 0.24,
phi: 0.98,
radius: 6.5,
target: [-3.25, 0.72, -0.75]
},
child: {
theta: 0.17,
phi: 1.00,
radius: 4.8,
target: [-0.45, 0.62, -0.90]
},
high: {
theta: 0.18,
phi: 1.00,
radius: 5.8,
target: [2.10, 0.86, -0.70]
},
narrow: {
theta: 0.13,
phi: 1.03,
radius: 4.9,
target: [4.75, 0.68, -1.05]
}
};
function focusView(name) {
const view = views[name];
desired.theta = view.theta;
desired.phi = view.phi;
desired.radius = view.radius;
desired.target.set(...view.target);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => focusView(button.dataset.view));
});
document.querySelector("#reset").addEventListener("click", () => focusView("all"));
const guidesButton = document.querySelector("#guides");
guidesButton.addEventListener("click", () => {
guideGroup.visible = !guideGroup.visible;
guidesButton.setAttribute("aria-pressed", String(guideGroup.visible));
});
const problemsButton = document.querySelector("#problems");
problemsButton.addEventListener("click", () => {
collisionGroup.visible = !collisionGroup.visible;
problemsButton.setAttribute("aria-pressed", String(collisionGroup.visible));
});
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.38,
1.38
);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.remove("active");
});
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
3.5,
27
);
},
{ passive: false }
);
function updateCamera() {
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, 0.09);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, 0.09);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, 0.09);
current.target.lerp(desired.target, 0.09);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
}
const projected = new THREE.Vector3();
function updateAnnotations() {
for (const annotation of annotations) {
if (annotation.problem && !collisionGroup.visible) {
annotation.element.hidden = true;
continue;
}
projected.copy(annotation.anchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
annotation.element.hidden = !visible;
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
annotation.element.style.marginTop = `${annotation.offset}px`;
}
}
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
collisionMeshes.forEach((mesh, index) => {
mesh.material.opacity =
0.23 + Math.sin(elapsed * 4.1 + index * 1.7) * 0.08;
});
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```