Prompt specification
Build or customize the Three.js 3D scene "Gallery of Orthographic and Perspective Views" 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: Gallery of Orthographic and Perspective Views
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/gallery-of-orthographic-and-perspective-views-x3319
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a voxel gallery comparing orthographic and perspective views. Build one compact city model with equal-height towers at different depths, parallel streets, and a few cubic trees. Present the same geometry in two adjacent viewports with matched orientation, one using each projection. Let the viewer move both cameras together and toggle guides along the streets. The orthographic view should preserve parallel projected lines, while the perspective view changes apparent sizes with depth. Keep world-space dimensions fixed. Frame the displays as a simple gallery installation with small projection labels and no additional building detail that obscures the comparison.
Working Three.js Starter (gallery-of-orthographic-and-perspective-views-x3319):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Projection Gallery — One City, Two Views</title>
<style>
:root {
--paper: #e4e0d6;
--paper-light: #f0ede5;
--ink: #242725;
--muted: #6b706b;
--line: rgba(36, 39, 37, 0.22);
--guide: #0b9e9a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
color: var(--ink);
background:
radial-gradient(circle at 50% 20%, #efede7 0%, var(--paper) 68%);
font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}
button {
font: inherit;
}
#app {
width: 100%;
height: 100dvh;
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
}
header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
padding: 18px 24px 13px;
border-bottom: 1px solid var(--line);
}
.eyebrow {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 27px);
font-weight: 550;
letter-spacing: -0.035em;
}
.specification {
color: var(--muted);
font-size: 10px;
line-height: 1.6;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
}
#stage {
position: relative;
min-height: 0;
margin: 12px 22px;
overflow: hidden;
border: 1px solid rgba(36, 39, 37, 0.28);
border-radius: 3px;
background: #ddd8cd;
box-shadow:
0 16px 40px rgba(35, 37, 34, 0.10),
inset 0 0 0 5px rgba(255, 255, 255, 0.18);
cursor: grab;
touch-action: none;
outline: none;
}
#stage:active {
cursor: grabbing;
}
#stage:focus-visible {
box-shadow:
0 16px 40px rgba(35, 37, 34, 0.10),
0 0 0 3px rgba(11, 158, 154, 0.35);
}
#scene {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
}
.viewport {
position: absolute;
top: 0;
bottom: 0;
z-index: 1;
width: 50%;
pointer-events: none;
}
#perspective-panel {
left: 50%;
border-left: 1px solid rgba(36, 39, 37, 0.24);
}
.projection-label {
position: absolute;
top: 18px;
left: 18px;
min-width: 160px;
padding: 10px 12px 9px;
border: 1px solid rgba(36, 39, 37, 0.16);
border-radius: 2px;
background: rgba(239, 236, 227, 0.90);
box-shadow: 0 5px 16px rgba(30, 33, 30, 0.06);
}
.projection-label strong {
display: block;
margin-bottom: 4px;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.projection-label span {
display: block;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.projection-label::before {
content: "";
display: block;
width: 25px;
height: 2px;
margin-bottom: 8px;
background: var(--ink);
}
#perspective-panel .projection-label::before {
background: var(--guide);
}
#sync-note {
position: absolute;
z-index: 2;
bottom: 13px;
left: 50%;
transform: translateX(-50%);
padding: 6px 9px;
border: 1px solid rgba(36, 39, 37, 0.14);
border-radius: 999px;
color: #505651;
background: rgba(239, 236, 227, 0.88);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.14em;
pointer-events: none;
text-transform: uppercase;
white-space: nowrap;
}
footer {
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 18px;
min-height: 64px;
padding: 10px 24px 14px;
border-top: 1px solid var(--line);
}
.controls {
display: flex;
align-items: center;
gap: 8px;
}
.control-button {
min-height: 34px;
padding: 8px 12px;
border: 1px solid rgba(36, 39, 37, 0.27);
border-radius: 2px;
color: var(--ink);
background: rgba(244, 241, 233, 0.72);
cursor: pointer;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
.control-button:hover {
border-color: rgba(36, 39, 37, 0.48);
background: rgba(255, 253, 247, 0.95);
}
.control-button:active {
transform: translateY(1px);
}
.control-button[aria-pressed="true"] {
border-color: rgba(11, 158, 154, 0.48);
color: #087b78;
background: rgba(216, 244, 240, 0.82);
}
.control-button:focus-visible {
outline: 2px solid rgba(11, 158, 154, 0.55);
outline-offset: 2px;
}
.hint {
margin: 0;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
}
.status {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--guide);
box-shadow: 0 0 0 3px rgba(11, 158, 154, 0.12);
}
@media (max-width: 760px) {
header {
align-items: flex-start;
padding: 14px 15px 10px;
}
.specification {
display: none;
}
#stage {
margin: 9px 10px;
}
.projection-label {
top: 10px;
left: 10px;
min-width: 0;
padding: 8px 9px;
}
.projection-label strong {
font-size: 9px;
}
.projection-label span {
display: none;
}
footer {
grid-template-columns: 1fr auto;
gap: 8px;
padding: 9px 12px 12px;
}
.hint {
display: none;
}
.control-button {
padding: 8px 9px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app">
<header>
<div>
<div class="eyebrow">Projection Gallery / Study 02</div>
<h1>One City, Two Spatial Readings</h1>
</div>
<div class="specification">
Model footprint: 10.4 × 10.4 m<br>
All towers: 2.4 m high
</div>
</header>
<main
id="stage"
tabindex="0"
aria-label="Interactive orthographic and perspective city comparison"
>
<canvas id="scene" aria-label="Voxel city rendered with two synchronized projections"></canvas>
<section id="orthographic-panel" class="viewport" aria-hidden="true">
<div class="projection-label">
<strong>Orthographic</strong>
<span>Parallel lines · Fixed scale</span>
</div>
</section>
<section id="perspective-panel" class="viewport" aria-hidden="true">
<div class="projection-label">
<strong>Perspective</strong>
<span>Convergence · Depth scale</span>
</div>
</section>
<div id="sync-note">Synchronized orientation</div>
</main>
<footer>
<div class="controls">
<button
id="guides-button"
class="control-button"
type="button"
aria-pressed="true"
>
Street guides: on
</button>
<button id="reset-button" class="control-button" type="button">
Reset view
</button>
</div>
<p class="hint">
Drag to orbit · Shift-drag to pan · Scroll to zoom · Arrow keys to move
</p>
<div class="status">
<span class="status-dot"></span>
Cameras linked
</div>
</footer>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const canvas = document.querySelector("#scene");
const guidesButton = document.querySelector("#guides-button");
const resetButton = document.querySelector("#reset-button");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
// The model and lights are static, so the shadow map only needs one update.
renderer.shadowMap.autoUpdate = false;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe4e0d6);
const cameraTarget = new THREE.Vector3(0, 0.72, 0);
const perspectiveCamera = new THREE.PerspectiveCamera(
38,
1,
0.1,
160
);
const orthographicCamera = new THREE.OrthographicCamera(
-1,
1,
1,
-1,
0.1,
160
);
const hemisphereLight = new THREE.HemisphereLight(
0xfff8e9,
0x68706d,
1.65
);
scene.add(hemisphereLight);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-7, 12, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d6df, 0.7);
fillLight.position.set(8, 5, -8);
scene.add(fillLight);
const materials = {
plinth: new THREE.MeshStandardMaterial({
color: 0xc9c4b9,
roughness: 0.92
}),
road: new THREE.MeshStandardMaterial({
color: 0x454b4a,
roughness: 0.98
}),
tower: new THREE.MeshStandardMaterial({
color: 0xc66b52,
roughness: 0.78
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x745541,
roughness: 0.95
}),
canopy: new THREE.MeshStandardMaterial({
color: 0x627f6b,
roughness: 0.9
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd9d5ca,
roughness: 1
}),
guide: new THREE.MeshBasicMaterial({
color: 0x0b9e9a,
toneMapped: false
})
};
function addBox(width, height, depth, material, x, y, z, castShadow = true) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// Gallery-like ground surrounding the architectural model.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.39;
floor.receiveShadow = true;
scene.add(floor);
// Compact city plinth.
addBox(
10.4,
0.36,
10.4,
materials.plinth,
0,
-0.18,
0,
false
);
// Two parallel streets running in world Z.
const roadCenters = [-1.75, 1.75];
for (const x of roadCenters) {
addBox(
1.55,
0.03,
9.8,
materials.road,
x,
0.015,
0,
false
);
}
// Equal-height towers arranged at several depths.
const towerGeometry = new THREE.BoxGeometry(1.25, 2.4, 1.25);
for (const x of [-3.45, 0, 3.45]) {
for (const z of [-3.15, 0, 3.15]) {
const tower = new THREE.Mesh(towerGeometry, materials.tower);
tower.position.set(x, 1.23, z);
tower.castShadow = true;
tower.receiveShadow = true;
scene.add(tower);
}
}
// A few cubic trees around the perimeter.
const treePositions = [
[-4.62, 3.75],
[-4.62, -2.85],
[4.62, -3.85],
[4.62, 2.70]
];
for (const [x, z] of treePositions) {
addBox(
0.22,
0.56,
0.22,
materials.trunk,
x,
0.31,
z
);
addBox(
0.82,
0.82,
0.82,
materials.canopy,
x,
0.92,
z
);
}
// Toggleable world-space guide strips along both sides of each street.
const guides = new THREE.Group();
scene.add(guides);
for (const roadX of roadCenters) {
for (const offset of [-0.775, 0.775]) {
const guide = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.014, 9.7),
materials.guide
);
guide.position.set(roadX + offset, 0.043, 0);
guides.add(guide);
}
}
// ---------------------------------------------------------------------
// Synchronized camera state
// ---------------------------------------------------------------------
const DEFAULT_YAW = 0.38;
const DEFAULT_ELEVATION = 0.54;
const state = {
yaw: DEFAULT_YAW,
elevation: DEFAULT_ELEVATION,
zoom: 1,
target: cameraTarget.clone()
};
let fitDistance = 22;
let viewportWidth = 1;
let viewportHeight = 1;
function updateCameras() {
const distance = fitDistance / state.zoom;
const horizontalDistance = Math.cos(state.elevation) * distance;
const position = new THREE.Vector3(
state.target.x + Math.sin(state.yaw) * horizontalDistance,
state.target.y + Math.sin(state.elevation) * distance,
state.target.z + Math.cos(state.yaw) * horizontalDistance
);
// Both cameras use exactly the same position, target and orientation.
perspectiveCamera.position.copy(position);
orthographicCamera.position.copy(position);
perspectiveCamera.lookAt(state.target);
orthographicCamera.lookAt(state.target);
// Orthographic zoom and perspective dolly are matched for framing.
// World-space geometry itself is never scaled.
orthographicCamera.zoom = state.zoom;
orthographicCamera.updateProjectionMatrix();
}
function resize() {
viewportWidth = Math.max(1, stage.clientWidth);
viewportHeight = Math.max(1, stage.clientHeight);
renderer.setSize(viewportWidth, viewportHeight, false);
const rightWidth = viewportWidth - Math.floor(viewportWidth / 2);
const aspect = rightWidth / viewportHeight;
// Keep the complete 10.4 m plinth visible in narrow panels.
const orthographicHeight = Math.max(12.0, 15.2 / aspect);
orthographicCamera.left = -orthographicHeight * aspect / 2;
orthographicCamera.right = orthographicHeight * aspect / 2;
orthographicCamera.top = orthographicHeight / 2;
orthographicCamera.bottom = -orthographicHeight / 2;
orthographicCamera.updateProjectionMatrix();
perspectiveCamera.aspect = aspect;
perspectiveCamera.updateProjectionMatrix();
const halfFov = THREE.MathUtils.degToRad(perspectiveCamera.fov / 2);
fitDistance = orthographicHeight / (2 * Math.tan(halfFov));
const farPlane = Math.max(160, fitDistance * 2.4);
perspectiveCamera.far = farPlane;
orthographicCamera.far = farPlane;
perspectiveCamera.updateProjectionMatrix();
orthographicCamera.updateProjectionMatrix();
updateCameras();
render();
}
function render() {
const split = Math.floor(viewportWidth / 2);
const rightWidth = viewportWidth - split;
renderer.setScissorTest(true);
// Left installation: orthographic projection.
renderer.setViewport(0, 0, split, viewportHeight);
renderer.setScissor(0, 0, split, viewportHeight);
renderer.render(scene, orthographicCamera);
// Right installation: perspective projection.
renderer.setViewport(split, 0, rightWidth, viewportHeight);
renderer.setScissor(split, 0, rightWidth, viewportHeight);
renderer.render(scene, perspectiveCamera);
renderer.setScissorTest(false);
}
// ---------------------------------------------------------------------
// Custom pointer, wheel and keyboard controls
// ---------------------------------------------------------------------
let drag = null;
stage.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
drag = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey || event.button === 2
};
stage.setPointerCapture(event.pointerId);
stage.focus({ preventScroll: true });
event.preventDefault();
});
stage.addEventListener("pointermove", (event) => {
if (!drag || event.pointerId !== drag.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const scale = (fitDistance / state.zoom) * 0.00125;
const cameraRight = new THREE.Vector3(
Math.cos(state.yaw),
0,
-Math.sin(state.yaw)
);
const cameraForward = new THREE.Vector3(
-Math.sin(state.yaw),
0,
-Math.cos(state.yaw)
);
state.target.addScaledVector(cameraRight, -dx * scale);
state.target.addScaledVector(cameraForward, dy * scale);
state.target.x = THREE.MathUtils.clamp(state.target.x, -2.5, 2.5);
state.target.z = THREE.MathUtils.clamp(state.target.z, -2.5, 2.5);
} else {
state.yaw -= dx * 0.006;
state.elevation = THREE.MathUtils.clamp(
state.elevation + dy * 0.005,
0.20,
1.15
);
}
updateCameras();
render();
});
function endDrag(event) {
if (!drag || event.pointerId !== drag.pointerId) return;
if (stage.hasPointerCapture(event.pointerId)) {
stage.releasePointerCapture(event.pointerId);
}
drag = null;
}
stage.addEventListener("pointerup", endDrag);
stage.addEventListener("pointercancel", endDrag);
stage.addEventListener("contextmenu", (event) => event.preventDefault());
stage.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const delta = THREE.MathUtils.clamp(event.deltaY, -100, 100);
state.zoom = THREE.MathUtils.clamp(
state.zoom * Math.exp(-delta * 0.0012),
0.65,
2.25
);
updateCameras();
render();
},
{ passive: false }
);
stage.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
state.yaw -= 0.08;
break;
case "ArrowRight":
state.yaw += 0.08;
break;
case "ArrowUp":
state.elevation = THREE.MathUtils.clamp(
state.elevation + 0.06,
0.20,
1.15
);
break;
case "ArrowDown":
state.elevation = THREE.MathUtils.clamp(
state.elevation - 0.06,
0.20,
1.15
);
break;
case "+":
case "=":
state.zoom = THREE.MathUtils.clamp(state.zoom * 1.1, 0.65, 2.25);
break;
case "-":
case "_":
state.zoom = THREE.MathUtils.clamp(state.zoom / 1.1, 0.65, 2.25);
break;
case "0":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCameras();
render();
}
});
function resetView() {
state.yaw = DEFAULT_YAW;
state.elevation = DEFAULT_ELEVATION;
state.zoom = 1;
state.target.set(0, 0.72, 0);
updateCameras();
render();
}
guidesButton.addEventListener("click", () => {
const visible = !guides.visible;
guides.visible = visible;
guidesButton.setAttribute("aria-pressed", String(visible));
guidesButton.textContent = `Street guides: ${visible ? "on" : "off"}`;
render();
});
resetButton.addEventListener("click", resetView);
// ---------------------------------------------------------------------
// Start
// ---------------------------------------------------------------------
renderer.shadowMap.needsUpdate = true;
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
</script>
</body>
</html>
```