Prompt specification
Build or customize the Three.js 3D scene "Template-guided repetition workshop" 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: Template-guided repetition workshop
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/template-guided-repetition-workshop-x0292
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly workshop for repeated panel assemblies. On a fixture table, place several blank panels, locating stops, clamps, and a reusable hole template with a visibly asymmetric pattern. Let users align the template against the stops before marking each panel, then move the completed examples into a row for comparison. The resulting hole positions should come from the template's actual placement rather than a separate decorative pattern. Include an intentionally shifted placement that produces a visible mismatch, and allow it to be corrected before assembly. Keep the completed panels' joint locations easy to compare from above. Give the template an obvious orientation notch, making a reversed placement distinguishable from a correctly oriented template that has merely shifted sideways.
Working Three.js Starter (template-guided-repetition-workshop-x0292):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Template Workshop</title>
<style>
:root {
--ink: #edf4f1;
--muted: #aebbb7;
--panel: rgba(19, 27, 29, 0.94);
--line: rgba(255, 255, 255, 0.12);
--orange: #ffad42;
--teal: #4bd2b2;
--red: #ff705d;
--blue: #73aee8;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd5d5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
#panel {
position: fixed;
z-index: 5;
top: 14px;
left: 14px;
width: 350px;
max-height: calc(100vh - 28px);
overflow: auto;
padding: 19px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(13, 24, 27, 0.28);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #5f716c transparent;
}
.eyebrow {
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 7px;
font-size: 27px;
line-height: 1.04;
letter-spacing: -0.045em;
}
.intro {
margin: 0 0 15px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status {
display: grid;
gap: 7px;
padding: 12px;
margin-bottom: 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.035);
font-size: 12px;
}
.status-row {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: baseline;
}
.status-row span:first-child { color: var(--muted); }
.status-row b { text-align: right; }
.good { color: var(--teal) !important; }
.bad { color: var(--red) !important; }
.neutral { color: var(--blue) !important; }
.section-label {
margin: 15px 0 7px;
color: #c7d0cd;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
button {
min-height: 36px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.065);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}
button:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.12);
transform: translateY(-1px);
}
button:active:not(:disabled) { transform: translateY(0); }
button.primary {
color: #24170c;
border-color: transparent;
background: var(--orange);
}
button.teal {
color: #09251e;
border-color: transparent;
background: var(--teal);
}
button:disabled {
cursor: not-allowed;
opacity: 0.32;
}
.note {
margin: 11px 0 0;
padding: 10px;
border-left: 2px solid var(--orange);
background: rgba(255, 173, 66, 0.07);
color: #d5dcd9;
font-size: 10px;
line-height: 1.48;
}
#selectedInfo {
min-height: 30px;
margin-top: 10px;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
#viewbar {
position: fixed;
z-index: 6;
top: 14px;
right: 14px;
display: flex;
gap: 7px;
padding: 7px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(19, 27, 29, 0.86);
backdrop-filter: blur(10px);
}
#viewbar button {
min-height: 32px;
background: rgba(255, 255, 255, 0.055);
}
#hint {
position: fixed;
z-index: 4;
right: 15px;
bottom: 14px;
max-width: 430px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(19, 27, 29, 0.78);
color: #d9e0dd;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(8px);
}
#toast {
position: fixed;
z-index: 10;
left: 50%;
bottom: 26px;
max-width: min(540px, calc(100vw - 40px));
padding: 11px 16px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 11px;
background: rgba(14, 20, 22, 0.94);
color: white;
font-size: 12px;
font-weight: 650;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
opacity: 0;
transform: translate(-50%, 12px);
transition: opacity 180ms ease, transform 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 700px) {
#panel {
width: min(315px, calc(100vw - 28px));
padding: 15px;
}
h1 { font-size: 23px; }
#hint { display: none; }
#viewbar { top: auto; bottom: 12px; right: 12px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly workshop"></canvas>
<aside id="panel">
<div class="eyebrow">Repeat Assembly / Fixture 04</div>
<h1>Template-to-joint workshop</h1>
<p class="intro">
Position the reusable template against the fixed stops, mark the blank,
then inspect the completed panel in the comparison row.
</p>
<div class="status">
<div class="status-row">
<span>Placement</span>
<b id="placementStatus">—</b>
</div>
<div class="status-row">
<span>Notch orientation</span>
<b id="orientationStatus">—</b>
</div>
<div class="status-row">
<span>Current work</span>
<b id="currentStatus">—</b>
</div>
</div>
<div class="section-label">Template experiments</div>
<div class="buttons">
<button id="shiftButton">Shift sideways</button>
<button id="flipButton">Reverse 180°</button>
<button id="alignButton">Align to stops</button>
<button id="topButton">Top view</button>
</div>
<div class="section-label">Panel workflow</div>
<div class="buttons">
<button id="markButton" class="primary">Mark panel</button>
<button id="sendButton">Send to comparison</button>
<button id="correctButton">Return & correct</button>
<button id="assembleButton" class="teal">Assemble selected</button>
<button id="newButton">New blank panel</button>
<button id="resetViewButton">Reset camera</button>
</div>
<div id="selectedInfo">No comparison panel selected.</div>
<p class="note">
The triangular notch must face the back-left stops. A sideways shift and a
reversed template are reported separately. Panel holes are sampled from
the template hole anchors after its actual position and rotation.
</p>
</aside>
<div id="viewbar">
<button id="isoButton">Isometric</button>
<button id="overheadButton">Straight above</button>
</div>
<div id="hint">
Drag the orange template to place it · drag the background to orbit ·
shift/right-drag to pan · wheel to zoom · click a comparison panel to select it
</div>
<div id="toast" role="status" aria-live="polite"></div>
<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 canvas = document.querySelector("#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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd6d6);
scene.fog = new THREE.Fog(0xcbd6d6, 19, 35);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemi = new THREE.HemisphereLight(0xe9f5ff, 0x716b59, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0d6, 3.3);
sun.position.set(-6, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cc7e0, 1.1);
fill.position.set(8, 6, -7);
scene.add(fill);
// -------------------------------------------------------------------------
// Constants and shared objects
// -------------------------------------------------------------------------
const TABLE_TOP = 1.28;
const PANEL_W = 2.65;
const PANEL_D = 1.65;
const PANEL_T = 0.12;
const TEMPLATE_W = 2.20;
const TEMPLATE_D = 1.15;
const FIXTURE = new THREE.Vector3(-2.90, TABLE_TOP + PANEL_T / 2, 1.20);
const COMPARE_SLOTS = [
new THREE.Vector3(1.10, TABLE_TOP + PANEL_T / 2, 1.20),
new THREE.Vector3(4.00, TABLE_TOP + PANEL_T / 2, 1.20),
new THREE.Vector3(6.90, TABLE_TOP + PANEL_T / 2, 1.20),
new THREE.Vector3(9.80, TABLE_TOP + PANEL_T / 2, 1.20)
];
// This same asymmetric pattern is cut into the physical template.
// Panel marks are never generated from a second decorative pattern.
const PATTERN = [
{ x: -0.76, z: -0.27 },
{ x: -0.58, z: 0.31 },
{ x: -0.16, z: -0.42 },
{ x: 0.12, z: 0.29 },
{ x: 0.39, z: -0.12 },
{ x: 0.69, z: 0.39 },
{ x: 0.86, z: -0.35 }
];
const colors = {
wood: 0xc9965e,
woodLight: 0xe0bb82,
woodDark: 0x755039,
orange: 0xff9f32,
teal: 0x32c7a4,
red: 0xf06450,
blue: 0x4f83ae,
dark: 0x253236,
metal: 0x718184,
wall: 0xaab8b7,
floor: 0x778786
};
const mat = (color, extra = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...extra
});
const materials = {
floor: mat(colors.floor),
wall: mat(colors.wall),
table: mat(0x435357),
tableEdge: mat(0x27363a),
wood: mat(colors.wood),
woodLight: mat(colors.woodLight),
woodDark: mat(colors.woodDark),
orange: mat(colors.orange),
teal: mat(colors.teal),
red: mat(colors.red),
blue: mat(colors.blue),
dark: mat(colors.dark),
metal: mat(colors.metal, { metalness: 0.62, roughness: 0.42 }),
template: mat(colors.orange, {
transparent: true,
opacity: 0.83,
depthWrite: false,
side: THREE.DoubleSide
}),
holeDark: mat(0x172125),
goodRing: mat(colors.teal, { emissive: 0x0a4638, emissiveIntensity: 0.25 }),
badRing: mat(colors.red, { emissive: 0x52150e, emissiveIntensity: 0.25 }),
brass: mat(0xd8ad56, { metalness: 0.58, roughness: 0.35 })
};
function addBox(parent, w, h, d, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent, rTop, rBottom, height, material,
x = 0, y = 0, z = 0, segments = 12
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, height, segments),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function setSpriteText(sprite, text, bg = "#203033", fg = "#f3f7f4") {
const { ctx, canvas: c, texture } = sprite.userData;
ctx.clearRect(0, 0, c.width, c.height);
ctx.fillStyle = bg;
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = "rgba(255,255,255,.18)";
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, c.width - 6, c.height - 6);
ctx.fillStyle = fg;
ctx.font = "800 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 1);
texture.needsUpdate = true;
}
function createTextSprite(text, width = 1.4, height = 0.34, bg, fg) {
const c = document.createElement("canvas");
c.width = 640;
c.height = 160;
const ctx = c.getContext("2d");
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.userData = { ctx, canvas: c, texture };
setSpriteText(sprite, text, bg, fg);
return sprite;
}
// -------------------------------------------------------------------------
// Low-poly workshop environment
// -------------------------------------------------------------------------
addBox(scene, 21, 0.20, 14, materials.floor, 1.5, -0.12, 0);
addBox(scene, 21, 5.6, 0.18, materials.wall, 1.5, 2.65, -5.25);
const floorGrid = new THREE.GridHelper(21, 42, 0x647572, 0x6d7f7d);
floorGrid.position.set(1.5, -0.012, 0);
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.28;
scene.add(floorGrid);
// Main fixture table.
addBox(scene, 7.70, 0.18, 3.25, materials.table, -3.20, TABLE_TOP - 0.09, 1.20);
addBox(scene, 7.82, 0.11, 0.13, materials.tableEdge, -3.20, TABLE_TOP - 0.19, 2.82);
for (const x of [-6.55, 0.15]) {
for (const z of [0.05, 2.35]) {
addBox(scene, 0.18, 1.20, 0.18, materials.dark, x, 0.58, z);
}
}
// Comparison table.
addBox(scene, 11.90, 0.18, 2.55, materials.table, 5.55, TABLE_TOP - 0.09, 1.20);
addBox(scene, 12.02, 0.10, 0.12, materials.tableEdge, 5.55, TABLE_TOP - 0.19, 2.43);
for (const x of [-0.10, 5.30, 11.20]) {
for (const z of [0.25, 2.15]) {
addBox(scene, 0.18, 1.20, 0.18, materials.dark, x, 0.58, z);
}
}
// Several blanks physically resting on the fixture table.
for (let i = 0; i < 3; i++) {
const blank = addBox(
scene, PANEL_W, 0.075, PANEL_D,
i === 1 ? materials.woodLight : materials.wood,
-5.78 + (i - 1) * 0.055,
TABLE_TOP + 0.045 + i * 0.082,
1.34 + (i - 1) * 0.045
);
blank.rotation.y = (i - 1) * 0.025;
}
const blanksLabel = createTextSprite("BLANK PANELS", 1.45, 0.27, "#6d4b32", "#fff7ea");
blanksLabel.position.set(-5.75, TABLE_TOP + 0.36, 2.05);
scene.add(blanksLabel);
// Slot markings on the comparison table.
COMPARE_SLOTS.forEach((slot, i) => {
const outline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-PANEL_W / 2, 0, -PANEL_D / 2),
new THREE.Vector3( PANEL_W / 2, 0, -PANEL_D / 2),
new THREE.Vector3( PANEL_W / 2, 0, PANEL_D / 2),
new THREE.Vector3(-PANEL_W / 2, 0, PANEL_D / 2)
]),
new THREE.LineBasicMaterial({
color: 0x8ba09e,
transparent: true,
opacity: 0.5
})
);
outline.position.set(slot.x, TABLE_TOP + 0.012, slot.z);
scene.add(outline);
const label = createTextSprite(`0${i + 1}`, 0.46, 0.20, "#334447", "#dfe9e5");
label.position.set(slot.x, TABLE_TOP + 0.06, 2.25);
scene.add(label);
});
const comparisonSign = createTextSprite("COMPARISON ROW", 3.0, 0.56, "#25373a", "#d9ebe5");
comparisonSign.position.set(5.6, 3.55, -5.08);
scene.add(comparisonSign);
const fixtureSign = createTextSprite("FIXTURE 04", 2.3, 0.45, "#3a2b20", "#ffe0ad");
fixtureSign.position.set(-4.8, 3.18, -5.08);
scene.add(fixtureSign);
// Back-wall shelving, bins, tools, and cabinet.
addBox(scene, 6.6, 0.14, 0.62, materials.woodDark, 2.2, 3.55, -4.75);
for (const x of [0.0, 2.2, 4.4]) {
addBox(scene, 0.12, 1.25, 0.30, materials.dark, x, 2.95, -4.92);
}
for (let i = 0; i < 7; i++) {
const x = 0.25 + i * 0.72;
addBox(
scene, 0.52, 0.43, 0.42,
[materials.blue, materials.red, materials.teal][i % 3],
x, 3.87, -4.68
);
addBox(scene, 0.37, 0.08, 0.45, materials.dark, x, 4.12, -4.68);
}
addBox(scene, 1.65, 2.05, 1.05, materials.blue, -7.00, 1.02, -3.95);
for (let i = 0; i < 4; i++) {
addBox(scene, 1.42, 0.08, 0.08, materials.dark, -7.00, 0.50 + i * 0.38, -3.39);
addBox(scene, 0.28, 0.07, 0.10, materials.metal, -7.00, 0.50 + i * 0.38, -3.32);
}
// Pegboard and low-poly tool silhouettes.
addBox(scene, 4.0, 1.75, 0.10, materials.woodLight, -1.9, 2.45, -5.08);
for (let i = 0; i < 8; i++) {
const x = -3.45 + i * 0.43;
addBox(scene, 0.075, 0.60, 0.07, materials.dark, x, 2.52, -5.00);
addBox(scene, 0.20, 0.12, 0.08, materials.orange, x, 2.18, -4.99);
}
// -------------------------------------------------------------------------
// Locating stops, clamps, guide, and physical template
// -------------------------------------------------------------------------
const stopMaterial = mat(0x6b7b7b);
const guideMaterial = new THREE.LineBasicMaterial({
color: 0x73aee8,
transparent: true,
opacity: 0.85
});
function addStop(localX, localZ, width, depth) {
const g = new THREE.Group();
g.position.set(
FIXTURE.x + localX,
TABLE_TOP,
FIXTURE.z + localZ
);
addBox(g, width, 0.17, depth, stopMaterial, 0, 0.085, 0);
addBox(g, width * 0.72, 0.025, depth * 0.70, materials.red, 0, 0.183, 0);
scene.add(g);
}
addStop(-1.16, 0.19, 0.15, 0.34);
addStop( 1.16, 0.19, 0.15, 0.34);
addStop(-0.34, -0.64, 0.44, 0.14);
addStop( 0.43, 0.64, 0.46, 0.14);
function addClamp(x, z, rotation) {
const g = new THREE.Group();
g.position.set(x, TABLE_TOP, z);
g.rotation.y = rotation;
addBox(g, 0.44, 0.10, 0.40, materials.dark, 0, 0.05, 0);
addCylinder(g, 0.055, 0.055, 0.62, materials.metal, 0, 0.38, 0, 10);
addBox(g, 0.16, 0.13, 0.68, materials.metal, 0, 0.67, -0.22);
addBox(g, 0.30, 0.18, 0.12, materials.orange, 0, 0.61, -0.54);
addCylinder(g, 0.035, 0.035, 0.26, materials.metal, 0, 0.44, 0, 8);
addBox(g, 0.34, 0.055, 0.08, materials.dark, 0, 0.58, 0);
scene.add(g);
}
addClamp(-4.25, 2.40, 0);
addClamp(-1.55, 2.40, 0);
const guide = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-TEMPLATE_W / 2, 0, -TEMPLATE_D / 2),
new THREE.Vector3( TEMPLATE_W / 2, 0, -TEMPLATE_D / 2),
new THREE.Vector3( TEMPLATE_W / 2, 0, TEMPLATE_D / 2),
new THREE.Vector3(-TEMPLATE_W / 2, 0, TEMPLATE_D / 2),
new THREE.Vector3(-TEMPLATE_W / 2, 0, -TEMPLATE_D / 2),
// Expected notch direction.
new THREE.Vector3(-1.02, 0, -0.53),
new THREE.Vector3(-0.89, 0, -0.39),
new THREE.Vector3(-0.76, 0, -0.53)
]),
guideMaterial
);
guide.position.set(FIXTURE.x, FIXTURE.y + PANEL_T / 2 + 0.015, FIXTURE.z);
scene.add(guide);
// A real extruded plate with real circular holes and a V-notch.
const templateShape = new THREE.Shape();
const n = 0.32;
const nd = 0.25;
templateShape.moveTo(-TEMPLATE_W / 2, -TEMPLATE_D / 2);
templateShape.lineTo( TEMPLATE_W / 2, -TEMPLATE_D / 2);
templateShape.lineTo( TEMPLATE_W / 2, TEMPLATE_D / 2);
templateShape.lineTo(-TEMPLATE_W / 2 + n, TEMPLATE_D / 2);
templateShape.lineTo(-TEMPLATE_W / 2 + n / 2, TEMPLATE_D / 2 - nd);
templateShape.lineTo(-TEMPLATE_W / 2, TEMPLATE_D / 2);
templateShape.closePath();
// The shape's Y axis becomes local -Z after rotation.
for (const p of PATTERN) {
const hole = new THREE.Path();
hole.absarc(p.x, -p.z, 0.085, 0, Math.PI * 2, true);
templateShape.holes.push(hole);
}
const templateGeometry = new THREE.ExtrudeGeometry(templateShape, {
depth: 0.055,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.010,
bevelThickness: 0.010,
curveSegments: 12
});
templateGeometry.rotateX(-Math.PI / 2);
const templateGroup = new THREE.Group();
templateGroup.position.set(FIXTURE.x, FIXTURE.y + PANEL_T / 2 + 0.015, FIXTURE.z);
const templateMesh = new THREE.Mesh(templateGeometry, materials.template);
templateMesh.castShadow = true;
templateMesh.receiveShadow = true;
templateGroup.add(templateMesh);
const templateEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(templateGeometry, 25),
new THREE.LineBasicMaterial({ color: 0x6f360a })
);
templateGroup.add(templateEdges);
// These anchors are the authoritative source of the marked panel positions.
const templateHoleAnchors = [];
const templateRingGeometry = new THREE.TorusGeometry(0.104, 0.013, 6, 24);
for (const p of PATTERN) {
const anchor = new THREE.Object3D();
anchor.position.set(p.x, 0.081, p.z);
templateGroup.add(anchor);
const ring = new THREE.Mesh(templateRingGeometry, materials.dark);
ring.rotation.x = Math.PI / 2;
ring.castShadow = true;
anchor.add(ring);
templateHoleAnchors.push(anchor);
}
const notchArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.085, 0.22, 3),
materials.woodLight
);
notchArrow.rotation.x = Math.PI / 2;
notchArrow.position.set(-0.84, 0.095, -0.39);
templateGroup.add(notchArrow);
const notchLabel = createTextSprite("NOTCH", 0.65, 0.17, "#ffe0a8", "#39220d");
notchLabel.position.set(-0.66, 0.18, -0.66);
templateGroup.add(notchLabel);
scene.add(templateGroup);
// Selection outline around a panel in the comparison row.
const selectionOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-PANEL_W / 2 - 0.06, 0, -PANEL_D / 2 - 0.06),
new THREE.Vector3( PANEL_W / 2 + 0.06, 0, -PANEL_D / 2 - 0.06),
new THREE.Vector3( PANEL_W / 2 + 0.06, 0, PANEL_D / 2 + 0.06),
new THREE.Vector3(-PANEL_W / 2 - 0.06, 0, PANEL_D / 2 + 0.06)
]),
new THREE.LineBasicMaterial({ color: 0x4bd2b2 })
);
selectionOutline.visible = false;
scene.add(selectionOutline);
// -------------------------------------------------------------------------
// Panel state and marking
// -------------------------------------------------------------------------
let currentPanel = null;
let selectedPanel = null;
let panelCounter = 1;
const comparisonPanels = [];
const panelAnimations = [];
const holeCylinderGeometry = new THREE.CylinderGeometry(0.062, 0.062, 0.018, 16);
const holeRingGeometry = new THREE.TorusGeometry(0.083, 0.012, 6, 24);
const fastenerGeometry = new THREE.CylinderGeometry(0.052, 0.052, 0.026, 12);
function createPanel() {
const id = `P-${String(panelCounter++).padStart(3, "0")}`;
const group = new THREE.Group();
group.position.copy(FIXTURE);
const panelMaterial = mat(0xd5a96d);
const mesh = addBox(group, PANEL_W, PANEL_T, PANEL_D, panelMaterial);
mesh.castShadow = true;
mesh.receiveShadow = true;
const edgeLines = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x7f5733,
transparent: true,
opacity: 0.55
})
);
group.add(edgeLines);
// Centerlines help compare actual joint locations from above.
const centerlines = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.20, PANEL_T / 2 + 0.003, 0),
new THREE.Vector3( 1.20, PANEL_T / 2 + 0.003, 0),
new THREE.Vector3(0, PANEL_T / 2 + 0.003, -0.69),
new THREE.Vector3(0, PANEL_T / 2 + 0.003, 0.69)
]),
new THREE.LineBasicMaterial({
color: 0x755331,
transparent: true,
opacity: 0.22
})
);
group.add(centerlines);
const label = createTextSprite(`${id} • BLANK`, 1.55, 0.30, "#694a2f", "#fff2dc");
label.position.set(0, 0.15, 0.68);
group.add(label);
const panel = {
id,
group,
mesh,
label,
marked: false,
good: false,
assembled: false,
holes: [],
holePositions: [],
holePulseStart: null,
fastenerGroup: null
};
mesh.userData.panel = panel;
scene.add(group);
return panel;
}
function updatePanelLabel(panel) {
if (!panel) return;
let state = "BLANK";
let bg = "#694a2f";
let fg = "#fff2dc";
if (panel.marked) {
state = panel.good ? "GOOD" : "MISMATCH";
bg = panel.good ? "#1b6757" : "#8e352b";
fg = "#ffffff";
}
if (panel.assembled) {
state = "ASSEMBLED";
bg = "#1b6757";
}
setSpriteText(panel.label, `${panel.id} • ${state}`, bg, fg);
}
function clearHoles(panel) {
if (!panel) return;
if (panel.holeGroup) {
panel.group.remove(panel.holeGroup);
}
panel.holes = [];
panel.holePositions = [];
panel.holePulseStart = null;
}
function placementInfo() {
const dx = templateGroup.position.x - FIXTURE.x;
const dz = templateGroup.position.z - FIXTURE.z;
const angle = ((templateGroup.rotation.y % (Math.PI * 2)) + Math.PI * 2)
% (Math.PI * 2);
const orientationCorrect =
angle < 0.045 ||
angle > Math.PI * 2 - 0.045;
const reversed =
Math.abs(angle - Math.PI) < 0.045;
const aligned = Math.hypot(dx, dz) < 0.065;
return {
dx,
dz,
angle,
aligned,
orientationCorrect,
reversed,
good: aligned && orientationCorrect
};
}
function markCurrentPanel(silent = false) {
if (!currentPanel) return;
clearHoles(currentPanel);
templateGroup.updateMatrixWorld(true);
currentPanel.group.updateMatrixWorld(true);
const holeGroup = new THREE.Group();
const world = new THREE.Vector3();
// Sample the actual world positions of the physical template's hole anchors.
for (const anchor of templateHoleAnchors) {
anchor.getWorldPosition(world);
const local = new THREE.Vector3(
world.x - currentPanel.group.position.x,
PANEL_T / 2 + 0.010,
world.z - currentPanel.group.position.z
);
const hole = new THREE.Group();
hole.position.copy(local);
const dark = new THREE.Mesh(holeCylinderGeometry, materials.holeDark);
dark.castShadow = true;
hole.add(dark);
const ring = new THREE.Mesh(
holeRingGeometry,
currentPanel.good ? materials.goodRing : materials.badRing
);
ring.rotation.x = Math.PI / 2;
hole.add(ring);
holeGroup.add(hole);
currentPanel.holes.push(hole);
currentPanel.holePositions.push({ x: local.x, z: local.z });
}
currentPanel.group.add(holeGroup);
currentPanel.holeGroup = holeGroup;
currentPanel.marked = true;
currentPanel.good = placementInfo().good;
currentPanel.holePulseStart = performance.now();
updatePanelLabel(currentPanel);
refreshUI();
if (!silent) {
if (currentPanel.good) {
toast("Panel marked from the registered template placement.");
} else {
toast(
"Mismatch marked: the panel holes followed the template’s actual shifted/reversed placement."
);
}
}
}
function addAssemblyFasteners(panel) {
if (panel.fastenerGroup) return;
const group = new THREE.Group();
for (const x of [-1.14, 1.14]) {
for (const z of [-0.66, 0.66]) {
const screw = new THREE.Mesh(fastenerGeometry, materials.brass);
screw.position.set(x, PANEL_T / 2 + 0.015, z);
screw.castShadow = true;
group.add(screw);
const plate = addBox(
group, 0.20, 0.035, 0.20,
materials.teal,
x, PANEL_T / 2 + 0.008, z
);
plate.rotation.y = Math.PI / 4;
}
}
panel.group.add(group);
panel.fastenerGroup = group;
panel.assembled = true;
updatePanelLabel(panel);
}
function animatePanelTo(panel, destination) {
panelAnimations.push({
panel,
start: panel.group.position.clone(),
end: destination.clone(),
elapsed: 0,
duration: 0.75
});
}
// -------------------------------------------------------------------------
// User workflow
// -------------------------------------------------------------------------
function setTemplate(x, z, rotation = templateGroup.rotation.y) {
templateGroup.position.set(x, templateGroup.position.y, z);
templateGroup.rotation.y = rotation;
templateGroup.updateMatrixWorld(true);
refreshUI();
}
function alignCurrent() {
if (!currentPanel) return;
setTemplate(FIXTURE.x, FIXTURE.z, 0);
if (currentPanel.marked) {
markCurrentPanel(true);
toast("Template aligned to the stops; the existing marks were recomputed.");
} else {
toast("Template aligned. The notch now faces the back-left stops.");
}
}
function shiftTemplate() {
if (!currentPanel) return;
// Deliberately sideways, while preserving the correct notch orientation.
setTemplate(FIXTURE.x + 0.34, FIXTURE.z + 0.16, 0);
toast("Intentional sideways shift applied. Mark now to reveal the mismatch.");
}
function flipTemplate() {
if (!currentPanel) return;
const angle = ((templateGroup.rotation.y % (Math.PI * 2)) + Math.PI * 2)
% (Math.PI * 2);
const next = Math.abs(angle - Math.PI) < 0.05 ? 0 : Math.PI;
setTemplate(templateGroup.position.x, templateGroup.position.z, next);
toast(
next === Math.PI
? "Template reversed: the notch now points away from the registered stops."
: "Template restored to the correct notch orientation."
);
}
function sendCurrentToComparison() {
if (!currentPanel || !currentPanel.marked) return;
if (comparisonPanels.length >= COMPARE_SLOTS.length) {
toast("The comparison row is full. Return or remove a mismatched example first.");
return;
}
const panel = currentPanel;
const destination = COMPARE_SLOTS[comparisonPanels.length].clone();
comparisonPanels.push(panel);
selectedPanel = panel;
animatePanelTo(panel, destination);
currentPanel = null;
templateGroup.visible = false;
guide.visible = false;
refreshUI();
toast(
panel.good
? `${panel.id} moved into the comparison row.`
: `${panel.id} moved into the comparison row as a flagged mismatch.`
);
}
function returnAndCorrectSelected() {
if (
!selectedPanel ||
selectedPanel.good ||
selectedPanel.assembled
) return;
const panel = selectedPanel;
const index = comparisonPanels.indexOf(panel);
if (index >= 0) comparisonPanels.splice(index, 1);
selectedPanel = null;
currentPanel = panel;
panel.group.position.copy(FIXTURE);
panel.marked = false;
panel.good = false;
clearHoles(panel);
updatePanelLabel(panel);
templateGroup.visible = true;
guide.visible = true;
setTemplate(FIXTURE.x, FIXTURE.z, 0);
markCurrentPanel(true);
toast(`${panel.id} returned, aligned, and re-marked correctly before assembly.`);
}
function assembleSelected() {
if (
!selectedPanel ||
!selectedPanel.marked ||
!selectedPanel.good ||
selectedPanel.assembled
) return;
addAssemblyFasteners(selectedPanel);
refreshUI();
toast(`${selectedPanel.id} assembled and retained in the comparison row.`);
}
function newBlankPanel() {
if (currentPanel) {
scene.remove(currentPanel.group);
}
currentPanel = createPanel();
updatePanelLabel(currentPanel);
templateGroup.visible = true;
guide.visible = true;
setTemplate(FIXTURE.x, FIXTURE.z, 0);
refreshUI();
toast(`${currentPanel.id} loaded on the fixture.`);
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const ui = {
placement: document.querySelector("#placementStatus"),
orientation: document.querySelector("#orientationStatus"),
current: document.querySelector("#currentStatus"),
selected: document.querySelector("#selectedInfo"),
shift: document.querySelector("#shiftButton"),
flip: document.querySelector("#flipButton"),
align: document.querySelector("#alignButton"),
mark: document.querySelector("#markButton"),
send: document.querySelector("#sendButton"),
correct: document.querySelector("#correctButton"),
assemble: document.querySelector("#assembleButton"),
next: document.querySelector("#newButton")
};
function refreshUI() {
const info = placementInfo();
if (!currentPanel) {
ui.placement.textContent = "FIXTURE CLEAR";
ui.placement.className = "neutral";
ui.orientation.textContent = "—";
ui.orientation.className = "";
ui.current.textContent = selectedPanel
? `${selectedPanel.id} selected`
: "Load a blank";
} else {
if (info.aligned) {
ui.placement.textContent = "REGISTERED";
ui.placement.className = "good";
} else {
ui.placement.textContent =
`X ${info.dx >= 0 ? "+" : ""}${info.dx.toFixed(2)} / ` +
`Z ${info.dz >= 0 ? "+" : ""}${info.dz.toFixed(2)}`;
ui.placement.className = "bad";
}
if (info.orientationCorrect) {
ui.orientation.textContent = "CORRECT";
ui.orientation.className = "good";
} else if (info.reversed) {
ui.orientation.textContent = "REVERSED";
ui.orientation.className = "bad";
} else {
ui.orientation.textContent = "OFF ANGLE";
ui.orientation.className = "bad";
}
const markState = currentPanel.marked
? ` / ${currentPanel.good ? "GOOD" : "MISMATCH"}`
: "";
ui.current.textContent = `${currentPanel.id}${markState}`;
ui.current.className = currentPanel.marked
? (currentPanel.good ? "good" : "bad")
: "";
}
ui.shift.disabled = !currentPanel;
ui.flip.disabled = !currentPanel;
ui.align.disabled = !currentPanel;
ui.mark.disabled = !currentPanel;
ui.send.disabled = !currentPanel || !currentPanel.marked;
ui.correct.disabled = !(
selectedPanel &&
selectedPanel.marked &&
!selectedPanel.good &&
!selectedPanel.assembled
);
ui.assemble.disabled = !(
selectedPanel &&
selectedPanel.marked &&
selectedPanel.good &&
!selectedPanel.assembled
);
ui.mark.textContent = currentPanel?.marked ? "Re-mark panel" : "Mark panel";
ui.send.textContent = currentPanel?.marked
? "Send to comparison"
: "Mark before sending";
if (selectedPanel) {
const state = selectedPanel.assembled
? "ASSEMBLED"
: (selectedPanel.good ? "GOOD" : "MISMATCH");
ui.selected.textContent =
`Selected ${selectedPanel.id} — ${state}. ` +
(selectedPanel.good
? "It can be assembled."
: "Return it to the fixture to correct the placement before assembly.");
ui.selected.className = selectedPanel.good ? "good" : "bad";
} else {
ui.selected.textContent = "No comparison panel selected.";
ui.selected.className = "";
}
const stopColor = info.good ? 0x2dbb98 : 0xc65a46;
stopMaterial.color.setHex(stopColor);
guideMaterial.color.setHex(info.good ? 0x4bd2b2 : 0x73aee8);
}
let toastTimer = null;
function toast(message) {
const el = document.querySelector("#toast");
el.textContent = message;
el.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => el.classList.remove("show"), 3000);
}
// -------------------------------------------------------------------------
// Direct camera controls and template dragging
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(1.40, 0.95, 1.15),
radius: 19.0,
theta: 0.47,
phi: 0.72
};
function applyCamera() {
const { target, radius, theta, phi } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.target.set(1.40, 0.95, 1.15);
cameraState.radius = 19.0;
cameraState.theta = 0.47;
cameraState.phi = 0.72;
applyCamera();
}
function topCamera() {
cameraState.target.set(1.70, 0.85, 1.20);
cameraState.radius = 16.6;
cameraState.theta = 0.001;
cameraState.phi = 0.035;
applyCamera();
}
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
const dragPoint = new THREE.Vector3();
const dragOffset = new THREE.Vector3();
let pointerMode = null;
let downX = 0;
let downY = 0;
let lastX = 0;
let lastY = 0;
let draggedDistance = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
updatePointer(event);
downX = event.clientX;
downY = event.clientY;
lastX = event.clientX;
lastY = event.clientY;
draggedDistance = 0;
if (event.button === 2 || event.shiftKey) {
pointerMode = "pan";
return;
}
raycaster.setFromCamera(pointer, camera);
if (currentPanel && templateGroup.visible) {
const hits = raycaster.intersectObject(templateGroup, true);
if (hits.length) {
dragPlane.constant = -templateGroup.position.y;
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
dragOffset.copy(templateGroup.position).sub(dragPoint);
pointerMode = "template";
return;
}
}
}
pointerMode = "orbit";
});
canvas.addEventListener("pointermove", event => {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
draggedDistance += Math.abs(dx) + Math.abs(dy);
if (pointerMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.035,
1.36
);
applyCamera();
} else if (pointerMode === "pan") {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3(
-Math.sin(cameraState.theta),
0,
-Math.cos(cameraState.theta)
);
const scale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(forward, dy * scale);
applyCamera();
} else if (pointerMode === "template" && currentPanel) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
const desired = dragPoint.clone().add(dragOffset);
const x = THREE.MathUtils.clamp(
desired.x,
FIXTURE.x - 0.78,
FIXTURE.x + 0.78
);
const z = THREE.MathUtils.clamp(
desired.z,
FIXTURE.z - 0.56,
FIXTURE.z + 0.56
);
setTemplate(x, z);
}
}
});
canvas.addEventListener("pointerup", event => {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
const click =
pointerMode === "orbit" &&
Math.hypot(event.clientX - downX, event.clientY - downY) < 5;
if (click && comparisonPanels.length) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
comparisonPanels.map(panel => panel.mesh),
false
);
if (hits.length) {
selectedPanel = hits[0].object.userData.panel;
refreshUI();
}
}
pointerMode = null;
});
canvas.addEventListener("pointercancel", () => {
pointerMode = null;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8.5,
28
);
applyCamera();
}, { passive: false });
// Keyboard placement nudges.
window.addEventListener("keydown", event => {
if (!currentPanel) return;
const step = event.shiftKey ? 0.10 : 0.035;
let handled = true;
switch (event.key.toLowerCase()) {
case "arrowleft":
setTemplate(templateGroup.position.x - step, templateGroup.position.z);
break;
case "arrowright":
setTemplate(templateGroup.position.x + step, templateGroup.position.z);
break;
case "arrowup":
setTemplate(templateGroup.position.x, templateGroup.position.z - step);
break;
case "arrowdown":
setTemplate(templateGroup.position.x, templateGroup.position.z + step);
break;
case "r":
flipTemplate();
break;
case "m":
markCurrentPanel();
break;
case "c":
alignCurrent();
break;
case "t":
topCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
// -------------------------------------------------------------------------
// UI events
// -------------------------------------------------------------------------
ui.shift.addEventListener("click", shiftTemplate);
ui.flip.addEventListener("click", flipTemplate);
ui.align.addEventListener("click", alignCurrent);
ui.mark.addEventListener("click", () => markCurrentPanel());
ui.send.addEventListener("click", sendCurrentToComparison);
ui.correct.addEventListener("click", returnAndCorrectSelected);
ui.assemble.addEventListener("click", assembleSelected);
ui.next.addEventListener("click", newBlankPanel);
document.querySelector("#topButton").addEventListener("click", topCamera);
document.querySelector("#overheadButton").addEventListener("click", topCamera);
document.querySelector("#isoButton").addEventListener("click", resetCamera);
document.querySelector("#resetViewButton").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Animation and initialization
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
for (let i = panelAnimations.length - 1; i >= 0; i--) {
const animation = panelAnimations[i];
animation.elapsed += 1 / 60;
const t = Math.min(animation.elapsed / animation.duration, 1);
const eased = 1 - Math.pow(1 - t, 3);
animation.panel.group.position.x = THREE.MathUtils.lerp(
animation.start.x, animation.end.x, eased
);
animation.panel.group.position.z = THREE.MathUtils.lerp(
animation.start.z, animation.end.z, eased
);
animation.panel.group.position.y = THREE.MathUtils.lerp(
animation.start.y, animation.end.y, eased
) + Math.sin(t * Math.PI) * 0.48;
if (t >= 1) {
animation.panel.group.position.copy(animation.end);
panelAnimations.splice(i, 1);
}
}
for (const panel of comparisonPanels) {
if (panel.holePulseStart !== null) {
const t = Math.min((now - panel.holePulseStart) / 430, 1);
const eased = 1 - Math.pow(1 - t, 3);
for (const hole of panel.holes) {
hole.scale.setScalar(Math.max(0.02, eased));
}
if (t >= 1) {
panel.holePulseStart = null;
for (const hole of panel.holes) hole.scale.setScalar(1);
}
}
}
if (selectedPanel) {
selectionOutline.visible = true;
selectionOutline.position.set(
selectedPanel.group.position.x,
selectedPanel.group.position.y + PANEL_T / 2 + 0.025,
selectedPanel.group.position.z
);
selectionOutline.material.color.setHex(
selectedPanel.good ? 0x4bd2b2 : 0xff705d
);
} else {
selectionOutline.visible = false;
}
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
applyCamera();
newBlankPanel();
requestAnimationFrame(animate);
</script>
</body>
</html>
```