Prompt specification
Build or customize the Three.js 3D scene "Calm adoption homecoming scene" 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: Calm adoption homecoming scene
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/calm-adoption-homecoming-scene-x3843
Scene Description Prompt:
Calm adoption homecoming scene. Compose a small living room with carrier, hiding place, water, and seated household members; the animal explores a short voluntary route without being chased or handled. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (calm-adoption-homecoming-scene-x3843):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Calm Adoption Homecoming</title>
<style>
html, body {
margin: 0; height: 100%; overflow: hidden;
background: radial-gradient(120% 95% at 50% 18%, #333a48 0%, #1d2029 58%, #12141a 100%);
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
color: #f4efe8;
}
#scene { position: fixed; inset: 0; }
canvas { display: block; }
.card {
position: fixed; pointer-events: none;
background: rgba(255,255,255,.075);
-webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,.14);
border-radius: 14px; padding: 13px 16px;
box-shadow: 0 12px 34px rgba(0,0,0,.38);
}
#title { top: 18px; left: 18px; width: 268px; }
#title h1 { font-size: 16px; margin: 0 0 4px; font-weight: 600; letter-spacing: .2px; }
#title p { margin: 0 0 10px; font-size: 12px; line-height: 1.55; color: rgba(244,239,232,.72); }
#stages { list-style: none; margin: 0; padding: 0; }
#stages li {
font-size: 11.5px; color: rgba(244,239,232,.45);
padding: 3px 0 3px 14px; position: relative; transition: color .4s;
}
#stages li::before {
content: ""; position: absolute; left: 0; top: 9px;
width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.22); transition: all .4s;
}
#stages li.on { color: #ffd9a8; }
#stages li.on::before { background: #ffbe7a; box-shadow: 0 0 9px #ffbe7a; }
#status {
bottom: 18px; left: 18px; font-size: 13px;
display: flex; align-items: center; gap: 10px; pointer-events: none;
}
#status .dot {
width: 8px; height: 8px; border-radius: 50%;
background: #7fd1b9; box-shadow: 0 0 10px #7fd1b9;
}
#hint {
bottom: 18px; right: 18px; font-size: 11.5px;
color: rgba(244,239,232,.55); line-height: 1.7; text-align: right;
}
#hint b { color: rgba(244,239,232,.85); font-weight: 600; }
#labels { position: fixed; inset: 0; pointer-events: none; }
#labels div {
position: absolute; transform: translate(-50%, -118%);
font-size: 11px; color: #f7f2e9; background: rgba(18,20,26,.55);
border: 1px solid rgba(255,255,255,.16); padding: 3px 9px; border-radius: 20px;
white-space: nowrap; transition: opacity .35s;
}
#labels div::after {
content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -3px;
border: 3px solid transparent; border-top-color: rgba(18,20,26,.55);
}
button {
pointer-events: auto; margin-top: 8px; cursor: pointer;
font: inherit; font-size: 11px; color: #f4efe8;
background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
border-radius: 20px; padding: 4px 12px;
}
button:hover { background: rgba(255,255,255,.2); }
button.off { opacity: .5; }
</style>
</head>
<body>
<div id="scene"></div>
<div id="labels"></div>
<div class="card" id="title">
<h1>Calm adoption homecoming</h1>
<p>The carrier door is open. Nobody reaches in — the animal steps out, explores, drinks, and settles on its own terms.</p>
<ul id="stages">
<li>01 · Settling in the carrier</li>
<li>02 · Stepping out & sniffing</li>
<li>03 · The hiding place</li>
<li>04 · Water</li>
<li>05 · The household</li>
</ul>
<button id="toggleLabels">Labels: on</button>
</div>
<div class="card" id="status"><span class="dot"></span><span id="statusText">Settling in the carrier</span></div>
<div class="card" id="hint">
<b>Drag</b> to orbit · <b>Scroll</b> to zoom<br>
<b>Shift-drag</b> pan · <b>Double-click</b> reset view
</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 */
/* ------------------------------------------------------------------ */
const host = document.getElementById('scene');
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.06;
renderer.outputColorSpace = THREE.SRGBColorSpace;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 120);
/* ------------------------------------------------------------------ */
/* materials + geometry helpers */
/* ------------------------------------------------------------------ */
const std = (color, o = {}) => new THREE.MeshStandardMaterial({ color, roughness: 0.88, metalness: 0.0, ...o });
function mesh(parent, geo, mat, x = 0, y = 0, z = 0, cast = true) {
const m = new THREE.Mesh(geo, mat);
m.position.set(x, y, z);
m.castShadow = cast;
m.receiveShadow = true;
parent.add(m);
return m;
}
const box = (p, w, h, d, mat, x = 0, y = 0, z = 0, cast = true) => mesh(p, new THREE.BoxGeometry(w, h, d), mat, x, y, z, cast);
const cyl = (p, rt, rb, h, seg, mat, x = 0, y = 0, z = 0, cast = true) => mesh(p, new THREE.CylinderGeometry(rt, rb, h, seg), mat, x, y, z, cast);
const cap = (p, r, len, mat, x = 0, y = 0, z = 0, cs = 5, rs = 14) => mesh(p, new THREE.CapsuleGeometry(r, len, cs, rs), mat, x, y, z);
const sph = (p, r, mat, x = 0, y = 0, z = 0, w = 20, h = 14) => mesh(p, new THREE.SphereGeometry(r, w, h), mat, x, y, z);
function roundedRect(c, w, h, r) {
const p = new c();
p.moveTo(-w / 2 + r, -h / 2);
p.lineTo(w / 2 - r, -h / 2);
p.quadraticCurveTo(w / 2, -h / 2, w / 2, -h / 2 + r);
p.lineTo(w / 2, h / 2 - r);
p.quadraticCurveTo(w / 2, h / 2, w / 2 - r, h / 2);
p.lineTo(-w / 2 + r, h / 2);
p.quadraticCurveTo(-w / 2, h / 2, -w / 2, h / 2 - r);
p.lineTo(-w / 2, -h / 2 + r);
p.quadraticCurveTo(-w / 2, -h / 2, -w / 2 + r, -h / 2);
return p;
}
/* ------------------------------------------------------------------ */
/* the room */
/* ------------------------------------------------------------------ */
const RW = 11, RH = 3.4, RD = 11;
const wallMat = std(0xf1e6d7);
const floorMat = std(0xc69a6c);
const ceilMat = std(0xf8f2e8);
const floor = mesh(scene, new THREE.PlaneGeometry(RW, RD), floorMat, 0, 0, 0, false);
floor.rotation.x = -Math.PI / 2;
const plankMat = std(0xb3885c);
for (let z = -4.5; z <= 4.5; z += 0.9) {
box(scene, RW, 0.006, 0.022, plankMat, 0, 0.004, z, false);
}
function wall(w, pos, ry) {
const m = mesh(scene, new THREE.PlaneGeometry(w, RH), wallMat, pos.x, pos.y, pos.z, false);
m.rotation.y = ry;
return m;
}
wall(RW, new THREE.Vector3(0, RH / 2, -RD / 2), 0); // back
wall(RW, new THREE.Vector3(0, RH / 2, RD / 2), Math.PI); // front
wall(RD, new THREE.Vector3(-RW / 2, RH / 2, 0), Math.PI / 2); // left
wall(RD, new THREE.Vector3( RW / 2, RH / 2, 0), -Math.PI / 2); // right
const ceil = mesh(scene, new THREE.PlaneGeometry(RW, RD), ceilMat, 0, RH, 0, false);
ceil.rotation.x = Math.PI / 2;
/* rug */
const rugMat = std(0x6f9a97, { roughness: 1 });
const rug = mesh(scene, new THREE.CircleGeometry(2.45, 56), rugMat, 0, 0.012, 0.2, false);
rug.rotation.x = -Math.PI / 2; rug.scale.set(1, 0.78, 1);
const rugInner = mesh(scene, new THREE.RingGeometry(1.55, 1.85, 56), std(0x87adaa, { roughness: 1 }), 0, 0.016, 0.2, false);
rugInner.rotation.x = -Math.PI / 2; rugInner.scale.set(1, 0.78, 1);
/* window on the back wall */
const winFrame = std(0xfaf5ec), sky = new THREE.MeshBasicMaterial({ color: 0xdfeaf2 });
const win = mesh(scene, new THREE.PlaneGeometry(1.9, 1.3), sky, 1.5, 2.0, -RD / 2 + 0.02, false);
box(scene, 2.06, 0.11, 0.06, winFrame, 1.5, 2.69, -RD / 2 + 0.05, false);
box(scene, 2.06, 0.11, 0.06, winFrame, 1.5, 1.31, -RD / 2 + 0.05, false);
box(scene, 0.11, 1.49, 0.06, winFrame, 0.59, 2.0, -RD / 2 + 0.05, false);
box(scene, 0.11, 1.49, 0.06, winFrame, 2.41, 2.0, -RD / 2 + 0.05, false);
box(scene, 0.07, 1.3, 0.06, winFrame, 1.5, 2.0, -RD / 2 + 0.05, false);
/* a soft patch of daylight on the floor */
const beam = new THREE.Mesh(new THREE.PlaneGeometry(1.8, 3.4),
new THREE.MeshBasicMaterial({ color: 0xffeec6, transparent: true, opacity: 0.2, depthWrite: false }));
beam.rotation.x = -Math.PI / 2; beam.rotation.z = -0.18;
beam.position.set(2.4, 0.008, -3.1);
scene.add(beam);
/* picture on the left wall */
const frameM = std(0x8a6f52), artM = std(0xe3c9a8);
box(scene, 0.05, 0.9, 1.2, frameM, -RW / 2 + 0.05, 1.85, 0.6, false);
box(scene, 0.02, 0.72, 1.0, artM, -RW / 2 + 0.09, 1.85, 0.6, false);
/* ------------------------------------------------------------------ */
/* lighting */
/* ------------------------------------------------------------------ */
scene.add(new THREE.HemisphereLight(0xfff3e2, 0x9a7454, 0.62));
const sun = new THREE.DirectionalLight(0xfff1d9, 1.15);
sun.position.set(5.5, 8.5, 6.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8; sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8; sun.shadow.camera.bottom = -8;
sun.shadow.camera.far = 26;
sun.shadow.bias = -0.0006;
sun.shadow.normalBias = 0.02;
scene.add(sun);
/* corner floor lamp */
const lampG = new THREE.Group();
lampG.position.set(-4.6, 0, -4.7);
cyl(lampG, 0.16, 0.2, 0.05, 20, std(0x4b4a52), 0, 0.025, 0);
cyl(lampG, 0.035, 0.035, 1.75, 12, std(0x6c6a63), 0, 0.9, 0);
const shade = mesh(lampG, new THREE.ConeGeometry(0.34, 0.36, 22, 1, true), std(0xf2e2c4), 0, 1.82, 0);
shade.material.side = THREE.DoubleSide;
const bulb = new THREE.PointLight(0xffcf92, 9, 9, 2);
bulb.position.set(0, 1.75, 0); lampG.add(bulb);
scene.add(lampG);
/* small plant, front-right */
const plant = new THREE.Group();
plant.position.set(4.3, 0, 3.0);
cyl(plant, 0.24, 0.17, 0.34, 20, std(0xc2704f), 0, 0.17, 0);
cyl(plant, 0.2, 0.2, 0.03, 16, std(0x4b3b2c), 0, 0.33, 0);
const leafMat = std(0x5f8b5c);
for (let i = 0; i < 7; i++) {
const a = (i / 7) * Math.PI * 2;
const leaf = mesh(plant, new THREE.CapsuleGeometry(0.055, 0.42, 4, 10), leafMat,
Math.cos(a) * 0.16, 0.62, Math.sin(a) * 0.16);
leaf.rotation.z = Math.cos(a) * 0.5; leaf.rotation.x = Math.sin(a) * 0.5;
}
scene.add(plant);
/* low sideboard by the left wall */
const sb = new THREE.Group(); sb.position.set(-5.05, 0, 0.9);
box(sb, 0.42, 0.55, 1.5, std(0xb08a5f), 0, 0.42, 0);
box(sb, 0.46, 0.05, 1.56, std(0x8d6c49), 0, 0.72, 0);
box(sb, 0.03, 0.06, 0.3, std(0x6d5336), 0.22, 0.45, -0.4);
box(sb, 0.03, 0.06, 0.3, std(0x6d5336), 0.22, 0.45, 0.4);
for (const z of [-0.75, 0.75]) box(sb, 0.07, 0.16, 0.07, std(0x5c452f), 0, 0.08, z);
cyl(sb, 0.1, 0.14, 0.26, 16, std(0xd8d2c6), 0, 0.87, 0);
scene.add(sb);
/* ------------------------------------------------------------------ */
/* the carrier (door hinged open) */
/* ------------------------------------------------------------------ */
const carrier = new THREE.Group();
carrier.position.set(-3.5, 0, -3.5);
carrier.rotation.y = 0.35;
const carrierMat = std(0x5c6672), carrierTrim = std(0x86b6b6), blanketMat = std(0xf0e4d2);
const CW = 0.64, CH = 0.46, CD = 0.68;
box(carrier, CW, 0.035, CD, carrierMat, 0, 0.018, 0);
box(carrier, CW, 0.035, CD, carrierMat, 0, CH - 0.018, 0);
box(carrier, CW, CH, 0.035, carrierMat, 0, CH / 2, -CD / 2 + 0.018);
box(carrier, 0.035, CH, CD, carrierMat, -CW / 2 + 0.018, CH / 2, 0);
box(carrier, 0.035, CH, CD, carrierMat, CW / 2 - 0.018, CH / 2, 0);
box(carrier, CW - 0.09, 0.02, CD - 0.1, blanketMat, 0, 0.055, 0); // blanket
box(carrier, CW - 0.16, 0.045, 0.3, std(0xd9c7ae), 0, 0.085, -0.1); // folded towel
/* fixed front frame (the opening) */
{
const shape = roundedRect(THREE.Shape, CW, CH, 0.06);
shape.holes.push(roundedRect(THREE.Path, 0.5, 0.32, 0.07));
const geo = new THREE.ExtrudeGeometry(shape, { depth: 0.03, bevelEnabled: true, bevelSize: 0.008, bevelThickness: 0.008, bevelSegments: 2 });
geo.translate(0, 0, -0.015);
const frame = mesh(carrier, geo, carrierMat, 0, CH / 2, CD / 2 - 0.02);
}
/* hinged door, swung open */
const doorPivot = new THREE.Group();
doorPivot.position.set(-CW / 2 + 0.02, CH / 2, CD / 2 - 0.01);
doorPivot.rotation.y = -1.95;
carrier.add(doorPivot);
{
const shape = roundedRect(THREE.Shape, CW - 0.04, CH - 0.04, 0.06);
shape.holes.push(roundedRect(THREE.Path, 0.46, 0.28, 0.07));
const geo = new THREE.ExtrudeGeometry(shape, { depth: 0.025, bevelEnabled: true, bevelSize: 0.006, bevelThickness: 0.006, bevelSegments: 2 });
geo.translate(0, 0, -0.012);
mesh(doorPivot, geo, carrierTrim, (CW - 0.04) / 2, 0, 0);
for (let i = 0; i < 5; i++) {
cyl(doorPivot, 0.009, 0.009, 0.26, 8, carrierTrim, 0.1 + i * 0.1, 0, 0.012);
}
box(doorPivot, 0.03, 0.12, 0.03, carrierTrim, 0.1 + 2 * 0.1, -0.16, 0.03); // latch
}
scene.add(carrier);
/* ------------------------------------------------------------------ */
/* the hiding place — extruded tunnel with an arched opening */
/* ------------------------------------------------------------------ */
const hide = new THREE.Group();
hide.position.set(-1.6, 0, -4.6);
{
const shape = roundedRect(THREE.Shape, 0.92, 0.7, 0.05);
const hole = new THREE.Path();
hole.moveTo(-0.19, -0.35);
hole.lineTo(-0.19, 0.10);
hole.absarc(0, 0.10, 0.19, Math.PI, 0, true);
hole.lineTo(0.19, -0.35);
hole.closePath();
shape.holes.push(hole);
const geo = new THREE.ExtrudeGeometry(shape, { depth: 0.72, bevelEnabled: true, bevelSize: 0.012, bevelThickness: 0.012, bevelSegments: 2 });
mesh(hide, geo, std(0xc79a68), 0, 0.35, 0);
box(hide, 0.5, 0.05, 0.55, std(0xe9dcc6), 0, 0.035, 0.4); // blanket inside
}
scene.add(hide);
/* ------------------------------------------------------------------ */
/* water bowl */
/* ------------------------------------------------------------------ */
const bowlG = new THREE.Group();
bowlG.position.set(0.9, 0, 1.2);
cyl(bowlG, 0.34, 0.34, 0.022, 28, std(0xd8cdb8), 0, 0.012, 0, false); // mat
const bowlOuter = mesh(bowlG, new THREE.CylinderGeometry(0.26, 0.17, 0.13, 30), std(0xf4f1e8), 0, 0.065, 0);
bowlOuter.material.side = THREE.DoubleSide;
const water = mesh(bowlG, new THREE.CircleGeometry(0.195, 30), new THREE.MeshStandardMaterial({ color: 0x8fc7dd, roughness: 0.15, metalness: 0.1 }), 0, 0.105, 0, false);
water.rotation.x = -Math.PI / 2;
scene.add(bowlG);
/* ------------------------------------------------------------------ */
/* couch + seated household members */
/* ------------------------------------------------------------------ */
const couch = new THREE.Group();
couch.position.set(4.4, 0, -1.0);
couch.rotation.y = -Math.PI / 2;
const couchMat = std(0x8ba189), cushionMat = std(0xa3b79e), legMat = std(0x5b4a3c);
box(couch, 2.2, 0.34, 0.9, couchMat, 0, 0.24, 0);
box(couch, 2.2, 0.62, 0.22, couchMat, 0, 0.58, -0.34);
box(couch, 0.2, 0.42, 0.9, couchMat, -1.0, 0.42, 0);
box(couch, 0.2, 0.42, 0.9, couchMat, 1.0, 0.42, 0);
for (const x of [-0.55, 0.55]) {
box(couch, 0.96, 0.12, 0.74, cushionMat, x, 0.47, 0.02);
box(couch, 0.96, 0.34, 0.14, cushionMat, x, 0.66, -0.26);
}
for (const x of [-0.95, 0.95]) for (const z of [-0.32, 0.32]) cyl(couch, 0.035, 0.028, 0.14, 10, legMat, x, 0.07, z);
scene.add(couch);
/* cushion on the floor for the second person */
cyl(scene, 0.5, 0.52, 0.11, 26, std(0xc08d84), 3.6, 0.055, 1.05);
/* --- person builder --- */
function makePerson({ seatY, coat, pants, hair, skin, crossed = false, mug = false }) {
const g = new THREE.Group();
const coatM = std(coat), pantsM = std(pants), hairM = std(hair), skinM = std(skin);
box(g, 0.34, 0.22, 0.30, pantsM, 0, seatY + 0.02, 0);
const torso = cap(g, 0.165, 0.30, coatM, 0, seatY + 0.36, 0.01);
torso.rotation.x = -0.05;
/* head on a pivot so they can glance at the animal */
const headPivot = new THREE.Group();
headPivot.position.set(0, seatY + 0.62, 0.015);
g.add(headPivot);
cyl(headPivot, 0.055, 0.065, 0.09, 12, skinM, 0, 0.02, 0);
const head = sph(headPivot, 0.155, skinM, 0, 0.14, 0);
head.scale.set(0.95, 1.08, 0.95);
const hairMesh = mesh(headPivot, new THREE.SphereGeometry(0.163, 20, 14, 0, Math.PI * 2, 0, Math.PI * 0.62), hairM, 0, 0.14, -0.01);
hairMesh.scale.set(0.98, 1.08, 1.0);
hairMesh.rotation.x = -0.14;
for (const s of [-1, 1]) {
sph(headPivot, 0.021, std(0x33261f), s * 0.052, 0.145, 0.135, 12, 10);
}
/* arms resting in the lap — never reaching */
for (const s of [-1, 1]) {
const shoulder = new THREE.Group();
shoulder.position.set(s * 0.20, seatY + 0.50, 0.02);
g.add(shoulder);
const upper = cap(shoulder, 0.055, 0.20, coatM, 0, -0.13, 0);
upper.rotation.x = 0.18; upper.rotation.z = s * 0.12;
const elbow = new THREE.Group();
elbow.position.set(0, -0.25, 0.02);
elbow.rotation.x = 1.15;
shoulder.add(elbow);
const fore = cap(elbow, 0.05, 0.18, coatM, 0, -0.10, 0);
sph(elbow, 0.052, skinM, 0, -0.21, 0);
if (mug && s === 1) {
cyl(elbow, 0.055, 0.05, 0.09, 14, std(0xf0ece2), 0, -0.2, 0.02);
cyl(elbow, 0.045, 0.045, 0.012, 14, std(0x8a5f3c), 0, -0.155, 0.02);
}
}
/* legs */
for (const s of [-1, 1]) {
const thigh = cap(g, 0.075, 0.22, pantsM, s * 0.10, seatY + 0.02, 0.14);
thigh.rotation.x = Math.PI / 2 + (crossed ? s * 0.35 : 0);
if (crossed) {
const shin = cap(g, 0.065, 0.20, pantsM, -s * 0.02, seatY - 0.015, 0.27);
shin.rotation.z = Math.PI / 2;
} else {
const shin = cap(g, 0.062, 0.22, pantsM, s * 0.10, seatY - 0.20, 0.26);
box(g, 0.11, 0.06, 0.20, std(0x3d3b42), s * 0.10, seatY - 0.34, 0.30);
}
}
return { group: g, headPivot, torso };
}
const personA = makePerson({
seatY: 0.47, coat: 0x7f9fb5, pants: 0x59617a, hair: 0x4b3729, skin: 0xd9a982
});
personA.group.position.set(4.52, 0, -0.55);
personA.group.rotation.y = -0.69;
scene.add(personA.group);
const personB = makePerson({
seatY: 0.13, coat: 0xc98d84, pants: 0x6b6152, hair: 0x2f2622, skin: 0xe0b28d, crossed: true, mug: true
});
personB.group.position.set(3.6, 0, 1.05);
personB.group.rotation.y = -1.83;
scene.add(personB.group);
/* ------------------------------------------------------------------ */
/* the animal */
/* ------------------------------------------------------------------ */
const fur = std(0xe3a264), furLight = std(0xf7e6ce), furDark = std(0x9c6538);
const cat = new THREE.Group();
const catBody = new THREE.Group();
cat.add(catBody);
const torso = cap(catBody, 0.115, 0.30, fur, 0, 0.22, 0);
torso.rotation.x = Math.PI / 2;
/* head */
const catHead = new THREE.Group();
catHead.position.set(0, 0.30, 0.235);
catBody.add(catHead);
const skull = sph(catHead, 0.125, fur, 0, 0, 0);
skull.scale.set(1, 0.95, 0.96);
const muzzle = sph(catHead, 0.072, furLight, 0, -0.05, 0.088);
muzzle.scale.set(1, 0.78, 0.95);
sph(catHead, 0.017, std(0xd98a86), 0, -0.022, 0.145, 10, 8);
const ears = [];
for (const s of [-1, 1]) {
const ear = new THREE.Group();
ear.position.set(s * 0.072, 0.10, -0.015);
ear.rotation.z = s * 0.28;
catHead.add(ear);
const outer = mesh(ear, new THREE.ConeGeometry(0.052, 0.115, 4), fur, 0, 0.045, 0);
const inner = mesh(ear, new THREE.ConeGeometry(0.032, 0.075, 4), furLight, 0, 0.04, 0.022);
inner.rotation.y = Math.PI / 4;
ears.push(ear);
}
const eyes = [];
for (const s of [-1, 1]) {
const eye = sph(catHead, 0.023, std(0x2b2118), s * 0.055, 0.022, 0.108, 12, 10);
sph(catHead, 0.008, std(0xffffff), s * 0.062, 0.032, 0.124, 8, 6);
eyes.push(eye);
}
/* whiskers */
for (const s of [-1, 1]) {
for (let i = 0; i < 2; i++) {
const w = cyl(catHead, 0.0035, 0.0035, 0.12, 6, std(0xf1e6d6), s * 0.055, -0.045 + i * 0.022, 0.105);
w.rotation.z = s * (1.15 + i * 0.18);
w.rotation.x = 0.35;
}
}
/* legs */
const legs = [];
const legDefs = [
{ x: -0.072, z: 0.155, phase: 0 },
{ x: 0.072, z: 0.155, phase: Math.PI },
{ x: -0.082, z: -0.155, phase: Math.PI },
{ x: 0.082, z: -0.155, phase: 0 },
];
for (const d of legDefs) {
const pivot = new THREE.Group();
pivot.position.set(d.x, 0.145, d.z);
catBody.add(pivot);
const upper = cap(pivot, 0.028, 0.06, fur, 0, -0.055, 0);
const lower = cap(pivot, 0.024, 0.05, fur, 0, -0.115, 0.012);
sph(pivot, 0.032, furLight, 0, -0.145, 0.02);
pivot.userData.phase = d.phase;
legs.push(pivot);
}
/* tail */
const tailRoot = new THREE.Group();
tailRoot.position.set(0, 0.255, -0.24);
catBody.add(tailRoot);
const tailSegs = [];
{
let parent = tailRoot;
for (let i = 0; i < 6; i++) {
const seg = new THREE.Group();
seg.position.z = i === 0 ? 0 : -0.058;
parent.add(seg);
const m = cap(seg, 0.028 - i * 0.003, 0.035, i === 5 ? furDark : fur, 0, 0, -0.028);
m.rotation.x = Math.PI / 2;
tailSegs.push(seg);
parent = seg;
}
}
scene.add(cat);
/* ------------------------------------------------------------------ */
/* the animal's voluntary route */
/* ------------------------------------------------------------------ */
const start = { x: -3.46, z: -3.39 };
const steps = [
{ type: 'rest', dur: 2.6, from: start, to: start, yaw: 0.35, label: 'Settling in the carrier', stage: 0, sit: 1, hp: -0.05, eyes: 1 },
{ type: 'walk', dur: 2.8, from: start, to: { x: -3.15, z: -2.6 }, yaw: 0.42, label: 'Stepping out of the carrier, on its own', stage: 1 },
{ type: 'sniff', dur: 2.6, from: { x: -3.15, z: -2.6 },to: { x: -3.15, z: -2.6 }, yaw: 0.60, label: 'Sniffing around the new room', stage: 1 },
{ type: 'walk', dur: 3.2, from: { x: -3.15, z: -2.6 },to: { x: -1.6, z: -3.15 }, yaw: 1.78, label: 'Walking over to the hiding place', stage: 2 },
{ type: 'walk', dur: 2.4, from: { x: -1.6, z: -3.15 }, to: { x: -1.6, z: -4.35 }, yaw: Math.PI, label: 'Stepping inside the hide', stage: 2 },
{ type: 'rest', dur: 3.8, from: { x: -1.6, z: -4.35 }, to: { x: -1.6, z: -4.35 }, yaw: Math.PI, label: 'Resting inside the hiding place', stage: 2, sit: 1, hp: 0.30, eyes: 0 },
{ type: 'walk', dur: 2.2, from: { x: -1.6, z: -4.35 }, to: { x: -1.6, z: -3.3 }, yaw: 0, label: 'Coming back out again', stage: 2 },
{ type: 'walk', dur: 3.6, from: { x: -1.6, z: -3.3 }, to: { x: 0.75, z: 0.72 }, yaw: 0.52, label: 'Approaching the water bowl', stage: 3 },
{ type: 'drink', dur: 3.4, from: { x: 0.75, z: 0.72 }, to: { x: 0.75, z: 0.72 }, yaw: 0.30, label: 'Drinking some water', stage: 3, hp: -0.95 },
{ type: 'walk', dur: 2.8, from: { x: 0.75, z: 0.72 }, to: { x: 2.15, z: 0.92 }, yaw: 1.46, label: 'Turning toward the household', stage: 4 },
{ type: 'greet', dur: 4.2, from: { x: 2.15, z: 0.92 }, to: { x: 2.15, z: 0.92 }, yaw: 1.35, label: 'Greeting the household', stage: 4, sit: 1, hp: 0.42, eyes: 1 },
{ type: 'walk', dur: 2.0, from: { x: 2.15, z: 0.92 }, to: { x: 2.85, z: 0.88 }, yaw: 1.25, label: 'Coming a little closer', stage: 4 },
{ type: 'rest', dur: Infinity, from: { x: 2.85, z: 0.88 }, to: { x: 2.85, z: 0.88 }, yaw: 1.25, label: 'Resting nearby, at their own pace', stage: 4, sit: 1, hp: 0.16, eyes: 1 },
];
let stepIndex = 0, stepTime = 0;
let catX = start.x, catZ = start.z, catYaw = 0.35;
let pose = { sit: 1, hp: -0.05, tail: 0.4, eyes: 1, bodyPitch: -0.45 };
let walkPhase = 0, walking = false;
let blinkTimer = 2.0, blinking = 0, nextEar = 3.5, earTwitch = -1;
const statusText = document.getElementById('statusText');
const stageEls = [...document.querySelectorAll('#stages li')];
let lastStage = -1;
function setStatus(i) {
const s = steps[i];
statusText.textContent = s.label;
if (s.stage !== lastStage) {
lastStage = s.stage;
stageEls.forEach((el, k) => el.classList.toggle('on', k === s.stage));
}
}
setStatus(0);
const lerp = (a, b, t) => a + (b - a) * t;
const clamp = THREE.MathUtils.clamp;
function angleLerp(a, b, t) {
let d = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (d < -Math.PI) d += Math.PI * 2;
return a + d * t;
}
/* ------------------------------------------------------------------ */
/* animation */
/* ------------------------------------------------------------------ */
function updateCat(dt, t) {
const s = steps[stepIndex];
stepTime += dt;
let u = s.dur ? Math.min(stepTime / s.dur, 1) : 0;
const e = u * u * (3 - 2 * u);
/* targets */
let targetSit = s.sit ?? 0;
let targetHp = s.hp ?? 0;
let targetTail = s.sit ? 0.75 : 0.25;
let targetEyes = s.eyes ?? 1;
let targetYaw = s.yaw ?? catYaw;
let targetX = s.to.x, targetZ = s.to.z;
walking = false;
if (s.type === 'walk') {
walking = true;
catX = lerp(s.from.x, s.to.x, e);
catZ = lerp(s.from.z, s.to.z, e);
walkPhase += dt * 9.5;
targetYaw = s.yaw ?? Math.atan2(s.to.x - s.from.x, s.to.z - s.from.z);
} else {
catX = s.to.x; catZ = s.to.z;
if (s.type === 'sniff') targetHp = -0.55 + Math.sin(t * 3.1) * 0.10;
if (s.type === 'drink') targetHp = -0.95 + Math.sin(t * 6.5) * 0.07;
if (s.type === 'greet') targetHp = 0.42 + Math.sin(t * 1.6) * 0.05;
if (s.type === 'rest') targetHp = (s.hp ?? 0) + Math.sin(t * 1.2) * 0.02;
}
const k = 1 - Math.exp(-4.5 * dt);
pose.sit = lerp(pose.sit, targetSit, k);
pose.hp = lerp(pose.hp, targetHp, 1 - Math.exp(-6 * dt));
pose.tail = lerp(pose.tail, targetTail, k);
pose.eyes = lerp(pose.eyes, targetEyes, 1 - Math.exp(-7 * dt));
catYaw = angleLerp(catYaw, targetYaw, 1 - Math.exp(-4 * dt));
/* head yaw (sniffing side to side) */
let headYaw = 0;
if (s.type === 'sniff') headYaw = Math.sin(t * 1.45) * 0.34;
if (s.type === 'greet') headYaw = Math.sin(t * 0.9) * 0.12;
cat.position.set(catX, walking ? Math.abs(Math.sin(walkPhase)) * 0.016 - 0.008 : -0.05 * pose.sit, catZ);
cat.rotation.y = catYaw;
catBody.rotation.x = -0.48 * pose.sit + (walking ? Math.sin(walkPhase * 2) * 0.035 : 0);
catBody.scale.y = 1 + Math.sin(t * 2.0) * 0.012;
catHead.rotation.x = pose.hp;
catHead.rotation.y = lerp(catHead.rotation.y, headYaw, 1 - Math.exp(-6 * dt));
/* blinking */
blinkTimer -= dt;
if (blinkTimer <= 0 && pose.eyes > 0.5) { blinking = 0.14; blinkTimer = 2.6 + Math.random() * 3.4; }
if (blinking > 0) blinking -= dt;
const eyeScale = (blinking > 0 ? 0.08 : 1) * pose.eyes;
for (const e2 of eyes) e2.scale.y = eyeScale;
/* ear twitch */
nextEar -= dt;
if (nextEar <= 0) { earTwitch = 0.3; nextEar = 3 + Math.random() * 4; }
if (earTwitch > 0) earTwitch -= dt;
const tw = earTwitch > 0 ? Math.sin(earTwitch * 40) * 0.22 : 0;
ears[0].rotation.x = tw; ears[1].rotation.x = -tw * 0.7;
/* legs */
for (let i = 0; i < legs.length; i++) {
const leg = legs[i];
const ph = walkPhase + leg.userData.phase;
let swing = walking ? Math.sin(ph) * 0.5 : 0;
if (pose.sit > 0.5 && i >= 2) swing = -1.05 * pose.sit; // hind legs tucked
if (pose.sit > 0.5 && i < 2) swing = 0;
leg.rotation.x = lerp(leg.rotation.x, swing, 1 - Math.exp(-12 * dt));
}
/* tail */
tailRoot.rotation.y = pose.tail + Math.sin(t * 1.4) * 0.12;
tailRoot.rotation.x = -0.12 * pose.sit;
for (let i = 0; i < tailSegs.length; i++) {
const seg = tailSegs[i];
seg.rotation.y = Math.sin(t * 1.9 - i * 0.55) * 0.11;
seg.rotation.x = 0.14 + i * 0.045 + (pose.sit > 0.5 ? 0.06 : 0);
}
if (stepTime >= s.dur && stepIndex < steps.length - 1) {
stepIndex++; stepTime = 0; setStatus(stepIndex);
}
}
/* people: quiet, attentive, hands staying put */
const people = [
{ p: personA, x: 4.52, z: -0.55, yaw: -0.69 },
{ p: personB, x: 3.6, z: 1.05, yaw: -1.83 },
];
function updatePeople(dt, t) {
for (const { p, x, z, yaw } of people) {
const worldAngle = Math.atan2(catX - x, catZ - z);
let local = worldAngle - yaw;
local = ((local + Math.PI) % (Math.PI * 2)) - Math.PI;
p.headPivot.rotation.y = lerp(p.headPivot.rotation.y, clamp(local, -0.75, 0.75), 1 - Math.exp(-2.2 * dt));
p.headPivot.rotation.x = Math.sin(t * 0.7 + x) * 0.03;
p.torso.scale.y = 1 + Math.sin(t * 1.5 + z) * 0.012;
}
}
/* ------------------------------------------------------------------ */
/* custom camera controls (no addons) */
/* ------------------------------------------------------------------ */
const cam = { az: 0.60, pol: 1.03, dist: 12.6, target: new THREE.Vector3(0, 0.75, 0) };
const camT = { az: 0.60, pol: 1.03, dist: 12.6 };
let dragging = false, panning = false, lastX = 0, lastY = 0;
renderer.domElement.addEventListener('pointerdown', (e) => {
dragging = true; panning = e.button === 2 || e.shiftKey;
lastX = e.clientX; lastY = e.clientY;
renderer.domElement.setPointerCapture(e.pointerId);
});
window.addEventListener('pointermove', (e) => {
if (!dragging) return;
const dx = e.clientX - lastX, dy = e.clientY - lastY;
lastX = e.clientX; lastY = e.clientY;
if (panning) {
const right = new THREE.Vector3(Math.cos(cam.az), 0, -Math.sin(cam.az));
cam.target.addScaledVector(right, -dx * 0.012 * cam.dist * 0.1);
cam.target.y = clamp(cam.target.y + dy * 0.01 * cam.dist * 0.1, 0.2, 2.4);
} else {
camT.az = clamp(camT.az - dx * 0.005, -0.85, 1.5);
camT.pol = clamp(camT.pol - dy * 0.004, 0.28, 1.42);
}
});
window.addEventListener('pointerup', () => { dragging = false; });
renderer.domElement.addEventListener('contextmenu', (e) => e.preventDefault());
renderer.domElement.addEventListener('wheel', (e) => {
e.preventDefault();
camT.dist = clamp(camT.dist * (1 + Math.sign(e.deltaY) * 0.08), 5.5, 19);
}, { passive: false });
renderer.domElement.addEventListener('dblclick', () => {
camT.az = 0.60; camT.pol = 1.03; camT.dist = 12.6; cam.target.set(0, 0.75, 0);
});
function updateCamera(dt) {
const k = 1 - Math.exp(-7 * dt);
cam.az = lerp(cam.az, camT.az, k);
cam.pol = lerp(cam.pol, camT.pol, k);
cam.dist = lerp(cam.dist, camT.dist, k);
const sp = Math.sin(cam.pol), cp = Math.cos(cam.pol);
camera.position.set(
cam.target.x + cam.dist * sp * Math.sin(cam.az),
cam.target.y + cam.dist * cp,
cam.target.z + cam.dist * sp * Math.cos(cam.az)
);
camera.lookAt(cam.target);
}
/* ------------------------------------------------------------------ */
/* projected labels */
/* ------------------------------------------------------------------ */
const labelDefs = [
{ name: 'Carrier', pos: new THREE.Vector3(-3.5, 0.70, -3.5) },
{ name: 'Hiding place', pos: new THREE.Vector3(-1.6, 0.78, -4.35) },
{ name: 'Water bowl', pos: new THREE.Vector3(0.9, 0.30, 1.2) },
{ name: 'Household', pos: new THREE.Vector3(4.3, 1.30, -0.5) },
];
const labelHost = document.getElementById('labels');
labelDefs.forEach((d) => {
d.el = document.createElement('div');
d.el.textContent = d.name;
labelHost.appendChild(d.el);
});
let labelsOn = true;
document.getElementById('toggleLabels').addEventListener('click', (e) => {
labelsOn = !labelsOn;
e.target.textContent = 'Labels: ' + (labelsOn ? 'on' : 'off');
e.target.classList.toggle('off', !labelsOn);
});
const proj = new THREE.Vector3();
function updateLabels() {
for (const d of labelDefs) {
if (!labelsOn) { d.el.style.opacity = 0; continue; }
proj.copy(d.pos).project(camera);
const vis = proj.z < 1 && Math.abs(proj.x) < 1.15 && Math.abs(proj.y) < 1.15;
d.el.style.opacity = vis ? 1 : 0;
if (vis) {
d.el.style.left = ((proj.x * 0.5 + 0.5) * innerWidth) + 'px';
d.el.style.top = ((-proj.y * 0.5 + 0.5) * innerHeight) + 'px';
}
}
}
/* ------------------------------------------------------------------ */
/* resize + loop */
/* ------------------------------------------------------------------ */
window.addEventListener('resize', () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const t = clock.elapsedTime;
updateCat(dt, t);
updatePeople(dt, t);
updateCamera(dt);
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```