Prompt specification
Build or customize the Three.js 3D scene "Three Stops and One Clamped Block" 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: Three Stops and One Clamped Block
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-stops-and-one-clamped-block-x2037
Scene Description Prompt:
Model a block against support pads and stops with a simple clamp. Show constrained directions and keep the intended tool-access region unobstructed. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (three-stops-and-one-clamped-block-x2037):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clamped Workblock — Fixture Study</title>
<style>
:root {
color-scheme: dark;
--bg: #071018;
--panel: rgba(11, 21, 30, 0.84);
--panel-border: rgba(163, 202, 220, 0.16);
--text: #e7f1f5;
--muted: #8fa6b4;
--clamp: #ffb547;
--stop: #ff6b57;
--reaction: #f5d76e;
--access: #57e1c2;
--blue: #7eb6df;
}
* {
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;
}
#scene,
#labels {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
overflow: hidden;
}
.panel {
position: fixed;
z-index: 10;
color: var(--text);
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 14px;
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 20px 22px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--blue);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 34px);
font-weight: 650;
letter-spacing: -0.04em;
line-height: 1.05;
}
.subtitle {
margin: 10px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.status-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.status-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
color: #bdd0da;
background: rgba(255, 255, 255, 0.035);
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 999px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.status-chip::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--access);
box-shadow: 0 0 10px rgba(87, 225, 194, 0.7);
content: "";
}
#controls {
top: 24px;
right: 24px;
display: flex;
gap: 5px;
padding: 6px;
pointer-events: auto;
}
#controls button {
min-width: 44px;
height: 34px;
padding: 0 10px;
color: var(--muted);
background: transparent;
border: 1px solid transparent;
border-radius: 8px;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
#controls button:hover {
color: var(--text);
background: rgba(255, 255, 255, 0.045);
}
#controls button.active {
color: #071018;
background: #c9e0e9;
border-color: #c9e0e9;
}
#constraint-panel {
bottom: 24px;
left: 24px;
width: 278px;
padding: 16px 17px;
pointer-events: none;
}
.panel-heading {
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.constraint-row {
display: grid;
grid-template-columns: 46px 1fr auto;
align-items: center;
min-height: 29px;
border-top: 1px solid rgba(255, 255, 255, 0.055);
font-size: 11px;
}
.constraint-row:first-of-type {
border-top: 0;
}
.axis {
font-size: 13px;
font-weight: 850;
}
.constraint-name {
color: #d4e1e7;
}
.constraint-source {
color: #718895;
font-size: 10px;
}
#access-panel {
right: 24px;
bottom: 24px;
width: 260px;
padding: 16px 17px;
pointer-events: none;
}
#access-panel .panel-heading {
color: var(--access);
}
.access-title {
margin-bottom: 5px;
font-size: 14px;
font-weight: 700;
}
.access-copy {
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.access-rule {
width: 100%;
height: 3px;
margin-top: 13px;
overflow: hidden;
background: rgba(87, 225, 194, 0.12);
border-radius: 3px;
}
.access-rule::after {
display: block;
width: 58%;
height: 100%;
background: var(--access);
box-shadow: 0 0 12px rgba(87, 225, 194, 0.55);
content: "";
}
#hint {
position: fixed;
z-index: 10;
right: 50%;
bottom: 25px;
padding: 7px 11px;
color: rgba(190, 210, 220, 0.64);
background: rgba(5, 12, 18, 0.62);
border-radius: 999px;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
transform: translateX(50%);
white-space: nowrap;
}
.scene-label {
position: absolute;
z-index: 6;
padding: 7px 9px;
color: var(--text);
background: rgba(8, 17, 24, 0.84);
border: 1px solid rgba(255, 255, 255, 0.11);
border-left: 3px solid currentColor;
border-radius: 7px;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
line-height: 1.35;
text-align: left;
text-transform: uppercase;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
white-space: nowrap;
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: currentColor;
content: "";
opacity: 0.55;
}
.scene-label small {
display: block;
margin-top: 2px;
color: #9aafba;
font-size: 8px;
font-weight: 650;
letter-spacing: 0.04em;
text-transform: none;
}
.label-clamp {
color: var(--clamp);
}
.label-stop {
color: var(--stop);
}
.label-reaction {
color: var(--reaction);
}
.label-access {
color: var(--access);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: var(--muted);
background: var(--bg);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
#title-panel {
top: 14px;
left: 14px;
width: 285px;
padding: 15px 17px;
}
.subtitle {
margin-bottom: 10px;
}
#controls {
top: 14px;
right: 14px;
}
#constraint-panel {
bottom: 14px;
left: 14px;
width: 240px;
}
#access-panel {
display: none;
}
#hint {
display: none;
}
}
@media (max-width: 560px) {
#title-panel {
width: calc(100vw - 28px);
}
#controls {
top: auto;
right: 14px;
bottom: 14px;
}
#constraint-panel {
display: none;
}
.scene-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<section id="title-panel" class="panel">
<div class="eyebrow">Mechanical fixture · Study 01</div>
<h1>Clamped Workblock</h1>
<p class="subtitle">
A rigid workpiece located by two support pads, two hard stops, and a
single side-mounted hold-down clamp.
</p>
<div class="status-row">
<span class="status-chip">X / Y / Z translations constrained</span>
<span class="status-chip">Tool envelope clear</span>
</div>
</section>
<nav id="controls" class="panel" aria-label="Camera views">
<button data-view="iso" class="active">ISO</button>
<button data-view="top">TOP</button>
<button data-view="front">FRONT</button>
<button data-view="reset">RESET</button>
</nav>
<section id="constraint-panel" class="panel">
<div class="panel-heading">Constrained directions</div>
<div class="constraint-row">
<span class="axis" style="color: var(--clamp)">−Y</span>
<span class="constraint-name">Clamp toe</span>
<span class="constraint-source">hold-down</span>
</div>
<div class="constraint-row">
<span class="axis" style="color: var(--stop)">+Z</span>
<span class="constraint-name">Rear stop</span>
<span class="constraint-source">location</span>
</div>
<div class="constraint-row">
<span class="axis" style="color: var(--stop)">−X</span>
<span class="constraint-name">Side stop</span>
<span class="constraint-source">location</span>
</div>
<div class="constraint-row">
<span class="axis" style="color: var(--reaction)">+Y</span>
<span class="constraint-name">Support pads</span>
<span class="constraint-source">reaction</span>
</div>
</section>
<section id="access-panel" class="panel">
<div class="panel-heading">Protected access envelope</div>
<div class="access-title">Top-right tool region</div>
<div class="access-copy">
The clamp toe and locating stops remain outside the marked working area,
leaving the intended tool path unobstructed.
</div>
<div class="access-rule"></div>
</section>
<div id="hint">Drag to orbit · Scroll to zoom · Shift-drag to pan</div>
<div id="loading">Building fixture…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const sceneHost = document.querySelector("#scene");
const labelHost = document.querySelector("#labels");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071018);
scene.fog = new THREE.Fog(0x071018, 16, 32);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xa7d2e8, 0x15202a, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d9, 3.1);
keyLight.position.set(-5, 10, 7);
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 = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6bbde2, 1.55);
rimLight.position.set(6, 4, -7);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffbd70, 18, 16, 2);
warmFill.position.set(-4, 4, 2);
scene.add(warmFill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.58,
metalness: options.metalness ?? 0.35,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
function bevelBoxGeometry(width, height, depth, bevel = 0.05) {
const b = Math.min(bevel, width / 4, height / 4, depth / 4);
const sw = width - 2 * b;
const sh = height - 2 * b;
const shape = new THREE.Shape();
shape.moveTo(-sw / 2, -sh / 2);
shape.lineTo(sw / 2, -sh / 2);
shape.lineTo(sw / 2, sh / 2);
shape.lineTo(-sw / 2, sh / 2);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: depth - 2 * b,
bevelEnabled: true,
bevelThickness: b,
bevelSize: b,
bevelSegments: 1,
steps: 1,
curveSegments: 1
});
geometry.center();
geometry.computeVertexNormals();
return geometry;
}
function addEdges(mesh, color = 0xb7cbd5, opacity = 0.2) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 28),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.renderOrder = 2;
mesh.add(edges);
return mesh;
}
function makeBox(
width,
height,
depth,
color,
position,
options = {}
) {
const material =
options.material ||
standardMaterial(color, {
roughness: options.roughness,
metalness: options.metalness,
emissive: options.emissive,
emissiveIntensity: options.emissiveIntensity
});
const mesh = new THREE.Mesh(
bevelBoxGeometry(width, height, depth, options.bevel ?? 0.04),
material
);
mesh.position.set(...position);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
if (options.edgeColor !== null) {
addEdges(mesh, options.edgeColor, options.edgeOpacity ?? 0.18);
}
scene.add(mesh);
return mesh;
}
function makeCylinder(
radius,
height,
color,
position,
radialSegments = 12,
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
height,
radialSegments,
1,
false
),
standardMaterial(color, {
roughness: options.roughness ?? 0.5,
metalness: options.metalness ?? 0.48
})
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function makeArrow(origin, direction, length, color) {
const group = new THREE.Group();
const headLength = Math.min(0.22, length * 0.3);
const shaftLength = length - headLength;
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.38,
roughness: 0.42,
metalness: 0.1,
flatShading: true
});
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.026, 0.026, shaftLength, 8),
material
);
shaft.position.y = shaftLength / 2;
shaft.castShadow = true;
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.095, headLength, 8),
material
);
head.position.y = shaftLength + headLength / 2;
head.castShadow = true;
group.add(head);
group.position.set(...origin);
group.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(...direction).normalize()
);
scene.add(group);
return group;
}
// -------------------------------------------------------------------------
// Ground, base, and fixture bed
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
standardMaterial(0x0b151e, {
roughness: 0.98,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.59;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x37505d, 0x20333d);
grid.position.y = -0.582;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
makeBox(
10,
0.5,
7,
0x17242d,
[0, -0.32, 0],
{
bevel: 0.12,
roughness: 0.72,
metalness: 0.4,
edgeColor: 0x6d8998,
edgeOpacity: 0.15
}
);
makeBox(
9.2,
0.14,
6.2,
0x243640,
[0, 0.02, 0],
{
bevel: 0.055,
roughness: 0.62,
metalness: 0.52,
edgeColor: 0x8aa8b7,
edgeOpacity: 0.17
}
);
// Recessed mounting holes and low-poly hex fasteners.
const boltPositions = [
[-4.1, -2.55],
[-4.1, 2.55],
[4.1, -2.55],
[4.1, 2.55]
];
for (const [x, z] of boltPositions) {
const hole = makeCylinder(0.16, 0.018, 0x071018, [x, 0.095, z], 16);
hole.receiveShadow = false;
const bolt = makeCylinder(0.105, 0.055, 0x8b9da6, [x, 0.125, z], 6);
bolt.receiveShadow = false;
}
// Subtle bed reference lines.
const bedLinePoints = [];
for (let x = -4; x <= 4; x += 0.5) {
bedLinePoints.push(
new THREE.Vector3(x, 0.097, -2.9),
new THREE.Vector3(x, 0.097, -2.78)
);
}
for (let z = -2.5; z <= 2.5; z += 0.5) {
bedLinePoints.push(
new THREE.Vector3(-4.3, 0.097, z),
new THREE.Vector3(-4.18, 0.097, z)
);
}
const bedLines = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(bedLinePoints),
new THREE.LineBasicMaterial({
color: 0x8ba3ae,
transparent: true,
opacity: 0.28
})
);
scene.add(bedLines);
// -------------------------------------------------------------------------
// Workpiece, support pads, and hard stops
// -------------------------------------------------------------------------
const padMaterial = standardMaterial(0xd6aa46, {
roughness: 0.58,
metalness: 0.28
});
makeBox(1.08, 0.26, 0.72, 0xd6aa46, [-0.66, 0.22, -0.82], {
material: padMaterial,
bevel: 0.035,
edgeColor: 0xffe29a,
edgeOpacity: 0.24
});
makeBox(1.08, 0.26, 0.78, 0xd6aa46, [0.78, 0.22, 0.83], {
material: padMaterial,
bevel: 0.035,
edgeColor: 0xffe29a,
edgeOpacity: 0.24
});
const stopMaterial = standardMaterial(0xd96545, {
roughness: 0.58,
metalness: 0.3
});
// Rear stop: its front face touches the rear face of the workpiece.
makeBox(3.9, 1.22, 0.46, 0xd96545, [0.2, 0.7, -1.43], {
material: stopMaterial,
bevel: 0.045,
edgeColor: 0xffb09a,
edgeOpacity: 0.22
});
// Short side stop leaves the front-right region open for tool access.
makeBox(0.45, 1.1, 0.95, 0xd96545, [2.075, 0.64, -0.62], {
material: stopMaterial,
bevel: 0.045,
edgeColor: 0xffb09a,
edgeOpacity: 0.22
});
// Main workpiece.
makeBox(3.3, 1.22, 2.4, 0x4c789d, [0.2, 0.96, 0], {
bevel: 0.07,
roughness: 0.48,
metalness: 0.46,
edgeColor: 0xb9d6e7,
edgeOpacity: 0.3
});
// Small front identification plate.
makeBox(0.78, 0.2, 0.025, 0x203746, [-0.68, 0.88, 1.208], {
bevel: 0.008,
roughness: 0.42,
metalness: 0.55,
edgeColor: 0x6f96ad,
edgeOpacity: 0.3
});
// -------------------------------------------------------------------------
// Side-mounted hold-down clamp
// -------------------------------------------------------------------------
makeBox(1.05, 0.28, 1.08, 0x455762, [-2.28, 0.23, -0.28], {
bevel: 0.045,
roughness: 0.5,
metalness: 0.58,
edgeColor: 0xa9bec8,
edgeOpacity: 0.22
});
makeCylinder(0.16, 1.56, 0x9aaab2, [-2.28, 1.07, -0.28], 12, {
roughness: 0.34,
metalness: 0.76
});
// Hex adjustment nut.
const clampNut = makeCylinder(
0.245,
0.15,
0x677a83,
[-2.28, 1.78, -0.28],
6,
{ roughness: 0.4, metalness: 0.7 }
);
clampNut.rotation.y = Math.PI / 6;
makeBox(1.55, 0.24, 0.56, 0xb5c3c9, [-1.73, 1.97, -0.28], {
bevel: 0.04,
roughness: 0.37,
metalness: 0.72,
edgeColor: 0xf0fbff,
edgeOpacity: 0.27
});
makeBox(0.44, 0.28, 0.68, 0xd0d9dc, [-1.33, 1.71, -0.28], {
bevel: 0.025,
roughness: 0.45,
metalness: 0.6,
edgeColor: 0xffffff,
edgeOpacity: 0.3
});
// -------------------------------------------------------------------------
// Clear tool-access region on the top-right of the workpiece
// -------------------------------------------------------------------------
const access = {
x0: -0.30,
x1: 1.50,
z0: -0.175,
z1: 1.075,
y: 1.581
};
const accessWidth = access.x1 - access.x0;
const accessDepth = access.z1 - access.z0;
const accessPlane = new THREE.Mesh(
new THREE.PlaneGeometry(accessWidth, accessDepth),
new THREE.MeshBasicMaterial({
color: 0x57e1c2,
transparent: true,
opacity: 0.13,
side: THREE.DoubleSide,
depthWrite: false
})
);
accessPlane.rotation.x = -Math.PI / 2;
accessPlane.position.set(
(access.x0 + access.x1) / 2,
access.y,
(access.z0 + access.z1) / 2
);
accessPlane.renderOrder = 4;
scene.add(accessPlane);
const accessBorder = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(access.x0, access.y + 0.006, access.z0),
new THREE.Vector3(access.x1, access.y + 0.006, access.z0),
new THREE.Vector3(access.x1, access.y + 0.006, access.z1),
new THREE.Vector3(access.x0, access.y + 0.006, access.z1),
new THREE.Vector3(access.x0, access.y + 0.006, access.z0)
]),
new THREE.LineDashedMaterial({
color: 0x57e1c2,
dashSize: 0.09,
gapSize: 0.055,
transparent: true,
opacity: 0.85
})
);
accessBorder.computeLineDistances();
accessBorder.renderOrder = 5;
scene.add(accessBorder);
// Corner brackets and short vertical guide posts.
const bracketPoints = [];
const bracketLength = 0.22;
function addCorner(x, z, sx, sz) {
bracketPoints.push(
new THREE.Vector3(x, access.y + 0.012, z),
new THREE.Vector3(
x + sx * bracketLength,
access.y + 0.012,
z
),
new THREE.Vector3(x, access.y + 0.012, z),
new THREE.Vector3(
x,
access.y + 0.012,
z + sz * bracketLength
)
);
}
addCorner(access.x0, access.z0, 1, 1);
addCorner(access.x1, access.z0, -1, 1);
addCorner(access.x1, access.z1, -1, -1);
addCorner(access.x0, access.z1, 1, -1);
const accessBrackets = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(bracketPoints),
new THREE.LineBasicMaterial({
color: 0x8fffe1,
transparent: true,
opacity: 0.95
})
);
accessBrackets.renderOrder = 6;
scene.add(accessBrackets);
const envelopeGuides = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(access.x0, access.y, access.z0),
new THREE.Vector3(access.x0, access.y + 0.18, access.z0),
new THREE.Vector3(access.x1, access.y, access.z0),
new THREE.Vector3(access.x1, access.y + 0.18, access.z0),
new THREE.Vector3(access.x1, access.y, access.z1),
new THREE.Vector3(access.x1, access.y + 0.18, access.z1),
new THREE.Vector3(access.x0, access.y, access.z1),
new THREE.Vector3(access.x0, access.y + 0.18, access.z1)
]),
new THREE.LineBasicMaterial({
color: 0x57e1c2,
transparent: true,
opacity: 0.28
})
);
scene.add(envelopeGuides);
// -------------------------------------------------------------------------
// Directional force arrows
// -------------------------------------------------------------------------
makeArrow([-1.33, 2.66, -0.28], [0, -1, 0], 0.88, 0xffb547);
makeArrow([0.2, 1.67, -2.38], [0, 0, 1], 0.9, 0xff6b57);
makeArrow([3.08, 0.92, -0.62], [-1, 0, 0], 0.92, 0xff6b57);
makeArrow([0.78, 0.02, 1.58], [0, 1, 0], 0.52, 0xf5d76e);
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labels = [];
function addSceneLabel(position, html, className) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.innerHTML = html;
labelHost.appendChild(element);
labels.push({
position: new THREE.Vector3(...position),
element
});
}
addSceneLabel(
[-1.33, 2.92, -0.28],
"Clamp force <small>−Y / hold-down</small>",
"label-clamp"
);
addSceneLabel(
[0.2, 1.92, -2.52],
"Rear stop <small>+Z / location</small>",
"label-stop"
);
addSceneLabel(
[3.2, 1.18, -0.62],
"Side stop <small>−X / location</small>",
"label-stop"
);
addSceneLabel(
[0.78, 0.56, 1.66],
"Pad reaction <small>+Y / support</small>",
"label-reaction"
);
addSceneLabel(
[0.62, 2.15, 0.46],
"Tool access <small>Top envelope / keep clear</small>",
"label-access"
);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, and shift-drag pan
// -------------------------------------------------------------------------
const view = {
theta: -0.68,
phi: 1.04,
radius: 11.7,
target: new THREE.Vector3(0.15, 0.68, 0)
};
const desiredView = {
theta: view.theta,
phi: view.phi,
radius: view.radius,
target: view.target.clone()
};
const presets = {
iso: {
theta: -0.68,
phi: 1.04,
radius: 11.7,
target: new THREE.Vector3(0.15, 0.68, 0)
},
top: {
theta: 0,
phi: 0.16,
radius: 10.6,
target: new THREE.Vector3(0.15, 0.55, 0)
},
front: {
theta: 0,
phi: 1.3,
radius: 10.7,
target: new THREE.Vector3(0.15, 0.74, 0)
},
reset: {
theta: -0.68,
phi: 1.04,
radius: 11.7,
target: new THREE.Vector3(0.15, 0.68, 0)
}
};
function selectView(name) {
const preset = presets[name];
desiredView.theta = preset.theta;
desiredView.phi = preset.phi;
desiredView.radius = preset.radius;
desiredView.target.copy(preset.target);
document.querySelectorAll("#controls button").forEach((button) => {
button.classList.toggle(
"active",
button.dataset.view === name || (name === "reset" && button.dataset.view === "iso")
);
});
}
document.querySelectorAll("#controls button").forEach((button) => {
button.addEventListener("click", () => selectView(button.dataset.view));
});
const pointer = {
active: false,
id: null,
x: 0,
y: 0,
panning: false
};
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.panning = event.shiftKey || event.button === 2;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointer.panning) {
camera.updateMatrixWorld();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
const panScale = view.radius * 0.00135;
view.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desiredView.target.copy(view.target);
} else {
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - dy * 0.006,
0.12,
1.46
);
desiredView.theta = view.theta;
desiredView.phi = view.phi;
}
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
pointer.panning = false;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = Math.exp(event.deltaY * 0.001);
view.radius = THREE.MathUtils.clamp(
view.radius * factor,
6.5,
18
);
desiredView.radius = view.radius;
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Rendering
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.opacity = visible ? "1" : "0";
if (!visible) 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`;
}
}
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
camera.updateMatrixWorld();
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function animate() {
requestAnimationFrame(animate);
const damping = 0.09;
view.theta += (desiredView.theta - view.theta) * damping;
view.phi += (desiredView.phi - view.phi) * damping;
view.radius += (desiredView.radius - view.radius) * damping;
view.target.lerp(desiredView.target, damping);
// Subtle access-zone breathing keeps the protected region legible.
accessPlane.material.opacity = 0.105 + Math.sin(performance.now() * 0.0018) * 0.025;
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```