Prompt specification
Build or customize the Three.js 3D scene "Container Spreader Above Four Corner Points" 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: Container Spreader Above Four Corner Points
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/container-spreader-above-four-corner-points-x2121
Scene Description Prompt:
Model a container and crane spreader with matching corner positions. Show alignment and lifting attachment geometry without claiming actual lifting-equipment specifications. Use Three.js from cdnjs in a single HTML file, with a 3D cutaway.
Working Three.js Starter (container-spreader-above-four-corner-points-x2121):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Container and Spreader Alignment Study</title>
<style>
:root {
color-scheme: light;
--panel: rgba(248, 251, 253, 0.94);
--line: rgba(25, 53, 68, 0.14);
--text: #173241;
--muted: #58707d;
--cyan: #078da8;
--amber: #e27712;
--orange: #f06428;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce7ed;
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(26, 54, 70, 0.13);
backdrop-filter: blur(14px);
}
#information {
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 18px;
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 21px;
line-height: 1.2;
letter-spacing: -0.025em;
}
.subtitle {
margin: 7px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.status-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 13px;
}
.status {
padding: 10px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.68);
}
.status span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.status strong {
font-size: 13px;
}
.status strong.good {
color: #087f69;
}
.notice {
padding: 11px 12px;
border-left: 3px solid var(--orange);
border-radius: 6px;
background: rgba(240, 100, 40, 0.08);
color: #6a402d;
font-size: 11px;
line-height: 1.5;
}
.notice strong {
color: #773714;
}
#toolbar {
top: 18px;
right: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(490px, calc(100vw - 36px));
padding: 9px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 8px;
padding: 9px 11px;
background: rgba(255, 255, 255, 0.82);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease;
}
button:hover {
border-color: rgba(7, 141, 168, 0.45);
background: white;
}
button.active {
border-color: rgba(7, 141, 168, 0.48);
background: rgba(7, 141, 168, 0.1);
color: #056e83;
}
button:focus-visible {
outline: 2px solid rgba(7, 141, 168, 0.55);
outline-offset: 2px;
}
#legend {
bottom: 18px;
left: 18px;
max-width: min(460px, calc(100vw - 36px));
padding: 12px 14px;
font-size: 11px;
line-height: 1.55;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 9px 17px;
align-items: center;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.swatch {
display: inline-block;
width: 19px;
height: 3px;
border-radius: 4px;
background: var(--cyan);
}
.swatch.amber {
background: var(--amber);
}
.swatch.dashed {
height: 0;
border-top: 2px dashed #77909e;
background: transparent;
}
.help {
margin-top: 7px;
color: var(--muted);
}
#world-labels {
position: fixed;
inset: 0;
z-index: 5;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
left: 0;
top: 0;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.65);
border-radius: 999px;
background: rgba(20, 45, 58, 0.84);
color: white;
box-shadow: 0 4px 14px rgba(18, 43, 56, 0.18);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.025em;
white-space: nowrap;
opacity: 0;
transition: opacity 100ms linear;
}
.world-label.cyan {
border-color: rgba(77, 227, 255, 0.75);
background: rgba(4, 93, 113, 0.9);
}
.world-label.amber {
border-color: rgba(255, 190, 105, 0.8);
background: rgba(119, 66, 13, 0.9);
}
.world-label.orange {
border-color: rgba(255, 165, 120, 0.8);
background: rgba(112, 46, 17, 0.9);
}
@media (max-width: 720px) {
#information {
width: calc(100vw - 36px);
max-width: 350px;
padding: 14px;
}
h1 {
font-size: 18px;
}
#toolbar {
top: auto;
right: 18px;
bottom: 102px;
max-width: calc(100vw - 36px);
}
#legend {
right: 18px;
max-width: none;
}
.status-grid {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<div id="app"></div>
<section id="information" class="panel" aria-label="Model information">
<p class="eyebrow">Illustrative geometry</p>
<h1>Container ↕ Spreader Alignment</h1>
<p class="subtitle">
Shared corner coordinates with an open container cutaway and a conceptual
bridle attachment arrangement.
</p>
<div class="status-grid">
<div class="status">
<span>Corner coordinate match</span>
<strong id="match-status" class="good">4 / 4 coincident</strong>
</div>
<div class="status">
<span>Presentation</span>
<strong>3D cutaway</strong>
</div>
</div>
<div class="notice">
<strong>Visualization only.</strong>
Corner matching is a coordinate relationship in this model. This is not a
certified lifting arrangement, capacity or SWL statement, rigging
specification, site plan, or operating procedure.
</div>
</section>
<nav id="toolbar" class="panel" aria-label="Display controls">
<button id="toggle-alignment" class="active" aria-pressed="true">
Corner guides
</button>
<button id="toggle-attachment" class="active" aria-pressed="true">
Attachment geometry
</button>
<button id="toggle-ghost" aria-pressed="false">
Removed envelope
</button>
<button id="reset-view">Reset view</button>
</nav>
<div id="world-labels" aria-hidden="true">
<div id="label-alignment" class="world-label cyan">Shared corner axis</div>
<div id="label-spreader" class="world-label amber">Spreader frame</div>
<div id="label-attachment" class="world-label amber">Conceptual bridle geometry</div>
<div id="label-cutaway" class="world-label orange">Container cutaway</div>
</div>
<section id="legend" class="panel" aria-label="Legend and controls">
<div class="legend-row">
<span class="legend-item">
<i class="swatch"></i>
Shared vertical corner axis
</span>
<span class="legend-item">
<i class="swatch amber"></i>
Conceptual attachment geometry
</span>
<span class="legend-item">
<i class="swatch dashed"></i>
Optional removed enclosure
</span>
</div>
<div class="help">
Drag to orbit · Wheel to zoom · Shift/right-drag to pan ·
Double-click to reset · Arrow keys orbit · +/− zoom
</div>
</section>
<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 app = document.getElementById("app");
const renderer = new THREE.WebGLRenderer({
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;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce7ed);
scene.fog = new THREE.Fog(0xdce7ed, 16, 35);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
100
);
const hemisphere = new THREE.HemisphereLight(
0xf8fcff,
0x506372,
2.25
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.3);
keyLight.position.set(7, 12, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9e6ff, 1.25);
fillLight.position.set(-7, 5, -6);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xcbd8de,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(28, 56, 0x8298a3, 0x9fb1ba);
grid.position.y = -0.02;
grid.material.transparent = true;
grid.material.opacity = 0.28;
grid.material.depthWrite = false;
scene.add(grid);
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinderBetween(
parent,
start,
end,
radius,
material,
radialSegments = 14
) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
length,
radialSegments
),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeMaterial(color, roughness = 0.65, metalness = 0.08) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
const material = {
container: makeMaterial(0x337a91, 0.66, 0.12),
containerRib: makeMaterial(0x286a81, 0.64, 0.13),
frame: makeMaterial(0x1c4c5c, 0.61, 0.18),
floor: makeMaterial(0x8d7a63, 0.86, 0.03),
cut: makeMaterial(0xff8a45, 0.53, 0.08),
corner: makeMaterial(0x25343b, 0.48, 0.42),
opening: makeMaterial(0x091216, 0.82, 0.05),
spreader: makeMaterial(0xf1a52b, 0.49, 0.18),
spreaderDark: makeMaterial(0xa9620e, 0.56, 0.24),
pin: makeMaterial(0xbfefff, 0.3, 0.66),
rope: makeMaterial(0x344750, 0.76, 0.2),
ring: makeMaterial(0xe9edf0, 0.31, 0.7)
};
// ---------------------------------------------------------------------
// Shared corner definitions
//
// These are illustrative model coordinates, not certified equipment
// dimensions. The same values drive both container and spreader geometry.
// ---------------------------------------------------------------------
const containerLength = 6.4;
const containerWidth = 2.6;
const containerHeight = 2.65;
const cornerInset = 0.16;
const lowerCutHeight = 0.78;
const cornerX = containerLength / 2 - cornerInset;
const cornerZ = containerWidth / 2 - cornerInset;
const spreaderY = containerHeight + 1.25;
const cornerCenters = [];
for (const xSign of [-1, 1]) {
for (const zSign of [-1, 1]) {
cornerCenters.push(
new THREE.Vector3(
xSign * cornerX,
containerHeight,
zSign * cornerZ
)
);
}
}
// ---------------------------------------------------------------------
// Container cutaway
// ---------------------------------------------------------------------
const containerGroup = new THREE.Group();
containerGroup.name = "Container cutaway";
scene.add(containerGroup);
// Base and interior floor.
addBox(
containerGroup,
[containerLength, 0.16, containerWidth],
[0, 0.08, 0],
material.frame
);
addBox(
containerGroup,
[containerLength - 0.18, 0.025, containerWidth - 0.18],
[0, 0.173, 0],
material.floor,
false
);
// Far side remains full height.
addBox(
containerGroup,
[
containerLength - 0.16,
containerHeight - 0.16,
0.08
],
[0, (containerHeight + 0.16) / 2, -containerWidth / 2 + 0.04],
material.container
);
// Near side is cut down to expose the interior.
addBox(
containerGroup,
[
containerLength - 0.16,
lowerCutHeight - 0.16,
0.08
],
[0, (lowerCutHeight + 0.16) / 2, containerWidth / 2 - 0.04],
material.container
);
// Rear end remains full height.
addBox(
containerGroup,
[
0.08,
containerHeight - 0.16,
containerWidth - 0.16
],
[-containerLength / 2 + 0.04, (containerHeight + 0.16) / 2, 0],
material.container
);
// Front end is also cut down.
addBox(
containerGroup,
[
0.08,
lowerCutHeight - 0.16,
containerWidth - 0.16
],
[containerLength / 2 - 0.04, (lowerCutHeight + 0.16) / 2, 0],
material.container
);
// Corrugations on the intact panels.
for (
let x = -containerLength / 2 + 0.26;
x < containerLength / 2 - 0.15;
x += 0.28
) {
addBox(
containerGroup,
[0.045, containerHeight - 0.38, 0.055],
[x, (containerHeight + 0.16) / 2, -containerWidth / 2 - 0.025],
material.containerRib
);
addBox(
containerGroup,
[0.045, lowerCutHeight - 0.28, 0.055],
[x, (lowerCutHeight + 0.16) / 2, containerWidth / 2 + 0.025],
material.containerRib
);
}
for (
let z = -containerWidth / 2 + 0.22;
z < containerWidth / 2 - 0.14;
z += 0.26
) {
addBox(
containerGroup,
[0.055, containerHeight - 0.38, 0.045],
[-containerLength / 2 - 0.025, (containerHeight + 0.16) / 2, z],
material.containerRib
);
addBox(
containerGroup,
[0.055, lowerCutHeight - 0.28, 0.045],
[containerLength / 2 + 0.025, (lowerCutHeight + 0.16) / 2, z],
material.containerRib
);
}
// Structural corner posts.
for (const xSign of [-1, 1]) {
for (const zSign of [-1, 1]) {
addBox(
containerGroup,
[0.14, containerHeight, 0.14],
[
xSign * containerLength / 2,
containerHeight / 2,
zSign * containerWidth / 2
],
material.frame
);
}
}
// Bottom rails.
for (const zSign of [-1, 1]) {
addBox(
containerGroup,
[containerLength, 0.13, 0.13],
[0, 0.23, zSign * containerWidth / 2],
material.frame
);
}
for (const xSign of [-1, 1]) {
addBox(
containerGroup,
[0.13, 0.13, containerWidth],
[xSign * containerLength / 2, 0.23, 0],
material.frame
);
}
// Intact upper rails. The near and front upper rails are omitted.
addBox(
containerGroup,
[containerLength, 0.14, 0.13],
[0, containerHeight - 0.07, -containerWidth / 2 + 0.065],
material.frame
);
addBox(
containerGroup,
[0.13, 0.14, containerWidth],
[-containerLength / 2 + 0.065, containerHeight - 0.07, 0],
material.frame
);
// Orange edges make the section cut explicit.
addBox(
containerGroup,
[containerLength, 0.045, 0.055],
[0, lowerCutHeight, containerWidth / 2 - 0.04],
material.cut,
false
);
addBox(
containerGroup,
[0.055, 0.045, containerWidth],
[containerLength / 2 - 0.04, lowerCutHeight, 0],
material.cut,
false
);
// Shared corner blocks and visible openings.
for (const corner of cornerCenters) {
addBox(
containerGroup,
[0.25, 0.22, 0.25],
[corner.x, containerHeight - 0.11, corner.z],
material.corner
);
const opening = new THREE.Mesh(
new THREE.CircleGeometry(0.065, 24),
material.opening
);
opening.rotation.x = -Math.PI / 2;
opening.position.set(
corner.x,
containerHeight + 0.008,
corner.z
);
containerGroup.add(opening);
}
// ---------------------------------------------------------------------
// Spreader frame and visible vertical pin geometry
// ---------------------------------------------------------------------
const spreaderGroup = new THREE.Group();
spreaderGroup.name = "Spreader";
scene.add(spreaderGroup);
// Long perimeter beams.
for (const zSign of [-1, 1]) {
addBox(
spreaderGroup,
[cornerX * 2, 0.19, 0.21],
[0, spreaderY, zSign * cornerZ],
material.spreader
);
}
// End beams.
for (const xSign of [-1, 1]) {
addBox(
spreaderGroup,
[0.21, 0.19, cornerZ * 2],
[xSign * cornerX, spreaderY, 0],
material.spreader
);
}
// Open corner housings expose the vertical pin geometry.
for (const corner of cornerCenters) {
addBox(
spreaderGroup,
[0.42, 0.065, 0.42],
[corner.x, spreaderY + 0.17, corner.z],
material.spreaderDark
);
addBox(
spreaderGroup,
[0.055, 0.32, 0.42],
[corner.x - 0.18, spreaderY + 0.015, corner.z],
material.spreaderDark
);
addBox(
spreaderGroup,
[0.055, 0.32, 0.42],
[corner.x + 0.18, spreaderY + 0.015, corner.z],
material.spreaderDark
);
addBox(
spreaderGroup,
[0.42, 0.32, 0.055],
[corner.x, spreaderY + 0.015, corner.z - 0.18],
material.spreaderDark
);
addBox(
spreaderGroup,
[0.42, 0.32, 0.055],
[corner.x, spreaderY + 0.015, corner.z + 0.18],
material.spreaderDark
);
// The pin and container opening share the same X/Z center.
addCylinderBetween(
spreaderGroup,
[corner.x, containerHeight + 0.035, corner.z],
[corner.x, spreaderY + 0.16, corner.z],
0.038,
material.pin,
18
);
// Tapered lower end of the pin.
const pinTip = new THREE.Mesh(
new THREE.ConeGeometry(0.057, 0.13, 18),
material.pin
);
pinTip.rotation.z = Math.PI;
pinTip.position.set(
corner.x,
containerHeight + 0.085,
corner.z
);
pinTip.castShadow = true;
spreaderGroup.add(pinTip);
}
// ---------------------------------------------------------------------
// Alignment guide group
// ---------------------------------------------------------------------
const alignmentGroup = new THREE.Group();
alignmentGroup.name = "Shared corner axes";
scene.add(alignmentGroup);
for (const corner of cornerCenters) {
const points = [
new THREE.Vector3(
corner.x,
containerHeight + 0.025,
corner.z
),
new THREE.Vector3(
corner.x,
spreaderY + 0.18,
corner.z
)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: 0x32d7f3,
dashSize: 0.09,
gapSize: 0.055,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
line.computeLineDistances();
line.renderOrder = 20;
alignmentGroup.add(line);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.014, 8, 32),
material.pin
);
halo.rotation.x = Math.PI / 2;
halo.position.set(
corner.x,
containerHeight + 0.025,
corner.z
);
halo.renderOrder = 21;
alignmentGroup.add(halo);
}
// ---------------------------------------------------------------------
// Conceptual bridle / lifting attachment geometry
// ---------------------------------------------------------------------
const attachmentGroup = new THREE.Group();
attachmentGroup.name = "Conceptual attachment geometry";
scene.add(attachmentGroup);
const bridleTopY = containerHeight + 3.85;
const masterRing = new THREE.Mesh(
new THREE.TorusGeometry(0.18, 0.045, 12, 36),
material.ring
);
masterRing.position.set(0, bridleTopY, 0);
masterRing.rotation.y = Math.PI / 2;
masterRing.castShadow = true;
attachmentGroup.add(masterRing);
for (const corner of cornerCenters) {
const cornerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.095, 0.022, 10, 30),
material.ring
);
cornerRing.position.set(
corner.x,
spreaderY + 0.34,
corner.z
);
cornerRing.rotation.y = Math.PI / 2;
cornerRing.castShadow = true;
attachmentGroup.add(cornerRing);
addCylinderBetween(
attachmentGroup,
[0, bridleTopY - 0.11, 0],
[corner.x, spreaderY + 0.34, corner.z],
0.024,
material.rope,
12
);
const connection = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 16, 12),
material.ring
);
connection.position.set(
corner.x,
spreaderY + 0.34,
corner.z
);
connection.castShadow = true;
attachmentGroup.add(connection);
}
// ---------------------------------------------------------------------
// Optional dashed outline of the omitted enclosure
// ---------------------------------------------------------------------
const ghostGroup = new THREE.Group();
ghostGroup.name = "Removed enclosure outline";
ghostGroup.visible = false;
scene.add(ghostGroup);
const enclosureEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(
containerLength,
containerHeight,
containerWidth
)
),
new THREE.LineDashedMaterial({
color: 0x6d8795,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.6,
depthWrite: false
})
);
enclosureEdges.position.y = containerHeight / 2;
enclosureEdges.computeLineDistances();
ghostGroup.add(enclosureEdges);
const roofGhost = new THREE.Mesh(
new THREE.PlaneGeometry(containerLength, containerWidth),
new THREE.MeshBasicMaterial({
color: 0x7c9aa8,
transparent: true,
opacity: 0.055,
side: THREE.DoubleSide,
depthWrite: false
})
);
roofGhost.rotation.x = Math.PI / 2;
roofGhost.position.y = containerHeight + 0.02;
ghostGroup.add(roofGhost);
// ---------------------------------------------------------------------
// Coordinate-match status
// ---------------------------------------------------------------------
const allAxesMatch = cornerCenters.every((corner) => {
const containerAxis = new THREE.Vector3(
corner.x,
containerHeight,
corner.z
);
const spreaderAxis = new THREE.Vector3(
corner.x,
spreaderY,
corner.z
);
return (
containerAxis.x === spreaderAxis.x &&
containerAxis.z === spreaderAxis.z
);
});
document.getElementById("match-status").textContent =
allAxesMatch ? "4 / 4 coincident" : "Review coordinates";
// ---------------------------------------------------------------------
// UI toggles
// ---------------------------------------------------------------------
function bindToggle(buttonId, object) {
const button = document.getElementById(buttonId);
button.addEventListener("click", () => {
object.visible = !object.visible;
button.classList.toggle("active", object.visible);
button.setAttribute("aria-pressed", String(object.visible));
});
}
bindToggle("toggle-alignment", alignmentGroup);
bindToggle("toggle-attachment", attachmentGroup);
bindToggle("toggle-ghost", ghostGroup);
// ---------------------------------------------------------------------
// Direct camera controls: orbit, zoom and pan
// ---------------------------------------------------------------------
const controls = {
yaw: 0.76,
pitch: 0.49,
distance: 13.6,
target: new THREE.Vector3(0, 2.65, 0),
dragging: false,
pan: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const sinPitch = Math.sin(controls.pitch);
const cosPitch = Math.cos(controls.pitch);
camera.position.set(
controls.target.x +
controls.distance * sinPitch * Math.sin(controls.yaw),
controls.target.y + controls.distance * cosPitch,
controls.target.z +
controls.distance * sinPitch * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resetCamera() {
controls.yaw = 0.76;
controls.pitch = 0.49;
controls.distance = 13.6;
controls.target.set(0, 2.65, 0);
updateCamera();
}
document.getElementById("reset-view").addEventListener("click", resetCamera);
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pan = event.button === 2 || event.shiftKey;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
if (controls.pan) {
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
const scale = controls.distance * 0.0014;
controls.target.addScaledVector(right, -dx * scale);
controls.target.addScaledVector(up, dy * scale);
controls.target.x = THREE.MathUtils.clamp(
controls.target.x,
-3.5,
3.5
);
controls.target.y = THREE.MathUtils.clamp(
controls.target.y,
0.8,
4.7
);
controls.target.z = THREE.MathUtils.clamp(
controls.target.z,
-2.5,
2.5
);
} else {
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.005,
0.12,
1.45
);
}
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.009,
6.5,
23
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.yaw += 0.08;
break;
case "ArrowRight":
controls.yaw -= 0.08;
break;
case "ArrowUp":
controls.pitch = THREE.MathUtils.clamp(
controls.pitch - 0.06,
0.12,
1.45
);
break;
case "ArrowDown":
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + 0.06,
0.12,
1.45
);
break;
case "+":
case "=":
controls.distance = Math.max(6.5, controls.distance - 0.7);
break;
case "-":
case "_":
controls.distance = Math.min(23, controls.distance + 0.7);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labels = [
{
element: document.getElementById("label-alignment"),
position: new THREE.Vector3(
cornerX,
containerHeight + 0.58,
cornerZ
)
},
{
element: document.getElementById("label-spreader"),
position: new THREE.Vector3(
-1.45,
spreaderY + 0.58,
cornerZ
)
},
{
element: document.getElementById("label-attachment"),
position: new THREE.Vector3(
0,
bridleTopY + 0.36,
0
)
},
{
element: document.getElementById("label-cutaway"),
position: new THREE.Vector3(
-0.7,
lowerCutHeight + 0.32,
containerWidth / 2 + 0.12
)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
const projected = label.position.clone().project(camera);
const inFront =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
if (!inFront) {
label.element.style.opacity = "0";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.transform =
"translate(-50%, -50%) translateY(-10px)";
label.element.style.opacity = "1";
}
}
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
function animate() {
requestAnimationFrame(animate);
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```