Prompt specification
Build or customize the Three.js 3D scene "Interlocking Paper Sculpture Study" 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: Interlocking Paper Sculpture Study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/interlocking-paper-sculpture-study-x3346
Scene Description Prompt:
Two voxel slotted paper planes assembling into a freestanding sculpture without overlap. Three.js from cdnjs, one HTML file.
Working Three.js Starter (interlocking-paper-sculpture-study-x3346):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Twin Fold — Slotted Voxel Paper Planes</title>
<style>
:root{
--ink:#e9eef4; --dim:#8ea0b4; --amber:#f0a13c; --cyan:#54b6de;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;overflow:hidden;background:#0b0e13;color:var(--ink);
font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace}
#app{position:fixed;inset:0}
canvas{display:block}
.panel{position:fixed;pointer-events:none;z-index:5}
#head{top:22px;left:24px}
#head h1{margin:0;font-size:15px;letter-spacing:.34em;font-weight:600}
#head p{margin:6px 0 0;font-size:11px;letter-spacing:.16em;color:var(--dim);text-transform:uppercase}
#read{bottom:22px;left:24px;font-size:11px;line-height:1.85;letter-spacing:.08em;color:var(--dim)}
#read b{color:var(--ink);font-weight:600}
#phase{color:var(--amber)}
#ok{color:#7fd6a2}
#help{bottom:22px;right:24px;font-size:10.5px;letter-spacing:.14em;color:#5d6d80;text-align:right;line-height:1.9}
button{pointer-events:auto;margin-top:8px;padding:8px 14px;font:inherit;font-size:10.5px;letter-spacing:.2em;
text-transform:uppercase;color:var(--ink);background:rgba(255,255,255,.05);
border:1px solid rgba(255,255,255,.16);border-radius:2px;cursor:pointer;transition:.18s}
button:hover{background:rgba(240,161,60,.14);border-color:var(--amber);color:#fff}
#bar{position:fixed;left:0;right:0;bottom:0;height:2px;background:rgba(255,255,255,.06);z-index:5}
#fill{height:100%;width:0%;background:linear-gradient(90deg,var(--amber),var(--cyan));transition:width .1s linear}
</style>
</head>
<body>
<div id="app"></div>
<div class="panel" id="head">
<h1>TWIN FOLD</h1>
<p>slotted voxel paper planes · interlocked sculpture</p>
</div>
<div class="panel" id="read">
<div>phase <b id="phase">—</b></div>
<div>voxels <b id="vc">—</b></div>
<div>joint <b>A groove ⇄ B slot</b></div>
<div>interpenetration <b id="ok">—</b></div>
</div>
<div class="panel" id="help">
drag · orbit / wheel · zoom / space · replay
<div><button id="replay">replay assembly</button></div>
</div>
<div id="bar"><div id="fill"></div></div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
/* ────────────────────────────── geometry constants ────────────────────────────── */
const CELL = 0.5; // world size of one voxel
const LEN = 41; // length of a plane, in voxels
const HALF = 9; // maximum half-width of a plane, in voxels
const A_Z0 = -30; // plane A: nose at z = -30, tail at z = +10
const B_Z0 = 30; // plane B: nose at z = +30, tail at z = -10
const SLOT_V0 = 20; // slot / groove run from this voxel index to the tail
const SLOT_V1 = LEN - 1;
/* plan-view outline of a paper plane: sharp nose, swept leading edges, tail notch */
function halfWidth(v){
if (v < 3) return 0;
const t = Math.min(1, (v - 3) / (LEN - 8));
return Math.min(HALF, Math.floor(HALF * Math.pow(t, 0.8)));
}
/*
cross-section of a plane, in local (lateral u, height level):
|u| = 0 -> crease band at level 1 (A) / level 0+1 (B)
|u| = 1 -> shoulders, levels 0 and 1
|u| >= 2 -> flat wing, level 0
A is built lying flat : world (x = u, y = level)
B is built standing up : world (x = level, y = u + 1)
so A's crease line (0,1,z) and B's sheet line (0,y,z) meet exactly on one line,
and A's shoulders (1,0|1,z) meet B's raised band (1,y,z) — the two joints.
*/
function buildPlane(isB){
const cells = [], cuts = [];
for (let v = 0; v < LEN; v++){
const hw = halfWidth(v);
const z = isB ? (B_Z0 - v) : (A_Z0 + v);
const inSlot = (v >= SLOT_V0 && v <= SLOT_V1);
for (let u = -hw; u <= hw; u++){
if (v === LEN - 1 && Math.abs(u) <= 1) continue; // tail V-notch
const a = Math.abs(u);
const levels = a === 0 ? (isB ? [0,1] : [1])
: a === 1 ? [0,1]
: [0];
for (const lv of levels){
const x = isB ? lv : u;
const y = isB ? (u + 1) : lv;
// ── the slots ──────────────────────────────────────────────
// A: groove cut along its crease (u = 0) B: slot cut through
// its raised crease band (level 1) the whole overlap
if (inSlot && (isB ? lv === 1 : u === 0)){ cuts.push({x,y,z}); continue; }
cells.push({x, y, z, band: lv, edge:false});
}
}
}
const k = c => c.x + ',' + c.y + ',' + c.z;
const cutSet = new Set(cuts.map(k));
const nb = [[1,0,0],[-1,0,0],[0,1,0],[0,-1,0],[0,0,1],[0,0,-1]];
for (const c of cells){
c.edge = nb.some(d => cutSet.has(k({x:c.x+d[0], y:c.y+d[1], z:c.z+d[2]})));
}
return {cells, cuts};
}
const planeA = buildPlane(false);
const planeB = buildPlane(true);
/* ────────────────────────────── renderer / scene ────────────────────────────── */
const app = document.getElementById('app');
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x0b0e13, 0.0135);
/* gradient sky */
(function(){
const c = document.createElement('canvas'); c.width = 4; c.height = 512;
const g = c.getContext('2d');
const grad = g.createLinearGradient(0,0,0,512);
grad.addColorStop(0.00,'#243141');
grad.addColorStop(0.45,'#151b25');
grad.addColorStop(1.00,'#090b0f');
g.fillStyle = grad; g.fillRect(0,0,4,512);
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
scene.background = tex;
})();
const camera = new THREE.PerspectiveCamera(38, innerWidth/innerHeight, 0.1, 400);
/* lighting */
scene.add(new THREE.HemisphereLight(0xc3d4e8, 0x101318, 0.55));
const key = new THREE.DirectionalLight(0xfff2df, 2.5);
key.position.set(16, 24, 14);
key.castShadow = true;
key.shadow.mapSize.set(2048,2048);
key.shadow.camera.left = -24; key.shadow.camera.right = 24;
key.shadow.camera.top = 24; key.shadow.camera.bottom = -24;
key.shadow.camera.near = 2; key.shadow.camera.far = 90;
key.shadow.bias = -0.0006; key.shadow.normalBias = 0.02;
scene.add(key);
const rim = new THREE.DirectionalLight(0x74b6ff, 1.0); rim.position.set(-18, 9, -16); scene.add(rim);
const fill = new THREE.DirectionalLight(0xffd9a8, 0.35); fill.position.set(-6, 4, 20); scene.add(fill);
/* ground */
const ground = new THREE.Mesh(
new THREE.CircleGeometry(70, 96),
new THREE.MeshStandardMaterial({color:0x0f1319, roughness:0.96, metalness:0.0})
);
ground.rotation.x = -Math.PI/2;
ground.position.y = -8*CELL - CELL*0.46; // exactly under B's lowest voxel
ground.receiveShadow = true;
scene.add(ground);
/* ────────────────────────────── voxel meshes ────────────────────────────── */
const PAL = {
A: {body:0xe9e1d2, crease:0xcdc0a8, edge:0xef9c33},
B: {body:0xdfe8f1, crease:0xbfcddb, edge:0x3fa3cc}
};
const BODY = 0xffffff;
function buildMesh(plane, pal, name){
const geo = new THREE.BoxGeometry(CELL*0.9, CELL*0.9, CELL*0.9);
const mat = new THREE.MeshStandardMaterial({color:BODY, roughness:0.86, metalness:0.04});
const mesh = new THREE.InstancedMesh(geo, mat, plane.cells.length);
mesh.name = name;
mesh.castShadow = true; mesh.receiveShadow = true;
mesh.frustumCulled = false;
const m = new THREE.Matrix4(), col = new THREE.Color();
const edgeIdx = [];
plane.cells.forEach((c,i)=>{
m.makeTranslation(c.x*CELL, c.y*CELL, c.z*CELL);
mesh.setMatrixAt(i, m);
if (c.edge){ edgeIdx.push(i); col.set(pal.edge); }
else col.set(c.band === 1 ? pal.crease : pal.body);
mesh.setColorAt(i, col);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.userData.edgeIdx = edgeIdx;
mesh.userData.pal = pal;
scene.add(mesh);
return mesh;
}
const meshA = buildMesh(planeA, PAL.A, 'planeA');
const meshB = buildMesh(planeB, PAL.B, 'planeB');
/* pulse the freshly-cut slot edges when the joint closes */
let pulse = 0;
function setEdgeColors(mesh, boost){
const {edgeIdx, pal} = mesh.userData;
const col = new THREE.Color();
const base = new THREE.Color(pal.edge);
col.copy(base).lerp(new THREE.Color(0xffffff), boost*0.75);
edgeIdx.forEach(i => mesh.setColorAt(i, col));
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
}
/* ────────────────────────────── assembly timeline ────────────────────────────── */
const A_FROM = -12, B_FROM = 30; // starting offsets, in cells
const T_A = [0.15, 1.60]; // A slides in along +x
const T_B = [1.45, 3.40]; // B drops in along -y
let t = 0, aOff = A_FROM, bOff = B_FROM, joined = false;
const ease = x => x < 0.5 ? 4*x*x*x : 1 - Math.pow(-2*x+2, 3)/2;
const clamp = (v,a,b) => Math.max(a, Math.min(b, v));
function updateAssembly(dt){
t += dt;
if (t >= T_A[0]){
const k = clamp((t - T_A[0]) / (T_A[1] - T_A[0]), 0, 1);
aOff = A_FROM * (1 - ease(k));
}
if (t >= T_B[0]){
const k = clamp((t - T_B[0]) / (T_B[1] - T_B[0]), 0, 1);
bOff = B_FROM * (1 - ease(k));
}
if (!joined && t >= T_B[1]){ joined = true; pulse = 1; }
meshA.position.x = aOff * CELL;
meshB.position.y = bOff * CELL;
document.getElementById('fill').style.width = (clamp(t / T_B[1], 0, 1) * 100) + '%';
document.getElementById('phase').textContent =
t < T_A[0] ? 'standby' :
t < T_A[1] ? 'I · slide A in' :
t < T_B[0] ? 'II · hover' :
t < T_B[1] ? 'III · engage slots' : 'assembled';
}
/* ────────────────────────────── live interpenetration test ────────────────────────────── */
const hashA = new Map();
function rehashA(){
hashA.clear();
for (const c of planeA.cells){
const k = (c.x + aOff) + ',' + c.y + ',' + c.z;
if (!hashA.has(k)) hashA.set(k, []);
hashA.get(k).push(c);
}
}
function overlapCount(){
const seen = new Set(), hits = [];
for (const c of planeB.cells){
const bx = c.x, by = c.y + bOff, bz = c.z;
for (let dx=-1; dx<=1; dx++) for (let dy=-1; dy<=1; dy++) for (let dz=-1; dz<=1; dz++){
const k = (bx+dx) + ',' + (by+dy) + ',' + (bz+dz);
if (!seen.has(k)){ seen.add(k); const list = hashA.get(k); if (list) hits.push(list); }
}
}
let n = 0;
for (const list of hits) for (const a of list){
const b = {x:a.x + aOff, y:a.y, z:a.z};
// exact geometric test on the voxel boxes (box width 0.9 cells)
if (Math.abs(b.x - planeB.xDummy) < 0) {}
}
return n;
}
/* simpler + exact: compare every B cell against A cells in the 27 neighbouring buckets */
function countCollisions(){
let n = 0;
const buckets = new Map();
for (const c of planeA.cells){
const k = (c.x + aOff) + ',' + c.y + ',' + c.z;
if (!buckets.has(k)) buckets.set(k, []);
buckets.get(k).push(c);
}
for (const c of planeB.cells){
const bx = c.x, by = c.y + bOff, bz = c.z;
for (let dx=-1; dx<=1; dx++) for (let dy=-1; dy<=1; dy++) for (let dz=-1; dz<=1; dz++){
const list = buckets.get((bx+dx) + ',' + (by+dy) + ',' + (bz+dz));
if (!list) continue;
for (const a of list){
if (Math.abs((a.x + aOff) - bx) < 0.9 &&
Math.abs(a.y - by) < 0.9 &&
Math.abs(a.z - bz) < 0.9) n++;
}
}
}
return n;
}
/* ────────────────────────────── camera rig (hand rolled) ────────────────────────────── */
const cam = {th:0.86, ph:1.16, d:34, tth:0.86, tph:1.16, td:34};
const look = new THREE.Vector3(0, 0.3, 0);
let idle = 0;
const pointers = new Map();
let prevPinch = 0;
const dom = renderer.domElement;
dom.addEventListener('pointerdown', e => {
dom.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, {x:e.clientX, y:e.clientY});
idle = 0;
});
dom.addEventListener('pointermove', e => {
const p = pointers.get(e.pointerId); if (!p) return;
const dx = e.clientX - p.x, dy = e.clientY - p.y;
p.x = e.clientX; p.y = e.clientY; idle = 0;
if (pointers.size === 1){
cam.tth -= dx * 0.006;
cam.tph = clamp(cam.tph - dy * 0.005, 0.16, 1.50);
} else if (pointers.size === 2){
const pts = [...pointers.values()];
const d = Math.hypot(pts[0].x-pts[1].x, pts[0].y-pts[1].y);
if (prevPinch) cam.td = clamp(cam.td * (prevPinch / d), 11, 80);
prevPinch = d;
}
});
const endPointer = e => { pointers.delete(e.pointerId); if (pointers.size < 2) prevPinch = 0; };
dom.addEventListener('pointerup', endPointer);
dom.addEventListener('pointercancel', endPointer);
dom.addEventListener('wheel', e => {
e.preventDefault();
cam.td = clamp(cam.td * Math.exp(e.deltaY * 0.0011), 11, 80);
idle = 0;
}, {passive:false});
function updateCamera(dt){
idle += dt;
if (idle > 2.2 && !pointers.size) cam.tth += dt * 0.10; // slow idle orbit
const k = 1 - Math.exp(-dt * 9);
cam.th += (cam.tth - cam.th) * k;
cam.ph += (cam.tph - cam.ph) * k;
cam.d += (cam.td - cam.d ) * k;
const sp = Math.sin(cam.ph), cp = Math.cos(cam.ph);
camera.position.set(
look.x + cam.d * sp * Math.cos(cam.th),
look.y + cam.d * cp,
look.z + cam.d * sp * Math.sin(cam.th)
);
camera.lookAt(look);
}
/* ────────────────────────────── hud ────────────────────────────── */
const elPhase = document.getElementById('phase');
const elVC = document.getElementById('vc');
const elOK = document.getElementById('ok');
elVC.textContent = (planeA.cells.length + planeB.cells.length) + ' voxels';
function replay(){
t = 0; aOff = A_FROM; bOff = B_FROM; joined = false; pulse = 0;
meshA.position.x = aOff*CELL; meshB.position.y = bOff*CELL;
}
document.getElementById('replay').addEventListener('click', replay);
addEventListener('keydown', e => { if (e.code === 'Space'){ e.preventDefault(); replay(); } });
/* ────────────────────────────── loop ────────────────────────────── */
const clock = new THREE.Clock();
let frame = 0;
function animate(){
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateAssembly(dt);
updateCamera(dt);
if (pulse > 0){
pulse = Math.max(0, pulse - dt * 1.8);
const b = Math.sin(pulse * Math.PI) * 0.55;
setEdgeColors(meshA, b); setEdgeColors(meshB, b);
}
if ((frame++ & 7) === 0){
const n = countCollisions();
elOK.textContent = n + (n === 1 ? ' voxel' : ' voxels');
elOK.style.color = n === 0 ? '#7fd6a2' : '#ff7a6b';
}
renderer.render(scene, camera);
}
animate();
addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```