Prompt specification
Build or customize the Three.js 3D scene "Small masonry courtyard under construction" 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: Small masonry courtyard under construction
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/small-masonry-courtyard-under-construction-x2175
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Create a courtyard with finished walls, an unfinished corner, and staged brick stacks. Show the same bond pattern continuing around openings and toward supported lintels.
Working Three.js Starter (small-masonry-courtyard-under-construction-x2175):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Masonry Courtyard</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: #d8dfdc;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: min(350px, calc(100vw - 36px));
padding: 16px 17px 14px;
color: #29302d;
background: rgba(247, 244, 235, 0.9);
border: 1px solid rgba(58, 65, 61, 0.17);
border-radius: 12px;
box-shadow: 0 12px 34px rgba(45, 49, 46, 0.16);
backdrop-filter: blur(10px);
user-select: none;
}
.eyebrow {
margin-bottom: 5px;
color: #9b513e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 20px;
line-height: 1.15;
letter-spacing: -0.025em;
}
.description {
margin: 9px 0 12px;
color: #5e6762;
font-size: 12px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 7px 13px;
margin-bottom: 13px;
color: #59615d;
font-size: 11px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.dot.complete {
background: #b65f45;
}
.dot.open {
background: #7a5b43;
}
.dot.staged {
background: #d07855;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding-top: 11px;
border-top: 1px solid rgba(58, 65, 61, 0.12);
}
.hint {
color: #69716d;
font-size: 10px;
line-height: 1.45;
}
button {
flex: 0 0 auto;
padding: 7px 10px;
color: #f8f4e9;
background: #3d4944;
border: 0;
border-radius: 7px;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
button:hover {
background: #29342f;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #52605a;
background: #d8dfdc;
font-size: 13px;
letter-spacing: 0.04em;
}
@media (max-width: 600px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 13px;
}
h1 {
font-size: 17px;
}
.description {
margin: 7px 0 9px;
}
.legend {
margin-bottom: 9px;
}
}
</style>
</head>
<body>
<div id="loading">Building the courtyard…</div>
<section class="panel" aria-label="Scene information">
<div class="eyebrow">Masonry study / 01</div>
<h1>Courtyard in Progress</h1>
<p class="description">
A single running-bond grid continues around every opening. Bricks are
clipped from that grid, while timber lintels bear on the surviving jambs.
</p>
<div class="legend">
<span><i class="dot complete"></i>Completed walls</span>
<span><i class="dot open"></i>Openings and lintels</span>
<span><i class="dot staged"></i>Staged brickwork</span>
</div>
<div class="panel-footer">
<div class="hint">
Drag to orbit · wheel to zoom<br>
Right-drag to pan · double-click to reset
</div>
<button id="reset" type="button">Reset view</button>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8dfdc);
scene.fog = new THREE.Fog(0xd8dfdc, 25, 48);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
camera.position.set(12, 9.2, 13.5);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly courtyard under construction"
);
document.body.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xf5efe0, 0x6a7169, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.2);
sun.position.set(-9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -15;
sun.shadow.camera.right = 15;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d4df, 0.65);
fill.position.set(10, 6, -8);
scene.add(fill);
// ------------------------------------------------------------
// Shared geometry and materials
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
brick: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.93,
metalness: 0
}),
mortar: new THREE.MeshStandardMaterial({
color: 0xc7b9a4,
roughness: 1
}),
stone: new THREE.MeshStandardMaterial({
color: 0xc8bda5,
roughness: 0.94
}),
wood: new THREE.MeshStandardMaterial({
color: 0x795039,
roughness: 0.88
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x4d382b,
roughness: 0.9
}),
iron: new THREE.MeshStandardMaterial({
color: 0x302d29,
roughness: 0.62,
metalness: 0.45
}),
ground: new THREE.MeshStandardMaterial({
color: 0x8b8b7e,
roughness: 1
})
};
const palette = [
0xb65e43,
0xc56a4a,
0xa9503d,
0xd17855,
0xb86049,
0xc06449,
0xad5942
];
const freshPalette = [
0xc16a4b,
0xd07855,
0xb65d43,
0xd48660,
0xbb6247
];
let randomSeed = 1847;
function random() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function pickColor(paletteList = palette) {
return new THREE.Color(
paletteList[Math.floor(random() * paletteList.length)]
);
}
const dummy = new THREE.Object3D();
function makeInstances(items, material, parent, castShadow = true) {
const mesh = new THREE.InstancedMesh(unitBox, material, items.length);
items.forEach((item, index) => {
dummy.position.set(item.x || 0, item.y || 0, item.z || 0);
dummy.rotation.set(
item.rx || 0,
item.ry || 0,
item.rz || 0
);
dummy.scale.set(
item.sx ?? 1,
item.sy ?? 1,
item.sz ?? 1
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (item.color !== undefined) {
mesh.setColorAt(
index,
item.color instanceof THREE.Color
? item.color
: new THREE.Color(item.color)
);
}
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
mesh.computeBoundingSphere();
parent.add(mesh);
return mesh;
}
function addBox(
parent,
sx,
sy,
sz,
x,
y,
z,
material,
rotation = null
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
if (rotation) {
mesh.rotation.set(
rotation.rx || 0,
rotation.ry || 0,
rotation.rz || 0
);
}
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// ------------------------------------------------------------
// Ground and courtyard paving
// ------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(28, 24),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.075;
ground.receiveShadow = true;
scene.add(ground);
const pavingColors = [
0xa9a294,
0xb0a89a,
0xa39d90,
0xb5ad9f,
0x9f9b8e
];
const paving = [];
for (let ix = 0; ix < 11; ix++) {
for (let iz = 0; iz < 9; iz++) {
paving.push({
x: -5.5 + ix * 1.1,
y: -0.018,
z: -4.72 + iz * 1.16,
sx: 1.075,
sy: 0.065,
sz: 1.135,
color: pickColor(pavingColors)
});
}
}
makeInstances(paving, materials.stone, scene, false);
// ------------------------------------------------------------
// Masonry helpers
//
// All courses use one alternating half-brick grid. Openings are
// subtracted from this grid instead of restarting it.
// ------------------------------------------------------------
const COURSE_HEIGHT = 0.36;
const BRICK_STEP = 0.80;
const MORTAR_GAP = 0.025;
const WALL_DEPTH = 0.38;
function subtractRectangle(rectangle, holes) {
let pieces = [rectangle];
for (const hole of holes) {
const next = [];
for (const piece of pieces) {
const overlaps =
hole.x0 < piece.x1 &&
hole.x1 > piece.x0 &&
hole.y0 < piece.y1 &&
hole.y1 > piece.y0;
if (!overlaps) {
next.push(piece);
continue;
}
if (piece.x0 < hole.x0) {
next.push({
x0: piece.x0,
x1: hole.x0,
y0: piece.y0,
y1: piece.y1
});
}
if (hole.x1 < piece.x1) {
next.push({
x0: hole.x1,
x1: piece.x1,
y0: piece.y0,
y1: piece.y1
});
}
const overlapY0 = Math.max(piece.y0, hole.y0);
const overlapY1 = Math.min(piece.y1, hole.y1);
const overlapX0 = Math.max(piece.x0, hole.x0);
const overlapX1 = Math.min(piece.x1, hole.x1);
if (piece.y0 < overlapY0) {
next.push({
x0: overlapX0,
x1: overlapX1,
y0: piece.y0,
y1: overlapY0
});
}
if (overlapY1 < piece.y1) {
next.push({
x0: overlapX0,
x1: overlapX1,
y0: overlapY1,
y1: piece.y1
});
}
}
pieces = next;
}
return pieces.filter(
piece =>
piece.x1 - piece.x0 > 0.001 &&
piece.y1 - piece.y0 > 0.001
);
}
function buildWall({
position,
rotationY = 0,
length,
segments,
openings = [],
finished = false,
fresh = false
}) {
const group = new THREE.Group();
group.position.set(...position);
group.rotation.y = rotationY;
scene.add(group);
const brickItems = [];
const mortarItems = [];
// The final course space is reserved for the lintel itself.
const holes = openings.map(opening => ({
x0: opening.x0,
x1: opening.x1,
y0: opening.y0,
y1: opening.y1 + COURSE_HEIGHT
}));
// Mortar backing: solid except where openings and lintels occur.
for (const segment of segments) {
const remaining = subtractRectangle(
{
x0: segment.x0,
x1: segment.x1,
y0: 0,
y1: segment.height
},
holes
);
for (const piece of remaining) {
mortarItems.push({
x: (piece.x0 + piece.x1) * 0.5,
y: (piece.y0 + piece.y1) * 0.5,
z: -0.025,
sx: piece.x1 - piece.x0,
sy: piece.y1 - piece.y0,
sz: 0.34
});
}
}
const minX = Math.min(...segments.map(segment => segment.x0));
const maxX = Math.max(...segments.map(segment => segment.x1));
const maxHeight = Math.max(...segments.map(segment => segment.height));
const rowCount = Math.ceil(maxHeight / COURSE_HEIGHT);
// Running-bond brick courses.
for (let row = 0; row < rowCount; row++) {
const rowY0 = row * COURSE_HEIGHT;
const rowY1 = (row + 1) * COURSE_HEIGHT;
const shift = row % 2 === 0 ? 0 : BRICK_STEP * 0.5;
const firstCell = Math.floor((minX - shift) / BRICK_STEP) - 1;
const lastCell = Math.ceil((maxX - shift) / BRICK_STEP) + 1;
for (const segment of segments) {
const courseY1 = Math.min(rowY1, segment.height);
if (courseY1 <= rowY0) {
continue;
}
for (let cell = firstCell; cell <= lastCell; cell++) {
const cellX0 = cell * BRICK_STEP + shift;
const cellX1 = cellX0 + BRICK_STEP;
const brickX0 = Math.max(cellX0, segment.x0);
const brickX1 = Math.min(cellX1, segment.x1);
if (brickX1 <= brickX0) {
continue;
}
const pieces = subtractRectangle(
{
x0: brickX0,
x1: brickX1,
y0: rowY0,
y1: courseY1
},
holes
);
for (const piece of pieces) {
const width = piece.x1 - piece.x0;
const height = piece.y1 - piece.y0;
brickItems.push({
x: (piece.x0 + piece.x1) * 0.5,
y: (piece.y0 + piece.y1) * 0.5,
z: 0,
sx: Math.max(0.045, width - MORTAR_GAP),
sy: Math.max(0.045, height - MORTAR_GAP),
sz: WALL_DEPTH,
color: pickColor(fresh ? freshPalette : palette)
});
}
}
}
}
makeInstances(mortarItems, materials.mortar, group, false);
makeInstances(brickItems, materials.brick, group, true);
// Stone coping distinguishes completed wall sections.
if (finished) {
for (const segment of segments) {
addBox(
group,
segment.x1 - segment.x0,
0.12,
0.54,
(segment.x0 + segment.x1) * 0.5,
segment.height + 0.06,
0,
materials.stone
);
}
}
// Supported timber lintels and optional stone window sills.
for (const opening of openings) {
const width = opening.x1 - opening.x0;
const centerX = (opening.x0 + opening.x1) * 0.5;
addBox(
group,
width + 0.36,
0.28,
0.54,
centerX,
opening.y1 + 0.14,
0,
opening.door ? materials.darkWood : materials.wood
);
// Iron pins on the room-facing side of the lintel.
for (const offset of [-0.28, 0, 0.28]) {
addBox(
group,
0.045,
0.045,
0.025,
centerX + offset,
opening.y1 + 0.14,
0.282,
materials.iron
);
}
if (!opening.door) {
addBox(
group,
width + 0.30,
0.10,
0.54,
centerX,
opening.y0 - 0.05,
0,
materials.stone
);
}
}
return group;
}
// ------------------------------------------------------------
// Completed north wall with two window openings
// ------------------------------------------------------------
buildWall({
position: [0, 0, -5.5],
length: 14,
finished: true,
segments: [
{ x0: -7, x1: 7, height: 3.6 }
],
openings: [
{
x0: -4.8,
x1: -3.0,
y0: 0.72,
y1: 2.16
},
{
x0: 1.2,
x1: 3.6,
y0: 1.08,
y1: 2.52
}
]
});
// Completed west wall with a doorway and supported lintel.
buildWall({
position: [-7, 0, 0],
rotationY: Math.PI / 2,
length: 11,
finished: true,
segments: [
{ x0: -5.5, x1: 5.5, height: 3.6 }
],
openings: [
{
x0: -1.15,
x1: 1.15,
y0: 0,
y1: 2.88,
door: true
}
]
});
// Unfinished east wall: the same bond grid steps down with the work.
buildWall({
position: [7, 0, 0],
rotationY: -Math.PI / 2,
length: 11,
fresh: true,
segments: [
{ x0: -5.5, x1: -2.75, height: 3.30 },
{ x0: -2.75, x1: 0.15, height: 2.52 },
{ x0: 0.15, x1: 2.05, height: 1.72 },
{ x0: 2.05, x1: 5.5, height: 0.90 }
]
});
// Foundations on the completed walls, leaving the doorway clear.
addBox(
scene,
14,
0.16,
0.54,
0,
0.08,
-5.5,
materials.stone
);
addBox(
scene,
4.35,
0.16,
0.54,
-7,
0.08,
-3.325,
materials.stone
);
addBox(
scene,
4.35,
0.16,
0.54,
-7,
0.08,
3.325,
materials.stone
);
// ------------------------------------------------------------
// Staged brick stacks on timber pallets
// ------------------------------------------------------------
function createBrickStack({
x,
z,
rotation = 0,
layers = 5,
columns = 4,
depthRows = 2
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
const palletWidth = columns * 0.8 + 0.45;
const palletDepth = 1.05;
// Pallet runners.
for (const runnerX of [-palletWidth * 0.38, 0, palletWidth * 0.38]) {
addBox(
group,
0.15,
0.11,
palletDepth,
runnerX,
0.055,
0,
materials.wood
);
}
// Pallet deck slats.
for (let i = 0; i < 7; i++) {
addBox(
group,
palletWidth,
0.07,
0.12,
0,
0.14,
-0.45 + i * 0.15,
materials.wood
);
}
const bricks = [];
for (let layer = 0; layer < layers; layer++) {
const offset = layer % 2 === 0 ? 0 : 0.39;
const count = columns + (layer % 2);
for (let column = 0; column < count; column++) {
for (let row = 0; row < depthRows; row++) {
const brickX =
(column - (count - 1) / 2) * 0.78 + offset;
const brickZ =
(row - (depthRows - 1) / 2) * 0.39 +
(layer % 2 ? 0.025 : 0);
bricks.push({
x: brickX,
y: 0.265 + layer * 0.185,
z: brickZ,
sx: 0.75,
sy: 0.17,
sz: 0.36,
color: pickColor()
});
}
}
}
makeInstances(bricks, materials.brick, group, true);
return group;
}
createBrickStack({
x: -3.25,
z: 1.45,
rotation: 0.06,
layers: 6,
columns: 4
});
createBrickStack({
x: 0.45,
z: 3.15,
rotation: -0.10,
layers: 4,
columns: 3
});
createBrickStack({
x: 5.10,
z: -2.55,
rotation: 0.14,
layers: 3,
columns: 2,
depthRows: 2
});
// Loose bricks staged beside the unfinished return wall.
for (let i = 0; i < 10; i++) {
addBox(
scene,
0.75,
0.17,
0.36,
5.25 + (random() - 0.5) * 1.25,
0.11,
-0.35 + (random() - 0.5) * 1.7,
materials.brick,
{ ry: random() * Math.PI }
);
}
// A simple timber ladder against the unfinished wall.
for (const z of [-2.95, -2.35]) {
addBox(
scene,
0.085,
3.15,
0.085,
7.36,
1.58,
z,
materials.wood
);
}
for (let i = 0; i < 8; i++) {
addBox(
scene,
0.085,
0.075,
0.68,
7.36,
0.38 + i * 0.37,
-2.65,
materials.wood
);
}
// Stacked timber offcuts.
for (let i = 0; i < 4; i++) {
addBox(
scene,
0.13,
0.13,
2.65,
6.18,
0.08 + i * 0.14,
-3.28,
materials.wood,
{ ry: 0.035 * i }
);
}
// ------------------------------------------------------------
// Camera controls implemented directly with Three.js core
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.15, -0.25);
const spherical = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(cameraTarget)
);
const initialTarget = cameraTarget.clone();
const initialSpherical = spherical.clone();
function updateCamera() {
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetView() {
cameraTarget.copy(initialTarget);
spherical.copy(initialSpherical);
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetView);
const canvas = renderer.domElement;
const pointers = new Map();
let pinchDistance = 0;
let pinchMidpoint = new THREE.Vector2();
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button,
pointerType: event.pointerType
});
if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
pinchMidpoint.set(
(points[0].x + points[1].x) * 0.5,
(points[0].y + points[1].y) * 0.5
);
}
});
canvas.addEventListener("pointermove", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) {
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size >= 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
const midpoint = new THREE.Vector2(
(points[0].x + points[1].x) * 0.5,
(points[0].y + points[1].y) * 0.5
);
if (pinchDistance > 0 && distance > 0) {
spherical.radius *= pinchDistance / distance;
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
7,
29
);
}
const panScale =
2 *
spherical.radius *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) /
innerHeight;
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
cameraTarget
.addScaledVector(
right,
-(midpoint.x - pinchMidpoint.x) * panScale
)
.addScaledVector(
up,
(midpoint.y - pinchMidpoint.y) * panScale
);
pinchDistance = distance;
pinchMidpoint.copy(midpoint);
clampTarget();
updateCamera();
return;
}
const panning =
pointer.pointerType === "mouse" &&
(pointer.button === 2 || event.shiftKey);
if (panning) {
const panScale =
2 *
spherical.radius *
Math.tan(THREE.MathUtils.degToRad(camera.fov * 0.5)) /
innerHeight;
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
1
);
cameraTarget
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
clampTarget();
} else {
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi,
0.22,
1.46
);
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
7,
29
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
function clampTarget() {
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -10, 10);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 0.2, 4.5);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -9, 9);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Render
// ------------------------------------------------------------
updateCamera();
document.getElementById("loading").remove();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```