Prompt specification
Build or customize the Three.js 3D scene "Locate a Hole From Two Edges" 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: Locate a Hole From Two Edges
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/locate-a-hole-from-two-edges-x2058
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows reference datums for locating part features. Create a workbench demonstration positioning a drill marker by two stated offsets. Change the reference edge and show why unchanged numeric values identify a different point. Voxel style.
Working Three.js Starter (locate-a-hole-from-two-edges-x2058):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Datum Lab — Voxel Workbench</title>
<style>
:root {
--paper: #f2eee3;
--panel: #fffdf6;
--ink: #17211b;
--muted: #687168;
--line: #c8c5b8;
--blue: #2859d9;
--blue-soft: #dfe7ff;
--coral: #e4583f;
--coral-soft: #ffe4dd;
--yellow: #f2c623;
--yellow-soft: #fff2ad;
--green: #47705a;
--shadow: 5px 5px 0 rgba(23, 33, 27, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.topbar {
height: 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 22px;
border-bottom: 2px solid var(--ink);
background: var(--panel);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 250px;
}
.brand-mark {
width: 31px;
height: 31px;
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 3px;
transform: rotate(-2deg);
}
.brand-mark i {
display: block;
background: var(--ink);
}
.brand-mark i:nth-child(1) {
background: var(--blue);
}
.brand-mark i:nth-child(2) {
background: var(--coral);
}
.brand-mark i:nth-child(3) {
background: var(--yellow);
}
.brand strong {
display: block;
font-size: 15px;
letter-spacing: 0.08em;
line-height: 1.05;
}
.brand small {
display: block;
margin-top: 4px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.lesson {
display: flex;
align-items: center;
gap: 12px;
text-align: center;
font-size: 13px;
font-weight: 700;
}
.lesson .lesson-number {
display: grid;
place-items: center;
width: 29px;
height: 29px;
border: 2px solid var(--ink);
background: var(--yellow);
font: 800 12px/1 ui-monospace, monospace;
box-shadow: 3px 3px 0 var(--ink);
}
.view-reset {
min-width: 125px;
border: 2px solid var(--ink);
border-radius: 0;
padding: 9px 12px;
background: var(--panel);
box-shadow: 3px 3px 0 var(--ink);
font: 800 11px/1 ui-monospace, monospace;
letter-spacing: 0.04em;
text-transform: uppercase;
cursor: pointer;
}
.view-reset:active {
transform: translate(3px, 3px);
box-shadow: 0 0 0 var(--ink);
}
.layout {
height: calc(100% - 68px);
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
}
.controls {
overflow-y: auto;
border-right: 2px solid var(--ink);
background: var(--panel);
padding: 22px 20px 24px;
scrollbar-width: thin;
scrollbar-color: var(--line) transparent;
}
.section {
padding-bottom: 22px;
margin-bottom: 22px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 9px;
color: var(--blue);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 27px;
line-height: 1.05;
letter-spacing: -0.045em;
}
.intro {
margin: 11px 0 17px;
color: #596259;
font-size: 13px;
line-height: 1.5;
}
.edge-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.edge-button {
position: relative;
min-height: 83px;
padding: 11px;
border: 2px solid var(--ink);
border-radius: 0;
background: #f7f3e9;
text-align: left;
cursor: pointer;
box-shadow: 3px 3px 0 rgba(23, 33, 27, 0.16);
transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}
.edge-button:hover {
transform: translateY(-2px);
box-shadow: 4px 5px 0 rgba(23, 33, 27, 0.16);
}
.edge-button.active {
background: var(--blue-soft);
border-color: var(--blue);
box-shadow: 4px 4px 0 var(--blue);
}
.edge-letter {
position: absolute;
top: 9px;
right: 9px;
display: grid;
place-items: center;
width: 25px;
height: 25px;
border: 2px solid var(--ink);
background: var(--yellow);
font: 900 12px/1 ui-monospace, monospace;
}
.edge-button.active .edge-letter {
background: var(--blue);
color: white;
}
.edge-button strong {
display: block;
margin-top: 20px;
font: 900 13px/1 ui-monospace, monospace;
letter-spacing: 0.05em;
}
.edge-button small {
display: block;
margin-top: 6px;
color: var(--muted);
font: 700 10px/1 ui-monospace, monospace;
}
.offset-control {
padding: 13px;
border: 2px solid var(--ink);
background: #f7f3e9;
margin-top: 11px;
position: relative;
overflow: hidden;
}
.offset-control.flash::after {
content: "";
position: absolute;
inset: 0;
background: var(--yellow-soft);
animation: value-flash 650ms ease-out;
pointer-events: none;
}
@keyframes value-flash {
0% { opacity: 0.95; }
100% { opacity: 0; }
}
.offset-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.offset-head label {
font: 900 12px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.offset-head span {
color: var(--muted);
font-size: 11px;
}
.number-box {
display: flex;
align-items: baseline;
gap: 8px;
margin-top: 10px;
}
.number-box input[type="number"] {
width: 100%;
min-width: 0;
border: 0;
border-bottom: 2px solid var(--ink);
padding: 3px 0 5px;
outline: none;
background: transparent;
color: var(--ink);
font: 900 29px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.number-box span {
color: var(--muted);
font: 800 10px/1 ui-monospace, monospace;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 11px 0 0;
accent-color: var(--coral);
cursor: pointer;
}
.offset-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.calculation {
border: 2px solid var(--ink);
background: #17211b;
color: #f8f4e9;
padding: 15px;
box-shadow: var(--shadow);
}
.calculation .eyebrow {
color: var(--yellow);
}
.calculation-title {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: center;
padding-bottom: 12px;
border-bottom: 1px solid #435047;
}
.calculation-title strong {
font: 900 17px/1 ui-monospace, monospace;
}
.calculation-title span {
color: #a9b3aa;
font: 700 10px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.equation {
margin: 14px 0 11px;
color: #fff3a8;
font: 800 14px/1.6 ui-monospace, monospace;
overflow-wrap: anywhere;
}
.vector-list {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.vector-item {
border: 1px solid #4b584e;
padding: 9px;
background: #202c24;
}
.vector-item small {
display: block;
color: #94a096;
font: 700 9px/1 ui-monospace, monospace;
text-transform: uppercase;
margin-bottom: 5px;
}
.vector-item b {
font: 800 12px/1 ui-monospace, monospace;
}
.reset-demo {
width: 100%;
margin-top: 14px;
border: 2px solid var(--ink);
border-radius: 0;
background: var(--yellow);
padding: 12px;
box-shadow: 4px 4px 0 var(--ink);
font: 900 11px/1 ui-monospace, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
.reset-demo:active {
transform: translate(4px, 4px);
box-shadow: 0 0 0 var(--ink);
}
.viewport {
position: relative;
min-width: 0;
overflow: hidden;
background: #eee9dc;
isolation: isolate;
}
.viewport canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
z-index: 0;
cursor: grab;
touch-action: none;
}
.viewport canvas.dragging {
cursor: grabbing;
}
.viewport::before {
content: "";
position: absolute;
inset: 0;
z-index: 1;
pointer-events: none;
background-image:
linear-gradient(rgba(23, 33, 27, 0.025) 1px, transparent 1px),
linear-gradient(90deg, rgba(23, 33, 27, 0.025) 1px, transparent 1px);
background-size: 24px 24px;
}
.world-labels {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
border: 2px solid var(--ink);
background: var(--panel);
padding: 5px 7px;
box-shadow: 3px 3px 0 rgba(23, 33, 27, 0.14);
font: 900 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.03em;
}
.world-label.edge-label {
padding: 5px 7px;
background: #f8f4e9;
color: #687168;
}
.world-label.edge-label.active {
background: var(--blue);
color: white;
border-color: var(--blue);
box-shadow: 3px 3px 0 #153489;
}
.world-label.datum-label {
background: var(--blue);
color: white;
border-color: var(--blue);
}
.world-label.dimension-label {
background: var(--coral);
color: white;
border-color: #a73625;
}
.world-label.drill-label {
background: var(--yellow);
border-color: var(--ink);
}
.world-label.ghost-label {
color: #5f675f;
border-style: dashed;
background: rgba(255, 253, 246, 0.9);
}
.world-label.feature-label {
border-color: #809487;
color: #52685a;
font-size: 9px;
padding: 4px 6px;
}
.hud {
position: absolute;
z-index: 4;
pointer-events: none;
}
.point-card {
top: 18px;
left: 18px;
width: 292px;
border: 2px solid var(--ink);
background: rgba(255, 253, 246, 0.94);
box-shadow: var(--shadow);
padding: 14px;
}
.point-card .eyebrow {
margin-bottom: 10px;
}
.point-row {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 10px;
}
.point-title {
font: 900 20px/1 ui-monospace, monospace;
}
.point-datum {
margin-top: 7px;
color: var(--blue);
font: 800 11px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.coordinates {
display: flex;
gap: 10px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid var(--line);
}
.coordinate {
flex: 1;
border-left: 4px solid var(--yellow);
padding-left: 9px;
}
.coordinate small {
display: block;
color: var(--muted);
font: 700 9px/1 ui-monospace, monospace;
margin-bottom: 5px;
}
.coordinate b {
font: 900 16px/1 ui-monospace, monospace;
}
.legend {
top: 18px;
right: 18px;
display: flex;
gap: 6px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 340px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
border: 1px solid var(--ink);
background: rgba(255, 253, 246, 0.9);
padding: 5px 7px;
font: 800 9px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.legend-item i {
width: 9px;
height: 9px;
display: block;
}
.legend-item.datum i { background: var(--blue); }
.legend-item.offset i { background: var(--coral); }
.legend-item.drill i { background: var(--yellow); }
.legend-item.previous i { background: #9aa19a; }
.comparison-card {
right: 18px;
bottom: 18px;
width: 360px;
border: 2px solid var(--ink);
background: rgba(255, 253, 246, 0.96);
box-shadow: var(--shadow);
padding: 15px;
}
.comparison-card .eyebrow {
color: var(--coral);
}
.comparison-main {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.comparison-main strong {
font: 900 22px/1 ui-monospace, monospace;
letter-spacing: -0.04em;
}
.comparison-main span {
color: var(--muted);
font: 700 10px/1.3 ui-monospace, monospace;
text-align: right;
text-transform: uppercase;
}
.comparison-details {
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
display: grid;
gap: 7px;
color: var(--muted);
font: 700 10px/1.35 ui-monospace, monospace;
}
.comparison-details b {
color: var(--ink);
}
.comparison-prompt {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.comparison-prompt b {
color: var(--blue);
}
.camera-tip {
left: 18px;
bottom: 18px;
border: 1px solid var(--line);
background: rgba(255, 253, 246, 0.82);
padding: 7px 9px;
color: var(--muted);
font: 700 9px/1 ui-monospace, monospace;
text-transform: uppercase;
}
.toast {
top: 88px;
left: 50%;
transform: translate(-50%, -12px);
border: 2px solid var(--ink);
background: var(--yellow);
padding: 9px 13px;
box-shadow: 4px 4px 0 var(--ink);
opacity: 0;
transition: opacity 180ms ease, transform 180ms ease;
font: 900 10px/1 ui-monospace, monospace;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
@media (max-width: 900px) {
html,
body {
overflow: auto;
}
.topbar {
position: sticky;
top: 0;
}
.lesson {
display: none;
}
.layout {
height: auto;
display: flex;
flex-direction: column;
}
.viewport {
order: 1;
height: 68vh;
min-height: 520px;
border-bottom: 2px solid var(--ink);
}
.controls {
order: 2;
overflow: visible;
border-right: 0;
}
.point-card {
width: 255px;
}
.comparison-card {
width: 330px;
}
}
@media (max-width: 600px) {
.topbar {
height: 60px;
padding: 0 12px;
}
.brand {
min-width: 0;
}
.brand small {
display: none;
}
.view-reset {
min-width: auto;
padding: 9px;
}
.layout {
min-height: calc(100% - 60px);
}
.controls {
padding: 18px 14px 22px;
}
.viewport {
height: 76vh;
min-height: 580px;
}
.point-card {
top: 10px;
left: 10px;
width: 215px;
padding: 11px;
}
.point-title {
font-size: 16px;
}
.coordinate b {
font-size: 13px;
}
.legend {
top: 10px;
right: 10px;
max-width: 130px;
}
.legend-item {
padding: 4px;
}
.legend-item span {
display: none;
}
.comparison-card {
left: 10px;
right: 10px;
bottom: 10px;
width: auto;
padding: 11px;
}
.comparison-main strong {
font-size: 18px;
}
.camera-tip {
display: none;
}
}
</style>
</head>
<body>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</div>
<div>
<strong>DATUM / WORKBENCH</strong>
<small>Voxel coordinate lesson 01</small>
</div>
</div>
<div class="lesson">
<span class="lesson-number">01</span>
<span>Same offsets. Different reference edge. Different point.</span>
</div>
<button class="view-reset" id="resetView" type="button">Reset view</button>
</header>
<main class="layout">
<aside class="controls" aria-label="Datum and offset controls">
<section class="section">
<div class="eyebrow">01 / Select the datum</div>
<h1>Pick a real edge.</h1>
<p class="intro">
The blue edge is the datum. The two dimensions are always measured from it,
so the numbers only describe a location when the datum is stated.
</p>
<div class="edge-grid" id="edgeButtons">
<button class="edge-button active" data-edge="left" type="button">
<span class="edge-letter">A</span>
<strong>LEFT</strong>
<small>X = −6.00</small>
</button>
<button class="edge-button" data-edge="right" type="button">
<span class="edge-letter">B</span>
<strong>RIGHT</strong>
<small>X = +6.00</small>
</button>
<button class="edge-button" data-edge="front" type="button">
<span class="edge-letter">C</span>
<strong>FRONT</strong>
<small>Z = +4.00</small>
</button>
<button class="edge-button" data-edge="back" type="button">
<span class="edge-letter">D</span>
<strong>BACK</strong>
<small>Z = −4.00</small>
</button>
</div>
</section>
<section class="section">
<div class="eyebrow">02 / State two offsets</div>
<div class="offset-control" id="offsetControl1">
<div class="offset-head">
<label for="offset1">Offset 1</label>
<span>along the selected edge</span>
</div>
<div class="number-box">
<input id="offset1" type="number" min="0" max="8" step="0.25" value="3.50" />
<span>blocks</span>
</div>
<input id="offset1Range" aria-label="Offset 1 slider" type="range" min="0" max="8" step="0.25" value="3.5" />
</div>
<div class="offset-control" id="offsetControl2">
<div class="offset-head">
<label for="offset2">Offset 2</label>
<span>inward from that edge</span>
</div>
<div class="number-box">
<input id="offset2" type="number" min="0" max="8" step="0.25" value="3.20" />
<span>blocks</span>
</div>
<input id="offset2Range" aria-label="Offset 2 slider" type="range" min="0" max="8" step="0.25" value="3.2" />
</div>
<p class="offset-note">
Offset 1 starts at the small blue corner on the chosen edge.
Offset 2 continues inward from that point.
</p>
</section>
<section class="section">
<div class="calculation">
<div class="eyebrow">Active calculation</div>
<div class="calculation-title">
<strong id="calcDatum">A / LEFT</strong>
<span>Part coordinates</span>
</div>
<div class="equation" id="equationText">
P = O + 3.50u + 3.20n
</div>
<div class="vector-list">
<div class="vector-item">
<small>Origin O</small>
<b id="originText">(−6.00, −4.00)</b>
</div>
<div class="vector-item">
<small>Direction u</small>
<b id="alongText">(0, +1)</b>
</div>
<div class="vector-item">
<small>Inward n</small>
<b id="inwardText">(+1, 0)</b>
</div>
<div class="vector-item">
<small>Result P</small>
<b id="resultText">(−2.80, −0.50)</b>
</div>
</div>
</div>
<button class="reset-demo" id="resetDemo" type="button">Reset demonstration</button>
</section>
</aside>
<section class="viewport" id="viewport" aria-label="Interactive 3D voxel workbench">
<div class="world-labels" id="worldLabels">
<div class="world-label edge-label" id="edgeLabelA">A / LEFT</div>
<div class="world-label edge-label" id="edgeLabelB">B / RIGHT</div>
<div class="world-label edge-label" id="edgeLabelC">C / FRONT</div>
<div class="world-label edge-label" id="edgeLabelD">D / BACK</div>
<div class="world-label datum-label" id="datumLabel">A / DATUM</div>
<div class="world-label dimension-label" id="dimensionLabel1">1 · 3.50</div>
<div class="world-label dimension-label" id="dimensionLabel2">2 · 3.20</div>
<div class="world-label drill-label" id="drillLabel">DRILL / D1</div>
<div class="world-label ghost-label" id="ghostLabel">PREVIOUS POINT</div>
<div class="world-label feature-label" id="featureLabel">FIXED KEYWAY</div>
</div>
<div class="hud point-card">
<div class="eyebrow">Active drill point</div>
<div class="point-row">
<div>
<div class="point-title" id="pointTitle">D1 / TARGET</div>
<div class="point-datum" id="pointDatum">From datum A / LEFT</div>
</div>
</div>
<div class="coordinates">
<div class="coordinate">
<small>PART X</small>
<b id="pointX">−2.80</b>
</div>
<div class="coordinate">
<small>PART Z</small>
<b id="pointZ">−0.50</b>
</div>
</div>
</div>
<div class="hud legend">
<div class="legend-item datum"><i></i><span>Datum edge</span></div>
<div class="legend-item offset"><i></i><span>Offsets</span></div>
<div class="legend-item drill"><i></i><span>Drill marker</span></div>
<div class="legend-item previous"><i></i><span>Previous point</span></div>
</div>
<div class="hud comparison-card">
<div class="eyebrow" id="comparisonEyebrow">Try the reference change</div>
<div class="comparison-main">
<strong id="comparisonTitle">KEEP THE NUMBERS</strong>
<span id="comparisonDatum">Choose another edge</span>
</div>
<div class="comparison-details" id="comparisonDetails" hidden>
<div>Previous <b id="previousCoordinates"></b></div>
<div>Current <b id="currentCoordinates"></b></div>
</div>
<p class="comparison-prompt" id="comparisonPrompt">
Select <b>B / RIGHT</b>. Both offset values will stay unchanged.
Watch the drill marker land somewhere else.
</p>
</div>
<div class="hud camera-tip">Drag to orbit · Wheel to zoom</div>
<div class="hud toast" id="toast">Reference changed — offsets held</div>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9dc);
scene.fog = new THREE.Fog(0xeee9dc, 28, 52);
const renderer = new THREE.WebGLRenderer({
antialias: false,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.BasicShadowMap;
renderer.domElement.setAttribute("aria-label", "Voxel workbench showing a drill point located from a selected reference edge");
viewport.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.1, 0);
const cameraState = {
yaw: 0.72,
pitch: 0.76,
radius: 24,
zoom: 1
};
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x718071, 2.2);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5d6, 3.1);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfd5ff, 1.0);
fill.position.set(10, 7, -10);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
bench: new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.92 }),
part: new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.82 }),
benchBase: new THREE.MeshStandardMaterial({ color: 0x665e50, roughness: 0.95 }),
ground: new THREE.MeshStandardMaterial({ color: 0xe8e2d4, roughness: 1 }),
datum: new THREE.MeshBasicMaterial({ color: 0x2859d9 }),
offset: new THREE.MeshBasicMaterial({ color: 0xe4583f }),
drillYellow: new THREE.MeshBasicMaterial({ color: 0xf2c623 }),
drillDark: new THREE.MeshBasicMaterial({ color: 0x27322a }),
ghost: new THREE.MeshBasicMaterial({
color: 0x8e9890,
transparent: true,
opacity: 0.38,
depthWrite: false
})
};
const PART_TOP = 0.34;
const PART_WIDTH = 12;
const PART_DEPTH = 8;
function makeBox(parent, sx, sy, sz, x, y, z, material, rotationY = 0) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.rotation.y = rotationY;
parent.add(mesh);
return mesh;
}
function clearGroup(group) {
while (group.children.length) {
group.remove(group.children[0]);
}
}
function addRail(parent, a, b, y, material, thickness = 0.07) {
const dx = b.x - a.x;
const dz = b.z - a.z;
const length = Math.hypot(dx, dz);
if (length < 0.001) return;
return makeBox(
parent,
length,
0.035,
thickness,
(a.x + b.x) * 0.5,
y,
(a.z + b.z) * 0.5,
material,
-Math.atan2(dz, dx)
);
}
function addSquareOutline(parent, x, z, size, y, material, bar = 0.055) {
makeBox(parent, size, 0.035, bar, x, y, z + (size - bar) * 0.5, material);
makeBox(parent, size, 0.035, bar, x, y, z - (size - bar) * 0.5, material);
makeBox(parent, bar, 0.035, size, x + (size - bar) * 0.5, y, z, material);
makeBox(parent, bar, 0.035, size, x - (size - bar) * 0.5, y, z, material);
}
function createTileField({
columns,
rows,
cellSize,
xStart,
zStart,
height,
y,
material,
colorFor
}) {
const count = columns * rows;
const mesh = new THREE.InstancedMesh(unitBox, material, count);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
let index = 0;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const x = xStart + column * cellSize;
const z = zStart + row * cellSize;
dummy.position.set(x, y, z);
dummy.scale.set(cellSize * 0.955, height, cellSize * 0.955);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
color.set(colorFor(column, row));
mesh.setColorAt(index, color);
index++;
}
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
const ground = makeBox(scene, 80, 0.2, 80, 0, -0.8, 0, materials.ground);
ground.receiveShadow = true;
makeBox(scene, 18.4, 0.22, 14.4, 0, -0.63, 0, materials.benchBase);
createTileField({
columns: 18,
rows: 14,
cellSize: 1,
xStart: -8.5,
zStart: -6.5,
height: 0.34,
y: -0.38,
material: materials.bench,
colorFor: (column, row) => {
const checker = (column + row) % 2;
const wear = (column * 7 + row * 11) % 13;
if (wear === 0) return 0xb7ad99;
return checker ? 0xcfc4af : 0xc3b8a3;
}
});
createTileField({
columns: PART_WIDTH,
rows: PART_DEPTH,
cellSize: 1,
xStart: -5.5,
zStart: -3.5,
height: 0.56,
y: 0.05,
material: materials.part,
colorFor: (column, row) => {
const x = column - 5.5;
const z = row - 3.5;
// Fixed physical feature: the dark keyway gives the part a visible orientation.
if ((x === 1.5 || x === 2.5) && z === -2.5) return 0x44594b;
const checker = (column + row) % 2;
const variation = (column * 5 + row * 3) % 9;
if (variation === 0) return 0xaabfb0;
return checker ? 0xc2d1c5 : 0xb8c9bd;
}
});
const datumGroup = new THREE.Group();
const dimensionGroup = new THREE.Group();
scene.add(datumGroup, dimensionGroup);
const markerGroup = new THREE.Group();
const ghostGroup = new THREE.Group();
scene.add(markerGroup, ghostGroup);
function buildCurrentMarker() {
clearGroup(markerGroup);
// Surface hole and target cross.
makeBox(markerGroup, 0.30, 0.035, 0.30, 0, 0.018, 0, materials.drillDark);
addSquareOutline(markerGroup, 0, 0, 0.48, 0.065, materials.drillYellow, 0.055);
// Voxel drill stem.
for (let i = 0; i < 5; i++) {
const mat = i % 2 === 0 ? materials.drillYellow : materials.drillDark;
const size = i === 4 ? 0.12 : 0.17;
makeBox(markerGroup, size, 0.16, size, 0, 0.23 + i * 0.18, 0, mat);
}
makeBox(markerGroup, 0.08, 0.12, 0.08, 0, 1.06, 0, materials.drillYellow);
}
function buildGhostMarker() {
clearGroup(ghostGroup);
addSquareOutline(ghostGroup, 0, 0, 0.48, 0.055, materials.ghost, 0.055);
makeBox(ghostGroup, 0.10, 0.76, 0.10, 0, 0.43, 0, materials.ghost);
makeBox(ghostGroup, 0.18, 0.10, 0.18, 0, 0.84, 0, materials.ghost);
}
buildCurrentMarker();
buildGhostMarker();
const edges = {
left: {
letter: "A",
name: "LEFT",
axis: "X = −6.00",
origin: { x: -6, z: -4 },
end: { x: -6, z: 4 },
along: { x: 0, z: 1 },
inward: { x: 1, z: 0 },
labelPosition: { x: -6.85, y: 0.72, z: 0 }
},
right: {
letter: "B",
name: "RIGHT",
axis: "X = +6.00",
origin: { x: 6, z: -4 },
end: { x: 6, z: 4 },
along: { x: 0, z: 1 },
inward: { x: -1, z: 0 },
labelPosition: { x: 6.85, y: 0.72, z: 0 }
},
front: {
letter: "C",
name: "FRONT",
axis: "Z = +4.00",
origin: { x: -6, z: 4 },
end: { x: 6, z: 4 },
along: { x: 1, z: 0 },
inward: { x: 0, z: -1 },
labelPosition: { x: 0, y: 0.72, z: 4.85 }
},
back: {
letter: "D",
name: "BACK",
axis: "Z = −4.00",
origin: { x: -6, z: -4 },
end: { x: 6, z: -4 },
along: { x: 1, z: 0 },
inward: { x: 0, z: 1 },
labelPosition: { x: 0, y: 0.72, z: -4.85 }
}
};
const state = {
edge: "left",
offset1: 3.5,
offset2: 3.2,
target: { x: -2.8, z: -0.5 },
previous: null,
previousEdge: null
};
let markerAnimation = null;
let dimensionPositions = {
first: { x: 0, y: 0, z: 0 },
second: { x: 0, y: 0, z: 0 },
datum: { x: 0, y: 0, z: 0 }
};
function calculatePoint(edgeName) {
const edge = edges[edgeName];
return {
x:
edge.origin.x +
edge.along.x * state.offset1 +
edge.inward.x * state.offset2,
z:
edge.origin.z +
edge.along.z * state.offset1 +
edge.inward.z * state.offset2
};
}
function formatNumber(value) {
const rounded = Math.abs(value) < 0.0001 ? 0 : value;
const prefix = rounded < 0 ? "−" : "+";
return prefix + Math.abs(rounded).toFixed(2);
}
function formatRaw(value) {
const rounded = Math.abs(value) < 0.0001 ? 0 : value;
return (rounded < 0 ? "−" : "") + Math.abs(rounded).toFixed(2);
}
function distanceBetween(a, b) {
return Math.hypot(a.x - b.x, a.z - b.z);
}
function buildMeasurementGeometry() {
clearGroup(datumGroup);
clearGroup(dimensionGroup);
const edge = edges[state.edge];
const origin = edge.origin;
const elbow = {
x: origin.x + edge.along.x * state.offset1,
z: origin.z + edge.along.z * state.offset1
};
// Active datum edge.
addRail(
datumGroup,
{ x: origin.x, z: origin.z },
{ x: edge.end.x, z: edge.end.z },
PART_TOP + 0.045,
materials.datum,
0.095
);
// Pixel-like datum ticks along the selected edge.
const edgeLength = Math.hypot(edge.end.x - origin.x, edge.end.z - origin.z);
const tickCount = Math.round(edgeLength);
for (let i = 0; i <= tickCount; i++) {
const t = i / tickCount;
const x = origin.x + (edge.end.x - origin.x) * t;
const z = origin.z + (edge.end.z - origin.z) * t;
makeBox(datumGroup, 0.14, 0.05, 0.14, x, PART_TOP + 0.075, z, materials.datum);
}
// Marked origin corner.
addSquareOutline(datumGroup, origin.x, origin.z, 0.43, PART_TOP + 0.085, materials.datum, 0.06);
makeBox(datumGroup, 0.12, 0.06, 0.12, origin.x, PART_TOP + 0.10, origin.z, materials.datum);
// Two coral offset rails.
addRail(dimensionGroup, origin, elbow, PART_TOP + 0.10, materials.offset, 0.065);
addRail(dimensionGroup, elbow, state.target, PART_TOP + 0.10, materials.offset, 0.065);
makeBox(dimensionGroup, 0.13, 0.06, 0.13, elbow.x, PART_TOP + 0.12, elbow.z, materials.offset);
makeBox(dimensionGroup, 0.13, 0.06, 0.13, state.target.x, PART_TOP + 0.12, state.target.z, materials.offset);
// Small square arrowheads at the ends of each dimension.
makeBox(dimensionGroup, 0.20, 0.06, 0.20, origin.x, PART_TOP + 0.13, origin.z, materials.offset);
makeBox(dimensionGroup, 0.20, 0.06, 0.20, elbow.x, PART_TOP + 0.13, elbow.z, materials.offset);
makeBox(dimensionGroup, 0.20, 0.06, 0.20, state.target.x, PART_TOP + 0.13, state.target.z, materials.offset);
dimensionPositions = {
first: {
x: (origin.x + elbow.x) * 0.5,
y: PART_TOP + 0.42,
z: (origin.z + elbow.z) * 0.5
},
second: {
x: (elbow.x + state.target.x) * 0.5,
y: PART_TOP + 0.42,
z: (elbow.z + state.target.z) * 0.5
},
datum: {
x: origin.x,
y: PART_TOP + 0.92,
z: origin.z
}
};
}
function animateMarker(to) {
markerAnimation = {
from: { x: markerGroup.position.x, z: markerGroup.position.z },
to: { x: to.x, z: to.z },
start: performance.now(),
duration: 680
};
}
function updateUI() {
const edge = edges[state.edge];
document.querySelectorAll(".edge-button").forEach((button) => {
button.classList.toggle("active", button.dataset.edge === state.edge);
});
document.getElementById("calcDatum").textContent = `${edge.letter} / ${edge.name}`;
document.getElementById("equationText").textContent =
`P = O + ${state.offset1.toFixed(2)}u + ${state.offset2.toFixed(2)}n`;
document.getElementById("originText").textContent =
`(${formatRaw(edge.origin.x)}, ${formatRaw(edge.origin.z)})`;
document.getElementById("alongText").textContent =
`(${formatRaw(edge.along.x)}, ${formatRaw(edge.along.z)})`;
document.getElementById("inwardText").textContent =
`(${formatRaw(edge.inward.x)}, ${formatRaw(edge.inward.z)})`;
document.getElementById("resultText").textContent =
`(${formatRaw(state.target.x)}, ${formatRaw(state.target.z)})`;
document.getElementById("pointDatum").textContent =
`From datum ${edge.letter} / ${edge.name}`;
document.getElementById("pointX").textContent = formatNumber(state.target.x);
document.getElementById("pointZ").textContent = formatNumber(state.target.z);
document.getElementById("datumLabel").textContent = `${edge.letter} / DATUM`;
document.getElementById("dimensionLabel1").textContent = `1 · ${state.offset1.toFixed(2)}`;
document.getElementById("dimensionLabel2").textContent = `2 · ${state.offset2.toFixed(2)}`;
for (const key of Object.keys(edges)) {
const label = document.getElementById(`edgeLabel${edges[key].letter}`);
const isActive = key === state.edge;
label.classList.toggle("active", isActive);
label.textContent = isActive
? `${edges[key].letter} / DATUM`
: `${edges[key].letter} / ${edges[key].name}`;
}
const comparisonEyebrow = document.getElementById("comparisonEyebrow");
const comparisonTitle = document.getElementById("comparisonTitle");
const comparisonDatum = document.getElementById("comparisonDatum");
const comparisonDetails = document.getElementById("comparisonDetails");
const comparisonPrompt = document.getElementById("comparisonPrompt");
if (state.previous && state.previousEdge) {
const oldEdge = edges[state.previousEdge];
const shift = distanceBetween(state.previous, state.target);
comparisonEyebrow.textContent = "Same numbers / new datum";
comparisonTitle.textContent = `Δ ${shift.toFixed(2)} BLOCKS`;
comparisonDatum.textContent =
`${oldEdge.letter} ${oldEdge.name} → ${edge.letter} ${edge.name}`;
comparisonDetails.hidden = false;
comparisonPrompt.hidden = true;
document.getElementById("previousCoordinates").textContent =
`${oldEdge.letter} (${formatNumber(state.previous.x)}, ${formatNumber(state.previous.z)})`;
document.getElementById("currentCoordinates").textContent =
`${edge.letter} (${formatNumber(state.target.x)}, ${formatNumber(state.target.z)})`;
} else {
comparisonEyebrow.textContent = "Try the reference change";
comparisonTitle.textContent = "KEEP THE NUMBERS";
comparisonDatum.textContent = "Choose another edge";
comparisonDetails.hidden = true;
comparisonPrompt.hidden = false;
comparisonPrompt.innerHTML =
`Select <b>B / RIGHT</b>. Both offset values will stay unchanged. ` +
`Watch the drill marker land somewhere else.`;
}
}
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
window.clearTimeout(showToast.timer);
showToast.timer = window.setTimeout(() => toast.classList.remove("show"), 1450);
}
function flashOffsets() {
document.getElementById("offsetControl1").classList.remove("flash");
document.getElementById("offsetControl2").classList.remove("flash");
// Force restart of the CSS animation.
void document.getElementById("offsetControl1").offsetWidth;
document.getElementById("offsetControl1").classList.add("flash");
document.getElementById("offsetControl2").classList.add("flash");
}
function selectEdge(edgeName) {
if (edgeName === state.edge) return;
state.previous = { ...state.target };
state.previousEdge = state.edge;
state.edge = edgeName;
state.target = calculatePoint(state.edge);
ghostGroup.visible = true;
ghostGroup.position.set(
state.previous.x,
PART_TOP + 0.025,
state.previous.z
);
animateMarker(state.target);
buildMeasurementGeometry();
updateUI();
flashOffsets();
showToast("Reference changed — offsets held");
}
function setOffset(value, source) {
let next = Number.parseFloat(value);
if (!Number.isFinite(next)) next = 0;
next = THREE.MathUtils.clamp(next, 0, 8);
state[source] = next;
state.previous = null;
state.previousEdge = null;
ghostGroup.visible = false;
const numberInput = document.getElementById(source === "offset1" ? "offset1" : "offset2");
const rangeInput = document.getElementById(source === "offset1" ? "offset1Range" : "offset2Range");
if (document.activeElement !== numberInput) numberInput.value = next.toFixed(2);
rangeInput.value = next;
state.target = calculatePoint(state.edge);
animateMarker(state.target);
buildMeasurementGeometry();
updateUI();
}
document.querySelectorAll(".edge-button").forEach((button) => {
button.addEventListener("click", () => selectEdge(button.dataset.edge));
});
const offset1 = document.getElementById("offset1");
const offset2 = document.getElementById("offset2");
const offset1Range = document.getElementById("offset1Range");
const offset2Range = document.getElementById("offset2Range");
offset1.addEventListener("input", (event) => setOffset(event.target.value, "offset1"));
offset2.addEventListener("input", (event) => setOffset(event.target.value, "offset2"));
offset1Range.addEventListener("input", (event) => setOffset(event.target.value, "offset1"));
offset2Range.addEventListener("input", (event) => setOffset(event.target.value, "offset2"));
[offset1, offset2].forEach((input) => {
input.addEventListener("change", () => {
const parsed = Number.parseFloat(input.value);
const clamped = THREE.MathUtils.clamp(Number.isFinite(parsed) ? parsed : 0, 0, 8);
input.value = clamped.toFixed(2);
setOffset(clamped, input === offset1 ? "offset1" : "offset2");
});
});
document.getElementById("resetDemo").addEventListener("click", () => {
state.edge = "left";
state.offset1 = 3.5;
state.offset2 = 3.2;
state.previous = null;
state.previousEdge = null;
state.target = calculatePoint(state.edge);
offset1.value = "3.50";
offset2.value = "3.20";
offset1Range.value = "3.5";
offset2Range.value = "3.2";
ghostGroup.visible = false;
animateMarker(state.target);
buildMeasurementGeometry();
updateUI();
showToast("Demonstration reset");
});
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.sin(yaw) * Math.cos(pitch),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(cameraTarget);
}
function updateProjection() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
const verticalSpan = cameraState.zoom * Math.max(12.6, 19 / aspect);
camera.left = (-verticalSpan * aspect) / 2;
camera.right = (verticalSpan * aspect) / 2;
camera.top = verticalSpan / 2;
camera.bottom = -verticalSpan / 2;
camera.updateProjectionMatrix();
}
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
updateProjection();
}
new ResizeObserver(resize).observe(viewport);
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.004,
0.34,
1.28
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(event.deltaY * 0.001),
0.62,
1.65
);
updateProjection();
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
cameraState.yaw = 0.72;
cameraState.pitch = 0.76;
cameraState.zoom = 1;
updateCamera();
updateProjection();
});
const projected = new THREE.Vector3();
function placeLabel(element, position, enabled = true) {
if (!enabled) {
element.style.display = "none";
return;
}
projected.set(position.x, position.y, position.z).project(camera);
const visible = projected.z >= -1 && projected.z <= 1;
element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * viewport.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * viewport.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
for (const key of Object.keys(edges)) {
const edge = edges[key];
const label = document.getElementById(`edgeLabel${edge.letter}`);
placeLabel(label, edge.labelPosition);
}
placeLabel(
document.getElementById("datumLabel"),
dimensionPositions.datum
);
placeLabel(
document.getElementById("dimensionLabel1"),
dimensionPositions.first
);
placeLabel(
document.getElementById("dimensionLabel2"),
dimensionPositions.second
);
placeLabel(
document.getElementById("drillLabel"),
{
x: markerGroup.position.x,
y: PART_TOP + 1.35,
z: markerGroup.position.z
}
);
placeLabel(
document.getElementById("ghostLabel"),
{
x: ghostGroup.position.x,
y: PART_TOP + 1.08,
z: ghostGroup.position.z
},
ghostGroup.visible
);
placeLabel(
document.getElementById("featureLabel"),
{
x: 2,
y: PART_TOP + 0.22,
z: -2.5
}
);
}
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
markerGroup.position.set(state.target.x, PART_TOP + 0.02, state.target.z);
ghostGroup.visible = false;
buildMeasurementGeometry();
updateUI();
updateCamera();
resize();
function animate(now) {
requestAnimationFrame(animate);
if (markerAnimation) {
const rawT = Math.min(1, (now - markerAnimation.start) / markerAnimation.duration);
const t = easeInOutCubic(rawT);
markerGroup.position.x = THREE.MathUtils.lerp(
markerAnimation.from.x,
markerAnimation.to.x,
t
);
markerGroup.position.z = THREE.MathUtils.lerp(
markerAnimation.from.z,
markerAnimation.to.z,
t
);
if (rawT >= 1) markerAnimation = null;
}
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```