Prompt specification
Build or customize the Three.js 3D scene "Workshop courtyard arranged for perspective study" 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: Workshop courtyard arranged for perspective study
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/workshop-courtyard-arranged-for-perspective-study-x2387
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: Workshop courtyard arranged for perspective study. Build a compact courtyard with repeated arches, tiled ground, and one fixed viewing station. Show converging projection lines without making the actual parallel structures converge. Return one self-contained HTML file.
Working Three.js Starter (workshop-courtyard-arranged-for-perspective-study-x2387):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Workshop Courtyard — Perspective Study</title>
<style>
:root {
--ink: #243039;
--paper: rgba(247, 240, 224, 0.9);
--paper-solid: #f3ead8;
--line: rgba(36, 48, 57, 0.22);
--teal: #087f86;
--teal-light: #75d9da;
--orange: #ba673b;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7c7ad;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene, #guides {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene { z-index: 0; }
#scene canvas { display: block; }
#guides {
z-index: 2;
pointer-events: none;
transition: opacity 180ms ease;
}
#guides.hidden { opacity: 0; }
.panel {
position: fixed;
z-index: 4;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 36px rgba(47, 38, 27, 0.12);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.title-panel {
top: 22px;
left: 22px;
width: min(420px, calc(100vw - 44px));
padding: 17px 19px 16px;
border-radius: 3px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--teal);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 38px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: rgba(36, 48, 57, 0.7);
font-size: 12px;
line-height: 1.5;
}
.readout {
top: 22px;
right: 22px;
width: 205px;
padding: 14px 15px;
border-radius: 3px;
font-size: 11px;
}
.lock {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.lock-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #3b9b78;
box-shadow: 0 0 0 3px rgba(59, 155, 120, 0.16);
}
.readout dl {
display: grid;
grid-template-columns: 1fr auto;
gap: 7px 12px;
margin: 0;
}
.readout dt {
color: rgba(36, 48, 57, 0.56);
}
.readout dd {
margin: 0;
font-variant-numeric: tabular-nums;
font-weight: 700;
}
.guide-panel {
left: 22px;
bottom: 22px;
width: 315px;
padding: 14px;
border-radius: 3px;
}
button {
appearance: none;
width: 100%;
padding: 10px 12px;
border: 1px solid rgba(8, 127, 134, 0.38);
border-radius: 2px;
background: var(--teal);
color: white;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
cursor: pointer;
transition: background 140ms ease, transform 140ms ease;
}
button:hover {
background: #076d73;
transform: translateY(-1px);
}
button:focus-visible {
outline: 3px solid rgba(117, 217, 218, 0.55);
outline-offset: 2px;
}
.legend {
display: grid;
gap: 8px;
margin-top: 13px;
font-size: 10px;
color: rgba(36, 48, 57, 0.72);
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 29px;
height: 0;
border-top: 2px solid var(--teal);
}
.swatch.dashed {
border-top-style: dashed;
opacity: 0.7;
}
.swatch.structure {
border-top-color: #846b4e;
}
.principle {
right: 22px;
bottom: 22px;
width: 280px;
padding: 13px 14px;
border-radius: 3px;
font-size: 10px;
line-height: 1.45;
}
.principle strong {
display: block;
margin-bottom: 8px;
font-size: 10px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.diagram {
display: grid;
grid-template-columns: 34px 24px 34px;
align-items: center;
gap: 7px;
margin: 8px 0 9px;
}
.diagram span {
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-align: center;
}
.diagram svg {
width: 34px;
height: 40px;
overflow: visible;
}
.diagram .arrow {
width: 24px;
color: var(--orange);
font-size: 18px;
text-align: center;
}
.principle p { margin: 0; }
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #d7c7ad;
color: #435057;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.guide-solid {
stroke: var(--teal-light);
stroke-width: 1.8;
fill: none;
opacity: 0.92;
vector-effect: non-scaling-stroke;
}
.guide-extension {
stroke: var(--teal-light);
stroke-width: 1.2;
stroke-dasharray: 5 7;
fill: none;
opacity: 0.6;
vector-effect: non-scaling-stroke;
}
.guide-node {
fill: rgba(247, 240, 224, 0.95);
stroke: var(--teal);
stroke-width: 1.4;
vector-effect: non-scaling-stroke;
}
.vp-ring {
fill: rgba(8, 127, 134, 0.13);
stroke: var(--teal-light);
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
.vp-label {
fill: #f5edda;
stroke: rgba(36, 48, 57, 0.72);
stroke-width: 3px;
paint-order: stroke;
font: 700 10px Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.12em;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.title-panel .subtitle { display: none; }
.readout {
top: 108px;
right: 12px;
width: 165px;
}
.guide-panel {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
.principle { display: none; }
.legend {
grid-template-columns: repeat(3, 1fr);
gap: 7px;
}
.legend-row {
align-items: flex-start;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="A low-poly workshop courtyard viewed from one fixed perspective station"></div>
<svg id="guides" aria-hidden="true"></svg>
<header class="panel title-panel">
<div class="eyebrow">Perspective study / 01</div>
<h1>Maker’s Courtyard</h1>
<p class="subtitle">
A compact workshop court with repeated stone arcades, tiled ground,
and one locked viewing station.
</p>
</header>
<aside class="panel readout" aria-label="Camera information">
<div class="lock"><span class="lock-dot"></span> Camera locked</div>
<dl>
<dt>Station</dt><dd>01</dd>
<dt>Camera height</dt><dd>3.15 m</dd>
<dt>Principal axis</dt><dd>0°</dd>
<dt>Field of view</dt><dd>49°</dd>
</dl>
</aside>
<section class="panel guide-panel">
<button id="guideToggle" type="button" aria-pressed="true">Hide projection guides</button>
<div class="legend">
<div class="legend-row"><span class="swatch"></span><span>Projected parallel edge</span></div>
<div class="legend-row"><span class="swatch dashed"></span><span>Extension to vanishing point</span></div>
<div class="legend-row"><span class="swatch structure"></span><span>Unmodified 3D structure</span></div>
</div>
</section>
<aside class="panel principle">
<strong>Parallel in world / convergent in image</strong>
<div class="diagram">
<span>World</span>
<span class="arrow">→</span>
<span>Image</span>
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M4 10 H30 M4 30 H30" fill="none" stroke="#846b4e" stroke-width="1.5"/>
</svg>
<span class="arrow">→</span>
<svg viewBox="0 0 34 40" aria-hidden="true">
<path d="M4 10 L29 20 M4 30 L29 20" fill="none" stroke="#087f86" stroke-width="1.5"/>
</svg>
</div>
<p>
The cyan construction rays are screen-space annotations. The stone rails
and tiled edges remain truly parallel in the 3D courtyard.
</p>
</aside>
<div id="loading">Building courtyard study…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and the single fixed viewing station
// ------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const guideSvg = document.getElementById("guides");
const loading = document.getElementById("loading");
const renderer = new THREE.WebGLRenderer({
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.12;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8c8ae);
scene.fog = new THREE.Fog(0xd8c8ae, 27, 58);
const camera = new THREE.PerspectiveCamera(
49,
window.innerWidth / window.innerHeight,
0.1,
100
);
// This camera is deliberately locked: there are no orbit or pan controls.
camera.position.set(0, 3.15, 12.55);
camera.lookAt(0, 2.35, -5.5);
camera.updateMatrixWorld(true);
const hemisphere = new THREE.HemisphereLight(0xfff1d4, 0x746b5c, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0aa, 3.25);
sun.position.set(8, 15, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 20;
sun.shadow.camera.bottom = -18;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9fc5d1, 0.55);
fill.position.set(-9, 7, -4);
scene.add(fill);
// ------------------------------------------------------------
// Materials and reusable geometry helpers
// ------------------------------------------------------------
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
flatShading: true,
...options
});
}
const mat = {
ground: standard(0x9f9078),
grout: standard(0x665d51),
plaster: standard(0xd6bf98),
plasterDark: standard(0xb99f78),
stone: standard(0xc9b18a),
stoneLight: standard(0xd7c39d),
stoneMid: standard(0xb89c75),
stoneDark: standard(0x9d805d),
wood: standard(0x76503a),
woodLight: standard(0xa8794d),
woodDark: standard(0x49372e),
roof: standard(0x69483b),
roofEdge: standard(0x3f3a34),
metal: standard(0x303a3d, { metalness: 0.38, roughness: 0.55 }),
brass: standard(0xb88b3f, { metalness: 0.62, roughness: 0.42 }),
glass: standard(0x668b8b, {
emissive: 0x183638,
emissiveIntensity: 0.28,
roughness: 0.28
}),
leaf: standard(0x667c4f),
leafLight: standard(0x7e8f59),
awning: standard(0xa85c3e, { side: THREE.DoubleSide }),
rope: standard(0xb9a27b)
};
const archMaterials = [
mat.stone,
mat.stoneLight,
mat.stoneMid,
mat.stone,
mat.stoneDark
];
const boxGeometryCache = new Map();
function addBox(parent, size, position, material, castShadow = true) {
const key = size.join(",");
let geometry = boxGeometryCache.get(key);
if (!geometry) {
geometry = new THREE.BoxGeometry(...size);
boxGeometryCache.set(key, geometry);
}
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
position,
material,
castShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeGableRoof(x, y, z, width, length, height, material) {
const w = width / 2;
const l = length / 2;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute([
-w, 0, -l,
w, 0, -l,
0, height, -l,
-w, 0, l,
w, 0, l,
0, height, l
], 3)
);
geometry.setIndex([
0, 2, 1,
3, 4, 5,
0, 3, 5, 0, 5, 2,
1, 2, 5, 1, 5, 4,
0, 1, 4, 0, 4, 3
]);
geometry.computeVertexNormals();
const roof = new THREE.Mesh(geometry, material);
roof.position.set(x, y, z);
roof.castShadow = true;
roof.receiveShadow = true;
scene.add(roof);
return roof;
}
function makeLabelTexture(
title,
subtitle = "",
background = "#26383b",
foreground = "#f5ead2"
) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 256;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "rgba(245,234,210,0.34)";
context.lineWidth = 4;
context.strokeRect(15, 15, canvas.width - 30, canvas.height - 30);
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = foreground;
context.font = "700 70px Georgia, serif";
context.fillText(title, canvas.width / 2, subtitle ? 104 : 128);
if (subtitle) {
context.font = "700 28px Arial, sans-serif";
context.letterSpacing = "8px";
context.fillText(subtitle, canvas.width / 2, 181);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addLabel(
parent,
width,
height,
position,
title,
subtitle = "",
background = "#26383b",
foreground = "#f5ead2"
) {
const texture = makeLabelTexture(
title,
subtitle,
background,
foreground
);
const material = new THREE.MeshBasicMaterial({ map: texture });
const label = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
material
);
label.position.set(...position);
parent.add(label);
return label;
}
// ------------------------------------------------------------
// Ground and tiled courtyard
// ------------------------------------------------------------
addBox(
scene,
[72, 0.18, 72],
[0, -0.31, 0],
mat.ground,
false
);
addBox(
scene,
[12.4, 0.24, 24.4],
[0, -0.12, 0],
mat.grout,
false
);
const tileGeometry = new THREE.BoxGeometry(0.72, 0.08, 0.72);
const tileMaterial = standard(0xffffff, {
vertexColors: true,
roughness: 0.92
});
const tileCountX = 16;
const tileCountZ = 32;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCountX * tileCountZ
);
tiles.receiveShadow = true;
tiles.castShadow = false;
const dummy = new THREE.Object3D();
const tileColors = [
new THREE.Color(0xc7ad82),
new THREE.Color(0xd0b98e),
new THREE.Color(0xbfa77f),
new THREE.Color(0xd8c39a),
new THREE.Color(0xc2aa80)
];
let seed = 173;
function seededRandom() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
let tileIndex = 0;
for (let zIndex = 0; zIndex < tileCountZ; zIndex++) {
for (let xIndex = 0; xIndex < tileCountX; xIndex++) {
const x = -5.625 + xIndex * 0.75;
const z = -11.625 + zIndex * 0.75;
dummy.position.set(x, 0.02 + seededRandom() * 0.012, z);
dummy.rotation.set(
0,
(seededRandom() - 0.5) * 0.008,
0
);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
tiles.setColorAt(tileIndex, tileColors[Math.floor(seededRandom() * tileColors.length)]);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Raised side walkways.
for (const side of [-1, 1]) {
addBox(
scene,
[1.2, 0.17, 24.2],
[side * 6.58, 0.035, -0.2],
mat.stoneMid
);
}
// ------------------------------------------------------------
// Repeated arcade: identical translated modules, never scaled
// or tapered to fake perspective.
// ------------------------------------------------------------
const archSpring = 2.15;
const archInnerRadius = 1.55;
const archBand = 0.36;
const archMidRadius = archInnerRadius + archBand / 2;
const archSegments = 9;
const archCenters = [-8.4, -4.2, 0, 4.2, 8.4];
const archSegmentGeometry = new THREE.BoxGeometry(
0.78,
archBand,
0.69
);
function addArcade(side) {
const sideX = side * 6.15;
for (let bay = 0; bay < archCenters.length; bay++) {
const centerZ = archCenters[bay];
const group = new THREE.Group();
group.position.set(sideX, 0, centerZ);
scene.add(group);
// Straight, full-height supports.
for (const direction of [-1, 1]) {
addBox(
group,
[0.78, archSpring, 0.42],
[0, archSpring / 2, direction * 1.78],
archMaterials[(bay + (direction > 0 ? 1 : 0)) % archMaterials.length]
);
addBox(
group,
[0.9, 0.16, 0.56],
[0, 0.08, direction * 1.78],
mat.stoneDark
);
}
// Polygonal voussoirs form a true semicircular opening.
for (let segment = 0; segment < archSegments; segment++) {
const theta = (segment / (archSegments - 1)) * Math.PI;
const stone = new THREE.Mesh(
archSegmentGeometry,
archMaterials[(segment + bay + (side > 0 ? 1 : 0)) % archMaterials.length]
);
stone.position.set(
0,
archSpring + Math.sin(theta) * archMidRadius,
Math.cos(theta) * archMidRadius
);
// Local Y is radial and local Z follows the arch tangent.
stone.rotation.x = Math.PI / 2 - theta;
stone.castShadow = true;
stone.receiveShadow = true;
group.add(stone);
}
// Slightly emphasized keystone.
addBox(
group,
[0.88, 0.54, 0.55],
[0, archSpring + archMidRadius, 0],
mat.stoneLight
);
}
// These two long members are exactly parallel in world space.
addBox(
scene,
[0.92, 0.31, 21.1],
[sideX, 4.2, -0.05],
mat.stoneDark
);
addBox(
scene,
[1.02, 0.12, 21.2],
[sideX, 4.41, -0.05],
mat.stoneLight
);
}
addArcade(-1);
addArcade(1);
// ------------------------------------------------------------
// Workshop buildings behind the arcades
// ------------------------------------------------------------
for (const side of [-1, 1]) {
addBox(
scene,
[3.2, 4.45, 23.7],
[side * 8.8, 2.225, -1.05],
side < 0 ? mat.plasterDark : mat.plaster
);
makeGableRoof(
side * 8.8,
4.45,
-1.05,
3.8,
24.5,
1.05,
mat.roof
);
// Recessed side-wall panels visible through the arches.
for (const z of [-8.5, -4.2, 0, 4.2, 8.4]) {
addBox(
scene,
[0.08, 1.25, 1.0],
[side * 7.16, 2.15, z],
mat.woodDark
);
addBox(
scene,
[0.09, 0.95, 0.72],
[side * 7.10, 2.15, z],
mat.glass
);
}
}
// Rear workshop facade.
addBox(
scene,
[13.8, 5.0, 0.62],
[0, 2.5, -12.35],
mat.plaster
);
addBox(
scene,
[14.15, 0.32, 1.25],
[0, 5.08, -12.55],
mat.roofEdge
);
for (let x = -6; x <= 6; x += 2) {
addBox(
scene,
[0.22, 4.75, 0.12],
[x, 2.45, -11.99],
mat.stoneMid
);
}
// Large double door.
addBox(
scene,
[3.55, 3.65, 0.18],
[-1.0, 1.83, -11.96],
mat.woodDark
);
addBox(
scene,
[1.57, 3.35, 0.13],
[-1.78, 1.7, -11.83],
mat.wood
);
addBox(
scene,
[1.57, 3.35, 0.13],
[-0.22, 1.7, -11.83],
mat.wood
);
for (const x of [-1.78, -0.22]) {
for (const y of [0.8, 1.7, 2.6]) {
addBox(
scene,
[1.38, 0.11, 0.1],
[x, y, -11.72],
mat.woodDark
);
}
}
addBox(
scene,
[0.08, 3.3, 0.12],
[-1.0, 1.72, -11.69],
mat.metal
);
addBox(
scene,
[0.3, 0.09, 0.12],
[-1.13, 1.75, -11.61],
mat.brass
);
addBox(
scene,
[0.3, 0.09, 0.12],
[-0.87, 1.75, -11.61],
mat.brass
);
// Sloping fabric awning.
const awning = addBox(
scene,
[4.15, 0.12, 1.65],
[-1.0, 3.73, -11.12],
mat.awning
);
awning.rotation.x = -0.17;
addBox(
scene,
[4.15, 0.13, 0.15],
[-1.0, 3.55, -10.34],
mat.woodDark
);
// Workshop windows.
for (const x of [-4.75, 3.3]) {
addBox(
scene,
[2.05, 1.7, 0.16],
[x, 2.85, -11.92],
mat.woodDark
);
addBox(
scene,
[1.77, 1.4, 0.13],
[x, 2.85, -11.80],
mat.glass
);
addBox(
scene,
[0.09, 1.42, 0.13],
[x, 2.85, -11.70],
mat.woodDark
);
addBox(
scene,
[1.79, 0.09, 0.13],
[x, 2.85, -11.70],
mat.woodDark
);
}
addLabel(
scene,
4.4,
0.92,
[-1.0, 4.48, -11.68],
"MAKER'S YARD",
"WORKSHOP 07"
);
// ------------------------------------------------------------
// Hanging work lights
// ------------------------------------------------------------
for (const z of [-6.2, 0, 6.2]) {
addBox(
scene,
[12.2, 0.035, 0.035],
[0, 4.62, z],
mat.metal,
false
);
addCylinder(
scene,
0.014,
0.014,
0.75,
6,
[0, 4.25, z],
mat.metal,
false
);
const shade = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.42, 0.32, 8, 1, true),
mat.metal
);
shade.position.set(0, 3.79, z);
shade.castShadow = true;
scene.add(shade);
const bulb = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 8, 6),
standard(0xffe2a0, {
emissive: 0xffb94f,
emissiveIntensity: 1.8
})
);
bulb.position.set(0, 3.64, z);
scene.add(bulb);
const lampLight = new THREE.PointLight(0xffc46d, 1.35, 6.5, 2);
lampLight.position.set(0, 3.55, z);
scene.add(lampLight);
}
// ------------------------------------------------------------
// Workshop props
// ------------------------------------------------------------
function makeCrate(x, z, rotation = 0, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.08, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
addBox(group, [0.86, 0.72, 0.86], [0, 0.36, 0], mat.woodLight);
addBox(group, [0.92, 0.1, 0.92], [0, 0.08, 0], mat.woodDark);
addBox(group, [0.92, 0.1, 0.92], [0, 0.67, 0], mat.woodDark);
for (const side of [-1, 1]) {
addBox(
group,
[0.09, 0.72, 0.91],
[side * 0.44, 0.36, 0],
mat.woodDark
);
}
}
function makeBarrel(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0.07, z);
group.rotation.y = rotation;
scene.add(group);
addCylinder(
group,
0.42,
0.35,
0.95,
8,
[0, 0.48, 0],
mat.wood
);
for (const y of [0.24, 0.72]) {
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(0.405, 0.035, 4, 12),
mat.metal
);
hoop.rotation.x = Math.PI / 2;
hoop.position.y = y;
hoop.castShadow = true;
group.add(hoop);
}
}
function makeWorkbench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
addBox(group, [3.0, 0.18, 1.15], [0, 1.35, 0], mat.woodLight);
for (const lx of [-1.25, 1.25]) {
for (const lz of [-0.42, 0.42]) {
addBox(
group,
[0.16, 1.3, 0.16],
[lx, 0.65, lz],
mat.woodDark
);
}
}
addBox(group, [2.7, 0.12, 0.18], [0, 0.47, 0], mat.wood);
addBox(group, [0.8, 0.16, 0.5], [-0.65, 1.52, 0.08], mat.metal);
addBox(group, [0.65, 0.12, 0.38], [0.55, 1.49, -0.05], mat.woodDark);
}
function makeTree(x, z) {
const group = new THREE.Group();
group.position.set(x, 0.06, z);
scene.add(group);
addBox(group, [1.25, 0.42, 1.25], [0, 0.21, 0], mat.stoneDark);
addCylinder(group, 0.16, 0.23, 2.0, 6, [0, 1.2, 0], mat.wood);
const foliage = [
[0, 2.35, 0, 0.95, mat.leaf],
[-0.42, 2.1, 0.1, 0.72, mat.leafLight],
[0.4, 2.18, -0.12, 0.76, mat.leaf],
[0.08, 2.75, 0.06, 0.72, mat.leafLight]
];
for (const [px, py, pz, radius, material] of foliage) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, 0),
material
);
mesh.position.set(px, py, pz);
mesh.rotation.set(0.2, 0.4, 0.1);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
}
makeWorkbench(3.8, -8.0, -0.06);
makeWorkbench(-3.7, -6.8, 0.08);
makeCrate(2.15, -9.75, 0.12, 1.0);
makeCrate(2.92, -9.45, -0.12, 0.75);
makeCrate(-4.85, -9.6, -0.05, 0.95);
makeBarrel(4.95, -9.6, 0.2);
makeBarrel(-2.4, -9.9, -0.2);
makeCrate(4.2, 5.4, 0.22, 0.75);
makeBarrel(-4.85, 5.15, 0.0);
makeTree(-4.65, 8.25);
makeTree(4.85, 8.55);
// Stacked timber.
for (let row = 0; row < 3; row++) {
for (let column = 0; column < 3 - row; column++) {
addBox(
scene,
[0.24, 0.2, 2.5],
[-3.8 + column * 0.27 + row * 0.14, 0.18 + row * 0.22, 2.0],
row % 2 ? mat.woodLight : mat.wood
);
}
}
// ------------------------------------------------------------
// Fixed viewing platform in the foreground
// ------------------------------------------------------------
const station = new THREE.Group();
station.position.set(0, 0, 11.4);
scene.add(station);
addBox(station, [4.0, 0.18, 2.3], [0, 1.0, 0], mat.woodDark);
for (let plank = 0; plank < 9; plank++) {
addBox(
station,
[0.38, 0.08, 2.22],
[-1.6 + plank * 0.4, 1.13, 0],
plank % 3 === 0 ? mat.wood : mat.woodLight
);
}
for (const x of [-1.65, 1.65]) {
for (const z of [-0.78, 0.78]) {
addBox(
station,
[0.19, 1.25, 0.19],
[x, 0.45, z],
mat.woodDark
);
}
}
const stationRing = new THREE.Mesh(
new THREE.TorusGeometry(0.62, 0.026, 5, 32),
mat.brass
);
stationRing.rotation.x = Math.PI / 2;
stationRing.position.set(0, 1.19, 0);
station.add(stationRing);
addBox(
station,
[0.055, 0.025, 0.64],
[0, 1.19, 0],
mat.brass
);
addBox(
station,
[0.64, 0.025, 0.055],
[0, 1.19, 0],
mat.brass
);
// A small angled sign beside the station.
addBox(
station,
[0.12, 1.25, 0.12],
[-2.25, 1.68, 0.75],
mat.woodDark
);
addBox(
station,
[1.75, 0.93, 0.12],
[-2.25, 2.2, 0.75],
mat.woodDark
);
addLabel(
station,
1.62,
0.8,
[-2.25, 2.2, 0.82],
"VIEW 01",
"FIXED STATION",
"#294449",
"#f6e8ca"
);
// ------------------------------------------------------------
// Screen-space projection construction
//
// The architecture is never modified to converge. These SVG lines
// are projected from actual 3D points using the locked camera.
// ------------------------------------------------------------
const depthMembers = [
{
name: "left floor edge",
near: new THREE.Vector3(-6.0, 0.09, 10.35),
far: new THREE.Vector3(-6.0, 0.09, -11.85)
},
{
name: "right floor edge",
near: new THREE.Vector3(6.0, 0.09, 10.35),
far: new THREE.Vector3(6.0, 0.09, -11.85)
},
{
name: "left arcade rail",
near: new THREE.Vector3(-6.15, 4.46, 8.85),
far: new THREE.Vector3(-6.15, 4.46, -10.75)
},
{
name: "right arcade rail",
near: new THREE.Vector3(6.15, 4.46, 8.85),
far: new THREE.Vector3(6.15, 4.46, -10.75)
}
];
function projectToScreen(worldPoint) {
const point = worldPoint.clone().project(camera);
return {
x: (point.x * 0.5 + 0.5) * window.innerWidth,
y: (-point.y * 0.5 + 0.5) * window.innerHeight,
z: point.z
};
}
function projectVanishingPoint(direction) {
// Transform a direction at infinity into clip space.
const viewDirection = new THREE.Vector4(
direction.x,
direction.y,
direction.z,
0
).applyMatrix4(camera.matrixWorldInverse);
const clip = viewDirection.applyMatrix4(camera.projectionMatrix);
const ndcX = clip.x / clip.w;
const ndcY = clip.y / clip.w;
return {
x: (ndcX * 0.5 + 0.5) * window.innerWidth,
y: (-ndcY * 0.5 + 0.5) * window.innerHeight
};
}
function updateProjectionGuides() {
camera.updateMatrixWorld(true);
const vanishingPoint = projectVanishingPoint(
new THREE.Vector3(0, 0, -1)
);
const segments = [];
for (const member of depthMembers) {
const near = projectToScreen(member.near);
const far = projectToScreen(member.far);
segments.push(`
<line
class="guide-solid"
x1="${near.x.toFixed(2)}"
y1="${near.y.toFixed(2)}"
x2="${far.x.toFixed(2)}"
y2="${far.y.toFixed(2)}"
/>
<line
class="guide-extension"
x1="${far.x.toFixed(2)}"
y1="${far.y.toFixed(2)}"
x2="${vanishingPoint.x.toFixed(2)}"
y2="${vanishingPoint.y.toFixed(2)}"
/>
<circle
class="guide-node"
cx="${near.x.toFixed(2)}"
cy="${near.y.toFixed(2)}"
r="2.8"
/>
<circle
class="guide-node"
cx="${far.x.toFixed(2)}"
cy="${far.y.toFixed(2)}"
r="2.8"
/>
`);
}
guideSvg.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
guideSvg.innerHTML = `
${segments.join("\n")}
<g transform="translate(${vanishingPoint.x.toFixed(2)} ${vanishingPoint.y.toFixed(2)})">
<circle class="vp-ring" cx="0" cy="0" r="10"/>
<circle cx="0" cy="0" r="2.3" fill="#087f86"/>
<text class="vp-label" x="15" y="-10">VP · DEPTH</text>
</g>
`;
}
const guideToggle = document.getElementById("guideToggle");
guideToggle.addEventListener("click", () => {
const hidden = guideSvg.classList.toggle("hidden");
guideToggle.setAttribute("aria-pressed", String(!hidden));
guideToggle.textContent = hidden
? "Show projection guides"
: "Hide projection guides";
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
updateProjectionGuides();
renderer.render(scene, camera);
}
window.addEventListener("resize", resize);
updateProjectionGuides();
renderer.render(scene, camera);
requestAnimationFrame(() => loading.remove());
</script>
</body>
</html>
```