Prompt specification
Build or customize the Three.js 3D scene "Park play-area social vignette" 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: Park play-area social vignette
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/park-play-area-social-vignette-x0671
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing dog play signals. Compose a fenced park corner with two dogs, handlers, water bowl, and open ground; show short alternating play and rest phases without crowded animal interactions. Stylized solid forms.
Working Three.js Starter (park-play-area-social-vignette-x0671):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PawCue — Play & Rest</title>
<style>
:root {
--ink: #173b3a;
--muted: #617674;
--cream: #fffaf0;
--play: #ef765f;
--rest: #4c9b91;
--line: rgba(23, 59, 58, 0.14);
--shadow: 0 18px 48px rgba(33, 58, 54, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce9e4;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 30px;
max-width: 470px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
border-radius: 99px;
background: var(--play);
content: "";
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 780;
letter-spacing: -0.055em;
line-height: 0.98;
}
.brand p {
max-width: 390px;
margin: 13px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.phase-card {
position: absolute;
top: 28px;
right: 30px;
width: 310px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 22px;
background: rgba(255, 250, 240, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
transition: border-color 220ms ease, transform 220ms ease;
}
.phase-card.play {
border-color: rgba(239, 118, 95, 0.38);
}
.phase-card.rest {
border-color: rgba(76, 155, 145, 0.38);
transform: translateY(2px);
}
.status-line {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 9px;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--play);
box-shadow: 0 0 0 6px rgba(239, 118, 95, 0.13);
animation: pulse 1.1s ease-in-out infinite;
}
.rest .status-dot {
background: var(--rest);
box-shadow: 0 0 0 6px rgba(76, 155, 145, 0.13);
animation-duration: 2.5s;
}
@keyframes pulse {
50% {
transform: scale(0.72);
opacity: 0.72;
}
}
#phaseName {
font-size: 13px;
font-weight: 900;
letter-spacing: 0.15em;
}
#phaseTimer {
color: var(--muted);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
#phaseCopy {
min-height: 40px;
margin: 12px 0 13px;
font-size: 14px;
font-weight: 650;
line-height: 1.42;
}
.signals {
display: grid;
gap: 7px;
}
.signal {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 10px;
border-radius: 11px;
background: rgba(23, 59, 58, 0.055);
color: var(--muted);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.035em;
transition: color 200ms ease, background 200ms ease;
}
.signal-icon {
display: grid;
width: 22px;
height: 22px;
place-items: center;
border-radius: 8px;
color: var(--play);
background: rgba(239, 118, 95, 0.11);
font-size: 12px;
font-weight: 900;
}
.rest .signal-icon {
color: var(--rest);
background: rgba(76, 155, 145, 0.11);
}
.timeline {
position: absolute;
bottom: 28px;
left: 30px;
width: min(560px, calc(100vw - 60px));
padding: 15px 17px 16px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 20px;
background: rgba(255, 250, 240, 0.9);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: auto;
cursor: pointer;
}
.timeline-meta {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
#timeReadout {
font-variant-numeric: tabular-nums;
letter-spacing: 0.04em;
}
.track {
position: relative;
display: flex;
height: 35px;
overflow: visible;
border-radius: 11px;
background: #e8ece5;
}
.segment {
display: flex;
align-items: center;
padding-left: 12px;
color: rgba(255, 255, 255, 0.95);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
}
.segment.play {
width: 55.5556%;
border-radius: 11px 0 0 11px;
background: var(--play);
}
.segment.rest {
width: 44.4444%;
border-radius: 0 11px 11px 0;
background: var(--rest);
}
#marker {
position: absolute;
top: 50%;
left: 0;
width: 16px;
height: 16px;
border: 3px solid var(--cream);
border-radius: 50%;
background: var(--ink);
box-shadow: 0 3px 10px rgba(23, 59, 58, 0.25);
transform: translate(-50%, -50%);
pointer-events: none;
}
.controls {
position: absolute;
right: 30px;
bottom: 28px;
display: flex;
gap: 8px;
pointer-events: auto;
}
.control-button {
min-width: 42px;
height: 42px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 13px;
color: var(--ink);
background: rgba(255, 250, 240, 0.9);
box-shadow: 0 10px 28px rgba(33, 58, 54, 0.11);
cursor: pointer;
font-size: 12px;
font-weight: 800;
transition: transform 150ms ease, background 150ms ease;
}
.control-button:hover {
transform: translateY(-2px);
background: #fffdf8;
}
.control-button:active {
transform: translateY(0);
}
.hint {
position: absolute;
right: 30px;
bottom: 82px;
color: rgba(23, 59, 58, 0.62);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--ink);
background: #dce9e4;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.brand {
top: 17px;
left: 17px;
max-width: 68%;
}
h1 {
font-size: 32px;
}
.brand p {
display: none;
}
.eyebrow {
margin-bottom: 7px;
font-size: 9px;
}
.phase-card {
top: 112px;
right: 16px;
width: 255px;
padding: 14px;
}
#phaseCopy {
min-height: 0;
margin: 9px 0 10px;
font-size: 12px;
}
.signal {
padding: 6px 8px;
font-size: 9px;
}
.signal-icon {
width: 19px;
height: 19px;
}
.timeline {
bottom: 17px;
left: 16px;
width: calc(100vw - 32px);
}
.controls {
top: 16px;
right: 16px;
bottom: auto;
}
.control-button {
width: 38px;
min-width: 38px;
height: 38px;
padding: 0;
}
.control-button .button-label {
display: none;
}
.hint {
display: none;
}
}
@media (max-height: 620px) {
.phase-card {
top: 85px;
}
.brand p,
.signals {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="hud">
<header class="brand">
<div class="eyebrow">PawCue · Social wellness</div>
<h1>Read the pause.</h1>
<p>
A roomy park corner where play bows, loose movement, and settling
are easy to recognize.
</p>
</header>
<section id="phaseCard" class="phase-card play" aria-live="polite">
<div class="status-line">
<span class="status-dot"></span>
<span id="phaseName">PLAY</span>
<span id="phaseTimer">5.0s</span>
</div>
<p id="phaseCopy">Bouncing gait, quick bows, and loose tails.</p>
<div class="signals">
<div class="signal">
<span id="signalIcon0" class="signal-icon">↘</span>
<span id="signalText0">Play bow with a soft front end</span>
</div>
<div class="signal">
<span id="signalIcon1" class="signal-icon">≈</span>
<span id="signalText1">Quick, buoyant tail wag</span>
</div>
<div class="signal">
<span id="signalIcon2" class="signal-icon">◎</span>
<span id="signalText2">Open mouth and relaxed face</span>
</div>
</div>
</section>
<section id="timeline" class="timeline" aria-label="Animation timeline">
<div class="timeline-meta">
<span>9-second play / rest rhythm</span>
<span id="timeReadout">0.0 / 9.0s</span>
</div>
<div class="track">
<div class="segment play">PLAY · 5s</div>
<div class="segment rest">REST · 4s</div>
<div id="marker"></div>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<div class="controls">
<button id="pauseButton" class="control-button" title="Pause or resume">
<span id="pauseIcon">Ⅱ</span>
<span class="button-label"> Pause</span>
</button>
<button id="nextButton" class="control-button" title="Next phase">
<span>⇥</span>
<span class="button-label"> Next</span>
</button>
<button id="resetButton" class="control-button" title="Reset camera">
<span>⌂</span>
<span class="button-label"> Reset view</span>
</button>
</div>
</div>
<div id="loading">Building the park…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const sceneHost = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
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;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce9e4);
scene.fog = new THREE.Fog(0xdce9e4, 30, 58);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.55, -0.3);
let cameraAzimuth = 0.66;
let cameraElevation = 0.67;
let cameraDistance = 28;
let cameraZoom = 1;
const hemi = new THREE.HemisphereLight(0xf7fbef, 0x7b8f78, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4da, 3.2);
sun.position.set(-8, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 15;
sun.shadow.camera.bottom = -15;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d8d5, 0.75);
fill.position.set(12, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Small geometry helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
const mats = {
baseGround: material(0xb9c9b6),
grass: material(0x8ead7d),
openGrass: material(0x9fbd89),
path: material(0xd7cfb8),
wood: material(0xcbb68c),
woodDark: material(0xa89066),
bark: material(0x87654d),
leaf: material(0x6e9670),
leafLight: material(0x83aa78),
stone: material(0xc9c3b5),
navy: material(0x244b4b),
coral: material(0xef765f),
teal: material(0x4c9b91),
cream: material(0xfff4dc),
water: material(0x65b8bd, { roughness: 0.18, metalness: 0.08 })
};
function addMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, mat, parent = scene, x = 0, y = 0, z = 0) {
const mesh = addMesh(new THREE.BoxGeometry(w, h, d), mat, parent);
mesh.position.set(x, y, z);
return mesh;
}
function addSphere(mat, parent = scene) {
return addMesh(new THREE.SphereGeometry(1, 24, 16), mat, parent);
}
function addCylinder(
topRadius,
bottomRadius,
height,
mat,
parent = scene,
segments = 24
) {
return addMesh(
new THREE.CylinderGeometry(topRadius, bottomRadius, height, segments),
mat,
parent
);
}
// -------------------------------------------------------------------------
// Park ground, paths, and fencing
// -------------------------------------------------------------------------
const baseGround = addBox(60, 0.5, 60, mats.baseGround, scene, 0, -0.56, 0);
baseGround.castShadow = false;
const park = addBox(18, 0.32, 13, mats.grass, scene, 0, -0.16, 0);
park.castShadow = false;
const openGround = addMesh(
new THREE.CircleGeometry(1, 64),
mats.openGrass,
scene
);
openGround.rotation.x = -Math.PI / 2;
openGround.scale.set(5.75, 3.55, 1);
openGround.position.set(0, 0.018, -0.05);
openGround.castShadow = false;
const path = addBox(18, 0.08, 1.35, mats.path, scene, 0, 0.025, 5.42);
path.castShadow = false;
function fencePost(x, z) {
addBox(0.18, 2.12, 0.18, mats.woodDark, scene, x, 1.02, z);
const cap = addSphere(mats.wood, scene);
cap.scale.set(0.14, 0.11, 0.14);
cap.position.set(x, 2.1, z);
}
// Back fence.
for (let i = 0; i <= 8; i++) {
fencePost(-8.8 + i * 2.2, -6.12);
}
for (let i = 0; i < 8; i++) {
const x = -7.7 + i * 2.2;
addBox(2.12, 0.13, 0.12, mats.wood, scene, x, 0.72, -6.12);
addBox(2.12, 0.13, 0.12, mats.wood, scene, x, 1.38, -6.12);
}
// Left fence forms the corner and stops before the foreground entrance.
for (let i = 0; i <= 5; i++) {
fencePost(-8.8, -6.12 + i * 2.05);
}
for (let i = 0; i < 5; i++) {
const z = -5.095 + i * 2.05;
addBox(0.12, 0.13, 1.98, mats.wood, scene, -8.8, 0.72, z);
addBox(0.12, 0.13, 1.98, mats.wood, scene, -8.8, 1.38, z);
}
// Small park sign.
const signCanvas = document.createElement("canvas");
signCanvas.width = 768;
signCanvas.height = 192;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#fff4dc";
signContext.fillRect(0, 0, 768, 192);
signContext.fillStyle = "#244b4b";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.font = "800 66px system-ui";
signContext.fillText("PAW · PLAY · PAUSE", 384, 94);
const signTexture = new THREE.CanvasTexture(signCanvas);
signTexture.colorSpace = THREE.SRGBColorSpace;
addBox(3.65, 0.92, 0.13, mats.woodDark, scene, 0, 1.33, -6.02);
const signFace = addMesh(
new THREE.PlaneGeometry(3.48, 0.78),
new THREE.MeshStandardMaterial({ map: signTexture, roughness: 0.9 }),
scene
);
signFace.position.set(0, 1.33, -5.945);
// -------------------------------------------------------------------------
// Bench, trees, and shrubs
// -------------------------------------------------------------------------
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
const trunk = addCylinder(0.22, 0.32, 2.25, mats.bark, tree);
trunk.position.y = 1.12;
const crownA = addSphere(mats.leaf, tree);
crownA.scale.set(1.2, 1.28, 1.15);
crownA.position.set(-0.35, 2.55, 0.1);
const crownB = addSphere(mats.leafLight, tree);
crownB.scale.set(1.05, 1.12, 1.02);
crownB.position.set(0.62, 2.72, -0.05);
const crownC = addSphere(mats.leaf, tree);
crownC.scale.set(0.95, 0.95, 0.95);
crownC.position.set(0.05, 3.35, 0.1);
return tree;
}
createTree(-7.45, -4.75, 1.04);
createTree(7.25, -4.85, 0.92);
function createShrub(x, z, scale = 1) {
const shrub = new THREE.Group();
shrub.position.set(x, 0, z);
shrub.scale.setScalar(scale);
scene.add(shrub);
for (let i = 0; i < 3; i++) {
const puff = addSphere(i === 1 ? mats.leafLight : mats.leaf, shrub);
puff.scale.set(0.62, 0.52, 0.58);
puff.position.set((i - 1) * 0.55, 0.42 + (i === 1 ? 0.13 : 0), 0);
}
}
createShrub(-7.8, -3.85, 0.8);
createShrub(7.85, -3.9, 0.72);
createShrub(-7.8, 1.05, 0.68);
const bench = new THREE.Group();
bench.position.set(3.1, 0, -4.82);
scene.add(bench);
addBox(3.15, 0.16, 0.76, mats.wood, bench, 0, 0.73, 0);
addBox(3.15, 0.82, 0.15, mats.wood, bench, 0, 1.18, -0.34);
addBox(0.16, 0.7, 0.58, mats.navy, bench, -1.2, 0.35, 0);
addBox(0.16, 0.7, 0.58, mats.navy, bench, 1.2, 0.35, 0);
addBox(0.16, 1.3, 0.16, mats.navy, bench, -1.3, 0.65, -0.28);
addBox(0.16, 1.3, 0.16, mats.navy, bench, 1.3, 0.65, -0.28);
// -------------------------------------------------------------------------
// Rest mats and water bowl
// -------------------------------------------------------------------------
function createMat(x, z, colorMat) {
const mat = addCylinder(1.37, 1.43, 0.06, colorMat, scene, 48);
mat.position.set(x, 0.055, z);
const rim = addMesh(
new THREE.TorusGeometry(1.37, 0.055, 8, 48),
mats.cream,
scene
);
rim.rotation.x = Math.PI / 2;
rim.position.set(x, 0.09, z);
}
createMat(-5.55, 2.35, mats.coral);
createMat(5.55, 2.35, mats.teal);
const bowlPad = addCylinder(0.82, 0.86, 0.08, mats.stone, scene, 40);
bowlPad.position.set(0, 0.055, 4.16);
const bowl = addCylinder(0.55, 0.42, 0.31, mats.teal, scene, 40);
bowl.position.set(0, 0.25, 4.16);
const bowlRim = addMesh(
new THREE.TorusGeometry(0.52, 0.065, 10, 40),
mats.cream,
scene
);
bowlRim.rotation.x = Math.PI / 2;
bowlRim.position.set(0, 0.405, 4.16);
const water = addMesh(
new THREE.CircleGeometry(0.455, 40),
mats.water,
scene
);
water.rotation.x = -Math.PI / 2;
water.position.set(0, 0.415, 4.16);
water.castShadow = false;
// -------------------------------------------------------------------------
// Stylized dog builder
// -------------------------------------------------------------------------
function createDog(options) {
const {
bodyColor,
chestColor,
earColor,
collarColor,
eyeColor = 0x1d2928,
noseColor = 0x26302f
} = options;
const root = new THREE.Group();
const model = new THREE.Group();
root.add(model);
scene.add(root);
const bodyMat = material(bodyColor);
const chestMat = material(chestColor);
const earMat = material(earColor);
const collarMat = material(collarColor);
const eyeMat = material(eyeColor, { roughness: 0.48 });
const noseMat = material(noseColor, { roughness: 0.55 });
const body = addSphere(bodyMat, model);
body.scale.set(0.67, 0.53, 1.02);
body.position.set(0, 0.82, 0);
const chest = addSphere(chestMat, model);
chest.scale.set(0.59, 0.48, 0.6);
chest.position.set(0, 0.78, 0.67);
const neck = addSphere(bodyMat, model);
neck.scale.set(0.42, 0.46, 0.42);
neck.position.set(0, 1.08, 0.67);
const head = new THREE.Group();
head.position.set(0, 1.3, 0.82);
model.add(head);
const headMesh = addSphere(bodyMat, head);
headMesh.scale.set(0.52, 0.5, 0.48);
const muzzle = addSphere(chestMat, head);
muzzle.scale.set(0.4, 0.25, 0.38);
muzzle.position.set(0, -0.09, 0.39);
const nose = addSphere(noseMat, head);
nose.scale.set(0.16, 0.12, 0.12);
nose.position.set(0, 0.0, 0.75);
const tongue = addSphere(mats.coral, head);
tongue.scale.set(0.095, 0.15, 0.055);
tongue.position.set(0, -0.3, 0.68);
const eyes = [];
for (const side of [-1, 1]) {
const eye = addSphere(eyeMat, head);
eye.scale.set(0.073, 0.085, 0.045);
eye.position.set(side * 0.2, 0.1, 0.425);
eyes.push(eye);
}
const earGroups = [];
for (const side of [-1, 1]) {
const ear = new THREE.Group();
ear.position.set(side * 0.43, 0.32, -0.03);
ear.rotation.z = side * 0.24;
ear.rotation.x = -0.08;
head.add(ear);
const earMesh = addSphere(earMat, ear);
earMesh.scale.set(0.19, 0.38, 0.145);
earMesh.position.y = -0.1;
earGroups.push(ear);
}
const collar = addMesh(
new THREE.TorusGeometry(0.42, 0.065, 8, 32),
collarMat,
head
);
collar.rotation.x = Math.PI / 2;
collar.position.set(0, -0.34, 0);
const tag = addSphere(mats.cream, head);
tag.scale.set(0.075, 0.075, 0.035);
tag.position.set(0, -0.48, 0.28);
const legs = [];
for (const front of [false, true]) {
for (const side of [-1, 1]) {
const leg = new THREE.Group();
leg.position.set(side * 0.37, 0.7, front ? 0.57 : -0.53);
model.add(leg);
const shin = addCylinder(0.13, 0.145, 0.62, bodyMat, leg, 16);
shin.position.y = -0.31;
const paw = addSphere(chestMat, leg);
paw.scale.set(0.17, 0.12, 0.22);
paw.position.set(0, -0.63, 0.07);
legs.push({ group: leg, front, side });
}
}
const tailPivot = new THREE.Group();
tailPivot.position.set(0, 0.98, -0.88);
model.add(tailPivot);
const tail = addCylinder(0.095, 0.14, 0.72, bodyMat, tailPivot, 16);
tail.position.set(0, 0.25, -0.14);
tail.rotation.x = -0.95;
const tailTip = addSphere(chestMat, tailPivot);
tailTip.scale.set(0.1, 0.11, 0.1);
tailTip.position.set(0, 0.38, -0.48);
return {
root,
model,
body,
chest,
neck,
head,
ears: earGroups,
eyes,
legs,
tailPivot
};
}
const goldenDog = createDog({
bodyColor: 0xd79a4c,
chestColor: 0xf2d39b,
earColor: 0xa76538,
collarColor: 0xef765f,
eyeColor: 0x39251c
});
const charcoalDog = createDog({
bodyColor: 0x4c5c5a,
chestColor: 0xd9d0bb,
earColor: 0x354340,
collarColor: 0x4c9b91,
eyeColor: 0x172321
});
// -------------------------------------------------------------------------
// Stylized handler builder
// -------------------------------------------------------------------------
function createHandler(options) {
const {
shirtColor,
trousersColor,
skinColor,
hairColor,
position,
rotation
} = options;
const root = new THREE.Group();
root.position.copy(position);
root.rotation.y = rotation;
scene.add(root);
const shirt = material(shirtColor);
const trousers = material(trousersColor);
const skin = material(skinColor);
const hair = material(hairColor);
const shoes = material(0x354440);
for (const side of [-1, 1]) {
const leg = addCylinder(0.13, 0.15, 0.76, trousers, root, 16);
leg.position.set(side * 0.19, 0.43, 0);
const shoe = addSphere(shoes, root);
shoe.scale.set(0.18, 0.12, 0.3);
shoe.position.set(side * 0.19, 0.12, 0.08);
}
const torso = addSphere(shirt, root);
torso.scale.set(0.47, 0.68, 0.32);
torso.position.set(0, 1.25, 0);
const neck = addCylinder(0.13, 0.15, 0.22, skin, root, 16);
neck.position.set(0, 1.83, 0);
const head = addSphere(skin, root);
head.scale.set(0.34, 0.39, 0.32);
head.position.set(0, 2.15, 0);
const hairMesh = addSphere(hair, root);
hairMesh.scale.set(0.36, 0.2, 0.34);
hairMesh.position.set(0, 2.38, -0.015);
const arms = [];
for (const side of [-1, 1]) {
const arm = new THREE.Group();
arm.position.set(side * 0.46, 1.61, 0);
root.add(arm);
const sleeve = addCylinder(0.105, 0.12, 0.72, shirt, arm, 16);
sleeve.position.y = -0.32;
const hand = addSphere(skin, arm);
hand.scale.set(0.12, 0.13, 0.12);
hand.position.y = -0.71;
arms.push(arm);
}
return { root, arms };
}
const leftHandler = createHandler({
shirtColor: 0xef765f,
trousersColor: 0x335958,
skinColor: 0xc98964,
hairColor: 0x40332c,
position: new THREE.Vector3(-7.25, 0.06, 2.42),
rotation: Math.PI / 2
});
const rightHandler = createHandler({
shirtColor: 0x4c9b91,
trousersColor: 0x354b52,
skinColor: 0x8f5c43,
hairColor: 0x242927,
position: new THREE.Vector3(7.25, 0.06, 2.42),
rotation: -Math.PI / 2
});
// -------------------------------------------------------------------------
// Individual play balls keep the dogs from converging on one object.
// -------------------------------------------------------------------------
function createBall(color) {
const group = new THREE.Group();
scene.add(group);
const ballMat = material(color, { roughness: 0.6 });
const sphere = addSphere(ballMat, group);
sphere.scale.setScalar(0.28);
const stripe = addMesh(
new THREE.TorusGeometry(0.205, 0.045, 8, 32),
mats.cream,
group
);
stripe.rotation.x = Math.PI / 2;
return group;
}
const leftBall = createBall(0xef765f);
const rightBall = createBall(0xf1bb55);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const CYCLE_LENGTH = 9;
const PLAY_LENGTH = 5;
const REST_LENGTH = CYCLE_LENGTH - PLAY_LENGTH;
let elapsed = 0;
let paused = false;
let lastTime = performance.now();
function clamp01(value) {
return Math.min(1, Math.max(0, value));
}
function smoothstep(edge0, edge1, value) {
const x = clamp01((value - edge0) / (edge1 - edge0));
return x * x * (3 - 2 * x);
}
function lerpAngle(a, b, amount) {
const delta = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + delta * amount;
}
function playBlend(cycleTime) {
if (cycleTime < PLAY_LENGTH) {
const enter = smoothstep(0, 0.9, cycleTime);
const leave = 1 - smoothstep(4.15, PLAY_LENGTH, cycleTime);
return enter * leave;
}
return 1 - smoothstep(PLAY_LENGTH, PLAY_LENGTH + 1, cycleTime);
}
function updateDog(dog, options) {
const { side, phaseOffset, playX, playZ, restX, restZ, ball } = options;
const cycleTime = elapsed % CYCLE_LENGTH;
const playAmount = playBlend(cycleTime);
const restAmount = 1 - playAmount;
const x = THREE.MathUtils.lerp(restX, playX, playAmount);
const z = THREE.MathUtils.lerp(restZ, playZ, playAmount);
dog.root.position.set(x, 0.06, z);
const restAngle = side < 0 ? 0.18 : -0.18;
const playAngle = side < 0 ? Math.PI / 2 : -Math.PI / 2;
dog.root.rotation.y = lerpAngle(restAngle, playAngle, playAmount);
const bounce = Math.abs(Math.sin(elapsed * 5.8 + phaseOffset));
const bowWave = Math.pow(
Math.max(0, Math.sin(elapsed * 2.25 + phaseOffset)),
5
);
const wag = Math.sin(elapsed * 8.5 + phaseOffset);
dog.model.position.y = bounce * 0.075 * playAmount;
dog.body.position.y = THREE.MathUtils.lerp(0.49, 0.82, playAmount);
dog.body.scale.y = THREE.MathUtils.lerp(0.76, 1, playAmount);
dog.body.rotation.x = 0.12 * bowWave * playAmount;
dog.chest.position.y = THREE.MathUtils.lerp(0.45, 0.78, playAmount);
dog.chest.rotation.x = dog.body.rotation.x;
dog.chest.scale.y = THREE.MathUtils.lerp(0.74, 1, playAmount);
dog.neck.position.y = THREE.MathUtils.lerp(0.72, 1.08, playAmount);
dog.neck.scale.y = THREE.MathUtils.lerp(0.83, 1, playAmount);
dog.head.position.y =
THREE.MathUtils.lerp(0.79, 1.3, playAmount) -
0.18 * bowWave * playAmount;
dog.head.position.z =
THREE.MathUtils.lerp(0.71, 0.82, playAmount) +
0.08 * bowWave * playAmount;
dog.head.rotation.x = 0.11 * bowWave * playAmount;
dog.ears.forEach((ear, index) => {
const side = index === 0 ? -1 : 1;
ear.rotation.z = side * THREE.MathUtils.lerp(0.29, 0.14, playAmount);
ear.rotation.x = -0.08 - 0.06 * bowWave * playAmount;
});
for (const leg of dog.legs) {
leg.group.position.y = THREE.MathUtils.lerp(0.25, 0.7, playAmount);
leg.group.scale.y = THREE.MathUtils.lerp(0.3, 1, playAmount);
leg.group.rotation.x = leg.front
? 0.58 * bowWave * playAmount
: -0.035 * bounce * playAmount;
leg.group.rotation.z = leg.side * 0.025 * bounce * playAmount;
}
dog.tailPivot.rotation.y = wag * THREE.MathUtils.lerp(0.08, 0.48, playAmount);
dog.tailPivot.rotation.x = THREE.MathUtils.lerp(-0.18, -0.42, playAmount);
// Occasional soft blink.
const blinkCycle = (elapsed + phaseOffset * 0.7) % 4.7;
const blink = blinkCycle < 0.13 ? 0.18 : 1;
dog.eyes.forEach((eye) => {
eye.scale.y = 0.085 * blink;
});
// Each ball remains in its own play lane.
const ballX = THREE.MathUtils.lerp(restX, side < 0 ? -2 : 2, playAmount);
const ballZ = THREE.MathUtils.lerp(restZ, 0.65, playAmount);
ball.position.set(
ballX,
0.08 + 0.29 + Math.abs(Math.sin(elapsed * 3.2 + phaseOffset)) * 0.34 * playAmount,
ballZ
);
ball.visible = playAmount > 0.025;
ball.scale.setScalar(Math.min(1, playAmount * 2));
ball.rotation.z = elapsed * 1.4 * playAmount;
ball.rotation.x = elapsed * 1.1 * playAmount;
}
function updateHandler(handler, phaseOffset, playAmount) {
const gesture =
0.5 + 0.5 * Math.sin(elapsed * 2.4 + phaseOffset);
handler.arms[0].rotation.x = THREE.MathUtils.lerp(
0.12,
-0.82,
playAmount * (0.55 + gesture * 0.45)
);
handler.arms[0].rotation.z = -0.12;
handler.arms[1].rotation.x = THREE.MathUtils.lerp(
0.08,
-0.35,
playAmount * gesture
);
handler.arms[1].rotation.z = 0.12;
handler.root.position.y =
0.06 + Math.sin(elapsed * 1.5 + phaseOffset) * 0.008;
}
// -------------------------------------------------------------------------
// HUD and controls
// -------------------------------------------------------------------------
const phaseCard = document.getElementById("phaseCard");
const phaseName = document.getElementById("phaseName");
const phaseTimer = document.getElementById("phaseTimer");
const phaseCopy = document.getElementById("phaseCopy");
const timeReadout = document.getElementById("timeReadout");
const marker = document.getElementById("marker");
const timeline = document.getElementById("timeline");
const signalIcons = [
document.getElementById("signalIcon0"),
document.getElementById("signalIcon1"),
document.getElementById("signalIcon2")
];
const signalTexts = [
document.getElementById("signalText0"),
document.getElementById("signalText1"),
document.getElementById("signalText2")
];
const playSignals = [
["↘", "Play bow with a soft front end"],
["≈", "Quick, buoyant tail wag"],
["◎", "Open mouth and relaxed face"]
];
const restSignals = [
["↓", "Head lowers and body settles"],
["=", "Loose, grounded posture"],
["○", "Breathing slows and softens"]
];
let lastHudPhase = "";
function updateHud(cycleTime) {
const isPlay = cycleTime < PLAY_LENGTH;
const phase = isPlay ? "PLAY" : "REST";
const remaining = isPlay
? PLAY_LENGTH - cycleTime
: CYCLE_LENGTH - cycleTime;
phaseName.textContent = phase;
phaseTimer.textContent = `${Math.max(0, remaining).toFixed(1)}s`;
timeReadout.textContent = `${cycleTime.toFixed(1)} / ${CYCLE_LENGTH.toFixed(1)}s`;
marker.style.left = `${(cycleTime / CYCLE_LENGTH) * 100}%`;
if (phase !== lastHudPhase) {
lastHudPhase = phase;
phaseCard.classList.toggle("play", isPlay);
phaseCard.classList.toggle("rest", !isPlay);
const signals = isPlay ? playSignals : restSignals;
phaseCopy.textContent = isPlay
? "Bouncing gait, quick bows, and loose tails."
: "Weight drops, heads soften, and the pause takes hold.";
signals.forEach((signal, index) => {
signalIcons[index].textContent = signal[0];
signalTexts[index].textContent = signal[1];
});
}
}
const pauseButton = document.getElementById("pauseButton");
const pauseIcon = document.getElementById("pauseIcon");
function setPaused(value) {
paused = value;
pauseIcon.textContent = paused ? "▶" : "Ⅱ";
pauseButton.setAttribute(
"aria-label",
paused ? "Resume animation" : "Pause animation"
);
}
pauseButton.addEventListener("click", () => {
setPaused(!paused);
});
document.getElementById("nextButton").addEventListener("click", () => {
const cycleTime = elapsed % CYCLE_LENGTH;
elapsed +=
cycleTime < PLAY_LENGTH
? PLAY_LENGTH - cycleTime
: CYCLE_LENGTH - cycleTime;
});
document.getElementById("resetButton").addEventListener("click", resetCamera);
timeline.addEventListener("pointerdown", (event) => {
const rect = timeline.getBoundingClientRect();
const ratio = clamp01((event.clientX - rect.left) / rect.width);
elapsed = ratio * CYCLE_LENGTH;
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setPaused(!paused);
} else if (event.key.toLowerCase() === "n") {
document.getElementById("nextButton").click();
} else if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Direct camera controls, implemented without addons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraAzimuth -= dx * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + dy * 0.004,
0.34,
1.25
);
});
function stopDragging() {
dragging = false;
renderer.domElement.classList.remove("dragging");
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(event.deltaY * 0.001),
0.72,
1.75
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
function resetCamera() {
cameraAzimuth = 0.66;
cameraElevation = 0.67;
cameraDistance = 28;
cameraZoom = 1;
}
function updateCamera() {
const horizontal = Math.cos(cameraElevation) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraAzimuth) * horizontal,
cameraTarget.y + Math.sin(cameraElevation) * cameraDistance,
cameraTarget.z + Math.cos(cameraAzimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(14.5, 21.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (!paused) {
elapsed += delta;
}
const cycleTime = elapsed % CYCLE_LENGTH;
const playAmount = playBlend(cycleTime);
updateDog(goldenDog, {
side: -1,
phaseOffset: 0.3,
playX: -3.55,
playZ: 0.65,
restX: -5.55,
restZ: 2.35,
ball: leftBall
});
updateDog(charcoalDog, {
side: 1,
phaseOffset: 1.7,
playX: 3.55,
playZ: 0.65,
restX: 5.55,
restZ: 2.35,
ball: rightBall
});
updateHandler(leftHandler, 0.5, playAmount);
updateHandler(rightHandler, 2.1, playAmount);
updateCamera();
updateHud(cycleTime);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```