Prompt specification
Build or customize the Three.js 3D scene "Hard panel and padded panel" 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: Hard panel and padded panel
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/hard-panel-and-padded-panel-x0161
Scene Description Prompt:
Compare voxel hard and padded wall panels with labeled schematic sound-reflection and absorption rays. Three.js from cdnjs, one HTML file.
Working Three.js Starter (hard-panel-and-padded-panel-x0161):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Wall Panels — Sound Reflection vs. Absorption</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(10, 22, 39, 0.82);
--border: rgba(160, 190, 220, 0.18);
--text: #edf7ff;
--muted: #9fb3c8;
--cyan: #59e3ff;
--yellow: #ffc857;
--pink: #ff5ca8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.header {
position: fixed;
top: 26px;
left: 30px;
z-index: 5;
max-width: 620px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 44px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 570px;
margin: 12px 0 0;
color: var(--muted);
font-size: clamp(12px, 1.2vw, 15px);
line-height: 1.55;
}
.legend {
position: fixed;
top: 28px;
right: 28px;
z-index: 5;
width: 242px;
padding: 15px 16px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-title {
margin-bottom: 11px;
color: #dcecf8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 26px 1fr;
align-items: start;
gap: 8px;
margin-top: 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.legend-row strong {
display: block;
color: var(--text);
font-size: 11px;
}
.swatch {
position: relative;
width: 25px;
height: 12px;
margin-top: 3px;
}
.swatch::before {
position: absolute;
top: 5px;
left: 0;
width: 25px;
height: 2px;
content: "";
background: var(--swatch);
box-shadow: 0 0 9px var(--swatch);
}
.swatch::after {
position: absolute;
top: 2px;
right: 0;
width: 0;
height: 0;
content: "";
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
border-left: 7px solid var(--swatch);
}
.swatch.dashed::before {
height: 0;
border-top: 2px dashed var(--swatch);
background: transparent;
box-shadow: none;
}
.hint {
position: fixed;
right: 30px;
bottom: 112px;
z-index: 5;
color: #7890a8;
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.controls {
position: fixed;
left: 50%;
bottom: 24px;
z-index: 10;
display: flex;
align-items: center;
gap: 18px;
width: min(900px, calc(100vw - 32px));
padding: 14px 16px;
transform: translateX(-50%);
border: 1px solid var(--border);
border-radius: 17px;
background: rgba(8, 19, 34, 0.88);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(18px);
}
.control-group {
display: flex;
align-items: center;
gap: 10px;
}
.control-label {
min-width: max-content;
color: #dcecf8;
font-size: 11px;
font-weight: 700;
}
.angle-control {
flex: 1;
min-width: 150px;
}
input[type="range"] {
width: 100%;
accent-color: var(--cyan);
cursor: pointer;
}
output {
min-width: 31px;
color: var(--cyan);
font-size: 12px;
font-variant-numeric: tabular-nums;
text-align: right;
}
button {
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(140, 180, 215, 0.2);
border-radius: 9px;
background: rgba(126, 165, 201, 0.09);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(89, 227, 255, 0.5);
background: rgba(89, 227, 255, 0.12);
}
button:active {
transform: translateY(1px);
}
.divider {
width: 1px;
height: 28px;
background: var(--border);
}
@media (max-width: 820px) {
.header {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
.subtitle {
max-width: 480px;
}
.legend {
top: auto;
right: 16px;
bottom: 108px;
width: 210px;
padding: 12px;
}
.hint {
display: none;
}
.controls {
gap: 10px;
padding: 11px;
}
.divider {
display: none;
}
.control-label {
display: none;
}
}
@media (max-width: 580px) {
.legend {
display: none;
}
.subtitle {
font-size: 11px;
}
.controls {
flex-wrap: wrap;
}
.angle-control {
flex-basis: 100%;
}
button {
flex: 1;
padding-inline: 8px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive comparison of hard and padded voxel wall panels"></canvas>
<header class="header">
<div class="eyebrow">Acoustic ray-path comparison</div>
<h1>Hard voxels reflect.<br />Padded voxels absorb.</h1>
<p class="subtitle">
A schematic comparison of sound meeting a rigid voxel surface versus a
porous padded surface. Energy either returns to the room or dissipates
inside the absorbing material.
</p>
</header>
<aside class="legend" aria-label="Ray color legend">
<div class="legend-title">Ray-path key</div>
<div class="legend-row">
<span class="swatch" style="--swatch: var(--cyan)"></span>
<span><strong>Incident sound</strong>Energy traveling toward the wall.</span>
</div>
<div class="legend-row">
<span class="swatch" style="--swatch: var(--yellow)"></span>
<span><strong>Reflected ray</strong>Energy returns at an equal angle.</span>
</div>
<div class="legend-row">
<span class="swatch dashed" style="--swatch: var(--pink)"></span>
<span><strong>Absorbed energy</strong>Motion and heat dissipate in the padding.</span>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="controls" aria-label="Visualization controls">
<div class="control-group angle-control">
<label class="control-label" for="angle">Incidence angle</label>
<input
id="angle"
type="range"
min="12"
max="32"
step="1"
value="24"
aria-label="Sound incidence angle"
/>
<output id="angleValue" for="angle">24°</output>
</div>
<div class="divider"></div>
<div class="control-group">
<button id="play" type="button" aria-pressed="true">Pause rays</button>
<button id="labels" type="button" aria-pressed="true">Hide labels</button>
<button id="reset" type="button">Reset view</button>
</div>
</section>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.Fog(0x07111f, 17, 29);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.65, 0);
const view = {
theta: -0.31,
phi: 1.21,
radius: 15.2
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xb9dcff, 0x142033, 2.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(-6, 9, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x38cfff, 18, 9, 2);
cyanLight.position.set(-4.8, 2.3, 3.4);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff4eaa, 16, 8, 2);
pinkLight.position.set(4.6, 2.6, 2.8);
scene.add(pinkLight);
// Ground and grid
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 18),
new THREE.MeshStandardMaterial({
color: 0x091727,
roughness: 0.92,
metalness: 0.08
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.06;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x1c3851, 0x10283b);
grid.position.y = -0.045;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
// -------------------------------------------------------------------------
// Label and glow helpers
// -------------------------------------------------------------------------
const labels = [];
function roundedRect(ctx, x, y, w, h, r) {
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeLabel(title, subtitle = "", accent = "#59e3ff", width = 2.5) {
const c = document.createElement("canvas");
c.width = 768;
c.height = 168;
const ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
roundedRect(ctx, 5, 5, 758, 158, 24);
ctx.fillStyle = "rgba(6, 16, 29, 0.91)";
ctx.fill();
ctx.strokeStyle = accent;
ctx.globalAlpha = 0.72;
ctx.lineWidth = 3;
ctx.stroke();
ctx.globalAlpha = 1;
ctx.fillStyle = accent;
roundedRect(ctx, 24, 27, 7, 114, 4);
ctx.fill();
let titleSize = 39;
ctx.font = `800 ${titleSize}px system-ui, sans-serif`;
while (ctx.measureText(title).width > 690 && titleSize > 24) {
titleSize -= 2;
ctx.font = `800 ${titleSize}px system-ui, sans-serif`;
}
ctx.textBaseline = "middle";
ctx.fillStyle = "#f2f8ff";
ctx.fillText(title, 49, subtitle ? 61 : 84);
if (subtitle) {
ctx.font = "500 24px system-ui, sans-serif";
ctx.fillStyle = "#9fb3c8";
ctx.fillText(subtitle, 49, 113);
}
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * (c.height / c.width), 1);
sprite.renderOrder = 50;
labels.push(sprite);
scene.add(sprite);
return sprite;
}
function makeGlowTexture() {
const c = document.createElement("canvas");
c.width = 128;
c.height = 128;
const ctx = c.getContext("2d");
const gradient = ctx.createRadialGradient(64, 64, 2, 64, 64, 64);
gradient.addColorStop(0, "rgba(89,227,255,0.95)");
gradient.addColorStop(0.18, "rgba(89,227,255,0.55)");
gradient.addColorStop(0.55, "rgba(89,227,255,0.12)");
gradient.addColorStop(1, "rgba(89,227,255,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const glowTexture = makeGlowTexture();
// -------------------------------------------------------------------------
// Voxel panel construction
// -------------------------------------------------------------------------
function addBox(group, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function createPanel(centerX, padded = false) {
const group = new THREE.Group();
scene.add(group);
const backingMaterial = new THREE.MeshStandardMaterial({
color: padded ? 0x261b35 : 0x17273b,
roughness: padded ? 0.94 : 0.5,
metalness: padded ? 0.02 : 0.32
});
if (padded) {
addBox(
group,
new THREE.Vector3(0.22, 3.18, 2.86),
new THREE.Vector3(centerX + 0.18, 1.65, 0),
backingMaterial
);
const foamMaterial = new THREE.MeshStandardMaterial({
color: 0x512742,
roughness: 1,
metalness: 0
});
addBox(
group,
new THREE.Vector3(0.25, 3.02, 2.7),
new THREE.Vector3(centerX + 0.02, 1.65, 0),
foamMaterial
);
const padMaterials = [
new THREE.MeshStandardMaterial({
color: 0xd76d78,
roughness: 0.98,
metalness: 0
}),
new THREE.MeshStandardMaterial({
color: 0xe27a80,
roughness: 1,
metalness: 0
}),
new THREE.MeshStandardMaterial({
color: 0xc85e72,
roughness: 0.96,
metalness: 0
})
];
const insetMaterial = new THREE.MeshStandardMaterial({
color: 0xf2a0a0,
roughness: 1,
metalness: 0
});
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 7; col++) {
const y = 0.27 + row * 0.38;
const z = -1.14 + col * 0.38;
const material = padMaterials[(row + col * 2) % padMaterials.length];
addBox(
group,
new THREE.Vector3(0.52, 0.35, 0.35),
new THREE.Vector3(centerX - 0.08, y, z),
material
);
addBox(
group,
new THREE.Vector3(0.025, 0.235, 0.235),
new THREE.Vector3(centerX - 0.352, y, z),
insetMaterial,
false
);
}
}
addBox(
group,
new THREE.Vector3(0.8, 0.16, 3.15),
new THREE.Vector3(centerX + 0.02, 0.08, 0),
new THREE.MeshStandardMaterial({
color: 0x251a31,
roughness: 0.75,
metalness: 0.25
})
);
return { group, faceOffset: 0.365 };
}
// Rigid backing and tightly packed hard voxels
addBox(
group,
new THREE.Vector3(0.18, 3.18, 2.86),
new THREE.Vector3(centerX + 0.12, 1.65, 0),
backingMaterial
);
const hardMaterials = [
new THREE.MeshStandardMaterial({
color: 0x91abc2,
roughness: 0.32,
metalness: 0.42
}),
new THREE.MeshStandardMaterial({
color: 0x7895ad,
roughness: 0.4,
metalness: 0.36
}),
new THREE.MeshStandardMaterial({
color: 0xa9bfd0,
roughness: 0.28,
metalness: 0.46
})
];
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xc7e2f2,
transparent: true,
opacity: 0.22
});
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 7; col++) {
const y = 0.27 + row * 0.38;
const z = -1.14 + col * 0.38;
const material = hardMaterials[(row + col) % hardMaterials.length];
const block = addBox(
group,
new THREE.Vector3(0.29, 0.35, 0.35),
new THREE.Vector3(centerX, y, z),
material
);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(block.geometry),
edgeMaterial
);
edges.position.copy(block.position);
group.add(edges);
}
}
addBox(
group,
new THREE.Vector3(0.58, 0.16, 3.15),
new THREE.Vector3(centerX + 0.04, 0.08, 0),
new THREE.MeshStandardMaterial({
color: 0x14263a,
roughness: 0.58,
metalness: 0.42
})
);
return { group, faceOffset: 0.155 };
}
const hardPanel = createPanel(-3.15, false);
const paddedPanel = createPanel(2.75, true);
// -------------------------------------------------------------------------
// Sound source
// -------------------------------------------------------------------------
function createSource(position) {
const group = new THREE.Group();
group.position.copy(position);
scene.add(group);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x18334a,
roughness: 0.45,
metalness: 0.5
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x59e3ff,
emissive: 0x1b7794,
emissiveIntensity: 1.5,
roughness: 0.35,
metalness: 0.25
});
addBox(
group,
new THREE.Vector3(0.42, 0.52, 0.42),
new THREE.Vector3(0, 0, 0),
bodyMaterial
);
const cone = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.18, 0.1, 24),
trimMaterial
);
cone.rotation.z = Math.PI / 2;
cone.position.x = 0.25;
group.add(cone);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(0.135, 0.022, 8, 28),
trimMaterial
);
rim.rotation.y = Math.PI / 2;
rim.position.x = 0.305;
group.add(rim);
const glowMaterial = new THREE.SpriteMaterial({
map: glowTexture,
transparent: true,
opacity: 0.38,
depthWrite: false,
depthTest: false
});
const glow = new THREE.Sprite(glowMaterial);
glow.scale.set(1.25, 1.25, 1);
glow.position.x = 0.32;
glow.renderOrder = 15;
group.add(glow);
return { group, glow };
}
// -------------------------------------------------------------------------
// Animated ray geometry
// -------------------------------------------------------------------------
const up = new THREE.Vector3(0, 1, 0);
const tempDirection = new THREE.Vector3();
function createAnimatedRay(color, dashed = false) {
const group = new THREE.Group();
group.renderOrder = 20;
scene.add(group);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.94,
depthTest: false,
depthWrite: false
});
const cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(0.021, 0.021, 1, 10),
material
);
cylinder.renderOrder = 20;
group.add(cylinder);
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.075, 0.19, 16),
material
);
arrow.renderOrder = 21;
group.add(arrow);
let line = null;
let lineMaterial = null;
if (dashed) {
cylinder.visible = false;
lineMaterial = new THREE.LineDashedMaterial({
color,
dashSize: 0.11,
gapSize: 0.075,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]),
lineMaterial
);
line.renderOrder = 20;
group.add(line);
}
const pulseGeometry = new THREE.SphereGeometry(0.065, 12, 12);
const pulses = [];
for (let i = 0; i < 3; i++) {
const pulseMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
});
const pulse = new THREE.Mesh(pulseGeometry, pulseMaterial);
pulse.renderOrder = 25;
group.add(pulse);
pulses.push(pulse);
}
return {
group,
cylinder,
arrow,
line,
pulses,
start: new THREE.Vector3(),
end: new THREE.Vector3(),
update(start, end) {
this.start.copy(start);
this.end.copy(end);
tempDirection.subVectors(end, start);
const length = tempDirection.length();
const direction = tempDirection.clone().normalize();
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const quaternion = new THREE.Quaternion().setFromUnitVectors(
up,
direction
);
cylinder.position.copy(midpoint);
cylinder.quaternion.copy(quaternion);
cylinder.scale.set(1, length, 1);
arrow.position.copy(end).addScaledVector(direction, -0.095);
arrow.quaternion.copy(quaternion);
if (line) {
const positions = line.geometry.attributes.position;
positions.setXYZ(0, start.x, start.y, start.z);
positions.setXYZ(1, end.x, end.y, end.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
line.computeLineDistances();
}
}
};
}
function createNormalLine() {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const material = new THREE.LineDashedMaterial({
color: 0xe8f4ff,
dashSize: 0.07,
gapSize: 0.055,
transparent: true,
opacity: 0.42,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.renderOrder = 18;
scene.add(line);
return {
update(start, end) {
const positions = line.geometry.attributes.position;
positions.setXYZ(0, start.x, start.y, start.z);
positions.setXYZ(1, end.x, end.y, end.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
line.computeLineDistances();
}
};
}
// -------------------------------------------------------------------------
// Build the two test rigs
// -------------------------------------------------------------------------
const CYAN = 0x59e3ff;
const YELLOW = 0xffc857;
const PINK = 0xff5ca8;
function createRig(panel, type) {
const centerX = type === "hard" ? -3.15 : 2.75;
const sourcePosition = new THREE.Vector3(
centerX - 2,
1.02,
0.12
);
const source = createSource(sourcePosition);
const incident = createAnimatedRay(CYAN);
const response = createAnimatedRay(
type === "hard" ? YELLOW : PINK,
type !== "hard"
);
const normal = type === "hard" ? createNormalLine() : null;
const title = makeLabel(
type === "hard"
? "A · HARD VOXEL PANEL"
: "B · PADDED VOXEL PANEL",
type === "hard"
? "DENSE, RIGID SURFACE"
: "POROUS, SOFT SURFACE",
type === "hard" ? "#a9c5d8" : "#ff83b3",
2.7
);
title.position.set(centerX, 3.66, 0.15);
const behavior = makeLabel(
type === "hard"
? "MOST ENERGY RETURNS"
: "ENERGY DISSIPATES",
type === "hard"
? "SPECULAR REFLECTION"
: "MOTION + HEAT IN THE FOAM",
type === "hard" ? "#ffc857" : "#ff5ca8",
2.35
);
behavior.position.set(centerX, 0.35, 1.1);
const incidentLabel = makeLabel(
"INCIDENT RAY",
"Sound travels toward the wall",
"#59e3ff",
2.15
);
const responseLabel = makeLabel(
type === "hard" ? "REFLECTED RAY" : "ABSORBED ENERGY",
type === "hard"
? "θ incidence = θ reflection"
: "Energy enters the porous padding",
type === "hard" ? "#ffc857" : "#ff5ca8",
2.4
);
const sourceLabel = makeLabel(
"SOUND SOURCE",
"",
"#59e3ff",
1.55
);
sourceLabel.position.set(sourcePosition.x, sourcePosition.y + 0.57, 0.48);
let angleLabel = null;
if (type === "hard") {
angleLabel = makeLabel(
"EQUAL ANGLES",
"θᵢ = θᵣ",
"#e8f4ff",
1.45
);
}
return {
type,
panel,
source,
sourcePosition,
incident,
response,
normal,
incidentLabel,
responseLabel,
angleLabel
};
}
const hardRig = createRig(hardPanel, "hard");
const paddedRig = createRig(paddedPanel, "padded");
// -------------------------------------------------------------------------
// Update ray geometry from the selected incidence angle
// -------------------------------------------------------------------------
let angleDegrees = 24;
function updateRig(rig) {
const angleRadians = THREE.MathUtils.degToRad(angleDegrees);
const slope = Math.tan(angleRadians);
const source = rig.sourcePosition;
const contactX =
(rig.type === "hard" ? -3.15 : 2.75) - rig.panel.faceOffset;
const horizontalDistance = contactX - source.x;
const contact = new THREE.Vector3(
contactX,
source.y + horizontalDistance * slope,
source.z
);
rig.incident.update(source, contact);
if (rig.type === "hard") {
const reflectedEnd = new THREE.Vector3(
contact.x - horizontalDistance,
contact.y + horizontalDistance * slope,
contact.z
);
rig.response.update(contact, reflectedEnd);
const normalStart = contact.clone();
const normalEnd = contact.clone().add(
new THREE.Vector3(-0.95, 0, 0)
);
rig.normal.update(normalStart, normalEnd);
const incidentMid = source.clone().add(contact).multiplyScalar(0.5);
incidentMid.y += 0.27;
incidentMid.z += 0.48;
rig.incidentLabel.position.copy(incidentMid);
const responseMid = contact
.clone()
.add(reflectedEnd)
.multiplyScalar(0.5);
responseMid.y += 0.3;
responseMid.z += 0.5;
rig.responseLabel.position.copy(responseMid);
rig.angleLabel.position.set(
contact.x - 0.12,
contact.y + 0.24,
contact.z + 0.62
);
} else {
const absorbedEnd = new THREE.Vector3(
contact.x + 0.54,
contact.y + 0.54 * slope,
contact.z
);
rig.response.update(contact, absorbedEnd);
const incidentMid = source.clone().add(contact).multiplyScalar(0.5);
incidentMid.y += 0.28;
incidentMid.z += 0.5;
rig.incidentLabel.position.copy(incidentMid);
rig.responseLabel.position.set(
absorbedEnd.x - 0.08,
absorbedEnd.y + 0.39,
absorbedEnd.z + 0.56
);
}
}
function updateAngle(value) {
angleDegrees = Number(value);
document.querySelector("#angleValue").textContent = `${angleDegrees}°`;
updateRig(hardRig);
updateRig(paddedRig);
}
updateAngle(angleDegrees);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let playing = true;
let elapsed = 0;
let lastTime = performance.now();
function animateRay(ray, time, speed, fadeOut = false) {
const distance = ray.start.distanceTo(ray.end);
ray.pulses.forEach((pulse, index) => {
const raw = (time * speed + index / ray.pulses.length) % 1;
const position = ray.start.clone().lerp(ray.end, raw);
pulse.position.copy(position);
if (fadeOut) {
const opacity = (1 - raw) * 0.95;
const scale = 1 - raw * 0.62;
pulse.material.opacity = opacity;
pulse.scale.setScalar(scale);
} else {
pulse.material.opacity = 0.78 + Math.sin(raw * Math.PI) * 0.22;
pulse.scale.setScalar(0.82 + Math.sin(raw * Math.PI) * 0.35);
}
});
}
function animate(now) {
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed += delta;
}
animateRay(hardRig.incident, elapsed, 0.31);
animateRay(hardRig.response, elapsed, 0.26);
animateRay(paddedRig.incident, elapsed, 0.31);
animateRay(paddedRig.response, elapsed, 0.21, true);
const pulse = 0.34 + Math.sin(elapsed * 4.2) * 0.1;
hardRig.source.glow.material.opacity = pulse;
paddedRig.source.glow.material.opacity = pulse;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// -------------------------------------------------------------------------
// UI controls
// -------------------------------------------------------------------------
const angleInput = document.querySelector("#angle");
const playButton = document.querySelector("#play");
const labelsButton = document.querySelector("#labels");
const resetButton = document.querySelector("#reset");
angleInput.addEventListener("input", (event) => {
updateAngle(event.target.value);
});
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause rays" : "Play rays";
playButton.setAttribute("aria-pressed", String(playing));
});
labelsButton.addEventListener("click", () => {
const shouldShow = !labels[0].visible;
labels.forEach((label) => {
label.visible = shouldShow;
});
labelsButton.textContent = shouldShow ? "Hide labels" : "Show labels";
labelsButton.setAttribute("aria-pressed", String(shouldShow));
});
function resetView() {
view.theta = -0.31;
view.phi = 1.21;
view.radius = 15.2;
updateCamera();
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.theta -= deltaX * 0.005;
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.005,
0.68,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", () => {
dragging = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
10,
23
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
```