Prompt specification
Build or customize the Three.js 3D scene "Neighborhood Swing Motion 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: Neighborhood Swing Motion Study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/neighborhood-swing-motion-study-x3623
Scene Description Prompt:
A voxel park swing and seated rider, with consistent suspension and a declared simplified motion model. Three.js from cdnjs, one HTML file.
Working Three.js Starter (neighborhood-swing-motion-study-x3623):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Park Swing</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #91cbe8;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
top: 18px;
left: 18px;
width: min(340px, calc(100vw - 36px));
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 14px;
color: #f4fbff;
background: rgba(18, 35, 45, 0.84);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.eyebrow {
margin: 0 0 4px;
color: #9de3b4;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.1;
letter-spacing: -0.03em;
}
.subtitle {
margin: 8px 0 13px;
color: #c8d8df;
font-size: 13px;
line-height: 1.45;
}
details {
border-top: 1px solid rgba(255, 255, 255, 0.12);
padding-top: 10px;
}
summary {
cursor: pointer;
color: #fff;
font-size: 13px;
font-weight: 750;
}
.equation {
margin: 11px 0 9px;
padding: 9px 10px;
border-radius: 8px;
color: #dff9e8;
background: rgba(0, 0, 0, 0.22);
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
overflow-wrap: anywhere;
}
.model-copy,
.readouts {
color: #c8d8df;
font-size: 12px;
line-height: 1.5;
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 11px;
}
.readout {
padding: 8px 9px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.06);
}
.readout span {
display: block;
color: #91aab4;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout strong {
display: block;
margin-top: 2px;
color: #fff;
font-size: 14px;
font-variant-numeric: tabular-nums;
}
.controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 12px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 8px;
padding: 8px 11px;
color: #fff;
background: rgba(255, 255, 255, 0.1);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background 120ms ease, transform 120ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.18);
}
button:active { transform: translateY(1px); }
button.primary {
color: #10251b;
border-color: transparent;
background: #9de3b4;
}
#help {
position: absolute;
right: 18px;
bottom: 17px;
padding: 9px 12px;
border-radius: 10px;
color: rgba(255, 255, 255, 0.94);
background: rgba(18, 35, 45, 0.72);
font-size: 12px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
backdrop-filter: blur(8px);
}
@media (max-width: 650px) {
.panel {
top: 10px;
left: 10px;
width: min(310px, calc(100vw - 20px));
padding: 12px;
}
h1 { font-size: 19px; }
.subtitle { margin-bottom: 8px; }
#help {
right: 10px;
bottom: 10px;
max-width: calc(100vw - 20px);
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="hud">
<section class="panel">
<p class="eyebrow">Voxel Park</p>
<h1>Rider on a Swinging Chair</h1>
<p class="subtitle">
A rigid, length-preserving suspension with a damped, periodically driven
planar pendulum.
</p>
<details open>
<summary>Declared simplified motion model</summary>
<div class="equation">
θ¨ = −(g/L) sin(θ) − cθ˙ + A sin(Ωt)
</div>
<div class="model-copy">
L = 2.35 m, g = 9.81 m/s², c = 0.045 s⁻¹,<br>
A = 0.018 rad/s², Ω = 2.05 rad/s.<br>
Integrated at a fixed 1/120 s step.
</div>
<div class="model-copy" style="margin-top: 9px;">
The seat, rider, and chain attachment points form one rigid body
rotating around the line through the two fixed upper pivots. Each
chain therefore remains attached and exactly L long at every angle.
</div>
<div class="readouts">
<div class="readout">
<span>Angle</span>
<strong id="angleReadout">0.0°</strong>
</div>
<div class="readout">
<span>Angular speed</span>
<strong id="speedReadout">0.00 rad/s</strong>
</div>
<div class="readout">
<span>Chain length</span>
<strong>2.35 m</strong>
</div>
<div class="readout">
<span>State</span>
<strong id="stateReadout">Moving</strong>
</div>
</div>
</details>
<div class="controls">
<button id="pauseButton" class="primary" type="button">Pause</button>
<button id="pushButton" type="button">Push</button>
<button id="resetButton" type="button">Reset</button>
<button id="viewButton" type="button">Reset view</button>
</div>
</section>
<div id="help">
Drag to orbit · Scroll to zoom · Space: pause · P: push · R: reset
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x91cbe8);
scene.fog = new THREE.Fog(0x91cbe8, 17, 39);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xe8f7ff, 0x526d43, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(-7, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color, metalness = 0) {
const key = `${color}:${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: metalness > 0 ? 0.38 : 0.84,
metalness
})
);
}
return materialCache.get(key);
}
function addBox(
parent,
size,
position,
color,
options = {}
) {
const mesh = new THREE.Mesh(
unitBox,
material(color, options.metalness ?? 0)
);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.cast !== false;
mesh.receiveShadow = options.receive !== false;
if (options.rotation) {
mesh.rotation.set(
options.rotation[0] ?? 0,
options.rotation[1] ?? 0,
options.rotation[2] ?? 0
);
}
parent.add(mesh);
return mesh;
}
// A stepped line of overlapping cubes, preserving the voxel aesthetic.
function voxelBeam(
parent,
start,
end,
width,
color,
step = width * 0.8
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const count = Math.max(1, Math.ceil(a.distanceTo(b) / step));
for (let i = 0; i < count; i++) {
const t = (i + 0.5) / count;
const p = new THREE.Vector3().lerpVectors(a, b, t);
addBox(parent, [width, width, width], p.toArray(), color);
}
}
// -------------------------------------------------------------------------
// Park environment
// -------------------------------------------------------------------------
addBox(
scene,
[30, 0.4, 26],
[0, -0.22, 0],
0x78ad59,
{ cast: false }
);
// A paved path running in the swing direction.
for (let z = -9; z <= 9; z += 0.72) {
addBox(
scene,
[3.15, 0.075, 0.64],
[0, 0.035, z],
z % 1.44 === 0 ? 0xd9bd83 : 0xe4c995,
{ cast: false }
);
}
// Park bench.
const bench = new THREE.Group();
bench.position.set(-5.1, 0, 2.8);
bench.rotation.y = -0.18;
scene.add(bench);
for (let i = 0; i < 4; i++) {
addBox(
bench,
[2.25, 0.13, 0.18],
[0, 0.72, -0.27 + i * 0.18],
0x9b633d
);
}
for (let i = 0; i < 3; i++) {
addBox(
bench,
[2.25, 0.16, 0.13],
[0, 0.97 + i * 0.18, -0.36],
0x9b633d
);
}
addBox(bench, [0.18, 0.75, 0.62], [-0.83, 0.36, 0], 0x40565a);
addBox(bench, [0.18, 0.75, 0.62], [0.83, 0.36, 0], 0x40565a);
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
addBox(tree, [0.43, 2.2, 0.43], [0, 1.1, 0], 0x805332);
addBox(tree, [2.25, 1.15, 2.05], [0, 2.55, 0], 0x3f8749);
addBox(tree, [1.65, 1.15, 1.7], [-0.55, 3.25, 0.12], 0x4c9c50);
addBox(tree, [1.55, 1.05, 1.55], [0.6, 3.3, -0.15], 0x5aaa55);
addBox(tree, [1.35, 0.85, 1.35], [0.05, 3.9, 0.08], 0x65b85b);
}
[
[-5.6, -5.8, 1.08],
[5.7, -5.4, 1.0],
[-6.0, 1.5, 0.9],
[5.8, 2.0, 1.12],
[-5.0, 6.2, 1.03],
[5.0, 6.5, 0.88],
[-7.3, -1.8, 0.78],
[7.0, -0.8, 0.8]
].forEach((args) => addTree(...args));
// Small voxel flowers and grass clumps.
for (let i = 0; i < 44; i++) {
const side = i % 2 === 0 ? -1 : 1;
const x = side * (2.15 + (i * 0.73) % 4.2);
const z = -9 + ((i * 1.91) % 18);
const height = 0.15 + (i % 3) * 0.055;
addBox(
scene,
[0.055, height, 0.055],
[x, height / 2, z],
0x3f8c43,
{ cast: false }
);
if (i % 4 === 0) {
const colors = [0xf6cf4e, 0xe97e87, 0xe8eef0, 0xb98bea];
addBox(
scene,
[0.13, 0.13, 0.13],
[x, height + 0.035, z],
colors[(i / 4) % colors.length],
{ cast: false }
);
}
}
// Blocky distant clouds.
function addCloud(x, y, z, scale = 1) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
addBox(cloud, [2.2, 0.7, 0.9], [0, 0, 0], 0xf1f7ef, { cast: false });
addBox(cloud, [1.35, 1.05, 1.0], [-0.45, 0.36, 0], 0xf7fbf4, { cast: false });
addBox(cloud, [1.45, 0.9, 0.95], [0.58, 0.28, 0], 0xf7fbf4, { cast: false });
}
addCloud(-7.8, 7.6, -11.5, 1.1);
addCloud(7.0, 8.5, -14, 1.35);
addCloud(3.2, 6.8, -17, 0.8);
// -------------------------------------------------------------------------
// Swing frame
// -------------------------------------------------------------------------
const frameColor = 0x3c6877;
const frameAccent = 0xf1c45b;
for (const x of [-2.78, 2.78]) {
voxelBeam(
scene,
[x, 0.12, -1.28],
[x, 4.48, 0],
0.24,
frameColor
);
voxelBeam(
scene,
[x, 0.12, 1.28],
[x, 4.48, 0],
0.24,
frameColor
);
addBox(scene, [0.55, 0.2, 0.62], [x, 0.1, -1.28], frameColor);
addBox(scene, [0.55, 0.2, 0.62], [x, 0.1, 1.28], frameColor);
}
addBox(scene, [6.35, 0.25, 0.34], [0, 4.57, 0], frameColor);
addBox(scene, [6.1, 0.11, 0.39], [0, 4.72, 0], frameAccent);
const pivotY = 4.39;
const pivotX = 0.86;
for (const x of [-pivotX, pivotX]) {
addBox(scene, [0.23, 0.23, 0.29], [x, pivotY, 0], frameAccent, {
metalness: 0.25
});
}
// -------------------------------------------------------------------------
// Rigid swing assembly
//
// The group's local X axis is the fixed pivot axis. The two upper chain
// endpoints have local Y = 0 and Z = 0, so they remain fixed under
// rotation. Lower endpoints have local Y = -L, guaranteeing a constant
// distance L from their corresponding upper pivots.
// -------------------------------------------------------------------------
const CHAIN_LENGTH = 2.35;
const swing = new THREE.Group();
swing.position.set(0, pivotY, 0);
scene.add(swing);
const linkCount = 13;
const linkHeight = CHAIN_LENGTH / linkCount;
for (const x of [-pivotX, pivotX]) {
for (let i = 0; i < linkCount; i++) {
const y = -(i + 0.5) * linkHeight;
const link = addBox(
swing,
[0.065, linkHeight * 0.84, 0.065],
[x, y, 0],
0xc7d0d2,
{ metalness: 0.62 }
);
if (i % 2 === 1) {
link.rotation.y = Math.PI / 2;
}
}
addBox(
swing,
[0.14, 0.13, 0.14],
[x, -CHAIN_LENGTH + 0.02, 0],
0x65767b,
{ metalness: 0.55 }
);
}
const seatTop = -CHAIN_LENGTH + 0.18;
// Seat.
addBox(
swing,
[1.95, 0.16, 0.88],
[0, seatTop - 0.08, 0],
0xd85f52
);
// Backrest.
addBox(
swing,
[1.95, 0.82, 0.13],
[0, seatTop + 0.40, -0.39],
0xb94743
);
// Armrests.
for (const x of [-0.91, 0.91]) {
addBox(
swing,
[0.10, 0.10, 0.79],
[x, seatTop + 0.35, 0.01],
0x743b39
);
}
// -------------------------------------------------------------------------
// Seated voxel rider
// -------------------------------------------------------------------------
const rider = new THREE.Group();
swing.add(rider);
const shirt = 0xf29d38;
const shirtDark = 0xd47c27;
const pants = 0x365e91;
const skin = 0xe8aa79;
const hair = 0x4b3026;
const shoe = 0x29343a;
// Hips and torso.
addBox(
rider,
[0.73, 0.28, 0.48],
[0, seatTop + 0.14, -0.03],
pants
);
addBox(
rider,
[0.78, 0.70, 0.46],
[0, seatTop + 0.63, -0.03],
shirt
);
addBox(
rider,
[0.80, 0.12, 0.48],
[0, seatTop + 0.39, -0.03],
shirtDark
);
// Neck and head.
addBox(
rider,
[0.19, 0.15, 0.19],
[0, seatTop + 1.03, -0.03],
skin
);
addBox(
rider,
[0.50, 0.50, 0.48],
[0, seatTop + 1.31, -0.03],
skin
);
addBox(
rider,
[0.54, 0.18, 0.51],
[0, seatTop + 1.52, -0.03],
hair
);
addBox(
rider,
[0.54, 0.30, 0.13],
[0, seatTop + 1.37, -0.25],
hair
);
// Face: small voxel eyes.
for (const x of [-0.11, 0.11]) {
addBox(
rider,
[0.055, 0.055, 0.035],
[x, seatTop + 1.34, 0.215],
0x27313a,
{ cast: false }
);
}
// Thighs extend forward from the seated hips.
for (const x of [-0.20, 0.20]) {
addBox(
rider,
[0.25, 0.23, 0.69],
[x, seatTop + 0.12, 0.27],
pants
);
addBox(
rider,
[0.22, 0.43, 0.23],
[x, seatTop - 0.13, 0.64],
pants
);
addBox(
rider,
[0.27, 0.16, 0.43],
[x, seatTop - 0.35, 0.78],
shoe
);
}
// Arms rest on the armrests.
for (const x of [-0.49, 0.49]) {
addBox(
rider,
[0.18, 0.52, 0.18],
[x, seatTop + 0.62, 0.03],
shirt
);
addBox(
rider,
[0.18, 0.17, 0.50],
[x, seatTop + 0.35, 0.22],
shirtDark
);
addBox(
rider,
[0.18, 0.16, 0.18],
[x, seatTop + 0.35, 0.46],
skin
);
}
// -------------------------------------------------------------------------
// Motion model
// -------------------------------------------------------------------------
const motion = {
theta: 0.20,
omega: 0,
time: 0,
paused: false
};
const GRAVITY = 9.81;
const DAMPING = 0.045;
const DRIVE_AMPLITUDE = 0.018;
const DRIVE_FREQUENCY = 2.05;
const FIXED_STEP = 1 / 120;
let accumulator = 0;
function integrateMotion(dt) {
motion.time += dt;
const angularAcceleration =
-(GRAVITY / CHAIN_LENGTH) * Math.sin(motion.theta)
- DAMPING * motion.omega
+ DRIVE_AMPLITUDE * Math.sin(DRIVE_FREQUENCY * motion.time);
motion.omega += angularAcceleration * dt;
motion.theta += motion.omega * dt;
}
swing.rotation.x = motion.theta;
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and reset
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.25, 0),
radius: 9.6,
azimuth: 0.58,
elevation: 0.34
};
function applyCamera() {
const { target, radius, azimuth, elevation } = cameraState;
camera.position.set(
target.x + radius * Math.cos(elevation) * Math.sin(azimuth),
target.y + radius * Math.sin(elevation),
target.z + radius * Math.cos(elevation) * Math.cos(azimuth)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.target.set(0, 2.25, 0);
cameraState.radius = 9.6;
cameraState.azimuth = 0.58;
cameraState.elevation = 0.34;
applyCamera();
}
applyCamera();
let drag = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
cameraState.azimuth -= dx * 0.006;
cameraState.elevation = THREE.MathUtils.clamp(
cameraState.elevation + dy * 0.005,
0.12,
1.25
);
drag.x = event.clientX;
drag.y = event.clientY;
applyCamera();
});
function endDrag(event) {
if (drag && drag.id === event.pointerId) {
drag = null;
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.8,
17
);
applyCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI and keyboard controls
// -------------------------------------------------------------------------
const pauseButton = document.getElementById("pauseButton");
const pushButton = document.getElementById("pushButton");
const resetButton = document.getElementById("resetButton");
const viewButton = document.getElementById("viewButton");
const angleReadout = document.getElementById("angleReadout");
const speedReadout = document.getElementById("speedReadout");
const stateReadout = document.getElementById("stateReadout");
function togglePause() {
motion.paused = !motion.paused;
pauseButton.textContent = motion.paused ? "Resume" : "Pause";
stateReadout.textContent = motion.paused ? "Paused" : "Moving";
}
function pushSwing() {
motion.omega += 0.32;
}
function resetSwing() {
motion.theta = 0.20;
motion.omega = 0;
motion.time = 0;
accumulator = 0;
swing.rotation.x = motion.theta;
}
pauseButton.addEventListener("click", togglePause);
pushButton.addEventListener("click", pushSwing);
resetButton.addEventListener("click", resetSwing);
viewButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePause();
} else if (event.key.toLowerCase() === "p") {
pushSwing();
} else if (event.key.toLowerCase() === "r") {
resetSwing();
}
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let uiTimer = 0;
function animate() {
requestAnimationFrame(animate);
const frameDelta = Math.min(clock.getDelta(), 0.05);
if (!motion.paused) {
accumulator += frameDelta;
while (accumulator >= FIXED_STEP) {
integrateMotion(FIXED_STEP);
accumulator -= FIXED_STEP;
}
} else {
accumulator = 0;
}
swing.rotation.x = motion.theta;
uiTimer += frameDelta;
if (uiTimer > 0.08) {
angleReadout.textContent =
`${THREE.MathUtils.radToDeg(motion.theta).toFixed(1)}°`;
speedReadout.textContent =
`${motion.omega.toFixed(2)} rad/s`;
uiTimer = 0;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```