Prompt specification
Build or customize the Three.js 3D scene "Test alternative reconstructions against evidence" 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: Test alternative reconstructions against evidence
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/test-alternative-reconstructions-against-evidence-x2260
Scene Description Prompt:
Test two low-poly roof reconstructions against excavated walls; highlight supported placements and mark uncertain details provisional. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (test-alternative-reconstructions-against-evidence-x2260):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Roof Fit Lab — Archaeological Reconstruction Test</title>
<style>
:root {
--ink: #202722;
--muted: #687169;
--paper: #e9e4d8;
--paper-deep: #d9d2c3;
--stage: #171c1a;
--green: #72d59b;
--green-dark: #397c57;
--amber: #f2b65f;
--amber-dark: #9a6528;
--red: #e77961;
--line: rgba(32, 39, 34, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: var(--stage);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
width: 100%;
height: 100%;
}
#panel {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 27px 25px 24px;
background:
linear-gradient(rgba(255, 255, 255, 0.16), transparent 170px),
var(--paper);
border-right: 1px solid rgba(255, 255, 255, 0.35);
box-shadow: 14px 0 35px rgba(0, 0, 0, 0.16);
}
.eyebrow {
margin-bottom: 13px;
color: #667067;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4vw, 47px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 em {
color: #5c675e;
font-weight: 400;
}
.intro {
margin: 18px 0 22px;
color: #566159;
font-size: 13px;
line-height: 1.55;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 22px 0 10px;
color: #5f6961;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.section-title::after {
content: "";
flex: 1;
height: 1px;
margin-left: 12px;
background: var(--line);
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr 1.15fr;
gap: 5px;
padding: 4px;
background: rgba(49, 59, 51, 0.09);
border: 1px solid rgba(49, 59, 51, 0.08);
border-radius: 8px;
}
.mode-btn {
min-height: 35px;
padding: 7px 6px;
border: 0;
border-radius: 5px;
background: transparent;
color: #59635c;
cursor: pointer;
font-size: 11px;
font-weight: 750;
transition: 160ms ease;
}
.mode-btn:hover {
background: rgba(255, 255, 255, 0.45);
color: var(--ink);
}
.mode-btn.active {
background: #263029;
color: #f5f1e7;
box-shadow: 0 4px 10px rgba(27, 34, 29, 0.17);
}
.candidate {
position: relative;
margin-bottom: 9px;
padding: 14px 14px 13px;
overflow: hidden;
background: rgba(255, 255, 255, 0.3);
border: 1px solid rgba(32, 39, 34, 0.1);
border-radius: 8px;
}
.candidate::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--green);
}
.candidate.provisional::before {
background: var(--amber);
}
.candidate-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.candidate-name {
margin: 0 0 4px;
font-size: 13px;
font-weight: 800;
}
.candidate-sub {
color: #6d756f;
font-size: 11px;
line-height: 1.35;
}
.fit-badge {
flex: 0 0 auto;
padding: 5px 7px;
color: #286642;
background: rgba(114, 213, 155, 0.22);
border: 1px solid rgba(57, 124, 87, 0.22);
border-radius: 999px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
}
.fit-badge.amber {
color: #80521f;
background: rgba(242, 182, 95, 0.22);
border-color: rgba(154, 101, 40, 0.25);
}
.fit-track {
height: 3px;
margin-top: 12px;
overflow: hidden;
background: rgba(32, 39, 34, 0.09);
border-radius: 4px;
}
.fit-track span {
display: block;
height: 100%;
background: var(--green-dark);
border-radius: inherit;
}
.candidate.provisional .fit-track span {
background: var(--amber-dark);
}
.metrics {
display: grid;
gap: 10px;
}
.metric-head {
display: flex;
justify-content: space-between;
gap: 10px;
margin-bottom: 5px;
font-size: 10px;
}
.metric-head span:first-child {
color: #59635c;
}
.metric-head span:last-child {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 800;
}
.metric-track {
height: 4px;
overflow: hidden;
background: rgba(32, 39, 34, 0.09);
border-radius: 4px;
}
.metric-fill {
width: 0;
height: 100%;
background: var(--green-dark);
border-radius: inherit;
transition: width 260ms ease, background 260ms ease;
}
.evidence-copy {
margin: 0;
padding: 12px 13px;
color: #59635b;
background: rgba(255, 255, 255, 0.28);
border: 1px solid rgba(32, 39, 34, 0.09);
border-radius: 7px;
font-size: 11px;
line-height: 1.5;
}
.legend {
display: grid;
gap: 9px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
color: #59635c;
font-size: 11px;
}
.swatch {
width: 10px;
height: 10px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 3px rgba(114, 213, 155, 0.14);
}
.swatch.amber {
background: var(--amber);
box-shadow: 0 0 0 3px rgba(242, 182, 95, 0.14);
}
.swatch.stone {
background: #b9af99;
box-shadow: 0 0 0 3px rgba(185, 175, 153, 0.14);
}
.data-note {
margin-top: 22px;
padding-top: 15px;
border-top: 1px solid var(--line);
color: #7a817a;
font-size: 9px;
line-height: 1.55;
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: var(--stage);
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.stage-top {
position: absolute;
top: 22px;
left: 24px;
right: 24px;
z-index: 3;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
}
.site-code {
color: rgba(236, 240, 233, 0.72);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
letter-spacing: 0.13em;
line-height: 1.7;
text-transform: uppercase;
}
.site-code strong {
display: block;
color: #f1eee5;
font-size: 12px;
letter-spacing: 0.08em;
}
.status-chip {
padding: 8px 11px;
color: #bceacb;
background: rgba(40, 80, 56, 0.66);
border: 1px solid rgba(114, 213, 155, 0.36);
border-radius: 999px;
backdrop-filter: blur(9px);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status-chip.provisional {
color: #ffe0ad;
background: rgba(105, 70, 28, 0.72);
border-color: rgba(242, 182, 95, 0.42);
}
.status-chip.overlay {
color: #f2e9d4;
background: rgba(66, 70, 62, 0.74);
border-color: rgba(242, 182, 95, 0.38);
}
.toolbar {
position: absolute;
z-index: 4;
right: 23px;
bottom: 24px;
display: flex;
gap: 5px;
padding: 5px;
background: rgba(18, 23, 21, 0.8);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
box-shadow: 0 9px 25px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(10px);
}
.toolbar button {
min-height: 32px;
padding: 7px 10px;
color: #cad0ca;
background: transparent;
border: 0;
border-radius: 5px;
cursor: pointer;
font-size: 10px;
font-weight: 750;
}
.toolbar button:hover {
color: white;
background: rgba(255, 255, 255, 0.09);
}
.hint {
position: absolute;
z-index: 2;
left: 24px;
bottom: 29px;
color: rgba(229, 235, 228, 0.48);
font-size: 10px;
letter-spacing: 0.025em;
pointer-events: none;
}
.compass {
position: absolute;
z-index: 2;
left: 25px;
top: 76px;
width: 38px;
height: 38px;
color: rgba(235, 239, 233, 0.56);
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 50%;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
pointer-events: none;
}
.compass::before {
content: "";
position: absolute;
top: 7px;
left: 17px;
width: 1px;
height: 12px;
background: var(--amber);
transform-origin: bottom;
transform: rotate(18deg);
}
.compass span {
position: absolute;
top: -14px;
left: 14px;
}
.world-label {
position: absolute;
z-index: 2;
max-width: 190px;
padding: 7px 9px;
color: #dff5e7;
background: rgba(32, 68, 45, 0.87);
border: 1px solid rgba(114, 213, 155, 0.48);
border-radius: 5px;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.05em;
line-height: 1.4;
pointer-events: none;
transform: translate(-50%, -100%);
white-space: nowrap;
}
.world-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
background: inherit;
border-right: 1px solid rgba(114, 213, 155, 0.48);
border-bottom: 1px solid rgba(114, 213, 155, 0.48);
transform: translateX(-50%) rotate(45deg);
}
.world-label.provisional {
color: #ffe1b0;
background: rgba(91, 57, 22, 0.9);
border-color: rgba(242, 182, 95, 0.55);
}
.world-label.provisional::after {
border-color: rgba(242, 182, 95, 0.55);
}
@media (max-width: 820px) {
body {
overflow: hidden;
}
#app {
grid-template-columns: 1fr;
grid-template-rows: 56vh 44vh;
}
#stage {
grid-row: 1;
}
#panel {
grid-row: 2;
padding: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.4);
border-right: 0;
}
h1 {
font-size: 31px;
}
.intro {
margin: 12px 0 15px;
}
.stage-top {
top: 14px;
left: 15px;
right: 15px;
}
.compass {
left: 16px;
top: 68px;
}
.toolbar {
right: 12px;
bottom: 13px;
}
.hint {
display: none;
}
.world-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app">
<aside id="panel">
<div class="eyebrow">Strata / Reconstruction Lab</div>
<h1>Roof fit<br /><em>against the walls</em></h1>
<p class="intro">
Compare two low-poly roof proposals using the excavated wall heads as
bearing evidence. Supported contacts are green; unresolved geometry
remains explicitly provisional.
</p>
<div class="section-title">Test mode</div>
<div class="mode-switch" role="group" aria-label="Choose reconstruction view">
<button class="mode-btn active" data-mode="A" aria-pressed="true">Candidate A</button>
<button class="mode-btn" data-mode="B" aria-pressed="false">Candidate B</button>
<button class="mode-btn" data-mode="compare" aria-pressed="false">Overlay</button>
</div>
<div class="section-title">Proposals</div>
<article class="candidate">
<div class="candidate-top">
<div>
<div class="candidate-name">A — Aligned gable</div>
<div class="candidate-sub">North–south ridge, aligned eaves</div>
</div>
<div class="fit-badge">88 · SUPPORTED</div>
</div>
<div class="fit-track"><span style="width: 88%"></span></div>
</article>
<article class="candidate provisional">
<div class="candidate-top">
<div>
<div class="candidate-name">B — Offset gable</div>
<div class="candidate-sub">Rotated and expanded footprint</div>
</div>
<div class="fit-badge amber">52 · PROVISIONAL</div>
</div>
<div class="fit-track"><span style="width: 52%"></span></div>
</article>
<div class="section-title">Fit report</div>
<div class="metrics">
<div class="metric">
<div class="metric-head"><span>Wall-head bearing</span><span id="metric0v">4 / 4</span></div>
<div class="metric-track"><div class="metric-fill" id="metric0"></div></div>
</div>
<div class="metric">
<div class="metric-head"><span>Eave alignment</span><span id="metric1v">92%</span></div>
<div class="metric-track"><div class="metric-fill" id="metric1"></div></div>
</div>
<div class="metric">
<div class="metric-head"><span>Ridge continuity</span><span id="metric2v">86%</span></div>
<div class="metric-track"><div class="metric-fill" id="metric2"></div></div>
</div>
<div class="metric">
<div class="metric-head"><span>Overall placement</span><span id="metric3v">88%</span></div>
<div class="metric-track"><div class="metric-fill" id="metric3"></div></div>
</div>
</div>
<div class="section-title">Interpretation</div>
<p class="evidence-copy" id="evidenceCopy">
Four eaves coincide with surviving wall heads. Ridge seam, roof covering,
and hidden joinery remain provisional.
</p>
<div class="section-title">Legend</div>
<div class="legend">
<div class="legend-item"><span class="swatch"></span>Supported wall-head bearing</div>
<div class="legend-item"><span class="swatch amber"></span>Provisional / unresolved detail</div>
<div class="legend-item"><span class="swatch stone"></span>Excavated wall fabric</div>
</div>
<div class="data-note">
Illustrative survey geometry. The supports, dimensions, confidence values,
and archaeological interpretations are demonstration data and should be
replaced by measured trench coordinates before evidentiary use.
</div>
</aside>
<main id="stage">
<canvas id="scene" aria-label="Interactive 3D reconstruction comparison"></canvas>
<div class="stage-top">
<div class="site-code">
<strong>North trench / test 07</strong>
Datum +0.00 m · grid 1 m
</div>
<div class="status-chip" id="fitChip">Candidate A · Supported placement</div>
</div>
<div class="compass"><span>N</span></div>
<div class="world-label supported" id="labelSupport">
WALL HEAD / BEARING
</div>
<div class="world-label provisional" id="labelAProvisional">
RIDGE SEAM / PROVISIONAL
</div>
<div class="world-label provisional" id="labelBProvisional">
OFFSET EAVE / PROVISIONAL
</div>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom</div>
<div class="toolbar" aria-label="Camera controls">
<button data-view="oblique" title="Oblique survey view">Oblique</button>
<button data-view="plan" title="Top-down plan view">Plan</button>
<button data-view="reset" title="Reset camera">Reset</button>
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Basic scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const canvas = document.getElementById("scene");
const fitChip = document.getElementById("fitChip");
const evidenceCopy = document.getElementById("evidenceCopy");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x171c1a);
scene.fog = new THREE.Fog(0x171c1a, 24, 48);
const camera = new THREE.PerspectiveCamera(
42,
stage.clientWidth / stage.clientHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const hemisphere = new THREE.HemisphereLight(0xe9eee7, 0x4a4438, 1.7);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe8c8, 3.0);
sun.position.set(-8, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc8d7, 0.75);
fill.position.set(12, 7, -10);
scene.add(fill);
const site = new THREE.Group();
scene.add(site);
// Deterministic randomness keeps the low-poly fabric stable between reloads.
function seededRandom(seed) {
return function () {
let t = seed += 0x6d2b79f5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(7041);
// -------------------------------------------------------------------------
// Excavation ground and walls
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 24),
new THREE.MeshStandardMaterial({
color: 0x30342e,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
site.add(ground);
const trenchFloor = new THREE.Mesh(
new THREE.PlaneGeometry(19.5, 13.2),
new THREE.MeshStandardMaterial({
color: 0x4a493e,
roughness: 1
})
);
trenchFloor.rotation.x = -Math.PI / 2;
trenchFloor.position.y = 0.015;
trenchFloor.receiveShadow = true;
site.add(trenchFloor);
const grid = new THREE.GridHelper(30, 30, 0x768077, 0x596059);
grid.position.y = 0.022;
grid.material.transparent = true;
grid.material.opacity = 0.17;
site.add(grid);
const wallGroup = new THREE.Group();
site.add(wallGroup);
const wallEdgeMaterial = new THREE.LineBasicMaterial({
color: 0x5d584d,
transparent: true,
opacity: 0.38
});
function addWall(ax, az, bx, bz, height, seed) {
const dx = bx - ax;
const dz = bz - az;
const length = Math.hypot(dx, dz);
const group = new THREE.Group();
group.position.set((ax + bx) / 2, 0, (az + bz) / 2);
group.rotation.y = -Math.atan2(dz, dx);
const localRandom = seededRandom(seed);
const hue = 0.105 + localRandom() * 0.025;
const lightness = 0.57 + localRandom() * 0.08;
const material = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(hue, 0.19, lightness),
roughness: 0.96,
metalness: 0,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.BoxGeometry(length, height, 0.44),
material
);
body.position.y = height / 2;
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(body.geometry),
wallEdgeMaterial
);
edges.position.copy(body.position);
group.add(edges);
// Broken cap stones create a low-poly excavated profile.
const count = Math.max(2, Math.ceil(length / 1.05));
const cell = length / count;
for (let i = 0; i < count; i++) {
const capHeight = 0.07 + localRandom() * 0.07;
const cap = new THREE.Mesh(
new THREE.BoxGeometry(cell * (0.78 + localRandom() * 0.12), capHeight, 0.45),
material.clone()
);
cap.material.color.offsetHSL(
(localRandom() - 0.5) * 0.012,
0,
(localRandom() - 0.5) * 0.035
);
cap.position.set(
-length / 2 + cell * (i + 0.5),
height + capHeight / 2 - 0.025,
(localRandom() - 0.5) * 0.045
);
cap.castShadow = true;
cap.receiveShadow = true;
group.add(cap);
}
wallGroup.add(group);
}
// Outer excavation limits.
addWall(-8.8, -5.8, 8.8, -5.8, 1.05, 12);
addWall(-8.8, -5.8, -8.8, 5.8, 1.46, 22);
addWall(8.8, -5.8, 8.8, 5.8, 0.98, 32);
addWall(-8.8, 5.8, -4.7, 5.8, 1.32, 42);
addWall(4.7, 5.8, 8.8, 5.8, 1.21, 52);
// Principal nave walls, deliberately broken into excavated wall-head groups.
addWall(-3.8, -4.8, -3.8, -2.9, 2.31, 61);
addWall(-3.8, -2.5, -3.8, -0.7, 2.68, 62);
addWall(-3.8, 0.0, -3.8, 1.6, 2.41, 63);
addWall(-3.8, 2.0, -3.8, 4.8, 2.68, 64);
addWall(3.8, -4.8, 3.8, -2.9, 2.26, 71);
addWall(3.8, -2.5, 3.8, -0.7, 2.68, 72);
addWall(3.8, 0.0, 3.8, 1.6, 2.37, 73);
addWall(3.8, 2.0, 3.8, 4.8, 2.68, 74);
// Lower cross-wall.
addWall(-3.8, -1.1, 3.8, -1.1, 1.31, 81);
// Small fragments around the trench edge.
const fragmentMaterial = new THREE.MeshStandardMaterial({
color: 0xa99d84,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 24; i++) {
const side = i % 4;
let x;
let z;
if (side === 0) {
x = -8.1 + random() * 16.2;
z = -6.25 - random() * 0.45;
} else if (side === 1) {
x = 8.15 + random() * 0.45;
z = -5.8 + random() * 11.6;
} else if (side === 2) {
x = -8.1 + random() * 16.2;
z = 6.15 + random() * 0.45;
} else {
x = -8.6 - random() * 0.45;
z = -5.8 + random() * 11.6;
}
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.09 + random() * 0.16, 0),
fragmentMaterial
);
rock.position.set(x, 0.07, z);
rock.scale.set(
0.7 + random() * 1.4,
0.45 + random() * 0.65,
0.7 + random() * 1.25
);
rock.rotation.set(random(), random(), random());
rock.castShadow = true;
rock.receiveShadow = true;
site.add(rock);
}
// -------------------------------------------------------------------------
// Low-poly roof construction
// -------------------------------------------------------------------------
const pulseItems = [];
function addBeam(group, start, end, thickness, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.BoxGeometry(thickness, length, thickness);
const beam = new THREE.Mesh(geometry, material);
beam.position.copy(start).add(end).multiplyScalar(0.5);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
group.add(beam);
return beam;
}
function addDashedLine(group, points, color, dashSize = 0.2, opacity = 0.95) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize,
gapSize: dashSize * 0.58,
transparent: true,
opacity,
depthTest: true
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
group.add(line);
return line;
}
function createRoof({
width,
depth,
eave,
ridge,
roofColor,
seed,
provisionalAll
}) {
const group = new THREE.Group();
const localRandom = seededRandom(seed);
const positions = [];
const colors = [];
function pushTriangle(a, b, c, color) {
positions.push(
a.x, a.y, a.z,
b.x, b.y, b.z,
c.x, c.y, c.z
);
for (let i = 0; i < 3; i++) {
colors.push(color.r, color.g, color.b);
}
}
const baseColor = new THREE.Color(roofColor);
const bays = 4;
for (let i = 0; i < bays; i++) {
const z0 = -depth / 2 + (depth / bays) * i;
const z1 = -depth / 2 + (depth / bays) * (i + 1);
const left0 = new THREE.Vector3(-width / 2, eave, z0);
const left1 = new THREE.Vector3(-width / 2, eave, z1);
const ridge0 = new THREE.Vector3(0, ridge, z0);
const ridge1 = new THREE.Vector3(0, ridge, z1);
const right0 = new THREE.Vector3(width / 2, eave, z0);
const right1 = new THREE.Vector3(width / 2, eave, z1);
const leftColor = baseColor.clone().offsetHSL(
(localRandom() - 0.5) * 0.012,
(localRandom() - 0.5) * 0.025,
(localRandom() - 0.5) * 0.11
);
const rightColor = baseColor.clone().offsetHSL(
(localRandom() - 0.5) * 0.012,
(localRandom() - 0.5) * 0.025,
(localRandom() - 0.5) * 0.11
);
pushTriangle(left0, left1, ridge1, leftColor);
pushTriangle(left0, ridge1, ridge0, leftColor);
pushTriangle(ridge0, ridge1, right1, rightColor);
pushTriangle(ridge0, right1, right0, rightColor);
}
const roofGeometry = new THREE.BufferGeometry();
roofGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
roofGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
roofGeometry.computeVertexNormals();
const roofMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
side: THREE.DoubleSide,
roughness: 0.92,
metalness: 0,
flatShading: true
});
const roof = new THREE.Mesh(roofGeometry, roofMaterial);
roof.castShadow = true;
roof.receiveShadow = true;
group.add(roof);
const timberMaterial = new THREE.MeshStandardMaterial({
color: 0x4d3a2b,
roughness: 0.88,
flatShading: true
});
// Ridge, purlins, rafters, tie beams and a simple king post.
addBeam(
group,
new THREE.Vector3(0, ridge - 0.17, -depth / 2),
new THREE.Vector3(0, ridge - 0.17, depth / 2),
0.16,
timberMaterial
);
for (const x of [-width * 0.25, width * 0.25]) {
const y = eave + (ridge - eave) * 0.5 - 0.08;
addBeam(
group,
new THREE.Vector3(x, y, -depth / 2),
new THREE.Vector3(x, y, depth / 2),
0.1,
timberMaterial
);
}
for (let i = 0; i <= 4; i++) {
const z = -depth / 2 + (depth / 4) * i;
addBeam(
group,
new THREE.Vector3(-width / 2, eave - 0.05, z),
new THREE.Vector3(0, ridge - 0.12, z),
0.095,
timberMaterial
);
addBeam(
group,
new THREE.Vector3(0, ridge - 0.12, z),
new THREE.Vector3(width / 2, eave - 0.05, z),
0.095,
timberMaterial
);
}
for (const z of [-depth / 2 + 0.13, depth / 2 - 0.13]) {
addBeam(
group,
new THREE.Vector3(-width / 2, eave - 0.12, z),
new THREE.Vector3(width / 2, eave - 0.12, z),
0.11,
timberMaterial
);
addBeam(
group,
new THREE.Vector3(0, eave - 0.12, z),
new THREE.Vector3(0, ridge - 0.18, z),
0.085,
timberMaterial
);
}
// Provisional ridge seam.
addDashedLine(
group,
[
new THREE.Vector3(0, ridge + 0.025, -depth / 2),
new THREE.Vector3(0, ridge + 0.025, depth / 2)
],
provisionalAll ? 0xf2b65f : 0xf2b65f,
0.18,
provisionalAll ? 1 : 0.86
);
// The far gable geometry is an inference, so it is explicitly provisional.
const gableZ = provisionalAll ? depth / 2 : depth / 2;
addDashedLine(
group,
[
new THREE.Vector3(-width / 2, eave, gableZ),
new THREE.Vector3(0, ridge, gableZ),
new THREE.Vector3(width / 2, eave, gableZ)
],
0xf2b65f,
0.16,
provisionalAll ? 1 : 0.82
);
if (provisionalAll) {
addDashedLine(
group,
[
new THREE.Vector3(-width / 2, eave, -depth / 2),
new THREE.Vector3(width / 2, eave, -depth / 2),
new THREE.Vector3(width / 2, eave, depth / 2),
new THREE.Vector3(-width / 2, eave, depth / 2),
new THREE.Vector3(-width / 2, eave, -depth / 2)
],
0xf2b65f,
0.17,
0.88
);
}
return group;
}
function addBearingMarker(group, x, z, eave, color, provisional = false) {
const padMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: provisional ? 0.68 : 0.92,
depthWrite: false
});
const pad = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.055, 0.76),
padMaterial
);
pad.position.set(x, eave + 0.015, z);
group.add(pad);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.25, 0.035, 8, 28),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(x, eave + 0.075, z);
group.add(ring);
pulseItems.push(ring);
}
// Candidate A: eaves align directly with four preserved wall heads.
const candidateA = createRoof({
width: 7.6,
depth: 9.6,
eave: 2.77,
ridge: 5.23,
roofColor: 0xb65c3e,
seed: 901,
provisionalAll: false
});
site.add(candidateA);
addBearingMarker(candidateA, -3.8, -2.2, 2.77, 0x72d59b);
addBearingMarker(candidateA, 3.8, -2.2, 2.77, 0x72d59b);
addBearingMarker(candidateA, -3.8, 3.1, 2.77, 0x72d59b);
addBearingMarker(candidateA, 3.8, 3.1, 2.77, 0x72d59b);
// Candidate B: expanded and rotated; only an approximate contact is visible.
const candidateB = createRoof({
width: 8.5,
depth: 10.8,
eave: 2.77,
ridge: 5.02,
roofColor: 0x9e7655,
seed: 1301,
provisionalAll: true
});
candidateB.position.set(0.55, 0.04, 0.35);
candidateB.rotation.y = THREE.MathUtils.degToRad(8);
site.add(candidateB);
addBearingMarker(candidateB, -4.25, -3.3, 2.77, 0xf2b65f, true);
// Save base material values so overlay transparency can be changed safely.
function prepareOpacity(group) {
group.traverse((object) => {
if (!object.material) return;
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
material.userData.baseOpacity = material.opacity;
material.userData.baseTransparent = material.transparent;
material.userData.baseDepthWrite = material.depthWrite;
}
});
}
prepareOpacity(candidateA);
prepareOpacity(candidateB);
function setGroupOpacity(group, factor) {
group.traverse((object) => {
if (!object.material) return;
const materials = Array.isArray(object.material)
? object.material
: [object.material];
for (const material of materials) {
const base = material.userData.baseOpacity ?? 1;
const opacity = base * factor;
material.opacity = opacity;
material.transparent =
opacity < 0.999 || material.userData.baseTransparent === true;
material.depthWrite =
opacity > 0.65 && material.userData.baseDepthWrite !== false;
material.needsUpdate = true;
}
});
}
// -------------------------------------------------------------------------
// Interface and fit reporting
// -------------------------------------------------------------------------
let currentMode = "A";
const metricValues = [0, 1, 2, 3].map(
(index) => document.getElementById(`metric${index}v`)
);
const metricFills = [0, 1, 2, 3].map(
(index) => document.getElementById(`metric${index}`)
);
const reports = {
A: {
values: ["4 / 4", "92%", "86%", "88%"],
widths: [100, 92, 86, 88],
color: "#397c57",
chip: "Candidate A · Supported placement",
chipClass: "",
copy:
"Four eaves coincide with surviving wall heads. Ridge seam, roof covering, " +
"and hidden joinery remain provisional."
},
B: {
values: ["1 / 4", "46%", "55%", "52%"],
widths: [25, 46, 55, 52],
color: "#9a6528",
chip: "Candidate B · Provisional placement",
chipClass: "provisional",
copy:
"Only one eave approaches a wall head. The expanded footprint, eave line, " +
"ridge position, and all unresolved roof details remain provisional."
},
compare: {
values: ["A 4/4 · B 1/4", "A 92% · B 46%", "A 86% · B 55%", "A 88% · B 52%"],
widths: [70, 69, 71, 70],
color: "#69736b",
chip: "Overlay · Two variants at one datum",
chipClass: "overlay",
copy:
"The overlay tests both proposals at the same datum. Green marks direct " +
"wall-head bearing; amber identifies geometry that remains unresolved."
}
};
function setMode(mode) {
currentMode = mode;
candidateA.visible = mode !== "B";
candidateB.visible = mode !== "A";
setGroupOpacity(candidateA, mode === "compare" ? 0.5 : 1);
setGroupOpacity(candidateB, mode === "compare" ? 0.28 : 1);
for (const button of document.querySelectorAll(".mode-btn")) {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
}
const report = reports[mode];
fitChip.textContent = report.chip;
fitChip.className = `status-chip ${report.chipClass}`.trim();
evidenceCopy.textContent = report.copy;
for (let i = 0; i < 4; i++) {
metricValues[i].textContent = report.values[i];
metricFills[i].style.width = `${report.widths[i]}%`;
metricFills[i].style.background = report.color;
}
}
for (const button of document.querySelectorAll(".mode-btn")) {
button.addEventListener("click", () => setMode(button.dataset.mode));
}
// -------------------------------------------------------------------------
// Custom camera controls — no add-ons or examples modules
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.69,
phi: 1.02,
radius: 23.5,
target: new THREE.Vector3(0, 1.15, 0)
};
let cameraGoal = null;
const pointers = new Map();
let previousPinchDistance = 0;
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setView(view) {
if (view === "plan") {
cameraGoal = {
theta: 0,
phi: 0.08,
radius: 22,
target: new THREE.Vector3(0, 0, 0)
};
} else if (view === "reset") {
cameraGoal = {
theta: 0.69,
phi: 1.02,
radius: 23.5,
target: new THREE.Vector3(0, 1.15, 0)
};
} else {
cameraGoal = {
theta: 0.69,
phi: 1.02,
radius: 23.5,
target: new THREE.Vector3(0, 1.15, 0)
};
}
}
for (const button of document.querySelectorAll("[data-view]")) {
button.addEventListener("click", () => setView(button.dataset.view));
}
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(points[0].x - points[1].x, points[0].y - points[1].y);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
cameraGoal = null;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size >= 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
9,
42
);
}
previousPinchDistance = distance;
return;
}
const pan = event.shiftKey || event.buttons === 2;
if (pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
const up = new THREE.Vector3()
.crossVectors(right, forward)
.normalize();
const scale = cameraState.radius * 0.00155;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.006,
0.07,
1.42
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraGoal = null;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9,
42
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// World-space annotations
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("labelSupport"),
anchor: () => new THREE.Vector3(-3.8, 3.15, -2.2),
modes: ["A", "compare"],
offsetX: -8,
offsetY: -8
},
{
element: document.getElementById("labelAProvisional"),
anchor: () => new THREE.Vector3(0, 5.48, 4.8),
modes: ["A", "compare"],
offsetX: 5,
offsetY: -5
},
{
element: document.getElementById("labelBProvisional"),
anchor: () =>
candidateB.localToWorld(new THREE.Vector3(-4.25, 3.02, -3.3)),
modes: ["B", "compare"],
offsetX: 14,
offsetY: -4
}
];
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
for (const label of labels) {
if (!label.modes.includes(currentMode)) {
label.element.style.display = "none";
continue;
}
const world = label.anchor();
const projected = world.clone().project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
projected.x < -1.1 ||
projected.x > 1.1 ||
projected.y < -1.1 ||
projected.y > 1.1
) {
label.element.style.display = "none";
continue;
}
const x = (projected.x * 0.5 + 0.5) * width + label.offsetX;
const y = (-projected.y * 0.5 + 0.5) * height + label.offsetY;
label.element.style.display = "block";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(stage);
resize();
setMode("A");
applyCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (cameraGoal) {
const easing = 0.09;
cameraState.theta += (cameraGoal.theta - cameraState.theta) * easing;
cameraState.phi += (cameraGoal.phi - cameraState.phi) * easing;
cameraState.radius += (cameraGoal.radius - cameraState.radius) * easing;
cameraState.target.lerp(cameraGoal.target, easing);
if (
Math.abs(cameraGoal.theta - cameraState.theta) < 0.001 &&
Math.abs(cameraGoal.phi - cameraState.phi) < 0.001 &&
Math.abs(cameraGoal.radius - cameraState.radius) < 0.01
) {
cameraState.theta = cameraGoal.theta;
cameraState.phi = cameraGoal.phi;
cameraState.radius = cameraGoal.radius;
cameraState.target.copy(cameraGoal.target);
cameraGoal = null;
}
}
for (let i = 0; i < pulseItems.length; i++) {
const pulse = 1 + Math.sin(elapsed * 2.2 + i * 0.7) * 0.07;
pulseItems[i].scale.setScalar(pulse);
}
applyCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
</script>
</body>
</html>
```