Prompt specification
Build or customize the Three.js 3D scene "Hội An timber shopfront and river-step fragment" 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: Hội An timber shopfront and river-step fragment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/h-i-an-timber-shopfront-and-river-step-fragment-x2981
Scene Description Prompt:
A voxel Hội An timber shopfront beside riverside steps, with its raised interior above the quay. Build standalone HTML using Three.js from cdnjs.
Working Three.js Starter (h-i-an-timber-shopfront-and-river-step-fragment-x2981):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hội An — Riverside Timber Shopfront</title>
<style>
:root {
color-scheme: light;
--ink: #38271f;
--paper: rgba(255, 247, 226, 0.92);
--accent: #a8492e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8c8a8;
font-family: Inter, "Segoe UI", Arial, sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#hud {
position: fixed;
top: 18px;
left: 18px;
z-index: 2;
width: min(340px, calc(100vw - 36px));
padding: 15px 17px;
color: var(--ink);
background: var(--paper);
border: 1px solid rgba(56, 39, 31, 0.18);
border-radius: 12px;
box-shadow: 0 10px 35px rgba(58, 42, 28, 0.18);
backdrop-filter: blur(9px);
pointer-events: none;
}
#hud h1 {
margin: 0 0 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 600;
letter-spacing: 0.03em;
}
#hud p {
margin: 0;
font-size: 12px;
line-height: 1.5;
opacity: 0.76;
}
#controls {
display: flex;
align-items: center;
gap: 10px;
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid rgba(56, 39, 31, 0.12);
pointer-events: auto;
}
#reset {
appearance: none;
border: 0;
border-radius: 7px;
padding: 7px 11px;
color: #fff7e8;
background: var(--accent);
font: inherit;
font-size: 12px;
font-weight: 650;
cursor: pointer;
box-shadow: 0 3px 10px rgba(168, 73, 46, 0.22);
}
#reset:hover {
background: #8e3d27;
}
#hint {
font-size: 11px;
opacity: 0.68;
}
#badge {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 2;
padding: 8px 11px;
color: #fff7e8;
background: rgba(56, 39, 31, 0.78);
border-radius: 8px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 600px) {
#hud {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
#hud h1 {
font-size: 21px;
}
#badge {
right: 10px;
bottom: 10px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D Hội An riverside shopfront"></canvas>
<div id="hud">
<h1>Hội An</h1>
<p>A voxel timber shopfront raised above the stone quay, with lantern light, roof tiles, river steps, and a small wooden boat.</p>
<div id="controls">
<button id="reset" type="button">Reset view</button>
<span id="hint">Drag to orbit · Wheel to zoom</span>
</div>
</div>
<div id="badge">Riverside / Quang Nam</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const resetButton = document.querySelector("#reset");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd7c7a8);
scene.fog = new THREE.Fog(0xd7c7a8, 27, 62);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const world = new THREE.Group();
scene.add(world);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const material = (color, roughness = 0.8, extra = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness,
...extra
});
const mats = {
plaster: material(0xd5a85f, 0.92),
plasterLight: material(0xe1bd78, 0.9),
plasterShade: material(0xd8ac70, 0.94),
wood: material(0x70422a, 0.82),
woodDark: material(0x3b281f, 0.88),
woodMid: material(0x855137, 0.82),
woodLight: material(0x9a6740, 0.8),
roofA: material(0xa74d2e, 0.86),
roofB: material(0xb85c35, 0.84),
roofC: material(0x923d29, 0.9),
roofD: material(0xc06b3d, 0.86),
stone: material(0x8e8879, 0.95),
stoneLight: material(0xaaa18c, 0.94),
stoneDark: material(0x706c63, 0.98),
stoneWarm: material(0x9d8f78, 0.95),
interior: material(0x30241d, 0.98),
red: material(0x9e3026, 0.62),
gold: material(0xc69a45, 0.5, { metalness: 0.12 }),
green: material(0x4e6b36, 0.94),
greenLight: material(0x71854a, 0.92),
ceramic: material(0x416d68, 0.7),
ceramicLight: material(0x789b88, 0.72),
cloth: material(0xc6a35e, 0.96),
water: material(0x477f83, 0.3, { metalness: 0.08 }),
ripple: new THREE.MeshBasicMaterial({
color: 0xc8ded2,
transparent: true,
opacity: 0.22,
depthWrite: false
})
};
// A small helper keeps the voxel construction readable.
function box(
width,
height,
depth,
mat,
x = 0,
y = 0,
z = 0,
parent = world,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffe5b8,
0x61736a,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0a3, 3.4);
sun.position.set(-9, 16, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -20;
sun.shadow.camera.right = 20;
sun.shadow.camera.top = 18;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 50;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bc3c7, 0.7);
fill.position.set(10, 7, -8);
scene.add(fill);
// ---------------------------------------------------------------------
// River and stone quay
// ---------------------------------------------------------------------
box(
70,
0.16,
70,
mats.water,
0,
-1.36,
18,
world,
false,
true
);
// Main quay body.
box(38, 1.3, 12.2, mats.stone, 0, -0.65, 0);
// Individual paving slabs.
const pavingMaterials = [
mats.stoneLight,
mats.stoneWarm,
mats.stone,
mats.stoneDark
];
for (let ix = -6; ix <= 6; ix++) {
for (let iz = -3; iz <= 3; iz++) {
const mat = pavingMaterials[
Math.abs(ix * 3 + iz * 5) % pavingMaterials.length
];
box(
2.88,
0.08,
1.82,
mat,
ix * 2.9,
0.04,
iz * 1.72,
world,
false,
true
);
}
}
// Quay retaining wall, with an opening for the riverside staircase.
function retainingWallSection(startX, endX) {
const blockWidth = 2.25;
const count = Math.ceil((endX - startX) / blockWidth);
for (let row = 0; row < 2; row++) {
for (let i = 0; i < count; i++) {
const x = startX + blockWidth * (i + 0.5);
const y = -0.28 - row * 0.55;
const mat = (i + row) % 3 === 0
? mats.stoneDark
: (i + row) % 2 === 0
? mats.stoneWarm
: mats.stone;
box(
blockWidth - 0.08,
0.5,
0.48,
mat,
x,
y,
6.02,
world,
false,
true
);
}
}
}
retainingWallSection(-17, 5.05);
retainingWallSection(9.55, 17);
// Broad stone stairs descending into the river.
for (let i = 0; i < 6; i++) {
const top = -i * 0.2;
const bottom = -1.25;
const height = top - bottom;
const z = 6.22 + i * 0.5;
const mat = i % 2 === 0 ? mats.stoneLight : mats.stoneWarm;
box(
4.25,
height,
0.53,
mat,
7.3,
top - height / 2,
z,
world,
false,
true
);
// Low stepped side cheeks.
box(
0.34,
height + 0.12,
0.55,
mats.stoneDark,
5.03,
top - height / 2 + 0.06,
z
);
box(
0.34,
height + 0.12,
0.55,
mats.stoneDark,
9.57,
top - height / 2 + 0.06,
z
);
}
// Subtle voxel water ripples.
const ripples = [];
for (let i = 0; i < 48; i++) {
const x = -18 + ((i * 7.13) % 36);
const z = 7.2 + ((i * 3.71) % 14);
const width = 0.55 + (i % 4) * 0.23;
const ripple = box(
width,
0.012,
0.075 + (i % 3) * 0.025,
mats.ripple,
x,
-1.267,
z,
world,
false,
false
);
ripple.userData.baseX = x;
ripple.userData.phase = i * 0.73;
ripples.push(ripple);
}
// ---------------------------------------------------------------------
// Raised shopfront structure
// ---------------------------------------------------------------------
// Raised stone foundation.
box(
11,
1.35,
5.85,
mats.stoneDark,
-1,
0.675,
-2.62
);
// Warm stone entrance steps.
for (let i = 0; i < 5; i++) {
const top = 1.35 - i * 0.3;
const bottom = 0.08;
const height = top - bottom;
box(
7.55,
height,
0.49,
i % 2 === 0 ? mats.stoneLight : mats.stoneWarm,
-0.72,
bottom + height / 2,
0.36 + i * 0.44,
world,
false,
true
);
}
const floorTop = 1.35;
const wallTop = 5.8;
// Back and side plaster walls.
box(
11,
wallTop - floorTop,
0.36,
mats.plaster,
-1,
(wallTop + floorTop) / 2,
-5.36
);
box(
0.36,
wallTop - floorTop,
5.85,
mats.plaster,
-6.32,
(wallTop + floorTop) / 2,
-2.58
);
box(
0.36,
wallTop - floorTop,
5.85,
mats.plasterLight,
4.32,
(wallTop + floorTop) / 2,
-2.58
);
// Front plaster piers surrounding the open shop.
box(
2.45,
wallTop - floorTop,
0.38,
mats.plasterLight,
-4.98,
(wallTop + floorTop) / 2,
0.34
);
box(
1.85,
wallTop - floorTop,
0.38,
mats.plaster,
3.3,
(wallTop + floorTop) / 2,
0.34
);
// Dark timber interior.
box(
10.3,
4.25,
0.12,
mats.interior,
-1,
3.47,
-5.12,
world,
false,
true
);
// Interior floorboards.
for (let i = 0; i < 16; i++) {
box(
0.62,
0.09,
5.1,
i % 3 === 0 ? mats.woodDark : mats.wood,
-5.85 + i * 0.65,
1.4,
-2.48,
world,
false,
true
);
}
// Structural timber posts.
const postXs = [-6.1, -3.68, 2.27, 4.12];
for (const x of postXs) {
box(
0.31,
4.45,
0.34,
mats.woodDark,
x,
3.575,
0.51
);
box(
0.46,
0.18,
0.48,
mats.wood,
x,
1.48,
0.53
);
box(
0.46,
0.18,
0.48,
mats.wood,
x,
5.64,
0.53
);
}
// Heavy horizontal beams.
box(10.6, 0.33, 0.46, mats.woodDark, -1, 5.55, 0.55);
box(10.55, 0.2, 0.42, mats.wood, -1, 4.44, 0.53);
// Upper front panel.
box(
10.1,
0.73,
0.22,
mats.plasterShade,
-1,
5.05,
0.23
);
// ---------------------------------------------------------------------
// Shop sign
// ---------------------------------------------------------------------
box(
6.55,
0.78,
0.16,
mats.woodDark,
-0.71,
4.91,
0.52
);
function makeSignTexture() {
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 220;
const ctx = signCanvas.getContext("2d");
ctx.fillStyle = "#3b281f";
ctx.fillRect(0, 0, 1024, 220);
ctx.strokeStyle = "#b88a45";
ctx.lineWidth = 8;
ctx.strokeRect(18, 18, 988, 184);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#f1d99b";
ctx.font = '600 92px Georgia, "Times New Roman", serif';
ctx.fillText("HỘI AN", 512, 91);
ctx.fillStyle = "#d8b978";
ctx.font = '500 31px Arial, sans-serif';
ctx.fillText("SILK • TEA • RIVER HOUSE", 512, 160);
const texture = new THREE.CanvasTexture(signCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(6.25, 0.66),
new THREE.MeshBasicMaterial({
map: makeSignTexture(),
toneMapped: false
})
);
sign.position.set(-0.71, 4.91, 0.608);
world.add(sign);
// ---------------------------------------------------------------------
// Lattice windows and shutters
// ---------------------------------------------------------------------
function addLatticeWindow(x, width) {
const bottom = 2.02;
const height = 1.92;
const centerY = bottom + height / 2;
box(width, height, 0.13, mats.woodDark, x, centerY, 0.56);
const frame = 0.12;
box(width + frame, frame, 0.22, mats.wood, x, bottom, 0.67);
box(width + frame, frame, 0.22, mats.wood, x, bottom + height, 0.67);
box(frame, height, 0.22, mats.wood, x - width / 2, centerY, 0.67);
box(frame, height, 0.22, mats.wood, x + width / 2, centerY, 0.67);
const bars = 4;
for (let i = 1; i <= bars; i++) {
const barX = x - width / 2 + (width * i) / (bars + 1);
box(0.075, height - 0.12, 0.17, mats.woodMid, barX, centerY, 0.68);
}
for (let i = 1; i <= 3; i++) {
const barY = bottom + (height * i) / 4;
box(width - 0.12, 0.075, 0.17, mats.woodMid, x, barY, 0.68);
}
}
addLatticeWindow(-4.96, 1.55);
addLatticeWindow(3.3, 1.08);
// Side shutters folded open beside the windows.
box(0.28, 2.03, 0.16, mats.woodMid, -5.95, 2.98, 0.71);
box(0.28, 2.03, 0.16, mats.woodMid, -3.98, 2.98, 0.71);
box(0.24, 2.03, 0.16, mats.woodMid, 2.64, 2.98, 0.71);
box(0.24, 2.03, 0.16, mats.woodMid, 3.98, 2.98, 0.71);
// ---------------------------------------------------------------------
// Open timber shop doors
// ---------------------------------------------------------------------
function addOpenDoor(hingeX, direction, angle) {
const pivot = new THREE.Group();
pivot.position.set(hingeX, 1.42, 0.59);
pivot.rotation.y = angle;
world.add(pivot);
const door = box(
1.08,
2.82,
0.13,
mats.woodMid,
direction * 0.54,
1.41,
0,
pivot
);
for (let i = 0; i < 5; i++) {
box(
0.91,
0.055,
0.06,
mats.woodDark,
direction * 0.54,
0.45 + i * 0.47,
0.09,
pivot
);
}
box(
0.08,
0.08,
0.12,
mats.gold,
direction * 0.88,
1.35,
0.12,
pivot
);
return door;
}
addOpenDoor(-3.58, 1, 0.92);
addOpenDoor(2.2, -1, -0.92);
// ---------------------------------------------------------------------
// Shop interior: counter, shelves, pottery and textiles
// ---------------------------------------------------------------------
box(5.55, 0.18, 1.35, mats.wood, -0.72, 2.15, -2.72);
box(5.55, 0.75, 0.92, mats.woodDark, -0.72, 1.78, -2.66);
box(5.72, 0.13, 1.02, mats.woodLight, -0.72, 2.27, -2.66);
// Rear shelving.
const shelfYs = [2.47, 3.27, 4.07];
for (const y of shelfYs) {
box(8.4, 0.13, 0.55, mats.woodMid, -1.05, y, -4.76);
box(0.15, 3.2, 0.42, mats.woodDark, -5.18, 3.38, -4.78);
box(0.15, 3.2, 0.42, mats.woodDark, 3.08, 3.38, -4.78);
}
// Boxed goods.
const goods = [
[-4.4, 2.74, mats.cloth],
[-3.7, 2.76, mats.ceramic],
[-3.0, 2.73, mats.gold],
[-2.25, 2.75, mats.red],
[-0.7, 2.75, mats.ceramicLight],
[0.05, 2.74, mats.cloth],
[1.4, 2.75, mats.woodLight],
[-4.2, 3.55, mats.ceramicLight],
[-3.2, 3.57, mats.red],
[-1.3, 3.55, mats.gold],
[0.2, 3.56, mats.ceramic],
[1.45, 3.55, mats.cloth]
];
for (const [x, y, mat] of goods) {
box(
0.46 + (Math.abs(x) % 0.18),
0.42,
0.38,
mat,
x,
y,
-4.69
);
}
// Stacked ceramic vessels, assembled from blocks.
for (let i = 0; i < 5; i++) {
const x = -2.6 + i * 0.83;
box(0.42, 0.28, 0.4, mats.ceramic, x, 2.72, -3.55);
box(0.31, 0.19, 0.3, mats.ceramicLight, x, 2.95, -3.55);
box(0.37, 0.08, 0.35, mats.gold, x, 3.07, -3.55);
}
// Hanging cloth inside the shop.
box(0.82, 1.8, 0.08, mats.cloth, 0.85, 3.82, -4.52);
box(0.65, 1.58, 0.1, mats.red, 1.02, 3.76, -4.45);
// Warm interior illumination.
const interiorLight = new THREE.PointLight(
0xffad54,
18,
8,
2
);
interiorLight.position.set(-0.7, 4.2, -2.4);
world.add(interiorLight);
// ---------------------------------------------------------------------
// Stepped voxel tile roof
// ---------------------------------------------------------------------
const roofMaterials = [
mats.roofA,
mats.roofB,
mats.roofC,
mats.roofD
];
const roofRows = 9;
const roofColumns = 22;
for (let row = 0; row < roofRows; row++) {
const z = -5.62 + row * 0.75;
const y = 6.84 - Math.abs(row - 4) * 0.335;
for (let col = 0; col < roofColumns; col++) {
const x = -6.58 + (col + 0.5) * 0.56;
const mat = roofMaterials[
(col * 3 + row * 5) % roofMaterials.length
];
box(
0.545,
0.22,
0.79,
mat,
x,
y,
z
);
}
// Stepped plaster gables at both ends.
const gableHeight = Math.max(0.2, y - wallTop);
box(
0.38,
gableHeight,
0.79,
mats.plaster,
-6.34,
wallTop + gableHeight / 2,
z
);
box(
0.38,
gableHeight,
0.79,
mats.plasterLight,
4.34,
wallTop + gableHeight / 2,
z
);
}
// Ridge cap.
box(12.05, 0.22, 0.32, mats.roofC, -0.92, 7.02, -2.61);
box(12.05, 0.09, 0.45, mats.roofB, -0.92, 7.15, -2.61);
// Eaves.
box(12.2, 0.2, 0.3, mats.woodDark, -0.92, 5.48, 0.83);
box(12.2, 0.2, 0.3, mats.woodDark, -0.92, 5.48, -5.68);
// ---------------------------------------------------------------------
// Hanging lanterns
// ---------------------------------------------------------------------
const lanterns = [];
function addLantern(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 4.26, z);
group.scale.setScalar(scale);
world.add(group);
box(0.035, 0.9, 0.035, mats.woodDark, 0, 0.76, 0, group);
box(0.48, 0.62, 0.48, mats.red, 0, 0, 0, group);
box(0.52, 0.07, 0.52, mats.gold, 0, 0.26, 0, group);
box(0.52, 0.07, 0.52, mats.gold, 0, -0.26, 0, group);
box(0.15, 0.11, 0.15, mats.woodDark, 0, 0.36, 0, group);
box(0.08, 0.24, 0.08, mats.gold, 0, -0.44, 0, group);
group.userData.phase = lanterns.length * 1.4;
lanterns.push(group);
return group;
}
addLantern(-3.1, 0.98);
addLantern(1.7, 0.98);
addLantern(-6.0, -0.15, 0.86);
const lanternLight = new THREE.PointLight(
0xffa449,
12,
6,
2
);
lanternLight.position.set(-3.1, 4.1, 1.05);
world.add(lanternLight);
// ---------------------------------------------------------------------
// Plants, pots and small street details
// ---------------------------------------------------------------------
function addPlant(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0.1, z);
group.scale.setScalar(scale);
world.add(group);
box(0.55, 0.55, 0.55, mats.roofC, 0, 0.28, 0, group);
box(0.64, 0.11, 0.64, mats.roofB, 0, 0.58, 0, group);
box(0.08, 0.85, 0.08, mats.woodDark, 0, 0.98, 0, group);
box(0.45, 0.32, 0.43, mats.green, -0.18, 1.28, 0.03, group);
box(0.38, 0.3, 0.38, mats.greenLight, 0.2, 1.34, -0.02, group);
box(0.31, 0.25, 0.3, mats.green, 0.02, 1.58, 0.08, group);
box(0.25, 0.22, 0.26, mats.greenLight, -0.12, 1.71, 0.03, group);
}
addPlant(-6.95, 1.18, 1.05);
addPlant(4.95, 1.05, 0.9);
addPlant(-4.65, -4.85, 0.72);
// Small stool and basket near the entrance.
box(0.58, 0.12, 0.5, mats.woodLight, 3.25, 1.52, 1.25);
box(0.13, 0.52, 0.13, mats.woodDark, 3.05, 1.28, 1.1);
box(0.13, 0.52, 0.13, mats.woodDark, 3.45, 1.28, 1.1);
box(0.13, 0.52, 0.13, mats.woodDark, 3.05, 1.28, 1.4);
box(0.13, 0.52, 0.13, mats.woodDark, 3.45, 1.28, 1.4);
// ---------------------------------------------------------------------
// Wooden river boat
// ---------------------------------------------------------------------
const boat = new THREE.Group();
boat.position.set(-8.3, -1.02, 10.5);
boat.rotation.y = -0.13;
world.add(boat);
box(4.8, 0.3, 1.42, mats.woodDark, 0, 0, 0, boat);
box(4.55, 0.38, 0.18, mats.woodMid, 0, 0.28, -0.64, boat);
box(4.55, 0.38, 0.18, mats.woodMid, 0, 0.28, 0.64, boat);
box(0.65, 0.4, 1.15, mats.woodMid, -2.18, 0.18, 0, boat);
box(0.65, 0.4, 1.15, mats.woodMid, 2.18, 0.18, 0, boat);
// Cross benches.
for (const x of [-1.45, -0.2, 1.1]) {
box(0.28, 0.13, 1.2, mats.woodLight, x, 0.39, 0, boat);
}
// Simple woven canopy.
for (const x of [-0.95, 0.7]) {
box(0.1, 1.35, 0.1, mats.woodDark, x, 1.06, -0.52, boat);
box(0.1, 1.35, 0.1, mats.woodDark, x, 1.06, 0.52, boat);
}
box(2.35, 0.13, 1.45, mats.cloth, -0.1, 1.8, 0, boat);
box(2.4, 0.3, 0.12, mats.roofB, -0.1, 1.68, 0.74, boat);
// Pole extending over the water.
const pole = box(0.09, 3.4, 0.09, mats.woodMid, 1.8, 0.8, 0, boat);
pole.rotation.z = -0.42;
// ---------------------------------------------------------------------
// Custom camera controls — no external control addons
// ---------------------------------------------------------------------
const defaultView = {
target: new THREE.Vector3(-0.8, 2.65, -0.5),
theta: 0.68,
phi: 1.18,
radius: 18.8
};
const controls = {
target: defaultView.target.clone(),
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius
};
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 resetView() {
controls.target.copy(defaultView.target);
controls.theta = defaultView.theta;
controls.phi = defaultView.phi;
controls.radius = defaultView.radius;
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.005,
0.55,
1.42
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.012,
8.5,
31
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta += 0.09;
break;
case "ArrowRight":
controls.theta -= 0.09;
break;
case "ArrowUp":
controls.phi = Math.max(0.55, controls.phi - 0.07);
break;
case "ArrowDown":
controls.phi = Math.min(1.42, controls.phi + 0.07);
break;
case "+":
case "=":
controls.radius = Math.max(8.5, controls.radius - 1);
break;
case "-":
controls.radius = Math.min(31, controls.radius + 1);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
boat.position.y = -1.02 + Math.sin(time * 0.85) * 0.045;
boat.rotation.z = Math.sin(time * 0.66) * 0.012;
boat.rotation.x = Math.sin(time * 0.51 + 1.2) * 0.008;
lanterns.forEach((lantern, index) => {
lantern.rotation.z =
Math.sin(time * 1.05 + lantern.userData.phase) * 0.035;
lantern.rotation.x =
Math.cos(time * 0.92 + lantern.userData.phase) * 0.018;
});
ripples.forEach((ripple) => {
ripple.position.x =
ripple.userData.baseX +
Math.sin(time * 0.55 + ripple.userData.phase) * 0.11;
});
renderer.render(scene, camera);
}
resize();
updateCamera();
animate();
</script>
</body>
</html>
```