Prompt specification
Build or customize the Three.js 3D scene "Al Fahidi wind-tower corner study" 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: Al Fahidi wind-tower corner study
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/al-fahidi-wind-tower-corner-study-x2905
Scene Description Prompt:
Cut away a low-poly Al Fahidi wind tower in Dubai, exposing openings and shaft with simplified airflow arrows. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (al-fahidi-wind-tower-corner-study-x2905):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Al Fahidi Wind Tower — Cutaway Study</title>
<style>
:root {
--ink: #39271c;
--sand: #f3dfbd;
--paper: rgba(255, 247, 229, 0.88);
--accent: #d47d3e;
--wind: #29b9cf;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9bcbd7;
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%;
cursor: grab;
touch-action: none;
}
canvas.dragging {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 10;
top: 24px;
left: 24px;
width: min(320px, calc(100vw - 48px));
padding: 18px 20px 17px;
border: 1px solid rgba(82, 53, 31, 0.14);
border-radius: 4px;
background: var(--paper);
box-shadow: 0 12px 34px rgba(62, 40, 23, 0.14);
backdrop-filter: blur(10px);
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(27px, 4vw, 40px);
font-weight: 500;
line-height: 0.94;
letter-spacing: -0.025em;
}
.subtitle {
margin: 9px 0 0;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.description {
margin: 13px 0 0;
max-width: 270px;
color: rgba(57, 39, 28, 0.72);
font-size: 12px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 12;
top: 24px;
right: 24px;
display: flex;
gap: 7px;
align-items: center;
}
button {
height: 38px;
border: 1px solid rgba(57, 39, 28, 0.16);
border-radius: 3px;
background: var(--paper);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 7px 18px rgba(62, 40, 23, 0.1);
backdrop-filter: blur(8px);
transition:
transform 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff8e9;
}
button:active {
transform: translateY(1px);
}
.icon-button {
width: 38px;
padding: 0;
font-size: 18px;
}
.airflow-button {
padding: 0 14px;
}
.airflow-button.active {
border-color: rgba(41, 185, 207, 0.42);
background: rgba(225, 250, 251, 0.92);
color: #147c8c;
}
.legend {
position: fixed;
z-index: 10;
bottom: 24px;
left: 24px;
display: flex;
gap: 18px;
align-items: center;
padding: 10px 13px;
border: 1px solid rgba(57, 39, 28, 0.13);
border-radius: 3px;
background: var(--paper);
box-shadow: 0 9px 25px rgba(62, 40, 23, 0.1);
backdrop-filter: blur(8px);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.legend-item {
display: flex;
gap: 7px;
align-items: center;
white-space: nowrap;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 10px;
background: var(--accent);
}
.swatch.wind {
background: var(--wind);
}
.hint {
position: fixed;
z-index: 10;
right: 24px;
bottom: 27px;
color: rgba(57, 39, 28, 0.72);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
text-shadow: 0 1px 10px rgba(255, 255, 255, 0.7);
pointer-events: none;
}
.scene-label {
position: fixed;
z-index: 7;
left: 0;
top: 0;
display: flex;
gap: 7px;
align-items: center;
padding: 5px 8px 5px 5px;
border: 1px solid rgba(57, 39, 28, 0.14);
border-radius: 2px;
background: rgba(255, 248, 232, 0.9);
color: var(--ink);
box-shadow: 0 5px 14px rgba(62, 40, 23, 0.1);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
transform: translate(-50%, -50%);
pointer-events: none;
transition: opacity 120ms ease;
white-space: nowrap;
}
.scene-label span {
display: grid;
width: 18px;
height: 18px;
place-items: center;
border-radius: 50%;
background: var(--accent);
color: #fff8e9;
font-size: 8px;
}
.scene-label.wind span {
background: var(--wind);
}
@media (max-width: 700px) {
.title-card {
top: 14px;
left: 14px;
width: 245px;
padding: 13px 15px;
}
.description {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 62px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: 185px;
}
button {
height: 34px;
}
.icon-button {
width: 34px;
}
.legend {
bottom: 14px;
left: 14px;
gap: 10px;
padding: 8px 10px;
font-size: 8px;
}
.hint {
display: none;
}
.scene-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<section class="title-card">
<div class="eyebrow">Dubai · Architectural Study</div>
<h1>Al Fahidi<br />Wind Tower</h1>
<p class="subtitle">Cutaway / Airflow Model</p>
<p class="description">
A low-poly interpretation of the historic Al Fahidi wind tower,
revealing its windward openings, central ventilation shaft, and
descending air path.
</p>
</section>
<nav class="controls" aria-label="Scene controls">
<button id="reset" class="icon-button" title="Reset camera" aria-label="Reset camera">↺</button>
<button id="zoomOut" class="icon-button" title="Zoom out" aria-label="Zoom out">−</button>
<button id="zoomIn" class="icon-button" title="Zoom in" aria-label="Zoom in">+</button>
<button id="airflow" class="airflow-button active" aria-pressed="true">Airflow on</button>
</nav>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<i class="swatch"></i>
Earthen structure
</div>
<div class="legend-item">
<i class="swatch wind"></i>
Airflow
</div>
</div>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
<div id="inletLabel" class="scene-label wind"><span>01</span>Wind inlet</div>
<div id="shaftLabel" class="scene-label"><span>02</span>Central shaft</div>
<div id="outletLabel" class="scene-label wind"><span>03</span>Low-level exhaust</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene and lighting
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x9bcbd7);
scene.fog = new THREE.Fog(0xd9c49b, 20, 54);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive cutaway model of the Al Fahidi wind tower"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xcce9f3, 0x8c5734, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe3b0, 3.4);
sun.position.set(9, 14, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x83c9db, 0.8);
fill.position.set(-10, 7, -9);
scene.add(fill);
const tower = new THREE.Group();
scene.add(tower);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const plaster = new THREE.MeshStandardMaterial({
color: 0xc78e57,
roughness: 0.96,
flatShading: true
});
const plasterLight = new THREE.MeshStandardMaterial({
color: 0xd9aa70,
roughness: 0.95,
flatShading: true
});
const plasterDark = new THREE.MeshStandardMaterial({
color: 0xad7043,
roughness: 1,
flatShading: true
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c88e,
roughness: 0.85,
flatShading: true
});
const shaftMaterial = new THREE.MeshStandardMaterial({
color: 0xb87848,
roughness: 0.96,
flatShading: true
});
const interiorMaterial = new THREE.MeshStandardMaterial({
color: 0x74432e,
roughness: 1,
flatShading: true
});
const timberMaterial = new THREE.MeshStandardMaterial({
color: 0x5b3828,
roughness: 0.92,
flatShading: true
});
const sandMaterial = new THREE.MeshStandardMaterial({
color: 0xd8b477,
roughness: 1,
flatShading: true
});
const pavingMaterial = new THREE.MeshStandardMaterial({
color: 0xe2c28e,
roughness: 1,
flatShading: true
});
const distantMaterial = new THREE.MeshStandardMaterial({
color: 0xa9aa9f,
roughness: 1,
flatShading: true
});
const skylineMaterial = new THREE.MeshStandardMaterial({
color: 0x8fa5aa,
roughness: 0.85,
flatShading: true
});
// ---------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------
function addBox(
width,
height,
depth,
material,
x = 0,
y = 0,
z = 0,
parent = tower
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radiusTop,
radiusBottom,
height,
segments,
material,
x = 0,
y = 0,
z = 0,
parent = scene
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Builds a wall as a solid extruded polygon with genuine pointed
// openings cut through it. No CSG or addons are required.
function addFacade({
xMin,
xMax,
height,
thickness = 0.32,
holes = [],
position,
rotationY = 0,
material = plaster
}) {
const shape = new THREE.Shape();
shape.moveTo(xMin, 0);
shape.lineTo(xMax, 0);
shape.lineTo(xMax, height);
shape.lineTo(xMin, height);
shape.closePath();
for (const opening of holes) {
const left = opening.cx - opening.width / 2;
const right = opening.cx + opening.width / 2;
const springY = opening.bottom + opening.spring;
const apexY = springY + opening.rise;
const hole = new THREE.Path();
hole.moveTo(left, opening.bottom);
hole.lineTo(left, springY);
hole.lineTo(opening.cx, apexY);
hole.lineTo(right, springY);
hole.lineTo(right, opening.bottom);
hole.closePath();
shape.holes.push(hole);
}
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: thickness,
bevelEnabled: false,
steps: 1,
curveSegments: 1
});
geometry.translate(0, 0, -thickness / 2);
const wall = new THREE.Mesh(geometry, material);
wall.position.copy(position);
wall.rotation.y = rotationY;
wall.castShadow = true;
wall.receiveShadow = true;
tower.add(wall);
return wall;
}
function addTriangleRelief(position, rotationY = 0) {
const shape = new THREE.Shape();
shape.moveTo(-0.23, -0.17);
shape.lineTo(0.23, -0.17);
shape.lineTo(0, 0.24);
shape.closePath();
const mesh = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
plasterDark
);
mesh.position.copy(position);
mesh.rotation.y = rotationY;
mesh.receiveShadow = true;
tower.add(mesh);
}
// ---------------------------------------------------------------------
// Ground and courtyard
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
sandMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.045;
ground.receiveShadow = true;
scene.add(ground);
addBox(
12.5,
0.09,
11.5,
pavingMaterial,
0,
0.015,
-0.8,
scene
);
const pavingGrid = new THREE.GridHelper(
12,
24,
0x9f754c,
0xb78d5d
);
pavingGrid.position.y = 0.066;
pavingGrid.material.transparent = true;
pavingGrid.material.opacity = 0.17;
scene.add(pavingGrid);
// Low courtyard enclosure, open toward the viewer.
addBox(
18,
1.25,
0.34,
plasterDark,
0,
0.625,
-7.3,
scene
);
addBox(
0.34,
1.25,
8.9,
plasterDark,
-8.4,
0.625,
-2.9,
scene
);
addBox(
0.34,
1.25,
8.9,
plasterDark,
8.4,
0.625,
-2.9,
scene
);
// ---------------------------------------------------------------------
// Al Fahidi wind tower
// ---------------------------------------------------------------------
const baseY = 0.44;
const facadeHeight = 5.55;
// Plinth and base moulding.
addBox(5.28, 0.32, 5.28, plasterDark, 0, 0.16, 0);
addBox(5.0, 0.12, 5.0, plasterLight, 0, 0.38, 0);
// Three remaining corner piers; the camera-facing corner is removed.
const columnPositions = [
[-2.08, -2.08],
[2.08, -2.08],
[-2.08, 2.08]
];
for (const [x, z] of columnPositions) {
addBox(
0.48,
facadeHeight + 0.08,
0.48,
plasterLight,
x,
baseY + facadeHeight / 2,
z
);
addBox(
0.58,
0.13,
0.58,
plasterDark,
x,
baseY + 0.04,
z
);
addBox(
0.58,
0.14,
0.58,
plasterDark,
x,
baseY + facadeHeight - 0.03,
z
);
}
const lowerOpenings = [
{
cx: -1.03,
bottom: 0.55,
width: 0.82,
spring: 0.52,
rise: 0.68
},
{
cx: 1.03,
bottom: 0.55,
width: 0.82,
spring: 0.52,
rise: 0.68
}
];
const upperOpenings = [
{
cx: -1.03,
bottom: 3.43,
width: 0.82,
spring: 0.52,
rise: 0.68
},
{
cx: 1.03,
bottom: 3.43,
width: 0.82,
spring: 0.52,
rise: 0.68
}
];
// Rear and left walls remain complete.
addFacade({
xMin: -2.08,
xMax: 2.08,
height: facadeHeight,
holes: [...lowerOpenings, ...upperOpenings],
position: new THREE.Vector3(0, baseY, -2.08)
});
addFacade({
xMin: -2.08,
xMax: 2.08,
height: facadeHeight,
holes: [...lowerOpenings, ...upperOpenings],
position: new THREE.Vector3(-2.08, baseY, 0),
rotationY: Math.PI / 2
});
// Front and right walls are cut back, removing the front-right quarter.
addFacade({
xMin: -2.08,
xMax: 0.08,
height: facadeHeight,
holes: [
{
cx: -1.02,
bottom: 0.55,
width: 0.82,
spring: 0.52,
rise: 0.68
},
{
cx: -1.02,
bottom: 3.43,
width: 0.82,
spring: 0.52,
rise: 0.68
}
],
position: new THREE.Vector3(0, baseY, 2.08),
material: plasterLight
});
addFacade({
xMin: -2.08,
xMax: -0.08,
height: facadeHeight,
holes: [
{
cx: -1.08,
bottom: 0.55,
width: 0.82,
spring: 0.52,
rise: 0.68
},
{
cx: -1.08,
bottom: 3.43,
width: 0.82,
spring: 0.52,
rise: 0.68
}
],
position: new THREE.Vector3(2.08, baseY, 0),
rotationY: -Math.PI / 2,
material: plasterLight
});
// Bright section faces make the architectural cut legible.
addBox(
0.08,
facadeHeight,
0.32,
cutMaterial,
0.08,
baseY + facadeHeight / 2,
2.08
);
addBox(
0.32,
facadeHeight,
0.08,
cutMaterial,
2.08,
baseY + facadeHeight / 2,
-0.08
);
// Upper frame, also partially sectioned.
addBox(
4.72,
0.22,
0.56,
plasterLight,
0,
6.02,
-1.9
);
addBox(
0.56,
0.22,
4.18,
plasterLight,
-1.9,
6.02,
0.18
);
addBox(
2.18,
0.22,
0.56,
plasterLight,
-1.0,
6.02,
2.08
);
addBox(
0.56,
0.22,
2.0,
plasterLight,
2.08,
6.02,
-1.08
);
// Mid-level gallery ledges around the central shaft.
addBox(
4.28,
0.14,
1.22,
plasterLight,
0,
2.73,
-1.47
);
addBox(
1.22,
0.14,
2.92,
plasterLight,
-1.47,
2.73,
-0.39
);
// Small triangular plaster reliefs.
addTriangleRelief(new THREE.Vector3(0, 4.87, -1.91), 0);
addTriangleRelief(new THREE.Vector3(-1.91, 4.87, 0), Math.PI / 2);
// ---------------------------------------------------------------------
// Central ventilation shaft, also quarter-cut
// ---------------------------------------------------------------------
const shaftHeight = 5.47;
addBox(
1.64,
0.16,
1.64,
plasterDark,
0,
0.48,
0
);
addBox(
1.28,
0.07,
1.28,
interiorMaterial,
0,
0.58,
0
);
const shaftVent = [
{
cx: 0,
bottom: 0.55,
width: 0.52,
spring: 0.34,
rise: 0.38
},
{
cx: 0,
bottom: 4.55,
width: 0.52,
spring: 0.34,
rise: 0.38
}
];
addFacade({
xMin: -0.68,
xMax: 0.68,
height: shaftHeight,
thickness: 0.17,
holes: shaftVent,
position: new THREE.Vector3(0, baseY, -0.68),
material: shaftMaterial
});
addFacade({
xMin: -0.68,
xMax: 0.68,
height: shaftHeight,
thickness: 0.17,
holes: shaftVent,
position: new THREE.Vector3(-0.68, baseY, 0),
rotationY: Math.PI / 2,
material: shaftMaterial
});
addFacade({
xMin: -0.68,
xMax: 0,
height: shaftHeight,
thickness: 0.17,
holes: [],
position: new THREE.Vector3(0, baseY, 0.68),
material: shaftMaterial
});
addFacade({
xMin: -0.68,
xMax: 0,
height: shaftHeight,
thickness: 0.17,
holes: [],
position: new THREE.Vector3(0.68, baseY, 0),
rotationY: -Math.PI / 2,
material: shaftMaterial
});
// Sectioned shaft edges.
addBox(
0.08,
shaftHeight,
0.18,
cutMaterial,
0,
baseY + shaftHeight / 2,
0.68
);
addBox(
0.18,
shaftHeight,
0.08,
cutMaterial,
0.68,
baseY + shaftHeight / 2,
0
);
// Partially retained cap and louvres.
addBox(
1.62,
0.15,
0.34,
plasterLight,
0,
6.01,
-0.58
);
addBox(
0.34,
0.15,
1.62,
plasterLight,
-0.58,
6.01,
0
);
addBox(
1.56,
0.13,
0.78,
plasterLight,
0,
6.06,
-0.39
);
for (let i = 0; i < 3; i++) {
addBox(
0.72,
0.07,
0.12,
timberMaterial,
0,
5.24 + i * 0.18,
-0.56
);
}
// ---------------------------------------------------------------------
// Distant Dubai skyline
// ---------------------------------------------------------------------
let seed = 137;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
for (let i = 0; i < 23; i++) {
const width = 0.8 + random() * 1.65;
const depth = 0.8 + random() * 1.5;
const height = 1.5 + random() * 4.7;
const x = -17 + i * 1.52 + random() * 0.5;
const z = -12.5 - random() * 8.5;
const building = addBox(
width,
height,
depth,
distantMaterial,
x,
height / 2,
z,
scene
);
building.castShadow = false;
}
// Abstract, low-poly stepped tower in the distant skyline.
const landmark = new THREE.Group();
landmark.position.set(-9.3, 0, -17.5);
scene.add(landmark);
let landmarkY = 0;
for (let i = 0; i < 8; i++) {
const radius = 0.95 * (1 - i * 0.105);
const height = 1.45;
const section = new THREE.Mesh(
new THREE.CylinderGeometry(
radius * 0.83,
radius,
height,
8
),
skylineMaterial
);
section.position.y = landmarkY + height / 2;
landmark.add(section);
landmarkY += height;
}
const spire = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 2.1, 8),
skylineMaterial
);
spire.position.y = landmarkY + 1.05;
landmark.add(spire);
// ---------------------------------------------------------------------
// Simplified airflow arrows
// ---------------------------------------------------------------------
const airflowGroup = new THREE.Group();
scene.add(airflowGroup);
const arrows = [];
function addFlowArrow(start, direction, length, phase = 0) {
const arrow = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0x32d5e6,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const headLength = Math.min(0.34, length * 0.3);
const bodyLength = Math.max(0.05, length - headLength);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, bodyLength, 6),
material
);
shaft.rotation.x = Math.PI / 2;
shaft.position.z = bodyLength / 2;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.13, headLength, 6),
material
);
head.rotation.x = Math.PI / 2;
head.position.z = bodyLength + headLength / 2;
arrow.add(shaft, head);
arrow.position.copy(start);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
arrow.userData.phase = phase;
arrow.userData.material = material;
airflowGroup.add(arrow);
arrows.push(arrow);
return arrow;
}
// Wind approaches the upper side opening.
addFlowArrow(
new THREE.Vector3(5.25, 4.03, -1.05),
new THREE.Vector3(-1, 0, 0),
2.35,
0
);
addFlowArrow(
new THREE.Vector3(3.4, 4.03, -1.05),
new THREE.Vector3(-1, 0, 0),
1.55,
1.2
);
addFlowArrow(
new THREE.Vector3(1.9, 4.03, -1.05),
new THREE.Vector3(-1, 0, 0),
1.55,
2.1
);
// Air descends through the central shaft.
addFlowArrow(
new THREE.Vector3(0.16, 5.62, 0.15),
new THREE.Vector3(0, -1, 0),
1.5,
0.7
);
addFlowArrow(
new THREE.Vector3(0.16, 4.0, 0.15),
new THREE.Vector3(0, -1, 0),
1.45,
1.9
);
addFlowArrow(
new THREE.Vector3(0.16, 2.55, 0.15),
new THREE.Vector3(0, -1, 0),
1.25,
3.0
);
// Air leaves through the low opening.
addFlowArrow(
new THREE.Vector3(0.16, 1.13, 0.45),
new THREE.Vector3(0, 0, 1),
1.85,
1.4
);
addFlowArrow(
new THREE.Vector3(0.16, 1.13, 2.0),
new THREE.Vector3(0, 0, 1),
1.35,
2.7
);
// Moving particles reinforce the direction of the airflow.
const particlePaths = [
{
start: new THREE.Vector3(5.8, 4.03, -1.05),
end: new THREE.Vector3(0.16, 4.03, -1.05)
},
{
start: new THREE.Vector3(0.16, 5.7, 0.15),
end: new THREE.Vector3(0.16, 0.82, 0.15)
},
{
start: new THREE.Vector3(0.16, 1.13, 0.35),
end: new THREE.Vector3(0.16, 1.13, 3.25)
}
];
const particles = [];
for (const path of particlePaths) {
for (let i = 0; i < 3; i++) {
const material = new THREE.MeshBasicMaterial({
color: 0xb3f8ff,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const particle = new THREE.Mesh(
new THREE.OctahedronGeometry(0.055, 0),
material
);
particle.userData = {
start: path.start,
end: path.end,
offset: i / 3
};
airflowGroup.add(particle);
particles.push(particle);
}
}
// ---------------------------------------------------------------------
// Custom camera controls: no external controls addon
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 2.85, 0);
const defaultView = {
theta: 0.72,
phi: 1.02,
radius: 11.7
};
let theta = defaultView.theta;
let phi = defaultView.phi;
let radius = defaultView.radius;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
theta = defaultView.theta;
phi = defaultView.phi;
radius = defaultView.radius;
updateCamera();
}
function zoomBy(multiplier) {
radius = THREE.MathUtils.clamp(radius * multiplier, 5.8, 19);
updateCamera();
}
const pointers = new Map();
let dragging = false;
let previousX = 0;
let previousY = 0;
let pinchDistance = 0;
function currentPinchDistance() {
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) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (pointers.size === 2) {
dragging = false;
pinchDistance = currentPinchDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2) {
const distance = currentPinchDistance();
if (pinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / distance),
5.8,
19
);
updateCamera();
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi - dy * 0.005, 0.34, 1.43);
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
dragging = false;
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomBy(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
theta += 0.08;
updateCamera();
} else if (event.key === "ArrowRight") {
theta -= 0.08;
updateCamera();
} else if (event.key === "ArrowUp") {
phi = Math.max(0.34, phi - 0.06);
updateCamera();
} else if (event.key === "ArrowDown") {
phi = Math.min(1.43, phi + 0.06);
updateCamera();
}
});
document.getElementById("reset").addEventListener("click", resetCamera);
document.getElementById("zoomIn").addEventListener("click", () => zoomBy(0.86));
document.getElementById("zoomOut").addEventListener("click", () => zoomBy(1.16));
const airflowButton = document.getElementById("airflow");
airflowButton.addEventListener("click", () => {
const visible = !airflowGroup.visible;
airflowGroup.visible = visible;
airflowButton.classList.toggle("active", visible);
airflowButton.setAttribute("aria-pressed", String(visible));
airflowButton.textContent = visible ? "Airflow on" : "Airflow off";
});
// ---------------------------------------------------------------------
// Screen-space labels
// ---------------------------------------------------------------------
const labels = [
{
element: document.getElementById("inletLabel"),
position: new THREE.Vector3(2.7, 4.55, -1.05)
},
{
element: document.getElementById("shaftLabel"),
position: new THREE.Vector3(-0.12, 2.85, 0.25)
},
{
element: document.getElementById("outletLabel"),
position: new THREE.Vector3(0.18, 1.3, 2.0)
}
];
function updateLabels() {
for (const label of labels) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
label.element.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
}
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", onResize);
updateCamera();
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
if (!reducedMotion) {
for (const arrow of arrows) {
const wave = Math.sin(time * 2.1 + arrow.userData.phase);
arrow.userData.material.opacity = 0.58 + wave * 0.22;
arrow.scale.z = 0.96 + wave * 0.055;
}
for (const particle of particles) {
const t =
(time * 0.22 + particle.userData.offset) % 1;
particle.position.lerpVectors(
particle.userData.start,
particle.userData.end,
t
);
particle.rotation.y = time * 1.8;
particle.rotation.x = time * 1.1;
particle.material.opacity = 0.35 + Math.sin(t * Math.PI) * 0.55;
}
}
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```