Prompt specification
Build or customize the Three.js 3D scene "Instruction Grounding Action Game" 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: Instruction Grounding Action Game
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/instruction-grounding-action-game-x3436
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a tabletop scene where users select actor, action, and object. Execute only geometrically valid combinations and explain unmet preconditions such as a closed container. Voxel style.
Working Three.js Starter (instruction-grounding-action-game-x3436):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Task Lab</title>
<style>
:root {
--ink: #f4f1e8;
--muted: #9babb7;
--panel: rgba(12, 22, 31, 0.92);
--line: rgba(255, 255, 255, 0.11);
--accent: #ffd166;
--green: #64d6a0;
--red: #ff7979;
--blue: #63b8ff;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09131d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, select { font: inherit; }
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active { cursor: grabbing; }
.brand {
position: fixed;
z-index: 5;
top: 24px;
left: 26px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 5px 0 3px;
font-size: clamp(24px, 3vw, 39px);
line-height: 1;
letter-spacing: -0.04em;
}
.brand p {
margin: 8px 0 0;
color: #b8c4cc;
font-size: 13px;
}
.panel {
position: fixed;
z-index: 10;
top: 96px;
bottom: 24px;
left: 24px;
width: 354px;
overflow: auto;
padding: 20px;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #405260 transparent;
}
.panel-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 18px;
}
.panel-top h2 {
margin: 0;
font-size: 16px;
letter-spacing: -0.02em;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--green);
box-shadow: 0 0 14px rgba(100, 214, 160, 0.8);
}
.field { margin-bottom: 14px; }
.field label {
display: block;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
select {
width: 100%;
height: 43px;
padding: 0 38px 0 12px;
color: var(--ink);
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 10px;
outline: none;
background-color: #172733;
background-image:
linear-gradient(45deg, transparent 50%, #9babb7 50%),
linear-gradient(135deg, #9babb7 50%, transparent 50%);
background-position:
calc(100% - 18px) 18px,
calc(100% - 13px) 18px;
background-size: 5px 5px, 5px 5px;
background-repeat: no-repeat;
appearance: none;
cursor: pointer;
}
select:focus {
border-color: rgba(255, 209, 102, 0.75);
box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.08);
}
.action-hint {
min-height: 50px;
margin: 3px 0 15px;
padding: 11px 12px;
color: #bdc8ce;
border-left: 3px solid #42657a;
border-radius: 0 8px 8px 0;
background: rgba(255, 255, 255, 0.035);
font-size: 12px;
line-height: 1.45;
}
.plan-card {
overflow: hidden;
margin-bottom: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.035);
}
.plan-status {
display: flex;
gap: 11px;
align-items: flex-start;
padding: 13px 14px;
border-bottom: 1px solid var(--line);
}
.status-icon {
display: grid;
flex: 0 0 auto;
width: 26px;
height: 26px;
place-items: center;
border-radius: 8px;
font-size: 13px;
font-weight: 900;
}
.plan-card.valid .status-icon {
color: #092017;
background: var(--green);
}
.plan-card.invalid .status-icon {
color: #2a0909;
background: var(--red);
}
.plan-card.busy .status-icon {
color: #251b05;
background: var(--accent);
}
.status-title {
margin-bottom: 3px;
font-size: 13px;
font-weight: 800;
}
.status-detail {
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.checks {
margin: 0;
padding: 7px 13px 11px;
list-style: none;
}
.check {
display: grid;
grid-template-columns: 18px 1fr;
gap: 7px;
padding: 7px 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.055);
}
.check:last-child { border-bottom: 0; }
.check-mark {
padding-top: 1px;
font-size: 11px;
font-weight: 900;
}
.check.pass .check-mark { color: var(--green); }
.check.fail .check-mark { color: var(--red); }
.check-name {
margin-bottom: 2px;
font-size: 11px;
font-weight: 750;
}
.check-detail {
color: var(--muted);
font-size: 10.5px;
line-height: 1.38;
}
.check.fail .check-name { color: #ffd0d0; }
.execute {
width: 100%;
height: 48px;
border: 0;
border-radius: 11px;
color: #17212a;
background: var(--accent);
box-shadow: 0 9px 24px rgba(255, 209, 102, 0.16);
font-weight: 850;
cursor: pointer;
transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}
.execute:hover:not(:disabled) {
filter: brightness(1.06);
transform: translateY(-1px);
}
.execute:active:not(:disabled) { transform: translateY(1px); }
.execute:disabled {
color: #78848c;
background: #26343d;
box-shadow: none;
cursor: not-allowed;
}
.history {
margin-top: 20px;
padding-top: 16px;
border-top: 1px solid var(--line);
}
.history h3 {
margin: 0 0 10px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.history-item {
position: relative;
margin-bottom: 9px;
padding-left: 17px;
color: #d5dde1;
font-size: 11px;
line-height: 1.4;
}
.history-item::before {
content: "";
position: absolute;
top: 4px;
left: 0;
width: 6px;
height: 6px;
border-radius: 2px;
background: var(--green);
}
.history-empty {
color: #788994;
font-size: 11px;
line-height: 1.45;
}
.reset {
position: fixed;
z-index: 12;
top: 25px;
right: 25px;
height: 38px;
padding: 0 14px;
color: #dce5e9;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(12, 22, 31, 0.84);
cursor: pointer;
backdrop-filter: blur(12px);
}
.reset:hover { background: #20333f; }
.camera-help {
position: fixed;
z-index: 4;
right: 25px;
bottom: 23px;
padding: 10px 13px;
color: #afbec7;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 10px;
background: rgba(10, 19, 27, 0.7);
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(10px);
}
.camera-help strong { color: #f1f4f4; }
.toast {
position: fixed;
z-index: 30;
left: 50%;
bottom: 28px;
max-width: min(520px, calc(100vw - 30px));
padding: 12px 17px;
color: #f5f7f7;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 12px;
background: rgba(14, 26, 35, 0.94);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
font-size: 12px;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 760px) {
.brand {
top: 15px;
left: 17px;
}
.brand h1 { font-size: 26px; }
.brand p { display: none; }
.reset {
top: 14px;
right: 14px;
height: 34px;
}
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 49vh;
padding: 15px;
border-radius: 17px;
}
.panel-top { margin-bottom: 12px; }
.action-hint { min-height: 0; margin-bottom: 10px; }
.checks { max-height: 180px; overflow: auto; }
.history { margin-top: 13px; padding-top: 12px; }
.camera-help { display: none; }
.toast { bottom: calc(49vh + 20px); }
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel tabletop"></div>
<header class="brand">
<div class="eyebrow">Voxel / Logic</div>
<h1>Tabletop Task Lab</h1>
<p>Compose a plan. Validate its geometry. Watch it unfold.</p>
</header>
<button class="reset" id="resetButton" type="button">Reset scene</button>
<aside class="panel">
<div class="panel-top">
<h2>Action planner</h2>
<div class="live-dot">Live world</div>
</div>
<div class="field">
<label for="actorSelect">Actor</label>
<select id="actorSelect"></select>
</div>
<div class="field">
<label for="actionSelect">Action</label>
<select id="actionSelect"></select>
</div>
<div class="field">
<label for="objectSelect">Object</label>
<select id="objectSelect"></select>
</div>
<div class="action-hint" id="actionHint"></div>
<div class="plan-card" id="planCard">
<div class="plan-status">
<div class="status-icon" id="statusIcon">✓</div>
<div>
<div class="status-title" id="statusTitle">Checking plan</div>
<div class="status-detail" id="statusDetail"></div>
</div>
</div>
<ul class="checks" id="checks"></ul>
</div>
<button class="execute" id="executeButton" type="button">Execute plan</button>
<section class="history">
<h3>Completed actions</h3>
<div id="history"></div>
</section>
</aside>
<div class="camera-help">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom ·
<strong>Click</strong> a voxel to select it
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const actorSelect = document.querySelector("#actorSelect");
const actionSelect = document.querySelector("#actionSelect");
const objectSelect = document.querySelector("#objectSelect");
const actionHint = document.querySelector("#actionHint");
const planCard = document.querySelector("#planCard");
const statusIcon = document.querySelector("#statusIcon");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const checksElement = document.querySelector("#checks");
const executeButton = document.querySelector("#executeButton");
const historyElement = document.querySelector("#history");
const toastElement = document.querySelector("#toast");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09131d);
scene.fog = new THREE.Fog(0x09131d, 12, 24);
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.1;
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-5, 5, 4, -4, 0.1, 100);
const orbit = {
theta: 0.68,
phi: 0.92,
zoom: 1,
target: new THREE.Vector3(-0.65, 0.35, 0)
};
const ambient = new THREE.HemisphereLight(0xbfe8ff, 0x263444, 2.0);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff2d2, 3.2);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5fa8ff, 1.35);
rimLight.position.set(-5, 4, -5);
scene.add(rimLight);
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...options
}));
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material(color, options)
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, accent = "#ffd166") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(8, 17, 24, 0.86)";
context.fillRect(4, 8, 504, 80);
context.strokeStyle = accent;
context.lineWidth = 5;
context.strokeRect(7, 11, 498, 74);
context.fillStyle = "#f4f1e8";
context.font = "700 34px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
}));
const width = Math.max(0.72, Math.min(1.55, text.length * 0.105));
sprite.scale.set(width, width * 0.1875, 1);
sprite.renderOrder = 20;
return sprite;
}
function buildTable() {
const tableTop = addBox(
scene,
new THREE.Vector3(7.7, 0.42, 5.45),
new THREE.Vector3(0, -0.24, 0),
0x263a46
);
tableTop.receiveShadow = true;
const tileGeometry = new THREE.BoxGeometry(0.535, 0.035, 0.535);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
flatShading: true
});
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 12 * 8);
tiles.receiveShadow = true;
const dummy = new THREE.Object3D();
const colorA = new THREE.Color(0xd7d0bd);
const colorB = new THREE.Color(0xe7dfcc);
let index = 0;
for (let row = 0; row < 8; row++) {
for (let column = 0; column < 12; column++) {
dummy.position.set(
-3.025 + column * 0.55,
-0.01,
-1.925 + row * 0.55
);
dummy.updateMatrix();
tiles.setMatrixAt(index, dummy.matrix);
tiles.setColorAt(index, (row + column) % 2 ? colorA : colorB);
index++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
const legMaterial = 0x172630;
for (const x of [-3.05, 3.05]) {
for (const z of [-1.95, 1.95]) {
addBox(
scene,
new THREE.Vector3(0.34, 2.1, 0.34),
new THREE.Vector3(x, -1.45, z),
legMaterial
);
}
}
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
material(0x0c1822)
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.5;
floor.receiveShadow = true;
scene.add(floor);
}
buildTable();
const interactive = [];
const objects = {};
const actors = {};
function createVoxelCube(id, label, position, size, color) {
const group = new THREE.Group();
group.userData.objectId = id;
group.position.copy(position);
addBox(
group,
size,
new THREE.Vector3(0, 0, 0),
color
);
const stud = 0.13;
for (const x of [-size.x * 0.23, size.x * 0.23]) {
for (const z of [-size.z * 0.23, size.z * 0.23]) {
addBox(
group,
new THREE.Vector3(stud, 0.08, stud),
new THREE.Vector3(x, size.y / 2 + 0.04, z),
color,
{ roughness: 0.65 }
);
}
}
const tag = makeLabel(label);
tag.position.set(0, size.y / 2 + 0.48, 0);
group.add(tag);
scene.add(group);
interactive.push(group);
objects[id] = {
id,
label,
type: "cube",
group,
size: size.clone(),
color,
heldBy: null,
inContainer: null,
supportedBy: null,
topObject: null,
animating: false
};
}
function createVoxelSphere(id, label, position, size, color) {
const group = new THREE.Group();
group.userData.objectId = id;
group.position.copy(position);
const cell = size.x / 3;
for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
for (let z = -1; z <= 1; z++) {
if (x * x + y * y + z * z <= 2.2) {
addBox(
group,
new THREE.Vector3(cell * 0.96, cell * 0.96, cell * 0.96),
new THREE.Vector3(x * cell, y * cell, z * cell),
color
);
}
}
}
}
const tag = makeLabel(label);
tag.position.set(0, size.y / 2 + 0.45, 0);
group.add(tag);
scene.add(group);
interactive.push(group);
objects[id] = {
id,
label,
type: "sphere",
group,
size: size.clone(),
color,
heldBy: null,
inContainer: null,
supportedBy: null,
topObject: null,
animating: false
};
}
function createPlatform(id, label, position, size) {
const group = new THREE.Group();
group.userData.objectId = id;
group.position.copy(position);
addBox(
group,
new THREE.Vector3(size.x, size.y, size.z),
new THREE.Vector3(0, size.y / 2, 0),
0x6bb7a3
);
for (let x = 0; x < 3; x++) {
for (let z = 0; z < 2; z++) {
addBox(
group,
new THREE.Vector3(size.x / 3 - 0.055, 0.035, size.z / 2 - 0.055),
new THREE.Vector3(
-size.x / 3 + x * (size.x / 3),
size.y + 0.0175,
-size.z / 4 + z * (size.z / 2)
),
0x91d5c1
);
}
}
const tag = makeLabel(label, "#91d5c1");
tag.position.set(0, size.y + 0.42, 0);
group.add(tag);
scene.add(group);
interactive.push(group);
objects[id] = {
id,
label,
type: "platform",
group,
size: size.clone(),
color: 0x6bb7a3,
heldBy: null,
inContainer: null,
supportedBy: null,
topObject: null,
animating: false
};
}
function createContainer(id, label, position, size, color, initiallyOpen) {
const group = new THREE.Group();
group.userData.objectId = id;
group.position.copy(position);
const wall = 0.14;
const wallHeight = size.y - 0.16;
addBox(
group,
new THREE.Vector3(size.x, 0.16, size.z),
new THREE.Vector3(0, 0.08, 0),
color
);
addBox(
group,
new THREE.Vector3(wall, wallHeight, size.z),
new THREE.Vector3(-(size.x - wall) / 2, 0.16 + wallHeight / 2, 0),
color
);
addBox(
group,
new THREE.Vector3(wall, wallHeight, size.z),
new THREE.Vector3((size.x - wall) / 2, 0.16 + wallHeight / 2, 0),
color
);
addBox(
group,
new THREE.Vector3(size.x - wall * 2, wallHeight, wall),
new THREE.Vector3(0, 0.16 + wallHeight / 2, -(size.z - wall) / 2),
color
);
addBox(
group,
new THREE.Vector3(size.x - wall * 2, wallHeight, wall),
new THREE.Vector3(0, 0.16 + wallHeight / 2, (size.z - wall) / 2),
color
);
for (const x of [-size.x / 2 + 0.07, size.x / 2 - 0.07]) {
for (const z of [-size.z / 2 + 0.07, size.z / 2 - 0.07]) {
addBox(
group,
new THREE.Vector3(0.18, wallHeight + 0.05, 0.18),
new THREE.Vector3(x, 0.16 + wallHeight / 2, z),
color,
{ roughness: 0.6 }
);
}
}
const lidPivot = new THREE.Group();
lidPivot.position.set(0, size.y - 0.05, -(size.z / 2 - 0.06));
addBox(
lidPivot,
new THREE.Vector3(size.x + 0.05, 0.13, size.z - 0.04),
new THREE.Vector3(0, 0, (size.z - 0.04) / 2),
color,
{ roughness: 0.62 }
);
addBox(
lidPivot,
new THREE.Vector3(0.36, 0.1, 0.16),
new THREE.Vector3(0, 0.1, size.z - 0.28),
0xffe08a
);
group.add(lidPivot);
const tag = makeLabel(label, initiallyOpen ? "#ffd166" : "#ff7979");
tag.position.set(0, size.y + 0.42, 0);
group.add(tag);
scene.add(group);
interactive.push(group);
objects[id] = {
id,
label,
type: "container",
group,
lidPivot,
size: size.clone(),
color,
lidState: initiallyOpen ? "open" : "closed",
contents: null,
heldBy: null,
inContainer: null,
supportedBy: null,
topObject: null,
animating: false
};
lidPivot.rotation.x = initiallyOpen ? -1.22 : 0;
}
createVoxelCube(
"cube",
"CUBE",
new THREE.Vector3(-1.75, 0.36, 0.65),
new THREE.Vector3(0.72, 0.72, 0.72),
0xe95d5d
);
createVoxelSphere(
"sphere",
"SPHERE",
new THREE.Vector3(-0.15, 0.33, 1.3),
new THREE.Vector3(0.66, 0.66, 0.66),
0x5797e8
);
createContainer(
"openBox",
"OPEN CRATE",
new THREE.Vector3(1.75, 0, 0.45),
new THREE.Vector3(1.2, 1.05, 1.2),
0xd69a54,
true
);
createContainer(
"closedBox",
"CLOSED CRATE",
new THREE.Vector3(1.55, 0, -1.35),
new THREE.Vector3(1.2, 1.05, 1.2),
0x6ba884,
false
);
createPlatform(
"platform",
"PLATFORM",
new THREE.Vector3(-1.15, 0, -1.45),
new THREE.Vector3(1.55, 0.3, 1.15)
);
function createActor(id, label, position, color, visualScale, reach, fitsInContainer) {
const group = new THREE.Group();
group.userData.actorId = id;
group.position.copy(position);
group.scale.setScalar(visualScale);
addBox(
group,
new THREE.Vector3(0.52, 0.5, 0.42),
new THREE.Vector3(0, 0.38, 0),
color
);
addBox(
group,
new THREE.Vector3(0.48, 0.34, 0.42),
new THREE.Vector3(0, 0.82, 0),
0xe8edf0
);
addBox(
group,
new THREE.Vector3(0.09, 0.09, 0.025),
new THREE.Vector3(-0.11, 0.85, 0.222),
0x16202a
);
addBox(
group,
new THREE.Vector3(0.09, 0.09, 0.025),
new THREE.Vector3(0.11, 0.85, 0.222),
0x16202a
);
addBox(
group,
new THREE.Vector3(0.24, 0.16, 0.28),
new THREE.Vector3(-0.16, 0.1, 0.04),
0x263746
);
addBox(
group,
new THREE.Vector3(0.24, 0.16, 0.28),
new THREE.Vector3(0.16, 0.1, 0.04),
0x263746
);
addBox(
group,
new THREE.Vector3(0.14, 0.38, 0.16),
new THREE.Vector3(-0.35, 0.45, 0),
color
);
addBox(
group,
new THREE.Vector3(0.14, 0.38, 0.16),
new THREE.Vector3(0.35, 0.45, 0),
color
);
addBox(
group,
new THREE.Vector3(0.045, 0.24, 0.045),
new THREE.Vector3(0, 1.12, 0),
0x394b59
);
addBox(
group,
new THREE.Vector3(0.12, 0.12, 0.12),
new THREE.Vector3(0, 1.27, 0),
0xffd166
);
const tag = makeLabel(label, "#ffffff");
tag.position.set(0, 1.58, 0);
group.add(tag);
scene.add(group);
interactive.push(group);
actors[id] = {
id,
label,
group,
color,
visualScale,
reach,
fitsInContainer,
holding: null,
inside: null,
handLocal: new THREE.Vector3(0.42, 0.7, 0.15)
};
}
createActor(
"pip",
"PIP",
new THREE.Vector3(-0.45, 0, 2.15),
0xf39a52,
0.9,
2.2,
true
);
createActor(
"rook",
"ROOK",
new THREE.Vector3(-2.65, 0, -0.45),
0x4d84c6,
1.08,
2.55,
false
);
const actorRing = new THREE.Group();
const ringColor = 0xffd166;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
actorRing,
new THREE.Vector3(0.34, 0.035, 0.07),
new THREE.Vector3(sx * 0.42, 0.025, sz * 0.56),
ringColor,
{ emissive: 0x6c5310, emissiveIntensity: 0.3 }
);
addBox(
actorRing,
new THREE.Vector3(0.07, 0.035, 0.34),
new THREE.Vector3(sx * 0.58, 0.025, sz * 0.42),
ringColor,
{ emissive: 0x6c5310, emissiveIntensity: 0.3 }
);
}
}
scene.add(actorRing);
const objectHelper = new THREE.BoxHelper(objects.cube.group, 0xffd166);
objectHelper.material.transparent = true;
objectHelper.material.opacity = 0.95;
objectHelper.material.depthTest = false;
objectHelper.renderOrder = 30;
scene.add(objectHelper);
const actions = {
move: {
label: "Move to",
hint: "The selected object is the destination. The actor walks to a clear standing position beside it."
},
pick: {
label: "Pick up",
hint: "The selected object must be a compact block or sphere, within reach, and not already held or contained."
},
put: {
label: "Put down",
hint: "Put the selected object down in the open space immediately in front of the actor."
},
open: {
label: "Open",
hint: "The selected object must be a closed container. Its lid must be reachable and unobstructed."
},
close: {
label: "Close",
hint: "The selected container can close only when it is open, empty, and no actor is inside."
},
enter: {
label: "Enter",
hint: "The selected container must be open, empty, within reach, and large enough for the selected actor."
},
exit: {
label: "Exit",
hint: "The selected container must currently contain the actor. This is the required first step after entering."
},
load: {
label: "Load into",
hint: "The actor must already hold a compact item. The selected container must be open, empty, and within reach."
},
unload: {
label: "Take out",
hint: "The selected container must contain an item, and the actor must be nearby with an empty gripper."
},
stack: {
label: "Stack onto",
hint: "The actor must hold a cube. The selected object is the support and must have a clear, flat top."
}
};
for (const [id, actor] of Object.entries(actors)) {
actorSelect.add(new Option(actor.label, id));
}
for (const [id, action] of Object.entries(actions)) {
actionSelect.add(new Option(action.label, id));
}
for (const [id, object] of Object.entries(objects)) {
objectSelect.add(new Option(object.label, id));
}
actorSelect.value = "pip";
actionSelect.value = "pick";
objectSelect.value = "cube";
let selectedActor = "pip";
let selectedAction = actionSelect.value;
let selectedObject = "cube";
let selectedKind = "object";
let busy = false;
function actorById(id) { return actors[id]; }
function objectById(id) { return objects[id]; }
function horizontalDistance(a, b) {
const dx = a.x - b.x;
const dz = a.z - b.z;
return Math.sqrt(dx * dx + dz * dz);
}
function reachable(actor, target) {
return horizontalDistance(actor.group.position, target.group.position) <= actor.reach;
}
function getDropPosition(actor, object) {
const offset = new THREE.Vector3(0, 0, 0.95)
.applyAxisAngle(new THREE.Vector3(0, 1, 0), actor.group.rotation.y);
const x = THREE.MathUtils.clamp(actor.group.position.x + offset.x, -3.35, 3.35);
const z = THREE.MathUtils.clamp(actor.group.position.z + offset.z, -2.55, 2.55);
return new THREE.Vector3(x, object.size.y / 2, z);
}
function dropPositionIsClear(position, object) {
const bounds = { x: 3.42, z: 2.62 };
if (
Math.abs(position.x) + object.size.x / 2 > bounds.x ||
Math.abs(position.z) + object.size.z / 2 > bounds.z
) {
return { ok: false, reason: "The drop position reaches beyond the tabletop boundary." };
}
for (const other of Object.values(objects)) {
if (other.id === object.id || other.heldBy || other.inContainer) continue;
const overlapX =
Math.abs(position.x - other.group.position.x) <
(object.size.x + other.size.x) / 2 - 0.08;
const overlapZ =
Math.abs(position.z - other.group.position.z) <
(object.size.z + other.size.z) / 2 - 0.08;
if (overlapX && overlapZ) {
return {
ok: false,
reason: `The drop position overlaps ${other.label.toLowerCase()}.`
};
}
}
return { ok: true, reason: "There is enough clear tabletop space for the object." };
}
function evaluatePlan() {
const actor = actorById(selectedActor);
const action = selectedAction;
const target = objectById(selectedObject);
const checks = [];
const add = (name, ok, detail) => checks.push({ name, ok, detail });
if (action === "move") {
add("Destination exists", true, `${target.label} is present on the tabletop.`);
add(
"Actor is not enclosed",
!actor.inside,
actor.inside
? "The actor is inside a container and must exit before moving."
: "The actor can move across the tabletop."
);
}
if (action === "pick") {
add(
"Object is liftable",
target.type === "cube" || target.type === "sphere",
target.type === "cube" || target.type === "sphere"
? "Its shape fits the actor’s voxel gripper."
: "This object is too broad or has no graspable center."
);
add(
"Gripper is empty",
!actor.holding,
actor.holding
? `The actor is already holding ${objectById(actor.holding).label.toLowerCase()}.`
: "The actor is not carrying anything."
);
add(
"Object is free",
!target.heldBy && !target.inContainer && !target.supportedBy,
target.heldBy
? "The object is already held."
: target.inContainer
? "The object is inside a container."
: target.supportedBy
? "The object is resting on another object."
: "The object is resting directly on the tabletop."
);
add(
"Object is within reach",
reachable(actor, target),
reachable(actor, target)
? `${horizontalDistance(actor.group.position, target.group.position).toFixed(2)} m from the actor; reach is ${actor.reach.toFixed(2)} m.`
: `Move ${actor.label} closer; the object is ${horizontalDistance(actor.group.position, target.group.position).toFixed(2)} m away.`
);
}
if (action === "put") {
add(
"Actor holds the selected object",
actor.holding === target.id,
actor.holding === target.id
? `${actor.label} is holding ${target.label.toLowerCase()}.`
: `The actor must first pick up ${target.label.toLowerCase()}.`
);
const drop = getDropPosition(actor, target);
const clear = dropPositionIsClear(drop, target);
add("Drop space is clear", clear.ok, clear.reason);
}
if (action === "open") {
add(
"Object has a lid",
target.type === "container",
target.type === "container"
? "The selected object is a hinged container."
: "The selected object has no lid."
);
add(
"Container is closed",
target.lidState === "closed",
target.lidState === "closed"
? "The lid is ready to rotate open."
: "The container is already open."
);
add(
"Lid is unobstructed",
!target.topObject,
target.topObject
? "An object is blocking the lid."
: "Nothing is resting on the lid."
);
add(
"Container is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can reach the lid."
: "The actor must move closer to the container."
);
add(
"Actor is not inside",
actor.inside !== target.id,
actor.inside === target.id
? "The actor cannot open the container from inside."
: "The actor is outside the container."
);
}
if (action === "close") {
add(
"Object has a lid",
target.type === "container",
target.type === "container"
? "The selected object is a hinged container."
: "The selected object has no lid."
);
add(
"Container is open",
target.lidState === "open",
target.lidState === "open"
? "The lid can rotate closed."
: "The container is already closed."
);
add(
"Container is empty",
!target.contents,
target.contents
? `${objectById(target.contents).label} is inside and would be crushed.`
: "The container interior is empty."
);
add(
"No actor is inside",
actor.inside !== target.id,
actor.inside === target.id
? "The actor must exit before closing the container."
: "The container interior is clear of actors."
);
add(
"Container is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can reach the lid."
: "The actor must move closer to the container."
);
}
if (action === "enter") {
add(
"Object is a container",
target.type === "container",
target.type === "container"
? "The selected object has a usable interior."
: "The selected object has no enterable interior."
);
add(
"Container is open",
target.lidState === "open",
target.lidState === "open"
? "The opening is clear."
: "Closed container: open the lid before entering."
);
add(
"Interior is empty",
!target.contents,
target.contents
? `${objectById(target.contents).label} occupies the interior.`
: "There is enough room inside the container."
);
add(
"Actor fits",
actor.fitsInContainer,
actor.fitsInContainer
? `${actor.label}'s dimensions fit through the opening.`
: `${actor.label} is too large to fit inside this container.`
);
add(
"Actor's gripper is empty",
!actor.holding,
actor.holding
? "The actor must put down the carried item before entering."
: "The actor is not carrying an item."
);
add(
"Container is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can reach the opening."
: "The actor must move closer to the container."
);
}
if (action === "exit") {
add(
"Object is a container",
target.type === "container",
target.type === "container"
? "The selected object has an interior."
: "The selected object is not a container."
);
add(
"Actor is inside",
actor.inside === target.id,
actor.inside === target.id
? `${actor.label} is inside ${target.label.toLowerCase()}.`
: `${actor.label} is not inside the selected container.`
);
}
if (action === "load") {
add(
"Object is a container",
target.type === "container",
target.type === "container"
? "The selected object has an interior."
: "The selected object cannot receive an item."
);
add(
"Container is open",
target.lidState === "open",
target.lidState === "open"
? "The opening is clear."
: "Closed container: open the lid before loading it."
);
add(
"Actor holds an item",
!!actor.holding,
actor.holding
? `The actor holds ${objectById(actor.holding).label.toLowerCase()}.`
: "The actor must pick up an item before loading it."
);
if (actor.holding) {
const held = objectById(actor.holding);
add(
"Held item fits",
held.type === "cube" || held.type === "sphere",
held.type === "cube" || held.type === "sphere"
? "The item fits through the container opening."
: "This item is too large to pass through the opening."
);
} else {
add("Held item fits", false, "There is no held item to test.");
}
add(
"Container interior is empty",
!target.contents,
target.contents
? `${objectById(target.contents).label} already occupies the interior.`
: "There is room for one additional item."
);
add(
"Actor is outside",
actor.inside !== target.id,
actor.inside === target.id
? "The actor cannot load an item from inside the container."
: "The actor is outside the container."
);
add(
"Container is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can reach the container opening."
: "The actor must move closer to the container."
);
}
if (action === "unload") {
add(
"Object is a container",
target.type === "container",
target.type === "container"
? "The selected object has an interior."
: "The selected object is not a container."
);
add(
"Container contains an item",
!!target.contents,
target.contents
? `${objectById(target.contents).label} is available to remove.`
: "The container is empty."
);
add(
"Actor's gripper is empty",
!actor.holding,
actor.holding
? `The actor must first put down ${objectById(actor.holding).label.toLowerCase()}.`
: "The actor can receive the item."
);
add(
"Actor is outside",
actor.inside !== target.id,
actor.inside === target.id
? "The actor cannot unload an item while inside."
: "The actor is outside the container."
);
add(
"Container is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can reach into the container."
: "The actor must move closer to the container."
);
}
if (action === "stack") {
add(
"Support has a flat top",
target.type === "platform" || target.type === "cube",
target.type === "platform" || target.type === "cube"
? "The selected support has a level, load-bearing top."
: "This object is round, hollow, or has a removable lid, so it is not a stable support."
);
add(
"Actor holds a cube",
actor.holding && objectById(actor.holding).type === "cube",
actor.holding
? objectById(actor.holding).type === "cube"
? "The held cube has a stable flat base."
: "Only a cube can be stacked reliably; a sphere would roll."
: "The actor must pick up a cube before stacking."
);
add(
"Support top is clear",
!target.topObject && !target.heldBy && !target.inContainer,
target.topObject
? `${objectById(target.topObject).label} already occupies the support.`
: target.heldBy || target.inContainer
? "The support itself is not stationary."
: "The support top is clear."
);
add(
"Stack height is safe",
target.size.y + (actor.holding ? objectById(actor.holding).size.y : 0) <= 2.25,
target.size.y + (actor.holding ? objectById(actor.holding).size.y : 0) <= 2.25
? "The combined height is within the stable stacking limit."
: "The combined stack would be too tall and unstable."
);
add(
"Support is within reach",
reachable(actor, target),
reachable(actor, target)
? "The actor can place the held cube on the support."
: "The actor must move closer to the support."
);
}
const valid = checks.every(check => check.ok);
const failures = checks.filter(check => !check.ok);
return { valid, checks, failures };
}
function renderPlan() {
const actor = actorById(selectedActor);
const target = objectById(selectedObject);
const action = actions[selectedAction];
const plan = evaluatePlan();
actionHint.textContent = action.hint;
planCard.classList.remove("valid", "invalid", "busy");
if (busy) {
planCard.classList.add("busy");
statusIcon.textContent = "…";
statusTitle.textContent = "Executing plan";
statusDetail.textContent = "Updating the tabletop geometry…";
} else if (plan.valid) {
planCard.classList.add("valid");
statusIcon.textContent = "✓";
statusTitle.textContent = "Ready to execute";
statusDetail.textContent = `All ${plan.checks.length} geometric checks passed.`;
} else {
planCard.classList.add("invalid");
statusIcon.textContent = "!";
statusTitle.textContent =
`${plan.failures.length} unmet precondition${plan.failures.length === 1 ? "" : "s"}`;
statusDetail.textContent = plan.failures[0].detail;
}
checksElement.innerHTML = plan.checks.map(check => `
<li class="check ${check.ok ? "pass" : "fail"}">
<span class="check-mark">${check.ok ? "✓" : "×"}</span>
<div>
<div class="check-name">${check.name}</div>
<div class="check-detail">${check.detail}</div>
</div>
</li>
`).join("");
executeButton.disabled = !plan.valid || busy;
executeButton.textContent = busy
? "Executing…"
: plan.valid
? `Execute ${action.label.toLowerCase()}`
: "Plan blocked";
actorSelect.disabled = busy;
actionSelect.disabled = busy;
objectSelect.disabled = busy;
}
const tweens = [];
function tween(duration, update) {
return new Promise(resolve => {
tweens.push({ elapsed: 0, duration, update, resolve });
});
}
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function faceActor(actor, point) {
const dx = point.x - actor.group.position.x;
const dz = point.z - actor.group.position.z;
actor.group.rotation.y = Math.atan2(dx, dz);
}
function handPosition(actor) {
actor.group.updateMatrixWorld(true);
return actor.group.localToWorld(actor.handLocal.clone());
}
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("show");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => toastElement.classList.remove("show"), 2800);
}
function addHistory(message) {
const empty = historyElement.querySelector(".history-empty");
if (empty) empty.remove();
const item = document.createElement("div");
item.className = "history-item";
item.textContent = message;
historyElement.prepend(item);
while (historyElement.children.length > 6) {
historyElement.lastElementChild.remove();
}
}
async function executePlan() {
const plan = evaluatePlan();
if (!plan.valid || busy) return;
busy = true;
renderPlan();
const actor = actorById(selectedActor);
const target = objectById(selectedObject);
const action = selectedAction;
try {
if (action === "move") {
const away = actor.group.position.clone().sub(target.group.position);
away.y = 0;
if (away.lengthSq() < 0.05) away.set(0, 0, 1);
away.normalize();
const destination = target.group.position.clone().addScaledVector(away, 1.18);
destination.y = 0;
destination.x = THREE.MathUtils.clamp(destination.x, -3.25, 3.25);
destination.z = THREE.MathUtils.clamp(destination.z, -2.4, 2.4);
faceActor(actor, target.group.position);
const start = actor.group.position.clone();
await tween(650, t => {
actor.group.position.lerpVectors(start, destination, t);
});
actor.group.position.copy(destination);
}
if (action === "pick") {
target.heldBy = actor.id;
target.supportedBy = null;
target.inContainer = null;
actor.holding = target.id;
target.animating = true;
const start = target.group.position.clone();
const end = handPosition(actor);
faceActor(actor, target.group.position);
await tween(520, t => {
target.group.position.lerpVectors(start, end, t);
target.group.position.y += Math.sin(t * Math.PI) * 0.35;
});
target.group.position.copy(end);
target.animating = false;
}
if (action === "put") {
const destination = getDropPosition(actor, target);
target.animating = true;
const start = target.group.position.clone();
await tween(500, t => {
target.group.position.lerpVectors(start, destination, t);
target.group.position.y += Math.sin(t * Math.PI) * 0.2;
});
target.group.position.copy(destination);
target.animating = false;
actor.holding = null;
target.heldBy = null;
target.supportedBy = null;
}
if (action === "open") {
faceActor(actor, target.group.position);
const startAngle = target.lidPivot.rotation.x;
await tween(520, t => {
target.lidPivot.rotation.x = THREE.MathUtils.lerp(startAngle, -1.22, t);
});
target.lidState = "open";
}
if (action === "close") {
faceActor(actor, target.group.position);
const startAngle = target.lidPivot.rotation.x;
await tween(520, t => {
target.lidPivot.rotation.x = THREE.MathUtils.lerp(startAngle, 0, t);
});
target.lidState = "closed";
}
if (action === "enter") {
faceActor(actor, target.group.position);
const start = actor.group.position.clone();
const destination = target.group.position.clone().add(new THREE.Vector3(0, 0.18, 0));
await tween(600, t => {
actor.group.position.lerpVectors(start, destination, t);
actor.group.position.y += Math.sin(t * Math.PI) * 0.22;
});
actor.inside = target.id;
actor.group.position.copy(destination);
}
if (action === "exit") {
const start = actor.group.position.clone();
const destination = target.group.position.clone().add(new THREE.Vector3(0, 0, 1.3));
destination.x = THREE.MathUtils.clamp(destination.x, -3.25, 3.25);
destination.z = THREE.MathUtils.clamp(destination.z, -2.4, 2.4);
await tween(550, t => {
actor.group.position.lerpVectors(start, destination, t);
actor.group.position.y += Math.sin(t * Math.PI) * 0.18;
});
actor.inside = null;
actor.group.position.copy(destination);
actor.group.rotation.y = 0;
}
if (action === "load") {
const held = objectById(actor.holding);
held.animating = true;
const start = held.group.position.clone();
const destination = target.group.position.clone().add(
new THREE.Vector3(0, 0.16 + held.size.y / 2, 0)
);
await tween(520, t => {
held.group.position.lerpVectors(start, destination, t);
held.group.position.y += Math.sin(t * Math.PI) * 0.3;
});
held.group.position.copy(destination);
held.animating = false;
held.heldBy = null;
held.inContainer = target.id;
held.supportedBy = null;
target.contents = held.id;
actor.holding = null;
}
if (action === "unload") {
const held = objectById(target.contents);
held.animating = true;
const start = held.group.position.clone();
const destination = handPosition(actor);
await tween(520, t => {
held.group.position.lerpVectors(start, destination, t);
held.group.position.y += Math.sin(t * Math.PI) * 0.3;
});
held.group.position.copy(destination);
held.animating = false;
held.inContainer = null;
held.heldBy = actor.id;
target.contents = null;
actor.holding = held.id;
}
if (action === "stack") {
const held = objectById(actor.holding);
const destination = target.group.position.clone().add(
new THREE.Vector3(0, target.size.y / 2 + held.size.y / 2, 0)
);
held.animating = true;
const start = held.group.position.clone();
await tween(550, t => {
held.group.position.lerpVectors(start, destination, t);
held.group.position.y += Math.sin(t * Math.PI) * 0.22;
});
held.group.position.copy(destination);
held.animating = false;
held.heldBy = null;
held.supportedBy = target.id;
target.topObject = held.id;
actor.holding = null;
}
addHistory(`${actor.label} completed “${actions[action].label}” on ${target.label}.`);
showToast(`${actions[action].label} completed successfully.`);
} finally {
busy = false;
renderPlan();
}
}
actorSelect.addEventListener("change", () => {
selectedActor = actorSelect.value;
selectedKind = "actor";
renderPlan();
});
actionSelect.addEventListener("change", () => {
selectedAction = actionSelect.value;
renderPlan();
});
objectSelect.addEventListener("change", () => {
selectedObject = objectSelect.value;
selectedKind = "object";
renderPlan();
});
executeButton.addEventListener("click", executePlan);
document.querySelector("#resetButton").addEventListener("click", () => {
window.location.reload();
});
historyElement.innerHTML = `
<div class="history-empty">
No actions yet. Try moving Pip to the closed crate, open it, and then load the cube.
</div>
`;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
let dragged = false;
function pickAt(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(interactive, true);
for (const hit of hits) {
let node = hit.object;
while (node) {
if (node.userData.objectId) {
selectedObject = node.userData.objectId;
selectedKind = "object";
objectSelect.value = selectedObject;
renderPlan();
return;
}
if (node.userData.actorId) {
selectedActor = node.userData.actorId;
selectedKind = "actor";
actorSelect.value = selectedActor;
renderPlan();
return;
}
node = node.parent;
}
}
}
renderer.domElement.addEventListener("pointerdown", event => {
pointerDown = {
x: event.clientX,
y: event.clientY,
theta: orbit.theta,
phi: orbit.phi
};
dragged = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) dragged = true;
orbit.theta = pointerDown.theta - dx * 0.007;
orbit.phi = THREE.MathUtils.clamp(pointerDown.phi + dy * 0.006, 0.48, 1.32);
});
renderer.domElement.addEventListener("pointerup", event => {
if (!dragged) pickAt(event);
pointerDown = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.8
);
}, { passive: false });
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewSize = width < 760 ? 5.25 : 5.55;
camera.left = -viewSize * aspect / 2;
camera.right = viewSize * aspect / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.zoom = orbit.zoom * (width < 760 ? 0.82 : 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
function updateCamera() {
const radius = 11;
const horizontal = radius * Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.theta),
orbit.target.y + radius * Math.cos(orbit.phi),
orbit.target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function updateDynamicObjects() {
for (const actor of Object.values(actors)) {
if (actor.inside && !busy) {
const container = objectById(actor.inside);
actor.group.position.copy(container.group.position);
actor.group.position.y += 0.18;
}
if (actor.holding) {
const held = objectById(actor.holding);
if (!held.animating) {
held.group.position.copy(handPosition(actor));
}
}
}
const selectedActorObject = actorById(selectedActor);
actorRing.position.copy(selectedActorObject.group.position);
actorRing.position.y = 0.035;
actorRing.scale.setScalar(selectedActorObject.visualScale);
actorRing.rotation.y = selectedActorObject.group.rotation.y;
if (selectedKind === "object") {
objectHelper.setFromObject(objectById(selectedObject).group);
objectHelper.visible = true;
} else {
objectHelper.visible = false;
}
}
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
for (let index = tweens.length - 1; index >= 0; index--) {
const animation = tweens[index];
animation.elapsed += delta * 1000;
const progress = Math.min(animation.elapsed / animation.duration, 1);
animation.update(easeInOutCubic(progress));
if (progress >= 1) {
tweens.splice(index, 1);
animation.resolve();
}
}
updateCamera();
updateDynamicObjects();
renderer.render(scene, camera);
}
renderPlan();
requestAnimationFrame(animate);
</script>
</body>
</html>
```