Prompt specification
Build or customize the Three.js 3D scene "Workshop Wall and Neighbor Window" 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: Workshop Wall and Neighbor Window
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/workshop-wall-and-neighbor-window-x3149
Scene Description Prompt:
Show sound spreading from a vibrating workshop machine toward a neighboring home in a low-poly schematic cutaway. Three.js from cdnjs, one HTML file.
Working Three.js Starter (workshop-wall-and-neighbor-window-x3149):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Workshop Vibration — Acoustic Cutaway</title>
<style>
:root {
--ink: #17343b;
--muted: #61777b;
--paper: rgba(250, 249, 242, 0.9);
--line: rgba(23, 52, 59, 0.14);
--cyan: #009eaa;
--orange: #ef9c32;
--coral: #d86650;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 18%, #f5f3e9 0, #e4ece7 42%, #d7e3df 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
background: var(--paper);
box-shadow: 0 12px 35px rgba(41, 70, 70, 0.11);
backdrop-filter: blur(12px);
}
#title-card {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 20px 22px 19px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
background: var(--cyan);
content: "";
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 1.02;
}
.subtitle {
max-width: 330px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#status-card {
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 10px;
padding: 11px 14px;
border-radius: 999px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
position: relative;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 0 4px rgba(0, 158, 170, 0.12);
}
.status-dot::after {
position: absolute;
inset: -5px;
border: 1px solid var(--cyan);
border-radius: 50%;
animation: ping 1.8s ease-out infinite;
content: "";
}
@keyframes ping {
0% {
opacity: 0.75;
transform: scale(0.65);
}
80%,
100% {
opacity: 0;
transform: scale(1.65);
}
}
#legend {
bottom: 22px;
left: 22px;
max-width: calc(100vw - 44px);
padding: 14px 17px;
border-radius: 15px;
}
.legend-row {
display: flex;
flex-wrap: wrap;
gap: 12px 18px;
align-items: center;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #425e63;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.045em;
text-transform: uppercase;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.swatch.source {
background: var(--orange);
}
.swatch.wave {
border-radius: 50%;
background: var(--cyan);
}
.swatch.receiver {
background: var(--coral);
}
.hint {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
color: #718589;
font-size: 10px;
line-height: 1.4;
}
#controls {
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border-radius: 14px;
}
button {
height: 34px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 9px;
background: #fffdf7;
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
background: #eef5f1;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.speed-control {
display: flex;
align-items: center;
gap: 8px;
height: 34px;
padding: 0 11px;
border-left: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
}
input[type="range"] {
width: 74px;
accent-color: var(--cyan);
cursor: pointer;
}
.scene-label {
position: fixed;
z-index: 4;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid rgba(23, 52, 59, 0.13);
border-radius: 8px;
background: rgba(255, 253, 247, 0.9);
box-shadow: 0 5px 16px rgba(28, 55, 57, 0.09);
color: #294a50;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 17px;
background: rgba(23, 52, 59, 0.25);
content: "";
}
.scene-label .dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
}
#source-label .dot {
background: var(--orange);
}
#home-label .dot {
background: var(--coral);
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
h1 {
font-size: 26px;
}
.subtitle {
max-width: 280px;
font-size: 11px;
}
#status-card {
top: 142px;
right: 12px;
}
#legend {
bottom: 72px;
left: 12px;
}
#controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: flex-end;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive acoustic cutaway of a workshop and neighboring home"></main>
<section id="title-card" class="panel">
<div class="eyebrow">Acoustic transfer · section A–A</div>
<h1>When the workshop shakes</h1>
<p class="subtitle">
Low-frequency vibration becomes airborne sound, crosses the shared
boundary, and reaches the neighboring home.
</p>
</section>
<section id="status-card" class="panel">
<span class="status-dot"></span>
<span id="status-text">Live propagation</span>
</section>
<div id="source-label" class="scene-label">
<span class="dot"></span>
Vibration source
</div>
<div id="wave-label" class="scene-label">
<span class="dot"></span>
Expanding sound field
</div>
<div id="home-label" class="scene-label">
<span class="dot"></span>
Neighboring home
</div>
<section id="legend" class="panel">
<div class="legend-row">
<div class="legend-item">
<span class="swatch source"></span>
Mechanical vibration
</div>
<div class="legend-item">
<span class="swatch wave"></span>
Sound wavefront
</div>
<div class="legend-item">
<span class="swatch receiver"></span>
Received energy
</div>
</div>
<div class="hint">
Drag to orbit · Wheel/pinch to zoom · Shift-drag or right-drag to pan
</div>
</section>
<section id="controls" class="panel">
<button id="pause-button" type="button">Pause</button>
<button id="reset-button" type="button">Reset view</button>
<label class="speed-control">
Speed
<input id="speed" type="range" min="0.4" max="1.6" step="0.1" value="1">
</label>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly workshop vibration and sound propagation scene"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe1ebe6, 25, 42);
const camera = new THREE.OrthographicCamera(-9, 9, 5.5, -5.5, 0.1, 80);
const orbit = {
theta: 0.54,
phi: 0.94,
radius: 16,
target: new THREE.Vector3(0, 0.8, 0),
zoom: 1
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
let viewWidth = 18.5;
let viewHeight = viewWidth / aspect;
if (viewHeight < 10.7) {
viewHeight = 10.7;
viewWidth = viewHeight * aspect;
}
camera.left = -viewWidth / 2;
camera.right = viewWidth / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// Scene lighting.
scene.add(new THREE.HemisphereLight(0xf8fbf4, 0x718487, 2.1));
const sun = new THREE.DirectionalLight(0xfff2d5, 3.25);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbfe6e8, 1.1);
fill.position.set(8, 5, -8);
scene.add(fill);
const palette = {
ground: 0xdce6e1,
site: 0xe9e5d9,
grid: 0x9aa9a4,
workshopFloor: 0xd8c6a9,
workshopWall: 0xaebfba,
workshopFrame: 0x3f5a5c,
homeFloor: 0xe8d5ba,
homeWall: 0xf0d7b8,
roof: 0xc9614d,
navy: 0x294b57,
dark: 0x203a42,
orange: 0xef9c32,
orangeDark: 0xb86a26,
teal: 0x009eaa,
tealLight: 0x75d5d4,
coral: 0xd86650,
cream: 0xf8f3e7,
wood: 0xb78458,
green: 0x5d8c68
};
function material(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02,
flatShading: true,
...extra
});
}
function addMesh(
geometry,
mat,
position = [0, 0, 0],
parent = scene,
outline = false,
outlineColor = 0x29454a
) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outline) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 28),
new THREE.LineBasicMaterial({
color: outlineColor,
transparent: true,
opacity: 0.28
})
);
mesh.add(edges);
}
return mesh;
}
function addBox(w, h, d, color, position, parent = scene, outline = false) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material(color),
position,
parent,
outline
);
}
function addCylinder(
radius,
height,
color,
position,
parent = scene,
radialSegments = 12,
outline = false
) {
return addMesh(
new THREE.CylinderGeometry(radius, radius, height, radialSegments),
material(color),
position,
parent,
outline
);
}
function beam(a, b, width, depth, color, parent = scene, outline = false) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = addBox(
length,
width,
depth,
color,
midpoint.toArray(),
parent,
outline
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(1, 0, 0),
direction.normalize()
);
return mesh;
}
// Ground and schematic site.
const ground = addMesh(
new THREE.PlaneGeometry(50, 32),
material(palette.ground),
[0, -0.34, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
addBox(
18.4,
0.28,
7.4,
palette.site,
[0, -0.16, 0],
scene,
true
);
const gridPoints = [];
for (let x = -9; x <= 9; x += 1) {
gridPoints.push(x, 0.005, -3.5, x, 0.005, 3.5);
}
for (let z = -3.5; z <= 3.5; z += 1) {
gridPoints.push(-9, 0.005, z, 9, 0.005, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPoints, 3)
);
scene.add(
new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: palette.grid,
transparent: true,
opacity: 0.15
})
)
);
// Workshop shell: back and left walls are retained as a cutaway.
const workshop = new THREE.Group();
scene.add(workshop);
addBox(5.4, 0.16, 3.8, palette.workshopFloor, [-3.7, 0.08, 0], workshop, true);
addBox(5.4, 3.0, 0.16, palette.workshopWall, [-3.7, 1.58, -1.9], workshop, true);
addBox(0.16, 2.75, 3.8, palette.workshopWall, [-6.3, 1.46, 0], workshop, true);
addBox(5.5, 0.18, 0.2, palette.workshopFrame, [-3.7, 3.1, -1.9], workshop, true);
addBox(0.2, 0.18, 3.9, palette.workshopFrame, [-6.3, 2.9, 0], workshop, true);
beam([-6.3, 2.95, -1.9], [-0.95, 2.95, -1.9], 0.15, 0.15, palette.workshopFrame, workshop);
beam([-6.25, 2.95, -1.9], [-3.7, 3.35, -1.9], 0.14, 0.14, palette.workshopFrame, workshop);
beam([-3.7, 3.35, -1.9], [-1.0, 2.95, -1.9], 0.14, 0.14, palette.workshopFrame, workshop);
// Workshop shelves and stored parts.
addBox(1.45, 0.12, 0.55, palette.wood, [-5.35, 1.3, -1.48], workshop, true);
addBox(1.45, 0.12, 0.55, palette.wood, [-5.35, 2.05, -1.48], workshop, true);
for (let i = 0; i < 3; i++) {
addBox(
0.33,
0.35 + (i % 2) * 0.12,
0.36,
[0x9ca9a1, 0xc59562, 0x718a83][i],
[-5.82 + i * 0.43, 1.56 + (i % 2) * 0.06, -1.47],
workshop,
true
);
}
addBox(1.35, 0.14, 0.72, palette.wood, [-5.4, 0.98, 0.72], workshop, true);
addBox(0.12, 0.8, 0.12, palette.dark, [-5.9, 0.53, 0.48], workshop);
addBox(0.12, 0.8, 0.12, palette.dark, [-4.9, 0.53, 0.48], workshop);
addBox(0.52, 0.36, 0.42, palette.orange, [-5.25, 1.23, 0.7], workshop, true);
// Vibrating industrial machine.
const machine = new THREE.Group();
machine.position.set(-3.8, 0, 0);
scene.add(machine);
addBox(2.55, 0.34, 1.55, palette.navy, [0, 0.38, 0], machine, true);
for (const x of [-0.95, 0.95]) {
for (const z of [-0.56, 0.56]) {
addBox(0.34, 0.24, 0.34, palette.dark, [x, 0.16, z], machine, true);
}
}
const vibrator = new THREE.Group();
machine.add(vibrator);
addBox(1.95, 0.18, 1.3, palette.orangeDark, [0.15, 0.68, 0], vibrator, true);
addBox(1.72, 0.12, 1.12, palette.orange, [0.15, 0.82, 0], vibrator, true);
// Press frame.
addBox(0.18, 1.2, 0.22, palette.navy, [0.08, 1.47, -0.38], vibrator, true);
addBox(0.18, 1.2, 0.22, palette.navy, [0.82, 1.47, -0.38], vibrator, true);
addBox(1.15, 0.22, 0.5, palette.navy, [0.45, 2.06, -0.38], vibrator, true);
const piston = addCylinder(
0.17,
0.65,
palette.cream,
[0.46, 1.55, -0.38],
vibrator,
10,
true
);
addBox(0.7, 0.18, 0.62, palette.dark, [0.46, 1.13, -0.38], vibrator, true);
// Motor and visible rotating flywheel.
const motor = addCylinder(
0.36,
0.95,
palette.navy,
[-0.66, 1.22, 0],
vibrator,
12,
true
);
motor.rotation.x = Math.PI / 2;
const rotor = new THREE.Group();
rotor.position.set(-0.66, 1.22, 0.51);
vibrator.add(rotor);
addMesh(
new THREE.TorusGeometry(0.31, 0.065, 6, 16),
material(palette.orange),
[0, 0, 0],
rotor,
true
);
const spokeA = addBox(0.52, 0.055, 0.055, palette.cream, [0, 0, 0], rotor);
const spokeB = addBox(0.055, 0.52, 0.055, palette.cream, [0, 0, 0], rotor);
addBox(0.24, 0.2, 0.22, palette.orange, [1.17, 1.04, 0], vibrator, true);
// Hazard marks on the moving platform.
for (let i = 0; i < 6; i++) {
const stripe = addBox(
0.1,
0.025,
0.52,
i % 2 ? palette.dark : palette.cream,
[-0.45 + i * 0.22, 0.895, 0.25],
vibrator
);
stripe.rotation.y = -0.25;
}
const indicatorMaterial = material(palette.teal, {
emissive: palette.teal,
emissiveIntensity: 0.7
});
addMesh(
new THREE.IcosahedronGeometry(0.075, 0),
indicatorMaterial,
[1.19, 1.2, 0],
vibrator
);
// Neighboring house shell.
const home = new THREE.Group();
scene.add(home);
addBox(4.2, 0.16, 3.6, palette.homeFloor, [4.3, 0.08, 0], home, true);
addBox(4.2, 3.0, 0.16, palette.homeWall, [4.3, 1.58, -1.75], home, true);
addBox(0.16, 1.05, 3.6, palette.homeWall, [6.35, 0.62, 0], home, true);
// Left wall with an actual window opening toward the workshop.
addBox(0.16, 3.0, 0.95, palette.homeWall, [2.2, 1.58, -1.25], home, true);
addBox(0.16, 3.0, 0.9, palette.homeWall, [2.2, 1.58, 1.25], home, true);
addBox(0.16, 1.1, 1.5, palette.homeWall, [2.2, 0.63, 0.05], home, true);
addBox(0.16, 0.75, 1.5, palette.homeWall, [2.2, 2.72, 0.05], home, true);
const windowMaterial = material(0x89cbd0, {
transparent: true,
opacity: 0.3,
roughness: 0.2,
metalness: 0.05,
emissive: 0x0b6b72,
emissiveIntensity: 0.12,
side: THREE.DoubleSide
});
const homeWindow = addBox(
0.025,
1.12,
1.45,
windowMaterial,
[2.17, 1.72, 0.05],
home
);
addBox(0.2, 0.09, 1.55, palette.cream, [2.12, 1.13, 0.05], home, true);
addBox(0.2, 0.09, 1.55, palette.cream, [2.12, 2.31, 0.05], home, true);
addBox(0.2, 1.28, 0.09, palette.cream, [2.12, 1.72, -0.7], home, true);
addBox(0.2, 1.28, 0.09, palette.cream, [2.12, 1.72, 0.8], home, true);
addBox(0.22, 1.16, 0.06, palette.cream, [2.1, 1.72, 0.05], home, true);
// Gable roof frame and a partial rear roof panel: a readable cutaway.
beam([2.2, 2.7, -1.7], [4.3, 3.27, -1.7], 0.15, 0.15, palette.roof, home, true);
beam([4.3, 3.27, -1.7], [6.4, 2.7, -1.7], 0.15, 0.15, palette.roof, home, true);
beam([4.3, 3.27, -1.7], [4.3, 3.27, -0.35], 0.15, 0.15, palette.roof, home, true);
beam([2.2, 2.7, -1.45], [4.3, 3.27, -1.45], 0.13, 1.2, palette.roof, home, true);
beam([4.3, 3.27, -1.45], [6.4, 2.7, -1.45], 0.13, 1.2, palette.roof, home, true);
addBox(0.48, 0.85, 0.48, 0x8d594a, [5.45, 3.3, -1.42], home, true);
// Rug, couch and furnishings.
addBox(2.05, 0.035, 1.5, 0xc58c76, [4.25, 0.19, 0.62], home, true);
addBox(1.65, 0.35, 0.72, 0x6f9290, [5.0, 0.42, -0.55], home, true);
addBox(1.65, 0.75, 0.16, 0x5d8280, [5.0, 0.76, -0.88], home, true);
addBox(0.18, 0.5, 0.78, 0x507573, [4.2, 0.57, -0.55], home, true);
addBox(0.18, 0.5, 0.78, 0x507573, [5.8, 0.57, -0.55], home, true);
addBox(0.5, 0.38, 0.5, palette.wood, [3.35, 0.38, 1.18], home, true);
addCylinder(0.055, 0.48, palette.wood, [3.35, 0.2, 1.18], home, 8);
addMesh(
new THREE.ConeGeometry(0.22, 0.42, 8),
material(0xf0bf69),
[3.35, 0.8, 1.18],
home,
true
);
// Small plant.
addCylinder(0.19, 0.28, 0xc9835e, [5.95, 0.3, 1.1], home, 9, true);
addMesh(
new THREE.IcosahedronGeometry(0.32, 0),
material(palette.green),
[5.95, 0.64, 1.1],
home,
true
);
// Resident inside the home.
const resident = new THREE.Group();
resident.position.set(4.12, 0.2, 0.55);
home.add(resident);
addCylinder(0.11, 0.78, 0x405b68, [-0.17, 0.39, 0], resident, 8, true);
addCylinder(0.11, 0.78, 0x405b68, [0.17, 0.39, 0], resident, 8, true);
addCylinder(0.3, 0.68, palette.coral, [0, 1.05, 0], resident, 8, true);
addCylinder(0.1, 0.6, palette.coral, [-0.32, 1.02, 0], resident, 8);
addCylinder(0.1, 0.6, palette.coral, [0.32, 1.02, 0], resident, 8);
const head = addMesh(
new THREE.IcosahedronGeometry(0.25, 1),
material(0xd5a176),
[0, 1.62, 0],
resident,
true
);
// Low-poly outdoor tree.
addCylinder(0.15, 1.5, 0x8c6b4d, [7.18, 0.65, -1.4], scene, 8, true);
addMesh(
new THREE.IcosahedronGeometry(0.72, 0),
material(0x6e9775),
[7.18, 1.72, -1.4],
scene,
true
);
// Airborne sound source.
const source = new THREE.Vector3(-2.58, 1.16, 0.05);
const sourceOrb = addMesh(
new THREE.IcosahedronGeometry(0.105, 1),
material(palette.teal, {
emissive: palette.teal,
emissiveIntensity: 0.8
}),
source.toArray(),
scene
);
const sourceRing = addMesh(
new THREE.TorusGeometry(0.25, 0.018, 5, 24),
new THREE.MeshBasicMaterial({
color: palette.teal,
transparent: true,
opacity: 0.55,
depthWrite: false
}),
source.toArray(),
scene
);
sourceRing.rotation.y = Math.PI / 2;
const sourceGroundRing = addMesh(
new THREE.TorusGeometry(0.3, 0.016, 5, 24),
new THREE.MeshBasicMaterial({
color: palette.tealLight,
transparent: true,
opacity: 0.4,
depthWrite: false
}),
[source.x, 0.23, source.z],
scene
);
sourceGroundRing.rotation.x = Math.PI / 2;
// Expanding wavefronts: low-poly cross-sections in planes perpendicular
// to the direction of travel.
const WAVE_COUNT = 9;
const WAVE_SEGMENTS = 42;
const TRAVEL_LENGTH = 8.95;
const waveMeshes = [];
const waveMarkers = [];
const markerGeometry = new THREE.OctahedronGeometry(0.055, 0);
for (let i = 0; i < WAVE_COUNT; i++) {
const positions = new Float32Array((WAVE_SEGMENTS + 1) * 3);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3).setUsage(THREE.DynamicDrawUsage)
);
const line = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: palette.teal,
transparent: true,
opacity: 0.6,
depthWrite: false
})
);
line.frustumCulled = false;
line.renderOrder = 2;
scene.add(line);
waveMeshes.push(line);
const marker = new THREE.Mesh(
markerGeometry,
new THREE.MeshBasicMaterial({
color: palette.tealLight,
transparent: true,
opacity: 0.85
})
);
scene.add(marker);
waveMarkers.push(marker);
}
// Directional ground line and chevrons.
const pathGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(source.x, 0.225, source.z),
new THREE.Vector3(6.15, 0.225, source.z)
]);
const pathLine = new THREE.Line(
pathGeometry,
new THREE.LineDashedMaterial({
color: palette.teal,
dashSize: 0.18,
gapSize: 0.13,
transparent: true,
opacity: 0.34
})
);
pathLine.computeLineDistances();
scene.add(pathLine);
const arrows = [];
for (let i = 0; i < 4; i++) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.11, 0.28, 4),
new THREE.MeshBasicMaterial({
color: palette.teal,
transparent: true,
opacity: 0.52
})
);
arrow.rotation.z = -Math.PI / 2;
arrow.position.set(-0.8 + i * 0.75, 0.25, source.z);
scene.add(arrow);
arrows.push(arrow);
}
// Individual energy particles moving through the sound field.
const particles = [];
const particleGeometry = new THREE.OctahedronGeometry(0.042, 0);
for (let i = 0; i < 28; i++) {
const mesh = new THREE.Mesh(
particleGeometry,
new THREE.MeshBasicMaterial({
color: i % 3 === 0 ? palette.tealLight : palette.teal,
transparent: true,
opacity: 0.75
})
);
scene.add(mesh);
particles.push({
mesh,
offset: (i / 28) * TRAVEL_LENGTH,
seed: i * 2.399,
speed: 0.93 + (i % 5) * 0.035
});
}
// Response rings around the resident.
const reactionRings = [];
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.012, 4, 18),
new THREE.MeshBasicMaterial({
color: palette.coral,
transparent: true,
opacity: 0,
depthWrite: false
})
);
ring.rotation.y = Math.PI / 2;
ring.position.set(4.12, 1.82, 0.55);
scene.add(ring);
reactionRings.push(ring);
}
// HTML labels are projected from Three.js world positions.
const labels = {
source: {
element: document.querySelector("#source-label"),
position: new THREE.Vector3(-3.6, 2.55, 0.05)
},
wave: {
element: document.querySelector("#wave-label"),
position: new THREE.Vector3(-0.1, 2.25, 0.2)
},
home: {
element: document.querySelector("#home-label"),
position: new THREE.Vector3(4.45, 3.65, -0.8)
}
};
function updateLabels() {
for (const label of Object.values(labels)) {
const projected = label.position.clone().project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
}
// Custom camera controls, implemented without Three.js addons.
let dragging = false;
let pointerButton = 0;
let lastX = 0;
let lastY = 0;
const cameraRight = new THREE.Vector3();
const cameraUp = new THREE.Vector3();
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerButton = event.button;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
const panning = event.shiftKey || pointerButton === 2;
if (panning) {
cameraRight.setFromMatrixColumn(camera.matrixWorld, 0);
cameraUp.setFromMatrixColumn(camera.matrixWorld, 1);
const panScale = orbit.radius / 850;
orbit.target.addScaledVector(cameraRight, -dx * panScale);
orbit.target.addScaledVector(cameraUp, dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -6, 6);
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, -1, 4);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -4, 4);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.32, 1.38);
}
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * Math.exp(-event.deltaY * 0.001),
0.62,
1.65
);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
// Pinch zoom for touch screens.
const activePointers = new Map();
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
dragging = false;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
orbit.zoom = THREE.MathUtils.clamp(
orbit.zoom * (distance / pinchDistance),
0.62,
1.65
);
camera.zoom = orbit.zoom;
camera.updateProjectionMatrix();
}
pinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
renderer.domElement.addEventListener("pointercancel", (event) => {
activePointers.delete(event.pointerId);
if (activePointers.size < 2) pinchDistance = 0;
});
function resetView() {
orbit.theta = 0.54;
orbit.phi = 0.94;
orbit.zoom = 1;
orbit.target.set(0, 0.8, 0);
camera.zoom = 1;
camera.updateProjectionMatrix();
updateCamera();
}
document.querySelector("#reset-button").addEventListener("click", resetView);
renderer.domElement.addEventListener("dblclick", resetView);
let paused = false;
let speed = 1;
let simulationTime = 0;
const pauseButton = document.querySelector("#pause-button");
const statusText = document.querySelector("#status-text");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
statusText.textContent = paused ? "Propagation paused" : "Live propagation";
document.querySelector(".status-dot").style.animationPlayState =
paused ? "paused" : "running";
});
document.querySelector("#speed").addEventListener("input", (event) => {
speed = Number(event.target.value);
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target.tagName !== "INPUT") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetView();
}
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) simulationTime += delta * speed;
const t = simulationTime;
// Mechanical vibration.
vibrator.position.x = Math.sin(t * 47) * 0.024;
vibrator.position.y = Math.sin(t * 61) * 0.012;
vibrator.rotation.z = Math.sin(t * 43) * 0.005;
rotor.rotation.z = -t * 8.5;
spokeA.rotation.z = 0.35;
spokeB.rotation.z = -0.75;
piston.position.y = 1.55 + Math.sin(t * 8.5) * 0.105;
// Source pulse.
const sourcePulse = 1 + Math.sin(t * 8.5) * 0.16;
sourceOrb.scale.setScalar(sourcePulse);
indicatorMaterial.emissiveIntensity = 0.55 + Math.sin(t * 8.5) * 0.25;
const ringPulse = (t * 0.85) % 1;
sourceRing.scale.setScalar(0.75 + ringPulse * 1.7);
sourceRing.material.opacity = (1 - ringPulse) * 0.55;
const groundPulse = (t * 0.7) % 1;
sourceGroundRing.scale.setScalar(0.65 + groundPulse * 2.1);
sourceGroundRing.material.opacity = (1 - groundPulse) * 0.38;
// Expanding sound wavefronts.
for (let i = 0; i < WAVE_COUNT; i++) {
const phase = (t * 0.16 + i / WAVE_COUNT) % 1;
const distance = phase * TRAVEL_LENGTH;
const radius = 0.34 + distance * 0.19;
const centerX = source.x + distance;
const groundY = 0.19;
const cosineLimit = THREE.MathUtils.clamp(
(groundY - source.y) / radius,
-1,
1
);
const angleLimit = Math.acos(cosineLimit);
const positions = waveMeshes[i].geometry.attributes.position.array;
for (let j = 0; j <= WAVE_SEGMENTS; j++) {
const fraction = j / WAVE_SEGMENTS;
const angle = -angleLimit + fraction * angleLimit * 2;
positions[j * 3] = centerX;
positions[j * 3 + 1] = source.y + Math.cos(angle) * radius;
positions[j * 3 + 2] = source.z + Math.sin(angle) * radius;
}
waveMeshes[i].geometry.attributes.position.needsUpdate = true;
waveMeshes[i].material.opacity =
Math.sin(Math.PI * phase) * 0.78;
const marker = waveMarkers[i];
marker.position.set(centerX, source.y + radius, source.z);
marker.rotation.set(t * 0.8 + i, t * 1.1, 0);
marker.material.opacity = Math.sin(Math.PI * phase) * 0.9;
marker.scale.setScalar(0.75 + Math.sin(Math.PI * phase) * 0.45);
}
// Moving energy particles.
for (const particle of particles) {
const distance =
(t * 1.35 * particle.speed + particle.offset) % TRAVEL_LENGTH;
const spread = 0.12 + distance * 0.13;
particle.mesh.position.set(
source.x + distance,
source.y + Math.sin(t * 3.2 + particle.seed) * spread * 0.38,
source.z + Math.sin(particle.seed * 1.7) * spread
);
particle.mesh.rotation.set(
t * 1.8 + particle.seed,
t * 1.2,
particle.seed
);
particle.mesh.material.opacity =
0.28 + 0.52 * Math.sin(Math.PI * (distance / TRAVEL_LENGTH));
}
// Direction arrows advance along the shared boundary.
arrows.forEach((arrow, index) => {
const offset = ((t * 0.24 + index * 0.25) % 1) * 0.7;
arrow.position.x = -0.8 + index * 0.75 + offset;
arrow.material.opacity = 0.38 + Math.sin(t * 3 + index) * 0.12;
});
// Detect the arrival of the nearest wavefront at the window.
const waveCycle = (t * 0.16) % 1;
const arrivalPhase = (2.2 - source.x) / TRAVEL_LENGTH;
let closestPhase = 10;
for (let i = 0; i < WAVE_COUNT; i++) {
const phase = (waveCycle + i / WAVE_COUNT) % 1;
const directDistance = Math.abs(phase - arrivalPhase);
const circularDistance = Math.min(directDistance, 1 - directDistance);
closestPhase = Math.min(closestPhase, circularDistance);
}
const arrival = Math.exp(-Math.pow(closestPhase / 0.055, 2));
windowMaterial.emissiveIntensity = 0.12 + arrival * 0.85;
windowMaterial.opacity = 0.3 + arrival * 0.16;
reactionRings.forEach((ring, index) => {
const local = (arrival + index * 0.19) % 1;
ring.scale.setScalar(0.8 + local * 2.1);
ring.material.opacity = arrival * (1 - local) * 0.8;
});
head.rotation.z = Math.sin(t * 8.5) * 0.025 * arrival;
resident.rotation.y = -0.12 + Math.sin(t * 1.1) * 0.025;
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```