Prompt specification
Build or customize the Three.js 3D scene "Cooperative Sculpture Transfer Through a Hatch" 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: Cooperative Sculpture Transfer Through a Hatch
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cooperative-sculpture-transfer-through-a-hatch-x3732
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows hand-object contact during grasping and release. Create two characters transferring one long rigid sculpture through an offset hatch. Coordinate grip changes and object rotation, verifying the swept shape clears the hatch while support remains continuous. Low-poly.
Working Three.js Starter (cooperative-sculpture-transfer-through-a-hatch-x3732):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Offset Hatch Transfer</title>
<style>
:root {
--bg: #071019;
--panel: rgba(8, 19, 29, 0.88);
--line: rgba(153, 196, 219, 0.2);
--text: #e7f4fb;
--muted: #8ea8b8;
--cyan: #48dfd0;
--green: #79ef9b;
--amber: #ffbd59;
--red: #ff6e73;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 18px;
left: 20px;
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.eyebrow {
color: var(--cyan);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 0;
font-size: clamp(20px, 2.4vw, 34px);
line-height: 1;
letter-spacing: -0.035em;
}
.status-row {
display: flex;
gap: 8px;
margin-left: 8px;
}
.badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(8, 19, 29, 0.76);
backdrop-filter: blur(10px);
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
.badge.pass {
color: var(--green);
border-color: rgba(121, 239, 155, 0.28);
}
.badge.fail {
color: var(--red);
border-color: rgba(255, 110, 115, 0.3);
}
.readout {
position: absolute;
top: 104px;
right: 20px;
width: min(330px, calc(100vw - 40px));
padding: 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
backdrop-filter: blur(16px);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
pointer-events: auto;
}
.readout h2 {
margin: 0 0 13px;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #c6dce8;
}
.metric {
display: grid;
grid-template-columns: 1fr auto;
gap: 12px;
padding: 8px 0;
border-top: 1px solid rgba(153, 196, 219, 0.11);
color: var(--muted);
font-size: 12px;
}
.metric:first-of-type { border-top: 0; }
.metric strong {
color: var(--text);
font: 700 12px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
}
.metric strong.good { color: var(--green); }
.metric strong.cyan { color: var(--cyan); }
.metric strong.amber { color: var(--amber); }
.note {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid rgba(153, 196, 219, 0.11);
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.grip-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
margin: 12px 0 3px;
}
.grip {
padding: 8px;
border: 1px solid var(--line);
border-radius: 8px;
color: var(--muted);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.grip.active {
color: var(--green);
border-color: rgba(121, 239, 155, 0.34);
background: rgba(121, 239, 155, 0.07);
}
.grip.reaching {
color: var(--amber);
border-color: rgba(255, 189, 89, 0.34);
background: rgba(255, 189, 89, 0.07);
}
.phase {
position: absolute;
left: 20px;
bottom: 100px;
max-width: min(520px, calc(100vw - 40px));
padding: 13px 15px;
border-left: 3px solid var(--cyan);
background: rgba(8, 19, 29, 0.77);
backdrop-filter: blur(10px);
}
.phase-title {
font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
color: var(--cyan);
}
.phase-copy {
margin-top: 6px;
color: #b9ceda;
font-size: 12px;
line-height: 1.45;
}
.timeline {
position: absolute;
left: 20px;
right: 20px;
bottom: 18px;
height: 64px;
display: flex;
align-items: center;
gap: 12px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: auto;
}
button, select {
color: var(--text);
background: #112532;
border: 1px solid rgba(153, 196, 219, 0.22);
border-radius: 8px;
padding: 8px 10px;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
}
button:hover, select:hover {
border-color: var(--cyan);
color: var(--cyan);
}
#play {
min-width: 68px;
color: #041311;
background: var(--cyan);
border-color: var(--cyan);
}
#scrub {
min-width: 100px;
flex: 1;
accent-color: var(--cyan);
}
#time {
min-width: 83px;
color: var(--muted);
text-align: center;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.views {
display: flex;
gap: 6px;
}
.help {
position: absolute;
left: 50%;
top: 19px;
transform: translateX(-50%);
color: rgba(205, 227, 239, 0.62);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.05em;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--cyan);
background: var(--bg);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
}
@media (max-width: 760px) {
.help { display: none; }
.status-row { margin-left: 0; }
.readout {
top: 118px;
right: 12px;
width: 285px;
padding: 13px;
}
.topbar { left: 12px; top: 12px; }
.timeline { left: 10px; right: 10px; bottom: 10px; }
.views { display: none; }
.phase { left: 12px; bottom: 86px; max-width: calc(100vw - 24px); }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div id="loading">BUILDING TRANSFER SCENE…</div>
<div class="hud">
<div class="topbar">
<div>
<div class="eyebrow">Coordinated manipulation / geometry verification</div>
<h1>Offset Hatch Transfer</h1>
</div>
<div class="status-row">
<div id="sweepBadge" class="badge pass">Sweep clear</div>
<div id="supportBadge" class="badge pass">Support continuous</div>
</div>
</div>
<div class="help">DRAG TO ORBIT · WHEEL TO ZOOM · SPACE TO PAUSE</div>
<aside class="readout">
<h2>Live transfer monitor</h2>
<div class="metric">
<span>Current phase</span>
<strong id="phaseName" class="cyan">DUAL GRIP</strong>
</div>
<div class="metric">
<span>Sculpture attitude</span>
<strong id="angleValue">−8.0°</strong>
</div>
<div class="metric">
<span>Wall-normal position</span>
<strong id="depthValue">−0.52 m</strong>
</div>
<div class="metric">
<span>Hatch aperture</span>
<strong>1.45 × 4.80 m</strong>
</div>
<div class="metric">
<span>Lateral offset</span>
<strong class="amber">+0.85 m</strong>
</div>
<div class="metric">
<span>Conservative envelope</span>
<strong>0.56 × 3.80 × 0.36 m</strong>
</div>
<div class="metric">
<span>Minimum sweep gap</span>
<strong id="clearanceValue" class="good">+0.33 m</strong>
</div>
<div class="metric">
<span>Minimum active grips</span>
<strong id="gripCount" class="good">2 / 4</strong>
</div>
<div class="eyebrow" style="margin-top:14px">Contact allocation</div>
<div class="grip-grid">
<div id="aLow" class="grip active">A · LOWER</div>
<div id="aUp" class="grip active">A · UPPER</div>
<div id="bLow" class="grip">B · LOWER</div>
<div id="bUp" class="grip">B · UPPER</div>
</div>
<p class="note">
The cyan patch is the conservative swept cross-section at the wall.
Verification clips the sculpture envelope against the wall slab at
900 trajectory samples. Green hand markers indicate rigid contact;
amber indicates approach.
</p>
</aside>
<div class="phase">
<div id="phaseTitle" class="phase-title">01 / DUAL GRIP</div>
<div id="phaseCopy" class="phase-copy">
Character A supports both handles while Character B reaches through the offset opening.
</div>
</div>
<div class="timeline">
<button id="play" title="Play or pause">PAUSE</button>
<button id="reset" title="Restart transfer">RESET</button>
<input id="scrub" type="range" min="0" max="18" step="0.01" value="0">
<div id="time">00.0 / 18.0</div>
<select id="speed" title="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
<div class="views">
<button id="overview">OVERVIEW</button>
<button id="hatch">HATCH</button>
<button id="side">SIDE</button>
</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const viewport = $("viewport");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
$("loading").textContent = "WEBGL IS NOT AVAILABLE";
throw error;
}
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.05;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.Fog(0x071019, 15, 32);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit controls: no examples/addons are used.
const orbit = {
target: new THREE.Vector3(0.25, 2.35, 0),
theta: 0.70,
phi: 1.13,
radius: 12.7
};
function updateCamera() {
const s = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * s * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * s * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function setView(name) {
if (name === "overview") {
orbit.target.set(0.25, 2.35, 0);
orbit.theta = 0.70;
orbit.phi = 1.13;
orbit.radius = 12.7;
} else if (name === "hatch") {
orbit.target.set(0.85, 2.55, 0);
orbit.theta = 0.10;
orbit.phi = 1.31;
orbit.radius = 9.2;
} else {
orbit.target.set(0.65, 2.35, 0);
orbit.theta = 1.48;
orbit.phi = 1.32;
orbit.radius = 10.7;
}
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.32, 1.48);
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.008,
6.2,
19
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => setView("overview"));
const hemisphere = new THREE.HemisphereLight(0xbfe8ff, 0x162229, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.2);
keyLight.position.set(6, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x46e5d4, 20, 16, 2);
rimLight.position.set(-4, 4.5, -3);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9c58, 16, 14, 2);
warmLight.position.set(5, 4, 4);
scene.add(warmLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0d1b24,
roughness: 0.92,
metalness: 0.08
});
const floor = new THREE.Mesh(
new THREE.BoxGeometry(15, 0.18, 15),
floorMaterial
);
floor.position.y = -0.1;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(14, 28, 0x2d5260, 0x17303c);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.46;
scene.add(grid);
function makeZone(color, z, label) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.075,
depthWrite: false
});
const plane = new THREE.Mesh(new THREE.PlaneGeometry(5.4, 4.1), material);
plane.rotation.x = -Math.PI / 2;
plane.position.set(0.85, 0.018, z);
scene.add(plane);
const sprite = makeTextSprite(label, {
color: "#b8d3df",
background: "rgba(6,18,27,0.74)",
border: "rgba(120,170,190,0.25)",
scale: 2.25
});
sprite.position.set(0.85, 0.12, z);
scene.add(sprite);
}
makeZone(0x49d8e0, -3.15, "SOURCE / A");
makeZone(0xffad55, 3.15, "RECEIVER / B");
const HATCH = {
minX: 0.125,
maxX: 1.575,
minY: 0.22,
maxY: 5.02,
wallDepth: 0.28
};
const OBJECT = {
width: 0.56,
height: 3.80,
depth: 0.36
};
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x1c3040,
roughness: 0.78,
metalness: 0.12,
transparent: true,
opacity: 0.78,
depthWrite: true
});
function wallBox(x0, x1, y0, y1) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(x1 - x0, y1 - y0, HATCH.wallDepth),
wallMaterial
);
mesh.position.set((x0 + x1) / 2, (y0 + y1) / 2, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Wall panels are assembled around the aperture, so the hole is real geometry.
wallBox(-4.0, 4.4, 0, HATCH.minY);
wallBox(-4.0, 4.4, HATCH.maxY, 6.1);
wallBox(-4.0, HATCH.minX, HATCH.minY, HATCH.maxY);
wallBox(HATCH.maxX, 4.4, HATCH.minY, HATCH.maxY);
function makeStripeTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#e7a42e";
ctx.fillRect(0, 0, 128, 128);
ctx.strokeStyle = "#17222a";
ctx.lineWidth = 24;
for (let x = -128; x < 256; x += 48) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x + 128, 128);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 2);
return texture;
}
const stripeMaterial = new THREE.MeshStandardMaterial({
map: makeStripeTexture(),
roughness: 0.65,
metalness: 0.22
});
const frameDepth = 0.42;
const frameThickness = 0.12;
function frameBox(w, h, x, y) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, frameDepth),
stripeMaterial
);
mesh.position.set(x, y, 0);
mesh.castShadow = true;
scene.add(mesh);
}
frameBox(
frameThickness,
HATCH.maxY - HATCH.minY + frameThickness * 2,
HATCH.minX - frameThickness / 2,
(HATCH.minY + HATCH.maxY) / 2
);
frameBox(
frameThickness,
HATCH.maxY - HATCH.minY + frameThickness * 2,
HATCH.maxX + frameThickness / 2,
(HATCH.minY + HATCH.maxY) / 2
);
frameBox(
HATCH.maxX - HATCH.minX + frameThickness * 2,
frameThickness,
(HATCH.minX + HATCH.maxX) / 2,
HATCH.minY - frameThickness / 2
);
frameBox(
HATCH.maxX - HATCH.minX + frameThickness * 2,
frameThickness,
(HATCH.minX + HATCH.maxX) / 2,
HATCH.maxY + frameThickness / 2
);
const aperturePoints = [
new THREE.Vector3(HATCH.minX, HATCH.minY, HATCH.wallDepth / 2 + 0.012),
new THREE.Vector3(HATCH.maxX, HATCH.minY, HATCH.wallDepth / 2 + 0.012),
new THREE.Vector3(HATCH.maxX, HATCH.maxY, HATCH.wallDepth / 2 + 0.012),
new THREE.Vector3(HATCH.minX, HATCH.maxY, HATCH.wallDepth / 2 + 0.012)
];
const apertureLine = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(aperturePoints),
new THREE.LineBasicMaterial({ color: 0x48dfd0 })
);
scene.add(apertureLine);
const hatchLabel = makeTextSprite("OFFSET HATCH +0.85 m", {
color: "#ffce78",
background: "rgba(8,19,29,0.86)",
border: "rgba(255,189,89,0.35)",
scale: 2.65
});
hatchLabel.position.set(0.85, 5.58, 0.22);
scene.add(hatchLabel);
const dimensionGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 5.32, 0.2),
new THREE.Vector3(0.85, 5.32, 0.2),
new THREE.Vector3(0, 5.22, 0.2),
new THREE.Vector3(0, 5.42, 0.2),
new THREE.Vector3(0.85, 5.22, 0.2),
new THREE.Vector3(0.85, 5.42, 0.2)
]);
scene.add(new THREE.LineSegments(
dimensionGeometry,
new THREE.LineBasicMaterial({ color: 0xffbd59 })
));
// One rigid low-poly sculpture.
const sculpture = new THREE.Group();
scene.add(sculpture);
const sculptureMaterial = new THREE.MeshStandardMaterial({
color: 0x42cdbf,
roughness: 0.32,
metalness: 0.58,
flatShading: true
});
const sculptureDark = new THREE.MeshStandardMaterial({
color: 0x164a55,
roughness: 0.4,
metalness: 0.52,
flatShading: true
});
const sculptureAmber = new THREE.MeshStandardMaterial({
color: 0xffb54c,
roughness: 0.38,
metalness: 0.42,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 3.18, 0.24),
sculptureMaterial
);
shaft.castShadow = true;
sculpture.add(shaft);
const nodeGeometry = new THREE.OctahedronGeometry(1, 0);
const nodeSpecs = [
[-1.52, 0.23, 0.32, 0.14, sculptureAmber],
[-0.76, 0.25, 0.30, 0.15, sculptureDark],
[ 0.00, 0.27, 0.36, 0.16, sculptureMaterial],
[ 0.76, 0.25, 0.30, 0.15, sculptureDark],
[ 1.52, 0.23, 0.32, 0.14, sculptureAmber]
];
for (const [y, sx, sy, sz, material] of nodeSpecs) {
const node = new THREE.Mesh(nodeGeometry, material);
node.position.y = y;
node.scale.set(sx, sy, sz);
node.rotation.y = y * 0.7;
node.castShadow = true;
sculpture.add(node);
}
const handleGeometry = new THREE.TorusGeometry(0.19, 0.035, 4, 12);
const upperHandle = new THREE.Mesh(
handleGeometry,
new THREE.MeshStandardMaterial({
color: 0xffc05c,
emissive: 0x633500,
emissiveIntensity: 0.35,
roughness: 0.35,
metalness: 0.45,
flatShading: true
})
);
upperHandle.position.y = 1.22;
sculpture.add(upperHandle);
const lowerHandle = new THREE.Mesh(
handleGeometry,
upperHandle.material.clone()
);
lowerHandle.position.y = -1.22;
sculpture.add(lowerHandle);
const upperGripHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.012, 4, 16),
new THREE.MeshBasicMaterial({
color: 0x79ef9b,
transparent: true,
opacity: 0.9
})
);
upperGripHalo.position.y = 1.22;
sculpture.add(upperGripHalo);
const lowerGripHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.245, 0.012, 4, 16),
new THREE.MeshBasicMaterial({
color: 0x79ef9b,
transparent: true,
opacity: 0.9
})
);
lowerGripHalo.position.y = -1.22;
sculpture.add(lowerGripHalo);
function makeTextSprite(text, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 144;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (options.background) {
ctx.fillStyle = options.background;
ctx.beginPath();
ctx.roundRect(6, 8, 628, 128, 22);
ctx.fill();
}
if (options.border) {
ctx.strokeStyle = options.border;
ctx.lineWidth = 3;
ctx.beginPath();
ctx.roundRect(6, 8, 628, 128, 22);
ctx.stroke();
}
ctx.fillStyle = options.color || "#d8edf5";
ctx.font = "700 42px ui-monospace, SFMono-Regular, Menlo, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 320, 74);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const scale = options.scale || 2;
sprite.scale.set(scale, scale * 0.225, 1);
sprite.renderOrder = 10;
return sprite;
}
function makeHuman(mainColor, accentColor, facing) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: mainColor,
roughness: 0.76,
metalness: 0.06,
flatShading: true
});
const accentMaterial = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.65,
metalness: 0.12,
flatShading: true
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xd9a77d,
roughness: 0.88,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x17232c,
roughness: 0.82,
flatShading: true
});
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.52, 1.08, 5),
bodyMaterial
);
torso.position.y = 1.72;
torso.castShadow = true;
group.add(torso);
const belt = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.15, 0.52),
accentMaterial
);
belt.position.y = 1.28;
belt.castShadow = true;
group.add(belt);
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.14, 0.22, 6),
skinMaterial
);
neck.position.y = 2.36;
group.add(neck);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.31, 0),
skinMaterial
);
head.position.y = 2.72;
head.scale.set(0.92, 1.08, 0.9);
head.castShadow = true;
group.add(head);
const hair = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.33, 0.18, 6),
darkMaterial
);
hair.position.set(0, 2.92, -0.015);
group.add(hair);
const visor = new THREE.Mesh(
new THREE.BoxGeometry(0.39, 0.12, 0.10),
accentMaterial
);
visor.position.set(0, 2.75, 0.27);
group.add(visor);
const legPivots = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.19, 1.21, 0);
group.add(pivot);
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.72, 0.23),
darkMaterial
);
leg.position.y = -0.36;
leg.castShadow = true;
pivot.add(leg);
const shoe = new THREE.Mesh(
new THREE.BoxGeometry(0.27, 0.17, 0.40),
accentMaterial
);
shoe.position.set(0, -0.76, 0.07);
shoe.castShadow = true;
pivot.add(shoe);
legPivots.push(pivot);
}
group.rotation.y = facing;
scene.add(group);
return { group, legPivots };
}
const characterA = makeHuman(0x327dba, 0x66d9ff, Math.PI / 2);
const characterB = makeHuman(0xc96945, 0xffb15b, -Math.PI / 2);
const armMaterialA = new THREE.MeshStandardMaterial({
color: 0x327dba,
roughness: 0.75,
flatShading: true
});
const armMaterialB = new THREE.MeshStandardMaterial({
color: 0xc96945,
roughness: 0.75,
flatShading: true
});
const handMaterialA = new THREE.MeshStandardMaterial({
color: 0x9aaab1,
roughness: 0.65,
flatShading: true
});
const handMaterialB = new THREE.MeshStandardMaterial({
color: 0x9aaab1,
roughness: 0.65,
flatShading: true
});
function makeArm(material, handMaterial) {
const upper = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.105, 1, 6),
material
);
const lower = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.092, 1, 6),
material
);
const hand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.115, 0),
handMaterial
);
upper.castShadow = lower.castShadow = hand.castShadow = true;
scene.add(upper, lower, hand);
return { upper, lower, hand };
}
const arms = {
aLow: makeArm(armMaterialA, handMaterialA),
aUp: makeArm(armMaterialA, handMaterialA),
bLow: makeArm(armMaterialB, handMaterialB),
bUp: makeArm(armMaterialB, handMaterialB)
};
const UP = new THREE.Vector3(0, 1, 0);
function orientBone(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
mesh.scale.set(1, length, 1);
}
const shoulderSpecs = {
aLow: { human: characterA, local: new THREE.Vector3(-0.43, 2.18, 0) },
aUp: { human: characterA, local: new THREE.Vector3( 0.43, 2.18, 0) },
bUp: { human: characterB, local: new THREE.Vector3(-0.43, 2.18, 0) },
bLow: { human: characterB, local: new THREE.Vector3( 0.43, 2.18, 0) }
};
const DURATION = 18;
const HATCH_CENTER_X = 0.85;
const OBJECT_CENTER_Y = 2.45;
function smoothstep(a, b, value) {
const x = THREE.MathUtils.clamp((value - a) / (b - a), 0, 1);
return x * x * (3 - 2 * x);
}
function poseAt(time) {
const alignment = smoothstep(1.5, 5.0, time);
const transfer = smoothstep(5.0, 12.0, time);
const finalPivot = smoothstep(12.0, 16.0, time);
const angle =
THREE.MathUtils.lerp(
THREE.MathUtils.degToRad(-8),
0,
alignment
) +
THREE.MathUtils.lerp(
0,
THREE.MathUtils.degToRad(22),
finalPivot
);
const z = THREE.MathUtils.lerp(-0.52, 1.35, transfer);
return {
position: new THREE.Vector3(HATCH_CENTER_X, OBJECT_CENTER_Y, z),
quaternion: new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 0, 1),
angle
),
angle
};
}
function contactFlags(time) {
return {
aLow: time < 9.7,
aUp: time < 3.2,
bLow: time >= 9.4,
bUp: time >= 2.8
};
}
const BOX_EDGES = [
[0, 1], [1, 2], [2, 3], [3, 0],
[4, 5], [5, 6], [6, 7], [7, 4],
[0, 4], [1, 5], [2, 6], [3, 7]
];
function boxCorners(pose) {
const x = OBJECT.width / 2;
const y = OBJECT.height / 2;
const z = OBJECT.depth / 2;
const local = [
[-x, -y, -z], [ x, -y, -z],
[ x, y, -z], [-x, y, -z],
[-x, -y, z], [ x, -y, z],
[ x, y, z], [-x, y, z]
];
return local.map(p =>
new THREE.Vector3(...p)
.applyQuaternion(pose.quaternion)
.add(pose.position)
);
}
// Clip the sculpture's conservative oriented box against the wall slab.
// Every vertex of the resulting intersection polygon must remain in the aperture.
function wallFootprint(pose) {
const corners = boxCorners(pose);
const points = [];
const halfDepth = HATCH.wallDepth / 2;
function addIfInside(point) {
if (
point.z >= -halfDepth - 1e-7 &&
point.z <= halfDepth + 1e-7
) {
points.push(point.clone());
}
}
function intersectEdgeAtZ(a, b, zPlane) {
const dz = b.z - a.z;
if (Math.abs(dz) < 1e-10) return null;
const t = (zPlane - a.z) / dz;
if (t < -1e-8 || t > 1 + 1e-8) return null;
return new THREE.Vector3().lerpVectors(a, b, THREE.MathUtils.clamp(t, 0, 1));
}
for (const corner of corners) addIfInside(corner);
for (const [aIndex, bIndex] of BOX_EDGES) {
const a = corners[aIndex];
const b = corners[bIndex];
const atBack = intersectEdgeAtZ(a, b, -halfDepth);
const atFront = intersectEdgeAtZ(a, b, halfDepth);
if (atBack) points.push(atBack);
if (atFront) points.push(atFront);
}
return points;
}
function signedApertureClearance(point) {
const dx = Math.min(
point.x - HATCH.minX,
HATCH.maxX - point.x
);
const dy = Math.min(
point.y - HATCH.minY,
HATCH.maxY - point.y
);
return Math.min(dx, dy);
}
// Precompute the complete motion before playback.
const VERIFY_SAMPLES = 900;
const verification = {
minimumClearance: Infinity,
minimumClearanceTime: 0,
minimumSupports: Infinity,
supportedFrames: 0,
points: [],
bounds: {
minX: Infinity,
maxX: -Infinity,
minY: Infinity,
maxY: -Infinity
}
};
for (let i = 0; i < VERIFY_SAMPLES; i++) {
const time = (i / (VERIFY_SAMPLES - 1)) * DURATION;
const pose = poseAt(time);
const footprint = wallFootprint(pose);
const flags = contactFlags(time);
const supportCount =
Number(flags.aLow) +
Number(flags.aUp) +
Number(flags.bLow) +
Number(flags.bUp);
verification.minimumSupports = Math.min(
verification.minimumSupports,
supportCount
);
if (supportCount >= 1) verification.supportedFrames++;
for (const point of footprint) {
const clearance = signedApertureClearance(point);
if (clearance < verification.minimumClearance) {
verification.minimumClearance = clearance;
verification.minimumClearanceTime = time;
}
verification.points.push(
point.x,
point.y,
HATCH.wallDepth / 2 + 0.019
);
verification.bounds.minX = Math.min(verification.bounds.minX, point.x);
verification.bounds.maxX = Math.max(verification.bounds.maxX, point.x);
verification.bounds.minY = Math.min(verification.bounds.minY, point.y);
verification.bounds.maxY = Math.max(verification.bounds.maxY, point.y);
}
}
const sweepPass = verification.minimumClearance >= 0;
const supportPass = verification.minimumSupports >= 1;
$("sweepBadge").className = `badge ${sweepPass ? "pass" : "fail"}`;
$("sweepBadge").textContent = sweepPass ? "Sweep clear" : "Sweep collision";
$("supportBadge").className = `badge ${supportPass ? "pass" : "fail"}`;
$("supportBadge").textContent = supportPass
? "Support continuous"
: "Support interrupted";
$("clearanceValue").textContent =
`${verification.minimumClearance >= 0 ? "+" : ""}` +
`${verification.minimumClearance.toFixed(2)} m`;
$("clearanceValue").className =
verification.minimumClearance >= 0 ? "good" : "";
$("gripCount").textContent = `${verification.minimumSupports} / 4`;
// Visualize the actual sampled wall-crossing footprint.
if (verification.points.length) {
const sweptGroup = new THREE.Group();
const width =
verification.bounds.maxX - verification.bounds.minX;
const height =
verification.bounds.maxY - verification.bounds.minY;
const sweptGeometry = new THREE.PlaneGeometry(width, height);
const sweptMaterial = new THREE.MeshBasicMaterial({
color: 0x48dfd0,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false
});
const sweptPlane = new THREE.Mesh(sweptGeometry, sweptMaterial);
sweptPlane.position.set(
(verification.bounds.minX + verification.bounds.maxX) / 2,
(verification.bounds.minY + verification.bounds.maxY) / 2,
HATCH.wallDepth / 2 + 0.015
);
sweptGroup.add(sweptPlane);
const sweptOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(sweptGeometry),
new THREE.LineBasicMaterial({
color: 0x48dfd0,
transparent: true,
opacity: 0.62
})
);
sweptOutline.position.copy(sweptPlane.position);
sweptOutline.position.z += 0.001;
sweptGroup.add(sweptOutline);
const pointGeometry = new THREE.BufferGeometry();
pointGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(verification.points, 3)
);
const sweptPoints = new THREE.Points(
pointGeometry,
new THREE.PointsMaterial({
color: 0x9bfff3,
size: 0.038,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
sweptGroup.add(sweptPoints);
scene.add(sweptGroup);
}
const sweptLabel = makeTextSprite("VERIFIED SWEPT CROSS-SECTION", {
color: "#83f4e9",
background: "rgba(5,24,30,0.72)",
border: "rgba(72,223,208,0.28)",
scale: 2.65
});
sweptLabel.position.set(0.85, 5.28, 0.23);
scene.add(sweptLabel);
const phaseDefinitions = [
{
limit: 3.2,
title: "01 / DUAL GRIP",
name: "DUAL GRIP",
copy: "Character A supports both handles while Character B reaches through the offset opening."
},
{
limit: 5.0,
title: "02 / ALIGN TO APERTURE",
name: "ALIGN",
copy: "The sculpture rotates upright before any part of its envelope enters the wall slab."
},
{
limit: 8.3,
title: "03 / CONTINUOUS PUSH",
name: "PUSH",
copy: "A holds the lower handle and B holds the upper handle while the rigid body crosses the hatch."
},
{
limit: 9.7,
title: "04 / LOWER-HAND HANDOVER",
name: "HANDOVER",
copy: "B establishes the lower grip before A releases it, preserving two-point support."
},
{
limit: 12.0,
title: "05 / LOAD TRANSFER",
name: "TRANSFER",
copy: "B now carries both handles. A releases and steps away while the sculpture clears the wall."
},
{
limit: 16.0,
title: "06 / CLEAR-SIDE PIVOT",
name: "PIVOT",
copy: "Only after the swept envelope is entirely beyond the wall does B rotate the sculpture."
},
{
limit: Infinity,
title: "07 / TRANSFER COMPLETE",
name: "COMPLETE",
copy: "The sculpture is fully transferred. Sweep clearance and continuous support remain verified."
}
];
function phaseAt(time) {
return phaseDefinitions.find(phase => time < phase.limit)
|| phaseDefinitions[phaseDefinitions.length - 1];
}
const tempUpper = new THREE.Vector3();
const tempLower = new THREE.Vector3();
function getHandlePositions() {
tempUpper.set(0, 1.22, 0)
.applyQuaternion(sculpture.quaternion)
.add(sculpture.position);
tempLower.set(0, -1.22, 0)
.applyQuaternion(sculpture.quaternion)
.add(sculpture.position);
}
function setHandState(arm, material, active, reaching) {
if (active) {
material.color.set(0x79ef9b);
material.emissive.set(0x174d2a);
material.emissiveIntensity = 0.8;
} else if (reaching) {
material.color.set(0xffbd59);
material.emissive.set(0x533100);
material.emissiveIntensity = 0.55;
} else {
material.color.set(0x9aaab1);
material.emissive.set(0x000000);
material.emissiveIntensity = 0;
}
}
function updateArm(name, shoulder, target, forward, bend) {
const arm = arms[name];
const elbow = new THREE.Vector3()
.addVectors(shoulder, target)
.multiplyScalar(0.5);
elbow.addScaledVector(forward, 0.24);
elbow.y += bend;
orientBone(arm.upper, shoulder, elbow);
orientBone(arm.lower, elbow, target);
arm.hand.position.copy(target);
}
function updateCharacters(time) {
const aStep = smoothstep(9.7, 12.2, time);
const bShift = smoothstep(5.0, 12.0, time);
const bob = Math.sin(time * 2.2) * 0.015;
characterA.group.position.set(
-0.35 - 0.58 * aStep,
bob,
-1.02 - 0.22 * aStep
);
characterA.group.rotation.y = Math.PI / 2;
characterB.group.position.set(
2.05,
bob * 0.8,
1.03 + 0.16 * bShift
);
characterB.group.rotation.y = -Math.PI / 2;
characterA.legPivots[0].rotation.x = 0.09 * Math.sin(time * 5) * aStep;
characterA.legPivots[1].rotation.x = -0.09 * Math.sin(time * 5) * aStep;
characterB.legPivots[0].rotation.x = -0.05 * Math.sin(time * 4) * bShift;
characterB.legPivots[1].rotation.x = 0.05 * Math.sin(time * 4) * bShift;
characterA.group.updateMatrixWorld(true);
characterB.group.updateMatrixWorld(true);
const shoulders = {};
for (const [name, spec] of Object.entries(shoulderSpecs)) {
shoulders[name] = spec.human.group.localToWorld(spec.local.clone());
}
const forwardA = new THREE.Vector3(1, 0, 0);
const forwardB = new THREE.Vector3(-1, 0, 0);
const aLowNeutral = shoulders.aLow.clone()
.addScaledVector(forwardA, 0.42);
aLowNeutral.y -= 0.88;
const aUpNeutral = shoulders.aUp.clone()
.addScaledVector(forwardA, 0.36);
aUpNeutral.y -= 0.46;
const bUpNeutral = shoulders.bUp.clone()
.addScaledVector(forwardB, 0.42);
bUpNeutral.y -= 0.46;
const bLowNeutral = shoulders.bLow.clone()
.addScaledVector(forwardB, 0.42);
bLowNeutral.y -= 0.88;
const aLowReach = 1;
const aUpReach = 1 - smoothstep(3.2, 3.9, time);
const bUpReach = smoothstep(0.8, 2.8, time);
const bLowReach = smoothstep(8.3, 9.4, time);
const aLowTarget = new THREE.Vector3()
.lerpVectors(aLowNeutral, tempLower, aLowReach);
const aUpTarget = new THREE.Vector3()
.lerpVectors(aUpNeutral, tempUpper, aUpReach);
const bUpTarget = new THREE.Vector3()
.lerpVectors(bUpNeutral, tempUpper, bUpReach);
const bLowTarget = new THREE.Vector3()
.lerpVectors(bLowNeutral, tempLower, bLowReach);
updateArm("aLow", shoulders.aLow, aLowTarget, forwardA, -0.22);
updateArm("aUp", shoulders.aUp, aUpTarget, forwardA, 0.24);
updateArm("bUp", shoulders.bUp, bUpTarget, forwardB, 0.24);
updateArm("bLow", shoulders.bLow, bLowTarget, forwardB, -0.22);
const flags = contactFlags(time);
setHandState(arms.aLow, handMaterialA, flags.aLow, false);
setHandState(arms.aUp, handMaterialA, flags.aUp, false);
setHandState(arms.bUp, handMaterialB, flags.bUp, bUpReach > 0 && !flags.bUp);
setHandState(arms.bLow, handMaterialB, flags.bLow, bLowReach > 0 && !flags.bLow);
const upperActive = flags.aUp || flags.bUp;
const lowerActive = flags.aLow || flags.bLow;
upperGripHalo.material.color.set(
upperActive ? 0x79ef9b : 0xffbd59
);
lowerGripHalo.material.color.set(
lowerActive ? 0x79ef9b : 0xffbd59
);
}
function updateUI(time) {
const phase = phaseAt(time);
const flags = contactFlags(time);
const pose = poseAt(time);
$("phaseTitle").textContent = phase.title;
$("phaseCopy").textContent = phase.copy;
$("phaseName").textContent = phase.name;
$("angleValue").textContent =
`${pose.angle >= 0 ? "+" : "−"}${Math.abs(THREE.MathUtils.radToDeg(pose.angle)).toFixed(1)}°`;
$("depthValue").textContent =
`${pose.position.z >= 0 ? "+" : "−"}${Math.abs(pose.position.z).toFixed(2)} m`;
$("aLow").className = `grip ${flags.aLow ? "active" : ""}`;
$("aUp").className = `grip ${flags.aUp ? "active" : ""}`;
$("bLow").className = `grip ${
flags.bLow ? "active" :
smoothstep(8.3, 9.4, time) > 0 ? "reaching" : ""
}`;
$("bUp").className = `grip ${
flags.bUp ? "active" :
smoothstep(0.8, 2.8, time) > 0 ? "reaching" : ""
}`;
$("scrub").value = time.toFixed(2);
$("time").textContent = `${time.toFixed(1).padStart(4, "0")} / 18.0`;
}
let time = 0;
let playing = true;
let playbackSpeed = 1;
function setPlaying(value) {
playing = value;
$("play").textContent = playing ? "PAUSE" : "PLAY";
}
$("play").addEventListener("click", () => {
if (!playing && time >= DURATION) time = 0;
setPlaying(!playing);
});
$("reset").addEventListener("click", () => {
time = 0;
setPlaying(true);
});
$("scrub").addEventListener("input", event => {
time = Number(event.target.value);
setPlaying(false);
});
$("speed").addEventListener("change", event => {
playbackSpeed = Number(event.target.value);
});
$("overview").addEventListener("click", () => setView("overview"));
$("hatch").addEventListener("click", () => setView("hatch"));
$("side").addEventListener("click", () => setView("side"));
window.addEventListener("keydown", event => {
if (event.code === "Space") {
event.preventDefault();
if (!playing && time >= DURATION) time = 0;
setPlaying(!playing);
}
if (event.key.toLowerCase() === "r") {
time = 0;
setPlaying(true);
}
});
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);
if (playing) {
time = Math.min(DURATION, time + delta * playbackSpeed);
if (time >= DURATION) setPlaying(false);
}
const pose = poseAt(time);
sculpture.position.copy(pose.position);
sculpture.quaternion.copy(pose.quaternion);
sculpture.updateMatrixWorld(true);
getHandlePositions();
updateCharacters(time);
updateUI(time);
renderer.render(scene, camera);
}
updateCamera();
updateUI(0);
$("loading").style.display = "none";
animate();
</script>
</body>
</html>
```