Prompt specification
Build or customize the Three.js 3D scene "Paraty stone pavement and raised doorway" 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: Paraty stone pavement and raised doorway
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/paraty-stone-pavement-and-raised-doorway-x2685
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing Paraty's historic waterfront. Build a referenced historic street tile with irregular stone paving and raised building threshold. Show the small elevation difference between doorway and street surface. Low-poly.
Working Three.js Starter (paraty-stone-pavement-and-raised-doorway-x2685):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Paraty — Historic Waterfront Street Tile</title>
<style>
:root {
color-scheme: light;
--ink: #23312e;
--paper: rgba(250, 247, 238, 0.91);
--accent: #b65d2c;
--line: rgba(35, 49, 46, 0.2);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8e5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: 22px;
left: 24px;
z-index: 10;
width: min(430px, calc(100vw - 48px));
padding: 17px 19px 15px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 38px rgba(37, 53, 49, 0.13);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3.1vw, 38px);
font-weight: 500;
line-height: 1;
letter-spacing: -0.02em;
}
.subtitle {
margin-top: 8px;
color: rgba(35, 49, 46, 0.74);
font-size: 12px;
line-height: 1.45;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 12px;
}
.chip {
padding: 5px 8px;
border: 1px solid rgba(35, 49, 46, 0.14);
border-radius: 999px;
background: rgba(255, 255, 255, 0.46);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.055em;
text-transform: uppercase;
}
.chip.accent {
border-color: rgba(182, 93, 44, 0.25);
color: #98491f;
background: rgba(182, 93, 44, 0.09);
}
.help {
position: fixed;
left: 24px;
bottom: 23px;
z-index: 10;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(250, 247, 238, 0.85);
box-shadow: 0 8px 30px rgba(37, 53, 49, 0.1);
backdrop-filter: blur(10px);
font-size: 10px;
pointer-events: none;
}
.help kbd {
padding: 2px 5px;
border: 1px solid rgba(35, 49, 46, 0.2);
border-bottom-width: 2px;
border-radius: 3px;
background: white;
font: inherit;
font-weight: 700;
}
#reset {
z-index: 12;
padding: 8px 10px;
border: 1px solid rgba(35, 49, 46, 0.2);
border-radius: 3px;
background: #faf7ee;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
#reset:hover {
background: white;
border-color: rgba(35, 49, 46, 0.4);
}
#detail-frame {
position: fixed;
right: 23px;
bottom: 22px;
z-index: 9;
width: 310px;
height: 194px;
overflow: hidden;
border: 1px solid rgba(35, 49, 46, 0.3);
border-radius: 4px;
box-shadow: 0 16px 45px rgba(25, 41, 38, 0.22);
pointer-events: none;
}
#detail-frame::before {
content: "";
position: absolute;
inset: 0;
border: 4px solid rgba(250, 247, 238, 0.9);
pointer-events: none;
}
.detail-caption {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 8px 10px 7px;
background: rgba(250, 247, 238, 0.91);
color: var(--ink);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.detail-caption strong {
float: right;
color: var(--accent);
}
.corner-mark {
position: absolute;
top: 9px;
left: 10px;
z-index: 2;
padding: 4px 6px;
border-radius: 2px;
background: rgba(250, 247, 238, 0.85);
color: var(--accent);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
@media (max-width: 700px) {
.title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 14px;
}
.subtitle {
display: none;
}
.chips {
margin-top: 8px;
}
.help {
left: 12px;
bottom: 12px;
max-width: calc(100vw - 24px);
}
.help .desktop-help {
display: none;
}
#detail-frame {
right: 12px;
bottom: 62px;
width: 230px;
height: 144px;
}
}
</style>
</head>
<body>
<header class="title-card">
<div class="eyebrow">Brazil · Low-poly architectural study</div>
<h1>Paraty Historic Waterfront</h1>
<div class="subtitle">
A compact street-tile interpretation of irregular granite paving,
a colonial façade, and the small elevation change at a raised doorway.
</div>
<div class="chips">
<span class="chip">Irregular stone paving</span>
<span class="chip">Raised doorway</span>
<span class="chip accent">+12 cm threshold</span>
</div>
</header>
<div class="help">
<button id="reset" type="button">Reset view</button>
<span class="desktop-help"><kbd>Drag</kbd> orbit</span>
<span class="desktop-help"><kbd>Scroll</kbd> zoom</span>
<span class="desktop-help"><kbd>← ↑ ↓ →</kbd> pan</span>
</div>
<aside id="detail-frame">
<span class="corner-mark">Detail view</span>
<div class="detail-caption">
Doorway threshold / street datum
<strong>+12 cm</strong>
</div>
</aside>
<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 renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.13;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8e5);
scene.fog = new THREE.Fog(0xdbe8e5, 22, 54);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.05,
100
);
const detailCamera = new THREE.PerspectiveCamera(34, 310 / 194, 0.02, 60);
detailCamera.position.set(2.55, 0.82, 0.02);
detailCamera.lookAt(0.34, 0.13, -1.78);
const hemisphere = new THREE.HemisphereLight(0xeaf5f2, 0x776954, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6bd, 3.2);
sun.position.set(-8, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.0002;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d5df, 0.55);
fill.position.set(9, 5, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const mat = {
plaster: new THREE.MeshStandardMaterial({
color: 0xd9b77e,
roughness: 0.92,
flatShading: true
}),
plasterLight: new THREE.MeshStandardMaterial({
color: 0xe8d3a7,
roughness: 0.94,
flatShading: true
}),
trim: new THREE.MeshStandardMaterial({
color: 0xefe2c5,
roughness: 0.86,
flatShading: true
}),
roof: new THREE.MeshStandardMaterial({
color: 0xa64f2f,
roughness: 0.91,
flatShading: true
}),
roofDark: new THREE.MeshStandardMaterial({
color: 0x743725,
roughness: 0.95,
flatShading: true
}),
wood: new THREE.MeshStandardMaterial({
color: 0x68432d,
roughness: 0.88,
flatShading: true
}),
darkWood: new THREE.MeshStandardMaterial({
color: 0x382b24,
roughness: 0.94,
flatShading: true
}),
door: new THREE.MeshStandardMaterial({
color: 0x315c53,
roughness: 0.76,
flatShading: true
}),
iron: new THREE.MeshStandardMaterial({
color: 0x252c2b,
roughness: 0.6,
metalness: 0.48,
flatShading: true
}),
threshold: new THREE.MeshStandardMaterial({
color: 0xb8ad92,
roughness: 0.95,
flatShading: true
}),
wallStone: new THREE.MeshStandardMaterial({
color: 0x8c8778,
roughness: 0.98,
flatShading: true
}),
soil: new THREE.MeshStandardMaterial({
color: 0x4b4940,
roughness: 1,
flatShading: true
}),
base: new THREE.MeshStandardMaterial({
color: 0x85745e,
roughness: 0.96,
flatShading: true
}),
terracotta: new THREE.MeshStandardMaterial({
color: 0xa95e37,
roughness: 0.94,
flatShading: true
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x4f7045,
roughness: 0.96,
flatShading: true
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x718457,
roughness: 0.96,
flatShading: true
}),
skin: new THREE.MeshStandardMaterial({
color: 0xa86f4e,
roughness: 0.95,
flatShading: true
}),
blue: new THREE.MeshStandardMaterial({
color: 0x547d8d,
roughness: 0.9,
flatShading: true
})
};
function addMesh(geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
function addBox(w, h, d, x, y, z, material) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material,
x,
y,
z
);
}
// -------------------------------------------------------------------------
// Diorama base and dark paving bed
// -------------------------------------------------------------------------
addBox(14.4, 0.5, 10.3, 0, -0.36, -0.7, mat.base);
addBox(13.75, 0.08, 6.25, 0, -0.055, 1.02, mat.soil);
// -------------------------------------------------------------------------
// Irregular low-poly paving stones
// -------------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function createIrregularStone(width, depth, height, random) {
const sides = 7;
const points = [];
for (let i = 0; i < sides; i++) {
const angle = (i / sides) * Math.PI * 2 + (random() - 0.5) * 0.13;
const radiusX = width * (0.43 + random() * 0.09);
const radiusZ = depth * (0.43 + random() * 0.09);
points.push(
new THREE.Vector2(
Math.cos(angle) * radiusX,
Math.sin(angle) * radiusZ
)
);
}
const positions = [];
// Top center.
positions.push(0, height, 0);
// Top triangles; reversed in XZ to face upward.
for (let i = 0; i < sides; i++) {
const current = points[i];
const next = points[(i + 1) % sides];
positions.push(0, height, 0);
positions.push(next.x, height, next.y);
positions.push(current.x, height, current.y);
}
// Bottom center and downward-facing bottom triangles.
positions.push(0, 0, 0);
for (let i = 0; i < sides; i++) {
const current = points[i];
const next = points[(i + 1) % sides];
positions.push(0, 0, 0);
positions.push(current.x, 0, current.y);
positions.push(next.x, 0, next.y);
}
// Outward-facing side walls.
for (let i = 0; i < sides; i++) {
const current = points[i];
const next = points[(i + 1) % sides];
positions.push(
current.x, height, current.y,
next.x, height, next.y,
next.x, 0, next.y
);
positions.push(
current.x, height, current.y,
next.x, 0, next.y,
current.x, 0, current.y
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.computeVertexNormals();
return geometry;
}
const pavingColors = [
0x8d8b80,
0x999486,
0x7e817a,
0xa39b87,
0x89867c,
0xb0a58e,
0x777a75
];
const stoneMaterials = pavingColors.map(
(color) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.97,
flatShading: true
})
);
const pavingRandom = seededRandom(9173);
let stoneIndex = 0;
for (let row = 0; row < 11; row++) {
const z = -1.78 + row * 0.54;
const rowOffset = row % 2 === 0 ? 0 : 0.29;
for (let col = 0; col < 23; col++) {
const x = -6.65 + col * 0.59 + rowOffset;
if (x > 6.8) continue;
const height = 0.064 + pavingRandom() * 0.024;
const geometry = createIrregularStone(
0.57 + pavingRandom() * 0.055,
0.51 + pavingRandom() * 0.045,
height,
pavingRandom
);
const stone = new THREE.Mesh(
geometry,
stoneMaterials[stoneIndex++ % stoneMaterials.length]
);
stone.position.set(x, -0.026, z);
stone.rotation.y = (pavingRandom() - 0.5) * 0.17;
stone.receiveShadow = true;
scene.add(stone);
}
}
// -------------------------------------------------------------------------
// Colonial building, assembled around a genuine doorway opening
// -------------------------------------------------------------------------
const wallLeft = -6.2;
const wallRight = 1.75;
const doorLeft = -0.25;
const doorRight = 0.95;
const facadeZ = -2.25;
const wallTop = 3.55;
// Side and rear walls.
addBox(
0.28,
wallTop,
3.65,
wallLeft,
wallTop / 2,
-4.02,
mat.plaster
);
addBox(
0.28,
wallTop,
3.65,
wallRight,
wallTop / 2,
-4.02,
mat.plasterLight
);
addBox(
wallRight - wallLeft,
wallTop,
0.28,
(wallLeft + wallRight) / 2,
wallTop / 2,
-5.78,
mat.plaster
);
// Front wall in three pieces, leaving the doorway open.
addBox(
doorLeft - wallLeft,
wallTop,
0.28,
(wallLeft + doorLeft) / 2,
wallTop / 2,
facadeZ,
mat.plaster
);
addBox(
wallRight - doorRight,
wallTop,
0.28,
(wallRight + doorRight) / 2,
wallTop / 2,
facadeZ,
mat.plasterLight
);
addBox(
doorRight - doorLeft,
wallTop - 2.5,
0.28,
(doorLeft + doorRight) / 2,
(wallTop + 2.5) / 2,
facadeZ,
mat.plaster
);
// Stone foundation at the base of the facade.
addBox(
doorLeft - wallLeft,
0.23,
0.34,
(wallLeft + doorLeft) / 2,
0.1,
facadeZ + 0.025,
mat.threshold
);
addBox(
wallRight - doorRight,
0.23,
0.34,
(wallRight + doorRight) / 2,
0.1,
facadeZ + 0.025,
mat.threshold
);
// Door recess and recessed wooden door.
addBox(
doorRight - doorLeft,
2.36,
0.12,
(doorLeft + doorRight) / 2,
1.35,
-2.37,
mat.darkWood
);
const door = addBox(
0.96,
2.18,
0.09,
0.35,
1.26,
-2.285,
mat.door
);
door.castShadow = false;
// Door panels.
for (const y of [0.72, 1.64]) {
addBox(0.66, 0.67, 0.035, 0.35, y, -2.225, mat.wood);
addBox(0.49, 0.49, 0.025, 0.35, y, -2.2, mat.door);
}
// Door frame.
addBox(0.13, 2.43, 0.18, -0.285, 1.355, -2.08, mat.trim);
addBox(0.13, 2.43, 0.18, 0.985, 1.355, -2.08, mat.trim);
addBox(1.4, 0.15, 0.19, 0.35, 2.5, -2.075, mat.trim);
// Small blue ceramic plaque.
addBox(
0.18,
0.24,
0.055,
1.13,
1.72,
-2.075,
new THREE.MeshStandardMaterial({
color: 0x5d8994,
roughness: 0.7,
flatShading: true
})
);
// Handle.
const handle = addMesh(
new THREE.SphereGeometry(0.045, 8, 6),
mat.iron,
0.72,
1.12,
-2.17
);
handle.scale.z = 0.5;
// -------------------------------------------------------------------------
// Raised threshold: average street top = 0.05, threshold top = 0.17
// -------------------------------------------------------------------------
const threshold = addBox(
1.48,
0.17,
0.76,
0.35,
0.085,
-1.94,
mat.threshold
);
threshold.castShadow = true;
// A worn top edge makes the elevation change easier to read.
addBox(
1.37,
0.018,
0.61,
0.35,
0.176,
-1.92,
new THREE.MeshStandardMaterial({
color: 0xc8bda1,
roughness: 0.94,
flatShading: true
})
);
// -------------------------------------------------------------------------
// Windows and shutters
// -------------------------------------------------------------------------
function addWindow(x, y, width = 1.16, height = 1.4) {
// Recess.
addBox(
width,
height,
0.08,
x,
y,
-2.085,
mat.darkWood
);
// White or stone surround.
addBox(width + 0.24, 0.12, 0.18, x, y + height / 2 + 0.05, -2.04, mat.trim);
addBox(width + 0.24, 0.11, 0.18, x, y - height / 2 - 0.04, -2.04, mat.trim);
addBox(0.12, height + 0.15, 0.18, x - width / 2 - 0.06, y, -2.04, mat.trim);
addBox(0.12, height + 0.15, 0.18, x + width / 2 + 0.06, y, -2.04, mat.trim);
// Wooden shutter panels.
const shutterWidth = width * 0.39;
addBox(shutterWidth, height, 0.1, x - width * 0.31, y, -1.995, mat.blue);
addBox(shutterWidth, height, 0.1, x + width * 0.31, y, -1.995, mat.blue);
// Central mullion.
addBox(0.065, height, 0.13, x, y, -1.965, mat.wood);
// Crossbars.
addBox(width * 0.9, 0.045, 0.1, x, y, -1.925, mat.wood);
addBox(width * 0.9, 0.045, 0.1, x, y + height * 0.18, -1.925, mat.wood);
addBox(width * 0.9, 0.045, 0.1, x, y - height * 0.18, -1.925, mat.wood);
}
addWindow(-4.55, 1.73, 1.3, 1.48);
addWindow(-2.45, 1.73, 1.16, 1.4);
addWindow(-0.78, 1.8, 0.78, 1.22);
// Small iron balcony above the doorway.
addBox(1.85, 0.08, 0.52, 0.35, 2.7, -1.84, mat.iron);
for (let i = 0; i < 9; i++) {
addBox(
0.035,
0.56,
0.035,
-0.47 + i * 0.205,
2.99,
-1.62,
mat.iron
);
}
addBox(1.85, 0.045, 0.045, 0.35, 3.25, -1.62, mat.iron);
addBox(1.85, 0.035, 0.035, 0.35, 2.91, -1.62, mat.iron);
// -------------------------------------------------------------------------
// Low-poly tiled roof
// -------------------------------------------------------------------------
const roofLength = 8.45;
const roofSlope = Math.atan2(0.52, 1.93);
const frontRoof = addBox(
roofLength,
0.13,
2.02,
-2.2,
3.82,
-2.97,
mat.roof
);
frontRoof.rotation.x = roofSlope;
const backRoof = addBox(
roofLength,
0.13,
2.02,
-2.2,
3.82,
-4.83,
mat.roof
);
backRoof.rotation.x = -roofSlope;
// Tile seams.
for (let i = 0; i < 17; i++) {
const x = -6.2 + i * 0.48;
const seamA = addBox(
0.035,
0.026,
1.94,
x,
3.91,
-2.97,
mat.roofDark
);
seamA.rotation.x = roofSlope;
const seamB = addBox(
0.035,
0.026,
1.94,
x,
3.91,
-4.83,
mat.roofDark
);
seamB.rotation.x = -roofSlope;
}
const ridge = addMesh(
new THREE.CylinderGeometry(0.12, 0.12, roofLength + 0.15, 8),
mat.roofDark,
-2.2,
4.09,
-3.9
);
ridge.rotation.z = Math.PI / 2;
// -------------------------------------------------------------------------
// Slight plaster weathering as flat polygon patches
// -------------------------------------------------------------------------
function addPlasterPatch(points, x, y, color, opacity = 0.25) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], points[i][1]);
}
shape.closePath();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 1,
transparent: true,
opacity,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -1
});
const patch = new THREE.Mesh(new THREE.ShapeGeometry(shape), material);
patch.position.set(x, y, -2.095);
scene.add(patch);
}
addPlasterPatch(
[[0, 0], [0.5, 0.08], [0.7, 0.43], [0.25, 0.72], [-0.08, 0.34]],
-5.65,
2.65,
0xb77e50,
0.19
);
addPlasterPatch(
[[0, 0], [0.38, 0.12], [0.5, 0.6], [0.06, 0.82], [-0.12, 0.3]],
-1.72,
0.38,
0xc48d5b,
0.13
);
// -------------------------------------------------------------------------
// Facade sign generated locally with Canvas
// -------------------------------------------------------------------------
function createFacadeSign() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const context = canvas.getContext("2d");
context.fillStyle = "#e8d7b6";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#745b42";
context.lineWidth = 9;
context.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
context.fillStyle = "#514235";
context.textAlign = "center";
context.textBaseline = "middle";
context.font = "600 66px Georgia";
context.fillText("CAIS DO PORTO", canvas.width / 2, 96);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.9,
flatShading: true
});
const sign = new THREE.Mesh(new THREE.PlaneGeometry(2.15, 0.54), material);
sign.position.set(-3.45, 2.92, -2.065);
scene.add(sign);
}
createFacadeSign();
// -------------------------------------------------------------------------
// Waterfront wall and coping
// -------------------------------------------------------------------------
const wallRandom = seededRandom(421);
const wallMaterials = [
mat.wallStone,
new THREE.MeshStandardMaterial({
color: 0x969182,
roughness: 0.98,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x7e7c72,
roughness: 0.98,
flatShading: true
})
];
for (let i = 0; i < 15; i++) {
const width = 0.94 + wallRandom() * 0.035;
const x = -6.98 + i * 0.965;
addBox(
width,
0.51 + wallRandom() * 0.035,
0.42,
x,
0.005,
4.2,
wallMaterials[i % wallMaterials.length]
);
addBox(
width + 0.025,
0.12,
0.52,
x,
0.305,
4.2,
i % 3 === 0 ? mat.threshold : mat.wallStone
);
}
// -------------------------------------------------------------------------
// Faceted water
// -------------------------------------------------------------------------
const waterGeometry = new THREE.PlaneGeometry(18, 9, 18, 9);
waterGeometry.rotateX(-Math.PI / 2);
let facetedWater = waterGeometry.toNonIndexed();
const waterPosition = facetedWater.attributes.position;
const waterColors = [];
const waterPalette = [
new THREE.Color(0x6f9d9c),
new THREE.Color(0x78a7a4),
new THREE.Color(0x639391),
new THREE.Color(0x84ada6)
];
for (let i = 0; i < waterPosition.count; i += 3) {
const color = waterPalette[Math.floor(Math.random() * waterPalette.length)];
for (let j = 0; j < 3; j++) {
const x = waterPosition.getX(i + j);
const z = waterPosition.getZ(i + j);
const wave =
Math.sin(x * 0.8 + z * 0.55) * 0.025 +
Math.cos(z * 1.15 - x * 0.25) * 0.018;
waterPosition.setY(i + j, -0.37 + wave);
waterColors.push(color.r, color.g, color.b);
}
}
facetedWater.setAttribute(
"color",
new THREE.Float32BufferAttribute(waterColors, 3)
);
facetedWater.computeVertexNormals();
const waterMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.46,
metalness: 0.04,
flatShading: true
});
const water = new THREE.Mesh(facetedWater, waterMaterial);
water.position.z = 8.6;
water.receiveShadow = true;
scene.add(water);
// Distant faceted shoreline.
const hillMaterials = [
new THREE.MeshStandardMaterial({
color: 0x667c62,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x7c8c69,
roughness: 1,
flatShading: true
})
];
[
[-7.8, 15.4, 3.6, 1.3],
[-2.5, 17.2, 4.5, 1.6],
[5.4, 16.1, 4.1, 1.35],
[10.4, 18.1, 5.1, 1.8]
].forEach(([x, z, sx, sy], index) => {
const hill = addMesh(
new THREE.IcosahedronGeometry(1, 1),
hillMaterials[index % 2],
x,
-0.1,
z
);
hill.scale.set(sx, sy, sx * 0.6);
hill.castShadow = false;
});
// -------------------------------------------------------------------------
// Low-poly boats
// -------------------------------------------------------------------------
function createBoat(x, z, color, scale = 1, rotation = 0) {
const group = new THREE.Group();
const hullMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
flatShading: true
});
const top = [
[0, 0.22, -1.45],
[-0.63, 0.22, 0.62],
[-0.43, 0.22, 1.02],
[0.43, 0.22, 1.02],
[0.63, 0.22, 0.62]
];
const positions = [];
for (let i = 0; i < top.length; i++) {
const next = (i + 1) % top.length;
const a = top[i];
const b = top[next];
const ax = a[0] * 0.55;
const az = a[2] * 0.55;
const bx = b[0] * 0.55;
const bz = b[2] * 0.55;
positions.push(
a[0], a[1], a[2],
b[0], b[1], b[2],
bx, -0.2, bz
);
positions.push(
a[0], a[1], a[2],
bx, -0.2, bz,
ax, -0.2, az
);
}
const hullGeometry = new THREE.BufferGeometry();
hullGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
hullGeometry.computeVertexNormals();
const hull = new THREE.Mesh(hullGeometry, hullMaterial);
hull.castShadow = true;
group.add(hull);
const deck = addBox(0.78, 0.06, 1.18, 0, 0.23, 0.15, mat.wood);
deck.castShadow = true;
group.add(deck);
const mast = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.045, 2.8, 6),
mat.wood
);
mast.position.set(0, 1.38, -0.15);
mast.castShadow = true;
group.add(mast);
const sailGeometry = new THREE.BufferGeometry();
sailGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0.04, 2.65, -0.14,
0.04, 0.4, -0.14,
1.25, 0.48, -0.14
],
3
)
);
sailGeometry.computeVertexNormals();
const sailMaterial = new THREE.MeshStandardMaterial({
color: 0xe8dfc8,
roughness: 0.92,
side: THREE.DoubleSide,
flatShading: true
});
const sail = new THREE.Mesh(sailGeometry, sailMaterial);
sail.castShadow = true;
group.add(sail);
group.position.set(x, -0.25, z);
group.rotation.y = rotation;
group.scale.setScalar(scale);
scene.add(group);
}
createBoat(3.05, 6.45, 0xb44f32, 0.82, -0.24);
createBoat(5.75, 8.2, 0xd5b34f, 0.66, 0.38);
// -------------------------------------------------------------------------
// Street lamps and plants
// -------------------------------------------------------------------------
function addLamp(x, z) {
const group = new THREE.Group();
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.22, 0.2, 8),
mat.iron
);
base.position.y = 0.1;
group.add(base);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 2.45, 7),
mat.iron
);
pole.position.y = 1.38;
pole.castShadow = true;
group.add(pole);
const lanternMaterial = new THREE.MeshStandardMaterial({
color: 0xf1d38c,
emissive: 0x7b4a12,
emissiveIntensity: 0.32,
roughness: 0.6,
flatShading: true
});
const lantern = new THREE.Mesh(
new THREE.CylinderGeometry(0.15, 0.19, 0.35, 6),
lanternMaterial
);
lantern.position.y = 2.7;
lantern.castShadow = true;
group.add(lantern);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.24, 0.18, 6),
mat.iron
);
cap.position.y = 2.95;
group.add(cap);
group.position.set(x, 0.05, z);
scene.add(group);
}
addLamp(4.55, 3.45);
addLamp(-5.85, 3.45);
function addPlant(x, z) {
const pot = addMesh(
new THREE.CylinderGeometry(0.23, 0.17, 0.34, 7),
mat.terracotta,
x,
0.17,
z
);
pot.castShadow = true;
const leafGeometry = new THREE.ConeGeometry(0.16, 0.63, 5);
const positions = [
[-0.15, 0.6, 0, -0.2],
[0.15, 0.58, 0.03, 0.2],
[0.02, 0.67, -0.1, 0.02],
[-0.02, 0.55, 0.14, -0.12]
];
positions.forEach(([lx, ly, lz, rotation], index) => {
const leaf = new THREE.Mesh(
leafGeometry,
index % 2 ? mat.leaf : mat.leafLight
);
leaf.position.set(x + lx, ly, z + lz);
leaf.rotation.z = rotation;
leaf.castShadow = true;
scene.add(leaf);
});
}
addPlant(-0.86, -1.4);
addPlant(1.52, -1.52);
addPlant(5.75, 3.1);
// -------------------------------------------------------------------------
// Simple low-poly pedestrian for scale
// -------------------------------------------------------------------------
function addPerson(x, z, rotation = 0) {
const group = new THREE.Group();
const shirt = new THREE.MeshStandardMaterial({
color: 0x5d8390,
roughness: 0.94,
flatShading: true
});
const trousers = new THREE.MeshStandardMaterial({
color: 0x3e4946,
roughness: 0.96,
flatShading: true
});
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.23, 0.65, 7),
shirt
);
torso.position.y = 1.02;
torso.castShadow = true;
group.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.145, 8, 6),
mat.skin
);
head.position.y = 1.51;
head.castShadow = true;
group.add(head);
const hat = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.24, 0.045, 8),
mat.wood
);
hat.position.y = 1.64;
group.add(hat);
const hatTop = new THREE.Mesh(
new THREE.CylinderGeometry(0.14, 0.16, 0.13, 8),
mat.wood
);
hatTop.position.y = 1.71;
group.add(hatTop);
for (const side of [-1, 1]) {
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.075, 0.72, 6),
trousers
);
leg.position.set(side * 0.105, 0.4, 0);
leg.castShadow = true;
group.add(leg);
const arm = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 0.58, 6),
shirt
);
arm.position.set(side * 0.245, 1.03, 0);
arm.rotation.z = side * 0.12;
arm.castShadow = true;
group.add(arm);
}
group.position.set(x, 0.05, z);
group.rotation.y = rotation;
scene.add(group);
}
addPerson(2.18, 2.22, -0.35);
// -------------------------------------------------------------------------
// Threshold measurement marker
// -------------------------------------------------------------------------
const measureMaterial = new THREE.LineBasicMaterial({
color: 0xb65d2c,
depthTest: false,
transparent: true,
opacity: 0.95
});
const measurePoints = [
new THREE.Vector3(1.25, 0.05, -1.34),
new THREE.Vector3(1.25, 0.17, -1.34),
new THREE.Vector3(1.15, 0.05, -1.34),
new THREE.Vector3(1.15, 0.17, -1.34),
new THREE.Vector3(1.35, 0.05, -1.34),
new THREE.Vector3(1.35, 0.17, -1.34)
];
const measureGeometry = new THREE.BufferGeometry().setFromPoints(measurePoints);
const measureLines = new THREE.LineSegments(measureGeometry, measureMaterial);
measureLines.renderOrder = 20;
scene.add(measureLines);
function createTextSprite(text) {
const canvas = document.createElement("canvas");
canvas.width = 320;
canvas.height = 104;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(250,247,238,0.95)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = "#b65d2c";
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = "#98491f";
context.font = "700 43px Arial";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.05, 0.34, 1);
sprite.position.set(1.55, 0.29, -1.22);
sprite.renderOrder = 21;
scene.add(sprite);
}
createTextSprite("12 cm");
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, keyboard pan, touch pinch
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(-0.25, 1.05, -1.25),
radius: 13.8,
theta: 0.61,
phi: 1.12,
panSpeed: 0.018
};
const defaultControls = {
target: controls.target.clone(),
radius: controls.radius,
theta: controls.theta,
phi: controls.phi
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * Math.cos(controls.phi),
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetCamera() {
controls.target.copy(defaultControls.target);
controls.radius = defaultControls.radius;
controls.theta = defaultControls.theta;
controls.phi = defaultControls.phi;
updateCamera();
}
updateCamera();
const pointers = new Map();
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.34,
1.46
);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
controls.radius = THREE.MathUtils.clamp(
controls.radius * (lastPinchDistance / distance),
6.2,
24
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
6.2,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
const step = controls.panSpeed;
if (event.key === "ArrowLeft") {
controls.target.x -= step;
} else if (event.key === "ArrowRight") {
controls.target.x += step;
} else if (event.key === "ArrowUp") {
controls.target.z -= step;
} else if (event.key === "ArrowDown") {
controls.target.z += step;
} else {
return;
}
controls.target.x = THREE.MathUtils.clamp(controls.target.x, -5, 5);
controls.target.z = THREE.MathUtils.clamp(controls.target.z, -4, 4);
updateCamera();
});
// -------------------------------------------------------------------------
// Resize and render, including the detail inset
// -------------------------------------------------------------------------
const detailFrame = document.getElementById("detail-frame");
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
const rect = detailFrame.getBoundingClientRect();
detailCamera.aspect = rect.width / rect.height;
detailCamera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function render() {
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
renderer.render(scene, camera);
const rect = detailFrame.getBoundingClientRect();
const x = rect.left;
const y = window.innerHeight - rect.bottom;
renderer.setScissorTest(true);
renderer.setScissor(x, y, rect.width, rect.height);
renderer.setViewport(x, y, rect.width, rect.height);
renderer.render(scene, detailCamera);
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
requestAnimationFrame(render);
}
render();
</script>
</body>
</html>
```