Prompt specification
Build or customize the Three.js 3D scene "Funicular cabin beside a hillside stair" 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: Funicular cabin beside a hillside stair
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/funicular-cabin-beside-a-hillside-stair-x2778
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows Petit-Champlain in Québec City. Create a compact referenced Québec vignette with funicular track, cabin, and nearby stepped route. Show two ways to reach the same higher level. Voxel style.
Working Three.js Starter (funicular-cabin-beside-a-hillside-stair-x2778):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#d8e8e4" />
<title>Petit-Champlain — Two Ways Up</title>
<style>
:root {
--ink: #17363b;
--muted: #607679;
--paper: rgba(255, 252, 242, 0.94);
--line: rgba(23, 54, 59, 0.14);
--funicular: #d99127;
--stairs: #248f91;
--petit: #a8443e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9e0df;
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%;
outline: none;
touch-action: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
overflow: hidden;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(255, 255, 255, 0.7);
background: var(--paper);
box-shadow: 0 12px 35px rgba(22, 48, 51, 0.14);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 20px;
border-radius: 18px;
}
.kicker {
margin-bottom: 7px;
color: var(--petit);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(31px, 4vw, 44px);
font-weight: 600;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 10px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.routes {
display: grid;
gap: 8px;
}
.route {
display: grid;
grid-template-columns: 34px 1fr auto;
align-items: center;
width: 100%;
padding: 9px 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.66);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.route:hover,
.route:focus-visible {
transform: translateY(-1px);
border-color: rgba(23, 54, 59, 0.32);
background: white;
outline: none;
}
.route-number {
display: grid;
place-items: center;
width: 24px;
height: 24px;
border-radius: 7px;
color: white;
font-size: 10px;
font-weight: 900;
}
.route[data-focus="funicular"] .route-number {
background: var(--funicular);
}
.route[data-focus="stairs"] .route-number {
background: var(--stairs);
}
.route strong {
display: block;
font-size: 12px;
font-weight: 800;
}
.route small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.route-arrow {
color: var(--muted);
font-size: 15px;
}
#tools {
top: 22px;
right: 22px;
display: flex;
gap: 6px;
padding: 7px;
border-radius: 13px;
}
.tool {
min-height: 34px;
padding: 8px 11px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.tool:hover,
.tool:focus-visible {
background: #e7efeb;
outline: none;
}
#hint {
right: 22px;
bottom: 20px;
padding: 10px 13px;
border-radius: 11px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.02em;
}
#credit {
position: fixed;
z-index: 5;
left: 22px;
bottom: 20px;
max-width: 310px;
padding: 9px 12px;
border-radius: 10px;
background: rgba(255, 252, 242, 0.82);
color: rgba(23, 54, 59, 0.68);
font-size: 9px;
line-height: 1.4;
box-shadow: 0 8px 24px rgba(22, 48, 51, 0.08);
}
.map-label {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 8px;
min-width: max-content;
padding: 7px 10px 7px 7px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 10px;
background: rgba(255, 252, 242, 0.92);
box-shadow: 0 6px 18px rgba(20, 42, 45, 0.15);
opacity: 0;
transition: opacity 120ms linear;
will-change: transform;
}
.map-label .pin {
display: grid;
place-items: center;
width: 25px;
height: 25px;
border-radius: 7px;
color: white;
font-size: 10px;
font-weight: 900;
}
.map-label strong {
display: block;
font-size: 11px;
font-weight: 850;
line-height: 1.1;
}
.map-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
line-height: 1.1;
}
#label-funicular .pin {
background: var(--funicular);
}
#label-stairs .pin {
background: var(--stairs);
}
#label-upper .pin {
background: var(--petit);
}
#label-lower .pin {
background: var(--ink);
}
@media (max-width: 700px) {
#intro {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 15px;
}
.subtitle {
margin-bottom: 12px;
}
#tools {
top: auto;
right: 12px;
bottom: 12px;
}
#hint,
#credit {
display: none;
}
.map-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="labels" aria-hidden="true">
<div class="map-label" id="label-funicular">
<span class="pin">1</span>
<div>
<strong>Funiculaire</strong>
<small>Direct inclined climb</small>
</div>
</div>
<div class="map-label" id="label-stairs">
<span class="pin">2</span>
<div>
<strong>Escalier</strong>
<small>Nearby stepped route</small>
</div>
</div>
<div class="map-label" id="label-upper">
<span class="pin">↗</span>
<div>
<strong>Dufferin Terrace</strong>
<small>Château Frontenac silhouette</small>
</div>
</div>
<div class="map-label" id="label-lower">
<span class="pin">◆</span>
<div>
<strong>Petit-Champlain</strong>
<small>Québec City, Québec</small>
</div>
</div>
</div>
<section class="panel" id="intro" aria-label="Scene information">
<div class="kicker">Québec City · Lower Town</div>
<h1>Petit-Champlain</h1>
<p class="subtitle">
Two ways climb the cliff: the historic funicular and its neighboring stepped route.
</p>
<div class="routes">
<button class="route" data-focus="funicular" type="button">
<span class="route-number">01</span>
<span>
<strong>Funicular</strong>
<small>Follow the inclined cabin</small>
</span>
<span class="route-arrow">→</span>
</button>
<button class="route" data-focus="stairs" type="button">
<span class="route-number">02</span>
<span>
<strong>Stepped route</strong>
<small>Climb beside the track</small>
</span>
<span class="route-arrow">→</span>
</button>
</div>
</section>
<nav class="panel" id="tools" aria-label="View controls">
<button class="tool" data-focus="overview" type="button">Overview</button>
<button class="tool" id="ride-toggle" type="button">Pause cabin</button>
</nav>
<div class="panel" id="hint">
Drag to orbit · Wheel to zoom · Right-drag or Shift-drag to pan
</div>
<div id="credit">
A compact voxel interpretation of the Petit-Champlain funicular and Dufferin Terrace.
The two routes converge at the same upper landing.
</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, camera
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9e0df);
scene.fog = new THREE.Fog(0xc9e0df, 28, 58);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel scene of Petit-Champlain in Quebec City"
);
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff5dc, 0x59717b, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe0aa, 3.0);
sun.position.set(-10, 17, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 45;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bd9ef, 1.05);
fill.position.set(12, 8, -12);
scene.add(fill);
// ---------------------------------------------------------------------
// Materials and construction helpers
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
const M = {
base: material(0x52666a),
lowerGround: material(0x9a9583),
cobble: material(0x737b78),
cobbleLight: material(0x8d9189),
cliff: material(0x827d70),
stoneA: material(0x9a9280),
stoneB: material(0x817b70),
stoneC: material(0xb0a58f),
upperGround: material(0x78956c),
upperPath: material(0x8a8f7e),
wood: material(0x76513a),
woodLight: material(0xa7794f),
darkWood: material(0x49352d),
rail: material(0x39464a, { metalness: 0.25, roughness: 0.55 }),
sleeper: material(0x76513b),
stairA: material(0xb1a18b),
stairB: material(0xc0ae94),
stairEdge: material(0x278f91),
amber: material(0xd99127),
cream: material(0xf1d58f),
red: material(0xa8443e),
green: material(0x365c52),
window: material(0x244d58, {
roughness: 0.35,
metalness: 0.12,
emissive: 0x102c33,
emissiveIntensity: 0.18
}),
wallCream: material(0xe1c89d),
wallBlue: material(0x7394a0),
wallRed: material(0xb76e5d),
wallMustard: material(0xc29a52),
wallStone: material(0xb9ad91),
roofGreen: material(0x365f55),
roofRed: material(0x8d443c),
roofSlate: material(0x4c5c61),
leaf: material(0x4d7957),
leafLight: material(0x648b5c),
leafDark: material(0x3e6850),
water: material(0x62a8b1, { roughness: 0.3, metalness: 0.12 }),
waterLight: material(0x91c8c8),
skin: material(0xd8a37f),
white: material(0xf4eee0),
black: material(0x263236)
};
function box(parent, width, height, depth, x, y, z, mat) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beamBetween(parent, a, b, width, height, mat) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, length),
mat
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cubeSign(x, y, z, mat, width = 0.48) {
box(scene, 0.075, 1.0, 0.075, x, y - 0.5, z, M.darkWood);
box(scene, width, width, 0.09, x, y, z, mat);
}
// ---------------------------------------------------------------------
// Diorama terrain
// ---------------------------------------------------------------------
const LOWER_Y = 0.4;
const UPPER_Y = 5.5;
// Display floor and beveled-looking block base.
box(scene, 90, 0.12, 90, 0, -1.08, 0, material(0xc9e0df));
box(scene, 15.2, 0.72, 16.0, 0, -0.64, 0, M.base);
box(scene, 14.9, 0.7, 15.7, 0, 0.05, 0, M.lowerGround);
// Upper cliff and terrace.
box(
scene,
14.9,
4.95,
4.4,
0,
(LOWER_Y + 5.35) / 2,
-6.15,
M.cliff
);
box(scene, 14.9, 0.15, 4.4, 0, UPPER_Y - 0.075, -6.15, M.upperGround);
// Individual retaining-wall blocks create the stepped voxel cliff face.
for (let row = 0; row < 9; row++) {
const y = 0.67 + row * 0.54;
const offset = row % 2 === 0 ? -0.1 : 0.08;
for (let col = 0; col < 8; col++) {
const x = -6.65 + col * 1.9 + offset;
const stone = [M.stoneA, M.stoneB, M.stoneC][
(row + col * 2) % 3
];
box(scene, 1.78, 0.49, 0.17, x, y, -3.91, stone);
}
}
// Shared upper landing: both routes terminate here.
box(scene, 11.2, 0.13, 1.05, 0, UPPER_Y - 0.065, -4.34, M.upperPath);
// Shared lower plaza.
box(scene, 11.3, 0.12, 1.65, 0, LOWER_Y - 0.06, 5.36, M.cobble);
// Small central pedestrian lane.
for (let i = 0; i < 6; i++) {
box(
scene,
1.05,
0.045,
0.66,
0,
LOWER_Y + 0.025,
4.45 - i * 0.72,
i % 2 ? M.cobble : M.cobbleLight
);
}
// A narrow glimpse of the Saint Lawrence at the right edge.
box(scene, 1.32, 0.09, 10.5, 6.92, LOWER_Y + 0.04, 2.05, M.water);
box(scene, 0.18, 0.42, 10.5, 6.20, LOWER_Y - 0.03, 2.05, M.stoneA);
for (let i = 0; i < 9; i++) {
box(
scene,
0.48,
0.025,
0.08,
6.80 + (i % 2) * 0.18,
LOWER_Y + 0.10,
-2.5 + i * 1.15,
M.waterLight
);
}
// Tiny river boat.
box(scene, 0.78, 0.24, 1.12, 6.88, LOWER_Y + 0.20, 3.35, M.red);
box(scene, 0.62, 0.34, 0.58, 6.88, LOWER_Y + 0.47, 3.22, M.white);
box(scene, 0.68, 0.08, 0.64, 6.88, LOWER_Y + 0.67, 3.22, M.amber);
// ---------------------------------------------------------------------
// Funicular
// ---------------------------------------------------------------------
const trackX = -2.7;
const lowerZ = 5.13;
const upperZ = -4.15;
const trackA = new THREE.Vector3(trackX, 0.64, lowerZ);
const trackB = new THREE.Vector3(trackX, 5.64, upperZ);
// Two rails.
for (const side of [-0.49, 0.49]) {
beamBetween(
scene,
new THREE.Vector3(trackX + side, trackA.y, trackA.z),
new THREE.Vector3(trackX + side, trackB.y, trackB.z),
0.11,
0.14,
M.rail
);
}
// Sleepers and small amber route markers.
const sleeperCount = 20;
for (let i = 0; i <= sleeperCount; i++) {
const t = i / sleeperCount;
const p = trackA.clone().lerp(trackB, t);
box(
scene,
1.34,
0.11,
0.21,
p.x,
p.y - 0.12,
p.z,
M.sleeper
);
if (i % 4 === 0) {
box(
scene,
0.11,
0.07,
0.28,
p.x - 0.69,
p.y - 0.05,
p.z,
M.amber
);
}
}
// Track supports.
for (const t of [0.20, 0.43, 0.65, 0.84]) {
const p = trackA.clone().lerp(trackB, t);
const height = Math.max(0.12, p.y - LOWER_Y);
box(
scene,
0.19,
height,
0.19,
p.x,
LOWER_Y + height / 2,
p.z,
M.rail
);
}
// Cabin group: body stays level while its position follows the incline.
const cabin = new THREE.Group();
scene.add(cabin);
box(cabin, 1.48, 0.23, 1.76, 0, 0.23, 0, M.rail);
box(cabin, 1.38, 1.02, 1.64, 0, 0.86, 0, M.cream);
box(cabin, 1.43, 0.19, 1.69, 0, 0.49, 0, M.red);
box(cabin, 1.58, 0.18, 1.84, 0, 1.47, 0, M.green);
// Front and rear windows.
box(cabin, 1.02, 0.57, 0.045, 0, 1.03, -0.835, M.window);
box(cabin, 1.02, 0.57, 0.045, 0, 1.03, 0.835, M.window);
// Side windows.
for (const side of [-1, 1]) {
box(cabin, 0.045, 0.57, 0.83, side * 0.705, 1.03, 0, M.window);
box(cabin, 0.055, 0.59, 0.055, side * 0.705, 1.03, 0, M.cream);
}
// Window dividers and door hints.
box(cabin, 0.045, 0.59, 0.055, 0, 1.03, -0.865, M.cream);
box(cabin, 0.045, 0.59, 0.055, 0, 1.03, 0.865, M.cream);
box(cabin, 0.045, 0.66, 0.055, 0, 0.78, -0.865, M.cream);
// Funicular station canopies.
function stationCanopy(z, baseY) {
box(scene, 2.32, 0.20, 1.55, trackX, baseY + 2.35, z, M.green);
box(scene, 2.38, 0.12, 1.60, trackX, baseY + 2.20, z, M.amber);
for (const side of [-1, 1]) {
box(
scene,
0.11,
2.10,
0.11,
trackX + side * 1.03,
baseY + 1.05,
z + 0.48,
M.green
);
}
}
stationCanopy(5.20, LOWER_Y);
stationCanopy(-4.12, UPPER_Y);
// Small attendant's booths.
function booth(x, z, y) {
box(scene, 1.08, 1.50, 1.02, x, y + 0.75, z, M.wallMustard);
box(scene, 1.22, 0.16, 1.16, x, y + 1.57, z, M.roofSlate);
box(scene, 0.52, 0.44, 0.045, x, y + 0.99, z + 0.525, M.window);
box(scene, 0.32, 0.67, 0.05, x + 0.25, y + 0.34, z + 0.535, M.green);
}
booth(-4.62, 4.80, LOWER_Y);
booth(-4.65, -4.62, UPPER_Y);
// ---------------------------------------------------------------------
// Neighboring stepped route
// ---------------------------------------------------------------------
const stairX = 2.65;
const stairWidth = 2.05;
const stairSteps = 25;
const stairRun = lowerZ - upperZ;
const tread = stairRun / stairSteps;
const rise = (UPPER_Y - LOWER_Y) / stairSteps;
for (let i = 0; i < stairSteps; i++) {
const top = LOWER_Y + (i + 1) * rise;
const z = lowerZ - (i + 0.5) * tread;
const height = top - LOWER_Y;
box(
scene,
stairWidth,
height,
tread + 0.025,
stairX,
LOWER_Y + height / 2,
z,
i % 2 ? M.stairA : M.stairB
);
// Colored nosing makes the second route easy to identify.
box(
scene,
stairWidth * 0.94,
0.035,
0.055,
stairX,
top + 0.017,
z + tread * 0.42,
M.stairEdge
);
}
// Sloped handrails.
for (const side of [-1, 1]) {
const railX = stairX + side * 1.07;
beamBetween(
scene,
new THREE.Vector3(railX, LOWER_Y + 1.05, lowerZ - 0.12),
new THREE.Vector3(railX, UPPER_Y + 1.05, upperZ + 0.12),
0.09,
0.09,
M.stairEdge
);
for (let i = 1; i < stairSteps; i += 3) {
const z = lowerZ - (i + 0.5) * tread;
const top = LOWER_Y + (i + 1) * rise;
box(
scene,
0.085,
1.05,
0.085,
railX,
top + 0.525,
z,
M.stairEdge
);
}
}
cubeSign(1.18, LOWER_Y + 1.18, 5.18, M.stairEdge);
cubeSign(-1.82, LOWER_Y + 1.18, 5.18, M.amber);
// ---------------------------------------------------------------------
// Lower Town architecture
// ---------------------------------------------------------------------
function house(x, z, width, depth, height, wallMat, roofMat) {
const baseY = LOWER_Y;
box(
scene,
width + 0.08,
0.12,
depth + 0.08,
x,
baseY + 0.06,
z,
M.stoneC
);
box(
scene,
width,
height,
depth,
x,
baseY + height / 2,
z,
wallMat
);
// Stepped voxel roof.
const roofWidths = [width + 0.20, width * 0.74, width * 0.38];
for (let i = 0; i < roofWidths.length; i++) {
box(
scene,
roofWidths[i],
0.17,
depth + 0.20,
x,
baseY + height + 0.085 + i * 0.15,
z,
roofMat
);
}
// Front windows and door.
const windowRows = height > 2.6 ? [0.85, 1.62] : [0.95];
for (const wy of windowRows) {
for (const dx of [-width * 0.25, width * 0.25]) {
box(
scene,
0.31,
0.43,
0.05,
x + dx,
baseY + wy,
z + depth / 2 + 0.03,
M.window
);
}
}
box(
scene,
0.36,
0.76,
0.055,
x + width * 0.12,
baseY + 0.38,
z + depth / 2 + 0.035,
M.green
);
// Side windows.
box(
scene,
0.045,
0.42,
0.36,
x + width / 2 + 0.03,
baseY + 1.04,
z + 0.18,
M.window
);
box(
scene,
0.18,
0.39,
0.18,
x - width * 0.25,
baseY + height + 0.56,
z - depth * 0.18,
M.stoneB
);
}
house(-5.42, 1.20, 1.62, 1.90, 2.55, M.wallCream, M.roofRed);
house(-5.42, -1.25, 1.62, 1.90, 3.05, M.wallRed, M.roofSlate);
house(5.05, 0.95, 1.62, 1.85, 2.65, M.wallBlue, M.roofSlate);
house(5.05, -1.40, 1.62, 1.85, 3.20, M.wallMustard, M.roofGreen);
// Upper silhouette inspired by Château Frontenac.
box(scene, 2.15, 2.00, 1.55, 4.70, UPPER_Y + 1.0, -6.85, M.wallStone);
box(scene, 1.05, 3.18, 1.05, 4.58, UPPER_Y + 1.59, -7.10, M.wallStone);
box(scene, 1.25, 0.16, 1.25, 4.58, UPPER_Y + 3.24, -7.10, M.roofGreen);
box(scene, 0.62, 0.70, 0.62, 4.58, UPPER_Y + 3.66, -7.10, M.roofGreen);
box(scene, 2.36, 0.18, 1.76, 4.70, UPPER_Y + 2.08, -6.85, M.roofGreen);
for (let i = 0; i < 4; i++) {
box(
scene,
0.24,
0.37,
0.04,
4.08 + i * 0.42,
UPPER_Y + 1.15,
-6.055,
M.window
);
}
// ---------------------------------------------------------------------
// Trees, lamps, benches, and tiny visitors
// ---------------------------------------------------------------------
function tree(x, z, y, scale = 1) {
box(
scene,
0.18 * scale,
0.75 * scale,
0.18 * scale,
x,
y + 0.375 * scale,
z,
M.wood
);
const clusters = [
[0, 1.02, 0, 0.72, 0.55, 0.67, M.leaf],
[-0.28, 0.94, 0.07, 0.49, 0.46, 0.51, M.leafLight],
[0.29, 1.04, -0.04, 0.52, 0.47, 0.54, M.leafDark],
[0.03, 1.40, 0.01, 0.54, 0.43, 0.52, M.leaf]
];
for (const [dx, dy, dz, w, h, d, mat] of clusters) {
box(
scene,
w * scale,
h * scale,
d * scale,
x + dx * scale,
y + dy * scale,
z + dz * scale,
mat
);
}
}
tree(-5.15, -6.45, UPPER_Y, 1.15);
tree(-2.65, -7.10, UPPER_Y, 0.95);
tree(0.05, -6.85, UPPER_Y, 1.08);
tree(2.15, -7.35, UPPER_Y, 0.85);
tree(-6.10, 3.60, LOWER_Y, 0.82);
function lamp(x, z, y) {
box(scene, 0.08, 1.55, 0.08, x, y + 0.775, z, M.rail);
box(scene, 0.30, 0.30, 0.30, x, y + 1.65, z, M.cream);
box(scene, 0.34, 0.08, 0.34, x, y + 1.84, z, M.rail);
}
lamp(-4.55, 5.85, LOWER_Y);
lamp(4.10, 5.85, LOWER_Y);
lamp(-0.90, -5.80, UPPER_Y);
lamp(1.20, -5.80, UPPER_Y);
function bench(x, z, y) {
box(scene, 1.10, 0.12, 0.42, x, y + 0.40, z, M.woodLight);
box(scene, 1.10, 0.40, 0.10, x, y + 0.65, z - 0.17, M.wood);
for (const dx of [-0.43, 0.43]) {
box(scene, 0.10, 0.40, 0.36, x + dx, y + 0.20, z, M.rail);
}
}
bench(-1.45, -6.45, UPPER_Y);
bench(-5.55, -4.95, UPPER_Y);
bench(4.65, 5.75, LOWER_Y);
function person(x, z, y, shirtMat, scale = 1) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
scene.add(group);
box(group, 0.25, 0.44, 0.20, 0, 0.54, 0, shirtMat);
box(group, 0.20, 0.20, 0.20, 0, 0.87, 0, M.skin);
box(group, 0.075, 0.34, 0.09, -0.07, 0.17, 0, M.black);
box(group, 0.075, 0.34, 0.09, 0.07, 0.17, 0, M.black);
}
person(0.25, 4.02, LOWER_Y, M.red, 0.92);
person(0.65, 3.66, LOWER_Y, M.wallBlue, 0.72);
person(-0.40, 5.83, LOWER_Y, M.amber, 0.82);
person(-0.80, -5.10, UPPER_Y, M.stairEdge, 0.76);
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labelData = [
{
element: document.getElementById("label-funicular"),
anchor: new THREE.Vector3(-2.70, 1.00, 5.62)
},
{
element: document.getElementById("label-stairs"),
anchor: new THREE.Vector3(2.65, 1.05, 5.45)
},
{
element: document.getElementById("label-upper"),
anchor: new THREE.Vector3(0.45, 6.65, -6.45)
},
{
element: document.getElementById("label-lower"),
anchor: new THREE.Vector3(0.20, 1.05, 6.85)
}
];
function updateLabels() {
for (const item of labelData) {
const projected = item.anchor.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.12 &&
projected.x < 1.12 &&
projected.y > -1.12 &&
projected.y < 1.12;
item.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
item.element.style.transform =
`translate(${x.toFixed(1)}px, ${y.toFixed(1)}px) translate(-50%, -50%)`;
}
}
}
// ---------------------------------------------------------------------
// Custom orbit, zoom, and pan controls — no external controls addon
// ---------------------------------------------------------------------
const initialTarget = new THREE.Vector3(0, 2.45, 0.15);
const desired = {
target: initialTarget.clone(),
radius: 19.2,
theta: 0.72,
phi: 0.96
};
const current = {
target: initialTarget.clone(),
radius: desired.radius,
theta: desired.theta,
phi: desired.phi
};
function focusView(name) {
if (name === "funicular") {
desired.target.set(-2.65, 2.75, 0.35);
desired.radius = 10.8;
desired.theta = 0.34;
desired.phi = 0.96;
} else if (name === "stairs") {
desired.target.set(2.65, 2.75, 0.35);
desired.radius = 10.8;
desired.theta = 1.02;
desired.phi = 0.96;
} else {
desired.target.set(0, 2.45, 0.15);
desired.radius = 19.2;
desired.theta = 0.72;
desired.phi = 0.96;
}
}
document.querySelectorAll("[data-focus]").forEach((button) => {
button.addEventListener("click", () => focusView(button.dataset.focus));
});
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrix.extractBasis(right, up, new THREE.Vector3());
const panScale = desired.radius * 0.00145;
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
} else {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.48,
1.28
);
}
});
function stopDragging(event) {
dragging = false;
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
8.2,
29
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") desired.theta -= 0.12;
if (event.key === "ArrowRight") desired.theta += 0.12;
if (event.key === "ArrowUp") desired.phi = Math.max(0.48, desired.phi - 0.08);
if (event.key === "ArrowDown") desired.phi = Math.min(1.28, desired.phi + 0.08);
if (event.key === "+" || event.key === "=") desired.radius = Math.max(8.2, desired.radius - 1);
if (event.key === "-") desired.radius = Math.min(29, desired.radius + 1);
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
let cabinRunning = !reducedMotion;
let rideTime = 0;
const rideButton = document.getElementById("ride-toggle");
function updateRideButton() {
rideButton.textContent = cabinRunning ? "Pause cabin" : "Play cabin";
rideButton.setAttribute("aria-pressed", String(!cabinRunning));
}
rideButton.addEventListener("click", () => {
cabinRunning = !cabinRunning;
updateRideButton();
});
updateRideButton();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (cabinRunning) {
rideTime += delta;
}
// Smooth out-of-bounds travel between the two stations.
const phase = (Math.sin(rideTime * 0.38 - Math.PI / 2) + 1) * 0.5;
cabin.position.copy(trackA).lerp(trackB, phase);
// Damped camera movement.
current.target.lerp(desired.target, 0.075);
current.radius += (desired.radius - current.radius) * 0.075;
current.theta += (desired.theta - current.theta) * 0.075;
current.phi += (desired.phi - current.phi) * 0.075;
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```