Prompt specification
Build or customize the Three.js 3D scene "Stone template beside a carved 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: Stone template beside a carved block
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/stone-template-beside-a-carved-block-x2345
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a Gothic stone-carving template and block. Place a full-size geometric template beside a partially carved stone block. Show matching curves and a clearly marked intended position without reproducing an entire cathedral component. Voxel style.
Working Three.js Starter (stone-template-beside-a-carved-block-x2345):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gothic Trefoil Carving Template — Voxel Workshop</title>
<style>
:root {
--teal: #65eadc;
--teal-soft: rgba(101, 234, 220, 0.16);
--amber: #ffb547;
--amber-soft: rgba(255, 181, 71, 0.15);
--ink: #f1eee7;
--muted: #a7aaa8;
--panel: rgba(20, 24, 28, 0.84);
--line: rgba(255, 255, 255, 0.12);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #15191d;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.topbar {
position: fixed;
top: 22px;
left: 24px;
right: 24px;
z-index: 5;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.title-block {
max-width: 570px;
padding: 17px 20px 16px;
background: linear-gradient(135deg, rgba(18,22,26,.92), rgba(18,22,26,.66));
border: 1px solid var(--line);
border-left: 3px solid var(--teal);
border-radius: 4px;
box-shadow: 0 16px 40px rgba(0,0,0,.22);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: .2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(22px, 2.3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: .015em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
min-width: 225px;
padding: 13px 15px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 4px;
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
margin: 7px 0;
color: #d8d8d3;
font-size: 11px;
letter-spacing: .04em;
}
.swatch {
width: 27px;
height: 5px;
flex: 0 0 auto;
border-radius: 1px;
}
.swatch.master {
background: var(--teal);
box-shadow: 0 0 12px rgba(101,234,220,.45);
}
.swatch.target {
height: 4px;
background: repeating-linear-gradient(
90deg,
var(--amber) 0 5px,
transparent 5px 9px
);
}
.swatch.cut {
height: 9px;
background: #55534e;
border-top: 2px solid #8a867d;
box-shadow: inset 0 -3px #292826;
}
.legend-note {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #8f9492;
font-size: 10px;
line-height: 1.4;
}
.controls {
position: fixed;
z-index: 6;
right: 24px;
bottom: 22px;
width: 255px;
padding: 15px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 4px;
backdrop-filter: blur(12px);
box-shadow: 0 18px 44px rgba(0,0,0,.28);
}
.control-heading {
margin-bottom: 11px;
color: #8d9290;
font-size: 9px;
font-weight: 800;
letter-spacing: .18em;
text-transform: uppercase;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 6px;
margin-bottom: 13px;
}
button {
appearance: none;
border: 1px solid rgba(255,255,255,.14);
border-radius: 3px;
padding: 8px 5px;
background: rgba(255,255,255,.055);
color: #e7e8e4;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: .06em;
cursor: pointer;
transition: background .18s, border-color .18s, color .18s;
}
button:hover {
background: var(--teal-soft);
border-color: rgba(101,234,220,.48);
color: var(--teal);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 10px 0;
color: #c6c9c6;
font-size: 11px;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--teal);
cursor: pointer;
}
.range-head {
display: flex;
justify-content: space-between;
margin: 14px 0 7px;
color: #c6c9c6;
font-size: 10px;
}
#progressText {
color: var(--amber);
font-weight: 800;
}
input[type="range"] {
width: 100%;
accent-color: var(--amber);
cursor: pointer;
}
.hint {
margin-top: 12px;
color: #7e8583;
font-size: 9px;
line-height: 1.45;
}
.world-label {
position: fixed;
z-index: 4;
padding: 7px 9px;
transform: translate(-50%, -100%);
border: 1px solid rgba(255,255,255,.18);
border-radius: 3px;
background: rgba(14,18,21,.82);
color: #e8e9e5;
font-size: 9px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(8px);
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 18px;
background: currentColor;
opacity: .6;
}
#templateLabel {
color: var(--teal);
border-color: rgba(101,234,220,.3);
}
#blockLabel {
color: #ddd8cd;
}
#targetLabel {
color: var(--amber);
border-color: rgba(255,181,71,.34);
background: rgba(40,29,15,.84);
}
.corner-note {
position: fixed;
z-index: 3;
left: 24px;
bottom: 22px;
max-width: 340px;
padding: 10px 12px;
border-left: 2px solid rgba(255,181,71,.75);
background: rgba(16,20,23,.68);
color: #8f9592;
font-size: 10px;
line-height: 1.45;
pointer-events: none;
backdrop-filter: blur(8px);
}
@media (max-width: 820px) {
.topbar { top: 12px; left: 12px; right: 12px; }
.title-block { padding: 13px 15px; max-width: 70%; }
.legend { display: none; }
.subtitle { display: none; }
.controls {
right: 12px;
bottom: 12px;
width: 220px;
padding: 12px;
}
.corner-note { display: none; }
.world-label { font-size: 8px; }
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div class="title-block">
<div class="eyebrow">Masonry study / isolated trefoil unit</div>
<h1>Gothic Carving Template</h1>
<p class="subtitle">
A full-size geometric master beside a partially cut stone block.
The isolated ornamental unit is shown at 1:1 scale—not as part of a cathedral elevation.
</p>
</div>
<div class="legend">
<div class="legend-row">
<span class="swatch master"></span>
Solid teal / master curve
</div>
<div class="legend-row">
<span class="swatch target"></span>
Amber / intended position
</div>
<div class="legend-row">
<span class="swatch cut"></span>
Recess / completed cut
</div>
<div class="legend-note">
Both curves share the same origin and scale. Amber markers project the
remaining geometry onto the stone.
</div>
</div>
</header>
<div id="templateLabel" class="world-label">Full-size geometric template</div>
<div id="blockLabel" class="world-label">Stone block · <span id="blockProgress">44%</span> cut</div>
<div id="targetLabel" class="world-label">Intended cut position</div>
<aside class="controls">
<div class="control-heading">Workshop view</div>
<div class="button-row">
<button id="frontBtn" type="button">FRONT</button>
<button id="angleBtn" type="button">3/4 VIEW</button>
<button id="resetBtn" type="button">RESET</button>
</div>
<label class="toggle">
Intended-position overlay
<input id="targetToggle" type="checkbox" checked />
</label>
<label class="toggle">
Template measuring grid
<input id="gridToggle" type="checkbox" checked />
</label>
<div class="range-head">
<span>Outer contour cut</span>
<span id="progressText">44%</span>
</div>
<input id="progressRange" type="range" min="0" max="100" value="44" />
<div class="hint">
Drag to orbit · wheel to zoom · double-click to reset.
The cut slider reveals how the master curve transfers to the block.
</div>
</aside>
<div class="corner-note">
<strong>Reading the scene:</strong> the teal template is the complete trefoil quarry unit.
The amber dotted geometry marks the exact future cut. The darker voxel recess is the portion already carved.
</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 host = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x15191d);
scene.fog = new THREE.Fog(0x15191d, 28, 58);
const camera = new THREE.PerspectiveCamera(40, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
host.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xb8d4df, 0x322a22, 1.6);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffe0b5, 4.0);
key.position.set(-7, 13, 15);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -18;
key.shadow.camera.right = 18;
key.shadow.camera.top = 15;
key.shadow.camera.bottom = -12;
key.shadow.camera.near = 1;
key.shadow.camera.far = 45;
key.shadow.bias = -0.0004;
scene.add(key);
const fill = new THREE.DirectionalLight(0x80c9dc, 1.8);
fill.position.set(12, 4, 8);
scene.add(fill);
const rim = new THREE.DirectionalLight(0x62e5d5, 1.2);
rim.position.set(-8, 3, -9);
scene.add(rim);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0x202429,
roughness: 1,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -6.18;
floor.receiveShadow = true;
scene.add(floor);
const workshopGrid = new THREE.GridHelper(60, 60, 0x485055, 0x30363a);
workshopGrid.position.y = -6.165;
workshopGrid.material.transparent = true;
workshopGrid.material.opacity = 0.24;
scene.add(workshopGrid);
// ------------------------------------------------------------
// Shared trefoil geometry
// The template and block use these exact same points.
// ------------------------------------------------------------
const SHAPE_SCALE = 1.38;
const LOBE_ANGLES = [
Math.PI / 2,
Math.PI / 2 + Math.PI * 2 / 3,
Math.PI / 2 + Math.PI * 4 / 3
];
function outerRadius(theta) {
return (1.55 + 0.90 * Math.cos(3 * (theta - Math.PI / 2))) * SHAPE_SCALE;
}
function innerRadius(theta) {
return (0.82 + 0.46 * Math.cos(3 * (theta - Math.PI / 2))) * SHAPE_SCALE;
}
function makeClosedCurve(count, radiusFunction) {
const points = [];
for (let i = 0; i < count; i++) {
const theta = i / count * Math.PI * 2;
const radius = radiusFunction(theta);
points.push(new THREE.Vector2(
Math.cos(theta) * radius,
Math.sin(theta) * radius
));
}
return points;
}
const outerCurve = makeClosedCurve(260, outerRadius);
const innerCurve = makeClosedCurve(220, innerRadius);
const spokeCurves = LOBE_ANGLES.map((angle) => {
const points = [];
const radius = outerRadius(angle);
for (let i = 0; i <= 40; i++) {
const t = i / 40;
points.push(new THREE.Vector2(
Math.cos(angle) * radius * t,
Math.sin(angle) * radius * t
));
}
return points;
});
function resampleClosed(points, spacing) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const length = a.distanceTo(b);
lengths.push(length);
total += length;
}
const count = Math.max(3, Math.floor(total / spacing));
const result = [];
let segment = 0;
let accumulated = 0;
for (let i = 0; i < count; i++) {
const distance = i / count * total;
while (
segment < lengths.length - 1 &&
accumulated + lengths[segment] < distance
) {
accumulated += lengths[segment];
segment++;
}
const local = lengths[segment] > 0
? (distance - accumulated) / lengths[segment]
: 0;
const a = points[segment];
const b = points[(segment + 1) % points.length];
result.push(new THREE.Vector2().lerpVectors(a, b, local));
}
return result;
}
function resampleOpen(points, spacing) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
const count = Math.max(2, Math.floor(total / spacing));
const result = [];
let segment = 0;
let accumulated = 0;
for (let i = 0; i < count; i++) {
const distance = i / count * total;
while (
segment < lengths.length - 1 &&
accumulated + lengths[segment] < distance
) {
accumulated += lengths[segment];
segment++;
}
const local = lengths[segment] > 0
? (distance - accumulated) / lengths[segment]
: 0;
result.push(new THREE.Vector2().lerpVectors(
points[segment],
points[segment + 1],
local
));
}
return result;
}
function createVoxelPath(points, color, cubeSize, z, spacing, emissive = 0x000000) {
const geometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
const material = new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: emissive ? 0.75 : 0,
roughness: 0.72,
metalness: 0.08
});
const mesh = new THREE.InstancedMesh(geometry, material, points.length);
const matrix = new THREE.Matrix4();
points.forEach((point, index) => {
matrix.makeTranslation(point.x, point.y, z);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// ------------------------------------------------------------
// Full-size physical template
// ------------------------------------------------------------
const templateGroup = new THREE.Group();
templateGroup.position.x = -6.2;
scene.add(templateGroup);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x687176,
roughness: 0.48,
metalness: 0.72
});
const panel = new THREE.Mesh(
new THREE.PlaneGeometry(9.15, 9.15),
new THREE.MeshBasicMaterial({
color: 0x75b5b5,
transparent: true,
opacity: 0.065,
side: THREE.DoubleSide,
depthWrite: false
})
);
panel.position.z = -0.58;
templateGroup.add(panel);
const frameParts = [
[0, 4.58, -0.38, 9.34, 0.18, 0.34],
[0, -4.58, -0.38, 9.34, 0.18, 0.34],
[-4.58, 0, -0.38, 0.18, 9.34, 0.34],
[4.58, 0, -0.38, 0.18, 9.34, 0.34]
];
const frameGeometry = new THREE.BoxGeometry(1, 1, 1);
frameParts.forEach(([x, y, z, sx, sy, sz]) => {
const bar = new THREE.Mesh(frameGeometry, frameMaterial);
bar.position.set(x, y, z);
bar.scale.set(sx, sy, sz);
bar.castShadow = true;
bar.receiveShadow = true;
templateGroup.add(bar);
});
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x394047,
roughness: 0.62,
metalness: 0.55
});
[-3.95, 3.95].forEach((x) => {
const leg = new THREE.Mesh(new THREE.BoxGeometry(0.22, 1.65, 0.25), standMaterial);
leg.position.set(x, -5.4, -0.38);
leg.castShadow = true;
templateGroup.add(leg);
const foot = new THREE.Mesh(new THREE.BoxGeometry(1.15, 0.16, 1.25), standMaterial);
foot.position.set(x, -6.07, -0.15);
foot.castShadow = true;
templateGroup.add(foot);
});
const templateGridGroup = new THREE.Group();
templateGroup.add(templateGridGroup);
const gridPositions = [];
for (let value = -4.4; value <= 4.41; value += 0.88) {
gridPositions.push(
value, -4.4, -0.51, value, 4.4, -0.51,
-4.4, value, -0.51, 4.4, value, -0.51
);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const templateGrid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x78bdb8,
transparent: true,
opacity: 0.16
})
);
templateGridGroup.add(templateGrid);
const masterOuter = createVoxelPath(
resampleClosed(outerCurve, 0.13),
0x64e7da,
0.19,
0.02,
0.13,
0x0b5552
);
templateGroup.add(masterOuter);
const masterInner = createVoxelPath(
resampleClosed(innerCurve, 0.13),
0xc0fff5,
0.16,
0.04,
0.13,
0x174e49
);
templateGroup.add(masterInner);
spokeCurves.forEach((curve) => {
const spoke = createVoxelPath(
resampleOpen(curve, 0.13),
0x8ff0e6,
0.14,
0.025,
0.13,
0x0b4643
);
templateGroup.add(spoke);
});
// Ruler ticks along the frame.
const tickPositions = [];
for (let i = -10; i <= 10; i++) {
const x = i * 0.44;
const length = i % 5 === 0 ? 0.28 : 0.15;
tickPositions.push(
x, 4.46, -0.15, x, 4.46 - length, -0.15,
x, -4.46, -0.15, x, -4.46 + length, -0.15
);
}
const ticksGeometry = new THREE.BufferGeometry();
ticksGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickPositions, 3)
);
const ticks = new THREE.LineSegments(
ticksGeometry,
new THREE.LineBasicMaterial({ color: 0x9aacaa, transparent: true, opacity: 0.62 })
);
templateGroup.add(ticks);
// ------------------------------------------------------------
// Stone block
// ------------------------------------------------------------
const blockGroup = new THREE.Group();
blockGroup.position.x = 5.7;
scene.add(blockGroup);
const GRID = 13;
const SPACING = 0.88;
const VOXEL_SIZE = 0.82;
const BLOCK_CENTER_Z = 0;
let carveProgress = 0.44;
let blockMesh = null;
const blockGeometry = new THREE.BoxGeometry(VOXEL_SIZE, VOXEL_SIZE, VOXEL_SIZE);
const blockMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0
});
function deterministicNoise(i, j, k) {
const value = Math.sin(i * 127.1 + j * 311.7 + k * 74.7) * 43758.5453;
return value - Math.floor(value);
}
function nearestOuterPoint(x, y) {
let minimumDistance = Infinity;
let nearestTheta = 0;
for (let i = 0; i < outerCurve.length; i++) {
const point = outerCurve[i];
const dx = x - point.x;
const dy = y - point.y;
const distance = dx * dx + dy * dy;
if (distance < minimumDistance) {
minimumDistance = distance;
nearestTheta = i / outerCurve.length * Math.PI * 2;
}
}
const thetaDistance = Math.atan2(
Math.sin(nearestTheta - Math.PI / 2),
Math.cos(nearestTheta - Math.PI / 2)
);
const normalizedArc = (thetaDistance + Math.PI * 2) % (Math.PI * 2);
return {
distance: Math.sqrt(minimumDistance),
arc: normalizedArc,
carved: normalizedArc <= carveProgress * Math.PI * 2
};
}
function rebuildStoneBlock() {
const instances = [];
const half = (GRID - 1) / 2;
for (let k = 0; k < 3; k++) {
for (let j = 0; j < GRID; j++) {
for (let i = 0; i < GRID; i++) {
const x = (i - half) * SPACING;
const y = (j - half) * SPACING;
const z = BLOCK_CENTER_Z + (k - 1) * SPACING;
const nearest = nearestOuterPoint(x, y);
const inGroove = nearest.distance < 0.52 && nearest.carved;
const behindGroove = nearest.distance < 0.56 && nearest.carved;
// Only the front layer is cut away. The darker middle layer
// remains as the recessed floor of the groove.
if (k === 2 && inGroove) continue;
const noise = deterministicNoise(i, j, k);
let shade = 0.86 + noise * 0.16;
if (k === 0) shade *= 0.72;
if (k === 1 && behindGroove) shade *= 0.46;
else if (k === 1) shade *= 0.86;
const warm = 7 * (noise - 0.5);
instances.push({
x, y, z,
color: new THREE.Color(
(0.59 * shade) + warm * 0.015,
(0.575 * shade) + warm * 0.01,
(0.525 * shade)
)
});
}
}
}
if (blockMesh) {
blockGroup.remove(blockMesh);
}
blockMesh = new THREE.InstancedMesh(
blockGeometry,
blockMaterial,
instances.length
);
const matrix = new THREE.Matrix4();
instances.forEach((instance, index) => {
matrix.makeTranslation(instance.x, instance.y, instance.z);
blockMesh.setMatrixAt(index, matrix);
blockMesh.setColorAt(index, instance.color);
});
blockMesh.instanceMatrix.needsUpdate = true;
if (blockMesh.instanceColor) blockMesh.instanceColor.needsUpdate = true;
blockMesh.castShadow = true;
blockMesh.receiveShadow = true;
blockGroup.add(blockMesh);
document.getElementById("progressText").textContent =
`${Math.round(carveProgress * 100)}%`;
document.getElementById("blockProgress").textContent =
`${Math.round(carveProgress * 100)}%`;
}
rebuildStoneBlock();
// Block cradle and feet.
const cradleMaterial = new THREE.MeshStandardMaterial({
color: 0x4a3a2d,
roughness: 0.9,
metalness: 0.04
});
const cradle = new THREE.Mesh(
new THREE.BoxGeometry(8.6, 0.34, 2.8),
cradleMaterial
);
cradle.position.set(0, -5.91, 0);
cradle.castShadow = true;
cradle.receiveShadow = true;
blockGroup.add(cradle);
[-3.75, 3.75].forEach((x) => {
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.75, 0.26, 2.45),
cradleMaterial
);
foot.position.set(x, -6.08, 0);
foot.castShadow = true;
blockGroup.add(foot);
});
// ------------------------------------------------------------
// Amber target projection on the block
// ------------------------------------------------------------
const targetGroup = new THREE.Group();
blockGroup.add(targetGroup);
const targetMaterial = new THREE.MeshStandardMaterial({
color: 0xffb547,
emissive: 0xa24d05,
emissiveIntensity: 1.05,
transparent: true,
opacity: 0.92,
roughness: 0.48,
metalness: 0.05
});
function createDottedPath(points, size, z) {
const geometry = new THREE.BoxGeometry(size, size, size);
const mesh = new THREE.InstancedMesh(geometry, targetMaterial, points.length);
const matrix = new THREE.Matrix4();
points.forEach((point, index) => {
matrix.makeTranslation(point.x, point.y, z);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = false;
return mesh;
}
const targetOuter = createDottedPath(
resampleClosed(outerCurve, 0.30),
0.115,
1.36
);
const targetInner = createDottedPath(
resampleClosed(innerCurve, 0.30),
0.105,
1.37
);
targetGroup.add(targetOuter, targetInner);
spokeCurves.forEach((curve) => {
targetGroup.add(createDottedPath(
resampleOpen(curve, 0.29),
0.095,
1.38
));
});
// Corner brackets clearly define the intended placement envelope.
const bracketMaterial = new THREE.MeshStandardMaterial({
color: 0xffa62f,
emissive: 0x7f3600,
emissiveIntensity: 0.75,
transparent: true,
opacity: 0.78
});
const bracketGeometry = new THREE.BoxGeometry(1, 1, 1);
const bracketHalf = 4.0;
const bracketLength = 0.85;
const bracketThickness = 0.065;
function addBracket(x, y, sx, sy) {
const mesh = new THREE.Mesh(bracketGeometry, bracketMaterial);
mesh.position.set(x, y, 1.37);
mesh.scale.set(sx, sy, bracketThickness);
targetGroup.add(mesh);
}
[
[-bracketHalf, bracketHalf, 1, 1],
[bracketHalf, bracketHalf, -1, 1],
[-bracketHalf, -bracketHalf, 1, -1],
[bracketHalf, -bracketHalf, -1, -1]
].forEach(([x, y, sx, sy]) => {
addBracket(x + sx * bracketLength * 0.5, y, bracketLength, bracketThickness);
addBracket(x, y + sy * bracketLength * 0.5, bracketThickness, bracketLength);
});
// Faint center crosshair for registration.
const crossGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-4.35, 0, 1.35),
new THREE.Vector3(4.35, 0, 1.35),
new THREE.Vector3(0, -4.35, 1.35),
new THREE.Vector3(0, 4.35, 1.35)
]);
const crosshair = new THREE.LineSegments(
crossGeometry,
new THREE.LineDashedMaterial({
color: 0xffc574,
dashSize: 0.18,
gapSize: 0.14,
transparent: true,
opacity: 0.38
})
);
crosshair.computeLineDistances();
targetGroup.add(crosshair);
// ------------------------------------------------------------
// Small voxel stone chips around the working area
// ------------------------------------------------------------
const chipGeometry = new THREE.BoxGeometry(1, 1, 1);
const chipMaterial = new THREE.MeshStandardMaterial({
color: 0x8a857a,
roughness: 1
});
const chips = new THREE.InstancedMesh(chipGeometry, chipMaterial, 24);
const chipMatrix = new THREE.Matrix4();
const chipPosition = new THREE.Vector3();
const chipQuaternion = new THREE.Quaternion();
const chipScale = new THREE.Vector3();
for (let i = 0; i < 24; i++) {
const side = i < 16 ? -1 : 1;
const size = 0.10 + deterministicNoise(i, 9, 4) * 0.24;
chipPosition.set(
5.7 + side * (4.5 + deterministicNoise(i, 3, 1) * 4.0),
-6.02 + size * 0.45,
(deterministicNoise(i, 7, 2) - 0.5) * 5.2
);
chipQuaternion.setFromEuler(new THREE.Euler(
deterministicNoise(i, 2, 8) * 0.7,
deterministicNoise(i, 5, 3) * Math.PI,
deterministicNoise(i, 6, 4) * 0.7
));
chipScale.set(size, size * 0.75, size);
chipMatrix.compose(chipPosition, chipQuaternion, chipScale);
chips.setMatrixAt(i, chipMatrix);
}
chips.instanceMatrix.needsUpdate = true;
chips.castShadow = true;
chips.receiveShadow = true;
scene.add(chips);
// ------------------------------------------------------------
// Custom orbit controls — no external controls module
// ------------------------------------------------------------
const orbit = {
theta: 0.10,
phi: 0.07,
zoom: 1,
desiredTheta: 0.10,
desiredPhi: 0.07,
desiredZoom: 1,
dragging: false,
previousX: 0,
previousY: 0
};
function fittedDistance() {
const verticalDistance = 14.6 / (2 * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)));
const horizontalDistance = 26.2 /
(2 * Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * camera.aspect);
return Math.max(verticalDistance, horizontalDistance);
}
function updateCamera() {
orbit.theta += (orbit.desiredTheta - orbit.theta) * 0.12;
orbit.phi += (orbit.desiredPhi - orbit.phi) * 0.12;
orbit.zoom += (orbit.desiredZoom - orbit.zoom) * 0.12;
const radius = fittedDistance() * orbit.zoom;
const horizontalRadius = Math.cos(orbit.phi) * radius;
camera.position.set(
Math.sin(orbit.theta) * horizontalRadius,
Math.sin(orbit.phi) * radius,
Math.cos(orbit.theta) * horizontalRadius
);
camera.lookAt(0, -0.1, 0);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.previousX = event.clientX;
orbit.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.previousX;
const dy = event.clientY - orbit.previousY;
orbit.previousX = event.clientX;
orbit.previousY = event.clientY;
orbit.desiredTheta -= dx * 0.005;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi + dy * 0.004,
-0.58,
0.58
);
});
function endDrag(event) {
orbit.dragging = false;
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();
orbit.desiredZoom = THREE.MathUtils.clamp(
orbit.desiredZoom * Math.exp(event.deltaY * 0.001),
0.57,
1.75
);
}, { passive: false });
function resetView() {
orbit.desiredTheta = 0.10;
orbit.desiredPhi = 0.07;
orbit.desiredZoom = 1;
}
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("frontBtn").addEventListener("click", () => {
orbit.desiredTheta = 0;
orbit.desiredPhi = 0;
orbit.desiredZoom = 1;
});
document.getElementById("angleBtn").addEventListener("click", () => {
orbit.desiredTheta = 0.22;
orbit.desiredPhi = 0.13;
orbit.desiredZoom = 1;
});
document.getElementById("resetBtn").addEventListener("click", resetView);
document.getElementById("targetToggle").addEventListener("change", (event) => {
targetGroup.visible = event.target.checked;
});
document.getElementById("gridToggle").addEventListener("change", (event) => {
templateGridGroup.visible = event.target.checked;
});
document.getElementById("progressRange").addEventListener("input", (event) => {
carveProgress = Number(event.target.value) / 100;
rebuildStoneBlock();
});
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const templateLabel = document.getElementById("templateLabel");
const blockLabel = document.getElementById("blockLabel");
const targetLabel = document.getElementById("targetLabel");
const labelPoint = new THREE.Vector3();
function placeLabel(element, x, y, z) {
labelPoint.set(x, y, z).project(camera);
const screenX = (labelPoint.x * 0.5 + 0.5) * innerWidth;
const screenY = (-labelPoint.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${screenX}px`;
element.style.top = `${screenY}px`;
element.style.visibility = labelPoint.z < 1 ? "visible" : "hidden";
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
targetMaterial.opacity = 0.78 + Math.sin(elapsed * 2.1) * 0.14;
bracketMaterial.opacity = 0.62 + Math.sin(elapsed * 2.1 + 0.8) * 0.12;
placeLabel(templateLabel, -6.2, 4.96, 0);
placeLabel(blockLabel, 5.7, 5.96, 0);
placeLabel(targetLabel, 8.55, 3.85, 1.4);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```