Prompt specification
Build or customize the Three.js 3D scene "Invitation and pause interaction" 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: Invitation and pause interaction
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/invitation-and-pause-interaction-x0670
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring dog play signals. Animate two dogs in a brief play sequence with bow, approach, and pause; use gentle motions and visible space so interaction changes can be followed clearly. Low-poly.
Working Three.js Starter (invitation-and-pause-interaction-x0670):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dog Play Signals</title>
<style>
:root {
--ink: #28332f;
--muted: #69746e;
--paper: rgba(255, 253, 246, 0.91);
--paper-solid: #fffdf6;
--line: rgba(40, 51, 47, 0.14);
--gold: #d79a43;
--blue: #667b91;
--green: #738b68;
--shadow: 0 14px 38px rgba(52, 61, 51, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button,
select {
color: var(--ink);
}
button {
cursor: pointer;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
position: absolute;
top: 22px;
left: 22px;
width: min(370px, calc(100vw - 44px));
padding: 19px 21px 18px;
border-radius: 20px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #75806f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(115, 139, 104, 0.13);
content: "";
}
h1 {
max-width: 330px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(26px, 3vw, 38px);
font-weight: 500;
line-height: 1.03;
letter-spacing: -0.035em;
}
.intro p {
max-width: 325px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.phase-card {
position: absolute;
top: 22px;
right: 22px;
width: 286px;
padding: 16px 18px;
border-radius: 18px;
}
.phase-topline {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.phase-kicker {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.time-readout {
color: #7c847d;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.phase-name {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 26px;
font-weight: 500;
}
.phase-dot {
width: 11px;
height: 11px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 5px rgba(215, 154, 67, 0.14);
transition: background 250ms ease, box-shadow 250ms ease;
}
.phase-card[data-phase="approach"] .phase-dot {
background: var(--green);
box-shadow: 0 0 0 5px rgba(115, 139, 104, 0.14);
}
.phase-card[data-phase="pause"] .phase-dot {
background: var(--blue);
box-shadow: 0 0 0 5px rgba(102, 123, 145, 0.14);
}
.phase-description {
min-height: 38px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.legend {
position: absolute;
bottom: 26px;
left: 22px;
width: 245px;
padding: 15px 16px;
border-radius: 18px;
}
.legend-title {
margin-bottom: 11px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 10px 46px 1fr;
align-items: center;
gap: 9px;
padding: 6px 0;
color: var(--muted);
font-size: 11px;
line-height: 1.25;
}
.legend-row strong {
color: var(--ink);
font-size: 11px;
}
.legend-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.dog-key {
display: flex;
flex-wrap: wrap;
gap: 9px;
margin-top: 12px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
}
.dog-key span {
display: flex;
align-items: center;
gap: 6px;
}
.transport {
position: absolute;
bottom: 24px;
left: 50%;
width: min(680px, calc(100vw - 590px));
min-width: 480px;
padding: 14px 16px 13px;
border-radius: 20px;
transform: translateX(-50%);
}
.transport-main {
display: flex;
align-items: center;
gap: 13px;
}
.icon-button {
display: inline-grid;
flex: 0 0 auto;
place-items: center;
width: 38px;
height: 38px;
padding: 0;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.76);
transition: transform 150ms ease, background 150ms ease;
}
.icon-button:hover {
background: white;
transform: translateY(-1px);
}
.icon-button.primary {
border-color: transparent;
background: var(--ink);
color: white;
}
.icon-button svg {
width: 16px;
height: 16px;
fill: currentColor;
}
.timeline-wrap {
position: relative;
flex: 1;
min-width: 0;
}
#timeline {
display: block;
width: 100%;
height: 18px;
margin: 0;
appearance: none;
background: transparent;
cursor: ew-resize;
}
#timeline::-webkit-slider-runnable-track {
height: 5px;
border-radius: 8px;
background:
linear-gradient(
to right,
var(--gold) 0%,
var(--gold) 28.5%,
var(--green) 28.5%,
var(--green) 69.5%,
var(--blue) 69.5%,
var(--blue) 100%
);
opacity: 0.86;
}
#timeline::-moz-range-track {
height: 5px;
border-radius: 8px;
background:
linear-gradient(
to right,
var(--gold) 0%,
var(--gold) 28.5%,
var(--green) 28.5%,
var(--green) 69.5%,
var(--blue) 69.5%,
var(--blue) 100%
);
opacity: 0.86;
}
#timeline::-webkit-slider-thumb {
width: 16px;
height: 16px;
margin-top: -5.5px;
appearance: none;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}
#timeline::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid var(--paper-solid);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}
.phase-steps {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 4px;
margin-top: 3px;
}
.phase-step {
padding: 4px 6px;
border: 0;
border-radius: 7px;
background: transparent;
color: #8b918c;
font-size: 10px;
font-weight: 700;
text-align: left;
transition: color 180ms ease, background 180ms ease;
}
.phase-step:nth-child(2) {
text-align: center;
}
.phase-step:nth-child(3) {
text-align: right;
}
.phase-step.active {
background: rgba(40, 51, 47, 0.07);
color: var(--ink);
}
.transport-options {
display: flex;
align-items: center;
gap: 8px;
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid var(--line);
}
.option-label {
margin-right: 2px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
}
select {
padding: 5px 25px 5px 8px;
border: 1px solid var(--line);
border-radius: 8px;
outline: none;
background: rgba(255, 255, 255, 0.74);
font-size: 10px;
}
.check-label {
display: flex;
align-items: center;
gap: 5px;
color: var(--muted);
font-size: 10px;
cursor: pointer;
}
.check-label input {
accent-color: var(--green);
}
.camera-hint {
margin-left: auto;
color: #8b918c;
font-size: 9px;
}
.dog-tag {
position: absolute;
z-index: 3;
min-width: 94px;
padding: 7px 10px 8px;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 12px;
background: rgba(255, 253, 246, 0.9);
box-shadow: 0 7px 20px rgba(48, 58, 48, 0.12);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
}
.dog-tag strong {
display: flex;
align-items: center;
gap: 6px;
font-size: 11px;
}
.dog-tag strong::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--gold);
content: "";
}
.dog-tag.blue strong::before {
background: var(--blue);
}
.dog-tag span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@media (max-width: 1000px) {
.legend {
display: none;
}
.transport {
left: 22px;
width: calc(100vw - 44px);
min-width: 0;
transform: none;
}
}
@media (max-width: 650px) {
.intro {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 16px;
}
.intro p {
display: none;
}
h1 {
font-size: 26px;
}
.phase-card {
top: 118px;
right: 12px;
width: 215px;
padding: 12px 14px;
}
.phase-name {
font-size: 21px;
}
.phase-description {
font-size: 10px;
}
.transport {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 11px;
}
.transport-options {
gap: 6px;
}
.camera-hint {
display: none;
}
.phase-step {
font-size: 9px;
}
.dog-tag {
min-width: 78px;
padding: 6px 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="hud">
<section class="intro panel" aria-label="Scene introduction">
<div class="eyebrow">Dog play signals</div>
<h1>A bow, a step closer, then a pause.</h1>
<p>
Watch how posture and space change during a gentle, low-pressure play invitation.
</p>
</section>
<section class="phase-card panel" id="phaseCard" data-phase="bow" aria-live="polite">
<div class="phase-topline">
<span class="phase-kicker">Current signal</span>
<span class="time-readout" id="timeReadout">0.0 / 11.2 s</span>
</div>
<div class="phase-name">
<span class="phase-dot"></span>
<span id="phaseName">Play bow</span>
</div>
<p class="phase-description" id="phaseDescription">
Front down, hips up — an invitation to play.
</p>
</section>
<aside class="legend panel" aria-label="Play signal guide">
<div class="legend-title">Read the sequence</div>
<div class="legend-row">
<span class="legend-dot" style="background: var(--gold)"></span>
<strong>Bow</strong>
<span>Lower head and raise hindquarters</span>
</div>
<div class="legend-row">
<span class="legend-dot" style="background: var(--green)"></span>
<strong>Approach</strong>
<span>Loose steps with visible personal space</span>
</div>
<div class="legend-row">
<span class="legend-dot" style="background: var(--blue)"></span>
<strong>Pause</strong>
<span>Still body and soft, attentive gaze</span>
</div>
<div class="dog-key">
<span><i class="legend-dot" style="background: var(--gold)"></i>Mochi</span>
<span><i class="legend-dot" style="background: var(--blue)"></i>Juniper</span>
</div>
</aside>
<section class="transport panel" aria-label="Animation controls">
<div class="transport-main">
<button class="icon-button primary" id="playButton" aria-label="Pause animation">
<svg id="playIcon" viewBox="0 0 24 24" aria-hidden="true">
<path d="M7 5h4v14H7zM13 5h4v14h-4z"></path>
</svg>
</button>
<button class="icon-button" id="replayButton" aria-label="Replay animation">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 5a7 7 0 1 1-6.7 9H2l3.5-4L9 14H6.35A5 5 0 1 0 12 7V5z"></path>
</svg>
</button>
<div class="timeline-wrap">
<input
id="timeline"
type="range"
min="0"
max="1000"
step="1"
value="0"
aria-label="Animation timeline"
/>
<div class="phase-steps" aria-label="Jump to signal">
<button class="phase-step active" data-time="0">01 · Bow</button>
<button class="phase-step" data-time="3.2">02 · Approach</button>
<button class="phase-step" data-time="7.8">03 · Pause</button>
</div>
</div>
</div>
<div class="transport-options">
<span class="option-label">Speed</span>
<select id="speedSelect" aria-label="Playback speed">
<option value="0.65">0.65×</option>
<option value="1" selected>1×</option>
<option value="1.35">1.35×</option>
</select>
<label class="check-label">
<input id="labelsToggle" type="checkbox" checked />
Labels
</label>
<button class="icon-button" id="cameraButton" aria-label="Reset camera" title="Reset camera">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M12 7a5 5 0 1 1-4.9 6H4l3.5-4L11 13H8.1A3 3 0 1 0 12 9V7zm3-5 3.5 4H16A5 5 0 1 0 17 13h2.1A7 7 0 1 1 15 4V2z"></path>
</svg>
</button>
<span class="camera-hint">Drag to orbit · Scroll to zoom</span>
</div>
</section>
<div class="dog-tag" id="goldTag">
<strong>Mochi</strong>
<span>play bow</span>
</div>
<div class="dog-tag blue" id="blueTag">
<strong>Juniper</strong>
<span>play bow</span>
</div>
<div class="sr-only" id="phaseLive" aria-live="polite"></div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Animated scene of two dogs exchanging play signals");
renderer.domElement.tabIndex = 0;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5d7);
scene.fog = new THREE.Fog(0xe9e5d7, 9, 19);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
40
);
const hemisphere = new THREE.HemisphereLight(0xfff8e7, 0x7b8975, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cf, 3.15);
sun.position.set(-4, 8, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 20;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xc8dce7, 0.7);
fill.position.set(6, 4, -5);
scene.add(fill);
// ------------------------------------------------------------
// Helpers and materials
// ------------------------------------------------------------
function standard(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...extra
});
}
function addMesh(parent, geometry, material, position, scale) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
if (scale) mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function smoothstep(min, max, value) {
const t = THREE.MathUtils.clamp((value - min) / (max - min), 0, 1);
return t * t * (3 - 2 * t);
}
function roundedRectangle(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + height - radius);
shape.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
shape.lineTo(x + radius, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
// ------------------------------------------------------------
// Park environment
// ------------------------------------------------------------
const outerGround = addMesh(
scene,
new THREE.CircleGeometry(6.4, 48),
standard(0xaebc94),
[0, -0.015, 0],
[1, 0.77, 1]
);
outerGround.rotation.x = -Math.PI / 2;
outerGround.castShadow = false;
const playPatch = addMesh(
scene,
new THREE.ShapeGeometry(roundedRectangle(8.9, 5.4, 1.45), 16),
standard(0xd8cda8),
[0, 0.008, 0]
);
playPatch.rotation.x = -Math.PI / 2;
playPatch.castShadow = false;
// Faint approach marks keep the direction of movement easy to follow.
const pathMaterial = standard(0xf5efd9, {
transparent: true,
opacity: 0.45,
depthWrite: false
});
for (let i = 0; i < 9; i++) {
const x = -2.7 + i * 0.675;
const mark = addMesh(
scene,
new THREE.BoxGeometry(0.26, 0.012, 0.045),
pathMaterial,
[x, 0.026, 0],
null
);
mark.rotation.y = i % 2 === 0 ? 0.05 : -0.05;
mark.castShadow = false;
mark.receiveShadow = false;
}
// Low-poly trees around the rear edge.
const trunkMaterial = standard(0x866c4f);
const leafMaterials = [
standard(0x71866a),
standard(0x849573),
standard(0x64795f)
];
function makeTree(x, z, scale = 1, variant = 0) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addMesh(
tree,
new THREE.CylinderGeometry(0.16, 0.23, 1.4, 6),
trunkMaterial,
[0, 0.7, 0]
);
addMesh(
tree,
new THREE.DodecahedronGeometry(0.9, 0),
leafMaterials[variant % leafMaterials.length],
[0, 1.8, 0],
[1, 1.08, 0.9]
);
addMesh(
tree,
new THREE.DodecahedronGeometry(0.62, 0),
leafMaterials[(variant + 1) % leafMaterials.length],
[0.43, 1.45, 0.08],
[1, 0.92, 0.88]
);
scene.add(tree);
}
makeTree(-4.65, -3.2, 1.18, 0);
makeTree(-2.7, -3.85, 0.92, 1);
makeTree(2.65, -3.72, 1.04, 2);
makeTree(4.65, -2.85, 1.2, 1);
const rockMaterial = standard(0xa9a693);
[
[-4.25, -1.85, 0.22],
[-3.75, -2.15, 0.14],
[3.9, -2.0, 0.18],
[4.35, -1.65, 0.12]
].forEach(([x, z, s]) => {
addMesh(
scene,
new THREE.DodecahedronGeometry(s, 0),
rockMaterial,
[x, s * 0.62, z],
[1.25, 0.75, 1]
);
});
// A bright tennis ball and a simple toy bone.
const ball = addMesh(
scene,
new THREE.IcosahedronGeometry(0.19, 0),
standard(0xe4c83f),
[3.55, 0.2, 1.35],
[1, 1, 1]
);
ball.rotation.set(0.3, 0.4, 0.2);
const bone = new THREE.Group();
bone.position.set(-3.45, 0.11, 1.5);
bone.rotation.y = -0.35;
const boneMaterial = standard(0xf2dfb8);
addMesh(
bone,
new THREE.CylinderGeometry(0.09, 0.09, 0.68, 6),
boneMaterial,
[0, 0, 0],
null
).rotation.z = Math.PI / 2;
[
[-0.36, 0.07, 0],
[-0.36, -0.07, 0],
[0.36, 0.07, 0],
[0.36, -0.07, 0]
].forEach((position) => {
addMesh(
bone,
new THREE.DodecahedronGeometry(0.13, 0),
boneMaterial,
position
);
});
scene.add(bone);
// ------------------------------------------------------------
// Low-poly dog construction
// ------------------------------------------------------------
const blackMaterial = standard(0x202624);
const noseMaterial = standard(0x202326);
const eyeWhiteMaterial = standard(0xfff9e8);
function createLeg(root, x, z, isFront, gaitOffset) {
const hip = new THREE.Group();
hip.position.set(x, isFront ? 0.78 : 0.82, z);
root.add(hip);
addMesh(
hip,
new THREE.CylinderGeometry(0.115, 0.145, 0.4, 6),
standard(0x000000, { color: 0x000000 }),
[0, -0.2, 0]
);
const knee = new THREE.Group();
knee.position.y = -0.37;
hip.add(knee);
addMesh(
knee,
new THREE.CylinderGeometry(0.095, 0.115, 0.32, 6),
standard(0x000000, { color: 0x000000 }),
[0, -0.16, 0]
);
addMesh(
knee,
new THREE.DodecahedronGeometry(0.17, 0),
standard(0x000000, { color: 0x000000 }),
[0.035, -0.34, 0],
[1.12, 0.76, 1.04]
);
return { hip, knee, gaitOffset, isFront };
}
function createDog({
name,
bodyColor,
lightColor,
muzzleColor,
collarColor,
startX,
rotation,
headTilt,
gaitOffset
}) {
const root = new THREE.Group();
root.position.x = startX;
root.rotation.y = rotation;
scene.add(root);
const bodyMaterial = standard(bodyColor);
const lightMaterial = standard(lightColor);
const muzzleMaterial = standard(muzzleColor);
const collarMaterial = standard(collarColor);
const bodyPivot = new THREE.Group();
bodyPivot.position.set(-0.28, 0.86, 0);
root.add(bodyPivot);
addMesh(
bodyPivot,
new THREE.DodecahedronGeometry(0.72, 0),
bodyMaterial,
[0.28, 0, 0],
[1.03, 0.68, 0.63]
);
addMesh(
bodyPivot,
new THREE.DodecahedronGeometry(0.46, 0),
lightMaterial,
[0.67, -0.04, 0],
[0.9, 0.94, 0.86]
);
// A subtle chest patch.
addMesh(
bodyPivot,
new THREE.DodecahedronGeometry(0.27, 0),
lightMaterial,
[0.86, -0.2, 0],
[0.78, 0.66, 0.78]
);
const headPivot = new THREE.Group();
headPivot.position.set(0.86, 0.23, 0);
bodyPivot.add(headPivot);
const head = addMesh(
headPivot,
new THREE.DodecahedronGeometry(0.48, 0),
bodyMaterial,
[0.13, 0.01, 0],
[0.96, 0.88, 0.84]
);
addMesh(
headPivot,
new THREE.DodecahedronGeometry(0.31, 0),
muzzleMaterial,
[0.5, -0.11, 0],
[1, 0.68, 0.76]
);
addMesh(
headPivot,
new THREE.IcosahedronGeometry(0.085, 0),
noseMaterial,
[0.73, -0.055, 0],
[1, 0.8, 0.92]
);
// Eyes are placed on both sides of the face.
[-1, 1].forEach((side) => {
addMesh(
headPivot,
new THREE.SphereGeometry(0.054, 8, 6),
eyeWhiteMaterial,
[0.35, 0.12, side * 0.225],
[1, 1, 0.55]
);
addMesh(
headPivot,
new THREE.SphereGeometry(0.028, 7, 5),
blackMaterial,
[0.37, 0.115, side * 0.255],
[1, 1, 0.5]
);
});
// Floppy, triangular ears.
[-1, 1].forEach((side) => {
const ear = addMesh(
headPivot,
new THREE.ConeGeometry(0.17, 0.43, 4),
bodyMaterial,
[-0.04, 0.35, side * 0.265],
[1, 1, 0.7]
);
ear.rotation.z = -0.12;
ear.rotation.x = side * 0.13;
});
// Collar sits around the neck.
const collar = addMesh(
bodyPivot,
new THREE.TorusGeometry(0.275, 0.045, 6, 12),
collarMaterial,
[0.68, 0.16, 0]
);
collar.rotation.y = Math.PI / 2;
addMesh(
bodyPivot,
new THREE.CylinderGeometry(0.065, 0.065, 0.035, 8),
standard(0xf2d276),
[0.7, -0.05, 0.26],
[1, 1, 0.45]
).rotation.x = Math.PI / 2;
const tailPivot = new THREE.Group();
tailPivot.position.set(-0.73, 0.09, 0);
bodyPivot.add(tailPivot);
addMesh(
tailPivot,
new THREE.CylinderGeometry(0.075, 0.135, 0.64, 6),
bodyMaterial,
[-0.29, 0, 0]
).rotation.z = Math.PI / 2;
addMesh(
tailPivot,
new THREE.DodecahedronGeometry(0.12, 0),
lightMaterial,
[-0.61, 0.015, 0],
[1.3, 0.8, 0.9]
);
const legs = [
createLeg(root, 0.52, 0.25, true, 0),
createLeg(root, 0.52, -0.25, true, Math.PI),
createLeg(root, -0.53, 0.25, false, Math.PI),
createLeg(root, -0.53, -0.25, false, 0)
];
// Colored ground halos make each dog's position easy to track.
const haloMaterial = new THREE.MeshBasicMaterial({
color: new THREE.Color(collarColor),
transparent: true,
opacity: 0.12,
depthWrite: false
});
const halo = addMesh(
scene,
new THREE.CircleGeometry(0.67, 32),
haloMaterial,
[startX, 0.035, 0]
);
halo.rotation.x = -Math.PI / 2;
halo.castShadow = false;
halo.receiveShadow = false;
return {
name,
root,
bodyPivot,
headPivot,
head,
tailPivot,
legs,
halo,
startX,
direction: rotation === 0 ? 1 : -1,
headTilt,
gaitOffset
};
}
const mochi = createDog({
name: "Mochi",
bodyColor: 0xd39a45,
lightColor: 0xe9bd6a,
muzzleColor: 0xf0d59b,
collarColor: 0xcf654e,
startX: -2.65,
rotation: 0,
headTilt: 0.075,
gaitOffset: 0
});
const juniper = createDog({
name: "Juniper",
bodyColor: 0x687c91,
lightColor: 0x91a3b4,
muzzleColor: 0xc9d1d2,
collarColor: 0x3e7f7b,
startX: 2.65,
rotation: Math.PI,
headTilt: -0.065,
gaitOffset: Math.PI
});
// ------------------------------------------------------------
// Timeline and pose animation
// ------------------------------------------------------------
const BOW_END = 3.2;
const APPROACH_END = 7.8;
const DURATION = 11.2;
let elapsed = 0;
let playing = true;
let speed = 1;
let currentPhase = "bow";
const phaseCard = document.querySelector("#phaseCard");
const phaseName = document.querySelector("#phaseName");
const phaseDescription = document.querySelector("#phaseDescription");
const timeReadout = document.querySelector("#timeReadout");
const phaseLive = document.querySelector("#phaseLive");
const timeline = document.querySelector("#timeline");
const playButton = document.querySelector("#playButton");
const playIcon = document.querySelector("#playIcon");
const replayButton = document.querySelector("#replayButton");
const speedSelect = document.querySelector("#speedSelect");
const labelsToggle = document.querySelector("#labelsToggle");
const cameraButton = document.querySelector("#cameraButton");
const phaseSteps = [...document.querySelectorAll(".phase-step")];
const goldTag = document.querySelector("#goldTag");
const blueTag = document.querySelector("#blueTag");
function updateDog(dog, time, bowAmount, approachAmount, pauseAmount) {
const walkTime = Math.max(0, time - BOW_END);
const walkProgress = THREE.MathUtils.clamp(
(time - BOW_END) / (APPROACH_END - BOW_END),
0,
1
);
const walkIntensity =
time >= BOW_END && time <= APPROACH_END
? Math.sin(Math.PI * walkProgress)
: 0;
const cycle = walkTime * 8.2 + dog.gaitOffset;
const bob = Math.abs(Math.sin(cycle)) * 0.055 * walkIntensity;
dog.root.position.x =
dog.startX + dog.direction * 1.08 * approachAmount;
dog.root.position.y = bob;
dog.halo.position.x = dog.root.position.x;
dog.halo.material.opacity = 0.1 + 0.035 * (1 - walkIntensity);
// Bow: hips rise slightly while the head lowers toward the ground.
dog.bodyPivot.position.y = 0.86 + bowAmount * 0.1 - pauseAmount * 0.02;
dog.bodyPivot.rotation.z =
-0.12 * bowAmount - 0.015 * pauseAmount;
dog.headPivot.rotation.z =
-0.4 * bowAmount +
dog.headTilt * pauseAmount +
Math.sin(time * 2.1 + dog.gaitOffset) * 0.018;
dog.headPivot.rotation.y =
Math.sin(time * 1.7 + dog.gaitOffset) * 0.025;
// Tail motion is quick during the bow, relaxed during the pause.
const wagFrequency = 8.5 + bowAmount * 4.5 - pauseAmount * 4;
const wagAmplitude = 0.18 + bowAmount * 0.2 + pauseAmount * 0.08;
dog.tailPivot.rotation.y = Math.sin(time * wagFrequency) * wagAmplitude;
dog.tailPivot.rotation.z =
0.13 + bowAmount * 0.27 - pauseAmount * 0.08;
dog.legs.forEach((leg, index) => {
const isOppositeForeleg = index === 0 || index === 3;
const sideOffset = leg.gaitOffset + dog.gaitOffset;
const swing =
Math.sin(cycle + sideOffset) * 0.34 * walkIntensity;
let hipAngle = swing;
let kneeAngle = Math.max(0, -Math.sin(cycle + sideOffset)) * 0.28;
if (leg.isFront) {
hipAngle -= bowAmount * 0.025;
kneeAngle += bowAmount * 0.02;
} else {
hipAngle += bowAmount * 0.24;
kneeAngle += bowAmount * 0.46;
}
// During the pause, Juniper softly lifts one near forepaw.
const raisedPaw =
dog.name === "Juniper" && index === 0
? pauseAmount * 0.16
: 0;
hipAngle -= raisedPaw;
kneeAngle += raisedPaw * 0.8;
hipAngle *= 1 - pauseAmount * 0.8;
kneeAngle *= 1 - pauseAmount * 0.75;
leg.hip.rotation.z = hipAngle;
leg.knee.rotation.z = kneeAngle;
});
}
function getPhase(time) {
if (time < BOW_END) return "bow";
if (time < APPROACH_END) return "approach";
return "pause";
}
function updatePhaseUI(phase) {
if (phase === currentPhase) return;
currentPhase = phase;
phaseCard.dataset.phase = phase;
if (phase === "bow") {
phaseName.textContent = "Play bow";
phaseDescription.textContent =
"Front down, hips up — an invitation to play.";
goldTag.querySelector("span").textContent = "play bow";
blueTag.querySelector("span").textContent = "play bow";
phaseLive.textContent = "Play bow: both dogs lower their heads and raise their hindquarters.";
} else if (phase === "approach") {
phaseName.textContent = "Approach";
phaseDescription.textContent =
"Loose steps and curved bodies — closing space without pressure.";
goldTag.querySelector("span").textContent = "gentle approach";
blueTag.querySelector("span").textContent = "gentle approach";
phaseLive.textContent = "Approach: both dogs move toward each other with gentle steps.";
} else {
phaseName.textContent = "Pause";
phaseDescription.textContent =
"Still bodies and soft eyes — checking the other dog.";
goldTag.querySelector("span").textContent = "soft pause";
blueTag.querySelector("span").textContent = "soft pause";
phaseLive.textContent = "Pause: both dogs stop and hold a calm, attentive posture.";
}
phaseSteps.forEach((button) => {
const buttonPhase =
Number(button.dataset.time) === 0
? "bow"
: Number(button.dataset.time) === BOW_END
? "approach"
: "pause";
button.classList.toggle("active", buttonPhase === phase);
});
}
function updatePlayButton() {
if (elapsed >= DURATION) {
playIcon.innerHTML =
'<path d="M8 5v14l11-7z"></path>';
playButton.setAttribute("aria-label", "Replay animation");
} else if (playing) {
playIcon.innerHTML =
'<path d="M7 5h4v14H7zM13 5h4v14h-4z"></path>';
playButton.setAttribute("aria-label", "Pause animation");
} else {
playIcon.innerHTML =
'<path d="M8 5v14l11-7z"></path>';
playButton.setAttribute("aria-label", "Play animation");
}
}
function updatePose(time) {
const bowAmount =
smoothstep(0, 0.65, time) *
(1 - smoothstep(BOW_END - 0.65, BOW_END, time));
const approachAmount = smoothstep(BOW_END, APPROACH_END, time);
const pauseAmount = smoothstep(APPROACH_END, APPROACH_END + 0.8, time);
updateDog(mochi, time, bowAmount, approachAmount, pauseAmount);
updateDog(juniper, time, bowAmount, approachAmount, pauseAmount);
const phase = getPhase(time);
updatePhaseUI(phase);
timeline.value = String(Math.round((time / DURATION) * 1000));
timeReadout.textContent = `${time.toFixed(1)} / ${DURATION.toFixed(1)} s`;
}
// ------------------------------------------------------------
// Custom orbit-style camera controls
// ------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 0.66, 0);
const defaultCamera = {
yaw: 0.48,
pitch: 0.38,
radius: window.innerWidth < 650 ? 11.6 : 10.1
};
const desiredCamera = { ...defaultCamera };
const currentCamera = { ...defaultCamera };
let dragging = false;
let dragX = 0;
let dragY = 0;
function applyCamera() {
const horizontalRadius = Math.cos(currentCamera.pitch) * currentCamera.radius;
camera.position.set(
cameraTarget.x + Math.sin(currentCamera.yaw) * horizontalRadius,
cameraTarget.y + Math.sin(currentCamera.pitch) * currentCamera.radius,
cameraTarget.z + Math.cos(currentCamera.yaw) * horizontalRadius
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
desiredCamera.yaw -= dx * 0.006;
desiredCamera.pitch = THREE.MathUtils.clamp(
desiredCamera.pitch + dy * 0.004,
0.18,
0.82
);
dragX = event.clientX;
dragY = event.clientY;
});
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();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.007,
6.8,
13.5
);
},
{ passive: false }
);
cameraButton.addEventListener("click", () => {
desiredCamera.yaw = defaultCamera.yaw;
desiredCamera.pitch = defaultCamera.pitch;
desiredCamera.radius = defaultCamera.radius;
});
// ------------------------------------------------------------
// UI interactions
// ------------------------------------------------------------
playButton.addEventListener("click", () => {
if (elapsed >= DURATION) {
elapsed = 0;
playing = true;
} else {
playing = !playing;
}
updatePlayButton();
});
replayButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
updatePlayButton();
});
speedSelect.addEventListener("change", () => {
speed = Number(speedSelect.value);
});
timeline.addEventListener("input", () => {
elapsed = (Number(timeline.value) / 1000) * DURATION;
playing = false;
updatePlayButton();
updatePose(elapsed);
});
phaseSteps.forEach((button) => {
button.addEventListener("click", () => {
elapsed = Number(button.dataset.time);
playing = false;
updatePlayButton();
updatePose(elapsed);
});
});
labelsToggle.addEventListener("change", () => {
const visible = labelsToggle.checked;
goldTag.style.display = visible ? "block" : "none";
blueTag.style.display = visible ? "block" : "none";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
playButton.click();
}
});
// ------------------------------------------------------------
// Project dog labels into screen space
// ------------------------------------------------------------
const projected = new THREE.Vector3();
const labelWorld = new THREE.Vector3();
function updateDogTag(dog, element, horizontalOffset) {
if (!labelsToggle.checked) return;
dog.head.getWorldPosition(labelWorld);
labelWorld.y += 0.62;
projected.copy(labelWorld).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + horizontalOffset;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// ------------------------------------------------------------
// Resize and animation loop
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
let lastTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed += delta * speed;
if (elapsed >= DURATION) {
elapsed = DURATION;
playing = false;
updatePlayButton();
}
}
updatePose(elapsed);
const easing = 1 - Math.exp(-delta * 8);
currentCamera.yaw = THREE.MathUtils.lerp(
currentCamera.yaw,
desiredCamera.yaw,
easing
);
currentCamera.pitch = THREE.MathUtils.lerp(
currentCamera.pitch,
desiredCamera.pitch,
easing
);
currentCamera.radius = THREE.MathUtils.lerp(
currentCamera.radius,
desiredCamera.radius,
easing
);
applyCamera();
scene.updateMatrixWorld();
updateDogTag(mochi, goldTag, -32);
updateDogTag(juniper, blueTag, 32);
renderer.render(scene, camera);
}
updatePlayButton();
updatePose(0);
applyCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```