Prompt specification
Build or customize the Three.js 3D scene "Sliding Block With One Empty Socket" 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: Sliding Block With One Empty Socket
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sliding-block-with-one-empty-socket-x3501
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: sliding block with one empty socket. Build a small rail containing two blocks and an empty position. Show constrained motion and make it impossible for a block to leave its guide. Return one self-contained HTML file.
Working Three.js Starter (sliding-block-with-one-empty-socket-x3501):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>One Slot Open — Guided Sliding Blocks</title>
<style>
:root {
color-scheme: light;
--ink: #18383a;
--muted: #5e7472;
--panel: rgba(255, 253, 247, 0.78);
--line: rgba(24, 56, 58, 0.14);
--accent: #16a995;
--accent-dark: #0b756a;
--coral: #ef735e;
--gold: #e8b84c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee8dc;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.intro {
position: absolute;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 5vw, 72px);
max-width: 390px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--accent-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
content: "";
background: var(--accent);
border-radius: 99px;
}
h1 {
margin: 0;
font-size: clamp(36px, 5vw, 68px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.95;
}
.intro p {
max-width: 330px;
margin: 17px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.controls {
position: absolute;
top: clamp(20px, 4vw, 48px);
right: clamp(20px, 4vw, 58px);
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-width: 44px;
height: 44px;
padding: 0 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 13px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 30px rgba(27, 55, 52, 0.08);
backdrop-filter: blur(14px);
transition:
transform 150ms ease,
background 150ms ease,
opacity 150ms ease;
}
button:hover:not(:disabled) {
transform: translateY(-2px);
background: rgba(255, 255, 255, 0.94);
}
button:active:not(:disabled) {
transform: translateY(0) scale(0.97);
}
button:disabled {
opacity: 0.35;
cursor: default;
}
button.reset {
padding-inline: 17px;
}
.status-wrap {
position: absolute;
left: 50%;
bottom: clamp(20px, 4vw, 44px);
width: min(92vw, 520px);
transform: translateX(-50%);
text-align: center;
}
.status {
display: inline-flex;
align-items: center;
gap: 10px;
max-width: 100%;
padding: 11px 16px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
color: var(--muted);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.025em;
box-shadow: 0 12px 36px rgba(27, 55, 52, 0.09);
backdrop-filter: blur(14px);
}
.status-dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(22, 169, 149, 0.12);
}
.hint {
margin-top: 10px;
color: rgba(24, 56, 58, 0.52);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.03em;
}
.axis-note {
position: absolute;
right: clamp(20px, 4vw, 58px);
bottom: clamp(24px, 4vw, 48px);
color: rgba(24, 56, 58, 0.48);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-align: right;
text-transform: uppercase;
}
@media (max-width: 700px) {
.intro {
max-width: 260px;
}
.intro p {
display: none;
}
.controls {
top: auto;
right: 16px;
bottom: 86px;
}
.axis-note {
display: none;
}
button {
height: 42px;
min-width: 42px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="overlay">
<section class="intro">
<div class="eyebrow">Kinetic study · 01</div>
<h1>One Slot<br />Open</h1>
<p>
A pair of blocks, one open socket, and a single guided axis.
Every block remains captured by the rail.
</p>
</section>
<nav class="controls" aria-label="Block controls">
<button id="shiftLeft" type="button" aria-label="Move selected block left">←</button>
<button id="shiftRight" type="button" aria-label="Move selected block right">→</button>
<button id="reset" class="reset" type="button">Reset</button>
</nav>
<div class="status-wrap">
<div class="status" role="status" aria-live="polite">
<span class="status-dot"></span>
<span id="statusText">Socket 03 is open. Drag block B along the guide.</span>
</div>
<div class="hint">Drag a block · Drag the background to orbit · Scroll to zoom</div>
</div>
<div class="axis-note">One-axis constraint<br />End stops engaged</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 stage = document.querySelector("#stage");
const statusText = document.querySelector("#statusText");
const shiftLeftButton = document.querySelector("#shiftLeft");
const shiftRightButton = document.querySelector("#shiftRight");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee8dc);
scene.fog = new THREE.Fog(0xeee8dc, 13, 25);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-5, 5, 3.3, -3.3, 0.1, 50);
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
const orbit = {
yaw: 0.56,
pitch: 0.48,
radius: 12,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xfff8e8, 0x76928d, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d4, 3.4);
keyLight.position.set(5.5, 9, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0006;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xaedbd5, 1.1);
fillLight.position.set(-5, 4, -4);
scene.add(fillLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xf5efe3,
roughness: 0.88,
metalness: 0
});
const floor = new THREE.Mesh(new THREE.CircleGeometry(4.75, 96), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.075;
floor.receiveShadow = true;
scene.add(floor);
const railGroup = new THREE.Group();
scene.add(railGroup);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x27494b,
roughness: 0.5,
metalness: 0.18
});
const railMaterial = new THREE.MeshStandardMaterial({
color: 0x638482,
emissive: 0x173e3d,
emissiveIntensity: 0.12,
roughness: 0.34,
metalness: 0.42
});
const insetMaterial = new THREE.MeshStandardMaterial({
color: 0x17363a,
roughness: 0.68,
metalness: 0.08
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(6.45, 0.25, 2.28),
baseMaterial
);
base.position.y = 0.12;
base.castShadow = true;
base.receiveShadow = true;
railGroup.add(base);
const inset = new THREE.Mesh(
new THREE.BoxGeometry(6.05, 0.1, 1.48),
insetMaterial
);
inset.position.y = 0.3;
inset.receiveShadow = true;
railGroup.add(inset);
[-0.91, 0.91].forEach((z) => {
const sideRail = new THREE.Mesh(
new THREE.BoxGeometry(6.18, 0.32, 0.16),
railMaterial
);
sideRail.position.set(0, 0.78, z);
sideRail.castShadow = true;
sideRail.receiveShadow = true;
railGroup.add(sideRail);
});
[-3.02, 3.02].forEach((x) => {
const stop = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.96, 1.98),
railMaterial
);
stop.position.set(x, 0.83, 0);
stop.castShadow = true;
stop.receiveShadow = true;
railGroup.add(stop);
const stopCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 2.02, 24),
new THREE.MeshStandardMaterial({
color: 0x8eaaa3,
roughness: 0.32,
metalness: 0.48
})
);
stopCap.rotation.x = Math.PI / 2;
stopCap.position.set(x, 1.27, 0);
stopCap.castShadow = true;
railGroup.add(stopCap);
});
const axisMaterial = new THREE.MeshStandardMaterial({
color: 0x4d9a8f,
roughness: 0.55,
metalness: 0.15
});
const axisLine = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, 4.65, 12),
axisMaterial
);
axisLine.rotation.z = Math.PI / 2;
axisLine.position.set(0, 0.075, 1.48);
railGroup.add(axisLine);
const arrowGeometry = new THREE.ConeGeometry(0.095, 0.27, 18);
const rightArrow = new THREE.Mesh(arrowGeometry, axisMaterial);
rightArrow.rotation.z = -Math.PI / 2;
rightArrow.position.set(2.43, 0.075, 1.48);
railGroup.add(rightArrow);
const leftArrow = new THREE.Mesh(arrowGeometry, axisMaterial);
leftArrow.rotation.z = Math.PI / 2;
leftArrow.position.set(-2.43, 0.075, 1.48);
railGroup.add(leftArrow);
const slots = [-1.55, 0, 1.55];
const slotRings = [];
const slotDiscs = [];
slots.forEach((x) => {
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0x65d8c1,
emissive: 0x36bda6,
emissiveIntensity: 1,
transparent: true,
opacity: 0.9,
roughness: 0.4,
metalness: 0.08
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.43, 0.035, 12, 64),
ringMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.set(x, 0.365, 0);
railGroup.add(ring);
slotRings.push(ring);
const discMaterial = new THREE.MeshBasicMaterial({
color: 0x65d8c1,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const disc = new THREE.Mesh(
new THREE.CircleGeometry(0.365, 64),
discMaterial
);
disc.rotation.x = -Math.PI / 2;
disc.position.set(x, 0.359, 0);
railGroup.add(disc);
slotDiscs.push(disc);
});
const targetMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.5, 0.026, 10, 64),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
targetMarker.rotation.x = -Math.PI / 2;
targetMarker.position.y = 0.38;
targetMarker.visible = false;
railGroup.add(targetMarker);
function roundedRectangleShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function makeLabelTexture(letter) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, 256, 256);
context.fillStyle = "rgba(255, 251, 239, 0.94)";
context.strokeStyle = "rgba(255, 255, 255, 0.9)";
context.lineWidth = 8;
context.beginPath();
context.roundRect(34, 34, 188, 188, 54);
context.fill();
context.stroke();
context.fillStyle = "#173a3b";
context.font = "800 132px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(letter, 128, 137);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function createBlock(letter, color, slot) {
const shape = roundedRectangleShape(1.04, 1.04, 0.14);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.96,
bevelEnabled: true,
bevelThickness: 0.07,
bevelSize: 0.07,
bevelSegments: 4,
curveSegments: 12,
steps: 1
});
geometry.center();
const material = new THREE.MeshStandardMaterial({
color,
emissive: new THREE.Color(color).multiplyScalar(0.16),
emissiveIntensity: 0.14,
roughness: 0.38,
metalness: 0.08
});
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(slots[slot], 0.96, 0);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const labelTexture = makeLabelTexture(letter);
const labelMaterial = new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
depthWrite: false,
toneMapped: false,
polygonOffset: true,
polygonOffsetFactor: -1
});
const frontLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.66, 0.66),
labelMaterial
);
frontLabel.position.z = 0.574;
frontLabel.renderOrder = 2;
mesh.add(frontLabel);
const backLabel = new THREE.Mesh(
new THREE.PlaneGeometry(0.66, 0.66),
labelMaterial.clone()
);
backLabel.position.z = -0.574;
backLabel.rotation.y = Math.PI;
backLabel.renderOrder = 2;
mesh.add(backLabel);
const topMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(color).multiplyScalar(0.76),
roughness: 0.45,
metalness: 0.08
});
const topInset = new THREE.Mesh(
new THREE.BoxGeometry(0.52, 0.035, 0.36),
topMaterial
);
topInset.position.set(0, 0.606, 0.06);
topInset.castShadow = true;
mesh.add(topInset);
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 24),
new THREE.LineBasicMaterial({
color: 0xfafff8,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
outline.scale.setScalar(1.025);
outline.renderOrder = 3;
mesh.add(outline);
const block = {
name: `Block ${letter}`,
letter,
mesh,
material,
outline,
slot,
animation: null
};
mesh.userData.block = block;
return block;
}
const blockA = createBlock("A", 0xef735e, 0);
const blockB = createBlock("B", 0xe8b84c, 1);
const blocks = [blockA, blockB];
const blockBodies = blocks.map((block) => block.mesh);
let selectedBlock = blockB;
let collisionPulse = 0;
function occupiedSlots() {
return new Set(blocks.map((block) => block.slot));
}
function openSocketIndex() {
const occupied = occupiedSlots();
return slots.findIndex((_, index) => !occupied.has(index));
}
function updateSlotVisuals() {
const occupied = occupiedSlots();
slotRings.forEach((ring, index) => {
const isOpen = !occupied.has(index);
ring.material.color.set(isOpen ? 0x67dfc7 : 0x426a68);
ring.material.emissive.set(isOpen ? 0x34c4aa : 0x173d3b);
ring.material.emissiveIntensity = isOpen ? 1.2 : 0.15;
ring.material.opacity = isOpen ? 0.95 : 0.36;
slotDiscs[index].material.opacity = isOpen ? 0.18 : 0.05;
slotDiscs[index].material.color.set(isOpen ? 0x67dfc7 : 0x557b77);
});
}
function setSelected(block) {
selectedBlock = block;
blocks.forEach((item) => {
const isSelected = item === block;
item.outline.visible = isSelected;
item.material.emissiveIntensity = isSelected ? 0.42 : 0.08;
});
updateButtons();
}
function updateButtons() {
if (!selectedBlock) return;
const leftTarget = selectedBlock.slot - 1;
const rightTarget = selectedBlock.slot + 1;
const occupied = occupiedSlots();
shiftLeftButton.disabled =
selectedBlock.animation !== null ||
leftTarget < 0 ||
occupied.has(leftTarget);
shiftRightButton.disabled =
selectedBlock.animation !== null ||
rightTarget >= slots.length ||
occupied.has(rightTarget);
}
function animateBlock(block, targetSlot, duration = 520) {
const now = performance.now();
block.slot = targetSlot;
block.animation = {
from: block.mesh.position.x,
to: slots[targetSlot],
start: now,
duration
};
updateSlotVisuals();
updateButtons();
}
function nearestSlot(x) {
let nearest = 0;
let distance = Infinity;
slots.forEach((slot, index) => {
const currentDistance = Math.abs(slot - x);
if (currentDistance < distance) {
distance = currentDistance;
nearest = index;
}
});
return nearest;
}
function targetSlotForDrag(block, x, startingSlot) {
let target = nearestSlot(x);
const other = blocks.find((item) => item !== block);
if (target === startingSlot) return startingSlot;
if (other.slot === target) return startingSlot;
const crossesOther =
(startingSlot < other.slot && target > other.slot) ||
(startingSlot > other.slot && target < other.slot);
return crossesOther ? startingSlot : target;
}
function moveSelected(direction) {
if (!selectedBlock || selectedBlock.animation) return;
const target = selectedBlock.slot + direction;
if (target < 0 || target >= slots.length) return;
const occupied = occupiedSlots();
if (occupied.has(target)) return;
animateBlock(selectedBlock, target);
statusText.textContent =
`${selectedBlock.name} slid into socket ${String(target + 1).padStart(2, "0")}.`;
}
shiftLeftButton.addEventListener("click", () => moveSelected(-1));
shiftRightButton.addEventListener("click", () => moveSelected(1));
resetButton.addEventListener("click", () => {
animateBlock(blockA, 0, 620);
animateBlock(blockB, 1, 620);
targetMarker.visible = false;
statusText.textContent = "Reset. Socket 03 is open; drag block B along the guide.";
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), -0.96);
const dragPoint = new THREE.Vector3();
let pointerMode = null;
let activeBlock = null;
let activePointerId = null;
let dragOffset = 0;
let dragStartX = 0;
let dragStartY = 0;
let dragMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function updateCamera() {
const horizontalRadius = orbit.radius * Math.cos(orbit.pitch);
camera.position.set(
cameraTarget.x + Math.sin(orbit.yaw) * horizontalRadius,
cameraTarget.y + Math.sin(orbit.pitch) * orbit.radius,
cameraTarget.z + Math.cos(orbit.yaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(6.2, 7.45 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
updatePointer(event);
const hits = raycaster.intersectObjects(blockBodies, false);
activePointerId = event.pointerId;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
if (hits.length > 0) {
const block = hits[0].object.userData.block;
setSelected(block);
if (block.animation) return;
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
pointerMode = "drag";
activeBlock = block;
dragOffset = block.mesh.position.x - dragPoint.x;
dragStartX = block.mesh.position.x;
dragStartY = block.slot;
dragMoved = false;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
} else {
pointerMode = "orbit";
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerMode === "drag" && activeBlock) {
updatePointer(event);
if (!raycaster.ray.intersectPlane(dragPlane, dragPoint)) return;
const rawX = dragPoint.x + dragOffset;
let constrainedX = THREE.MathUtils.clamp(rawX, -2.3, 2.3);
let blocked = rawX !== constrainedX;
const other = blocks.find((block) => block !== activeBlock);
const otherX = other.mesh.position.x;
const contactDistance = 1.19;
if (otherX > dragStartX + 0.01) {
const collisionLimit = otherX - contactDistance;
if (constrainedX > collisionLimit) {
constrainedX = collisionLimit;
blocked = true;
}
} else if (otherX < dragStartX - 0.01) {
const collisionLimit = otherX + contactDistance;
if (constrainedX < collisionLimit) {
constrainedX = collisionLimit;
blocked = true;
}
}
activeBlock.mesh.position.x = constrainedX;
dragMoved =
dragMoved ||
Math.abs(constrainedX - dragStartX) > 0.035 ||
Math.abs(event.clientX - lastPointerX) > 3;
const target = targetSlotForDrag(
activeBlock,
constrainedX,
dragStartY
);
if (target !== dragStartY) {
targetMarker.visible = true;
targetMarker.position.x = slots[target];
} else {
targetMarker.visible = false;
}
if (blocked) {
collisionPulse = 1;
statusText.textContent = "Guide limit reached · the block remains captured.";
} else {
statusText.textContent =
target !== dragStartY
? `Release to move ${activeBlock.name} into socket ${String(target + 1).padStart(2, "0")}.`
: `${activeBlock.name} is moving on the single-axis guide.`;
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
return;
}
if (pointerMode === "orbit") {
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
orbit.yaw -= deltaX * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.005,
0.28,
1.06
);
updateCamera();
lastPointerX = event.clientX;
lastPointerY = event.clientY;
return;
}
updatePointer(event);
const hoveringBlock = raycaster.intersectObjects(blockBodies, false).length > 0;
renderer.domElement.style.cursor = hoveringBlock ? "grab" : "default";
});
function finishPointer(event) {
if (pointerMode === "drag" && activeBlock) {
if (dragMoved) {
const target = targetSlotForDrag(
activeBlock,
activeBlock.mesh.position.x,
dragStartY
);
animateBlock(activeBlock, target);
statusText.textContent =
target !== dragStartY
? `${activeBlock.name} settled into socket ${String(target + 1).padStart(2, "0")}.`
: `${activeBlock.name} returned to socket ${String(dragStartY + 1).padStart(2, "0")}.`;
} else {
statusText.textContent =
`${activeBlock.name} selected · drag along the rail or use the arrow buttons.`;
}
}
targetMarker.visible = false;
if (
activePointerId !== null &&
renderer.domElement.hasPointerCapture(activePointerId)
) {
renderer.domElement.releasePointerCapture(activePointerId);
}
pointerMode = null;
activeBlock = null;
activePointerId = null;
renderer.domElement.style.cursor = "grab";
updateButtons();
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.7
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.yaw = 0.56;
orbit.pitch = 0.48;
orbit.zoom = 1;
updateCamera();
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function animate() {
const now = performance.now();
blocks.forEach((block) => {
if (!block.animation) return;
const animation = block.animation;
const progress = THREE.MathUtils.clamp(
(now - animation.start) / animation.duration,
0,
1
);
const eased = easeInOutCubic(progress);
block.mesh.position.x = THREE.MathUtils.lerp(
animation.from,
animation.to,
eased
);
if (progress >= 1) {
block.mesh.position.x = animation.to;
block.animation = null;
updateButtons();
}
});
const openIndex = openSocketIndex();
slotRings.forEach((ring, index) => {
if (index === openIndex) {
const pulse = 1 + Math.sin(now * 0.004) * 0.045;
ring.scale.setScalar(pulse);
} else {
ring.scale.setScalar(1);
}
});
if (collisionPulse > 0) {
collisionPulse = Math.max(0, collisionPulse - 0.035);
}
railMaterial.emissiveIntensity =
0.12 + collisionPulse * (0.45 + Math.sin(now * 0.04) * 0.15);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
updateCamera();
updateSlotVisuals();
setSelected(blockB);
animate();
</script>
</body>
</html>
```