Prompt specification
Build or customize the Three.js 3D scene "Kathmandu Durbar Square selected-corner scene" 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: Kathmandu Durbar Square selected-corner scene
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kathmandu-durbar-square-selected-corner-scene-x2999
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Kathmandu Durbar Square. Build a bounded low-poly scene with a few referenced temple and civic forms, raised plinths, and public paths. Specify the represented date because restoration and damage states may differ. Low-poly.
Working Three.js Starter (kathmandu-durbar-square-selected-corner-scene-x2999):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kathmandu Durbar Square — Low-Poly Interpretation</title>
<style>
:root {
color-scheme: dark;
--ink: #f5edda;
--muted: #c9c0ad;
--gold: #e0b64d;
--panel: rgba(26, 30, 28, 0.82);
--line: rgba(255, 255, 255, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd8d1;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
display: block;
width: 100%;
height: 100%;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
padding: 19px 20px 17px;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 18px 48px rgba(20, 23, 21, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 38px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.date {
display: flex;
align-items: baseline;
gap: 8px;
margin: 15px 0 11px;
padding: 10px 11px;
color: #f8e5af;
background: rgba(224, 182, 77, 0.1);
border: 1px solid rgba(224, 182, 77, 0.25);
border-radius: 8px;
font-size: 12px;
line-height: 1.35;
}
.date span {
flex: 0 0 auto;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.description {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.forms {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px 10px;
margin: 13px 0 14px;
padding: 0;
list-style: none;
color: #e6ddc9;
font-size: 11px;
}
.forms li::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin: 0 7px 1px 0;
background: var(--gold);
border-radius: 50%;
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
button,
.toggle {
color: var(--ink);
font: inherit;
}
button {
padding: 7px 10px;
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 7px;
cursor: pointer;
font-size: 11px;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
}
.toggle {
display: flex;
align-items: center;
gap: 7px;
margin-right: auto;
color: var(--muted);
cursor: pointer;
font-size: 11px;
}
.toggle input {
accent-color: var(--gold);
}
.controls {
position: fixed;
z-index: 10;
right: 18px;
bottom: 18px;
padding: 9px 12px;
color: rgba(255, 255, 255, 0.86);
background: rgba(26, 30, 28, 0.7);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
font-size: 11px;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #efe7d7;
background: #26302c;
font-family: Georgia, serif;
font-size: 20px;
transition: opacity 0.4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.panel {
top: 10px;
left: 10px;
width: min(340px, calc(100vw - 20px));
padding: 15px 16px;
}
.forms {
display: none;
}
.description {
font-size: 11px;
}
.controls {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<main id="app" aria-label="Interactive low-poly model of Kathmandu Durbar Square"></main>
<section class="panel">
<div class="eyebrow">Architectural interpretation · Nepal</div>
<h1>Kathmandu<br>Durbar Square</h1>
<div class="date">
<span>Represented date</span>
<time datetime="2015">c. 2015, interpreted in its pre-25-April condition</time>
</div>
<p class="description">
A bounded, low-poly reconstruction of the Hanuman Dhoka civic and temple
precinct. The arrangement is interpretive rather than survey-exact;
later restoration, damage, and reconstruction states may differ.
</p>
<ul class="forms">
<li>Taleju Temple</li>
<li>Narayan Temple</li>
<li>Shiva–Parvati Temple</li>
<li>Kumari Ghar</li>
<li>Old Palace range</li>
</ul>
<div class="actions">
<label class="toggle">
<input id="labels" type="checkbox" checked>
Form labels
</label>
<button id="reset" type="button">Reset view</button>
<button id="zoom-in" type="button" aria-label="Zoom in">+</button>
<button id="zoom-out" type="button" aria-label="Zoom out">−</button>
</div>
</section>
<div class="controls">
Drag: orbit · Shift/right-drag: pan · Wheel/pinch buttons: zoom · Arrow keys: orbit
</div>
<div id="loading" role="status">Building the Durbar Square…</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 camera
// -------------------------------------------------------------------------
const app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbd8d1);
scene.fog = new THREE.Fog(0xcbd8d1, 105, 185);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
300
);
const hemisphere = new THREE.HemisphereLight(0xe8f3ed, 0x70604b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6b3, 3.25);
sun.position.set(-38, 72, 42);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -65;
sun.shadow.camera.right = 65;
sun.shadow.camera.top = 58;
sun.shadow.camera.bottom = -58;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 160;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d4df, 0.75);
fill.position.set(50, 24, -45);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.84,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? true,
side: options.side ?? THREE.FrontSide,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1
});
}
const materials = {
ground: material(0x706a56),
paving: material(0xc4b89f),
path: material(0xd0c3a8),
pathEdge: material(0x817964),
stone: material(0xa99c82),
stoneLight: material(0xc2b69b),
stoneDark: material(0x766e5d),
plaster: material(0xeee5d1),
plasterShade: material(0xd5c8b0),
redBrick: material(0x9c4032),
redDark: material(0x672e27),
timber: material(0x482820),
dark: material(0x24231f),
gold: material(0xd8a936, {
metalness: 0.38,
roughness: 0.48
}),
goldDark: material(0xa97820, {
metalness: 0.32,
roughness: 0.56
}),
roofUnder: material(0x70401f),
foliage: material(0x53684a),
foliageLight: material(0x72815c),
trunk: material(0x5b4430)
};
function box(parent, size, position, mat) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, segments, position, mat) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function hipRoof(parent, width, depth, height, baseY, roofMaterial) {
const tw = width * 0.36;
const td = depth * 0.34;
const positions = new Float32Array([
-width / 2, 0, -depth / 2,
width / 2, 0, -depth / 2,
width / 2, 0, depth / 2,
-width / 2, 0, depth / 2,
-tw / 2, height, -td / 2,
tw / 2, height, -td / 2,
tw / 2, height, td / 2,
-tw / 2, height, td / 2
]);
const indices = [
3, 2, 6, 3, 6, 7,
2, 1, 5, 2, 5, 6,
1, 0, 4, 1, 4, 5,
0, 3, 7, 0, 7, 4,
4, 7, 6, 4, 6, 5
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const roof = new THREE.Mesh(geometry, roofMaterial);
roof.position.y = baseY;
roof.castShadow = true;
roof.receiveShadow = true;
parent.add(roof);
// Projecting eaves give the roofs a stronger pagoda silhouette.
box(parent, [width + 0.85, 0.20, 0.22],
[0, baseY - 0.08, -depth / 2], materials.goldDark);
box(parent, [width + 0.85, 0.20, 0.22],
[0, baseY - 0.08, depth / 2], materials.goldDark);
box(parent, [0.22, 0.20, depth + 0.85],
[-width / 2, baseY - 0.08, 0], materials.goldDark);
box(parent, [0.22, 0.20, depth + 0.85],
[width / 2, baseY - 0.08, 0], materials.goldDark);
return roof;
}
function triangularPrism(parent, width, height, depth, position, mat) {
const w = width / 2;
const d = depth / 2;
const h = height / 2;
const positions = new Float32Array([
-w, -h, d,
w, -h, d,
0, h, d,
-w, -h, -d,
w, -h, -d,
0, h, -d
]);
const indices = [
0, 1, 2,
3, 5, 4,
0, 3, 4, 0, 4, 1,
1, 4, 5,
0, 2, 5, 0, 5, 3
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (1664525 * value + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(20150425);
// -------------------------------------------------------------------------
// Bounded ground plane and public paths
// -------------------------------------------------------------------------
box(scene, [96, 0.9, 80], [0, -0.5, 0], materials.ground);
const paverGeometry = new THREE.BoxGeometry(1.78, 0.10, 1.78);
const paverMaterial = material(0xffffff, {
roughness: 0.95
});
paverMaterial.vertexColors = true;
const paverCount = 50 * 40;
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
paverCount
);
pavers.receiveShadow = true;
const dummy = new THREE.Object3D();
const paverColor = new THREE.Color();
let paverIndex = 0;
for (let iz = 0; iz < 40; iz++) {
for (let ix = 0; ix < 50; ix++) {
const x = -44.55 + ix * 1.82;
const z = -36.4 + iz * 1.82;
dummy.position.set(x, 0.05, z);
dummy.rotation.y = (random() - 0.5) * 0.018;
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
const lightness = 0.64 + random() * 0.065;
paverColor.setHSL(0.095, 0.16, lightness);
pavers.setColorAt(paverIndex, paverColor);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
if (pavers.instanceColor) {
pavers.instanceColor.needsUpdate = true;
}
scene.add(pavers);
// Main north-south and east-west public routes.
box(scene, [9.2, 0.09, 75], [0, 0.145, 0], materials.path);
box(scene, [91, 0.09, 6.8], [0, 0.15, 1.8], materials.path);
box(scene, [49, 0.09, 5.0], [-22, 0.15, -4], materials.path);
// Low drainage channels and path edging.
box(scene, [0.22, 0.12, 74], [-4.7, 0.16, 0], materials.pathEdge);
box(scene, [0.22, 0.12, 74], [4.7, 0.16, 0], materials.pathEdge);
box(scene, [90, 0.12, 0.22], [0, 0.16, 5.3], materials.pathEdge);
box(scene, [90, 0.12, 0.22], [0, 0.16, -1.7], materials.pathEdge);
// -------------------------------------------------------------------------
// Low perimeter wall and gateways
// -------------------------------------------------------------------------
box(scene, [91.5, 1.35, 0.75], [0, 0.7, -37.6], materials.stone);
box(scene, [41, 1.35, 0.75], [-25, 0.7, 37.6], materials.stone);
box(scene, [41, 1.35, 0.75], [25, 0.7, 37.6], materials.stone);
box(scene, [0.75, 1.35, 38], [-46, 0.7, -18], materials.stone);
box(scene, [0.75, 1.35, 38], [-46, 0.7, 18], materials.stone);
box(scene, [0.75, 1.35, 38], [46, 0.7, -18], materials.stone);
box(scene, [0.75, 1.35, 38], [46, 0.7, 18], materials.stone);
for (const x of [-5.5, 5.5]) {
box(scene, [1.8, 2.7, 1.8], [x, 1.35, 37.5], materials.stoneLight);
box(scene, [2.25, 0.28, 2.25], [x, 2.82, 37.5], materials.stoneDark);
}
// -------------------------------------------------------------------------
// Temple construction helpers
// -------------------------------------------------------------------------
function decorateTempleBody(group, width, depth, height, baseY, bodyMaterial) {
const trim = bodyMaterial === materials.redBrick
? materials.plaster
: materials.redBrick;
box(group, [width + 0.24, 0.30, depth + 0.24],
[0, baseY + 0.17, 0], trim);
box(group, [width + 0.30, 0.34, depth + 0.30],
[0, baseY + height - 0.18, 0], trim);
for (const x of [-width / 2 + 0.22, width / 2 - 0.22]) {
for (const z of [-depth / 2 + 0.22, depth / 2 - 0.22]) {
box(group, [0.52, height, 0.52], [x, baseY + height / 2, z], trim);
}
}
// Front doorway.
box(group, [1.55, 2.65, 0.16], [0, baseY + 1.33, depth / 2 + 0.08],
materials.dark);
box(group, [1.95, 0.20, 0.24], [0, baseY + 2.75, depth / 2 + 0.11], trim);
// Recessed front and side windows.
for (const x of [-width * 0.27, width * 0.27]) {
box(group, [0.88, 1.38, 0.13], [x, baseY + height * 0.60,
depth / 2 + 0.07], materials.dark);
box(group, [1.12, 0.16, 0.18], [x, baseY + height * 0.60 + 0.77,
depth / 2 + 0.10], trim);
}
for (const x of [-width * 0.32, width * 0.32]) {
box(group, [0.13, 1.28, 0.84], [x, baseY + height * 0.61,
depth * 0.17], materials.dark);
}
// Porch columns.
for (const x of [-width * 0.39, width * 0.39]) {
cylinder(group, 0.20, 0.23, height * 0.72, 8,
[x, baseY + height * 0.36, depth / 2 + 0.43], materials.plaster);
}
}
function addFinial(group, x, y, z) {
cylinder(group, 0.15, 0.22, 1.1, 8, [x, y + 0.55, z], materials.gold);
const orb = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.36, 0),
materials.gold
);
orb.position.set(x, y + 1.18, z);
orb.castShadow = true;
group.add(orb);
cylinder(group, 0.03, 0.13, 0.75, 8, [x, y + 1.78, z], materials.gold);
}
function makeTieredTemple(options, parent = scene) {
const {
x = 0,
z = 0,
width = 10,
depth = 10,
levels = 2,
rotation = 0
} = options;
const group = new THREE.Group();
parent.add(group);
group.position.set(x, 0, z);
group.rotation.y = rotation;
// Three stepped plinth courses.
box(group, [width + 4.2, 0.38, depth + 4.2],
[0, 0.29, 0], materials.stoneDark);
box(group, [width + 3.0, 0.38, depth + 3.0],
[0, 0.67, 0], materials.stone);
box(group, [width + 1.6, 0.34, depth + 1.6],
[0, 1.03, 0], materials.stoneLight);
let currentY = 1.18;
for (let level = 0; level < levels; level++) {
const scale = 1 - level * 0.28;
const bodyWidth = width * scale;
const bodyDepth = depth * scale;
const bodyHeight = level === 0 ? 4.35 : 3.0;
const bodyMaterial = level === 0
? materials.redBrick
: materials.plaster;
box(group, [bodyWidth, bodyHeight, bodyDepth],
[0, currentY + bodyHeight / 2, 0], bodyMaterial);
decorateTempleBody(
group,
bodyWidth,
bodyDepth,
bodyHeight,
currentY,
bodyMaterial
);
const roofBase = currentY + bodyHeight;
const roofHeight = (level === 0 ? 3.15 : 2.65) * (1 - level * 0.06);
hipRoof(
group,
bodyWidth + 3.15,
bodyDepth + 3.15,
roofHeight,
roofBase,
materials.gold
);
if (level < levels - 1) {
currentY = roofBase + 1.18;
} else {
addFinial(group, 0, roofBase + roofHeight - 0.05, 0);
}
}
// Shallow entrance steps.
box(group, [3.4, 0.24, 1.25],
[0, 0.18, depth / 2 + 2.25], materials.stoneLight);
box(group, [2.7, 0.24, 0.85],
[0, 0.37, depth / 2 + 1.76], materials.stone);
return group;
}
function stoneLion(parent, x, z) {
const group = new THREE.Group();
parent.add(group);
group.position.set(x, 0, z);
box(group, [0.95, 0.35, 1.1], [0, 0.2, 0], materials.stoneDark);
box(group, [0.72, 1.1, 0.70], [0, 0.9, 0], materials.stone);
box(group, [0.85, 0.76, 0.72], [0, 1.72, 0.08], materials.stoneLight);
for (const sx of [-0.22, 0.22]) {
box(group, [0.22, 0.65, 0.25], [sx, 0.43, 0.31], materials.stoneLight);
}
box(group, [0.17, 0.15, 0.12], [-0.20, 1.84, 0.47], materials.dark);
box(group, [0.17, 0.15, 0.12], [0.20, 1.84, 0.47], materials.dark);
}
// -------------------------------------------------------------------------
// Referenced forms
// -------------------------------------------------------------------------
// Taleju Temple: compact three-tiered shrine with gilded roofs.
const taleju = makeTieredTemple({
x: 16,
z: -9,
width: 10.5,
depth: 10.5,
levels: 3,
rotation: -0.07
});
stoneLion(taleju, -6.0, -5.9);
stoneLion(taleju, 6.0, -5.9);
// Narayan Temple: red-and-white shrine with smaller corner pavilions.
const narayan = makeTieredTemple({
x: 26,
z: 16,
width: 9.2,
depth: 9.2,
levels: 1,
rotation: 0.10
});
for (const px of [-5.4, 5.4]) {
for (const pz of [-5.4, 5.4]) {
makeTieredTemple({
x: px,
z: pz,
width: 2.7,
depth: 2.7,
levels: 1
}, narayan);
}
}
// Shiva-Parvati Temple: paired white-and-red masses beneath gilded roofs.
const shivaParvati = new THREE.Group();
scene.add(shivaParvati);
shivaParvati.position.set(-12, 0, -22);
shivaParvati.rotation.y = 0.04;
box(shivaParvati, [18.5, 0.42, 13.0], [0, 0.31, 0], materials.stoneDark);
box(shivaParvati, [17.0, 0.40, 11.8], [0, 0.72, 0], materials.stone);
box(shivaParvati, [15.8, 0.34, 10.6], [0, 1.08, 0], materials.stoneLight);
for (const x of [-3.7, 3.7]) {
box(shivaParvati, [6.5, 4.65, 8.0],
[x, 3.55, 0], materials.plaster);
decorateTempleBody(
shivaParvati,
6.5,
8.0,
4.65,
1.22,
materials.plaster
);
hipRoof(shivaParvati, 8.0, 9.4, 2.8, 5.85, materials.gold);
}
box(shivaParvati, [8.2, 2.35, 5.2],
[0, 7.10, 0], materials.plaster);
hipRoof(shivaParvati, 10.4, 7.2, 2.55, 8.25, materials.gold);
addFinial(shivaParvati, 0, 10.75, 0);
// Kumari Ghar: long neoclassical palace facade facing into the square.
const kumari = new THREE.Group();
scene.add(kumari);
kumari.position.set(-31, 0, 2);
kumari.rotation.y = Math.PI / 2;
box(kumari, [28.5, 0.55, 15.0], [0, 0.35, 0], materials.stoneDark);
box(kumari, [27.5, 0.55, 14.0], [0, 0.85, 0], materials.stone);
box(kumari, [26.0, 1.15, 12.2], [0, 1.55, 0], materials.plasterShade);
box(kumari, [26.0, 6.25, 12.0], [0, 5.75, 0], materials.plaster);
// Rusticated horizontal bands.
for (let y = 1.3; y < 2.5; y += 0.38) {
box(kumari, [26.25, 0.12, 12.3], [0, y, 0], materials.plasterShade);
}
box(kumari, [27.0, 0.42, 12.8], [0, 8.55, 0], materials.plasterShade);
hipRoof(kumari, 27.2, 13.0, 1.15, 8.75, materials.redDark);
// Central entrance.
box(kumari, [3.0, 4.5, 0.18], [0, 3.75, 6.08], materials.timber);
box(kumari, [3.7, 0.24, 0.30], [0, 6.08, 6.14], materials.plaster);
// Upper windows and balcony.
for (const x of [-9, -6, -3, 3, 6, 9]) {
box(kumari, [1.45, 2.0, 0.14], [x, 6.55, 6.08], materials.dark);
box(kumari, [1.78, 0.18, 0.25], [x, 7.65, 6.14], materials.plaster);
}
box(kumari, [23.0, 0.18, 0.22], [0, 5.45, 6.70], materials.timber);
for (let x = -11; x <= 11; x += 1.25) {
box(kumari, [0.09, 0.85, 0.09], [x, 5.85, 6.68], materials.timber);
}
// Colonnade.
for (const x of [-11, -8.5, -6, -3.5, 3.5, 6, 8.5, 11]) {
cylinder(kumari, 0.25, 0.30, 6.4, 8,
[x, 4.65, 6.55], materials.plaster);
box(kumari, [0.72, 0.30, 0.72], [x, 1.62, 6.55], materials.plasterShade);
box(kumari, [0.72, 0.28, 0.72], [x, 7.90, 6.55], materials.plaster);
}
triangularPrism(kumari, 8.0, 2.35, 0.65,
[0, 9.45, 6.18], materials.plaster);
triangularPrism(kumari, 6.8, 1.55, 0.16,
[0, 9.33, 6.56], materials.redDark);
// Old Palace range along the northern side.
const oldPalace = new THREE.Group();
scene.add(oldPalace);
oldPalace.position.set(9, 0, -33.1);
box(oldPalace, [32.5, 0.60, 8.4], [0, 0.38, 0], materials.stoneDark);
box(oldPalace, [30.8, 6.35, 6.8], [0, 4.15, 0], materials.redBrick);
box(oldPalace, [31.2, 0.32, 7.2], [0, 7.42, 0], materials.plaster);
hipRoof(oldPalace, 31.5, 7.6, 1.05, 7.55, materials.redDark);
for (let x = -13.5; x <= 13.5; x += 3) {
box(oldPalace, [1.55, 2.0, 0.16], [x, 5.35, 3.48], materials.dark);
box(oldPalace, [1.88, 0.18, 0.28], [x, 6.45, 3.55], materials.plaster);
if (Math.abs(x) > 2) {
box(oldPalace, [1.22, 1.75, 0.14], [x, 2.55, 3.48], materials.dark);
box(oldPalace, [1.48, 0.16, 0.25], [x, 3.50, 3.55], materials.plaster);
}
}
// Pale pilasters divide the palace facade.
for (let x = -14.8; x <= 14.8; x += 3.0) {
box(oldPalace, [0.38, 6.2, 0.28], [x, 4.2, 3.54], materials.plasterShade);
}
// Simple civic clock.
const clock = cylinder(oldPalace, 0.74, 0.74, 0.15, 16,
[0, 4.9, 3.62], materials.plaster);
clock.rotation.x = Math.PI / 2;
const clockFace = cylinder(oldPalace, 0.60, 0.60, 0.17, 16,
[0, 4.9, 3.72], materials.dark);
clockFace.rotation.x = Math.PI / 2;
box(oldPalace, [0.06, 0.48, 0.05], [0, 5.04, 3.83], materials.plaster);
box(oldPalace, [0.34, 0.06, 0.05], [0.15, 4.88, 3.83], materials.plaster);
// -------------------------------------------------------------------------
// Trees, people, and street-scale details
// -------------------------------------------------------------------------
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
scene.add(group);
group.position.set(x, 0.12, z);
group.scale.setScalar(scale);
cylinder(group, 0.18, 0.25, 2.8, 7, [0, 1.4, 0], materials.trunk);
const crown = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.45, 0),
materials.foliage
);
crown.position.y = 3.25;
crown.scale.set(0.9, 1.25, 0.9);
crown.castShadow = true;
group.add(crown);
const upper = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.9, 0),
materials.foliageLight
);
upper.position.set(0.22, 4.12, -0.12);
upper.castShadow = true;
group.add(upper);
}
addTree(-42.2, -30, 1.15);
addTree(-41.5, -25.5, 0.95);
addTree(-41.8, 27.5, 1.05);
addTree(40.8, -29.0, 1.1);
addTree(40.5, 27.5, 0.95);
addTree(34.0, -34.0, 0.8);
function addPerson(x, z, color, scale = 1, rotation = 0) {
const group = new THREE.Group();
scene.add(group);
group.position.set(x, 0.19, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
const cloth = material(color, { roughness: 0.95 });
cylinder(group, 0.10, 0.11, 0.72, 6,
[-0.13, 0.36, 0], materials.dark);
cylinder(group, 0.10, 0.11, 0.72, 6,
[0.13, 0.36, 0], materials.dark);
cylinder(group, 0.22, 0.28, 0.86, 7,
[0, 1.10, 0], cloth);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.22, 1),
material(0xb88763)
);
head.position.y = 1.72;
head.castShadow = true;
group.add(head);
}
addPerson(-1.8, 27.5, 0x9d493b, 1.0, 0.25);
addPerson(2.4, 18.0, 0x425b68, 0.92, -0.45);
addPerson(-2.6, 11.2, 0xc2a251, 1.04, 0.8);
addPerson(1.4, 6.4, 0x705468, 0.86, 2.3);
addPerson(-13.5, 2.0, 0x5f7856, 0.95, -0.8);
addPerson(8.0, 1.6, 0xa7583e, 1.05, 1.1);
addPerson(19.0, 8.5, 0x394f67, 0.90, 2.0);
addPerson(29.5, 9.0, 0xb69747, 0.96, -0.2);
addPerson(-5.0, -8.0, 0x82493a, 0.98, 1.7);
addPerson(4.3, -15.0, 0x54664b, 0.88, 0.1);
// Small stone posts and trough-like civic fixtures.
for (const [x, z] of [[-7, 18], [7, 18], [-7, 12], [7, 12]]) {
box(scene, [0.75, 0.85, 0.75], [x, 0.52, z], materials.stone);
box(scene, [0.95, 0.18, 0.95], [x, 1.03, z], materials.stoneLight);
}
// -------------------------------------------------------------------------
// In-scene labels drawn with the core CanvasTexture API
// -------------------------------------------------------------------------
const labelsGroup = new THREE.Group();
scene.add(labelsGroup);
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
function makeLabel(title, subtitle, x, y, z, scale = 13) {
const canvas = document.createElement("canvas");
canvas.width = 720;
canvas.height = 170;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 5, 5, 710, 160, 22);
ctx.fillStyle = "rgba(27, 30, 27, 0.86)";
ctx.fill();
ctx.strokeStyle = "rgba(226, 188, 91, 0.72)";
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#f5edda";
ctx.font = "600 37px system-ui, sans-serif";
ctx.fillText(title, 360, 69);
ctx.fillStyle = "#dfb84e";
ctx.font = "500 24px system-ui, sans-serif";
ctx.fillText(subtitle, 360, 116);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, y, z);
sprite.scale.set(scale, scale * 170 / 720, 1);
sprite.renderOrder = 20;
labelsGroup.add(sprite);
}
makeLabel("Taleju Temple", "multi-tiered shrine", 16, 20.2, -9, 13.5);
makeLabel("Narayan Temple", "red-and-white sanctuary", 26, 12.5, 16, 13.5);
makeLabel("Shiva–Parvati Temple", "paired gilded-roof shrine", -12, 14.1, -22, 14.5);
makeLabel("Kumari Ghar", "royal palace facade", -31, 13.1, 2, 13.5);
makeLabel("Old Palace", "Hanuman Dhoka range", 9, 10.5, -33, 12.5);
// -------------------------------------------------------------------------
// Custom orbit, pan, and zoom controls — no Three.js addons
// -------------------------------------------------------------------------
const orbit = {
target: new THREE.Vector3(0, 3.2, -2),
radius: 95,
theta: 0.62,
phi: 0.86
};
const home = {
target: orbit.target.clone(),
radius: orbit.radius,
theta: orbit.theta,
phi: orbit.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
let dragging = false;
let panning = false;
let lastX = 0;
let lastY = 0;
let activePointer = null;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
activePointer = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== activePointer) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (panning) {
const scale = orbit.radius * 0.00145;
const cosTheta = Math.cos(orbit.theta);
const sinTheta = Math.sin(orbit.theta);
orbit.target.x -= dx * scale * cosTheta;
orbit.target.z += dx * scale * sinTheta;
orbit.target.y += dy * scale * 0.25;
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -38, 38);
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, 0.5, 14);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -35, 35);
} else {
orbit.theta -= dx * 0.0055;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0048,
0.30,
1.43
);
}
updateCamera();
});
function stopDragging(event) {
if (event && activePointer !== null && event.pointerId !== activePointer) {
return;
}
dragging = false;
panning = false;
activePointer = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
27,
145
);
updateCamera();
}, { passive: false });
document.querySelector("#reset").addEventListener("click", () => {
orbit.target.copy(home.target);
orbit.radius = home.radius;
orbit.theta = home.theta;
orbit.phi = home.phi;
updateCamera();
});
document.querySelector("#zoom-in").addEventListener("click", () => {
orbit.radius = Math.max(27, orbit.radius * 0.86);
updateCamera();
});
document.querySelector("#zoom-out").addEventListener("click", () => {
orbit.radius = Math.min(145, orbit.radius * 1.16);
updateCamera();
});
document.querySelector("#labels").addEventListener("change", event => {
labelsGroup.visible = event.target.checked;
});
window.addEventListener("keydown", event => {
const step = 0.08;
if (event.key === "ArrowLeft") {
orbit.theta += step;
} else if (event.key === "ArrowRight") {
orbit.theta -= step;
} else if (event.key === "ArrowUp") {
orbit.phi = Math.max(0.30, orbit.phi - step * 0.65);
} else if (event.key === "ArrowDown") {
orbit.phi = Math.min(1.43, orbit.phi + step * 0.65);
} else if (event.key === "+" || event.key === "=") {
orbit.radius = Math.max(27, orbit.radius * 0.9);
} else if (event.key === "-" || event.key === "_") {
orbit.radius = Math.min(145, orbit.radius * 1.1);
} else {
return;
}
event.preventDefault();
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => {
document.querySelector("#loading").remove();
}, 450);
});
</script>
</body>
</html>
```