Prompt specification
Build or customize the Three.js 3D scene "Foundation pad and column starter" 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: Foundation pad and column starter
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/foundation-pad-and-column-starter-x2185
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a foundation pad with marked column position and a separate column element. Use a two-step assembly guide that clearly places the support before the vertical member. Stylized solid forms.
Working Three.js Starter (foundation-pad-and-column-starter-x2185):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Foundation Pad + Column — Assembly Guide</title>
<style>
:root {
--ink: #17313a;
--muted: #667b83;
--line: #d8e1e4;
--teal: #246779;
--orange: #ec7148;
--yellow: #f2bf49;
--green: #26966f;
--panel: rgba(255, 255, 255, 0.91);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7edef;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
overflow: hidden;
}
.guide {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
width: min(370px, calc(100vw - 48px));
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.82);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 22px 60px rgba(38, 65, 75, 0.15),
0 3px 10px rgba(38, 65, 75, 0.06);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--yellow);
content: "";
transform: rotate(45deg);
}
h1 {
margin: 0;
font-size: 34px;
font-weight: 760;
letter-spacing: -0.045em;
line-height: 1;
}
.subtitle {
margin: 11px 0 20px;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.steps {
display: grid;
gap: 9px;
margin: 0 0 18px;
padding: 0;
list-style: none;
}
.step {
display: grid;
grid-template-columns: 38px 1fr auto;
align-items: center;
gap: 11px;
min-height: 65px;
padding: 11px 12px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.58);
transition:
border-color 180ms ease,
background 180ms ease,
opacity 180ms ease;
}
.step-number {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border-radius: 11px;
background: #edf2f3;
color: var(--muted);
font-size: 13px;
font-weight: 800;
transition: 180ms ease;
}
.step-title {
display: block;
font-size: 14px;
font-weight: 760;
}
.step-detail {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.step-status {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.step.active {
border-color: rgba(36, 103, 121, 0.42);
background: rgba(36, 103, 121, 0.075);
}
.step.active .step-number {
background: var(--teal);
color: white;
box-shadow: 0 5px 12px rgba(36, 103, 121, 0.24);
}
.step.done {
border-color: rgba(38, 150, 111, 0.34);
background: rgba(38, 150, 111, 0.065);
}
.step.done .step-number {
background: var(--green);
color: white;
}
.step.done .step-status {
color: var(--green);
}
.step.locked {
opacity: 0.56;
}
.instruction {
min-height: 40px;
margin: 0 0 16px;
color: #425c65;
font-size: 13px;
line-height: 1.5;
}
.action {
display: flex;
width: 100%;
min-height: 50px;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 17px;
border: 0;
border-radius: 14px;
background: var(--ink);
color: white;
cursor: pointer;
font: inherit;
font-size: 14px;
font-weight: 760;
box-shadow: 0 10px 22px rgba(23, 49, 58, 0.18);
transition:
transform 160ms ease,
background 160ms ease,
opacity 160ms ease;
}
.action:hover:not(:disabled) {
background: #234a57;
transform: translateY(-1px);
}
.action:active:not(:disabled) {
transform: translateY(1px);
}
.action:disabled {
cursor: wait;
opacity: 0.72;
}
.action svg {
flex: 0 0 auto;
}
.scene-hint {
position: fixed;
z-index: 8;
right: 22px;
bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(255, 255, 255, 0.72);
color: #536b73;
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
transition: opacity 300ms ease;
}
.hint-icon {
position: relative;
width: 19px;
height: 19px;
border: 1.5px solid currentColor;
border-radius: 50%;
}
.hint-icon::before {
position: absolute;
top: 4px;
left: 4px;
width: 9px;
height: 5px;
border-bottom: 1.5px solid currentColor;
border-left: 1.5px solid currentColor;
content: "";
transform: rotate(-25deg);
}
.object-label {
position: absolute;
z-index: 5;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 999px;
background: rgba(255, 255, 255, 0.86);
box-shadow: 0 7px 20px rgba(38, 65, 75, 0.13);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 150ms ease;
}
.object-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 12px;
background: rgba(42, 68, 76, 0.35);
content: "";
}
.label-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 3px rgba(36, 103, 121, 0.12);
}
#columnLabel .label-dot {
background: var(--orange);
box-shadow: 0 0 0 3px rgba(236, 113, 72, 0.13);
}
.loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #e7edef;
color: var(--teal);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 700px) {
.guide {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 17px;
border-radius: 18px;
}
h1 {
font-size: 27px;
}
.subtitle {
display: none;
}
.eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
.steps {
margin-top: 14px;
}
.step {
min-height: 57px;
grid-template-columns: 34px 1fr auto;
padding: 9px 10px;
}
.step-number {
width: 32px;
height: 32px;
}
.step-detail {
display: none;
}
.instruction {
min-height: 0;
margin: 13px 0;
font-size: 12px;
}
.scene-hint {
right: 12px;
bottom: 12px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels" aria-hidden="true">
<div id="supportLabel" class="object-label">
<span class="label-dot"></span>
<span>01 · SUPPORT</span>
</div>
<div id="columnLabel" class="object-label">
<span class="label-dot"></span>
<span>02 · COLUMN</span>
</div>
</div>
<main class="guide" aria-label="Two-step assembly guide">
<div class="eyebrow">Assembly guide · 2 steps</div>
<h1>Pad + Column</h1>
<p class="subtitle">
A two-part assembly with a clearly marked foundation position.
</p>
<ol class="steps">
<li id="step1" class="step active">
<span class="step-number">01</span>
<span>
<span class="step-title">Seat the support</span>
<span class="step-detail">Align with the yellow corner marks.</span>
</span>
<span id="step1Status" class="step-status">Ready</span>
</li>
<li id="step2" class="step locked">
<span class="step-number">02</span>
<span>
<span class="step-title">Add the vertical member</span>
<span class="step-detail">Lower onto the seated support.</span>
</span>
<span id="step2Status" class="step-status">Locked</span>
</li>
</ol>
<p id="instruction" class="instruction" aria-live="polite">
Move the teal support onto the marked position before adding the column.
</p>
<button id="actionButton" class="action" type="button">
<span id="actionText">Place support</span>
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" aria-hidden="true">
<path d="M4 10H15M11 5L16 10L11 15" stroke="currentColor" stroke-width="1.8"
stroke-linecap="round" stroke-linejoin="round" />
</svg>
</button>
</main>
<div id="cameraHint" class="scene-hint">
<span class="hint-icon"></span>
<span>Drag to orbit · Scroll to zoom</span>
</div>
<div id="loading" class="loading">Loading assembly…</div>
<script type="module">
// Three.js core only. No addons or example modules are used.
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneContainer = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7edef);
scene.fog = new THREE.Fog(0xe7edef, 23, 42);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneContainer.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D foundation and column assembly scene"
);
const hemisphere = new THREE.HemisphereLight(0xf7fbfc, 0x8fa1a7, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-4.5, 10, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbcdbe3, 1.15);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe3eaec,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.005;
ground.receiveShadow = true;
scene.add(ground);
function makeMaterial(color, roughness = 0.75, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const concreteMaterial = makeMaterial(0xb8c1c3, 0.94);
const concreteSideMaterial = makeMaterial(0xa7b2b5, 0.96);
const dockMaterial = makeMaterial(0xd6dfe1, 0.88);
const supportMaterial = makeMaterial(0x246779, 0.48, 0.22);
const supportDarkMaterial = makeMaterial(0x173f4c, 0.5, 0.28);
const socketMaterial = makeMaterial(0x112c35, 0.7, 0.12);
const columnMaterial = makeMaterial(0xec7148, 0.56, 0.08);
const columnCapMaterial = makeMaterial(0xf38a5e, 0.52, 0.08);
const boltMaterial = makeMaterial(0xcbd5d8, 0.32, 0.7);
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xf2bf49,
emissive: 0xf2bf49,
emissiveIntensity: 0.14,
roughness: 0.62,
transparent: true,
opacity: 0.94
});
/*
A small chamfered-box builder made entirely with Three.js core geometry.
Extrusion is used to create clean, stylized solid edges.
*/
function chamferedBox(width, height, depth, bevel = 0.06) {
const b = Math.min(bevel, width / 5, height / 5, depth / 5);
const halfX = width / 2 - b;
const halfY = depth / 2 - b;
const shape = new THREE.Shape();
shape.moveTo(-halfX, -halfY);
shape.lineTo(halfX, -halfY);
shape.lineTo(halfX, halfY);
shape.lineTo(-halfX, halfY);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: Math.max(0.001, height - b * 2),
steps: 1,
curveSegments: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: b,
bevelThickness: b
});
geometry.rotateX(-Math.PI / 2);
geometry.center();
geometry.computeVertexNormals();
return geometry;
}
function addShadowMesh(parent, geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Assembly coordinates.
const anchor = new THREE.Vector3(-1.35, 0, 0.05);
const padHeight = 0.46;
const padTop = padHeight;
const supportStart = new THREE.Vector3(3.25, 0.08, -0.72);
const supportEnd = new THREE.Vector3(anchor.x, padTop, anchor.z);
const columnStart = new THREE.Vector3(5.15, 0.08, 0.74);
const supportTopLocal = 0.48;
const columnEnd = new THREE.Vector3(
anchor.x,
padTop + supportTopLocal,
anchor.z
);
// Foundation pad.
const foundation = new THREE.Group();
foundation.position.set(anchor.x, 0, anchor.z);
scene.add(foundation);
const pad = addShadowMesh(
foundation,
chamferedBox(4.55, padHeight, 3.18, 0.10),
concreteMaterial,
new THREE.Vector3(0, padHeight / 2, 0)
);
const padEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(pad.geometry, 24),
new THREE.LineBasicMaterial({
color: 0x8d9b9f,
transparent: true,
opacity: 0.32
})
);
pad.add(padEdges);
// A subtle lower edge makes the foundation read as a solid poured block.
addShadowMesh(
foundation,
chamferedBox(4.38, 0.11, 3.01, 0.035),
concreteSideMaterial,
new THREE.Vector3(0, 0.045, 0)
);
// Four simple anchor details on the pad.
const anchorBoltGeometry = new THREE.CylinderGeometry(0.065, 0.065, 0.035, 20);
for (const x of [-1.85, 1.85]) {
for (const z of [-1.13, 1.13]) {
addShadowMesh(
foundation,
anchorBoltGeometry,
boltMaterial,
new THREE.Vector3(x, padTop + 0.015, z)
);
}
}
// Yellow square corner marks show the required column position.
const marker = new THREE.Group();
marker.position.set(anchor.x, padTop + 0.018, anchor.z);
scene.add(marker);
const markerHalf = 0.75;
const markerLength = 0.38;
const markerThickness = 0.035;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addShadowMesh(
marker,
new THREE.BoxGeometry(markerLength, 0.022, markerThickness),
markerMaterial,
new THREE.Vector3(
sx * (markerHalf - markerLength / 2),
0,
sz * markerHalf
)
);
addShadowMesh(
marker,
new THREE.BoxGeometry(markerThickness, 0.022, markerLength),
markerMaterial,
new THREE.Vector3(
sx * markerHalf,
0,
sz * (markerHalf - markerLength / 2)
)
);
}
}
const targetRing = new THREE.Mesh(
new THREE.RingGeometry(0.17, 0.22, 40),
new THREE.MeshBasicMaterial({
color: 0xf2bf49,
transparent: true,
opacity: 0.58,
side: THREE.DoubleSide
})
);
targetRing.rotation.x = -Math.PI / 2;
targetRing.position.y = 0.006;
marker.add(targetRing);
// Parts docks emphasize that the support and column begin as separate pieces.
const supportDock = addShadowMesh(
scene,
chamferedBox(1.8, 0.08, 1.65, 0.035),
dockMaterial,
new THREE.Vector3(supportStart.x, 0.04, supportStart.z)
);
const columnDock = addShadowMesh(
scene,
chamferedBox(1.25, 0.08, 1.45, 0.035),
dockMaterial,
new THREE.Vector3(columnStart.x, 0.04, columnStart.z)
);
const supportDockStripe = addShadowMesh(
scene,
new THREE.BoxGeometry(1.45, 0.018, 0.055),
markerMaterial,
new THREE.Vector3(supportStart.x, 0.089, supportStart.z + 0.66)
);
const columnDockStripe = addShadowMesh(
scene,
new THREE.BoxGeometry(0.92, 0.018, 0.055),
markerMaterial,
new THREE.Vector3(columnStart.x, 0.089, columnStart.z + 0.56)
);
// Teal support assembly.
const support = new THREE.Group();
scene.add(support);
addShadowMesh(
support,
chamferedBox(1.3, 0.14, 1.3, 0.035),
supportMaterial,
new THREE.Vector3(0, 0.07, 0)
);
const pedestal = addShadowMesh(
support,
new THREE.CylinderGeometry(0.39, 0.53, 0.3, 4, 1, false),
supportMaterial,
new THREE.Vector3(0, 0.29, 0)
);
pedestal.rotation.y = Math.PI / 4;
addShadowMesh(
support,
chamferedBox(0.61, 0.065, 0.61, 0.018),
socketMaterial,
new THREE.Vector3(0, 0.45, 0)
);
const boltGeometry = new THREE.CylinderGeometry(0.045, 0.045, 0.035, 16);
for (const x of [-0.49, 0.49]) {
for (const z of [-0.49, 0.49]) {
addShadowMesh(
support,
boltGeometry,
boltMaterial,
new THREE.Vector3(x, 0.153, z)
);
}
}
// Orange vertical member, staged separately.
const column = new THREE.Group();
scene.add(column);
addShadowMesh(
column,
chamferedBox(0.68, 0.14, 0.68, 0.035),
supportDarkMaterial,
new THREE.Vector3(0, 0.07, 0)
);
addShadowMesh(
column,
chamferedBox(0.54, 2.42, 0.54, 0.075),
columnMaterial,
new THREE.Vector3(0, 1.32, 0)
);
addShadowMesh(
column,
chamferedBox(0.66, 0.18, 0.66, 0.05),
columnCapMaterial,
new THREE.Vector3(0, 2.57, 0)
);
addShadowMesh(
column,
chamferedBox(0.38, 0.055, 0.38, 0.018),
supportDarkMaterial,
new THREE.Vector3(0, 2.69, 0)
);
// Dashed vertical alignment guide for the second step.
const alignmentGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(anchor.x, padTop + 0.07, anchor.z),
new THREE.Vector3(anchor.x, padTop + 3.1, anchor.z)
]);
const alignmentLine = new THREE.Line(
alignmentGeometry,
new THREE.LineDashedMaterial({
color: 0xf2bf49,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.55
})
);
alignmentLine.computeLineDistances();
alignmentLine.visible = false;
scene.add(alignmentLine);
support.position.copy(supportStart);
column.position.copy(columnStart);
// UI elements.
const step1 = document.getElementById("step1");
const step2 = document.getElementById("step2");
const step1Status = document.getElementById("step1Status");
const step2Status = document.getElementById("step2Status");
const instruction = document.getElementById("instruction");
const actionButton = document.getElementById("actionButton");
const actionText = document.getElementById("actionText");
const supportLabel = document.getElementById("supportLabel");
const columnLabel = document.getElementById("columnLabel");
const cameraHint = document.getElementById("cameraHint");
let phase = "ready";
let activeAnimation = null;
function setButton(label, disabled = false) {
actionText.textContent = label;
actionButton.disabled = disabled;
}
function updateGuide() {
step1.classList.remove("active", "done", "locked");
step2.classList.remove("active", "done", "locked");
if (phase === "ready") {
step1.classList.add("active");
step1Status.textContent = "Ready";
step2.classList.add("locked");
step2Status.textContent = "Locked";
instruction.textContent =
"Move the teal support onto the marked position before adding the column.";
setButton("Place support");
} else if (phase === "supportMoving") {
step1.classList.add("active");
step1Status.textContent = "Placing";
step2.classList.add("locked");
step2Status.textContent = "Locked";
instruction.textContent =
"The support is moving over the yellow marks and lowering into place.";
setButton("Placing support…", true);
} else if (phase === "supportPlaced") {
step1.classList.add("done");
step1Status.textContent = "Seated ✓";
step2.classList.add("active");
step2Status.textContent = "Ready";
instruction.textContent =
"Support seated. Now lower the orange column vertically onto the square socket.";
setButton("Place column");
} else if (phase === "columnMoving") {
step1.classList.add("done");
step1Status.textContent = "Seated ✓";
step2.classList.add("active");
step2Status.textContent = "Lowering";
instruction.textContent =
"Keeping the column vertical, lower it directly onto the seated support.";
setButton("Lowering column…", true);
} else {
step1.classList.add("done");
step1Status.textContent = "Seated ✓";
step2.classList.add("done");
step2Status.textContent = "Attached ✓";
instruction.textContent =
"Assembly complete: the support was seated first, then the vertical member was added.";
setButton("Replay assembly");
}
}
const easeInOutCubic = (t) =>
t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
function beginSupportAnimation() {
activeAnimation = {
type: "support",
start: performance.now(),
duration: 1650,
from: support.position.clone(),
to: supportEnd.clone(),
fromRotation: support.rotation.clone()
};
phase = "supportMoving";
updateGuide();
}
function beginColumnAnimation() {
activeAnimation = {
type: "column",
start: performance.now(),
duration: 1900,
from: column.position.clone(),
to: columnEnd.clone(),
fromRotation: column.rotation.clone()
};
phase = "columnMoving";
updateGuide();
}
function resetAssembly() {
support.position.copy(supportStart);
support.rotation.set(0, 0, 0);
column.position.copy(columnStart);
column.rotation.set(0, 0, 0);
activeAnimation = null;
alignmentLine.visible = false;
phase = "ready";
updateGuide();
}
actionButton.addEventListener("click", () => {
if (phase === "ready") {
beginSupportAnimation();
} else if (phase === "supportPlaced") {
beginColumnAnimation();
} else if (phase === "complete") {
resetAssembly();
window.setTimeout(beginSupportAnimation, 350);
}
});
// Custom camera controls, implemented directly without addons.
const cameraTarget = new THREE.Vector3(0.85, 0.85, 0);
const spherical = new THREE.Spherical(12.8, 1.05, 0.52);
let zoomMultiplier = 1;
let fitRadius = 12.8;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const radius = fitRadius * zoomMultiplier;
spherical.radius = radius;
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
cameraHint.style.opacity = "0.25";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.62,
1.36
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && 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();
zoomMultiplier = THREE.MathUtils.clamp(
zoomMultiplier * Math.exp(event.deltaY * 0.001),
0.72,
1.65
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") spherical.theta -= 0.08;
if (event.key === "ArrowRight") spherical.theta += 0.08;
if (event.key === "ArrowUp") {
spherical.phi = THREE.MathUtils.clamp(spherical.phi - 0.06, 0.62, 1.36);
}
if (event.key === "ArrowDown") {
spherical.phi = THREE.MathUtils.clamp(spherical.phi + 0.06, 0.62, 1.36);
}
if (event.key === "+" || event.key === "=") {
zoomMultiplier = THREE.MathUtils.clamp(zoomMultiplier * 0.9, 0.72, 1.65);
}
if (event.key === "-") {
zoomMultiplier = THREE.MathUtils.clamp(zoomMultiplier * 1.1, 0.72, 1.65);
}
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Preserve the entire assembly on narrow screens.
fitRadius = 12.8 * Math.max(1, 1.15 / aspect);
updateCamera();
}
window.addEventListener("resize", resize);
resize();
function updateAnimation(now) {
if (!activeAnimation) return;
const rawT = THREE.MathUtils.clamp(
(now - activeAnimation.start) / activeAnimation.duration,
0,
1
);
const t = easeInOutCubic(rawT);
const arc = Math.sin(Math.PI * rawT);
if (activeAnimation.type === "support") {
support.position.x = THREE.MathUtils.lerp(
activeAnimation.from.x,
activeAnimation.to.x,
t
);
support.position.z = THREE.MathUtils.lerp(
activeAnimation.from.z,
activeAnimation.to.z,
t
);
support.position.y =
THREE.MathUtils.lerp(activeAnimation.from.y, activeAnimation.to.y, t) +
arc * 1.05;
support.rotation.y = THREE.MathUtils.lerp(
activeAnimation.fromRotation.y,
0.08,
t
);
support.rotation.z = arc * 0.045;
} else {
column.position.x = THREE.MathUtils.lerp(
activeAnimation.from.x,
activeAnimation.to.x,
t
);
column.position.z = THREE.MathUtils.lerp(
activeAnimation.from.z,
activeAnimation.to.z,
t
);
column.position.y =
THREE.MathUtils.lerp(activeAnimation.from.y, activeAnimation.to.y, t) +
arc * 1.45;
column.rotation.z = arc * -0.075;
column.rotation.x = arc * 0.025;
}
if (rawT >= 1) {
if (activeAnimation.type === "support") {
support.position.copy(supportEnd);
support.rotation.set(0, 0.08, 0);
phase = "supportPlaced";
alignmentLine.visible = true;
updateGuide();
} else {
column.position.copy(columnEnd);
column.rotation.set(0, 0, 0);
phase = "complete";
alignmentLine.visible = false;
updateGuide();
}
activeAnimation = null;
}
}
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const labelPosition = new THREE.Vector3();
function animate(now) {
requestAnimationFrame(animate);
updateAnimation(now);
const pulse = 0.5 + 0.5 * Math.sin(now * 0.0032);
markerMaterial.opacity = phase === "supportMoving"
? 0.78 + pulse * 0.22
: 0.78 + pulse * 0.16;
markerMaterial.emissiveIntensity =
phase === "supportMoving" ? 0.2 + pulse * 0.25 : 0.1;
targetRing.material.opacity = 0.38 + pulse * 0.28;
targetRing.scale.setScalar(1 + pulse * 0.08);
supportMaterial.emissive.setHex(0x0b3440);
supportMaterial.emissiveIntensity =
phase === "supportMoving" ? 0.12 : 0.025;
columnMaterial.emissive.setHex(0x7b2812);
columnMaterial.emissiveIntensity =
phase === "columnMoving" ? 0.13 : 0.015;
if (phase === "columnMoving") {
alignmentLine.material.opacity = 0.35 + pulse * 0.35;
}
labelPosition.copy(support.position);
labelPosition.y += 0.57;
positionLabel(supportLabel, labelPosition);
labelPosition.copy(column.position);
labelPosition.y += 2.94;
positionLabel(columnLabel, labelPosition);
renderer.render(scene, camera);
}
updateGuide();
requestAnimationFrame(animate);
loading.remove();
</script>
</body>
</html>
```