Prompt specification
Build or customize the Three.js 3D scene "Opposite openings in a room shell" 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: Opposite openings in a room shell
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/opposite-openings-in-a-room-shell-x2189
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Build a simple room shell with openings on opposite walls. Draw a continuous illustrative airflow ribbon connecting them and label the assumed wind direction.
Working Three.js Starter (opposite-openings-in-a-room-shell-x2189):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Illustrative Cross-Room Airflow</title>
<style>
:root {
--ink: #17343b;
--muted: #587077;
--accent: #17aeb4;
--panel: rgba(250, 253, 251, 0.82);
--line: rgba(23, 52, 59, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eaf0ed;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 28px;
left: 30px;
width: min(360px, calc(100vw - 60px));
padding: 18px 20px 17px;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(31, 62, 67, 0.09);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 2.4vw, 31px);
font-weight: 650;
letter-spacing: -0.035em;
line-height: 1.08;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
bottom: 30px;
left: 30px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
color: var(--muted);
font-size: 11px;
backdrop-filter: blur(10px);
}
.swatch {
width: 30px;
height: 7px;
border-radius: 99px;
background: linear-gradient(90deg, #39d2c5, #3c7df0);
box-shadow: 0 0 10px rgba(41, 176, 198, 0.38);
}
.controls {
position: absolute;
right: 30px;
bottom: 30px;
max-width: calc(100vw - 60px);
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
color: var(--muted);
font-size: 11px;
text-align: right;
backdrop-filter: blur(10px);
}
.world-label {
position: absolute;
z-index: 3;
padding: 9px 12px;
border: 1px solid rgba(20, 65, 73, 0.18);
border-radius: 10px;
background: rgba(251, 254, 253, 0.91);
color: #17343b;
box-shadow: 0 8px 24px rgba(28, 63, 67, 0.12);
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 160ms ease;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.world-label::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 12px;
background: rgba(23, 52, 59, 0.32);
}
.world-label small {
display: block;
margin-bottom: 3px;
color: #658087;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.world-label strong {
font-size: 11px;
font-weight: 750;
letter-spacing: 0.03em;
}
.direction-label {
padding: 11px 15px;
border-color: rgba(16, 151, 159, 0.25);
background: rgba(241, 255, 253, 0.94);
text-align: center;
}
.direction-label strong {
color: #087e88;
font-size: 12px;
}
.direction-label i {
display: inline-block;
margin: 0 4px;
font-style: normal;
}
@media (max-width: 700px) {
.title-card {
top: 16px;
left: 16px;
width: calc(100vw - 32px);
padding: 14px 16px;
}
.subtitle {
max-width: 270px;
}
.legend {
bottom: 16px;
left: 16px;
}
.controls {
right: 16px;
bottom: 16px;
display: none;
}
.world-label {
transform: translate(-50%, -100%) scale(0.88);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Spatial study / 01</div>
<h1>Cross-room airflow</h1>
<p class="subtitle">
Illustrative stream through openings on opposite side walls.
The path is conceptual, not a fluid simulation.
</p>
</section>
<div class="legend">
<span class="swatch"></span>
<span>Illustrative airflow ribbon</span>
</div>
<div class="controls">
Drag to orbit · Scroll to zoom · Shift-drag to pan · Double-click to reset
</div>
<div id="inletLabel" class="world-label">
<small>Opening A</small>
<strong>INLET</strong>
</div>
<div id="directionLabel" class="world-label direction-label">
<small>Assumed wind direction</small>
<strong>LEFT OPENING <i>→</i> RIGHT OPENING</strong>
</div>
<div id="outletLabel" class="world-label">
<small>Opening B</small>
<strong>OUTLET</strong>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Stylized room with an illustrative airflow ribbon connecting opposite openings"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf0ed);
scene.fog = new THREE.Fog(0xeaf0ed, 22, 48);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8aa49d, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff3dc, 3.1);
sun.position.set(-7, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb7e9ee, 0.85);
fill.position.set(8, 6, 5);
scene.add(fill);
// ------------------------------------------------------------
// Materials and geometry helpers
// ------------------------------------------------------------
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xf1eee6,
roughness: 0.84,
metalness: 0.02
});
const sideWallMaterial = new THREE.MeshStandardMaterial({
color: 0xe5ebe6,
roughness: 0.88,
metalness: 0.01
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xf8f5ec,
roughness: 0.91
});
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xcbd8d2,
roughness: 0.82
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x31565c,
roughness: 0.58,
metalness: 0.08
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0xa8bbb5,
roughness: 0.76
});
const outlineMaterial = new THREE.LineBasicMaterial({
color: 0x57716c,
transparent: true,
opacity: 0.19
});
function addBox(
width,
height,
depth,
x,
y,
z,
material,
{
cast = true,
receive = true,
outline = false
} = {}
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
scene.add(mesh);
if (outline) {
const edgeGeometry = new THREE.EdgesGeometry(geometry, 25);
const edges = new THREE.LineSegments(edgeGeometry, outlineMaterial);
edges.position.copy(mesh.position);
scene.add(edges);
}
return mesh;
}
// ------------------------------------------------------------
// Room shell
// ------------------------------------------------------------
const ROOM_WIDTH = 12;
const ROOM_DEPTH = 10;
const ROOM_HEIGHT = 5.2;
const HALF_WIDTH = ROOM_WIDTH / 2;
const HALF_DEPTH = ROOM_DEPTH / 2;
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe5ece8,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.35;
ground.receiveShadow = true;
scene.add(ground);
addBox(
12.9,
0.28,
10.9,
0,
-0.18,
0,
platformMaterial,
{ outline: true }
);
addBox(
ROOM_WIDTH,
0.18,
ROOM_DEPTH,
0,
-0.04,
0,
floorMaterial,
{ outline: true }
);
const floorGrid = new THREE.GridHelper(10, 20, 0x9ebbb4, 0xc8d8d2);
floorGrid.position.y = 0.058;
floorGrid.scale.x = 1.2;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.28;
floorGrid.material.depthWrite = false;
scene.add(floorGrid);
// Back wall closes the room; the front remains open as a cutaway.
addBox(
12.35,
ROOM_HEIGHT,
0.28,
0,
ROOM_HEIGHT / 2,
-5.04,
wallMaterial,
{ outline: true }
);
const openingHalfDepth = 1.65;
const openingBottom = 1.15;
const openingTop = 3.85;
const openingHeight = openingTop - openingBottom;
const openingCenterY = (openingBottom + openingTop) / 2;
const endPanelDepth = HALF_DEPTH - openingHalfDepth;
function buildSideWall(x) {
const thickness = 0.28;
// Lower wall band.
addBox(
thickness,
openingBottom,
ROOM_DEPTH + 0.25,
x,
openingBottom / 2,
0,
sideWallMaterial,
{ outline: true }
);
// Upper wall band.
addBox(
thickness,
ROOM_HEIGHT - openingTop,
ROOM_DEPTH + 0.25,
x,
openingTop + (ROOM_HEIGHT - openingTop) / 2,
0,
sideWallMaterial,
{ outline: true }
);
// Front and rear portions surrounding the opening.
for (const sign of [-1, 1]) {
addBox(
thickness,
openingHeight,
endPanelDepth,
x,
openingCenterY,
sign * (openingHalfDepth + endPanelDepth / 2),
sideWallMaterial,
{ outline: true }
);
}
// Dark portal frame around the opening.
for (const sign of [-1, 1]) {
addBox(
0.4,
openingHeight + 0.34,
0.18,
x,
openingCenterY,
sign * (openingHalfDepth + 0.08),
frameMaterial
);
}
addBox(
0.4,
0.18,
openingHalfDepth * 2 + 0.35,
x,
openingBottom - 0.08,
0,
frameMaterial
);
addBox(
0.4,
0.18,
openingHalfDepth * 2 + 0.35,
x,
openingTop + 0.08,
0,
frameMaterial
);
// Projecting sill.
addBox(
0.56,
0.12,
openingHalfDepth * 2 + 0.38,
x,
openingBottom - 0.12,
0,
trimMaterial
);
}
buildSideWall(-HALF_WIDTH);
buildSideWall(HALF_WIDTH);
// Interior skirting and upper perimeter trim.
addBox(
12.05,
0.18,
0.12,
0,
0.15,
-4.84,
trimMaterial
);
for (const x of [-5.84, 5.84]) {
addBox(0.12, 0.18, 9.9, x, 0.15, 0, trimMaterial);
addBox(0.38, 0.18, 10.2, x, 5.15, 0, trimMaterial);
}
addBox(12.35, 0.18, 0.38, 0, 5.15, -4.86, trimMaterial);
// ------------------------------------------------------------
// Illustrative airflow path
// ------------------------------------------------------------
const airflowCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-7.15, 2.55, 0.00),
new THREE.Vector3(-5.65, 2.48, -0.32),
new THREE.Vector3(-4.10, 3.10, -1.12),
new THREE.Vector3(-2.10, 3.34, -0.92),
new THREE.Vector3(0.00, 2.83, 0.18),
new THREE.Vector3(2.05, 3.40, 1.12),
new THREE.Vector3(4.05, 3.15, 0.78),
new THREE.Vector3(5.65, 2.64, 0.14),
new THREE.Vector3(7.15, 2.55, 0.00)
],
false,
"centripetal",
0.5
);
const ribbonSegments = 160;
const ribbonWidth = 0.78;
const positions = [];
const normals = [];
const uvs = [];
const colors = [];
const indices = [];
const edgeA = [];
const edgeB = [];
const startColor = new THREE.Color(0x39d2c5);
const endColor = new THREE.Color(0x3c7df0);
const worldUp = new THREE.Vector3(0, 1, 0);
for (let i = 0; i <= ribbonSegments; i++) {
const t = i / ribbonSegments;
const point = airflowCurve.getPointAt(t);
const tangent = airflowCurve.getTangentAt(t).normalize();
const side = new THREE.Vector3()
.crossVectors(worldUp, tangent)
.normalize();
// A slight twist makes the strip read as a flowing ribbon.
side.applyAxisAngle(tangent, Math.sin(t * Math.PI * 2) * 0.24);
const normal = new THREE.Vector3()
.crossVectors(tangent, side)
.normalize();
const taper = 0.76 + Math.sin(Math.PI * t) * 0.24;
const halfWidth = (ribbonWidth * taper) / 2;
const a = point.clone().addScaledVector(side, halfWidth);
const b = point.clone().addScaledVector(side, -halfWidth);
positions.push(a.x, a.y, a.z, b.x, b.y, b.z);
normals.push(
normal.x, normal.y, normal.z,
normal.x, normal.y, normal.z
);
uvs.push(t, 0, t, 1);
const color = new THREE.Color().lerpColors(startColor, endColor, t);
colors.push(color.r, color.g, color.b, color.r, color.g, color.b);
edgeA.push(a.clone());
edgeB.push(b.clone());
if (i < ribbonSegments) {
const v0 = i * 2;
const v1 = v0 + 1;
const v2 = v0 + 2;
const v3 = v0 + 3;
indices.push(v0, v1, v2, v1, v3, v2);
}
}
const ribbonGeometry = new THREE.BufferGeometry();
ribbonGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
ribbonGeometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
ribbonGeometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
ribbonGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
ribbonGeometry.setIndex(indices);
const ribbonMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
vertexColors: true,
transparent: true,
opacity: 0.62,
roughness: 0.28,
metalness: 0.02,
clearcoat: 0.25,
clearcoatRoughness: 0.35,
emissive: 0x0b4650,
emissiveIntensity: 0.15,
side: THREE.DoubleSide,
depthWrite: false
});
const ribbon = new THREE.Mesh(ribbonGeometry, ribbonMaterial);
ribbon.renderOrder = 3;
scene.add(ribbon);
// Fine outlines make the continuous strip easy to read.
const edgeMaterial = new THREE.MeshBasicMaterial({
color: 0x087f8c,
transparent: true,
opacity: 0.78
});
for (const edgePoints of [edgeA, edgeB]) {
const edgeCurve = new THREE.CatmullRomCurve3(edgePoints);
const edgeGeometry = new THREE.TubeGeometry(
edgeCurve,
ribbonSegments,
0.018,
5,
false
);
const edgeMesh = new THREE.Mesh(edgeGeometry, edgeMaterial);
edgeMesh.renderOrder = 4;
scene.add(edgeMesh);
}
// Small arrowheads establish the assumed left-to-right direction.
const arrowGeometry = new THREE.ConeGeometry(0.12, 0.34, 12);
const arrowMaterial = new THREE.MeshBasicMaterial({
color: 0xf2ffff,
transparent: true,
opacity: 0.9
});
const arrowPositions = [0.17, 0.35, 0.53, 0.71, 0.84];
for (const t of arrowPositions) {
const arrow = new THREE.Mesh(arrowGeometry, arrowMaterial);
const point = airflowCurve.getPointAt(t);
const tangent = airflowCurve.getTangentAt(t).normalize();
const side = new THREE.Vector3()
.crossVectors(worldUp, tangent)
.normalize();
const normal = new THREE.Vector3()
.crossVectors(tangent, side)
.normalize();
arrow.position.copy(point).addScaledVector(normal, 0.07);
arrow.quaternion.setFromUnitVectors(worldUp, tangent);
arrow.renderOrder = 5;
scene.add(arrow);
}
// Moving streaks animate the apparent flow without a simulation.
const streakGeometry = new THREE.CylinderGeometry(0.018, 0.018, 0.24, 6);
const streakMaterial = new THREE.MeshBasicMaterial({
color: 0xeaffff,
transparent: true,
opacity: 0.78
});
const streaks = [];
for (let i = 0; i < 18; i++) {
const mesh = new THREE.Mesh(streakGeometry, streakMaterial);
mesh.renderOrder = 5;
scene.add(mesh);
streaks.push({
mesh,
phase: i / 18,
offset: ((i % 3) - 1) * 0.19
});
}
// ------------------------------------------------------------
// Camera controls: implemented directly, without addons
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.12, 0),
targetGoal: new THREE.Vector3(0, 2.12, 0),
spherical: new THREE.Spherical(16.5, 1.23, 0),
sphericalGoal: new THREE.Spherical(16.5, 1.23, 0)
};
const pointers = new Map();
let pinchDistance = 0;
function resetView() {
controls.targetGoal.set(0, 2.12, 0);
controls.sphericalGoal.set(
window.innerWidth < 700 ? 21.5 : 16.5,
1.23,
0
);
}
function updatePointerPan(dx, dy) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const panScale = controls.spherical.radius * 0.00145;
controls.targetGoal.addScaledVector(right, -dx * panScale);
controls.targetGoal.addScaledVector(up, dy * panScale);
controls.targetGoal.x = THREE.MathUtils.clamp(
controls.targetGoal.x,
-5,
5
);
controls.targetGoal.y = THREE.MathUtils.clamp(
controls.targetGoal.y,
0.5,
4.5
);
controls.targetGoal.z = THREE.MathUtils.clamp(
controls.targetGoal.z,
-5,
5
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus({ preventScroll: true });
if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
if (event.shiftKey) {
updatePointerPan(dx, dy);
} else {
controls.sphericalGoal.theta -= dx * 0.006;
controls.sphericalGoal.phi = THREE.MathUtils.clamp(
controls.sphericalGoal.phi - dy * 0.005,
0.42,
1.48
);
}
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0 && distance > 0) {
controls.sphericalGoal.radius = THREE.MathUtils.clamp(
controls.sphericalGoal.radius * (pinchDistance / distance),
9,
28
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.sphericalGoal.radius = THREE.MathUtils.clamp(
controls.sphericalGoal.radius * Math.exp(event.deltaY * 0.001),
9,
28
);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") {
controls.sphericalGoal.theta += 0.08;
} else if (key === "arrowright") {
controls.sphericalGoal.theta -= 0.08;
} else if (key === "arrowup") {
controls.sphericalGoal.phi = THREE.MathUtils.clamp(
controls.sphericalGoal.phi - 0.06,
0.42,
1.48
);
} else if (key === "arrowdown") {
controls.sphericalGoal.phi = THREE.MathUtils.clamp(
controls.sphericalGoal.phi + 0.06,
0.42,
1.48
);
} else if (key === "+" || key === "=") {
controls.sphericalGoal.radius = THREE.MathUtils.clamp(
controls.sphericalGoal.radius - 0.7,
9,
28
);
} else if (key === "-") {
controls.sphericalGoal.radius = THREE.MathUtils.clamp(
controls.sphericalGoal.radius + 0.7,
9,
28
);
} else if (key === "home") {
resetView();
} else {
return;
}
event.preventDefault();
});
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 10);
controls.spherical.radius +=
(controls.sphericalGoal.radius - controls.spherical.radius) * damping;
controls.spherical.phi +=
(controls.sphericalGoal.phi - controls.spherical.phi) * damping;
controls.spherical.theta +=
(controls.sphericalGoal.theta - controls.spherical.theta) * damping;
controls.target.lerp(controls.targetGoal, damping);
camera.position
.setFromSpherical(controls.spherical)
.add(controls.target);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
// ------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------
const inletLabel = document.getElementById("inletLabel");
const directionLabel = document.getElementById("directionLabel");
const outletLabel = document.getElementById("outletLabel");
const inletAnchor = new THREE.Vector3(-7.15, 4.28, 0);
const directionAnchor = new THREE.Vector3(0, 5.72, 0.25);
const outletAnchor = new THREE.Vector3(7.15, 4.28, 0);
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
// ------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
if (window.innerWidth < 700) {
controls.spherical.radius = 21.5;
controls.sphericalGoal.radius = 21.5;
}
camera.position
.setFromSpherical(controls.spherical)
.add(controls.target);
camera.lookAt(controls.target);
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(dt);
for (const streak of streaks) {
const t = (streak.phase + elapsed * 0.058) % 1;
const point = airflowCurve.getPointAt(t);
const tangent = airflowCurve.getTangentAt(t).normalize();
const side = new THREE.Vector3()
.crossVectors(worldUp, tangent)
.normalize();
streak.mesh.position
.copy(point)
.addScaledVector(side, streak.offset);
streak.mesh.quaternion.setFromUnitVectors(worldUp, tangent);
}
ribbonMaterial.opacity = 0.59 + Math.sin(elapsed * 1.6) * 0.035;
positionLabel(inletLabel, inletAnchor);
positionLabel(directionLabel, directionAnchor);
positionLabel(outletLabel, outletAnchor);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```