Prompt specification
Build or customize the Three.js 3D scene "Plaza Mayor corner and central open space" 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: Plaza Mayor corner and central open space
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/plaza-mayor-corner-and-central-open-space-x2847
Scene Description Prompt:
Plaza Mayor corner and central open space. Build a bounded voxel corner of the referenced square with arcades, regular window rhythm, and one entrance passage. Avoid modeling every facade when a smaller fragment explains the layout. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (plaza-mayor-corner-and-central-open-space-x2847):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Plaza Mayor — Voxel Corner</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d9e2df;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 22px;
z-index: 10;
width: min(340px, calc(100vw - 44px));
padding: 16px 18px;
color: #f8edda;
background: rgba(64, 39, 34, 0.88);
border: 1px solid rgba(255, 236, 201, 0.24);
border-radius: 4px;
box-shadow: 0 12px 35px rgba(41, 35, 31, 0.18);
backdrop-filter: blur(10px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #d9aa7d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 4vw, 35px);
font-weight: 500;
line-height: 1;
}
.subtitle {
margin: 9px 0 0;
color: rgba(248, 237, 218, 0.72);
font-size: 12px;
line-height: 1.45;
}
.controls {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 14px;
padding: 10px 12px;
color: #4a3931;
background: rgba(248, 241, 225, 0.9);
border: 1px solid rgba(76, 55, 45, 0.16);
border-radius: 4px;
box-shadow: 0 8px 28px rgba(49, 41, 35, 0.13);
backdrop-filter: blur(8px);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.025em;
}
.controls span {
white-space: nowrap;
}
.separator {
width: 1px;
height: 15px;
background: rgba(74, 57, 49, 0.2);
}
button {
appearance: none;
padding: 7px 10px;
color: #f8edda;
background: #77483c;
border: 0;
border-radius: 3px;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
}
button:hover {
background: #63382f;
}
button:focus-visible {
outline: 2px solid #d9aa7d;
outline-offset: 2px;
}
@media (max-width: 650px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
}
.desktop-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="title-card">
<div class="eyebrow">Architectural voxel study</div>
<h1>Plaza Mayor</h1>
<p class="subtitle">
A bounded corner fragment: brick arcades, repeated upper windows,
one through-entrance, and an open civic space.
</p>
</div>
<div class="controls">
<span>Drag to orbit</span>
<span class="separator"></span>
<span class="desktop-hint">Scroll to zoom</span>
<span class="separator desktop-hint"></span>
<button id="reset" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Scene and renderer
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9e2df);
scene.fog = new THREE.Fog(0xd9e2df, 45, 95);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.querySelector("#scene").appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel model of a Plaza Mayor corner"
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xe9f2ee,
0x75614f,
1.7
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe7c5, 3.2);
sun.position.set(-13, 24, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -25;
sun.shadow.camera.right = 25;
sun.shadow.camera.top = 25;
sun.shadow.camera.bottom = -25;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d5de, 0.65);
fill.position.set(16, 10, -18);
scene.add(fill);
// ------------------------------------------------------------
// Palette
// ------------------------------------------------------------
const COLOR = {
brick: 0xa84f3e,
brickLight: 0xb85b45,
brickDark: 0x8d3d32,
brickMuted: 0x78362f,
stone: 0xe6d4b6,
trim: 0xf2e3c6,
shadow: 0x542d29,
roof: 0x873b32,
roofLight: 0xa14a38,
glass: 0x294653,
glassLight: 0x3e6170,
paving: 0xc6b99f,
pavingLight: 0xd1c6ae,
pavingDark: 0xb2a58d,
base: 0x73766e,
water: 0x58a9b0,
bronze: 0x49645d,
lamp: 0xffbb62
};
// Instanced batches keep the thousands of visible voxels efficient.
const batches = {
solid: [],
glass: [],
glow: [],
water: []
};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function addBox(batch, x, y, z, sx, sy, sz, color) {
batches[batch].push({
x, y, z,
sx, sy, sz,
color
});
}
function brickVariation(ix, iy, side = 0) {
const value = Math.abs(ix * 13 + iy * 7 + side * 11) % 5;
if (value === 0) return COLOR.brickLight;
if (value === 1) return COLOR.brickDark;
return COLOR.brick;
}
// ------------------------------------------------------------
// Bounded voxel platform and paving
// ------------------------------------------------------------
addBox(
"solid",
-1.375, -0.36, 2.25,
22.75, 0.72, 22.5,
COLOR.base
);
for (let ix = 0, x = -12.5; x <= 9.5; ix++, x += 1) {
for (let iz = 0, z = -8.5; z <= 13; iz++, z += 1) {
const pattern = (ix + iz * 2) % 5;
let color = COLOR.paving;
if (pattern === 0) color = COLOR.pavingLight;
if (pattern === 3) color = COLOR.pavingDark;
// A subtly lighter processional axis through the plaza.
if (Math.abs(x + 2.5) < 1.2) {
color = COLOR.pavingLight;
}
addBox(
"solid",
x, 0.075, z,
0.92, 0.13, 0.92,
color
);
}
}
// Low edge blocks make the model read as a finite architectural maquette.
for (let x = -12.5; x <= 9.5; x += 1) {
addBox(
"solid",
x, 0.18, 13.25,
0.88, 0.3, 0.42,
COLOR.stone
);
}
for (let z = -8.5; z <= 13; z += 1) {
// Leave a gap aligned with the single entrance passage.
if (z > 2.8 && z < 6.2) continue;
addBox(
"solid",
9.75, 0.18, z,
0.42, 0.3, 0.88,
COLOR.stone
);
}
// ------------------------------------------------------------
// Back wing: foundations and recessed ground-floor arcade
// ------------------------------------------------------------
const backCenters = [-9.5, -5.5, -1.5, 2.5, 6.5];
const backPiers = [-11.5, -7.5, -3.5, 0.5, 4.5, 8.5];
addBox(
"solid",
-1.75, 0.22, -6.25,
20.5, 0.42, 2.65,
COLOR.stone
);
// Rear wall behind the arcade creates deep, shaded niches.
for (let ix = 0, x = -11.75; x < 8.5; ix++, x += 0.5) {
for (let iy = 0, y = 0.3; y < 2.45; iy++, y += 0.5) {
addBox(
"solid",
x, y, -7.08,
0.47, 0.46, 0.55,
iy % 4 === 0 ? COLOR.brickMuted : COLOR.brickDark
);
}
}
// Voxel piers.
for (let p = 0; p < backPiers.length; p++) {
for (let iy = 0, y = 0.3; y < 2.3; iy++, y += 0.5) {
addBox(
"solid",
backPiers[p], y, -6.18,
0.92, 0.46, 1.72,
brickVariation(p, iy, 1)
);
}
}
function addArchX(center, z, spring, radius, depth = 0.56) {
for (let dy = 0; dy <= radius + 0.45; dy += 0.48) {
const y = spring + dy;
for (
let dx = -radius - 0.45;
dx <= radius + 0.45;
dx += 0.48
) {
const radiusSquared = dx * dx + dy * dy;
if (
radiusSquared >= (radius - 0.16) ** 2 &&
radiusSquared <= (radius + 0.40) ** 2
) {
addBox(
"solid",
center + dx, y, z,
0.46, 0.46, depth,
COLOR.trim
);
}
}
}
}
backCenters.forEach((center) => {
addArchX(center, -5.18, 2.12, 1.48);
});
// ------------------------------------------------------------
// Back wing upper facade with regular window rhythm
// ------------------------------------------------------------
for (let ix = 0, x = -11.75; x < 8.5; ix++, x += 0.5) {
for (let iy = 0, y = 3.85; y < 9.55; iy++, y += 0.5) {
let isWindow = false;
for (const center of backCenters) {
const nearWindowColumn = Math.abs(x - center) < 0.52;
const firstFloorWindow = y >= 4.0 && y <= 5.75;
const secondFloorWindow = y >= 6.45 && y <= 8.15;
if (
nearWindowColumn &&
(firstFloorWindow || secondFloorWindow)
) {
isWindow = true;
break;
}
}
if (!isWindow) {
addBox(
"solid",
x, y, -5.75,
0.47, 0.46, 1.0,
brickVariation(ix, iy, 2)
);
} else {
addBox(
"glass",
x, y, -5.34,
0.45, 0.44, 0.12,
(ix + iy) % 4 === 0
? COLOR.glassLight
: COLOR.glass
);
}
}
}
function addBackWindowTrim(center, bottom, top) {
// Segmented vertical stone jambs.
for (let y = bottom + 0.1; y <= top - 0.1; y += 0.5) {
addBox(
"solid",
center - 0.72, y, -5.10,
0.24, 0.45, 0.42,
COLOR.trim
);
addBox(
"solid",
center + 0.72, y, -5.10,
0.24, 0.45, 0.42,
COLOR.trim
);
}
addBox(
"solid",
center, bottom - 0.12, -5.08,
1.68, 0.25, 0.48,
COLOR.stone
);
addBox(
"solid",
center, top + 0.12, -5.08,
1.68, 0.28, 0.48,
COLOR.trim
);
addBox(
"solid",
center, (bottom + top) * 0.5, -5.21,
0.12, top - bottom, 0.13,
COLOR.stone
);
}
backCenters.forEach((center) => {
addBackWindowTrim(center, 3.92, 5.78);
addBackWindowTrim(center, 6.38, 8.18);
});
// Horizontal string courses.
[3.70, 6.20, 9.56].forEach((y) => {
for (let x = -11.75; x < 8.5; x += 0.5) {
addBox(
"solid",
x, y, -5.13,
0.47, 0.27, 0.48,
COLOR.stone
);
}
});
// ------------------------------------------------------------
// Right wing: arcade with one distinct through-entrance
// ------------------------------------------------------------
const rightCenters = [-3.5, 0.5, 4.5];
const rightPiers = [-5.5, -1.5, 2.5, 6.5];
addBox(
"solid",
7.62, 0.22, 0.6,
2.25, 0.42, 11.8,
COLOR.stone
);
// Full-depth piers form the sides of the arcade and the passage.
for (let p = 0; p < rightPiers.length; p++) {
for (let iy = 0, y = 0.3; y < 2.3; iy++, y += 0.5) {
addBox(
"solid",
7.57, y, rightPiers[p],
2.25, 0.46, 0.92,
brickVariation(p, iy, 3)
);
}
}
// Two ordinary recessed bays.
for (let bay = 0; bay < 2; bay++) {
const start = rightPiers[bay] + 0.5;
const end = rightPiers[bay + 1] - 0.5;
for (let z = start; z < end; z += 0.5) {
for (let y = 0.3; y < 2.45; y += 0.5) {
addBox(
"solid",
8.35, y, z,
0.52, 0.46, 0.47,
(Math.round(y * 2) + Math.round(z * 2)) % 4 === 0
? COLOR.shadow
: COLOR.brickMuted
);
}
}
}
function addArchZ(center, x, spring, radius, depth = 0.58) {
for (let dy = 0; dy <= radius + 0.45; dy += 0.48) {
const y = spring + dy;
for (
let dz = -radius - 0.45;
dz <= radius + 0.45;
dz += 0.48
) {
const radiusSquared = dz * dz + dy * dy;
if (
radiusSquared >= (radius - 0.16) ** 2 &&
radiusSquared <= (radius + 0.40) ** 2
) {
addBox(
"solid",
x, y, center + dz,
depth, 0.46, 0.46,
COLOR.trim
);
}
}
}
}
rightCenters.forEach((center) => {
addArchZ(center, 6.30, 2.12, 1.48);
});
// The third bay is the only actual through-passage.
for (let x = 6.5; x <= 9.5; x += 0.5) {
for (let z = 3.5; z <= 5.5; z += 0.5) {
addBox(
"solid",
x, 0.17, z,
0.46, 0.12, 0.46,
COLOR.pavingDark
);
}
}
// Dark passage ceiling.
for (let x = 6.6; x <= 9.4; x += 0.5) {
addBox(
"solid",
x, 3.14, 4.5,
0.47, 0.24, 2.65,
COLOR.shadow
);
}
// Sunlit exterior seen through the passage.
addBox(
"solid",
9.52, 1.47, 4.5,
0.12, 2.65, 2.55,
0xf3dfb8
);
// A highlighted keystone identifies this as the singular entrance.
addBox(
"glow",
6.05, 3.63, 4.5,
0.44, 0.46, 0.52,
COLOR.lamp
);
// Pair of low entrance posts.
[3.0, 6.0].forEach((z) => {
addBox(
"solid",
5.82, 0.57, z,
0.42, 0.85, 0.42,
COLOR.stone
);
addBox(
"solid",
5.82, 1.03, z,
0.5, 0.14, 0.5,
COLOR.trim
);
});
// ------------------------------------------------------------
// Right wing upper facade
// ------------------------------------------------------------
for (let iz = 0, z = -5.05; z < 6.5; iz++, z += 0.5) {
for (let iy = 0, y = 3.85; y < 9.55; iy++, y += 0.5) {
let isWindow = false;
for (const center of rightCenters) {
const nearWindowColumn = Math.abs(z - center) < 0.52;
const firstFloorWindow = y >= 4.0 && y <= 5.75;
const secondFloorWindow = y >= 6.45 && y <= 8.15;
if (
nearWindowColumn &&
(firstFloorWindow || secondFloorWindow)
) {
isWindow = true;
break;
}
}
if (!isWindow) {
addBox(
"solid",
7.56, y, z,
2.1, 0.46, 0.47,
brickVariation(iz, iy, 4)
);
} else {
addBox(
"glass",
6.62, y, z,
0.12, 0.44, 0.45,
(iz + iy) % 4 === 0
? COLOR.glassLight
: COLOR.glass
);
}
}
}
function addRightWindowTrim(center, bottom, top) {
for (let y = bottom + 0.1; y <= top - 0.1; y += 0.5) {
addBox(
"solid",
6.28, y, center - 0.72,
0.42, 0.45, 0.24,
COLOR.trim
);
addBox(
"solid",
6.28, y, center + 0.72,
0.42, 0.45, 0.24,
COLOR.trim
);
}
addBox(
"solid",
6.27, bottom - 0.12, center,
0.48, 0.25, 1.68,
COLOR.stone
);
addBox(
"solid",
6.27, top + 0.12, center,
0.48, 0.28, 1.68,
COLOR.trim
);
addBox(
"solid",
6.40, (bottom + top) * 0.5, center,
0.13, top - bottom, 0.12,
COLOR.stone
);
}
rightCenters.forEach((center) => {
addRightWindowTrim(center, 3.92, 5.78);
addRightWindowTrim(center, 6.38, 8.18);
});
[3.70, 6.20, 9.56].forEach((y) => {
for (let z = -5.05; z < 6.5; z += 0.5) {
addBox(
"solid",
6.28, y, z,
0.48, 0.27, 0.47,
COLOR.stone
);
}
});
// ------------------------------------------------------------
// Stepped tiled roofs
// ------------------------------------------------------------
for (let ix = 0, x = -12.25; x <= 8.75; ix++, x += 0.5) {
for (let iz = 0, z = -7.8; z <= -5.3; iz++, z += 0.5) {
const lift = (Math.abs(z + 5.3) / 2.5) * 0.45;
addBox(
"solid",
x, 10.0 + lift, z,
0.47, 0.3, 0.47,
(ix + iz) % 3 === 0 ? COLOR.roofLight : COLOR.roof
);
}
}
for (let iz = 0, z = -5.3; z <= 6.5; iz++, z += 0.5) {
for (let ix = 0, x = 6.3; x <= 8.8; ix++, x += 0.5) {
const lift = ((x - 6.3) / 2.5) * 0.45;
addBox(
"solid",
x, 10.0 + lift, z,
0.47, 0.3, 0.47,
(ix + iz) % 3 === 0 ? COLOR.roofLight : COLOR.roof
);
}
}
// Small block-built roof chimneys.
[-8.5, -0.5, 6.0].forEach((x) => {
for (let y = 10.35; y < 11.35; y += 0.45) {
addBox(
"solid",
x, y, -6.55,
0.52, 0.42, 0.52,
COLOR.brickDark
);
}
addBox(
"solid",
x, 11.43, -6.55,
0.68, 0.18, 0.68,
COLOR.stone
);
});
// ------------------------------------------------------------
// Central square fountain, built entirely from blocks
// ------------------------------------------------------------
const fountainX = -2.5;
const fountainZ = 4.0;
addBox(
"solid",
fountainX, 0.31, fountainZ,
3.7, 0.34, 3.7,
COLOR.stone
);
// Square basin rim.
addBox(
"solid",
fountainX, 0.58, fountainZ - 1.55,
3.7, 0.46, 0.48,
COLOR.trim
);
addBox(
"solid",
fountainX, 0.58, fountainZ + 1.55,
3.7, 0.46, 0.48,
COLOR.trim
);
addBox(
"solid",
fountainX - 1.55, 0.58, fountainZ,
0.48, 0.46, 2.62,
COLOR.trim
);
addBox(
"solid",
fountainX + 1.55, 0.58, fountainZ,
0.48, 0.46, 2.62,
COLOR.trim
);
addBox(
"water",
fountainX, 0.54, fountainZ,
2.65, 0.12, 2.65,
COLOR.water
);
// Central pedestal and simplified bronze figure.
addBox(
"solid",
fountainX, 0.83, fountainZ,
1.15, 0.38, 1.15,
COLOR.stone
);
addBox(
"solid",
fountainX, 1.28, fountainZ,
0.62, 0.56, 0.62,
COLOR.bronze
);
addBox(
"solid",
fountainX, 1.78, fountainZ,
0.48, 0.5, 0.42,
COLOR.bronze
);
addBox(
"solid",
fountainX, 2.16, fountainZ,
0.34, 0.3, 0.34,
COLOR.bronze
);
addBox(
"solid",
fountainX - 0.37, 1.82, fountainZ,
0.24, 0.7, 0.24,
COLOR.bronze
);
addBox(
"solid",
fountainX + 0.37, 1.82, fountainZ,
0.24, 0.7, 0.24,
COLOR.bronze
);
// ------------------------------------------------------------
// Voxel lamps
// ------------------------------------------------------------
const lampPositions = [
[-10.2, 9.8],
[3.8, 10.5],
[-10.0, -2.3],
[3.8, -2.3]
];
lampPositions.forEach(([x, z], index) => {
addBox("solid", x, 0.47, z, 0.48, 0.55, 0.48, COLOR.stone);
addBox("solid", x, 1.02, z, 0.18, 0.75, 0.18, COLOR.bronze);
addBox("glow", x, 1.55, z, 0.36, 0.42, 0.36, COLOR.lamp);
addBox("solid", x, 1.83, z, 0.52, 0.16, 0.52, COLOR.bronze);
if (index < 2) {
const light = new THREE.PointLight(0xffb45e, 2.2, 4.2, 2);
light.position.set(x, 1.55, z);
scene.add(light);
}
});
// ------------------------------------------------------------
// Small voxel people provide scale without crowding the plaza
// ------------------------------------------------------------
const people = [
[-8.2, 7.0, 0xa44f43],
[-5.8, 8.4, 0x4f6671],
[1.6, 2.3, 0xc49a5a],
[4.0, 6.2, 0x745c77],
[-9.4, 1.0, 0x4d725f],
[-0.4, 10.2, 0x9a4f50],
[-0.9, -2.3, 0xb17b45],
[4.7, -3.4, 0x56697b],
[-6.2, 2.4, 0x795b5b],
[1.8, 10.8, 0x55726a]
];
people.forEach(([x, z, clothing]) => {
addBox("solid", x - 0.13, 0.48, z, 0.18, 0.65, 0.24, 0x46494a);
addBox("solid", x + 0.13, 0.48, z, 0.18, 0.65, 0.24, 0x46494a);
addBox("solid", x, 1.06, z, 0.48, 0.58, 0.3, clothing);
addBox("solid", x, 1.54, z, 0.34, 0.34, 0.34, 0xd6a47b);
});
// ------------------------------------------------------------
// Build instanced meshes
// ------------------------------------------------------------
const materials = {
solid: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0
}),
glass: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.25,
metalness: 0.2
}),
glow: new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: 0xff9a45,
emissiveIntensity: 1.55,
roughness: 0.45,
metalness: 0
}),
water: new THREE.MeshStandardMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.82,
roughness: 0.18,
metalness: 0.05
})
};
function createBatch(name, material) {
const entries = batches[name];
if (!entries.length) return;
const mesh = new THREE.InstancedMesh(
unitBox,
material,
entries.length
);
const transform = new THREE.Object3D();
entries.forEach((entry, index) => {
transform.position.set(entry.x, entry.y, entry.z);
transform.scale.set(entry.sx, entry.sy, entry.sz);
transform.updateMatrix();
mesh.setMatrixAt(index, transform.matrix);
mesh.setColorAt(index, new THREE.Color(entry.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.castShadow = name !== "water" && name !== "glow";
mesh.receiveShadow = name !== "glow";
mesh.computeBoundingSphere();
scene.add(mesh);
}
createBatch("solid", materials.solid);
createBatch("glass", materials.glass);
createBatch("glow", materials.glow);
createBatch("water", materials.water);
// Neutral ground beyond the bounded model catches the platform shadow.
const shadowGround = new THREE.Mesh(
new THREE.PlaneGeometry(180, 180),
new THREE.MeshStandardMaterial({
color: 0xbfc9c3,
roughness: 1
})
);
shadowGround.rotation.x = -Math.PI * 0.5;
shadowGround.position.y = -0.73;
shadowGround.receiveShadow = true;
scene.add(shadowGround);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, and reset
// ------------------------------------------------------------
const target = new THREE.Vector3(-1.2, 2.3, 1.2);
const defaultView = {
azimuth: -0.68,
elevation: 0.58,
radius: 34
};
let azimuth = defaultView.azimuth;
let elevation = defaultView.elevation;
let radius = defaultView.radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const horizontalRadius = Math.cos(elevation) * radius;
camera.position.set(
target.x + Math.sin(azimuth) * horizontalRadius,
target.y + Math.sin(elevation) * radius,
target.z + Math.cos(azimuth) * horizontalRadius
);
camera.lookAt(target);
}
function resetView() {
azimuth = defaultView.azimuth;
elevation = defaultView.elevation;
radius = defaultView.radius;
updateCamera();
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
azimuth -= deltaX * 0.006;
elevation = THREE.MathUtils.clamp(
elevation - deltaY * 0.005,
0.24,
1.25
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
18,
50
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
document.querySelector("#reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
azimuth += 0.1;
break;
case "ArrowRight":
azimuth -= 0.1;
break;
case "ArrowUp":
elevation = THREE.MathUtils.clamp(elevation + 0.08, 0.24, 1.25);
break;
case "ArrowDown":
elevation = THREE.MathUtils.clamp(elevation - 0.08, 0.24, 1.25);
break;
case "+":
case "=":
radius = Math.max(18, radius - 1.5);
break;
case "-":
case "_":
radius = Math.min(50, radius + 1.5);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
});
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```