Prompt specification
Build or customize the Three.js 3D scene "Rotation before insertion" 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: Rotation before insertion
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rotation-before-insertion-x0374
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a shape sorter. Move a rectangular block toward its opening at different angles; only the aligned orientation passes through, while mismatches stop above the lid without deformation. Low-poly.
Working Three.js Starter (rotation-before-insertion-x0374):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Low-Poly Shape Sorter</title>
<style>
:root {
--ink: #17314b;
--muted: #64778a;
--panel: rgba(255, 255, 255, 0.88);
--border: rgba(23, 49, 75, 0.13);
--accent: #ff9b62;
--good: #28b889;
--bad: #ed6b65;
--shadow: 0 18px 45px rgba(25, 50, 75, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9ef;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 2;
border: 1px solid var(--border);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px 20px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 5px;
color: #e87948;
font-size: 0.72rem;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.35rem, 3vw, 2rem);
line-height: 1.05;
letter-spacing: -0.045em;
}
.brand p:last-child {
margin: 9px 0 0;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.45;
}
.status {
top: 22px;
right: 22px;
width: 290px;
padding: 16px 17px;
transition: border-color 180ms ease;
}
.status-head {
display: flex;
align-items: center;
gap: 10px;
}
.status-dot {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--good);
box-shadow: 0 0 0 5px rgba(40, 184, 137, 0.13);
transition: background 180ms ease, box-shadow 180ms ease;
}
.status-title {
font-size: 0.95rem;
font-weight: 800;
}
.status-copy {
margin: 9px 0 0;
color: var(--muted);
font-size: 0.8rem;
line-height: 1.45;
}
.status.warning .status-dot {
background: var(--bad);
box-shadow: 0 0 0 5px rgba(237, 107, 101, 0.13);
}
.status.moving .status-dot {
background: #e6a536;
box-shadow: 0 0 0 5px rgba(230, 165, 54, 0.14);
animation: pulse 900ms ease-in-out infinite alternate;
}
@keyframes pulse {
to {
transform: scale(1.25);
opacity: 0.65;
}
}
.controls {
left: 50%;
bottom: 22px;
width: min(640px, calc(100vw - 32px));
padding: 17px;
transform: translateX(-50%);
}
.control-top {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 18px;
}
.angle-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 16px;
margin-bottom: 9px;
font-size: 0.84rem;
font-weight: 800;
}
output {
min-width: 48px;
color: #e87948;
font-variant-numeric: tabular-nums;
text-align: right;
}
input[type="range"] {
width: 100%;
height: 7px;
margin: 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(
to right,
#54c99f 0%,
#54c99f calc(50% - 4px),
#e87948 calc(50% - 4px),
#e87948 calc(50% + 4px),
#d9e1e8 calc(50% + 4px)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 21px;
height: 21px;
appearance: none;
border: 4px solid white;
border-radius: 50%;
background: #e87948;
box-shadow: 0 3px 10px rgba(23, 49, 75, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 4px solid white;
border-radius: 50%;
background: #e87948;
box-shadow: 0 3px 10px rgba(23, 49, 75, 0.25);
}
.presets {
display: flex;
gap: 6px;
}
.preset {
min-width: 49px;
height: 34px;
border: 1px solid rgba(23, 49, 75, 0.12);
border-radius: 10px;
background: #edf3f5;
color: var(--ink);
font: inherit;
font-size: 0.76rem;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
.preset:hover,
.preset.active {
background: #dff5ed;
color: #16805f;
}
.preset:active {
transform: translateY(1px);
}
.control-bottom {
display: flex;
align-items: center;
gap: 10px;
margin-top: 14px;
}
.note {
flex: 1;
color: var(--muted);
font-size: 0.75rem;
line-height: 1.35;
}
button.action {
height: 43px;
border: 0;
border-radius: 13px;
padding: 0 17px;
font: inherit;
font-size: 0.84rem;
font-weight: 850;
cursor: pointer;
transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}
button.action:hover {
transform: translateY(-1px);
}
button.action:active {
transform: translateY(1px);
}
button.action:disabled {
opacity: 0.55;
cursor: wait;
transform: none;
}
#reset {
background: #e8eef1;
color: var(--ink);
}
#push {
min-width: 132px;
background: var(--accent);
color: #402116;
box-shadow: 0 7px 16px rgba(232, 121, 72, 0.25);
}
.hint {
position: fixed;
z-index: 2;
right: 22px;
bottom: 22px;
padding: 8px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.64);
color: #65778a;
font-size: 0.7rem;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.brand p:last-child {
display: none;
}
.status {
top: 103px;
right: 12px;
width: 225px;
padding: 12px 13px;
}
.status-copy {
display: none;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
.control-top {
grid-template-columns: 1fr;
gap: 11px;
}
.presets {
justify-content: space-between;
}
.preset {
flex: 1;
}
.note,
.hint {
display: none;
}
#push {
flex: 1;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="panel brand">
<p class="eyebrow">Low-poly play lab</p>
<h1>Shape Sorter</h1>
<p>Rotate the rectangular block and test it against the lid opening.</p>
</header>
<section id="statusPanel" class="panel status" aria-live="polite">
<div class="status-head">
<span class="status-dot"></span>
<span id="statusTitle" class="status-title">Aligned orientation</span>
</div>
<p id="statusCopy" class="status-copy">
The long edges match the slot. This block should pass through cleanly.
</p>
</section>
<section class="panel controls">
<div class="control-top">
<div>
<label class="angle-label" for="angle">
<span>Block rotation</span>
<output id="angleValue" for="angle">0°</output>
</label>
<input
id="angle"
type="range"
min="-90"
max="90"
step="1"
value="0"
aria-label="Block rotation in degrees"
>
</div>
<div class="presets" aria-label="Angle presets">
<button class="preset active" data-angle="0" type="button">0°</button>
<button class="preset" data-angle="30" type="button">30°</button>
<button class="preset" data-angle="60" type="button">60°</button>
<button class="preset" data-angle="90" type="button">90°</button>
</div>
</div>
<div class="control-bottom">
<div class="note">
±8° alignment window<br>
The block remains rigid during every test.
</div>
<button id="reset" class="action" type="button">Reset</button>
<button id="push" class="action" type="button">Push block</button>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Space to push</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9ef);
scene.fog = new THREE.Fog(0xdce9ef, 13, 25);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly shape sorter scene"
);
document.querySelector("#scene").appendChild(renderer.domElement);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const standard = (color, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.02,
flatShading: true,
...extra
});
const bodyMaterial = standard(0x79b9ae);
const lidMaterial = standard(0xf2bd69);
const rimMaterial = standard(0x51d0a3, {
emissive: 0x0b4f3b,
emissiveIntensity: 0.28
});
const darkMaterial = standard(0x243d4c);
const coralMaterial = standard(0xee7867);
const blueMaterial = standard(0x688bd4);
const creamMaterial = standard(0xfff4dc);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xe8f8ff, 0x788c78, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff2d7, 3.2);
keyLight.position.set(5.5, 9, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x9dc7ff, 1.25);
fillLight.position.set(-6, 4, -4);
scene.add(fillLight);
// ------------------------------------------------------------
// Ground and low-poly pedestal
// ------------------------------------------------------------
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(5.5, 5.8, 0.22, 24),
standard(0xc7d7dc)
);
pedestal.position.y = -0.13;
pedestal.receiveShadow = true;
scene.add(pedestal);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
standard(0xdce9ef)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
// ------------------------------------------------------------
// Sorter body
// ------------------------------------------------------------
const BODY_W = 3.8;
const BODY_D = 2.8;
const SLOT_W = 1.42;
const SLOT_D = 0.82;
const LID_TOP = 1.8;
function addBox(width, height, depth, x, y, z, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Base and interior floor.
addBox(BODY_W, 0.22, BODY_D, 0, 0.11, 0, bodyMaterial);
addBox(BODY_W - 0.3, 0.025, BODY_D - 0.3, 0, 0.232, 0, darkMaterial);
// Four rigid outer walls.
const wallHeight = 1.42;
const wallY = 0.22 + wallHeight / 2;
addBox(BODY_W, wallHeight, 0.16, 0, wallY, -BODY_D / 2 + 0.08, bodyMaterial);
addBox(BODY_W, wallHeight, 0.16, 0, wallY, BODY_D / 2 - 0.08, bodyMaterial);
addBox(0.16, wallHeight, BODY_D - 0.32, -BODY_W / 2 + 0.08, wallY, 0, bodyMaterial);
addBox(0.16, wallHeight, BODY_D - 0.32, BODY_W / 2 - 0.08, wallY, 0, bodyMaterial);
// Four separate lid panels leave a genuine rectangular opening.
const sideWidth = (BODY_W - SLOT_W) / 2;
const endDepth = (BODY_D - SLOT_D) / 2;
const lidThickness = 0.16;
const lidY = LID_TOP - lidThickness / 2;
addBox(
sideWidth,
lidThickness,
BODY_D,
-(SLOT_W / 2 + sideWidth / 2),
lidY,
0,
lidMaterial
);
addBox(
sideWidth,
lidThickness,
BODY_D,
SLOT_W / 2 + sideWidth / 2,
lidY,
0,
lidMaterial
);
addBox(
SLOT_W,
lidThickness,
endDepth,
0,
lidY,
-(SLOT_D / 2 + endDepth / 2),
lidMaterial
);
addBox(
SLOT_W,
lidThickness,
endDepth,
0,
lidY,
SLOT_D / 2 + endDepth / 2,
lidMaterial
);
// Colored rim pieces surrounding the opening.
const rimY = LID_TOP + 0.018;
const rimThickness = 0.045;
addBox(
rimThickness,
0.035,
SLOT_D + 0.1,
-SLOT_W / 2 - rimThickness / 2,
rimY,
0,
rimMaterial
);
addBox(
rimThickness,
0.035,
SLOT_D + 0.1,
SLOT_W / 2 + rimThickness / 2,
rimY,
0,
rimMaterial
);
addBox(
SLOT_W + 0.1,
0.035,
rimThickness,
0,
rimY,
-SLOT_D / 2 - rimThickness / 2,
rimMaterial
);
addBox(
SLOT_W + 0.1,
0.035,
rimThickness,
0,
rimY,
SLOT_D / 2 + rimThickness / 2,
rimMaterial
);
// A few toys inside the box make the opening read as a real cavity.
const toyCube = addBox(
0.46,
0.46,
0.46,
-1.15,
0.475,
0.72,
coralMaterial
);
toyCube.rotation.y = 0.18;
const toyCylinder = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.24, 0.48, 6),
blueMaterial
);
toyCylinder.position.set(1.22, 0.475, 0.76);
toyCylinder.rotation.y = 0.35;
toyCylinder.castShadow = true;
toyCylinder.receiveShadow = true;
scene.add(toyCylinder);
// ------------------------------------------------------------
// Movable rectangular block
// ------------------------------------------------------------
const BLOCK_W = 1.2;
const BLOCK_H = 0.64;
const BLOCK_D = 0.62;
const START_Y = 3.18;
const block = new THREE.Group();
scene.add(block);
const blockMesh = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_W, BLOCK_H, BLOCK_D),
standard(0xef825d)
);
blockMesh.castShadow = true;
blockMesh.receiveShadow = true;
block.add(blockMesh);
const blockEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(blockMesh.geometry),
new THREE.LineBasicMaterial({
color: 0x9e4939,
transparent: true,
opacity: 0.7
})
);
block.add(blockEdges);
// A cream top stripe makes the orientation immediately readable.
const topStripe = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_W * 0.68, 0.018, 0.18),
creamMaterial
);
topStripe.position.set(-0.06, BLOCK_H / 2 + 0.012, 0);
topStripe.castShadow = true;
block.add(topStripe);
// Low-poly arrow pointing along the block's long axis.
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.105, 0.19, 3),
creamMaterial
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(BLOCK_W * 0.36, BLOCK_H / 2 + 0.04, 0);
arrow.castShadow = true;
block.add(arrow);
// Matching stripe on the front face.
const frontStripe = new THREE.Mesh(
new THREE.BoxGeometry(BLOCK_W * 0.62, 0.09, 0.015),
creamMaterial
);
frontStripe.position.set(-0.04, 0, BLOCK_D / 2 + 0.009);
block.add(frontStripe);
block.position.set(0, START_Y, 0);
// ------------------------------------------------------------
// Projected footprint on the lid
// ------------------------------------------------------------
const projectionGeometry = new THREE.BufferGeometry();
projectionGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(12), 3)
);
const projectionMaterial = new THREE.LineBasicMaterial({
color: 0x28b889,
transparent: true,
opacity: 0.95
});
const projection = new THREE.LineLoop(
projectionGeometry,
projectionMaterial
);
projection.position.y = LID_TOP + 0.041;
scene.add(projection);
// ------------------------------------------------------------
// UI and interaction state
// ------------------------------------------------------------
const angleInput = document.querySelector("#angle");
const angleValue = document.querySelector("#angleValue");
const pushButton = document.querySelector("#push");
const resetButton = document.querySelector("#reset");
const statusPanel = document.querySelector("#statusPanel");
const statusTitle = document.querySelector("#statusTitle");
const statusCopy = document.querySelector("#statusCopy");
const presetButtons = [...document.querySelectorAll(".preset")];
const ALIGNMENT_TOLERANCE = 8;
let angleDegrees = 0;
let movementState = "ready";
let animationStart = 0;
let animationFrom = START_Y;
let animationTo = START_Y;
let animationDuration = 1500;
function isAligned(degrees = angleDegrees) {
return Math.abs(degrees) <= ALIGNMENT_TOLERANCE;
}
function setStatus(kind, title, copy) {
statusPanel.className = `panel status ${kind}`;
statusTitle.textContent = title;
statusCopy.textContent = copy;
}
function updateProjection() {
const radians = THREE.MathUtils.degToRad(angleDegrees);
const cosine = Math.cos(radians);
const sine = Math.sin(radians);
const corners = [
[-BLOCK_W / 2, -BLOCK_D / 2],
[BLOCK_W / 2, -BLOCK_D / 2],
[BLOCK_W / 2, BLOCK_D / 2],
[-BLOCK_W / 2, BLOCK_D / 2]
];
const positions = projectionGeometry.attributes.position;
corners.forEach(([x, z], index) => {
const worldX = x * cosine + z * sine;
const worldZ = -x * sine + z * cosine;
positions.setXYZ(index, worldX, 0, worldZ);
});
positions.needsUpdate = true;
const color = isAligned() ? 0x28b889 : 0xed6b65;
projectionMaterial.color.setHex(color);
rimMaterial.color.setHex(isAligned() ? 0x51d0a3 : 0xed6b65);
rimMaterial.emissive.setHex(isAligned() ? 0x0b4f3b : 0x5f1714);
}
function updateAngle(value) {
angleDegrees = THREE.MathUtils.clamp(Number(value), -90, 90);
angleInput.value = String(angleDegrees);
const sign = angleDegrees > 0 ? "+" : "";
angleValue.value = `${sign}${angleDegrees}°`;
block.rotation.y = THREE.MathUtils.degToRad(angleDegrees);
// Any angle edit resets the test to the starting position.
movementState = "ready";
block.position.y = START_Y;
pushButton.disabled = false;
pushButton.textContent = "Push block";
presetButtons.forEach((button) => {
button.classList.toggle("active", Number(button.dataset.angle) === angleDegrees);
});
updateProjection();
if (isAligned()) {
setStatus(
"",
"Aligned orientation",
"The long edges match the slot. This block should pass through cleanly."
);
} else {
setStatus(
"warning",
"Rotation mismatch",
`The block is ${Math.abs(angleDegrees)}° off. It will stop above the rigid lid.`
);
}
}
function pushBlock() {
if (movementState === "moving") return;
const aligned = isAligned();
movementState = "moving";
animationStart = performance.now();
animationFrom = START_Y;
animationDuration = aligned ? 1850 : 1450;
// Aligned blocks descend into the box. Mismatched blocks stop
// with their lower face safely above the lid.
animationTo = aligned
? 0.55
: LID_TOP + BLOCK_H / 2 + 0.09;
block.position.y = animationFrom;
pushButton.disabled = true;
pushButton.textContent = "Testing…";
setStatus(
"moving",
aligned ? "Moving through opening" : "Testing clearance",
aligned
? "The block is aligned and descending into the sorter."
: "The rigid block is descending toward the lid."
);
}
function resetScene() {
updateAngle(0);
}
angleInput.addEventListener("input", (event) => {
updateAngle(event.target.value);
});
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
updateAngle(button.dataset.angle);
});
});
pushButton.addEventListener("click", pushBlock);
resetButton.addEventListener("click", resetScene);
window.addEventListener("keydown", (event) => {
const tag = event.target.tagName;
if (event.code === "Space" && tag !== "INPUT" && tag !== "BUTTON") {
event.preventDefault();
pushBlock();
}
});
// ------------------------------------------------------------
// Custom orbit controls, implemented without external addons
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
let cameraRadius = 9.2;
let cameraTheta = 0.68;
let cameraPhi = 0.93;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x + cameraRadius * Math.sin(cameraPhi) * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * Math.sin(cameraPhi) * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + deltaY * 0.005,
0.42,
1.35
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.006,
6.2,
13.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraRadius = 9.2;
cameraTheta = 0.68;
cameraPhi = 0.93;
updateCamera();
});
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const easeInOutCubic = (value) =>
value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
function animate(now) {
requestAnimationFrame(animate);
if (movementState === "moving") {
const progress = THREE.MathUtils.clamp(
(now - animationStart) / animationDuration,
0,
1
);
const eased = easeInOutCubic(progress);
block.position.y = THREE.MathUtils.lerp(
animationFrom,
animationTo,
eased
);
if (progress >= 1) {
movementState = "result";
pushButton.disabled = false;
pushButton.textContent = "Push again";
if (isAligned()) {
setStatus(
"",
"Passed through opening",
"The block descended through the slot without bending or deforming."
);
} else {
setStatus(
"warning",
"Stopped above lid",
"The corners could not clear the opening. The block remained completely rigid."
);
}
}
}
renderer.render(scene, camera);
}
updateAngle(0);
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```