Prompt specification
Build or customize the Three.js 3D scene "Cairo metalwork shop threshold and hanging lamp" 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: Cairo metalwork shop threshold and hanging lamp
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cairo-metalwork-shop-threshold-and-hanging-lamp-x2897
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts Khan el-Khalili's market passages in Cairo. Build a referenced shop threshold with an original geometric hanging lamp and shallow display shelf. Keep decorative objects distinct from the route through the narrow passage. Low-poly.
Working Three.js Starter (cairo-metalwork-shop-threshold-and-hanging-lamp-x2897):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Khan el-Khalili — Market Passage</title>
<style>
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cdb99a;
font-family: Georgia, "Times New Roman", serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.title {
position: fixed;
top: 24px;
left: 28px;
z-index: 2;
max-width: 380px;
padding: 15px 18px 14px;
color: #f5e8ce;
background: rgba(44, 31, 23, 0.82);
border: 1px solid rgba(238, 190, 103, 0.48);
box-shadow: 0 8px 28px rgba(35, 24, 16, 0.22);
pointer-events: none;
}
.title h1 {
margin: 0 0 6px;
font-size: clamp(21px, 3vw, 31px);
font-weight: 500;
letter-spacing: 0.035em;
}
.title p {
margin: 0;
color: #d8c39f;
font: 12px/1.45 Arial, sans-serif;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 2;
padding: 10px 13px;
color: #f5e8ce;
background: rgba(44, 31, 23, 0.76);
border: 1px solid rgba(238, 190, 103, 0.34);
font: 11px/1.4 Arial, sans-serif;
letter-spacing: 0.07em;
text-transform: uppercase;
pointer-events: none;
}
.legend {
position: fixed;
left: 28px;
bottom: 22px;
z-index: 2;
display: flex;
align-items: center;
gap: 9px;
color: #49372a;
font: 11px/1.3 Arial, sans-serif;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
text-shadow: 0 1px rgba(255,255,255,0.35);
}
.legend::before {
content: "";
width: 28px;
height: 5px;
background: #dfc59d;
border: 1px solid rgba(65, 45, 30, 0.45);
}
@media (max-width: 650px) {
.title {
top: 14px;
left: 14px;
right: 14px;
}
.legend {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div class="title">
<h1>Khan el-Khalili</h1>
<p>Market passage · threshold study</p>
</div>
<div class="legend">Clear route through the passage</div>
<div class="controls">Drag to look · wheel to dolly · double-click to reset</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 atmosphere
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcdb99a);
scene.fog = new THREE.Fog(0xcdb99a, 10, 35);
const camera = new THREE.PerspectiveCamera(
48,
innerWidth / innerHeight,
0.05,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xffe7bd, 0x574331, 1.9);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffdfac, 3.1);
sun.position.set(-4, 10, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const world = new THREE.Group();
scene.add(world);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0,
flatShading: true,
...options
});
const mats = {
plaster: material(0xc99c69),
plasterLight: material(0xdab27b),
plasterDark: material(0xad794f),
plasterPink: material(0xc58e6d),
stone: material(0xb99a75),
path: material(0xdfc59d),
paving: material(0xb79872),
wood: material(0x5a3523),
darkWood: material(0x38251e),
brass: material(0xa77934, { metalness: 0.65, roughness: 0.4 }),
copper: material(0x9b5937, { metalness: 0.52, roughness: 0.5 }),
turquoise: material(0x376e6c, { metalness: 0.18, roughness: 0.58 }),
cream: material(0xe6d2a5),
rust: material(0xa85036),
olive: material(0x686b43),
black: material(0x201b19),
interior: material(0x35231c),
amber: material(0xe8a74f, {
emissive: 0xa84d13,
emissiveIntensity: 0.65,
transparent: true,
opacity: 0.9,
roughness: 0.55
})
};
function box(w, h, d, x, y, z, mat, parent = world, cast = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(rt, rb, h, segments, x, y, z, mat, parent = world) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function rod(a, b, radius, mat, parent = world) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 6),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function ring(radius, tube, x, y, z, mat, parent = world) {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(radius, tube, 4, 8),
mat
);
mesh.rotation.x = Math.PI / 2;
mesh.position.set(x, y, z);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// ---------------------------------------------------------------------
// Passage shell and paving
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(8, 34),
mats.stone
);
ground.rotation.x = -Math.PI / 2;
ground.position.set(0, -0.045, -1);
ground.receiveShadow = true;
world.add(ground);
// The pale central strip remains intentionally free of merchandise.
const route = new THREE.Mesh(
new THREE.PlaneGeometry(1.85, 32),
mats.path
);
route.rotation.x = -Math.PI / 2;
route.position.set(0, 0.002, -1);
route.receiveShadow = true;
world.add(route);
// Low-poly cobbles occupy only the outer bands of the passage.
const cobbleCount = 180;
const cobbles = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.62, 0.085, 0.46),
mats.paving,
cobbleCount
);
const dummy = new THREE.Object3D();
const cobbleColor = new THREE.Color();
let cobbleIndex = 0;
for (const side of [-1, 1]) {
for (let row = 0; row < 2; row++) {
for (let z = -15.5; z < 14; z += 0.72) {
const jitterX = (Math.random() - 0.5) * 0.12;
const jitterZ = (Math.random() - 0.5) * 0.16;
dummy.position.set(
side * (1.56 + row * 0.79) + jitterX,
0.025 + Math.random() * 0.025,
z + jitterZ
);
dummy.rotation.set(
0,
(Math.random() - 0.5) * 0.12,
0
);
dummy.scale.set(
0.9 + Math.random() * 0.18,
0.8 + Math.random() * 0.35,
0.84 + Math.random() * 0.24
);
dummy.updateMatrix();
cobbles.setMatrixAt(cobbleIndex, dummy.matrix);
cobbleColor.setHSL(
0.09 + Math.random() * 0.025,
0.25 + Math.random() * 0.12,
0.48 + Math.random() * 0.12
);
cobbles.setColorAt(cobbleIndex, cobbleColor);
cobbleIndex++;
}
}
}
cobbles.instanceMatrix.needsUpdate = true;
if (cobbles.instanceColor) cobbles.instanceColor.needsUpdate = true;
cobbles.receiveShadow = true;
world.add(cobbles);
// Narrow passage walls. The right wall has a real shop opening.
box(0.38, 5.5, 30, -3.05, 2.75, -1, mats.plaster);
box(0.38, 5.5, 14.6, 3.05, 2.75, -8.7, mats.plaster);
box(0.38, 5.5, 12.5, 3.05, 2.75, 7.75, mats.plasterPink);
box(0.38, 2.5, 3.3, 3.05, 4.25, 0.05, mats.plaster);
// Irregular plaster patches and masonry joints.
const patchData = [
[-2.84, 3.7, -10.8, 0.035, 1.1, 2.4, mats.plasterLight],
[-2.83, 1.8, -2.7, 0.035, 1.6, 1.7, mats.plasterPink],
[-2.84, 4.2, 8.4, 0.035, 1.4, 2.5, mats.plasterDark],
[2.84, 4.0, -10.1, 0.035, 1.6, 2.0, mats.plasterLight],
[2.84, 1.6, 8.2, 0.035, 1.4, 2.7, mats.plasterPink],
[2.84, 3.8, 5.4, 0.035, 1.2, 1.9, mats.plasterDark]
];
for (const [x, y, z, w, h, d, mat] of patchData) {
box(w, h, d, x, y, z, mat);
}
// Wall base courses.
box(0.12, 0.42, 14.6, -2.82, 0.21, -8.7, mats.plasterDark);
box(0.12, 0.42, 12.5, 2.82, 0.21, 7.75, mats.plasterDark);
// Upper irregular roofline.
box(0.62, 0.7, 3.2, -3.0, 5.85, -8.6, mats.plasterLight);
box(0.58, 1.15, 4.0, -3.05, 6.05, 3.0, mats.plasterDark);
box(0.6, 0.55, 5.0, 3.0, 5.8, 8.2, mats.plasterLight);
// ---------------------------------------------------------------------
// Distant arch at the end of the passage
// ---------------------------------------------------------------------
box(1.45, 5.5, 0.4, -2.38, 2.75, -16, mats.plasterDark);
box(1.45, 5.5, 0.4, 2.38, 2.75, -16, mats.plaster);
box(3.3, 2.05, 0.4, 0, 4.48, -16, mats.plasterLight);
const archDark = new THREE.Mesh(
new THREE.PlaneGeometry(3.35, 3.35),
mats.interior
);
archDark.position.set(0, 1.68, -16.23);
world.add(archDark);
for (let i = 0; i < 10; i++) {
const angle = (i / 9) * Math.PI;
const x = Math.cos(angle) * 1.78;
const y = 1.63 + Math.sin(angle) * 1.78;
const voussoir = box(
0.48,
0.65,
0.48,
x,
y,
-15.94,
i % 2 ? mats.plasterLight : mats.plaster
);
voussoir.rotation.z = angle - Math.PI / 2;
}
// ---------------------------------------------------------------------
// Shop threshold: recess, jambs, door, step and sign
// ---------------------------------------------------------------------
// Recessed shop interior.
box(0.16, 3.0, 3.15, 3.56, 1.5, 0.05, mats.interior);
box(0.3, 0.12, 3.15, 3.48, 0.06, 0.05, mats.darkWood);
// Carved jambs and lintel.
box(0.38, 3.12, 0.22, 2.91, 1.56, -1.43, mats.darkWood);
box(0.38, 3.12, 0.22, 2.91, 1.56, 1.53, mats.darkWood);
box(0.42, 0.25, 3.18, 2.90, 3.12, 0.05, mats.darkWood);
// Narrow raised threshold.
box(0.48, 0.13, 3.08, 2.78, 0.065, 0.05, mats.plasterLight);
// Partly open wooden door.
box(0.12, 2.62, 0.91, 3.39, 1.34, -0.85, mats.wood);
for (let i = 0; i < 5; i++) {
box(0.145, 0.06, 0.82, 3.30, 0.32 + i * 0.48, -0.85, mats.darkWood);
}
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.095, 0.018, 4, 8),
mats.brass
);
handle.rotation.y = Math.PI / 2;
handle.position.set(3.285, 1.38, -0.52);
world.add(handle);
// Canvas-generated shop sign.
function makeSignTexture() {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#294f48";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#d4a64e";
ctx.lineWidth = 8;
ctx.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
ctx.strokeStyle = "#e5c778";
ctx.lineWidth = 2;
ctx.strokeRect(24, 24, canvas.width - 48, canvas.height - 48);
ctx.textAlign = "center";
ctx.fillStyle = "#f1d995";
ctx.font = "46px Georgia";
ctx.fillText("KHAN EL-KHALILI", 384, 82);
ctx.fillStyle = "#d8bf7e";
ctx.font = "21px Arial";
ctx.fillText("COPPER • LAMPS • SPICES", 384, 132);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const signMaterial = new THREE.MeshStandardMaterial({
map: makeSignTexture(),
roughness: 0.85,
flatShading: true
});
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(2.16, 0.54),
signMaterial
);
sign.rotation.y = -Math.PI / 2;
sign.position.set(2.665, 3.38, 0.05);
world.add(sign);
// Striped threshold canopy.
for (let i = 0; i < 7; i++) {
box(
0.61,
0.045,
0.39,
2.73,
3.18,
-1.08 + i * 0.38,
i % 2 ? mats.cream : mats.rust
);
}
rod([3.02, 3.16, -1.25], [2.42, 3.16, -1.25], 0.025, mats.brass);
rod([3.02, 3.16, 1.35], [2.42, 3.16, 1.35], 0.025, mats.brass);
// ---------------------------------------------------------------------
// Shallow display shelf, kept outside the central walking route
// ---------------------------------------------------------------------
box(0.64, 0.10, 2.28, 3.08, 1.03, 0.12, mats.darkWood);
box(0.09, 0.72, 0.09, 3.36, 0.66, -0.79, mats.brass);
box(0.09, 0.72, 0.09, 3.36, 0.66, 1.02, mats.brass);
rod([3.36, 0.34, -0.79], [3.36, 1.0, -0.79], 0.035, mats.brass);
rod([3.36, 0.34, 1.02], [3.36, 1.0, 1.02], 0.035, mats.brass);
// Shelf wares: low-poly cups, jars, folded cloth and a brass bowl.
cylinder(0.10, 0.08, 0.18, 8, 2.96, 1.17, -0.68, mats.turquoise);
cylinder(0.09, 0.11, 0.24, 8, 3.06, 1.20, -0.19, mats.copper);
cylinder(0.12, 0.09, 0.22, 8, 2.94, 1.19, 0.29, mats.cream);
cylinder(0.08, 0.08, 0.13, 8, 3.12, 1.14, 0.71, mats.turquoise);
const bowl = new THREE.Mesh(
new THREE.CylinderGeometry(0.20, 0.11, 0.13, 8, 1, true),
mats.brass
);
bowl.position.set(2.98, 1.15, 0.95);
bowl.castShadow = true;
world.add(bowl);
box(0.32, 0.09, 0.50, 3.04, 1.13, -0.43, mats.rust);
box(0.30, 0.075, 0.46, 3.02, 1.21, -0.43, mats.olive);
// ---------------------------------------------------------------------
// Original geometric hanging lamp
// ---------------------------------------------------------------------
const lamp = new THREE.Group();
lamp.position.set(2.30, 2.32, 0.08);
world.add(lamp);
// Three faceted glass volumes create an elongated hexagonal silhouette.
cylinder(0.09, 0.31, 0.34, 6, 0, 0.24, 0, mats.amber, lamp);
cylinder(0.31, 0.31, 0.50, 6, 0, -0.18, 0, mats.amber, lamp);
cylinder(0.31, 0.08, 0.30, 6, 0, -0.58, 0, mats.amber, lamp);
ring(0.32, 0.027, 0, 0.41, 0, mats.brass, lamp);
ring(0.32, 0.027, 0, 0.07, 0, mats.brass, lamp);
ring(0.32, 0.027, 0, -0.43, 0, mats.brass, lamp);
// Six straight structural ribs.
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
const x = Math.cos(angle) * 0.32;
const z = Math.sin(angle) * 0.32;
rod([x, 0.42, z], [x, -0.43, z], 0.018, mats.brass, lamp);
}
cylinder(0.17, 0.05, 0.15, 6, 0, 0.48, 0, mats.brass, lamp);
cylinder(0.045, 0.075, 0.16, 6, 0, -0.80, 0, mats.brass, lamp);
// Wall bracket and suspension.
rod([3.02, 3.72, 0.08], [2.30, 3.72, 0.08], 0.035, mats.brass);
rod([2.30, 3.72, 0.08], [2.30, 2.80, 0.08], 0.014, mats.black);
rod([3.02, 3.72, 0.08], [3.02, 3.37, 0.08], 0.03, mats.brass);
const lampLight = new THREE.PointLight(0xffad4d, 13, 5.2, 2);
lampLight.position.set(2.28, 2.27, 0.08);
world.add(lampLight);
const shopLight = new THREE.PointLight(0xffc477, 5, 3.8, 2);
shopLight.position.set(3.08, 2.0, 0.2);
world.add(shopLight);
// ---------------------------------------------------------------------
// Left-side mashrabiya and balcony
// ---------------------------------------------------------------------
box(0.12, 1.25, 2.45, -2.82, 3.64, -6.75, mats.darkWood);
box(0.65, 0.13, 2.85, -2.60, 4.48, -6.75, mats.wood);
for (let i = 0; i < 8; i++) {
box(0.075, 1.12, 0.035, -2.73, 3.64, -7.82 + i * 0.31, mats.wood);
}
for (let i = 0; i < 4; i++) {
box(0.075, 0.035, 2.30, -2.73, 3.16 + i * 0.32, -6.75, mats.wood);
}
for (let i = 0; i < 8; i++) {
box(0.055, 0.62, 0.055, -2.46, 4.80, -8.0 + i * 0.34, mats.darkWood);
}
box(0.09, 0.07, 2.72, -2.46, 5.08, -6.75, mats.darkWood);
// ---------------------------------------------------------------------
// Textile, pottery bench, rugs and crates on the outer edges
// ---------------------------------------------------------------------
function makeTextileTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 384;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#8e3528";
ctx.fillRect(0, 0, 256, 384);
ctx.fillStyle = "#c68a45";
ctx.fillRect(14, 14, 228, 356);
ctx.fillStyle = "#3d5550";
ctx.fillRect(26, 26, 204, 332);
ctx.strokeStyle = "#d9b56b";
ctx.lineWidth = 5;
for (let y = 70; y < 340; y += 75) {
ctx.beginPath();
ctx.moveTo(128, y - 25);
ctx.lineTo(158, y);
ctx.lineTo(128, y + 25);
ctx.lineTo(98, y);
ctx.closePath();
ctx.stroke();
}
ctx.fillStyle = "#d9b56b";
for (let y = 46; y < 380; y += 16) {
ctx.fillRect(0, y, 256, 4);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const textile = new THREE.Mesh(
new THREE.PlaneGeometry(1.55, 2.25),
new THREE.MeshStandardMaterial({
map: makeTextileTexture(),
roughness: 1,
flatShading: true,
side: THREE.DoubleSide
})
);
textile.rotation.y = Math.PI / 2;
textile.position.set(-2.82, 2.03, 3.7);
textile.castShadow = true;
world.add(textile);
rod([-2.78, 3.22, 2.9], [-2.78, 3.22, 4.5], 0.035, mats.wood);
// Pottery bench.
box(0.58, 0.10, 2.55, -2.50, 0.64, 6.45, mats.wood);
box(0.10, 0.60, 0.10, -2.52, 0.30, 5.45, mats.darkWood);
box(0.10, 0.60, 0.10, -2.52, 0.30, 7.45, mats.darkWood);
const pottery = [
[-2.45, 0.89, 5.55, 0.22, 0.46, mats.copper],
[-2.48, 0.86, 6.05, 0.18, 0.34, mats.cream],
[-2.43, 0.96, 6.58, 0.27, 0.55, mats.turquoise],
[-2.48, 0.83, 7.12, 0.17, 0.30, mats.rust]
];
for (const [x, y, z, radius, height, mat] of pottery) {
cylinder(radius * 0.58, radius, height, 8, x, y, z, mat);
cylinder(radius * 0.67, radius * 0.67, 0.055, 8, x, y + height / 2, z, mat);
}
// Folded rugs.
box(0.62, 0.10, 1.42, -2.47, 0.10, 9.08, mats.rust);
box(0.58, 0.09, 1.36, -2.46, 0.19, 9.03, mats.olive);
box(0.54, 0.08, 1.30, -2.45, 0.28, 8.98, mats.cream);
// Wooden crates tucked against the left edge.
box(0.68, 0.52, 0.75, -2.46, 0.26, 11.35, mats.wood);
box(0.62, 0.46, 0.69, -2.48, 0.73, 11.30, mats.darkWood);
box(0.72, 0.07, 0.08, -2.43, 0.48, 11.35, mats.brass);
box(0.72, 0.07, 0.08, -2.43, 0.18, 11.35, mats.brass);
// ---------------------------------------------------------------------
// Overhead beams, cords and awning fragments
// ---------------------------------------------------------------------
for (const z of [-10.4, -3.5, 5.4]) {
box(6.15, 0.14, 0.18, 0, 5.05, z, mats.darkWood);
}
rod([-2.8, 4.55, 8.0], [2.8, 4.42, 8.0], 0.012, mats.black);
const clothA = box(0.74, 0.92, 0.025, -1.85, 4.03, 8.0, mats.cream);
clothA.rotation.z = -0.08;
const clothB = box(0.64, 0.72, 0.025, 1.35, 4.04, 8.0, mats.turquoise);
clothB.rotation.z = 0.10;
// ---------------------------------------------------------------------
// Sparse airborne dust
// ---------------------------------------------------------------------
const dustCount = 150;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 4.8;
dustPositions[i * 3 + 1] = 0.4 + Math.random() * 4.1;
dustPositions[i * 3 + 2] = -15 + Math.random() * 29;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe4ad,
size: 0.032,
transparent: true,
opacity: 0.38,
depthWrite: false,
sizeAttenuation: true
})
);
world.add(dust);
// ---------------------------------------------------------------------
// Direct camera controls: constrained orbit/look and dolly
// ---------------------------------------------------------------------
const controls = {
yaw: -0.125,
pitch: 0.033,
radius: 10.7,
target: new THREE.Vector3(0.45, 1.72, -1.0)
};
const home = {
yaw: controls.yaw,
pitch: controls.pitch,
radius: controls.radius
};
function updateCamera() {
const horizontal = Math.cos(controls.pitch) * controls.radius;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.radius,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.yaw = THREE.MathUtils.clamp(
controls.yaw - dx * 0.0032,
-0.55,
0.38
);
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0022,
-0.12,
0.34
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.008,
4.5,
14
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.yaw = home.yaw;
controls.pitch = home.pitch;
controls.radius = home.radius;
updateCamera();
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
lampLight.intensity = 13 + Math.sin(elapsed * 2.1) * 0.55
+ Math.sin(elapsed * 5.7) * 0.18;
const positions = dustGeometry.attributes.position.array;
for (let i = 0; i < dustCount; i++) {
positions[i * 3] += Math.sin(elapsed * 0.24 + i) * 0.00018;
positions[i * 3 + 1] += 0.00055;
if (positions[i * 3 + 1] > 4.8) {
positions[i * 3 + 1] = 0.35;
}
}
dustGeometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
}
updateCamera();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```