Prompt specification
Build or customize the Three.js 3D scene "Vaulted shop bay with shutter panels" 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: Vaulted shop bay with shutter panels
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/vaulted-shop-bay-with-shutter-panels-x2381
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing an Ottoman bazaar shop bay. Build a single historically informed bazaar shop bay with folding shutters, counter, and roof vault. Keep the trading surface distinct from the public passage. Voxel style.
Working Three.js Starter (vaulted-shop-bay-with-shutter-panels-x2381):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ottoman Bazaar Shop Bay</title>
<style>
:root {
--ink: #29221c;
--paper: rgba(244, 232, 207, 0.92);
--line: rgba(73, 52, 34, 0.24);
--gold: #b88739;
--trade: #8e3f32;
--public: #b8aa91;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d7c4a3;
color: var(--ink);
font-family: Georgia, "Times New Roman", serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid var(--line);
box-shadow: 0 10px 30px rgba(57, 38, 23, 0.14);
backdrop-filter: blur(8px);
}
#title {
top: 22px;
left: 24px;
max-width: 390px;
padding: 17px 20px 16px;
border-radius: 3px;
}
#title .eyebrow {
margin-bottom: 7px;
color: #8b6331;
font: 700 10px/1.2 Arial, sans-serif;
letter-spacing: 0.22em;
text-transform: uppercase;
}
#title h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
font-weight: 500;
line-height: 1.05;
}
#title p {
margin: 10px 0 0;
color: #625447;
font: 12px/1.45 Arial, sans-serif;
}
#legend {
left: 24px;
bottom: 24px;
display: flex;
gap: 20px;
padding: 12px 16px;
border-radius: 3px;
font: 11px/1.25 Arial, sans-serif;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 12px;
height: 12px;
border: 1px solid rgba(0, 0, 0, 0.18);
}
.swatch.trade {
background: var(--trade);
}
.swatch.public {
background: var(--public);
}
#controls {
right: 24px;
bottom: 24px;
padding: 11px 12px;
border-radius: 3px;
font: 11px/1.35 Arial, sans-serif;
}
#controls strong {
display: block;
margin-bottom: 7px;
color: #6f4c2c;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#controls div {
color: #625447;
}
button {
margin-top: 9px;
padding: 7px 10px;
border: 1px solid #8c755c;
border-radius: 2px;
background: #f2e5cc;
color: #493726;
font: 11px Arial, sans-serif;
cursor: pointer;
}
button:hover {
background: #e6d2af;
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
background: #d7c4a3;
color: #60462f;
font: 12px Arial, sans-serif;
letter-spacing: 0.14em;
text-transform: uppercase;
}
@media (max-width: 700px) {
#title {
top: 12px;
left: 12px;
max-width: calc(100vw - 24px);
}
#title p {
display: none;
}
#legend {
left: 12px;
bottom: 12px;
gap: 12px;
}
#controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title" class="panel">
<div class="eyebrow">Kapalıçarşı · Bay 07</div>
<h1>Ottoman Bazaar Shop Bay</h1>
<p>
A recessed merchant’s bay with folding kanat shutters, a raised trade
counter, masonry piers, and a ribbed roof vault.
</p>
</section>
<section id="legend" class="panel">
<div class="legend-item">
<span class="swatch trade"></span>
Trading bay
</div>
<div class="legend-item">
<span class="swatch public"></span>
Public passage
</div>
</section>
<section id="controls" class="panel">
<strong>Camera</strong>
<div>Drag: rotate · Wheel: zoom</div>
<div>Shift-drag / right-drag: pan</div>
<button id="reset" type="button">Reset view</button>
</section>
<div id="loading">Building the bazaar…</div>
<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 host = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd9c7a7);
scene.fog = new THREE.Fog(0xd9c7a7, 22, 43);
const renderer = new THREE.WebGLRenderer({
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;
host.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
// ------------------------------------------------------------
// Materials
// ------------------------------------------------------------
const M = {};
function makeMaterial(name, color, options = {}) {
M[name] = new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
...options
});
}
makeMaterial("stone", 0x82796a);
makeMaterial("stoneLight", 0xa39781);
makeMaterial("stoneDark", 0x5f584e);
makeMaterial("brick", 0x985a40);
makeMaterial("brickLight", 0xb36d4c);
makeMaterial("mortar", 0xb1a48e);
makeMaterial("wood", 0x67432a);
makeMaterial("woodLight", 0x8c5b37);
makeMaterial("woodDark", 0x38251b);
makeMaterial("woodPale", 0xa27348);
makeMaterial("red", 0x793a2e);
makeMaterial("redLight", 0x984d38);
makeMaterial("blue", 0x315863);
makeMaterial("turquoise", 0x47777a);
makeMaterial("cream", 0xd6c296);
makeMaterial("ochre", 0xc08b42);
makeMaterial("brass", 0xb8893d, {
roughness: 0.38,
metalness: 0.68
});
makeMaterial("iron", 0x292624, {
roughness: 0.55,
metalness: 0.62
});
makeMaterial("ceramic", 0xd9d0b8, {
roughness: 0.52
});
makeMaterial("fabricRed", 0x8e332e);
makeMaterial("fabricBlue", 0x315964);
makeMaterial("fabricGold", 0xb68842);
makeMaterial("fabricCream", 0xcbb785);
makeMaterial("floorWood", 0x806044);
makeMaterial("floorWoodDark", 0x60452f);
makeMaterial("floorClay", 0x9b6748);
makeMaterial("passage", 0xb8aa91);
makeMaterial("passageLight", 0xc4b69d);
makeMaterial("passageDark", 0xa79b84);
makeMaterial("earth", 0xb7a589);
makeMaterial("glow", 0xffd57a, {
emissive: 0xffa832,
emissiveIntensity: 1.8,
roughness: 0.5
});
// ------------------------------------------------------------
// Instanced voxel builder
// ------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const batches = new Map();
function B(x, y, z, w, h, d, material, rotation = [0, 0, 0]) {
if (!batches.has(material)) batches.set(material, []);
batches.get(material).push({
x, y, z, w, h, d,
rx: rotation[0],
ry: rotation[1],
rz: rotation[2]
});
}
function finishBatches() {
const dummy = new THREE.Object3D();
for (const [material, records] of batches) {
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
records.length
);
records.forEach((r, i) => {
dummy.position.set(r.x, r.y, r.z);
dummy.rotation.set(r.rx, r.ry, r.rz);
dummy.scale.set(r.w, r.h, r.d);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
});
mesh.instanceMatrix.setUsage(THREE.StaticDrawUsage);
mesh.castShadow = material !== M.glow;
mesh.receiveShadow = true;
mesh.computeBoundingBox();
mesh.computeBoundingSphere();
scene.add(mesh);
}
}
// Deterministic pseudo-random variation.
function seeded(n) {
const x = Math.sin(n * 127.1 + 311.7) * 43758.5453;
return x - Math.floor(x);
}
// ------------------------------------------------------------
// Ground, shop floor, and distinct public passage
// ------------------------------------------------------------
B(0, -0.58, 1.0, 32, 0.6, 31, M.earth);
// Shop platform: dark timber floor, visually distinct from passage.
B(0, -0.14, -0.15, 8.45, 0.28, 6.95, M.floorWoodDark);
for (let i = 0; i < 17; i++) {
const x = -3.84 + i * 0.48;
const mat = i % 4 === 0 ? M.floorWoodDark : M.floorWood;
B(x, 0.025, -0.1, 0.445, 0.065, 6.72, mat);
}
// Customer-side trading apron inside the bay.
B(0, 0.065, 2.18, 6.95, 0.06, 1.72, M.floorClay);
B(-3.42, 0.104, 2.18, 0.10, 0.035, 1.72, M.brass);
B(3.42, 0.104, 2.18, 0.10, 0.035, 1.72, M.brass);
B(0, 0.104, 1.36, 6.95, 0.035, 0.10, M.brass);
B(0, 0.104, 3.00, 6.95, 0.035, 0.10, M.brass);
// Public passage paving, lower than the merchant's platform.
B(0, -0.23, 5.3, 12.0, 0.28, 4.15, M.passageDark);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 11; col++) {
const r = seeded(row * 31 + col);
const mat =
r < 0.22 ? M.passageLight :
r < 0.38 ? M.passageDark :
M.passage;
const x = -5.25 + col * 1.05;
const z = 3.70 + row * 1.02;
B(x, -0.065, z, 1.01, 0.11, 0.98, mat);
}
}
// Brass threshold strip and stone step clearly separate the spaces.
B(0, -0.065, 3.38, 8.18, 0.17, 0.48, M.stoneDark);
B(0, 0.032, 3.50, 7.85, 0.026, 0.075, M.brass);
B(-3.73, 0.10, 3.38, 0.20, 0.20, 0.50, M.stoneLight);
B(3.73, 0.10, 3.38, 0.20, 0.20, 0.50, M.stoneLight);
// ------------------------------------------------------------
// Masonry shell
// ------------------------------------------------------------
// Lower and upper rear wall.
B(0, 2.40, -3.52, 8.55, 4.80, 0.46, M.stoneDark);
B(0, 5.73, -3.52, 8.55, 3.55, 0.46, M.stoneDark);
// Exposed rear masonry courses.
for (let row = 0; row < 14; row++) {
const y = 0.30 + row * 0.51;
const offset = row % 2 === 0 ? 0 : 0.34;
for (let col = 0; col < 11; col++) {
const x = -4.02 + col * 0.76 + offset;
if (x > 4.18) continue;
const r = seeded(row * 17 + col * 7);
const mat =
r < 0.20 ? M.stoneLight :
r < 0.32 ? M.brick :
M.stone;
B(x, y, -3.255, 0.70, 0.455, 0.12, mat);
}
}
// Left wall is retained; right wall is cut away for the axonometric view.
B(-4.10, 2.00, -0.80, 0.40, 4.00, 5.80, M.stoneDark);
B(4.10, 2.00, -2.48, 0.40, 4.00, 2.00, M.stoneDark);
// Left wall facing.
for (let row = 0; row < 8; row++) {
for (let z = -3.2; z < 2.5; z += 0.72) {
const r = seeded(row * 29 + z * 4);
const mat = r < 0.25 ? M.stoneLight : M.stone;
B(-3.86, 0.30 + row * 0.51, z, 0.13, 0.45, 0.65, mat);
}
}
// Low cutaway right wall.
B(4.10, 0.58, 0.78, 0.40, 1.10, 4.38, M.stone);
B(4.10, 1.16, 0.78, 0.46, 0.14, 4.42, M.stoneLight);
// Front piers.
B(-3.78, 1.98, 3.02, 0.74, 3.96, 0.68, M.stone);
B(3.78, 1.98, 3.02, 0.74, 3.96, 0.68, M.stone);
for (let row = 0; row < 8; row++) {
const y = 0.25 + row * 0.49;
for (const x of [-3.78, 3.78]) {
const mat = row % 3 === 0 ? M.stoneLight : M.stone;
B(x, y, 3.395, 0.70, 0.44, 0.10, mat);
}
}
// Stepped Ottoman-style bracket details at the springing points.
for (const side of [-1, 1]) {
B(side * 3.30, 3.43, 3.12, 0.66, 0.25, 0.72, M.stoneLight);
B(side * 3.17, 3.66, 3.12, 0.50, 0.25, 0.72, M.stone);
B(side * 3.04, 3.86, 3.12, 0.34, 0.22, 0.72, M.stoneLight);
}
// ------------------------------------------------------------
// Voxel arch and roof-vault ribs
// ------------------------------------------------------------
const springY = 3.98;
const archRadius = 3.36;
const archSegments = 21;
function archRing(radius, z, depth, tangentWidth, radialHeight, materials) {
for (let i = 0; i < archSegments; i++) {
const angle = (i / (archSegments - 1)) * Math.PI;
const x = Math.cos(angle) * radius;
const y = springY + Math.sin(angle) * radius;
B(
x, y, z,
tangentWidth, radialHeight, depth,
materials[i % materials.length],
[0, 0, angle - Math.PI / 2]
);
}
}
// Broad masonry/brick archivolt.
archRing(
archRadius,
3.02,
0.62,
0.62,
0.50,
[M.brick, M.brickLight, M.stone]
);
// Inner timber archivolt.
archRing(
3.07,
3.15,
0.22,
0.40,
0.18,
[M.woodDark]
);
// Keystone and crown.
B(0, 7.30, 3.02, 0.62, 0.80, 0.70, M.stoneLight);
B(0, 7.68, 3.02, 0.78, 0.16, 0.76, M.brickLight);
// Barrel-vault ribs running through the bay.
for (const z of [1.05, -0.88, -2.72]) {
archRing(
3.06,
z,
0.20,
0.30,
0.19,
[M.woodDark]
);
}
// Longitudinal roof timbers follow the vault curve.
for (const degrees of [24, 52, 90, 128, 156]) {
const angle = THREE.MathUtils.degToRad(degrees);
const x = Math.cos(angle) * 3.04;
const y = springY + Math.sin(angle) * 3.04;
B(x, y, -0.84, 0.18, 0.18, 5.72, M.wood);
}
// Rear vault infill, mostly hidden by the ribs.
for (const degrees of [35, 55, 90, 125, 145]) {
const angle = THREE.MathUtils.degToRad(degrees);
const x = Math.cos(angle) * 3.22;
const y = springY + Math.sin(angle) * 3.22;
B(x, y, -3.08, 1.22, 0.16, 0.58, M.brick);
}
// ------------------------------------------------------------
// Folding shutters / kanat
// ------------------------------------------------------------
function shutterPanel(cx, cz, yaw, width = 0.80, height = 3.55) {
const cy = 0.22 + height / 2;
const slatCount = 7;
const slatWidth = 0.075;
const slatGap = 0.018;
const totalWidth = slatCount * slatWidth + (slatCount - 1) * slatGap;
const cos = Math.cos(yaw);
const sin = Math.sin(yaw);
for (let i = 0; i < slatCount; i++) {
const localX = -totalWidth / 2 + slatWidth / 2 + i * (slatWidth + slatGap);
const x = cx + cos * localX;
const z = cz - sin * localX;
B(
x, cy, z,
slatWidth, height, 0.105,
i % 3 === 0 ? M.woodLight : M.wood,
[0, yaw, 0]
);
}
// Horizontal rails.
for (const y of [0.32, 1.96, 3.62]) {
B(cx, y, cz, width, 0.12, 0.15, M.woodDark, [0, yaw, 0]);
}
// Dark hinge straps.
for (const y of [0.63, 3.27]) {
B(cx, y, cz + 0.075, width * 0.80, 0.065, 0.045, M.iron, [0, yaw, 0]);
}
}
// Left and right shutters fold inward in visible zigzags.
shutterPanel(-3.18, 2.48, THREE.MathUtils.degToRad(55));
shutterPanel(-2.88, 1.92, THREE.MathUtils.degToRad(-50));
shutterPanel(-2.56, 1.36, THREE.MathUtils.degToRad(55));
shutterPanel(3.18, 2.48, THREE.MathUtils.degToRad(-55));
shutterPanel(2.88, 1.92, THREE.MathUtils.degToRad(50));
shutterPanel(2.56, 1.36, THREE.MathUtils.degToRad(-55));
// Small iron pivot blocks at the front piers.
for (const x of [-3.34, 3.34]) {
B(x, 0.62, 2.73, 0.16, 0.16, 0.24, M.iron);
B(x, 3.23, 2.73, 0.16, 0.16, 0.24, M.iron);
}
// ------------------------------------------------------------
// Raised merchant counter
// ------------------------------------------------------------
B(0, 0.16, 0.55, 6.22, 0.24, 1.12, M.woodDark);
B(0, 0.72, 0.55, 6.08, 1.18, 1.06, M.red);
B(0, 1.37, 0.55, 6.36, 0.19, 1.24, M.woodLight);
// Painted front panels.
for (let i = 0; i < 7; i++) {
const x = -2.58 + i * 0.86;
const mat = i % 2 === 0 ? M.cream : M.blue;
B(x, 0.73, 1.097, 0.72, 0.72, 0.055, mat);
B(x, 0.73, 1.132, 0.53, 0.53, 0.030, M.redLight);
B(x, 0.73, 1.153, 0.16, 0.16, 0.025, M.ochre);
}
// Counter edge and brass pins.
B(0, 1.28, 1.18, 6.36, 0.09, 0.08, M.woodDark);
for (let i = 0; i < 9; i++) {
B(-2.8 + i * 0.7, 1.29, 1.23, 0.055, 0.055, 0.035, M.brass);
}
// Folded cloth spread on the trading surface.
B(-1.62, 1.485, 0.52, 1.78, 0.035, 0.87, M.fabricRed);
B(-1.62, 1.507, 0.52, 1.62, 0.018, 0.72, M.fabricGold);
B(-1.62, 1.520, 0.52, 1.48, 0.012, 0.58, M.fabricBlue);
// ------------------------------------------------------------
// Counter goods
// ------------------------------------------------------------
function bowl(cx, y, cz, material = M.ceramic, radius = 0.20) {
const blocks = 8;
for (let i = 0; i < blocks; i++) {
const a = (i / blocks) * Math.PI * 2;
B(
cx + Math.cos(a) * radius,
y + 0.05,
cz + Math.sin(a) * radius,
0.12, 0.10, 0.12,
material
);
}
B(cx, y, cz, radius * 1.15, 0.08, radius * 1.15, material);
}
function jar(cx, y, cz, material, scale = 1) {
B(cx, y + 0.18 * scale, cz, 0.30 * scale, 0.36 * scale, 0.30 * scale, material);
B(cx, y + 0.43 * scale, cz, 0.21 * scale, 0.16 * scale, 0.21 * scale, material);
B(cx, y + 0.54 * scale, cz, 0.26 * scale, 0.07 * scale, 0.26 * scale, M.woodDark);
}
// Ceramic bowls and cups.
bowl(-0.25, 1.49, 0.64, M.ceramic, 0.22);
bowl(-0.25, 1.59, 0.64, M.turquoise, 0.15);
bowl(0.34, 1.49, 0.48, M.cream, 0.18);
B(0.72, 1.56, 0.72, 0.13, 0.16, 0.13, M.ceramic);
B(0.72, 1.66, 0.72, 0.16, 0.045, 0.16, M.blue);
// Brass balance.
B(1.40, 1.50, 0.42, 0.74, 0.08, 0.53, M.brass);
B(1.40, 1.92, 0.31, 0.07, 0.82, 0.07, M.brass);
B(1.40, 2.32, 0.31, 0.72, 0.07, 0.07, M.brass);
for (const x of [1.08, 1.72]) {
B(x, 2.04, 0.31, 0.025, 0.52, 0.025, M.iron);
B(x, 1.78, 0.31, 0.28, 0.055, 0.24, M.brass);
}
// Cubic brass coffee pot.
B(2.34, 1.71, 0.53, 0.42, 0.47, 0.40, M.brass);
B(2.34, 1.99, 0.53, 0.30, 0.12, 0.30, M.brass);
B(2.34, 2.08, 0.53, 0.14, 0.08, 0.14, M.woodDark);
B(2.59, 1.80, 0.53, 0.24, 0.10, 0.10, M.brass, [0, 0, -0.55]);
B(2.10, 1.78, 0.53, 0.20, 0.07, 0.07, M.brass);
B(2.10, 1.63, 0.53, 0.07, 0.30, 0.07, M.brass);
// Wrapped parcel and small bottles.
B(-2.85, 1.58, 0.55, 0.55, 0.25, 0.48, M.fabricCream);
B(-2.85, 1.59, 0.55, 0.09, 0.27, 0.50, M.fabricRed);
jar(2.94, 1.49, 0.35, M.turquoise, 0.65);
// ------------------------------------------------------------
// Rear niches, shelving, textiles, and pottery
// ------------------------------------------------------------
// Recessed wall panels.
B(-2.12, 2.30, -3.15, 2.30, 3.30, 0.12, M.woodDark);
B(1.88, 2.30, -3.15, 2.55, 3.30, 0.12, M.woodDark);
// Decorative turquoise tile bands.
for (let i = 0; i < 7; i++) {
B(-3.06 + i * 0.31, 3.82, -3.055, 0.24, 0.24, 0.055, M.turquoise);
B(0.88 + i * 0.31, 3.82, -3.055, 0.24, 0.24, 0.055, M.turquoise);
}
// Shelves.
for (const x of [-2.12, 1.88]) {
B(x, 1.20, -2.92, 2.34, 0.13, 0.62, M.woodLight);
B(x, 2.28, -2.92, 2.34, 0.13, 0.62, M.woodLight);
B(x, 3.35, -2.92, 2.34, 0.13, 0.62, M.woodLight);
}
// Stored folded rugs.
for (let i = 0; i < 4; i++) {
const mat = i % 2 === 0 ? M.fabricBlue : M.fabricRed;
B(-2.45 + i * 0.38, 2.47, -2.88, 0.34, 0.23, 0.47, mat);
B(-2.45 + i * 0.38, 2.69, -2.88, 0.32, 0.18, 0.45, i % 2 ? M.fabricGold : M.fabricCream);
}
// Pottery on lower shelves.
jar(-2.72, 1.28, -2.88, M.ceramic, 0.82);
jar(-2.18, 1.28, -2.88, M.turquoise, 0.72);
jar(-1.68, 1.28, -2.88, M.ochre, 0.78);
jar(1.10, 1.28, -2.88, M.ceramic, 0.88);
jar(1.58, 1.28, -2.88, M.blue, 0.68);
jar(2.03, 1.28, -2.88, M.ceramic, 0.78);
jar(2.51, 1.28, -2.88, M.ochre, 0.68);
// Brass trays on the middle shelf.
B(1.20, 2.39, -2.87, 0.68, 0.06, 0.40, M.brass);
B(1.91, 2.39, -2.87, 0.68, 0.06, 0.40, M.brass);
B(2.60, 2.39, -2.87, 0.50, 0.06, 0.40, M.brass);
// Rolled textiles on the upper shelf.
for (let i = 0; i < 6; i++) {
const mat = i % 3 === 0 ? M.fabricRed : i % 3 === 1 ? M.fabricBlue : M.fabricCream;
B(0.90 + i * 0.38, 3.58, -2.88, 0.31, 0.34, 0.43, mat);
}
// Central carved wooden panel.
B(0, 2.16, -3.05, 0.65, 2.78, 0.16, M.wood);
for (let i = 0; i < 7; i++) {
B(0, 1.08 + i * 0.34, -2.94, 0.48, 0.13, 0.07, M.woodLight);
}
B(0, 2.18, -2.90, 0.13, 2.25, 0.07, M.woodDark);
// ------------------------------------------------------------
// Hanging lantern and practical details
// ------------------------------------------------------------
// Chain from the vault.
B(0, 5.85, 0.35, 0.045, 1.15, 0.045, M.iron);
B(0, 5.18, 0.35, 0.52, 0.70, 0.52, M.iron);
// Glowing panes and frame.
B(0, 5.18, 0.35, 0.39, 0.50, 0.39, M.glow);
B(0, 5.56, 0.35, 0.66, 0.10, 0.66, M.iron);
B(0, 4.80, 0.35, 0.62, 0.10, 0.62, M.iron);
B(0, 5.20, 0.07, 0.62, 0.62, 0.055, M.iron);
B(0, 5.20, 0.63, 0.62, 0.62, 0.055, M.iron);
// Iron brackets on the counter ends.
for (const x of [-3.07, 3.07]) {
B(x, 1.48, 0.40, 0.16, 0.13, 0.66, M.iron);
B(x, 1.61, 0.72, 0.08, 0.25, 0.08, M.iron);
}
// Small stools behind the counter.
for (const x of [-1.75, 1.55]) {
B(x, 0.48, -1.52, 0.72, 0.14, 0.48, M.woodLight);
for (const dx of [-0.25, 0.25]) {
for (const dz of [-0.15, 0.15]) {
B(x + dx, 0.22, -1.52 + dz, 0.10, 0.42, 0.10, M.woodDark);
}
}
}
// A rolled carpet leaning against the left rear.
B(-3.55, 1.12, -1.35, 0.42, 2.05, 0.48, M.fabricRed, [0, 0, -0.06]);
B(-3.55, 1.12, -1.10, 0.38, 2.00, 0.08, M.fabricGold);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffe8c5,
0x49372a,
1.65
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe4bd, 3.25);
sun.position.set(-7.5, 12.0, 8.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const interiorLight = new THREE.PointLight(
0xffb552,
32,
12,
2
);
interiorLight.position.set(0, 5.12, 0.35);
scene.add(interiorLight);
const counterLight = new THREE.PointLight(
0xffc878,
17,
8,
2
);
counterLight.position.set(-0.8, 3.25, 1.4);
scene.add(counterLight);
const passageLight = new THREE.DirectionalLight(
0xffe9c9,
0.75
);
passageLight.position.set(6, 5, 12);
scene.add(passageLight);
finishBatches();
// ------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, touch pinch
// ------------------------------------------------------------
const target = new THREE.Vector3(0, 2.55, 0.25);
const spherical = new THREE.Spherical(16.4, 1.12, 0.40);
const pointerMap = new Map();
let previousPinchDistance = 0;
let draggingButton = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function updateCamera() {
spherical.phi = clamp(spherical.phi, 0.25, 1.48);
spherical.radius = clamp(spherical.radius, 9.5, 27);
spherical.makeSafe();
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
function resetCamera() {
target.set(0, 2.55, 0.25);
spherical.set(16.4, 1.12, 0.40);
updateCamera();
}
function panCamera(dx, dy) {
const distance = camera.position.distanceTo(target);
const panScale = distance * 0.0014;
const right = new THREE.Vector3();
const forward = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), forward);
forward.y = 0;
forward.normalize();
target.addScaledVector(right, -dx * panScale);
target.addScaledVector(forward, -dy * panScale);
target.x = clamp(target.x, -7, 7);
target.y = clamp(target.y, 0.7, 6.5);
target.z = clamp(target.z, -4, 6);
}
function pointerDistance() {
const values = [...pointerMap.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);
pointerMap.set(event.pointerId, { x: event.clientX, y: event.clientY });
draggingButton = event.button;
if (pointerMap.size === 2) {
previousPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerMap.has(event.pointerId)) return;
const previous = pointerMap.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointerMap.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointerMap.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0) {
spherical.radius *= previousPinchDistance / Math.max(distance, 1);
}
previousPinchDistance = distance;
updateCamera();
return;
}
const panning =
event.shiftKey ||
draggingButton === 2 ||
event.buttons === 4;
if (panning) {
panCamera(dx, dy);
} else {
spherical.theta -= dx * 0.0055;
spherical.phi -= dy * 0.0047;
}
updateCamera();
});
function releasePointer(event) {
pointerMap.delete(event.pointerId);
if (pointerMap.size < 2) previousPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateCamera();
loading.remove();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```