Prompt specification
Build or customize the Three.js 3D scene "Divider angle exploration" 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: Divider angle exploration
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/divider-angle-exploration-x0214
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Place a hinged three-panel divider on a floor grid; adjusting hinge angles changes its footprint and blocks some sightlines without closing the walking passage beside it.
Working Three.js Starter (divider-angle-exploration-x0214):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hinged Divider — Footprint & Sightline Study</title>
<style>
:root {
--ink: #20312e;
--muted: #667570;
--paper: rgba(249, 247, 238, 0.92);
--line: rgba(32, 49, 46, 0.14);
--orange: #dc8451;
--teal: #168b83;
--green: #188a66;
--red: #c95348;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd5ce;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.card {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow:
0 16px 45px rgba(35, 49, 44, 0.14),
0 2px 8px rgba(35, 49, 44, 0.06);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.controls {
position: absolute;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 20px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--orange);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 24px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.control {
padding: 13px 0 11px;
border-top: 1px solid var(--line);
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 12px;
font-weight: 750;
}
output {
min-width: 48px;
padding: 3px 7px;
border-radius: 7px;
background: #e8ece5;
color: var(--ink);
font-variant-numeric: tabular-nums;
text-align: center;
}
input[type="range"] {
--p: 50%;
width: 100%;
height: 5px;
margin: 0;
border-radius: 99px;
outline: none;
appearance: none;
-webkit-appearance: none;
background:
linear-gradient(to right,
var(--orange) 0%,
var(--orange) var(--p),
#d8ddd7 var(--p),
#d8ddd7 100%);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 18px;
height: 18px;
border: 3px solid #fffaf1;
border-radius: 50%;
appearance: none;
-webkit-appearance: none;
background: var(--orange);
box-shadow: 0 2px 8px rgba(45, 55, 49, 0.25);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid #fffaf1;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 2px 8px rgba(45, 55, 49, 0.25);
}
.presets {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 12px;
}
button {
min-height: 34px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.5);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff;
}
button:active { transform: translateY(0); }
.status {
position: absolute;
top: 22px;
right: 22px;
width: 245px;
padding: 16px;
border-radius: 16px;
}
.status-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.passage-badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border-radius: 99px;
background: rgba(24, 139, 102, 0.11);
color: var(--green);
font-size: 10px;
letter-spacing: 0.08em;
}
.passage-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
content: "";
box-shadow: 0 0 0 4px rgba(24, 139, 102, 0.11);
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 9px 0;
border-top: 1px solid var(--line);
}
.metric span {
color: var(--muted);
font-size: 11px;
}
.metric strong {
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.legend {
position: absolute;
bottom: 22px;
left: 22px;
display: flex;
gap: 15px;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 11px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 19px;
height: 3px;
border-radius: 99px;
background: var(--red);
}
.swatch.visible { background: var(--green); }
.swatch.route { background: var(--teal); }
.help {
position: absolute;
right: 22px;
bottom: 22px;
padding: 9px 12px;
border-radius: 10px;
color: rgba(32, 49, 46, 0.67);
font-size: 11px;
}
.safety-note {
margin-top: 12px;
padding: 10px 11px;
border-left: 3px solid var(--teal);
border-radius: 0 8px 8px 0;
background: rgba(22, 139, 131, 0.08);
color: #49635f;
font-size: 10px;
line-height: 1.45;
}
@media (max-width: 720px) {
.controls {
top: 12px;
left: 12px;
width: min(315px, calc(100vw - 24px));
padding: 15px;
}
h1 { font-size: 20px; }
.intro { margin-bottom: 12px; }
.control { padding: 9px 0; }
.status {
top: auto;
right: 12px;
bottom: 52px;
width: 205px;
padding: 12px;
}
.legend, .help { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional hinged divider"></canvas>
<div class="ui">
<section class="card controls">
<div class="eyebrow">Spatial planning study</div>
<h1>Hinged divider</h1>
<p class="intro">
Fold three rigid panels to change the divider’s footprint and interrupt
selected sightlines.
</p>
<div class="control">
<label class="control-label" for="rootAngle">
<span>Root hinge</span>
<output id="rootAngleValue">0°</output>
</label>
<input id="rootAngle" type="range" min="-60" max="60" value="0" step="1" />
</div>
<div class="control">
<label class="control-label" for="foldA">
<span>Hinge A · relative</span>
<output id="foldAValue">0°</output>
</label>
<input id="foldA" type="range" min="-135" max="135" value="0" step="1" />
</div>
<div class="control">
<label class="control-label" for="foldB">
<span>Hinge B · relative</span>
<output id="foldBValue">0°</output>
</label>
<input id="foldB" type="range" min="-135" max="135" value="0" step="1" />
</div>
<div class="presets">
<button type="button" data-preset="straight">Straight</button>
<button type="button" data-preset="zigzag">Zig-zag</button>
<button type="button" data-preset="folded">Folded</button>
</div>
<div class="safety-note">
Protected route: the hinge limits and anchor keep at least 1.2 m between
the divider and the walking passage.
</div>
</section>
<aside class="card status" aria-live="polite">
<div class="status-heading">
<span>Live analysis</span>
<span class="passage-badge">Passage open</span>
</div>
<div class="metric">
<span>Blocked sightlines</span>
<strong id="blockedValue">2 / 3</strong>
</div>
<div class="metric">
<span>Route clearance</span>
<strong id="clearanceValue">1.2 m</strong>
</div>
<div class="metric">
<span>Footprint span</span>
<strong id="spanValue">6.8 × 0.2 m</strong>
</div>
</aside>
<div class="card legend">
<div class="legend-item"><i class="swatch"></i> Blocked view</div>
<div class="legend-item"><i class="swatch visible"></i> Clear view</div>
<div class="legend-item"><i class="swatch route"></i> Walking route</div>
</div>
<div class="card help">Drag to orbit · Wheel to zoom · Double-click to reset camera</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd5ce);
scene.fog = new THREE.Fog(0xcbd5ce, 23, 38);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
// ---------------------------------------------------------------------
// Camera: custom orbit/zoom controls, implemented without external addons.
// ---------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.6, 0.9, 0);
const initialCamera = {
yaw: 0.72,
pitch: 0.48,
radius: 17.5
};
const cameraState = {
yaw: initialCamera.yaw,
pitch: initialCamera.pitch,
radius: initialCamera.radius,
desiredYaw: initialCamera.yaw,
desiredPitch: initialCamera.pitch,
desiredRadius: initialCamera.radius
};
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
cameraTarget.x + radius * Math.cos(pitch) * Math.sin(yaw),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(pitch) * Math.cos(yaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.desiredYaw = initialCamera.yaw;
cameraState.desiredPitch = initialCamera.pitch;
cameraState.desiredRadius = initialCamera.radius;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.desiredYaw -= dx * 0.005;
cameraState.desiredPitch = THREE.MathUtils.clamp(
cameraState.desiredPitch + dy * 0.004,
0.18,
1.2
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
9,
26
);
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
// ---------------------------------------------------------------------
// Lighting.
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xf3f4e9, 0x6b776f, 2.0));
const sun = new THREE.DirectionalLight(0xfff3d7, 3.1);
sun.position.set(-4, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8e0df, 1.0);
fill.position.set(8, 6, -7);
scene.add(fill);
// ---------------------------------------------------------------------
// Floor and rectangular grid.
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.BoxGeometry(16, 0.22, 12),
new THREE.MeshStandardMaterial({
color: 0xd9d5c8,
roughness: 0.94,
metalness: 0
})
);
floor.position.y = -0.12;
floor.receiveShadow = true;
scene.add(floor);
function addGridLines(step, color, opacity) {
const positions = [];
for (let x = -8; x <= 8; x += step) {
positions.push(x, 0.008, -6, x, 0.008, 6);
}
for (let z = -6; z <= 6; z += step) {
positions.push(-8, 0.008, z, 8, 0.008, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const lines = new THREE.LineSegments(
geometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
scene.add(lines);
}
addGridLines(1, 0x87948e, 0.2);
addGridLines(4, 0x64736d, 0.35);
// ---------------------------------------------------------------------
// Protected walking passage.
// ---------------------------------------------------------------------
const CORRIDOR_LEFT = 3.0;
const CORRIDOR_RIGHT = 7.2;
const corridor = new THREE.Mesh(
new THREE.PlaneGeometry(CORRIDOR_RIGHT - CORRIDOR_LEFT, 11.7),
new THREE.MeshBasicMaterial({
color: 0x46b6aa,
transparent: true,
opacity: 0.14,
depthWrite: false
})
);
corridor.rotation.x = -Math.PI / 2;
corridor.position.set((CORRIDOR_LEFT + CORRIDOR_RIGHT) / 2, 0.014, 0);
scene.add(corridor);
const routeBorderMaterial = new THREE.LineDashedMaterial({
color: 0x168b83,
dashSize: 0.32,
gapSize: 0.18,
transparent: true,
opacity: 0.75
});
for (const x of [CORRIDOR_LEFT, CORRIDOR_RIGHT]) {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.032, -5.8),
new THREE.Vector3(x, 0.032, 5.8)
]);
const line = new THREE.Line(geometry, routeBorderMaterial);
line.computeLineDistances();
scene.add(line);
}
const arrowShape = new THREE.Shape();
arrowShape.moveTo(0, 0.42);
arrowShape.lineTo(-0.34, -0.18);
arrowShape.lineTo(0, -0.03);
arrowShape.lineTo(0.34, -0.18);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0x168b83,
transparent: true,
opacity: 0.48,
side: THREE.DoubleSide,
depthWrite: false
});
for (const z of [-4.3, -2.4, -0.5, 1.4, 3.3]) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
arrow.rotation.x = -Math.PI / 2;
arrow.position.set(5.1, 0.03, z);
scene.add(arrow);
}
function makeCanvasTexture(width, height, draw) {
const textureCanvas = document.createElement("canvas");
textureCanvas.width = width;
textureCanvas.height = height;
draw(textureCanvas.getContext("2d"), width, height);
const texture = new THREE.CanvasTexture(textureCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const corridorTextTexture = makeCanvasTexture(1024, 128, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "rgba(22, 139, 131, 0.88)";
ctx.font = "700 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("WALKING PASSAGE · KEEP CLEAR", w / 2, h / 2);
});
const corridorText = new THREE.Mesh(
new THREE.PlaneGeometry(3.85, 0.48),
new THREE.MeshBasicMaterial({
map: corridorTextTexture,
transparent: true,
depthWrite: false
})
);
corridorText.rotation.x = -Math.PI / 2;
corridorText.position.set(5.1, 0.038, 4.8);
scene.add(corridorText);
// ---------------------------------------------------------------------
// Low-poly divider panels.
// ---------------------------------------------------------------------
const PANEL_LENGTH = 2.3;
const PANEL_HEIGHT = 2.6;
const ANCHOR = new THREE.Vector3(-5.2, 0, 0);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x293a36,
roughness: 0.62,
metalness: 0.18,
flatShading: true
});
const hingeMaterial = new THREE.MeshStandardMaterial({
color: 0x53625c,
roughness: 0.4,
metalness: 0.5,
flatShading: true
});
const panelColors = [0xd59a63, 0xd6b37a, 0xbc7556];
const panels = [];
const obstacleMeshes = [];
function makeBadgeTexture(number) {
return makeCanvasTexture(512, 160, (ctx, w, h) => {
ctx.fillStyle = "#293a36";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#e6aa6f";
ctx.fillRect(0, h - 12, w, 12);
ctx.fillStyle = "#fff8e8";
ctx.font = "800 64px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(`PANEL ${number}`, w / 2, h / 2 - 4);
});
}
function createPanel(index) {
const group = new THREE.Group();
scene.add(group);
const panelMaterial = new THREE.MeshStandardMaterial({
color: panelColors[index],
roughness: 0.82,
metalness: 0,
flatShading: true
});
const board = new THREE.Mesh(
new THREE.BoxGeometry(
PANEL_LENGTH - 0.18,
PANEL_HEIGHT - 0.18,
0.1
),
panelMaterial
);
board.position.set(PANEL_LENGTH / 2, 1.48, 0);
board.castShadow = true;
board.receiveShadow = true;
group.add(board);
obstacleMeshes.push(board);
const verticalGeometry = new THREE.BoxGeometry(0.12, 2.76, 0.16);
for (const x of [0.08, PANEL_LENGTH - 0.08]) {
const bar = new THREE.Mesh(verticalGeometry, frameMaterial);
bar.position.set(x, 1.48, 0);
bar.castShadow = true;
group.add(bar);
}
const horizontalGeometry = new THREE.BoxGeometry(PANEL_LENGTH, 0.12, 0.16);
for (const y of [0.15, 2.81]) {
const bar = new THREE.Mesh(horizontalGeometry, frameMaterial);
bar.position.set(PANEL_LENGTH / 2, y, 0);
bar.castShadow = true;
group.add(bar);
}
// Shallow decorative rails give the infill a hand-built low-poly look.
const railMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(panelColors[index]).multiplyScalar(0.82),
roughness: 0.9,
flatShading: true
});
for (const x of [0.78, 1.52]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 2.35, 0.025),
railMaterial
);
rail.position.set(x, 1.48, 0.065);
group.add(rail);
}
const footGeometry = new THREE.CylinderGeometry(0.11, 0.15, 0.14, 8);
for (const x of [0.34, PANEL_LENGTH - 0.34]) {
const foot = new THREE.Mesh(footGeometry, frameMaterial);
foot.position.set(x, 0.07, 0);
foot.castShadow = true;
group.add(foot);
}
const footprint = new THREE.Mesh(
new THREE.BoxGeometry(PANEL_LENGTH, 0.018, 0.5),
new THREE.MeshBasicMaterial({
color: 0xdc8451,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
footprint.position.set(PANEL_LENGTH / 2, 0.026, 0);
group.add(footprint);
const hinge = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.095, 0.65, 10),
hingeMaterial
);
hinge.position.set(0, 0.58, 0);
hinge.castShadow = true;
group.add(hinge);
const hingeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.105, 0.023, 6, 12),
new THREE.MeshStandardMaterial({
color: 0xdc8451,
roughness: 0.5,
metalness: 0.25,
flatShading: true
})
);
hingeRing.position.set(0, 0.9, 0);
hingeRing.rotation.x = Math.PI / 2;
group.add(hingeRing);
const pivot = new THREE.Mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.025, 12),
new THREE.MeshStandardMaterial({
color: 0xdc8451,
roughness: 0.75,
flatShading: true
})
);
pivot.position.y = 0.04;
group.add(pivot);
const badgeTexture = makeBadgeTexture(String(index + 1).padStart(2, "0"));
const badgeMaterial = new THREE.MeshBasicMaterial({
map: badgeTexture,
transparent: true,
depthWrite: false
});
const frontBadge = new THREE.Mesh(
new THREE.PlaneGeometry(0.76, 0.24),
badgeMaterial
);
frontBadge.position.set(PANEL_LENGTH / 2, 2.22, 0.071);
group.add(frontBadge);
const backBadge = new THREE.Mesh(
new THREE.PlaneGeometry(0.76, 0.24),
badgeMaterial
);
backBadge.position.set(PANEL_LENGTH / 2, 2.22, -0.071);
backBadge.rotation.y = Math.PI;
group.add(backBadge);
return { group, board };
}
for (let i = 0; i < 3; i++) {
panels.push(createPanel(i));
}
// Floor arcs make each hinge angle readable.
function createArc() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(25 * 3), 3)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xdc8451,
transparent: true,
opacity: 0.85
})
);
scene.add(line);
return line;
}
const arcs = [createArc(), createArc(), createArc()];
function updateArc(line, center, fromAngle, toAngle, radius = 0.68) {
const positions = line.geometry.attributes.position.array;
const count = positions.length / 3;
for (let i = 0; i < count; i++) {
const t = i / (count - 1);
const angle = THREE.MathUtils.lerp(fromAngle, toAngle, t);
positions[i * 3] = center.x + Math.cos(angle) * radius;
positions[i * 3 + 1] = 0.052;
positions[i * 3 + 2] = center.z + Math.sin(angle) * radius;
}
line.geometry.attributes.position.needsUpdate = true;
line.geometry.computeBoundingSphere();
}
// ---------------------------------------------------------------------
// Low-poly viewer and sightline targets.
// ---------------------------------------------------------------------
function makeTextSprite(text, color = "#20312e") {
const texture = makeCanvasTexture(512, 128, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "rgba(249,247,238,0.92)";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.strokeRect(3, 3, w - 6, h - 6);
ctx.fillStyle = color;
ctx.font = "800 42px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2);
});
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.1, 0.275, 1);
sprite.renderOrder = 10;
return sprite;
}
const observer = new THREE.Group();
observer.position.set(-1.25, 0, 4.15);
scene.add(observer);
const observerMaterial = new THREE.MeshStandardMaterial({
color: 0x3e6970,
roughness: 0.8,
flatShading: true
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0xd6aa79,
roughness: 0.9,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.3, 0.72, 7),
observerMaterial
);
body.position.y = 1.08;
body.castShadow = true;
observer.add(body);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 0),
skinMaterial
);
head.position.y = 1.67;
head.castShadow = true;
observer.add(head);
for (const x of [-0.13, 0.13]) {
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.085, 0.68, 6),
frameMaterial
);
leg.position.set(x, 0.4, 0);
leg.castShadow = true;
observer.add(leg);
}
for (const x of [-0.31, 0.31]) {
const arm = new THREE.Mesh(
new THREE.CylinderGeometry(0.06, 0.07, 0.58, 6),
observerMaterial
);
arm.position.set(x, 1.06, 0);
arm.rotation.z = x > 0 ? -0.12 : 0.12;
arm.castShadow = true;
observer.add(arm);
}
const observerHalo = new THREE.Mesh(
new THREE.RingGeometry(0.38, 0.47, 24),
new THREE.MeshBasicMaterial({
color: 0x3e6970,
transparent: true,
opacity: 0.45,
side: THREE.DoubleSide
})
);
observerHalo.rotation.x = -Math.PI / 2;
observerHalo.position.y = 0.035;
observer.add(observerHalo);
const viewerLabel = makeTextSprite("VIEWER", "#3e6970");
viewerLabel.position.set(0, 2.18, 0);
observer.add(viewerLabel);
const targetPositions = [
new THREE.Vector3(-4.8, 1.25, -4.4),
new THREE.Vector3(-0.5, 1.25, -4.4),
new THREE.Vector3(5.0, 1.25, -4.4)
];
const targets = [];
for (let i = 0; i < targetPositions.length; i++) {
const material = new THREE.MeshStandardMaterial({
color: 0x188a66,
emissive: 0x188a66,
emissiveIntensity: 0.2,
roughness: 0.5,
flatShading: true
});
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
material
);
marker.position.copy(targetPositions[i]);
marker.castShadow = true;
scene.add(marker);
const label = makeTextSprite(String.fromCharCode(65 + i), "#20312e");
label.position.copy(targetPositions[i]).add(new THREE.Vector3(0, 0.55, 0));
label.scale.set(0.5, 0.25, 1);
scene.add(label);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: 0x188a66,
transparent: true,
opacity: 0.9
})
);
scene.add(line);
const hitMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 8, 5),
new THREE.MeshBasicMaterial({ color: 0xc95348 })
);
hitMarker.visible = false;
scene.add(hitMarker);
targets.push({ marker, label, line, hitMarker });
}
const raycaster = new THREE.Raycaster();
function updateSightlines() {
scene.updateMatrixWorld(true);
const eye = observer.localToWorld(new THREE.Vector3(0, 1.63, 0.2));
let blockedCount = 0;
for (let i = 0; i < targets.length; i++) {
const target = targets[i];
const destination = targetPositions[i];
const direction = destination.clone().sub(eye);
const distance = direction.length();
direction.normalize();
raycaster.set(eye, direction);
raycaster.near = 0;
raycaster.far = distance;
const hits = raycaster.intersectObjects(obstacleMeshes, false);
const blocked = hits.length > 0;
const endpoint = blocked ? hits[0].point.clone() : destination.clone();
const positions = target.line.geometry.attributes.position.array;
positions[0] = eye.x;
positions[1] = eye.y;
positions[2] = eye.z;
positions[3] = endpoint.x;
positions[4] = endpoint.y;
positions[5] = endpoint.z;
target.line.geometry.attributes.position.needsUpdate = true;
target.line.geometry.computeBoundingSphere();
const color = blocked ? 0xc95348 : 0x188a66;
target.line.material.color.setHex(color);
target.marker.material.color.setHex(color);
target.marker.material.emissive.setHex(color);
target.hitMarker.visible = blocked;
target.hitMarker.position.copy(endpoint);
if (blocked) blockedCount++;
}
document.querySelector("#blockedValue").textContent =
`${blockedCount} / ${targets.length}`;
}
// ---------------------------------------------------------------------
// Small environmental props.
// ---------------------------------------------------------------------
function createPlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
const pot = new THREE.Mesh(
new THREE.CylinderGeometry(0.34, 0.26, 0.52, 7),
new THREE.MeshStandardMaterial({
color: 0x9f644d,
roughness: 0.9,
flatShading: true
})
);
pot.position.y = 0.26;
pot.castShadow = true;
group.add(pot);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.06, 0.85, 6),
frameMaterial
);
stem.position.y = 0.9;
stem.castShadow = true;
group.add(stem);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x507b5d,
roughness: 0.9,
flatShading: true
});
for (let i = 0; i < 5; i++) {
const leaf = new THREE.Mesh(
new THREE.ConeGeometry(0.23, 0.72, 5),
leafMaterial
);
const angle = i * Math.PI * 2 / 5;
leaf.position.set(
Math.cos(angle) * 0.22,
1.08 + i * 0.08,
Math.sin(angle) * 0.22
);
leaf.rotation.z = Math.cos(angle) * 0.55;
leaf.rotation.x = Math.sin(angle) * 0.55;
leaf.castShadow = true;
group.add(leaf);
}
scene.add(group);
}
createPlant(-7.05, -4.8, 1.0);
createPlant(7.45, -4.8, 0.86);
const bench = new THREE.Group();
bench.position.set(-6.45, 0, 4.45);
scene.add(bench);
const benchSeat = new THREE.Mesh(
new THREE.BoxGeometry(1.55, 0.15, 0.55),
new THREE.MeshStandardMaterial({
color: 0x9b7653,
roughness: 0.9,
flatShading: true
})
);
benchSeat.position.y = 0.48;
benchSeat.castShadow = true;
bench.add(benchSeat);
for (const x of [-0.55, 0.55]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 0.45, 0.42),
frameMaterial
);
leg.position.set(x, 0.22, 0);
leg.castShadow = true;
bench.add(leg);
}
// ---------------------------------------------------------------------
// Hinge controls and dynamic footprint analysis.
// ---------------------------------------------------------------------
const angleInputs = [
document.querySelector("#rootAngle"),
document.querySelector("#foldA"),
document.querySelector("#foldB")
];
const angleOutputs = [
document.querySelector("#rootAngleValue"),
document.querySelector("#foldAValue"),
document.querySelector("#foldBValue")
];
function paintRange(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.setProperty("--p", `${percent}%`);
}
function updateDivider() {
const degrees = angleInputs.map((input) => Number(input.value));
const radians = degrees.map(THREE.MathUtils.degToRad);
angleOutputs.forEach((output, index) => {
output.textContent = `${degrees[index]}°`;
});
angleInputs.forEach(paintRange);
const headings = [
radians[0],
radians[0] + radians[1],
radians[0] + radians[1] + radians[2]
];
const origin = ANCHOR.clone();
const points = [];
for (let i = 0; i < panels.length; i++) {
panels[i].group.position.copy(origin);
panels[i].group.rotation.y = -headings[i];
points.push(origin.clone());
origin.x += Math.cos(headings[i]) * PANEL_LENGTH;
origin.z += Math.sin(headings[i]) * PANEL_LENGTH;
points.push(origin.clone());
}
updateArc(arcs[0], panels[0].group.position, 0, headings[0]);
updateArc(
arcs[1],
panels[1].group.position,
headings[0],
headings[1]
);
updateArc(
arcs[2],
panels[2].group.position,
headings[1],
headings[2]
);
const xs = points.map((point) => point.x);
const zs = points.map((point) => point.z);
const minX = Math.min(...xs) - 0.1;
const maxX = Math.max(...xs) + 0.1;
const minZ = Math.min(...zs) - 0.1;
const maxZ = Math.max(...zs) + 0.1;
const clearance = Math.max(0, CORRIDOR_LEFT - maxX);
document.querySelector("#clearanceValue").textContent =
`${clearance.toFixed(1)} m`;
document.querySelector("#spanValue").textContent =
`${(maxX - minX).toFixed(1)} × ${(maxZ - minZ).toFixed(1)} m`;
updateSightlines();
}
angleInputs.forEach((input) => {
input.addEventListener("input", updateDivider);
});
const presets = {
straight: [0, 0, 0],
zigzag: [0, 58, -58],
folded: [0, 138, -138]
};
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const values = presets[button.dataset.preset];
angleInputs.forEach((input, index) => {
input.value = values[index];
});
updateDivider();
});
});
// ---------------------------------------------------------------------
// Resize and render loop.
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateDivider();
resetCamera();
updateCamera();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
cameraState.yaw +=
(cameraState.desiredYaw - cameraState.yaw) * 0.12;
cameraState.pitch +=
(cameraState.desiredPitch - cameraState.pitch) * 0.12;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * 0.12;
updateCamera();
const pulse = 1 + Math.sin(time * 2.2) * 0.055;
observerHalo.scale.setScalar(pulse);
for (const target of targets) {
target.marker.rotation.y = time * 0.7;
target.marker.rotation.x = time * 0.35;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```