Prompt specification
Build or customize the Three.js 3D scene "Family room conversation circle" 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: Family room conversation circle
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/family-room-conversation-circle-x0203
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a stylized family room with modular seating. Use several matching seat units around a low table, with a bookshelf against the back wall and a small toy basket near one corner. Offer two or three arrangements that face a shared conversation center while leaving the doorway and route to the shelf open. Animate the units moving between layouts without passing through each other. Keep the same furniture pieces in every arrangement so the change is spatial rather than a replacement of the room. Use warm upholstery, rounded solid shapes, and a high oblique camera that shows both faces and circulation space.
Working Three.js Starter (family-room-conversation-circle-x0203):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modular Family Room</title>
<style>
:root {
--ink: #302a25;
--muted: #776d63;
--paper: rgba(255, 251, 244, 0.91);
--line: rgba(84, 67, 51, 0.14);
--accent: #bb7048;
--accent-dark: #8e4f32;
--green: #617866;
--shadow: 0 18px 55px rgba(64, 45, 28, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9dfd1;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 22px;
pointer-events: none;
}
.intro,
.layout-panel {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.58);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.intro {
width: min(390px, 36vw);
padding: 21px 23px 20px;
border-radius: 22px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 3vw, 41px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.intro p {
margin: 13px 0 0;
max-width: 310px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.layout-panel {
width: min(470px, 49vw);
padding: 10px;
border-radius: 22px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px 10px;
}
.panel-heading span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel-heading strong {
color: var(--green);
font-size: 11px;
font-weight: 700;
}
.layouts {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.layout-button {
appearance: none;
border: 1px solid transparent;
border-radius: 15px;
background: transparent;
color: var(--ink);
padding: 10px 8px 11px;
cursor: pointer;
text-align: left;
transition:
background 180ms ease,
border-color 180ms ease,
transform 180ms ease;
}
.layout-button:hover:not(:disabled) {
background: rgba(188, 147, 111, 0.1);
transform: translateY(-1px);
}
.layout-button.active {
border-color: rgba(187, 112, 72, 0.38);
background: rgba(187, 112, 72, 0.12);
}
.layout-button:disabled {
cursor: wait;
opacity: 0.72;
}
.layout-button svg {
display: block;
width: 100%;
height: 54px;
margin-bottom: 6px;
overflow: visible;
}
.layout-button .name {
display: block;
font-size: 12px;
font-weight: 750;
}
.layout-button .description {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9.5px;
}
.status-panel {
position: fixed;
z-index: 10;
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 13px 16px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 16px;
background: rgba(255, 251, 244, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.status-row {
display: flex;
align-items: center;
gap: 9px;
}
.status-dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(97, 120, 102, 0.12);
}
.status-dot.moving {
background: var(--accent);
box-shadow: 0 0 0 4px rgba(187, 112, 72, 0.14);
animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
50% {
transform: scale(1.35);
}
}
#statusText {
font-size: 11px;
font-weight: 700;
letter-spacing: 0.015em;
}
.progress-track {
height: 3px;
margin-top: 10px;
overflow: hidden;
border-radius: 10px;
background: rgba(75, 58, 43, 0.1);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--accent), #d69b70);
transition: width 90ms linear;
}
.legend {
position: fixed;
z-index: 9;
right: 24px;
bottom: 25px;
display: flex;
align-items: center;
gap: 17px;
padding: 10px 14px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 14px;
background: rgba(255, 251, 244, 0.78);
color: var(--muted);
box-shadow: 0 12px 35px rgba(64, 45, 28, 0.09);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
pointer-events: none;
font-size: 10px;
font-weight: 700;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.route-key {
width: 23px;
height: 3px;
border-radius: 3px;
background: #c47c4f;
}
.clear-key {
width: 12px;
height: 12px;
border: 2px solid #71816d;
border-radius: 4px;
}
.hint {
position: fixed;
z-index: 8;
right: 25px;
top: 168px;
color: rgba(62, 52, 43, 0.55);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 780px) {
.topbar {
top: 12px;
left: 12px;
right: 12px;
flex-direction: column;
gap: 9px;
}
.intro {
width: 100%;
padding: 14px 17px;
border-radius: 17px;
}
.intro h1 {
font-size: 27px;
}
.intro p {
display: none;
}
.layout-panel {
width: 100%;
border-radius: 17px;
}
.panel-heading {
padding-bottom: 5px;
}
.layout-button {
padding: 6px 5px 8px;
}
.layout-button svg {
height: 40px;
}
.layout-button .description {
display: none;
}
.status-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.legend,
.hint {
display: none;
}
}
</style>
</head>
<body>
<header class="topbar">
<section class="intro">
<div class="eyebrow">Hearth / Modular study</div>
<h1>Conversation,<br>reconfigured.</h1>
<p>
Four matching lounge units share the same coffee-table center.
Choose a layout; every seat travels a planned path around the others.
</p>
</section>
<section class="layout-panel" aria-label="Furniture arrangements">
<div class="panel-heading">
<span>Choose an arrangement</span>
<strong>Entry → bookshelf stays open</strong>
</div>
<div class="layouts">
<button class="layout-button active" data-layout="0" type="button">
<svg viewBox="0 0 64 48" aria-hidden="true">
<rect x="20" y="14" width="24" height="20" rx="8" fill="#e9d5bd"/>
<rect x="25" y="18" width="14" height="12" rx="5" fill="#c98558"/>
<g fill="#bc754c">
<rect x="26" y="3" width="12" height="8" rx="3"/>
<rect x="26" y="37" width="12" height="8" rx="3"/>
<rect x="4" y="18" width="8" height="12" rx="3"/>
<rect x="52" y="18" width="8" height="12" rx="3"/>
</g>
</svg>
<span class="name">Square</span>
<span class="description">Balanced four-way</span>
</button>
<button class="layout-button" data-layout="1" type="button">
<svg viewBox="0 0 64 48" aria-hidden="true">
<rect x="21" y="14" width="22" height="20" rx="7" fill="#e9d5bd"/>
<rect x="26" y="18" width="12" height="12" rx="5" fill="#c98558"/>
<g fill="#bc754c">
<rect x="40" y="4" width="13" height="8" rx="3" transform="rotate(45 46 8)"/>
<rect x="40" y="36" width="13" height="8" rx="3" transform="rotate(-45 46 40)"/>
<rect x="7" y="36" width="13" height="8" rx="3" transform="rotate(45 13 40)"/>
<rect x="7" y="4" width="13" height="8" rx="3" transform="rotate(-45 13 8)"/>
</g>
</svg>
<span class="name">Diamond</span>
<span class="description">Open diagonal circle</span>
</button>
<button class="layout-button" data-layout="2" type="button">
<svg viewBox="0 0 64 48" aria-hidden="true">
<rect x="21" y="14" width="22" height="20" rx="7" fill="#e9d5bd"/>
<rect x="26" y="18" width="12" height="12" rx="5" fill="#c98558"/>
<g fill="#bc754c">
<rect x="24" y="3" width="13" height="8" rx="3" transform="rotate(7 30 7)"/>
<rect x="48" y="15" width="8" height="13" rx="3" transform="rotate(-12 52 21)"/>
<rect x="18" y="34" width="13" height="8" rx="3" transform="rotate(-8 24 38)"/>
<rect x="5" y="13" width="8" height="13" rx="3" transform="rotate(12 9 19)"/>
</g>
</svg>
<span class="name">Easy arc</span>
<span class="description">Relaxed, asymmetrical</span>
</button>
</div>
</section>
</header>
<div class="status-panel" aria-live="polite">
<div class="status-row">
<span id="statusDot" class="status-dot"></span>
<span id="statusText">Square arrangement ready</span>
</div>
<div class="progress-track">
<div id="progressFill"></div>
</div>
</div>
<div class="legend">
<span><i class="route-key"></i> Protected circulation</span>
<span><i class="clear-key"></i> Clear doorway</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</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, lighting, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9dfd1);
scene.fog = new THREE.Fog(0xe9dfd1, 24, 43);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 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;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.65, -0.25);
const defaultCamera = {
radius: 22.8,
theta: 0.57,
phi: 1.01
};
const orbit = { ...defaultCamera };
let dragging = false;
let previousPointer = { x: 0, y: 0 };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
Object.assign(orbit, defaultCamera);
updateCamera();
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointer = { x: event.clientX, y: event.clientY };
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
orbit.theta -= dx * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.004, 0.62, 1.16);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
18.5,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
const hemisphere = new THREE.HemisphereLight(0xfff3dc, 0x806b58, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4be, 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.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xcbd9e2, 0.75);
fill.position.set(10, 7, -9);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and reusable rounded geometry
// -------------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xe7dac7,
roughness: 0.92
}),
wallLower: new THREE.MeshStandardMaterial({
color: 0xc9c3ad,
roughness: 0.95
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd3ad7e,
roughness: 0.86
}),
wood: new THREE.MeshStandardMaterial({
color: 0x855b3d,
roughness: 0.72
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x624332,
roughness: 0.76
}),
upholstery: new THREE.MeshStandardMaterial({
color: 0xb96f49,
roughness: 0.9
}),
upholsteryLight: new THREE.MeshStandardMaterial({
color: 0xc98558,
roughness: 0.92
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf0e2ca,
roughness: 0.88
}),
rug: new THREE.MeshStandardMaterial({
color: 0xd9c8aa,
roughness: 1
}),
rugInset: new THREE.MeshStandardMaterial({
color: 0xcbb693,
roughness: 1
}),
green: new THREE.MeshStandardMaterial({
color: 0x617866,
roughness: 0.88
}),
dark: new THREE.MeshStandardMaterial({
color: 0x3b342e,
roughness: 0.9
}),
wicker: new THREE.MeshStandardMaterial({
color: 0xa66f42,
roughness: 0.93
}),
toyBlue: new THREE.MeshStandardMaterial({
color: 0x6f94a6,
roughness: 0.72
}),
toyYellow: new THREE.MeshStandardMaterial({
color: 0xd8a64d,
roughness: 0.72
}),
toyRed: new THREE.MeshStandardMaterial({
color: 0xb65f50,
roughness: 0.72
})
};
function roundedRectShape(width, height, radius) {
const r = Math.min(radius, width * 0.48, height * 0.48);
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function roundedBoxGeometry(width, height, depth, radius) {
const bevel = Math.min(radius * 0.3, depth * 0.2, 0.055);
const geometry = new THREE.ExtrudeGeometry(
roundedRectShape(width, height, radius),
{
depth,
steps: 1,
curveSegments: 8,
bevelEnabled: true,
bevelThickness: bevel,
bevelSize: bevel,
bevelOffset: 0,
bevelSegments: 3
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function addRounded(
parent,
width,
height,
depth,
radius,
material,
position = [0, 0, 0]
) {
const mesh = new THREE.Mesh(
roundedBoxGeometry(width, height, depth, radius),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(parent, size, position, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...size),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
radialSegments = 24
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
radialSegments
),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Room shell: floor, rug, cutaway walls, doorway, and protected circulation
// -------------------------------------------------------------------------
const room = new THREE.Group();
scene.add(room);
addBox(room, [14.7, 0.28, 10.6], [0, -0.15, 0], materials.floor);
const plankMaterial = new THREE.LineBasicMaterial({
color: 0x8d6547,
transparent: true,
opacity: 0.18
});
const plankPositions = [];
for (let x = -7; x <= 7; x += 0.72) {
plankPositions.push(x, 0.006, -5.25, x, 0.006, 5.25);
}
for (let z = -5.2; z <= 5.2; z += 0.76) {
plankPositions.push(-7.3, 0.006, z, 7.3, 0.006, z);
}
const plankGeometry = new THREE.BufferGeometry();
plankGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(plankPositions, 3)
);
room.add(new THREE.LineSegments(plankGeometry, plankMaterial));
function roundedFloorShape(width, depth, radius, material, y) {
const geometry = new THREE.ShapeGeometry(
roundedRectShape(width, depth, radius),
10
);
const mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI / 2;
mesh.position.y = y;
mesh.receiveShadow = true;
room.add(mesh);
return mesh;
}
roundedFloorShape(6.7, 4.8, 0.55, materials.rug, 0.018);
roundedFloorShape(5.95, 4.05, 0.45, materials.rugInset, 0.023);
// Back wall with a real opening at the upper-right.
addBox(room, [11.7, 4.25, 0.24], [-1.4, 2.125, -5.2], materials.wall);
addBox(room, [0.9, 4.25, 0.24], [6.8, 2.125, -5.2], materials.wall);
addBox(room, [1.9, 1.18, 0.24], [5.4, 3.66, -5.2], materials.wall);
// A darker recess beyond the doorway gives the opening depth.
addBox(
room,
[1.87, 3.05, 0.08],
[5.4, 1.525, -5.38],
new THREE.MeshStandardMaterial({
color: 0x403b35,
roughness: 1
})
);
addBox(room, [0.24, 4.25, 10.5], [-7.3, 2.125, 0], materials.wall);
// Lower wall band and simple skirting.
addBox(room, [11.7, 0.82, 0.05], [-1.4, 0.41, -5.055], materials.wallLower);
addBox(room, [0.9, 0.82, 0.05], [6.8, 0.41, -5.055], materials.wallLower);
addBox(room, [0.05, 0.82, 10.45], [-7.155, 0.41, 0], materials.wallLower);
addBox(room, [11.7, 0.11, 0.1], [-1.4, 0.055, -5.03], materials.cream);
addBox(room, [0.9, 0.11, 0.1], [6.8, 0.055, -5.03], materials.cream);
addBox(room, [0.1, 0.11, 10.45], [-7.13, 0.055, 0], materials.cream);
// Door casing.
addRounded(room, 0.15, 3.12, 0.34, 0.045, materials.darkWood, [4.43, 1.56, -5.02]);
addRounded(room, 0.15, 3.12, 0.34, 0.045, materials.darkWood, [6.37, 1.56, -5.02]);
addRounded(room, 2.1, 0.18, 0.36, 0.055, materials.darkWood, [5.4, 3.08, -5.0]);
addBox(room, [1.9, 0.025, 0.5], [5.4, 0.018, -5.02], materials.darkWood);
// Soft route from the entry to the bookshelf.
const routeCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(5.4, 0.052, -5.03),
new THREE.Vector3(5.4, 0.052, -4.1),
new THREE.Vector3(5.12, 0.052, -3.76),
new THREE.Vector3(-3.55, 0.052, -3.76),
new THREE.Vector3(-3.55, 0.052, -4.05)
]);
const routeMesh = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 80, 0.025, 8, false),
new THREE.MeshBasicMaterial({
color: 0xc77c4e,
transparent: true,
opacity: 0.62
})
);
room.add(routeMesh);
// -------------------------------------------------------------------------
// Modular chair construction
// -------------------------------------------------------------------------
const chairGeometryParts = [];
function createChair(index) {
const group = new THREE.Group();
group.userData.index = index;
// Four tapered-looking wooden feet.
for (const x of [-0.67, 0.67]) {
for (const z of [-0.54, 0.54]) {
const leg = addCylinder(
group,
0.065,
0.085,
0.48,
[x, 0.24, z],
materials.darkWood,
16
);
leg.rotation.z = x * 0.035;
}
}
addRounded(
group,
1.88,
0.19,
1.63,
0.14,
materials.wood,
[0, 0.49, 0]
);
addRounded(
group,
1.64,
0.32,
1.43,
0.15,
materials.upholsteryLight,
[0, 0.74, 0.05]
);
const back = addRounded(
group,
1.72,
1.03,
0.34,
0.18,
materials.upholstery,
[0, 1.34, -0.69]
);
back.rotation.x = -0.055;
addRounded(
group,
0.26,
0.58,
1.54,
0.12,
materials.upholstery,
[-0.89, 1.01, -0.01]
);
addRounded(
group,
0.26,
0.58,
1.54,
0.12,
materials.upholstery,
[0.89, 1.01, -0.01]
);
addRounded(
group,
0.12,
0.73,
0.16,
0.05,
materials.darkWood,
[-0.73, 1.22, -0.82]
);
addRounded(
group,
0.12,
0.73,
0.16,
0.05,
materials.darkWood,
[0.73, 1.22, -0.82]
);
group.traverse((object) => {
if (object.isMesh) {
object.castShadow = true;
object.receiveShadow = true;
}
});
room.add(group);
return group;
}
const chairs = [0, 1, 2, 3].map(createChair);
// -------------------------------------------------------------------------
// Shared low table
// -------------------------------------------------------------------------
const coffeeTable = new THREE.Group();
coffeeTable.position.set(0, 0, 0);
room.add(coffeeTable);
addRounded(
coffeeTable,
2.35,
0.25,
1.72,
0.18,
materials.cream,
[0, 0.52, 0]
);
for (const x of [-0.82, 0.82]) {
for (const z of [-0.48, 0.48]) {
addCylinder(
coffeeTable,
0.075,
0.1,
0.4,
[x, 0.2, z],
materials.darkWood,
18
);
}
}
// A small tray and two books establish the center without blocking sightlines.
addRounded(
coffeeTable,
0.74,
0.08,
0.5,
0.05,
materials.wood,
[0.36, 0.69, 0.02]
);
addRounded(
coffeeTable,
0.45,
0.08,
0.34,
0.025,
materials.green,
[-0.47, 0.69, -0.08]
);
addRounded(
coffeeTable,
0.41,
0.07,
0.32,
0.025,
materials.rugInset,
[-0.46, 0.76, -0.06]
);
const bowl = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 24, 12, 0, Math.PI * 2, 0, Math.PI / 2),
materials.upholstery
);
bowl.rotation.x = Math.PI;
bowl.position.set(0.36, 0.75, 0.02);
bowl.castShadow = true;
coffeeTable.add(bowl);
// -------------------------------------------------------------------------
// Bookshelf against the back wall
// -------------------------------------------------------------------------
const shelf = new THREE.Group();
shelf.position.set(-3.65, 0, -4.68);
room.add(shelf);
addRounded(shelf, 3.5, 2.7, 0.13, 0.035, materials.darkWood, [0, 1.4, -0.36]);
addRounded(shelf, 0.16, 2.82, 0.78, 0.045, materials.wood, [-1.68, 1.41, 0]);
addRounded(shelf, 0.16, 2.82, 0.78, 0.045, materials.wood, [1.68, 1.41, 0]);
for (const y of [0.12, 0.91, 1.72, 2.65]) {
addRounded(shelf, 3.36, 0.13, 0.8, 0.035, materials.wood, [0, y, 0]);
}
let seed = 8127;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const bookMaterials = [
materials.green,
materials.toyBlue,
materials.toyRed,
materials.upholsteryLight,
materials.cream,
materials.rugInset
];
for (const shelfY of [0.185, 0.975, 1.785]) {
let cursor = -1.47;
while (cursor < 1.2) {
const width = 0.13 + random() * 0.12;
const height = 0.42 + random() * 0.25;
const depth = 0.4 + random() * 0.1;
const book = addBox(
shelf,
[width, height, depth],
[
cursor + width / 2,
shelfY + height / 2,
0.03
],
bookMaterials[Math.floor(random() * bookMaterials.length)]
);
book.rotation.z = (random() - 0.5) * 0.035;
cursor += width + 0.035;
}
// Horizontal book stacks on alternating shelves.
const stackColor =
shelfY < 0.5
? materials.toyBlue
: shelfY < 1.2
? materials.cream
: materials.upholstery;
addRounded(
shelf,
0.64,
0.11,
0.42,
0.025,
stackColor,
[1.1, shelfY + 0.055, 0.03]
);
addRounded(
shelf,
0.58,
0.09,
0.4,
0.022,
materials.green,
[1.08, shelfY + 0.15, 0.02]
);
}
// Framed print above the shelf.
addRounded(room, 1.34, 0.95, 0.08, 0.04, materials.darkWood, [-3.65, 3.48, -5.02]);
addRounded(room, 1.12, 0.73, 0.03, 0.025, materials.cream, [-3.65, 3.48, -4.96]);
addRounded(room, 0.63, 0.38, 0.025, 0.04, materials.green, [-3.65, 3.41, -4.93]);
const artSun = new THREE.Mesh(
new THREE.CircleGeometry(0.13, 24),
materials.upholsteryLight
);
artSun.position.set(-3.84, 3.55, -4.9);
room.add(artSun);
// -------------------------------------------------------------------------
// Toy basket in the front-left corner
// -------------------------------------------------------------------------
const basket = new THREE.Group();
basket.position.set(-5.88, 0, 3.82);
room.add(basket);
addCylinder(
basket,
0.52,
0.47,
0.61,
[0, 0.305, 0],
materials.wicker,
32
);
const basketOpening = new THREE.Mesh(
new THREE.CircleGeometry(0.46, 32),
materials.darkWood
);
basketOpening.rotation.x = -Math.PI / 2;
basketOpening.position.y = 0.615;
basket.add(basketOpening);
const basketRim = new THREE.Mesh(
new THREE.TorusGeometry(0.505, 0.055, 10, 36),
materials.cream
);
basketRim.rotation.x = Math.PI / 2;
basketRim.position.y = 0.61;
basketRim.castShadow = true;
basket.add(basketRim);
const ball1 = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 20, 12),
materials.toyBlue
);
ball1.position.set(-0.16, 0.68, 0.05);
ball1.castShadow = true;
basket.add(ball1);
const ball2 = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 20, 12),
materials.toyYellow
);
ball2.position.set(0.16, 0.66, -0.11);
ball2.castShadow = true;
basket.add(ball2);
addRounded(
basket,
0.28,
0.22,
0.26,
0.06,
materials.toyRed,
[0.1, 0.73, 0.12]
);
// -------------------------------------------------------------------------
// Layouts
// -------------------------------------------------------------------------
const layouts = [
{
name: "Square",
positions: [
{ x: 0, z: 3.15 },
{ x: 3.25, z: 0 },
{ x: 0, z: -2.15 },
{ x: -3.25, z: 0 }
]
},
{
name: "Diamond",
positions: [
{ x: 2.4, z: 2.4 },
{ x: 2.4, z: -2.4 },
{ x: -2.4, z: -2.4 },
{ x: -2.4, z: 2.4 }
]
},
{
name: "Easy arc",
positions: [
{ x: 0.75, z: 3.0 },
{ x: 3.4, z: -0.1 },
{ x: -1.15, z: -2.35 },
{ x: -3.3, z: 0.65 }
]
}
];
function faceCenter(position) {
// Chair local forward is +Z.
return Math.atan2(-position.x, -position.z);
}
layouts.forEach((layout) => {
layout.positions.forEach((position) => {
position.angle = faceCenter(position);
});
});
const chairStates = layouts[0].positions.map((position, index) => {
chairs[index].position.set(position.x, 0, position.z);
chairs[index].rotation.y = position.angle;
return {
x: position.x,
z: position.z,
angle: position.angle
};
});
let activeLayout = 0;
let transitionActive = false;
// -------------------------------------------------------------------------
// Collision geometry and path planning
//
// Chairs are represented by oriented rectangles. A grid A* search checks the
// swept footprint along every segment. Chairs move one at a time, and the
// final rotation is also tested against all stationary chairs.
// -------------------------------------------------------------------------
const CHAIR_HALF_WIDTH = 0.98;
const CHAIR_HALF_DEPTH = 0.9;
const staticObstacles = [
{
x: 0,
z: 0,
angle: 0,
hw: 1.22,
hd: 0.9
},
{
x: -3.65,
z: -4.68,
angle: 0,
hw: 1.78,
hd: 0.45
},
{
x: -5.88,
z: 3.82,
angle: 0,
hw: 0.57,
hd: 0.57
}
];
function makeOBB(x, z, angle, hw, hd) {
return {
x,
z,
hw,
hd,
ax: { x: Math.cos(angle), z: -Math.sin(angle) },
az: { x: Math.sin(angle), z: Math.cos(angle) }
};
}
function dot2(a, b) {
return a.x * b.x + a.z * b.z;
}
function overlapsOBB(a, b) {
const axes = [a.ax, a.az, b.ax, b.az];
for (const axis of axes) {
const distance = Math.abs(
(b.x - a.x) * axis.x + (b.z - a.z) * axis.z
);
const radiusA =
a.hw * Math.abs(dot2(a.ax, axis)) +
a.hd * Math.abs(dot2(a.az, axis));
const radiusB =
b.hw * Math.abs(dot2(b.ax, axis)) +
b.hd * Math.abs(dot2(b.az, axis));
if (distance >= radiusA + radiusB) {
return false;
}
}
return true;
}
function stateOBB(state, padding = 0) {
return makeOBB(
state.x,
state.z,
state.angle,
CHAIR_HALF_WIDTH + padding,
CHAIR_HALF_DEPTH + padding
);
}
function poseIsClear(x, z, angle, otherStates, padding = 0.05) {
// Stay inside the visible floor and away from the room edges.
if (x < -6.2 || x > 6.2 || z < -4.18 || z > 4.3) {
return false;
}
const moving = makeOBB(
x,
z,
angle,
CHAIR_HALF_WIDTH + padding,
CHAIR_HALF_DEPTH + padding
);
for (const obstacle of staticObstacles) {
const solid = makeOBB(
obstacle.x,
obstacle.z,
obstacle.angle,
obstacle.hw,
obstacle.hd
);
if (overlapsOBB(moving, solid)) return false;
}
for (const other of otherStates) {
const solid = makeOBB(
other.x,
other.z,
other.angle,
CHAIR_HALF_WIDTH,
CHAIR_HALF_DEPTH
);
if (overlapsOBB(moving, solid)) return false;
}
return true;
}
function segmentIsClear(a, b, angle, otherStates) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const distance = Math.hypot(dx, dz);
if (distance < 0.0001) {
return poseIsClear(a.x, a.z, angle, otherStates);
}
const steps = Math.max(1, Math.ceil(distance / 0.12));
for (let i = 0; i <= steps; i++) {
const t = i / steps;
if (
!poseIsClear(
a.x + dx * t,
a.z + dz * t,
angle,
otherStates,
0.045
)
) {
return false;
}
}
return true;
}
function rotationAtTargetIsClear(
target,
fromAngle,
toAngle,
otherStates
) {
for (let i = 0; i <= 24; i++) {
const t = i / 24;
const angle = fromAngle + shortestAngle(fromAngle, toAngle) * t;
if (
!poseIsClear(
target.x,
target.z,
angle,
otherStates,
0.035
)
) {
return false;
}
}
return true;
}
function shortestAngle(from, to) {
return Math.atan2(Math.sin(to - from), Math.cos(to - from));
}
const GRID_STEP = 0.31;
const GRID_MIN_X = -6.4;
const GRID_MIN_Z = -4.4;
const GRID_COLUMNS = 43;
const GRID_ROWS = 29;
const gridPositions = new Array(GRID_COLUMNS * GRID_ROWS);
for (let row = 0; row < GRID_ROWS; row++) {
for (let column = 0; column < GRID_COLUMNS; column++) {
gridPositions[row * GRID_COLUMNS + column] = {
x: GRID_MIN_X + column * GRID_STEP,
z: GRID_MIN_Z + row * GRID_STEP
};
}
}
function findPath(start, target, otherStates) {
if (
segmentIsClear(
{ x: start.x, z: start.z },
{ x: target.x, z: target.z },
start.angle,
otherStates
)
) {
return [
{ x: start.x, z: start.z },
{ x: target.x, z: target.z }
];
}
const valid = new Uint8Array(gridPositions.length);
for (let i = 0; i < gridPositions.length; i++) {
const point = gridPositions[i];
valid[i] = poseIsClear(
point.x,
point.z,
start.angle,
otherStates,
0.045
) ? 1 : 0;
}
const validIndices = [];
for (let i = 0; i < valid.length; i++) {
if (valid[i]) validIndices.push(i);
}
function nearestUsable(point, requiresConnection) {
const candidates = validIndices
.map((index) => ({
index,
distance:
Math.hypot(
gridPositions[index].x - point.x,
gridPositions[index].z - point.z
)
}))
.sort((a, b) => a.distance - b.distance);
for (const candidate of candidates) {
const gridPoint = gridPositions[candidate.index];
const other = requiresConnection
? { x: point.x, z: point.z }
: point;
if (
segmentIsClear(
point,
gridPoint,
start.angle,
otherStates
)
) {
return candidate.index;
}
}
return -1;
}
const startIndex = nearestUsable(
{ x: start.x, z: start.z },
false
);
const goalIndex = nearestUsable(
{ x: target.x, z: target.z },
true
);
if (startIndex < 0 || goalIndex < 0) return null;
const total = gridPositions.length;
const gScore = new Float64Array(total);
const fScore = new Float64Array(total);
const cameFrom = new Int32Array(total);
const closed = new Uint8Array(total);
const open = [startIndex];
gScore.fill(Infinity);
fScore.fill(Infinity);
cameFrom.fill(-1);
const goalPoint = gridPositions[goalIndex];
function heuristic(index) {
const point = gridPositions[index];
return Math.hypot(
point.x - goalPoint.x,
point.z - goalPoint.z
);
}
gScore[startIndex] = 0;
fScore[startIndex] = heuristic(startIndex);
const directions = [
[-1, 0],
[1, 0],
[0, -1],
[0, 1],
[-1, -1],
[1, -1],
[-1, 1],
[1, 1]
];
while (open.length) {
let bestOpenIndex = 0;
for (let i = 1; i < open.length; i++) {
if (fScore[open[i]] < fScore[open[bestOpenIndex]]) {
bestOpenIndex = i;
}
}
const current = open.splice(bestOpenIndex, 1)[0];
if (current === goalIndex) break;
if (closed[current]) continue;
closed[current] = 1;
const column = current % GRID_COLUMNS;
const row = Math.floor(current / GRID_COLUMNS);
for (const [dx, dz] of directions) {
const nextColumn = column + dx;
const nextRow = row + dz;
if (
nextColumn < 0 ||
nextColumn >= GRID_COLUMNS ||
nextRow < 0 ||
nextRow >= GRID_ROWS
) {
continue;
}
const next = nextRow * GRID_COLUMNS + nextColumn;
if (!valid[next] || closed[next]) continue;
// Prevent diagonal movement through a blocked corner.
if (dx !== 0 && dz !== 0) {
const sideA = row * GRID_COLUMNS + nextColumn;
const sideB = nextRow * GRID_COLUMNS + column;
if (!valid[sideA] || !valid[sideB]) continue;
}
const currentPoint = gridPositions[current];
const nextPoint = gridPositions[next];
if (
!segmentIsClear(
currentPoint,
nextPoint,
start.angle,
otherStates
)
) {
continue;
}
const movement = Math.hypot(dx, dz) * GRID_STEP;
const tentative = gScore[current] + movement;
if (tentative < gScore[next]) {
cameFrom[next] = current;
gScore[next] = tentative;
fScore[next] = tentative + heuristic(next);
if (!open.includes(next)) open.push(next);
}
}
}
if (cameFrom[goalIndex] < 0 && goalIndex !== startIndex) {
return null;
}
const raw = [];
let cursor = goalIndex;
while (cursor >= 0) {
raw.push(gridPositions[cursor]);
if (cursor === startIndex) break;
cursor = cameFrom[cursor];
}
raw.reverse();
const complete = [
{ x: start.x, z: start.z },
...raw,
{ x: target.x, z: target.z }
];
// Remove redundant waypoints when a longer straight segment is safe.
const smooth = [];
let anchor = 0;
while (anchor < complete.length - 1) {
let furthest = anchor + 1;
for (let candidate = complete.length - 1; candidate > anchor + 1; candidate--) {
if (
segmentIsClear(
complete[anchor],
complete[candidate],
start.angle,
otherStates
)
) {
furthest = candidate;
break;
}
}
smooth.push(complete[anchor]);
anchor = furthest;
}
smooth.push(complete[complete.length - 1]);
return smooth;
}
function planTransition(targetLayout) {
const simulated = chairStates.map((state) => ({ ...state }));
const assigned = new Set();
const usedTargets = new Set();
const sequence = [];
function search() {
if (sequence.length === chairs.length) return true;
for (let chairIndex = 0; chairIndex < chairs.length; chairIndex++) {
if (assigned.has(chairIndex)) continue;
const from = simulated[chairIndex];
for (let targetIndex = 0; targetIndex < targetLayout.positions.length; targetIndex++) {
if (usedTargets.has(targetIndex)) continue;
const target = targetLayout.positions[targetIndex];
const otherStates = simulated.filter(
(_, index) => index !== chairIndex
);
if (
!rotationAtTargetIsClear(
target,
from.angle,
target.angle,
otherStates
)
) {
continue;
}
const path = findPath(from, target, otherStates);
if (!path) continue;
sequence.push({
chairIndex,
target,
targetAngle: target.angle,
fromAngle: from.angle,
path
});
assigned.add(chairIndex);
usedTargets.add(targetIndex);
simulated[chairIndex] = {
x: target.x,
z: target.z,
angle: target.angle
};
if (search()) return true;
assigned.delete(chairIndex);
usedTargets.delete(targetIndex);
simulated[chairIndex] = { ...from };
sequence.pop();
}
}
return false;
}
return search() ? sequence : null;
}
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const statusText = document.getElementById("statusText");
const statusDot = document.getElementById("statusDot");
const progressFill = document.getElementById("progressFill");
const buttons = [...document.querySelectorAll(".layout-button")];
let activeTween = null;
let tweenResolve = null;
function pathMetrics(path) {
const distances = [0];
let total = 0;
for (let i = 1; i < path.length; i++) {
total += Math.hypot(
path[i].x - path[i - 1].x,
path[i].z - path[i - 1].z
);
distances.push(total);
}
return { distances, total };
}
function pointAlongPath(path, metrics, distance) {
if (distance <= 0) return path[0];
for (let i = 1; i < path.length; i++) {
if (distance <= metrics.distances[i]) {
const startDistance = metrics.distances[i - 1];
const segmentLength = metrics.distances[i] - startDistance;
const t = segmentLength > 0
? (distance - startDistance) / segmentLength
: 0;
return {
x: THREE.MathUtils.lerp(path[i - 1].x, path[i].x, t),
z: THREE.MathUtils.lerp(path[i - 1].z, path[i].z, t)
};
}
}
return path[path.length - 1];
}
function animateTween(tween) {
const metrics = pathMetrics(tween.path);
activeTween = {
...tween,
metrics,
phase: "move",
elapsed: 0,
duration: Math.max(1.05, metrics.total * 0.8),
progress: 0
};
return new Promise((resolve) => {
tweenResolve = resolve;
});
}
function updateTween(delta) {
if (!activeTween) return;
const tween = activeTween;
const chair = chairs[tween.chairIndex];
if (tween.phase === "move") {
tween.elapsed += delta;
const raw = Math.min(1, tween.elapsed / tween.duration);
const eased = raw * raw * (3 - 2 * raw);
const point = pointAlongPath(
tween.path,
tween.metrics,
eased * tween.metrics.total
);
chair.position.x = point.x;
chair.position.z = point.z;
chair.rotation.y = tween.fromAngle;
tween.progress = raw * 0.82;
if (raw >= 1) {
tween.phase = "rotate";
tween.elapsed = 0;
tween.duration = 0.72;
}
} else {
tween.elapsed += delta;
const raw = Math.min(1, tween.elapsed / tween.duration);
const eased = raw * raw * (3 - 2 * raw);
const deltaAngle = shortestAngle(
tween.fromAngle,
tween.targetAngle
);
chair.rotation.y = tween.fromAngle + deltaAngle * eased;
tween.progress = 0.82 + eased * 0.18;
if (raw >= 1) {
chair.rotation.y = tween.targetAngle;
chairStates[tween.chairIndex] = {
x: tween.target.x,
z: tween.target.z,
angle: tween.targetAngle
};
const resolve = tweenResolve;
activeTween = null;
tweenResolve = null;
if (resolve) resolve();
}
}
}
function setStatus(text, moving = false) {
statusText.textContent = text;
statusDot.classList.toggle("moving", moving);
}
async function changeLayout(index) {
if (transitionActive || index === activeLayout) return;
transitionActive = true;
buttons.forEach((button) => (button.disabled = true));
setStatus("Planning clear routes around the furniture…", true);
progressFill.style.width = "0%";
await new Promise((resolve) => requestAnimationFrame(resolve));
const plan = planTransition(layouts[index]);
if (!plan) {
setStatus("No collision-free route found. Please try again.", false);
progressFill.style.width = "0%";
transitionActive = false;
buttons.forEach((button) => (button.disabled = false));
return;
}
for (let i = 0; i < plan.length; i++) {
const step = plan[i];
setStatus(
`Moving seat ${i + 1} of ${plan.length} · route reserved`,
true
);
await animateTween(step);
progressFill.style.width = `${((i + 1) / plan.length) * 100}%`;
}
activeLayout = index;
buttons.forEach((button, buttonIndex) => {
button.classList.toggle("active", buttonIndex === index);
});
setStatus(
`${layouts[index].name} arrangement ready · doorway and shelf route clear`,
false
);
transitionActive = false;
buttons.forEach((button) => (button.disabled = false));
}
buttons.forEach((button) => {
button.addEventListener("click", () => {
changeLayout(Number(button.dataset.layout));
});
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateTween(delta);
if (activeTween) {
const overall =
((activeLayout === 0 ? 0 : 0) + activeTween.progress) / 1;
progressFill.style.width = `${Math.max(
Number(progressFill.style.width.replace("%", "")) || 0,
overall
)}%`;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```