Prompt specification
Build or customize the Three.js 3D scene "Whisker contacts a nearby edge" 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: Whisker contacts a nearby edge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/whisker-contacts-a-nearby-edge-x0666
Scene Description Prompt:
Make one HTML file with Three.js from cdnjs: a voxel cat’s whisker bends against a box opening and triggers a contact indicator.
Working Three.js Starter (whisker-contacts-a-nearby-edge-x0666):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Cat — Box Contact</title>
<style>
:root {
color-scheme: dark;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101722;
color: #edf4ff;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
z-index: 2;
pointer-events: none;
}
.title-card {
left: 24px;
bottom: 24px;
max-width: min(360px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 18px;
background: rgba(13, 20, 31, 0.76);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 7px;
color: #72dbc2;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 32px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.description {
margin: 10px 0 0;
color: #aebbd0;
font-size: 13px;
line-height: 1.55;
}
.sensor {
top: 24px;
right: 24px;
display: flex;
align-items: center;
gap: 13px;
min-width: 218px;
padding: 14px 16px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 16px;
background: rgba(13, 20, 31, 0.78);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
transition:
border-color 180ms ease,
background 180ms ease,
box-shadow 180ms ease;
}
.sensor.active {
border-color: rgba(255, 91, 109, 0.8);
background: rgba(48, 18, 29, 0.86);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.32),
0 0 32px rgba(255, 63, 88, 0.22);
}
.lamp {
position: relative;
width: 17px;
height: 17px;
flex: 0 0 auto;
border-radius: 50%;
background: #45d7b4;
box-shadow: 0 0 13px rgba(69, 215, 180, 0.65);
transition:
background 160ms ease,
box-shadow 160ms ease;
}
.sensor.active .lamp {
background: #ff4f68;
box-shadow: 0 0 18px rgba(255, 79, 104, 0.95);
}
.sensor.active .lamp::after {
content: "";
position: absolute;
inset: -6px;
border: 1px solid rgba(255, 79, 104, 0.75);
border-radius: 50%;
animation: ping 1s ease-out infinite;
}
@keyframes ping {
from {
transform: scale(0.6);
opacity: 1;
}
to {
transform: scale(1.5);
opacity: 0;
}
}
.sensor-copy {
display: grid;
gap: 3px;
}
.sensor-label {
color: #8391a8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.sensor-value {
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sensor.active .sensor-value {
color: #ff8797;
}
.controls {
right: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 12px;
pointer-events: auto;
}
button {
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 12px;
padding: 11px 15px;
color: #eef5ff;
background: rgba(17, 27, 42, 0.86);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(12px);
transition:
transform 150ms ease,
border-color 150ms ease,
background 150ms ease;
}
button:hover {
transform: translateY(-2px);
border-color: rgba(114, 219, 194, 0.65);
background: rgba(27, 49, 57, 0.92);
}
button:active {
transform: translateY(0);
}
.hint {
color: #8795aa;
font-size: 11px;
text-shadow: 0 1px 8px #000;
}
@media (max-width: 700px) {
.title-card {
left: 14px;
bottom: 14px;
padding: 14px 16px;
}
.description {
display: none;
}
.sensor {
top: 14px;
right: 14px;
min-width: 190px;
padding: 12px 14px;
}
.controls {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="hud title-card">
<p class="eyebrow">Voxel contact study</p>
<h1>Curiosity, with consequences.</h1>
<p class="description">
A voxel cat probes the rim of a cardboard box. Its whisker bends on impact
and activates the contact sensor.
</p>
</section>
<section id="sensor" class="hud sensor" aria-live="polite">
<div class="lamp"></div>
<div class="sensor-copy">
<div class="sensor-label">Contact sensor</div>
<div id="sensorValue" class="sensor-value">No contact</div>
</div>
</section>
<div class="hud controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="replay" type="button">Replay contact</button>
</div>
<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 sensor = document.querySelector("#sensor");
const sensorValue = document.querySelector("#sensorValue");
const replayButton = document.querySelector("#replay");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101722);
scene.fog = new THREE.Fog(0x101722, 12, 24);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbdd9ff, 0x4b3025, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d7, 3.5);
keyLight.position.set(4.5, 8, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x70aaff, 1.8);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const materials = {
orange: new THREE.MeshStandardMaterial({
color: 0xd98238,
roughness: 0.82
}),
orangeDark: new THREE.MeshStandardMaterial({
color: 0xa95829,
roughness: 0.86
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf4dfb5,
roughness: 0.9
}),
pink: new THREE.MeshStandardMaterial({
color: 0xe99591,
roughness: 0.85
}),
black: new THREE.MeshStandardMaterial({
color: 0x121820,
roughness: 0.5
}),
green: new THREE.MeshStandardMaterial({
color: 0x75e1a8,
emissive: 0x164a35,
emissiveIntensity: 0.7,
roughness: 0.38
}),
white: new THREE.MeshStandardMaterial({
color: 0xfff9e9,
emissive: 0x332d22,
emissiveIntensity: 0.12,
roughness: 0.6
})
};
function makeBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Procedural cardboard texture: no external assets.
function makeCardboardTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 128;
const context = canvas.getContext("2d");
context.fillStyle = "#d49b59";
context.fillRect(0, 0, 128, 128);
for (let i = 0; i < 900; i++) {
const shade = 120 + Math.floor(Math.random() * 80);
context.fillStyle = `rgba(${shade}, ${Math.floor(shade * 0.68)}, 35, 0.16)`;
context.fillRect(
Math.random() * 128,
Math.random() * 128,
1 + Math.random() * 3,
1
);
}
for (let i = 0; i < 35; i++) {
context.strokeStyle = "rgba(255,225,170,0.12)";
context.beginPath();
const y = Math.random() * 128;
context.moveTo(0, y);
context.lineTo(128, y + Math.random() * 3 - 1.5);
context.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2, 2);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const cardboardTexture = makeCardboardTexture();
const cardboard = new THREE.MeshStandardMaterial({
color: 0xffffff,
map: cardboardTexture,
roughness: 0.96
});
const cardboardDark = new THREE.MeshStandardMaterial({
color: 0xb87c43,
map: cardboardTexture,
roughness: 1
});
const cardboardEdge = new THREE.MeshStandardMaterial({
color: 0x81532f,
roughness: 1
});
const tapeMaterial = new THREE.MeshStandardMaterial({
color: 0xe6c38c,
roughness: 0.72
});
// Ground.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x111a27,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(30, 30, 0x304158, 0x233047);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Voxel cat body.
makeBox(1.05, 1.42, 1.04, materials.orange, -1.72, 1.12, 0.22);
makeBox(0.28, 1.05, 0.78, materials.cream, -1.10, 1.12, 0.18);
makeBox(1.34, 1.16, 1.16, materials.orange, -1.60, 2.20, 0.25);
makeBox(1.22, 0.18, 1.02, materials.orangeDark, -1.66, 2.66, 0.25);
// Cheeks and muzzle.
makeBox(0.24, 0.29, 0.35, materials.cream, -0.86, 2.03, 0.01);
makeBox(0.24, 0.29, 0.35, materials.cream, -0.86, 2.03, 0.43);
makeBox(0.20, 0.18, 0.22, materials.cream, -0.75, 2.10, 0.22);
makeBox(0.10, 0.11, 0.14, materials.pink, -0.62, 2.13, 0.22);
// Eyes.
for (const z of [-0.12, 0.54]) {
makeBox(0.065, 0.19, 0.19, materials.black, -0.91, 2.37, z);
makeBox(0.028, 0.125, 0.125, materials.green, -0.865, 2.37, z);
makeBox(0.018, 0.045, 0.045, materials.white, -0.842, 2.42, z + 0.035);
}
// Forehead stripes.
for (const z of [-0.23, 0.12, 0.47]) {
makeBox(0.055, 0.19, 0.13, materials.orangeDark, -0.925, 2.63, z);
}
// Stepped voxel ears.
for (const z of [-0.10, 0.58]) {
makeBox(0.52, 0.58, 0.49, materials.orange, -1.72, 2.93, z);
makeBox(0.43, 0.28, 0.41, materials.orange, -1.72, 3.30, z);
makeBox(0.055, 0.38, 0.27, materials.pink, -1.44, 2.94, z);
}
// Body stripes and a blocky tail.
makeBox(0.18, 0.20, 1.08, materials.orangeDark, -2.29, 1.44, 0.22);
makeBox(0.30, 0.32, 0.72, materials.orangeDark, -2.35, 0.77, 0.06);
makeBox(0.31, 0.31, 0.55, materials.orange, -2.48, 0.48, -0.07);
makeBox(0.30, 0.30, 0.40, materials.cream, -2.48, 0.48, -0.35);
// Cardboard box, centered at x = 1.4.
const boxCenterX = 1.4;
const halfWidth = 1.6;
const halfDepth = 1.2;
const wallHeight = 1.48;
const wallY = 0.82;
// Bottom.
makeBox(3.2, 0.16, 2.4, cardboardDark, boxCenterX, 0.08, 0);
// Side walls. The left rim is the whisker contact point.
makeBox(0.16, wallHeight, 2.4, cardboard, -0.12, wallY, 0);
makeBox(0.16, wallHeight, 2.4, cardboard, 2.92, wallY, 0);
// Back and shortened front wall reveal the opening.
makeBox(3.2, wallHeight, 0.16, cardboard, boxCenterX, wallY, -1.12);
makeBox(3.2, 0.76, 0.16, cardboard, boxCenterX, 0.46, 1.12);
// Dark inner floor.
makeBox(2.88, 0.035, 2.08, cardboardDark, boxCenterX, 0.18, 0);
// Open flaps.
const backFlap = makeBox(3.04, 0.12, 0.94, cardboard, boxCenterX, 1.49, -1.61);
backFlap.rotation.x = -0.08;
const rightFlap = makeBox(0.94, 0.12, 2.22, cardboard, 3.40, 1.49, 0);
rightFlap.rotation.z = 0.08;
const frontFlap = makeBox(3.02, 0.12, 0.82, cardboard, boxCenterX, 1.43, 1.60);
frontFlap.rotation.x = 0.20;
// Flap seams and tape.
makeBox(2.92, 0.018, 0.035, cardboardEdge, boxCenterX, 1.56, -1.76);
makeBox(0.035, 0.018, 2.10, cardboardEdge, 3.76, 1.56, 0);
makeBox(0.34, 0.025, 0.78, tapeMaterial, 3.40, 1.57, 0.18);
makeBox(0.35, 0.025, 0.73, tapeMaterial, boxCenterX, 1.52, 1.62);
// Corrugated edge strips.
makeBox(0.17, 0.035, 2.39, cardboardEdge, -0.12, 1.57, 0);
makeBox(0.17, 0.035, 2.39, cardboardEdge, 2.92, 1.57, 0);
makeBox(3.18, 0.035, 0.17, cardboardEdge, boxCenterX, 1.57, -1.12);
// Whiskers are chains of tapered voxel-like cylinders.
const whiskerGeometry = new THREE.CylinderGeometry(0.014, 0.023, 1, 6);
const secondaryWhiskerGeometry = new THREE.CylinderGeometry(0.010, 0.017, 1, 6);
const axisY = new THREE.Vector3(0, 1, 0);
function createWhisker(segmentCount, geometry, material) {
const segments = [];
for (let i = 0; i < segmentCount; i++) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
scene.add(mesh);
segments.push(mesh);
}
return segments;
}
function setSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(axisY, direction.normalize());
mesh.scale.set(1, length, 1);
}
function cubicBezier(p0, p1, p2, p3, t, target) {
const s = 1 - t;
target.set(0, 0, 0);
target.addScaledVector(p0, s * s * s);
target.addScaledVector(p1, 3 * s * s * t);
target.addScaledVector(p2, 3 * s * t * t);
target.addScaledVector(p3, t * t * t);
return target;
}
function updateWhisker(segments, p0, p1, p2, p3) {
const point = new THREE.Vector3();
let previous = cubicBezier(p0, p1, p2, p3, 0, point).clone();
for (let i = 0; i < segments.length; i++) {
const next = cubicBezier(
p0,
p1,
p2,
p3,
(i + 1) / segments.length,
point
).clone();
setSegment(segments[i], previous, next);
previous = next;
}
}
const primaryWhisker = createWhisker(11, whiskerGeometry, materials.white);
const secondaryWhiskers = [
createWhisker(8, secondaryWhiskerGeometry, materials.white),
createWhisker(8, secondaryWhiskerGeometry, materials.white)
];
const whiskerRoot = new THREE.Vector3(-0.68, 2.02, 0.49);
const contactPoint = new THREE.Vector3(-0.20, 1.57, 0.56);
const contactDirection = new THREE.Vector3()
.subVectors(contactPoint, whiskerRoot)
.normalize();
const relaxedTip = contactPoint.clone().addScaledVector(contactDirection, -0.27);
const bentTip = contactPoint.clone().add(new THREE.Vector3(0, 0.13, 0));
// In-world contact indicator.
const contactMarkerMaterial = new THREE.MeshBasicMaterial({
color: 0x45d7b4,
transparent: true,
opacity: 0.3,
depthWrite: false
});
const contactMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 16, 12),
contactMarkerMaterial
);
contactMarker.position.copy(contactPoint).add(new THREE.Vector3(-0.015, 0, 0));
scene.add(contactMarker);
const contactRingMaterial = new THREE.MeshBasicMaterial({
color: 0x45d7b4,
transparent: true,
opacity: 0.22,
depthWrite: false
});
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.15, 0.017, 6, 32),
contactRingMaterial
);
contactRing.position.copy(contactMarker.position);
contactRing.rotation.y = Math.PI / 2;
scene.add(contactRing);
const contactLight = new THREE.PointLight(0xff405c, 0, 2.2, 2);
contactLight.position.copy(contactPoint).add(new THREE.Vector3(0.12, 0.12, 0));
scene.add(contactLight);
function smoothStep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
let contactActive = false;
let startTime = performance.now();
function setContactState(active) {
if (active === contactActive) return;
contactActive = active;
sensor.classList.toggle("active", active);
sensorValue.textContent = active ? "Contact detected" : "No contact";
}
function updatePrimaryWhisker(time, phase) {
let tip;
let bend = 0;
if (phase < 1.0) {
// Extend from the cheek.
const amount = smoothStep(phase);
tip = whiskerRoot
.clone()
.addScaledVector(contactDirection, 0.25)
.lerp(relaxedTip, amount);
} else if (phase < 2.0) {
// Approach the box rim.
const amount = smoothStep((phase - 1.0) / 1.0);
tip = relaxedTip.clone().lerp(contactPoint, amount);
} else if (phase < 4.3) {
// Impact: the tip curls upward against the edge.
const amount = smoothStep((phase - 2.0) / 1.25);
bend = amount;
tip = contactPoint.clone().lerp(bentTip, amount);
} else if (phase < 5.65) {
// Pull away from the rim.
const amount = smoothStep((phase - 4.3) / 1.35);
tip = bentTip.clone().lerp(relaxedTip, amount);
bend = 1 - amount;
} else {
tip = relaxedTip.clone();
}
const p1 = whiskerRoot
.clone()
.addScaledVector(contactDirection, 0.33)
.add(new THREE.Vector3(0, 0.025, 0));
const p2 = tip
.clone()
.addScaledVector(contactDirection, -0.22)
.add(new THREE.Vector3(0, 0.17 * bend, 0));
updateWhisker(primaryWhisker, whiskerRoot, p1, p2, tip);
}
function updateSecondaryWhiskers(time) {
const sway = Math.sin(time * 1.7) * 0.018;
const rootA = new THREE.Vector3(-0.69, 2.00, 0.08);
const tipA = new THREE.Vector3(-0.20, 1.84, 0.02).add(new THREE.Vector3(0, sway, 0));
const p1A = rootA.clone().lerp(tipA, 0.34);
const p2A = rootA.clone().lerp(tipA, 0.72);
updateWhisker(secondaryWhiskers[0], rootA, p1A, p2A, tipA);
const rootB = new THREE.Vector3(-0.69, 2.10, 0.34);
const tipB = new THREE.Vector3(-0.26, 2.25, 0.48).add(new THREE.Vector3(0, sway * 0.7, 0));
const p1B = rootB.clone().lerp(tipB, 0.34);
const p2B = rootB.clone().lerp(tipB, 0.72);
updateWhisker(secondaryWhiskers[1], rootB, p1B, p2B, tipB);
}
// Custom orbit controls, implemented without external addons.
const target = new THREE.Vector3(0.25, 1.55, 0);
const spherical = new THREE.Spherical(9.4, 1.18, 0.72);
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + dy * 0.005,
0.55,
1.45
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (lastPinchDistance / Math.max(distance, 1)),
6.0,
14.0
);
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius + event.deltaY * 0.006,
6.0,
14.0
);
},
{ passive: false }
);
replayButton.addEventListener("click", () => {
startTime = performance.now();
setContactState(false);
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
const cameraOffset = new THREE.Vector3();
renderer.setAnimationLoop((now) => {
const elapsed = (now - startTime) / 1000;
const phase = elapsed % 7.2;
cameraOffset.setFromSpherical(spherical);
camera.position.copy(target).add(cameraOffset);
camera.lookAt(target);
updatePrimaryWhisker(elapsed, phase);
updateSecondaryWhiskers(elapsed);
const active = phase >= 2.0 && phase < 4.3;
setContactState(active);
const pulse = 1 + Math.sin(elapsed * 9) * 0.14;
contactRing.scale.setScalar(active ? pulse : 1);
contactRingMaterial.opacity = active ? 0.9 : 0.18;
contactMarkerMaterial.opacity = active ? 1 : 0.3;
contactMarkerMaterial.color.setHex(active ? 0xff4f68 : 0x45d7b4);
contactRingMaterial.color.setHex(active ? 0xff4f68 : 0x45d7b4);
contactLight.intensity = active ? 1.8 + Math.sin(elapsed * 9) * 0.45 : 0;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```