Prompt specification
Build or customize the Three.js 3D scene "Courtyard communication experiment" 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: Courtyard communication experiment
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/courtyard-communication-experiment-x0383
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts a string telephone. Compose two visitors on opposite sides of a small courtyard using cup telephones; show synchronized speaking and receiving indicators linked by the visible string path. Voxel style.
Working Three.js Starter (courtyard-communication-experiment-x0383):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The String Line — Voxel Courtyard</title>
<style>
:root {
--ink: #25332f;
--paper: #f5edd8;
--amber: #f0a33b;
--teal: #56b9aa;
--muted: #718078;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c8ddd3;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
header {
position: absolute;
top: 25px;
left: 28px;
max-width: 430px;
}
.eyebrow {
display: inline-block;
margin-bottom: 9px;
padding: 5px 9px;
border: 2px solid var(--ink);
background: var(--paper);
box-shadow: 4px 4px 0 rgba(37, 51, 47, 0.22);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
}
h1 {
margin: 0;
font-size: clamp(27px, 4.2vw, 58px);
line-height: 0.95;
letter-spacing: -0.075em;
text-transform: uppercase;
text-shadow: 3px 3px 0 rgba(245, 237, 216, 0.55);
}
header p {
margin: 11px 0 0;
color: #43564e;
font-size: 12px;
letter-spacing: 0.05em;
}
#controls {
position: absolute;
top: 25px;
right: 28px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 10px;
pointer-events: auto;
}
.control-row {
display: flex;
gap: 8px;
}
#controls button {
border: 2px solid var(--ink);
padding: 10px 13px;
background: var(--paper);
color: var(--ink);
box-shadow: 4px 4px 0 rgba(37, 51, 47, 0.22);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition: transform 120ms ease, box-shadow 120ms ease;
}
#controls button:hover {
transform: translate(-1px, -1px);
box-shadow: 6px 6px 0 rgba(37, 51, 47, 0.22);
}
#controls button:active {
transform: translate(3px, 3px);
box-shadow: 1px 1px 0 rgba(37, 51, 47, 0.22);
}
.hint {
color: #43564e;
font-size: 10px;
letter-spacing: 0.05em;
}
#status-deck {
position: absolute;
right: 28px;
bottom: 25px;
left: 28px;
display: grid;
grid-template-columns: minmax(220px, 290px) 1fr minmax(220px, 290px);
align-items: end;
gap: 16px;
}
.status-card {
position: relative;
min-height: 116px;
border: 3px solid var(--ink);
padding: 14px 15px 13px;
background: rgba(245, 237, 216, 0.94);
box-shadow: 6px 6px 0 rgba(37, 51, 47, 0.2);
transition: background 160ms ease, transform 160ms ease;
}
.status-card.active {
background: #fff6dd;
transform: translateY(-4px);
}
#tx-card {
justify-self: start;
width: 100%;
}
#rx-card {
justify-self: end;
width: 100%;
}
.status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.visitor-name {
font-size: 15px;
font-weight: 900;
letter-spacing: 0.08em;
}
.state {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.state-dot {
width: 9px;
height: 9px;
border: 2px solid var(--ink);
background: #b9b4a4;
}
#tx-card .state-dot {
background: var(--amber);
}
#rx-card .state-dot {
background: var(--teal);
}
.state.active {
color: var(--ink);
}
.state.active .state-dot {
animation: blink 520ms steps(2, end) infinite;
}
.role {
margin-top: 7px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.level {
position: relative;
height: 10px;
margin-top: 13px;
overflow: hidden;
border: 2px solid var(--ink);
background: #d8d2bd;
}
.level i {
position: absolute;
inset: 0;
display: block;
transform: scaleX(0);
transform-origin: left;
background: var(--amber);
will-change: transform;
}
#rx-card .level i {
transform-origin: right;
background: var(--teal);
}
#link-badge {
justify-self: center;
align-self: end;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
min-width: 170px;
padding: 12px 15px;
border: 2px solid rgba(37, 51, 47, 0.7);
background: rgba(245, 237, 216, 0.84);
box-shadow: 4px 4px 0 rgba(37, 51, 47, 0.16);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.link-line {
position: relative;
width: 125px;
height: 4px;
overflow: hidden;
background: #9e9787;
}
.link-line::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 38px;
background: var(--amber);
transform: translateX(-45px);
}
#link-badge.active .link-line::after {
animation: travel 1.2s linear infinite;
}
@keyframes travel {
to { transform: translateX(135px); }
}
@keyframes blink {
50% { opacity: 0.35; }
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
}
header p {
display: none;
}
#controls {
top: 18px;
right: 18px;
}
.hint {
display: none;
}
#controls button {
padding: 9px 10px;
font-size: 9px;
}
#status-deck {
right: 16px;
bottom: 16px;
left: 16px;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.status-card {
min-height: 105px;
padding: 11px;
}
#link-badge {
position: absolute;
left: 50%;
bottom: 127px;
min-width: 145px;
transform: translateX(-50%);
padding: 9px 12px;
}
.visitor-name {
font-size: 12px;
}
.state {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<header>
<div class="eyebrow">Voxel Courtyard / Study 01</div>
<h1>The String Line</h1>
<p>Two voices. One visible connection.</p>
</header>
<div id="controls">
<div class="control-row">
<button id="call-button" type="button">Pause call</button>
<button id="reset-button" type="button">Reset view</button>
</div>
<div class="hint">DRAG TO ORBIT · WHEEL TO ZOOM · SPACE TO PAUSE</div>
</div>
<div id="status-deck">
<section id="tx-card" class="status-card active" aria-live="polite">
<div class="status-top">
<div class="visitor-name">MARA</div>
<div id="tx-state" class="state active">
<span class="state-dot"></span>
<span id="tx-label">Speaking</span>
</div>
</div>
<div class="role">Transmitter · left courtyard</div>
<div class="level"><i id="tx-level"></i></div>
</section>
<div id="link-badge" class="active">
<span id="link-label">Live string signal</span>
<span class="link-line"></span>
</div>
<section id="rx-card" class="status-card active" aria-live="polite">
<div class="status-top">
<div class="visitor-name">ELI</div>
<div id="rx-state" class="state active">
<span class="state-dot"></span>
<span id="rx-label">Receiving</span>
</div>
</div>
<div class="role">Receiver · right courtyard</div>
<div class="level"><i id="rx-level"></i></div>
</section>
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xc8ddd3);
scene.fog = new THREE.Fog(0xc8ddd3, 21, 35);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel courtyard with two visitors using string telephones"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-9, 9, 5.25, -5.25, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.45, 0);
const orbit = {
desired: { theta: 0.61, phi: 0.82, radius: 16.2 },
current: { theta: 0.61, phi: 0.82, radius: 16.2 }
};
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 1.15 ? 14 / aspect : 10.5;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
const hemisphere = new THREE.HemisphereLight(0xfff4d8, 0x658676, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe9bd, 3.2);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 28;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9bc8c0, 0.65);
fill.position.set(7, 5, -6);
scene.add(fill);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const zAxis = new THREE.Vector3(0, 0, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0,
...options
});
}
const materials = {
grass: material(0x829b78),
earth: material(0x756b54),
tileA: material(0xd8d1b9),
tileB: material(0xc8c8b5),
tileC: material(0xe4d9bd),
wall: material(0xc38d67),
wallCap: material(0xe3bf91),
wood: material(0x75513b),
darkWood: material(0x4d3b31),
planter: material(0xaa6048),
leafA: material(0x4f7853),
leafB: material(0x668d5d),
leafC: material(0x385f48),
stand: material(0x405b50),
cupA: material(0xd99046, { metalness: 0.2, roughness: 0.55 }),
cupB: material(0x64aa9d, { metalness: 0.2, roughness: 0.55 }),
cupRimA: material(0xf1bb6b, { metalness: 0.25, roughness: 0.5 }),
cupRimB: material(0x91d2c1, { metalness: 0.25, roughness: 0.5 }),
cupInside: material(0x3b3a34),
string: material(0x5b3b2d, {
emissive: 0xb8792c,
emissiveIntensity: 0.05,
roughness: 0.95
}),
signal: material(0xffd05b, {
emissive: 0xffa629,
emissiveIntensity: 1.5,
roughness: 0.4
}),
skinA: material(0xd89a70),
skinB: material(0x9c674b),
hairA: material(0x342c29),
hairB: material(0x57402f),
shirtA: material(0xe7a23a),
shirtB: material(0xd86650),
pantsA: material(0x365d68),
pantsB: material(0x4c4663),
shoes: material(0x303633),
eye: material(0x202725),
mouth: material(0x58362f),
white: material(0xf7f1df),
tx: material(0xf0a33b, {
emissive: 0xd86d16,
emissiveIntensity: 0.25
}),
rx: material(0x56b9aa, {
emissive: 0x238e83,
emissiveIntensity: 0.25
})
};
function block(
parent,
mat,
sx,
sy,
sz,
x = 0,
y = 0,
z = 0,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
// Courtyard platform and tiled ground.
block(scene, materials.grass, 13.3, 0.45, 9.4, 0, -0.27, 0, false, true);
block(scene, materials.earth, 13.7, 0.24, 9.8, 0, -0.54, 0, false, true);
const tileMaterials = [
materials.tileA,
materials.tileB,
materials.tileC
];
for (let ix = -6; ix <= 6; ix++) {
for (let iz = -4; iz <= 4; iz++) {
const index = Math.abs((ix * 3 + iz * 5) % 3);
block(
scene,
tileMaterials[index],
0.84,
0.1,
0.84,
ix * 0.91,
0.05,
iz * 0.9,
false,
true
);
}
}
// Low voxel courtyard walls.
for (let i = 0; i < 11; i++) {
const x = -5.7 + i * 1.14;
block(scene, materials.wall, 1.08, 0.82, 0.52, x, 0.46, -4.48);
block(scene, materials.wallCap, 1.12, 0.12, 0.59, x, 0.93, -4.48);
}
for (const x of [-6.25, 6.25]) {
for (let i = 0; i < 8; i++) {
const z = -3.93 + i * 1.05;
block(scene, materials.wall, 0.5, 0.74, 0.98, x, 0.42, z);
block(scene, materials.wallCap, 0.58, 0.11, 1.02, x, 0.85, z);
}
}
// Back bench.
block(scene, materials.wood, 3.25, 0.18, 0.62, 0, 0.75, -3.92);
block(scene, materials.wood, 3.25, 0.62, 0.15, 0, 1.12, -4.19);
block(scene, materials.darkWood, 0.22, 0.68, 0.46, -1.28, 0.38, -3.92);
block(scene, materials.darkWood, 0.22, 0.68, 0.46, 1.28, 0.38, -3.92);
function createTree(x, z) {
block(scene, materials.planter, 1.22, 0.48, 1.22, x, 0.29, z);
block(scene, materials.planter, 1.35, 0.12, 1.35, x, 0.55, z);
block(scene, materials.wood, 0.28, 1.48, 0.28, x, 1.23, z);
block(scene, materials.leafC, 1.2, 0.78, 1.1, x, 2.05, z);
block(scene, materials.leafA, 1.62, 0.76, 1.24, x - 0.18, 2.38, z);
block(scene, materials.leafB, 1.42, 0.7, 1.18, x + 0.34, 2.83, z);
block(scene, materials.leafC, 0.92, 0.64, 0.92, x - 0.6, 2.76, z);
}
createTree(-5.05, -3.15);
createTree(5.05, -3.15);
function createVisitor(x, z, rotation, palette) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
scene.add(group);
// Shoes and legs.
block(group, palette.shoes, 0.4, 0.23, 0.58, -0.22, 0.19, 0.1);
block(group, palette.shoes, 0.4, 0.23, 0.58, 0.22, 0.19, 0.1);
block(group, palette.pants, 0.35, 0.88, 0.39, -0.22, 0.72, 0);
block(group, palette.pants, 0.35, 0.88, 0.39, 0.22, 0.72, 0);
// Torso, collar and neck.
block(group, palette.shirt, 0.98, 1.06, 0.57, 0, 1.65, 0);
block(group, palette.shirt, 0.4, 0.2, 0.61, 0, 2.23, 0);
block(group, palette.skin, 0.3, 0.2, 0.3, 0, 2.38, 0);
// Head and voxel hair.
block(group, palette.skin, 0.68, 0.66, 0.62, 0, 2.76, 0);
block(group, palette.hair, 0.72, 0.18, 0.66, 0, 3.12, -0.01);
block(group, palette.hair, 0.16, 0.5, 0.6, -0.29, 2.86, -0.03);
block(group, palette.hair, 0.16, 0.5, 0.6, 0.29, 2.86, -0.03);
block(group, palette.hair, 0.68, 0.43, 0.12, 0, 2.88, -0.29);
// Face.
block(group, materials.eye, 0.09, 0.1, 0.05, -0.15, 2.83, 0.327, false, false);
block(group, materials.eye, 0.09, 0.1, 0.05, 0.15, 2.83, 0.327, false, false);
block(group, palette.skin, 0.1, 0.11, 0.09, 0, 2.72, 0.35, false, false);
const mouth = block(
group,
materials.mouth,
0.2,
0.06,
0.045,
0,
2.58,
0.337,
false,
false
);
// Resting arm.
block(group, palette.shirt, 0.3, 0.76, 0.35, -0.58, 1.69, 0.04);
block(group, palette.skin, 0.28, 0.28, 0.3, -0.58, 1.25, 0.08);
// Raised arm reaches toward the cup.
block(group, palette.shirt, 0.31, 0.58, 0.36, 0.58, 1.92, 0.22);
block(group, palette.shirt, 0.3, 0.31, 0.53, 0.58, 2.08, 0.48);
block(group, palette.skin, 0.29, 0.29, 0.3, 0.58, 2.12, 0.84);
return { group, mouth };
}
const mara = createVisitor(-4.15, 0.1, Math.PI / 2, {
skin: materials.skinA,
hair: materials.hairA,
shirt: materials.shirtA,
pants: materials.pantsA,
shoes: materials.shoes
});
const eli = createVisitor(4.15, 0.1, -Math.PI / 2, {
skin: materials.skinB,
hair: materials.hairB,
shirt: materials.shirtB,
pants: materials.pantsB,
shoes: materials.shoes
});
function createPhoneStand(x, cupMaterial, rimMaterial, handleSide) {
const stand = new THREE.Group();
stand.position.x = x;
scene.add(stand);
block(stand, materials.stand, 0.8, 0.12, 0.72, 0, 0.17, 0.1);
block(stand, materials.stand, 0.27, 1.42, 0.27, 0, 0.92, 0.1);
block(stand, materials.stand, 0.95, 0.14, 0.8, 0, 1.68, 0.1);
const cup = new THREE.Group();
cup.position.set(0, 1.75, 0.1);
stand.add(cup);
// Open, square tin cup.
block(cup, cupMaterial, 0.72, 0.1, 0.72, 0, 0.05, 0);
block(cup, cupMaterial, 0.72, 0.62, 0.09, 0, 0.36, 0.315);
block(cup, cupMaterial, 0.72, 0.62, 0.09, 0, 0.36, -0.315);
block(cup, cupMaterial, 0.09, 0.62, 0.54, 0.315, 0.36, 0);
block(cup, cupMaterial, 0.09, 0.62, 0.54, -0.315, 0.36, 0);
block(cup, materials.cupInside, 0.53, 0.035, 0.53, 0, 0.61, 0);
// Bright upper rims.
block(cup, rimMaterial, 0.76, 0.08, 0.1, 0, 0.69, 0.315);
block(cup, rimMaterial, 0.76, 0.08, 0.1, 0, 0.69, -0.315);
block(cup, rimMaterial, 0.1, 0.08, 0.56, 0.315, 0.69, 0);
block(cup, rimMaterial, 0.1, 0.08, 0.56, -0.315, 0.69, 0);
// Block-built handle on the outside of each cup.
const handleX = handleSide * 0.405;
block(cup, cupMaterial, 0.12, 0.45, 0.13, handleX, 0.36, 0);
block(cup, cupMaterial, 0.27, 0.1, 0.13, handleSide * 0.33, 0.57, 0);
block(cup, cupMaterial, 0.27, 0.1, 0.13, handleSide * 0.33, 0.15, 0);
// Small knot where the string joins the cup bottom.
block(cup, materials.darkWood, 0.12, 0.11, 0.12, 0, 0.005, 0);
return cup;
}
const leftCup = createPhoneStand(-3.05, materials.cupA, materials.cupRimA, -1);
const rightCup = createPhoneStand(3.05, materials.cupB, materials.cupRimB, 1);
// The sagging, visible telephone string.
const stringCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-3.05, 1.8, 0.1),
new THREE.Vector3(-2.55, 1.24, 0.08),
new THREE.Vector3(-1.45, 0.79, 0.05),
new THREE.Vector3(0, 0.62, 0.02),
new THREE.Vector3(1.45, 0.79, -0.03),
new THREE.Vector3(2.55, 1.24, -0.06),
new THREE.Vector3(3.05, 1.8, 0.1)
],
false,
"catmullrom",
0.22
);
const stringSegments = [];
const segmentCount = 68;
for (let i = 0; i < segmentCount; i++) {
const p0 = stringCurve.getPoint(i / segmentCount);
const p1 = stringCurve.getPoint((i + 1) / segmentCount);
const midpoint = p0.clone().lerp(p1, 0.5);
const direction = p1.clone().sub(p0).normalize();
const length = p0.distanceTo(p1);
const segment = block(
scene,
materials.string,
0.085,
0.085,
length + 0.025,
midpoint.x,
midpoint.y,
midpoint.z,
false,
false
);
segment.quaternion.setFromUnitVectors(zAxis, direction);
stringSegments.push({
mesh: segment,
basePosition: midpoint.clone()
});
}
// Bright signal packets traveling from Mara to Eli.
const packetOffsets = [0, 0.6, 1.2, 1.8, 2.4, 3.0];
const packetTravelTime = 1.2;
const packets = [];
for (let i = 0; i < packetOffsets.length; i++) {
const packet = new THREE.Group();
scene.add(packet);
block(packet, materials.signal, 0.19, 0.19, 0.19, 0, 0, 0, false, false);
block(packet, materials.signal, 0.14, 0.14, 0.14, 0, 0, -0.18, false, false);
block(packet, materials.signal, 0.09, 0.09, 0.09, 0, 0, -0.32, false, false);
packets.push(packet);
}
function createIndicator(x, mat) {
const group = new THREE.Group();
group.position.set(x, 3.53, 0.1);
scene.add(group);
const bars = [];
const baseHeights = [0.28, 0.48, 0.66, 0.48, 0.28];
for (let i = 0; i < 5; i++) {
const bar = block(
group,
mat,
0.15,
baseHeights[i],
0.15,
(i - 2) * 0.27,
baseHeights[i] / 2,
0,
false,
false
);
bars.push({ mesh: bar, baseHeight: baseHeights[i] });
}
return { group, bars };
}
const txIndicator = createIndicator(-4.15, materials.tx);
const rxIndicator = createIndicator(4.15, materials.rx);
function createLabel(text, accent, x) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const context = canvas.getContext("2d");
context.imageSmoothingEnabled = false;
context.fillStyle = "#25332f";
context.fillRect(0, 0, 512, 128);
context.fillStyle = accent;
context.fillRect(0, 0, 18, 128);
context.fillStyle = "#f5edd8";
context.font = "bold 48px monospace";
context.textBaseline = "middle";
context.fillText(text, 38, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
depthTest: false,
depthWrite: false
})
);
sprite.position.set(x, 4.18, 0.1);
sprite.scale.set(2.65, 0.66, 1);
sprite.renderOrder = 10;
scene.add(sprite);
}
createLabel("MARA / TX", "#f0a33b", -4.15);
createLabel("ELI / RX", "#56b9aa", 4.15);
// Direct camera controls, implemented without addon modules.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
orbit.desired.theta -= dx * 0.006;
orbit.desired.phi = THREE.MathUtils.clamp(
orbit.desired.phi - dy * 0.005,
0.42,
1.18
);
});
function endDrag(event) {
dragging = false;
if (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.desired.radius = THREE.MathUtils.clamp(
orbit.desired.radius + event.deltaY * 0.009,
10,
23
);
},
{ passive: false }
);
function resetView() {
orbit.desired.theta = 0.61;
orbit.desired.phi = 0.82;
orbit.desired.radius = 16.2;
}
renderer.domElement.addEventListener("dblclick", resetView);
let callActive = true;
let callClock = 0.78;
const callButton = document.getElementById("call-button");
const resetButton = document.getElementById("reset-button");
function toggleCall() {
callActive = !callActive;
callButton.textContent = callActive ? "Pause call" : "Resume call";
}
callButton.addEventListener("click", toggleCall);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
toggleCall();
}
if (event.key.toLowerCase() === "r") {
resetView();
}
});
const txCard = document.getElementById("tx-card");
const rxCard = document.getElementById("rx-card");
const txState = document.getElementById("tx-state");
const rxState = document.getElementById("rx-state");
const txLabel = document.getElementById("tx-label");
const rxLabel = document.getElementById("rx-label");
const txLevel = document.getElementById("tx-level");
const rxLevel = document.getElementById("rx-level");
const linkBadge = document.getElementById("link-badge");
const linkLabel = document.getElementById("link-label");
function updateIndicator(indicator, strength, phaseOffset, time) {
indicator.bars.forEach((bar, index) => {
const wave = 0.5 + 0.5 * Math.sin(time * 8 - index * 0.85 + phaseOffset);
const height = bar.baseHeight * (0.3 + strength * (0.58 + wave * 0.42));
bar.mesh.scale.y = height;
bar.mesh.position.y = height / 2;
});
}
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
if (callActive) {
callClock += dt;
}
const cycle = callClock % 5;
const txWindow = cycle < 3.0;
const rxWindow = cycle >= 0.6 && cycle < 4.2;
let txStrength = 0;
let rxStrength = 0;
let arrivalBoost = 0;
if (callActive && txWindow) {
txStrength = 0.68 + 0.32 * (0.5 + 0.5 * Math.sin(time * 9));
}
if (callActive && rxWindow) {
rxStrength = 0.58 + 0.22 * (0.5 + 0.5 * Math.sin(time * 8 + 1.3));
for (const offset of packetOffsets) {
const arrivalTime = offset + packetTravelTime;
if (cycle >= arrivalTime && cycle - arrivalTime < 0.55) {
arrivalBoost = Math.max(
arrivalBoost,
Math.exp(-(cycle - arrivalTime) * 8)
);
}
}
rxStrength = Math.min(1, rxStrength + arrivalBoost * 0.5);
}
// Signal packets are synchronized with the receiver activation.
packets.forEach((packet, index) => {
const age = cycle - packetOffsets[index];
const visible = callActive && age >= 0 && age <= packetTravelTime;
packet.visible = visible;
if (!visible) return;
const progress = THREE.MathUtils.clamp(age / packetTravelTime, 0, 1);
packet.position.copy(stringCurve.getPoint(progress));
const tangent = stringCurve.getTangent(progress).normalize();
packet.quaternion.setFromUnitVectors(zAxis, tangent);
});
// Tiny vibration makes the taut line visibly carry the signal.
const linkStrength = Math.max(txStrength, rxStrength);
stringSegments.forEach((segment, index) => {
segment.mesh.position.y =
segment.basePosition.y +
Math.sin(time * 18 + index * 0.73) * 0.022 * linkStrength;
});
materials.string.emissiveIntensity = 0.05 + linkStrength * 0.22;
mara.mouth.scale.y = 0.06 * (1 + txStrength * 1.8);
eli.mouth.scale.y = 0.06 * (1 + rxStrength * 1.7);
leftCup.rotation.z = Math.sin(time * 13) * 0.009 * linkStrength;
rightCup.rotation.z = Math.sin(time * 13 + 1) * 0.009 * linkStrength;
updateIndicator(txIndicator, txStrength, 0, time);
updateIndicator(rxIndicator, rxStrength, 1.8, time);
txCard.classList.toggle("active", txStrength > 0.05);
rxCard.classList.toggle("active", rxStrength > 0.05);
txState.classList.toggle("active", txStrength > 0.05);
rxState.classList.toggle("active", rxStrength > 0.05);
txLabel.textContent = !callActive
? "Paused"
: txWindow
? "Speaking"
: "Listening";
rxLabel.textContent = !callActive
? "Paused"
: rxWindow
? "Receiving"
: "Waiting";
txLevel.style.transform = `scaleX(${txStrength})`;
rxLevel.style.transform = `scaleX(${rxStrength})`;
linkBadge.classList.toggle("active", callActive);
linkLabel.textContent = callActive ? "Live string signal" : "Link paused";
// Smoothly damp the direct orbit camera.
const damping = 1 - Math.exp(-dt * 8);
orbit.current.theta +=
(orbit.desired.theta - orbit.current.theta) * damping;
orbit.current.phi +=
(orbit.desired.phi - orbit.current.phi) * damping;
orbit.current.radius +=
(orbit.desired.radius - orbit.current.radius) * damping;
const sinPhi = Math.sin(orbit.current.phi);
camera.position.set(
cameraTarget.x +
orbit.current.radius *
sinPhi *
Math.sin(orbit.current.theta),
cameraTarget.y + orbit.current.radius * Math.cos(orbit.current.phi),
cameraTarget.z +
orbit.current.radius *
sinPhi *
Math.cos(orbit.current.theta)
);
camera.lookAt(cameraTarget);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```