Prompt specification
Build or customize the Three.js 3D scene "Hawa Mahal screened-window bay 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: Hawa Mahal screened-window bay study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hawa-mahal-screened-window-bay-study-x2989
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a screened-window bay of Hawa Mahal in Jaipur. Build one simplified referenced screened-window bay with layered facade depth. Show the opening's relation to an interior viewing position without reproducing every decorative element. Voxel style.
Working Three.js Starter (hawa-mahal-screened-window-bay-study-x2989):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hawa Mahal — Screened-Window Bay</title>
<style>
:root {
--ink: #3f2926;
--paper: #f5e8d4;
--sand: #d59a78;
--rose: #bf655d;
--gold: #f0c487;
--glass: rgba(255, 248, 236, 0.82);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7c3aa;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
canvas {
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(74, 43, 35, 0.18);
background: var(--glass);
box-shadow: 0 12px 35px rgba(63, 38, 30, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.title-panel {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 18px 20px 16px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #985044;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(24px, 4vw, 35px);
font-weight: 500;
line-height: 1.03;
}
.subtitle {
margin: 9px 0 0;
color: rgba(63, 41, 38, 0.76);
font-size: 12px;
line-height: 1.5;
}
.view-panel {
right: 20px;
top: 20px;
width: min(330px, calc(100vw - 40px));
padding: 10px;
border-radius: 14px;
}
.view-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
}
button {
appearance: none;
border: 0;
border-radius: 9px;
padding: 10px 8px;
background: rgba(105, 55, 47, 0.08);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(105, 55, 47, 0.15);
transform: translateY(-1px);
}
button.active {
background: var(--rose);
color: #fff7eb;
}
.caption {
min-height: 66px;
margin: 11px 5px 3px;
color: rgba(63, 41, 38, 0.78);
font-size: 11px;
line-height: 1.55;
}
.caption strong {
color: var(--ink);
}
.legend {
left: 20px;
bottom: 20px;
padding: 12px 15px;
border-radius: 12px;
color: rgba(63, 41, 38, 0.78);
font-size: 10px;
line-height: 1.7;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 18px;
height: 7px;
border-radius: 2px;
background: #c76d62;
}
.swatch.screen {
background: #edb38a;
}
.swatch.interior {
background: #755448;
}
.hint {
right: 20px;
bottom: 20px;
padding: 10px 13px;
border-radius: 10px;
color: rgba(63, 41, 38, 0.68);
font-size: 10px;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
top: 0;
left: 0;
padding: 6px 9px;
border: 1px solid rgba(63, 41, 38, 0.16);
border-radius: 999px;
background: rgba(255, 247, 232, 0.88);
box-shadow: 0 5px 16px rgba(63, 41, 38, 0.1);
color: #5a3932;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.world-label::before {
content: "";
display: inline-block;
width: 5px;
height: 5px;
margin-right: 6px;
border-radius: 50%;
background: #c9675d;
vertical-align: 1px;
}
.world-label.gold::before {
background: #c68d43;
}
.world-label.dark::before {
background: #6b5147;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
display: none;
}
.view-panel {
top: 108px;
right: 12px;
width: calc(100vw - 24px);
}
.caption {
min-height: 0;
}
.legend,
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<canvas id="scene" aria-label="Interactive voxel model of a Hawa Mahal screened-window bay"></canvas>
<header class="panel title-panel">
<div class="eyebrow">Jaipur · Architectural Voxel Study</div>
<h1>Hawa Mahal<br>Screened-Window Bay</h1>
<p class="subtitle">
A simplified jharokha with projecting latticework, recessed opening,
and an interior viewing position.
</p>
</header>
<section class="panel view-panel" aria-label="Scene viewpoints">
<nav class="view-buttons">
<button data-view="exterior" class="active">Exterior</button>
<button data-view="section">Section</button>
<button data-view="interior">Interior</button>
</nav>
<div id="caption" class="caption">
<strong>Exterior view.</strong> The projecting screen sits ahead of
the recessed wall opening, creating a layered facade.
</div>
</section>
<aside class="panel legend" aria-label="Model legend">
<div class="legend-row"><span class="swatch"></span> Pink sandstone facade</div>
<div class="legend-row"><span class="swatch screen"></span> Projecting jali screen</div>
<div class="legend-row"><span class="swatch interior"></span> Interior viewing space</div>
</aside>
<div class="panel hint">Drag to orbit · Scroll or pinch to zoom · Arrow keys to rotate</div>
<div id="opening-label" class="world-label">Projecting screened opening</div>
<div id="depth-label" class="world-label">Layered facade depth</div>
<div id="viewpoint-label" class="world-label gold">Interior viewing position</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7c3aa);
scene.fog = new THREE.Fog(0xd7c3aa, 25, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
100
);
const hemisphere = new THREE.HemisphereLight(0xfff4dc, 0x76584d, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b9, 3.1);
sun.position.set(9, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0003;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const interiorLight = new THREE.PointLight(0xffc880, 20, 9, 2);
interiorLight.position.set(0, 5.3, -2.7);
scene.add(interiorLight);
const fillLight = new THREE.DirectionalLight(0xaec7d1, 0.9);
fillLight.position.set(-10, 7, -8);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Materials and reusable geometry
// -------------------------------------------------------------------------
const materials = {
wall: new THREE.MeshStandardMaterial({
color: 0xc76d62,
roughness: 0.86,
metalness: 0
}),
wallLight: new THREE.MeshStandardMaterial({
color: 0xd78370,
roughness: 0.84
}),
wallDark: new THREE.MeshStandardMaterial({
color: 0xa95650,
roughness: 0.9
}),
trim: new THREE.MeshStandardMaterial({
color: 0xe3a07c,
roughness: 0.74
}),
trimLight: new THREE.MeshStandardMaterial({
color: 0xf0b58c,
roughness: 0.72
}),
recess: new THREE.MeshStandardMaterial({
color: 0x7d433e,
roughness: 0.95
}),
screen: new THREE.MeshStandardMaterial({
color: 0xf0bb91,
roughness: 0.76
}),
screenRear: new THREE.MeshStandardMaterial({
color: 0x9b554b,
roughness: 0.92
}),
interior: new THREE.MeshStandardMaterial({
color: 0x76574d,
roughness: 0.95
}),
interiorLight: new THREE.MeshStandardMaterial({
color: 0xa98268,
roughness: 0.92
}),
floor: new THREE.MeshStandardMaterial({
color: 0xa77a63,
roughness: 0.94
}),
path: new THREE.MeshStandardMaterial({
color: 0x7e4d47,
roughness: 0.9
}),
figure: new THREE.MeshStandardMaterial({
color: 0x39454b,
roughness: 0.9
}),
gold: new THREE.MeshStandardMaterial({
color: 0xe4b86e,
emissive: 0x8c5520,
emissiveIntensity: 0.12,
roughness: 0.62
}),
seam: new THREE.MeshStandardMaterial({
color: 0xb55f55,
roughness: 0.9
}),
ground: new THREE.MeshStandardMaterial({
color: 0xc9ad8c,
roughness: 1
})
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
parent.add(mesh);
return mesh;
}
const facade = new THREE.Group();
const interior = new THREE.Group();
scene.add(facade, interior);
// -------------------------------------------------------------------------
// Main facade wall with a real recessed opening
// -------------------------------------------------------------------------
const openingHalfWidth = 2.25;
const openingBottom = 2.1;
const archSpring = 5.75;
const archRadius = 2.25;
const openingTop = archSpring + archRadius;
const facadeHalfWidth = 4.8;
const facadeTop = 11.2;
// Side wall masses.
const sideWidth = facadeHalfWidth - openingHalfWidth;
const sideCenter = (facadeHalfWidth + openingHalfWidth) / 2;
box(facade, [sideWidth, facadeTop, 0.78], [-sideCenter, facadeTop / 2, 0], materials.wall);
box(facade, [sideWidth, facadeTop, 0.78], [sideCenter, facadeTop / 2, 0], materials.wall);
// Wall below and above the opening.
box(
facade,
[openingHalfWidth * 2, openingBottom, 0.78],
[0, openingBottom / 2, 0],
materials.wall
);
box(
facade,
[openingHalfWidth * 2, facadeTop - openingTop, 0.78],
[0, (facadeTop + openingTop) / 2, 0],
materials.wall
);
// Stepped, voxel-like masonry around the curved head of the opening.
const archRows = 9;
const archRowHeight = (openingTop - archSpring) / archRows;
for (let i = 0; i < archRows; i++) {
const y = archSpring + (i + 0.5) * archRowHeight;
const dy = y - archSpring;
const halfOpening = Math.sqrt(
Math.max(0, archRadius * archRadius - dy * dy)
);
const fillWidth = openingHalfWidth - halfOpening;
if (fillWidth > 0.01) {
box(
facade,
[fillWidth, archRowHeight + 0.012, 0.79],
[-(halfOpening + fillWidth / 2), y, 0],
materials.wallLight
);
box(
facade,
[fillWidth, archRowHeight + 0.012, 0.79],
[halfOpening + fillWidth / 2, y, 0],
materials.wallLight
);
}
}
// Subtle horizontal masonry courses on the solid facade areas.
for (let y = 0.55; y < facadeTop; y += 0.78) {
box(facade, [sideWidth - 0.12, 0.026, 0.025], [-sideCenter, y, 0.402], materials.seam);
box(facade, [sideWidth - 0.12, 0.026, 0.025], [sideCenter, y, 0.402], materials.seam);
if (y > openingTop + 0.25 && y < facadeTop - 0.2) {
box(facade, [4.42, 0.026, 0.025], [0, y, 0.402], materials.seam);
}
}
// Vertical course joints.
for (let x = -4.25; x <= 4.3; x += 0.84) {
if (Math.abs(x) > openingHalfWidth + 0.1) {
box(facade, [0.025, facadeTop - 0.2, 0.026], [x, facadeTop / 2, 0.403], materials.seam);
}
}
// -------------------------------------------------------------------------
// Projecting bay: piers, sill, inner and outer frames
// -------------------------------------------------------------------------
box(
facade,
[0.42, 6.1, 1.75],
[-2.58, 5.08, 0.55],
materials.wallDark
);
box(
facade,
[0.42, 6.1, 1.75],
[2.58, 5.08, 0.55],
materials.wallDark
);
// Projecting sill and lower lintel.
box(facade, [5.62, 0.34, 2.25], [0, 1.94, 0.55], materials.trim);
box(facade, [5.28, 0.18, 1.95], [0, 2.18, 0.48], materials.trimLight);
// Inner recessed frame.
box(
facade,
[0.22, archSpring - openingBottom, 0.23],
[-openingHalfWidth - 0.09, (openingBottom + archSpring) / 2, 0.48],
materials.recess
);
box(
facade,
[0.22, archSpring - openingBottom, 0.23],
[openingHalfWidth + 0.09, (openingBottom + archSpring) / 2, 0.48],
materials.recess
);
// Outer projecting frame.
box(
facade,
[0.36, archSpring - openingBottom, 0.34],
[-openingHalfWidth - 0.19, (openingBottom + archSpring) / 2, 1.23],
materials.trim
);
box(
facade,
[0.36, archSpring - openingBottom, 0.34],
[openingHalfWidth + 0.19, (openingBottom + archSpring) / 2, 1.23],
materials.trim
);
function halfWidthAt(y) {
if (y <= archSpring) return openingHalfWidth;
const dy = y - archSpring;
return Math.sqrt(Math.max(0, archRadius * archRadius - dy * dy));
}
for (let i = 0; i < archRows; i++) {
const y = archSpring + (i + 0.5) * archRowHeight;
const half = halfWidthAt(y);
box(
facade,
[0.36, archRowHeight + 0.015, 0.34],
[-half - 0.19, y, 1.23],
materials.trim
);
box(
facade,
[0.36, archRowHeight + 0.015, 0.34],
[half + 0.19, y, 1.23],
materials.trim
);
}
box(facade, [4.9, 0.27, 0.38], [0, openingTop + 0.13, 1.23], materials.trimLight);
// -------------------------------------------------------------------------
// Stepped jali lattice
// -------------------------------------------------------------------------
function isInsideOpening(x, y) {
if (y < openingBottom + 0.12 || y > openingTop - 0.06) return false;
return Math.abs(x) < halfWidthAt(y) - 0.08;
}
function addJali(parent, z, spacing, cubeSize, color, depth = 0.13) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.82
});
const positions = [];
const step = cubeSize * 1.12;
const lineOffset = spacing;
for (let c = -12; c <= 12; c++) {
const offset = c * lineOffset;
for (let x = -2.18; x <= 2.18; x += step) {
const yA = offset + x;
const yB = offset - x;
if (isInsideOpening(x, yA)) {
positions.push([x, yA, z]);
}
if (isInsideOpening(x, yB)) {
positions.push([x, yB, z]);
}
}
}
const mesh = new THREE.InstancedMesh(unitBox, material, positions.length);
const matrix = new THREE.Matrix4();
const quaternion = new THREE.Quaternion();
const scale = new THREE.Vector3(cubeSize, cubeSize, depth);
positions.forEach((position, index) => {
matrix.compose(
new THREE.Vector3(position[0], position[1], position[2]),
quaternion,
scale
);
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Rear lattice is darker and more widely spaced, making the screen depth legible.
addJali(facade, 0.36, 0.52, 0.052, 0x8d4d47, 0.08);
addJali(facade, 1.19, 0.39, 0.094, 0xf0b98e, 0.15);
// Small voxel medallion at the center of the jali.
const medallion = new THREE.Group();
facade.add(medallion);
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
box(
medallion,
[0.13, 0.13, 0.19],
[Math.cos(a) * 0.52, 4.85 + Math.sin(a) * 0.52, 1.31],
materials.trimLight
);
}
box(medallion, [0.32, 0.32, 0.19], [0, 4.85, 1.31], materials.trim);
box(medallion, [0.12, 0.12, 0.21], [0, 4.85, 1.32], materials.wallDark);
// -------------------------------------------------------------------------
// Stepped canopy/cornice above the jharokha
// -------------------------------------------------------------------------
box(facade, [10.15, 0.38, 1.18], [0, 11.22, 0.03], materials.trim);
box(facade, [9.65, 0.18, 0.9], [0, 11.49, 0], materials.trimLight);
// Simple parapet blocks.
for (let x = -4.5; x <= 4.5; x += 0.75) {
box(facade, [0.43, 0.38, 0.58], [x, 11.78, -0.02], materials.wallLight);
}
// Broad projecting eave.
box(facade, [6.15, 0.32, 2.45], [0, 8.27, 0.54], materials.trim);
box(facade, [5.86, 0.18, 2.12], [0, 8.5, 0.5], materials.trimLight);
// Voxel stepped roof.
const roofSteps = [
[5.65, 0.28, 1.98, 8.70],
[5.18, 0.26, 1.75, 8.97],
[4.70, 0.25, 1.52, 9.23],
[4.08, 0.24, 1.30, 9.48],
[3.38, 0.23, 1.08, 9.72],
[2.62, 0.22, 0.86, 9.95],
[1.82, 0.20, 0.64, 10.16]
];
roofSteps.forEach((step, index) => {
box(
facade,
[step[0], step[1], step[2]],
[0, step[3], 0.42],
index % 2 ? materials.wallLight : materials.trim
);
});
box(facade, [0.26, 0.58, 0.26], [0, 10.51, 0.42], materials.trim);
box(facade, [0.48, 0.20, 0.48], [0, 10.84, 0.42], materials.trimLight);
// Simplified relief motifs on the solid wall areas.
function wallMotif(x, y, z, scale = 1) {
const group = new THREE.Group();
facade.add(group);
box(group, [0.24 * scale, 0.24 * scale, 0.12], [0, 0, 0], materials.trim);
box(group, [0.12 * scale, 0.38 * scale, 0.11], [0, 0, 0.01], materials.trim);
box(group, [0.38 * scale, 0.12 * scale, 0.11], [0, 0, 0.01], materials.trim);
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
box(
group,
[0.11 * scale, 0.11 * scale, 0.1],
[sx * 0.18 * scale, sy * 0.18 * scale, 0],
materials.trimLight
);
}
}
group.position.set(x, y, z);
}
wallMotif(-3.55, 6.72, 0.47, 1.05);
wallMotif(3.55, 6.72, 0.47, 1.05);
wallMotif(-3.55, 9.45, 0.47, 0.75);
wallMotif(3.55, 9.45, 0.47, 0.75);
// -------------------------------------------------------------------------
// Interior room and viewing position
// -------------------------------------------------------------------------
// Interior floor.
box(interior, [9.45, 0.18, 5.45], [0, -0.09, -2.55], materials.floor);
// Back and far-side room walls.
box(interior, [9.55, 9.25, 0.3], [0, 4.52, -5.18], materials.interior);
box(interior, [0.3, 9.25, 5.35], [-4.62, 4.52, -2.5], materials.interior);
// A few shallow interior courses, intentionally sparse.
for (let y = 1; y < 8.8; y += 1.05) {
box(interior, [8.85, 0.025, 0.025], [0, y, -5.01], materials.interiorLight);
}
// Near-side wall is hidden for the section and interior views.
const nearWall = new THREE.Group();
interior.add(nearWall);
box(nearWall, [0.3, 9.25, 5.35], [4.62, 4.52, -2.5], materials.interior);
// Threshold and interior passage.
box(interior, [4.55, 0.12, 0.5], [0, 0.04, -0.14], materials.interiorLight);
for (let z = -4.7; z < -0.2; z += 0.47) {
box(interior, [1.78, 0.06, 0.39], [0.12, 0.025, z], materials.path);
box(interior, [1.52, 0.025, 0.31], [0.12, 0.062, z], materials.interiorLight);
}
// Low viewing bench.
box(interior, [1.25, 0.28, 0.62], [0.62, 0.18, -2.95], materials.interiorLight);
box(interior, [1.1, 0.12, 0.53], [0.62, 0.38, -2.95], materials.path);
// Stylized human figure, facing the screened opening.
const person = new THREE.Group();
interior.add(person);
box(person, [0.34, 0.34, 0.32], [0, 1.58, 0], materials.figure);
box(person, [0.48, 0.62, 0.28], [0, 1.11, 0], materials.figure);
box(person, [0.16, 0.58, 0.18], [-0.13, 0.55, 0], materials.figure);
box(person, [0.16, 0.58, 0.18], [0.13, 0.55, 0], materials.figure);
box(person, [0.13, 0.58, 0.16], [-0.31, 1.04, 0], materials.figure);
box(person, [0.13, 0.58, 0.16], [0.31, 1.04, 0], materials.figure);
person.position.set(0.62, 0, -2.55);
person.rotation.y = Math.PI;
// Gold floor markers identify the exact interior viewing position.
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2;
box(
interior,
[0.10, 0.035, 0.10],
[
person.position.x + Math.cos(a) * 0.5,
0.075,
person.position.z + Math.sin(a) * 0.5
],
materials.gold
);
}
// Two subtle sightlines run from the figure toward the opening edges.
function floorRay(x1, z1, x2, z2) {
const dx = x2 - x1;
const dz = z2 - z1;
const length = Math.hypot(dx, dz);
const ray = box(
interior,
[length, 0.018, 0.026],
[(x1 + x2) / 2, 0.075, (z1 + z2) / 2],
materials.gold,
{ castShadow: false }
);
ray.rotation.y = Math.atan2(-dz, dx);
}
floorRay(0.62, -2.45, -1.72, 0.95);
floorRay(0.62, -2.45, 1.72, 0.95);
// -------------------------------------------------------------------------
// Ground, plinth, and contextual base
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.22;
ground.receiveShadow = true;
scene.add(ground);
box(scene, [10.55, 0.28, 2.0], [0, -0.03, 0.15], materials.wallDark);
box(scene, [10.2, 0.16, 1.76], [0, 0.17, 0.12], materials.trim);
// A few low voxel blocks suggest the larger palace without recreating it.
box(scene, [4.4, 1.15, 1.1], [-7.2, 0.45, -0.15], materials.wall);
box(scene, [4.65, 0.2, 1.3], [-7.2, 1.1, -0.12], materials.trim);
box(scene, [3.2, 0.85, 1.0], [7.0, 0.3, -0.4], materials.wallLight);
// -------------------------------------------------------------------------
// Camera presets and direct camera controls
// -------------------------------------------------------------------------
const presets = {
exterior: {
target: new THREE.Vector3(0, 4.85, 0.05),
radius: 15.8,
theta: 0.60,
phi: 1.24
},
section: {
target: new THREE.Vector3(0.15, 4.35, -0.55),
radius: 14.4,
theta: 1.30,
phi: 1.27
},
interior: {
target: new THREE.Vector3(0, 4.45, -1.35),
radius: 3.45,
theta: Math.PI,
phi: 1.34
}
};
const current = {
target: presets.exterior.target.clone(),
radius: presets.exterior.radius,
theta: presets.exterior.theta,
phi: presets.exterior.phi
};
const goal = {
target: presets.exterior.target.clone(),
radius: presets.exterior.radius,
theta: presets.exterior.theta,
phi: presets.exterior.phi
};
let activeView = "exterior";
const buttons = [...document.querySelectorAll("[data-view]")];
const caption = document.querySelector("#caption");
const captions = {
exterior:
"<strong>Exterior view.</strong> The pale projecting jali sits ahead of the recessed wall opening, creating a layered facade.",
section:
"<strong>Cutaway section.</strong> The near wall is removed to reveal the screen, deep reveal, passage, and interior viewing position.",
interior:
"<strong>Interior view.</strong> The screened opening filters light and views from the marked position inside the chamber."
};
function setView(name) {
const preset = presets[name];
if (!preset) return;
activeView = name;
goal.target.copy(preset.target);
goal.radius = preset.radius;
goal.theta = preset.theta;
goal.phi = preset.phi;
buttons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
caption.innerHTML = captions[name];
nearWall.visible = name === "exterior";
}
buttons.forEach((button) => {
button.addEventListener("click", () => setView(button.dataset.view));
});
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
goal.theta -= dx * 0.006;
goal.phi = THREE.MathUtils.clamp(goal.phi - dy * 0.005, 0.48, 1.49);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
pointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goal.radius = THREE.MathUtils.clamp(
goal.radius * Math.exp(event.deltaY * 0.001),
2.7,
26
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const key = event.key;
if (key === "ArrowLeft") goal.theta += 0.12;
if (key === "ArrowRight") goal.theta -= 0.12;
if (key === "ArrowUp") goal.phi = Math.max(0.48, goal.phi - 0.08);
if (key === "ArrowDown") goal.phi = Math.min(1.49, goal.phi + 0.08);
if (key === "+" || key === "=") goal.radius = Math.max(2.7, goal.radius - 0.7);
if (key === "-") goal.radius = Math.min(26, goal.radius + 0.7);
if (key.startsWith("Arrow") || key === "+" || key === "=" || key === "-") {
event.preventDefault();
}
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#opening-label"),
position: new THREE.Vector3(0, 7.45, 1.28),
modes: ["exterior", "section", "interior"]
},
{
element: document.querySelector("#depth-label"),
position: new THREE.Vector3(2.85, 5.35, 0.72),
modes: ["section"]
},
{
element: document.querySelector("#viewpoint-label"),
position: new THREE.Vector3(0.62, 2.25, -2.55),
modes: ["section", "interior"]
}
];
function updateLabels() {
labels.forEach((label) => {
const projected = label.position.clone().project(camera);
const visible =
label.modes.includes(activeView) &&
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.08 &&
Math.abs(projected.y) < 1.08;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
});
}
// -------------------------------------------------------------------------
// 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);
});
function animate() {
requestAnimationFrame(animate);
const easing = 1 - Math.pow(0.001, 1 / 60);
current.target.lerp(goal.target, easing);
current.radius = THREE.MathUtils.lerp(current.radius, goal.radius, easing);
current.phi = THREE.MathUtils.lerp(current.phi, goal.phi, easing);
let thetaDifference = goal.theta - current.theta;
thetaDifference = Math.atan2(Math.sin(thetaDifference), Math.cos(thetaDifference));
current.theta += thetaDifference * easing;
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);
}
animate();
</script>
</body>
</html>
```