Prompt specification
Build or customize the Three.js 3D scene "Sliding dovetail insertion path" 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 dovetail insertion path
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sliding-dovetail-insertion-path-x2202
Scene Description Prompt:
Use Three.js from cdnjs to animate a dovetail insert moving along its permitted direction into a matching groove. Show why a perpendicular insertion fails due to the interlocking profile geometry. Deliver one self-contained HTML file with low-poly forms.
Working Three.js Starter (sliding-dovetail-insertion-path-x2202):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dovetail Insert — Permitted vs Perpendicular Motion</title>
<style>
:root {
color-scheme: dark;
--bg: #09111e;
--panel: rgba(13, 24, 39, 0.82);
--border: rgba(151, 205, 231, 0.18);
--text: #eaf6ff;
--muted: #9bb1c5;
--green: #5ce5a5;
--red: #ff6478;
--amber: #ffbd59;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
header {
position: absolute;
top: 24px;
left: 26px;
width: min(560px, calc(100vw - 250px));
}
.eyebrow {
color: var(--amber);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
color: var(--text);
font-size: clamp(24px, 3vw, 42px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 540px;
margin: 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid var(--border);
border-radius: 10px;
padding: 10px 14px;
color: var(--text);
background: rgba(16, 31, 49, 0.86);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
}
button:hover {
border-color: rgba(92, 229, 165, 0.55);
background: rgba(23, 45, 65, 0.95);
}
.world-tag {
position: absolute;
top: 0;
left: 0;
min-width: 220px;
padding: 10px 13px;
border: 1px solid var(--border);
border-radius: 12px;
color: var(--text);
background: rgba(8, 17, 29, 0.84);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
transition: opacity 120ms linear;
}
.world-tag .tag-title {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-tag .tag-status {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 11px;
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px currentColor;
}
.red .dot {
background: var(--red);
}
.explanation {
position: absolute;
right: 24px;
bottom: 22px;
left: 24px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
pointer-events: none;
}
.card {
position: relative;
overflow: hidden;
padding: 16px 18px 15px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
}
.card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
content: "";
background: var(--green);
}
.card.blocked::before {
background: var(--red);
}
.card h2 {
margin: 0 0 7px;
color: var(--text);
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.card p {
max-width: 700px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.dimension {
display: inline-block;
margin-top: 9px;
padding: 5px 8px;
border: 1px solid rgba(255, 100, 120, 0.28);
border-radius: 6px;
color: #ff9aaa;
background: rgba(255, 100, 120, 0.08);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
footer {
position: absolute;
bottom: 7px;
left: 50%;
color: rgba(177, 198, 216, 0.65);
font-size: 10px;
transform: translateX(-50%);
white-space: nowrap;
}
@media (max-width: 760px) {
header {
top: 16px;
left: 16px;
width: calc(100vw - 145px);
}
.subtitle { display: none; }
.controls {
top: 15px;
right: 14px;
flex-direction: column;
}
button { padding: 8px 10px; }
.explanation {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: 1fr;
gap: 7px;
}
.card { padding: 11px 13px; }
.card p { font-size: 11px; }
.dimension { display: none; }
.world-tag { min-width: 160px; padding: 8px 10px; }
.world-tag .tag-status { font-size: 10px; }
footer { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated 3D comparison of valid and invalid dovetail insertion directions"></canvas>
<div class="hud">
<header>
<div class="eyebrow">Interlocking geometry</div>
<h1>Direction makes the fit.</h1>
<p class="subtitle">
The same flared insert and matching tapered groove are tested along two axes.
Sliding along the rail works; dropping across the mouth is geometrically blocked.
</p>
</header>
<div class="controls">
<button id="replay" type="button">↻ Replay</button>
<button id="pause" type="button">Ⅱ Pause</button>
</div>
<div class="world-tag" id="allowedTag">
<div class="tag-title"><span class="dot"></span>Permitted · rail axis +Z</div>
<span class="tag-status" id="allowedStatus">Flare aligned with groove</span>
</div>
<div class="world-tag red" id="blockedTag">
<div class="tag-title"><span class="dot"></span>Perpendicular · Y motion</div>
<span class="tag-status" id="blockedStatus">Ready above the mouth</span>
</div>
<section class="explanation">
<article class="card">
<h2>Allowed: translate along Z</h2>
<p>
The insert’s trapezoidal profile enters the identically tapered cavity.
Because motion is parallel to the groove, the two cross-sections remain aligned
and their clearance is preserved throughout insertion.
</p>
</article>
<article class="card blocked">
<h2>Rejected: translate along Y</h2>
<p>
The receiver has solid shoulders at the narrow mouth. The insert’s lower flare
is wider than that opening, so vertical travel must pass through material that
cannot be crossed by pure translation.
</p>
<span class="dimension">FLARE 1.64 > MOUTH 0.96</span>
</article>
</section>
<footer>Drag to orbit · Scroll to zoom · Double-click to reset the camera</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111e);
scene.fog = new THREE.Fog(0x09111e, 18, 34);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
theta: 2.47,
phi: 1.03,
radius: 18.8,
target: new THREE.Vector3(0, 0.65, 0.35)
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb8dcff, 0x172033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d8, 3.2);
keyLight.position.set(5, 10, -7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65a9ff, 1.7);
rimLight.position.set(-8, 4, 6);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0c1726,
roughness: 0.92,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.035;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(32, 32, 0x24445d, 0x142b3e);
grid.position.y = -1.025;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
/*
Receiver cross-section in XY, extruded along Z.
The cavity is wider at its bottom and narrower at the top mouth.
This creates the overhanging shoulders that reject perpendicular motion.
*/
const receiverShape = new THREE.Shape();
receiverShape.moveTo(-2.6, -1.0);
receiverShape.lineTo( 2.6, -1.0);
receiverShape.lineTo( 2.6, 1.0);
receiverShape.lineTo( 0.48, 1.0); // right side of narrow mouth
receiverShape.lineTo( 0.95, -0.55); // tapered cavity wall
receiverShape.lineTo(-0.95, -0.55); // cavity floor
receiverShape.lineTo(-0.48, 1.0); // left side of narrow mouth
receiverShape.lineTo(-2.6, 1.0);
receiverShape.closePath();
const receiverGeometry = new THREE.ExtrudeGeometry(receiverShape, {
depth: 4.0,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
receiverGeometry.computeVertexNormals();
const receiverMaterial = new THREE.MeshStandardMaterial({
color: 0x477a96,
roughness: 0.72,
metalness: 0.08,
transparent: true,
opacity: 0.56,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const receiverEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xa7ddf2,
transparent: true,
opacity: 0.72
});
const receiverEdgesGeometry = new THREE.EdgesGeometry(receiverGeometry, 15);
/*
Male dovetail cross-section:
a narrow neck above the receiver and a wide lower flare.
Its 1.64-unit base cannot pass through the receiver's 0.96-unit mouth.
*/
const insertShape = new THREE.Shape();
insertShape.moveTo(-0.30, 1.45);
insertShape.lineTo( 0.30, 1.45);
insertShape.lineTo( 0.82, -0.45);
insertShape.lineTo(-0.82, -0.45);
insertShape.closePath();
const insertGeometry = new THREE.ExtrudeGeometry(insertShape, {
depth: 3.2,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
insertGeometry.computeVertexNormals();
const insertMaterial = new THREE.MeshStandardMaterial({
color: 0xf3a33d,
roughness: 0.48,
metalness: 0.16,
flatShading: true
});
const insertEdgeMaterial = new THREE.LineBasicMaterial({
color: 0xffe0a1,
transparent: true,
opacity: 0.95
});
const insertEdgesGeometry = new THREE.EdgesGeometry(insertGeometry, 15);
const correctX = -4.0;
const blockedX = 4.0;
function makeReceiver(x) {
const mesh = new THREE.Mesh(receiverGeometry, receiverMaterial);
mesh.position.x = x;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
const edges = new THREE.LineSegments(receiverEdgesGeometry, receiverEdgeMaterial);
edges.position.x = x;
scene.add(edges);
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(5.25, 0.14, 4.25),
new THREE.MeshStandardMaterial({
color: 0x14263a,
roughness: 0.82,
metalness: 0.08
})
);
plinth.position.set(x, -1.10, 2.0);
plinth.receiveShadow = true;
scene.add(plinth);
}
function makeInsert(x) {
const group = new THREE.Group();
group.position.x = x;
const mesh = new THREE.Mesh(insertGeometry, insertMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
const edges = new THREE.LineSegments(insertEdgesGeometry, insertEdgeMaterial);
group.add(edges);
scene.add(group);
return group;
}
makeReceiver(correctX);
makeReceiver(blockedX);
const correctInsert = makeInsert(correctX);
correctInsert.position.z = -3.35;
const blockedInsert = makeInsert(blockedX);
blockedInsert.position.z = 0.4;
blockedInsert.position.y = 2.85;
/* Motion-direction arrows. */
const greenArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(correctX, 2.28, -2.85),
2.55,
0x5ce5a5,
0.34,
0.20
);
scene.add(greenArrow);
const redArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
new THREE.Vector3(blockedX + 1.42, 3.85, 1.65),
1.45,
0xff6478,
0.30,
0.18
);
scene.add(redArrow);
/*
The highlighted strips identify the exact receiver shoulders contacted
by the insert's over-wide base during the failed vertical attempt.
*/
const shoulderMaterial = new THREE.MeshBasicMaterial({
color: 0xff4f69,
transparent: true,
opacity: 0,
depthWrite: false
});
for (const side of [-1, 1]) {
const shoulder = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.035, 3.2),
shoulderMaterial
);
shoulder.position.set(blockedX + side * 0.65, 1.012, 2.0);
scene.add(shoulder);
}
/* Contact bars on the front and rear edges of the flared base. */
const contactMaterial = new THREE.MeshBasicMaterial({
color: 0xff334f,
transparent: true,
opacity: 0
});
const contactGeometry = new THREE.BoxGeometry(1.64, 0.04, 0.04);
for (const z of [0, 3.2]) {
const contact = new THREE.Mesh(contactGeometry, contactMaterial);
contact.position.set(0, -0.45, z);
blockedInsert.add(contact);
}
/* Small low-poly impact diamonds at the two lower corners. */
const impactMaterial = new THREE.MeshBasicMaterial({
color: 0xff526d,
transparent: true,
opacity: 0
});
const impactGeometry = new THREE.OctahedronGeometry(0.085, 0);
for (const x of [-0.82, 0.82]) {
const marker = new THREE.Mesh(impactGeometry, impactMaterial);
marker.position.set(x, -0.44, 0);
blockedInsert.add(marker);
}
/* A simple reference line through the permitted slide direction. */
const axisPoints = [
new THREE.Vector3(correctX, -0.91, -3.45),
new THREE.Vector3(correctX, -0.91, 0.85)
];
const axisGeometry = new THREE.BufferGeometry().setFromPoints(axisPoints);
const axisMaterial = new THREE.LineDashedMaterial({
color: 0x5ce5a5,
dashSize: 0.18,
gapSize: 0.12,
transparent: true,
opacity: 0.55
});
const axisLine = new THREE.Line(axisGeometry, axisMaterial);
axisLine.computeLineDistances();
scene.add(axisLine);
/* DOM labels projected from world-space anchors. */
const allowedTag = document.getElementById("allowedTag");
const blockedTag = document.getElementById("blockedTag");
const allowedStatus = document.getElementById("allowedStatus");
const blockedStatus = document.getElementById("blockedStatus");
function placeTag(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
const allowedAnchor = new THREE.Vector3(correctX, 2.95, -2.0);
const blockedAnchor = new THREE.Vector3(blockedX, 4.72, 1.65);
/* Direct camera controls, implemented without any Three.js addons. */
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.35,
1.45
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
10,
27
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => {
cameraState.theta = 2.47;
cameraState.phi = 1.03;
cameraState.radius = 18.8;
cameraState.target.set(0, 0.65, 0.35);
updateCamera();
});
/* Timeline and UI state. */
let elapsed = 0;
let paused = false;
let previousTime = performance.now();
const cycleDuration = 9.5;
const pauseButton = document.getElementById("pause");
const replayButton = document.getElementById("replay");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "▶ Play" : "Ⅱ Pause";
});
replayButton.addEventListener("click", () => {
elapsed = 0;
});
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smooth01(value) {
const x = clamp01(value);
return x * x * (3 - 2 * x);
}
function lerp(a, b, amount) {
return a + (b - a) * amount;
}
function updateTimeline(time) {
const startZ = -3.35;
const seatedZ = 0.65;
let insertZ;
if (time < 1.0) {
insertZ = startZ;
allowedStatus.textContent = "Flare aligned with groove";
} else if (time < 4.35) {
const p = smooth01((time - 1.0) / 3.35);
insertZ = lerp(startZ, seatedZ, p);
allowedStatus.textContent = "Sliding along +Z · clearance maintained";
} else if (time < 6.15) {
insertZ = seatedZ;
allowedStatus.textContent = "Seated · matching tapered profile";
} else if (time < 8.0) {
const p = smooth01((time - 6.15) / 1.85);
insertZ = lerp(seatedZ, startZ, p);
allowedStatus.textContent = "Withdrawing along the permitted axis";
} else {
insertZ = startZ;
allowedStatus.textContent = "Flare aligned with groove";
}
correctInsert.position.z = insertZ;
const raisedY = 2.85;
const blockedY = 1.45;
let insertY;
let impact = 0;
if (time < 1.0) {
insertY = raisedY;
blockedStatus.textContent = "Ready above the narrow mouth";
} else if (time < 3.3) {
const p = smooth01((time - 1.0) / 2.3);
insertY = lerp(raisedY, blockedY, p);
blockedStatus.textContent = "Attempting downward −Y translation";
} else if (time < 5.15) {
insertY = blockedY;
const pulse = 0.5 + 0.5 * Math.sin((time - 3.3) * 16);
impact = 0.7 + 0.3 * pulse;
blockedStatus.textContent = "BLOCKED · flare meets solid shoulders";
} else if (time < 7.25) {
const p = smooth01((time - 5.15) / 2.1);
insertY = lerp(blockedY, raisedY, p);
blockedStatus.textContent = "Retracting from the blocked position";
} else {
insertY = raisedY;
blockedStatus.textContent = "Ready above the narrow mouth";
}
blockedInsert.position.y = insertY;
shoulderMaterial.opacity = impact * 0.72;
contactMaterial.opacity = impact;
impactMaterial.opacity = impact;
const markerScale = 1 + impact * 0.65;
blockedInsert.children.forEach((child) => {
if (child.geometry === impactGeometry) {
child.scale.setScalar(markerScale);
}
});
}
function animate(now) {
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (!paused) {
elapsed = (elapsed + dt) % cycleDuration;
}
updateTimeline(elapsed);
placeTag(allowedTag, allowedAnchor);
placeTag(blockedTag, blockedAnchor);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```