Prompt specification
Build or customize the Three.js 3D scene "Eyes Lead a Head Turn" 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: Eyes Lead a Head Turn
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/eyes-lead-a-head-turn-x3726
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring gaze direction, head movement, and visual attention. Animate a character noticing an object with eye movement followed by head rotation. Keep the target fixed and label attention as an authored animation cue. Voxel style.
Working Three.js Starter (eyes-lead-a-head-turn-x3726):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Attention — Authored Animation Cue</title>
<style>
:root {
--bg: #09101e;
--panel: rgba(13, 23, 41, 0.82);
--panel-border: rgba(147, 197, 255, 0.18);
--text: #eef6ff;
--muted: #93a9c5;
--cyan: #58e6ff;
--gold: #ffc85a;
--green: #80f0ba;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: absolute;
inset: 0;
overflow: hidden;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.vignette {
position: absolute;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 35%, rgba(3, 7, 15, 0.34) 100%),
linear-gradient(180deg, rgba(5, 10, 20, 0.2), transparent 25%, transparent 75%, rgba(5, 10, 20, 0.35));
}
.topbar {
position: absolute;
top: 24px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
pointer-events: none;
gap: 18px;
}
.brand {
max-width: 470px;
}
.eyebrow,
.micro-label,
.order-step,
.badge,
.metric-label,
.phase-status {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
}
.brand h1 {
margin: 0;
font-size: clamp(22px, 3vw, 38px);
line-height: 1;
letter-spacing: -0.04em;
font-weight: 760;
}
.brand p {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.badge {
display: inline-flex;
align-items: center;
gap: 9px;
padding: 10px 12px;
border: 1px solid rgba(88, 230, 255, 0.34);
border-radius: 999px;
background: rgba(11, 25, 43, 0.72);
color: #baf5ff;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
box-shadow: 0 0 28px rgba(88, 230, 255, 0.08);
}
.badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.panel {
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.story-card {
position: absolute;
left: 24px;
bottom: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px;
border-radius: 16px;
pointer-events: none;
}
.story-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 13px;
}
.micro-label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
}
.phase-status {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--green);
font-size: 9px;
font-weight: 800;
}
.phase-status::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
}
.phase-title {
margin: 0 0 5px;
font-size: 19px;
letter-spacing: -0.02em;
}
.phase-description {
min-height: 38px;
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.timeline {
display: grid;
grid-template-columns: 1fr 0.8fr 1fr 1fr;
gap: 7px;
margin-top: 16px;
}
.timeline-cell {
min-width: 0;
}
.timeline-track {
height: 4px;
margin-bottom: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.timeline-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--cyan);
box-shadow: 0 0 10px rgba(88, 230, 255, 0.5);
}
.timeline-label {
display: block;
overflow: hidden;
color: #7890ae;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
letter-spacing: 0.08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.timeline-cell.active .timeline-label {
color: #d8f9ff;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.metric-label {
color: #6f87a5;
font-size: 8px;
font-weight: 700;
}
.metric-value {
margin-top: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 14px;
color: #dff8ff;
}
.control-card {
position: absolute;
right: 24px;
bottom: 24px;
width: 270px;
padding: 15px;
border-radius: 15px;
pointer-events: none;
}
.control-card h2 {
margin: 0 0 10px;
font-size: 12px;
letter-spacing: 0.01em;
}
.order-list {
display: grid;
gap: 7px;
margin-bottom: 13px;
}
.order-step {
display: flex;
align-items: center;
gap: 9px;
padding: 8px 9px;
border: 1px solid transparent;
border-radius: 9px;
color: #6f87a5;
font-size: 8px;
font-weight: 750;
transition: 180ms ease;
}
.order-step b {
display: grid;
width: 19px;
height: 19px;
place-items: center;
border-radius: 5px;
background: rgba(255, 255, 255, 0.05);
color: #8ba3bf;
font-size: 8px;
}
.order-step.active {
border-color: rgba(88, 230, 255, 0.2);
background: rgba(88, 230, 255, 0.07);
color: #d7faff;
}
.order-step.active b {
background: var(--cyan);
color: #071321;
}
.control-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.camera-hint {
color: #7188a5;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
line-height: 1.55;
}
#replay {
min-width: 78px;
padding: 9px 11px;
border: 1px solid rgba(88, 230, 255, 0.28);
border-radius: 9px;
background: rgba(88, 230, 255, 0.1);
color: #d8faff;
cursor: pointer;
pointer-events: auto;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: background 160ms ease, transform 160ms ease;
}
#replay:hover {
background: rgba(88, 230, 255, 0.18);
transform: translateY(-1px);
}
#target-label {
position: absolute;
z-index: 5;
min-width: 142px;
padding: 9px 11px 10px;
border: 1px solid rgba(255, 200, 90, 0.4);
border-radius: 9px;
background: rgba(19, 22, 31, 0.9);
color: var(--gold);
pointer-events: none;
transform: translate(-50%, -100%);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}
#target-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 25px;
background: linear-gradient(var(--gold), transparent);
}
#target-label span {
display: block;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#target-label strong {
display: block;
margin-top: 4px;
color: #fff2cb;
font-size: 11px;
letter-spacing: 0.02em;
}
.corner-note {
position: absolute;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
color: rgba(167, 188, 213, 0.55);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
letter-spacing: 0.08em;
pointer-events: none;
text-transform: uppercase;
white-space: nowrap;
}
@media (max-width: 760px) {
.topbar {
top: 14px;
left: 14px;
right: 14px;
}
.brand p {
display: none;
}
.badge {
padding: 8px 9px;
font-size: 7px;
}
.story-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.phase-description {
display: none;
}
.control-card {
top: 78px;
right: 12px;
bottom: auto;
width: 205px;
padding: 11px;
}
.order-list,
.camera-hint {
display: none;
}
.control-card h2 {
margin-bottom: 8px;
}
.control-actions {
padding-top: 8px;
}
#replay {
width: 100%;
}
.corner-note {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel attention animation"></main>
<div class="vignette"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Voxel Behavior Study / Cue 01</div>
<h1>Noticing a target</h1>
<p>Eye acquisition precedes head rotation in this directed attention sequence.</p>
</div>
<div class="badge">Authored animation cue</div>
</header>
<section class="panel story-card" aria-live="polite">
<div class="story-top">
<span class="micro-label">Directed attention / Timeline</span>
<span id="phase-status" class="phase-status">Rest / Idle</span>
</div>
<h2 id="phase-title" class="phase-title">Waiting for the cue</h2>
<p id="phase-description" class="phase-description">
The character is idle. The target remains fixed at world position.
</p>
<div class="timeline" aria-hidden="true">
<div class="timeline-cell active">
<div class="timeline-track"><div id="fill-rest" class="timeline-fill"></div></div>
<span class="timeline-label">Rest</span>
</div>
<div class="timeline-cell">
<div class="timeline-track"><div id="fill-gaze" class="timeline-fill"></div></div>
<span class="timeline-label">Eyes</span>
</div>
<div class="timeline-cell">
<div class="timeline-track"><div id="fill-head" class="timeline-fill"></div></div>
<span class="timeline-label">Head</span>
</div>
<div class="timeline-cell">
<div class="timeline-track"><div id="fill-hold" class="timeline-fill"></div></div>
<span class="timeline-label">Hold</span>
</div>
</div>
<div class="metrics">
<div>
<div class="metric-label">Eye acquisition</div>
<div id="eye-metric" class="metric-value">0%</div>
</div>
<div>
<div class="metric-label">Head rotation</div>
<div id="head-metric" class="metric-value">0%</div>
</div>
</div>
</section>
<aside class="panel control-card">
<h2>Animation order</h2>
<div class="order-list">
<div id="step-0" class="order-step active"><b>01</b> Eyes acquire fixed target</div>
<div id="step-1" class="order-step"><b>02</b> Head rotates toward target</div>
<div id="step-2" class="order-step"><b>03</b> Attention is held</div>
</div>
<div class="control-actions">
<div class="camera-hint">Drag to orbit<br />Scroll to zoom</div>
<button id="replay" type="button">Replay cue</button>
</div>
</aside>
<div id="target-label">
<span>Attention target</span>
<strong>Fixed / Authored cue</strong>
</div>
<div class="corner-note">Keyframed narrative attention — not live gaze tracking</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const targetLabel = document.querySelector("#target-label");
const replayButton = document.querySelector("#replay");
const phaseStatus = document.querySelector("#phase-status");
const phaseTitle = document.querySelector("#phase-title");
const phaseDescription = document.querySelector("#phase-description");
const eyeMetric = document.querySelector("#eye-metric");
const headMetric = document.querySelector("#head-metric");
const fillRest = document.querySelector("#fill-rest");
const fillGaze = document.querySelector("#fill-gaze");
const fillHead = document.querySelector("#fill-head");
const fillHold = document.querySelector("#fill-hold");
const stepEls = [
document.querySelector("#step-0"),
document.querySelector("#step-1"),
document.querySelector("#step-2")
];
const timelineCells = [...document.querySelectorAll(".timeline-cell")];
// ------------------------------------------------------------
// Renderer, scene, and orthographic camera
// ------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09101e);
scene.fog = new THREE.Fog(0x09101e, 13, 24);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(stage.clientWidth, stage.clientHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-5, 5, 4, -4, 0.1, 60);
const cameraTarget = new THREE.Vector3(0, 1.15, 0.25);
const cameraState = {
theta: 0.67,
phi: 1.25,
radius: 12,
zoom: 1
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
const horizontal = Math.sin(phi) * radius;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(theta),
cameraTarget.y + Math.cos(phi) * radius,
cameraTarget.z + horizontal * Math.cos(theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const viewHeight = Math.max(6.6, 7.8 / aspect) / cameraState.zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------
// Direct camera controls: pointer orbit and wheel zoom
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - deltaY * 0.005,
0.62,
1.43
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(event.deltaY * 0.001),
0.72,
1.55
);
resize();
},
{ passive: false }
);
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9d8ff, 0x101421, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff0d7, 3.2);
keyLight.position.set(-4, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4adfff, 1.65);
rimLight.position.set(5, 4, -5);
scene.add(rimLight);
const targetLight = new THREE.PointLight(0xffb84d, 13, 6, 2);
targetLight.position.set(2.3, 1.35, 1.9);
scene.add(targetLight);
// ------------------------------------------------------------
// Voxel helpers and materials
// ------------------------------------------------------------
function box(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
const materials = {
tileA: new THREE.MeshStandardMaterial({
color: 0x17253a,
roughness: 0.9,
metalness: 0.08
}),
tileB: new THREE.MeshStandardMaterial({
color: 0x1b2c43,
roughness: 0.86,
metalness: 0.08
}),
tileEdge: new THREE.MeshStandardMaterial({
color: 0x0b1424,
roughness: 0.95
}),
skin: new THREE.MeshStandardMaterial({
color: 0xe3aa7f,
roughness: 0.78
}),
skinLight: new THREE.MeshStandardMaterial({
color: 0xf1bd93,
roughness: 0.78
}),
hair: new THREE.MeshStandardMaterial({
color: 0x282238,
roughness: 0.88
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x497cf4,
roughness: 0.68
}),
shirtDark: new THREE.MeshStandardMaterial({
color: 0x3158b8,
roughness: 0.72
}),
pants: new THREE.MeshStandardMaterial({
color: 0x27344e,
roughness: 0.84
}),
shoes: new THREE.MeshStandardMaterial({
color: 0x111927,
roughness: 0.72
}),
eyeWhite: new THREE.MeshStandardMaterial({
color: 0xf4fbff,
roughness: 0.42,
emissive: 0xbdefff,
emissiveIntensity: 0.12
}),
pupil: new THREE.MeshStandardMaterial({
color: 0x07111e,
roughness: 0.28,
metalness: 0.1
}),
glint: new THREE.MeshBasicMaterial({ color: 0xffffff }),
mouth: new THREE.MeshStandardMaterial({
color: 0x623d45,
roughness: 0.85
}),
pedestal: new THREE.MeshStandardMaterial({
color: 0x253650,
roughness: 0.68,
metalness: 0.18
}),
pedestalDark: new THREE.MeshStandardMaterial({
color: 0x142138,
roughness: 0.72,
metalness: 0.22
}),
target: new THREE.MeshStandardMaterial({
color: 0xffb83e,
emissive: 0xff8d1f,
emissiveIntensity: 0.72,
roughness: 0.3,
metalness: 0.22
}),
targetCap: new THREE.MeshStandardMaterial({
color: 0xffd46e,
emissive: 0xffa62b,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.16
}),
cyan: new THREE.MeshBasicMaterial({
color: 0x55e7ff,
transparent: true,
opacity: 0.76
})
};
// ------------------------------------------------------------
// Voxel platform
// ------------------------------------------------------------
box(
scene,
[10.4, 0.25, 10.4],
[0, -0.23, 0],
materials.tileEdge,
false
);
for (let x = -5; x <= 5; x++) {
for (let z = -5; z <= 5; z++) {
const material = (x + z) % 2 === 0 ? materials.tileA : materials.tileB;
box(
scene,
[0.86, 0.12, 0.86],
[x * 0.9, -0.055, z * 0.9],
material,
false
);
}
}
// Small decorative voxel blocks provide scale and depth.
const decorMaterial = new THREE.MeshStandardMaterial({
color: 0x21344d,
roughness: 0.88
});
const decor = [
[-3.65, 0.16, -2.8, 0.32],
[-3.3, 0.26, -2.8, 0.22],
[3.7, 0.2, -2.25, 0.4],
[3.95, 0.12, -1.9, 0.25],
[-3.8, 0.11, 2.65, 0.22],
[3.55, 0.12, 3.25, 0.24]
];
decor.forEach(([x, y, z, s]) => {
box(scene, [s, s, s], [x, y, z], decorMaterial);
});
// ------------------------------------------------------------
// Character
// Local forward direction for the character is +Z.
// ------------------------------------------------------------
const characterRoot = new THREE.Group();
characterRoot.position.set(-1.6, 0, 0);
scene.add(characterRoot);
// Legs and shoes.
box(characterRoot, [0.36, 0.72, 0.44], [-0.26, 0.48, 0], materials.pants);
box(characterRoot, [0.36, 0.72, 0.44], [0.26, 0.48, 0], materials.pants);
box(characterRoot, [0.43, 0.22, 0.58], [-0.26, 0.12, 0.08], materials.shoes);
box(characterRoot, [0.43, 0.22, 0.58], [0.26, 0.12, 0.08], materials.shoes);
// Hips, torso, and badge.
box(characterRoot, [0.96, 0.3, 0.66], [0, 0.94, 0], materials.pants);
box(characterRoot, [1.06, 0.9, 0.68], [0, 1.49, 0], materials.shirt);
box(characterRoot, [0.82, 0.17, 0.04], [0, 1.26, 0.36], materials.shirtDark);
box(characterRoot, [0.18, 0.18, 0.045], [0.27, 1.65, 0.365], materials.cyan);
// Arms and hands.
box(characterRoot, [0.28, 0.7, 0.38], [-0.67, 1.47, 0], materials.shirt);
box(characterRoot, [0.28, 0.7, 0.38], [0.67, 1.47, 0], materials.shirt);
box(characterRoot, [0.3, 0.32, 0.38], [-0.67, 0.98, 0], materials.skin);
box(characterRoot, [0.3, 0.32, 0.38], [0.67, 0.98, 0], materials.skin);
// Neck and independently rotating head.
box(characterRoot, [0.4, 0.25, 0.4], [0, 2.03, 0], materials.skin);
const headGroup = new THREE.Group();
headGroup.position.set(0, 2.08, 0);
headGroup.rotation.order = "YXZ";
characterRoot.add(headGroup);
box(headGroup, [1.2, 1.08, 1.0], [0, 0.57, 0], materials.skin);
// Hair and ears.
box(headGroup, [1.26, 0.25, 1.05], [0, 1.06, -0.01], materials.hair);
box(headGroup, [0.26, 0.25, 0.25], [-0.42, 1.1, 0.02], materials.hair);
box(headGroup, [0.26, 0.25, 0.25], [0.4, 1.1, 0.02], materials.hair);
box(headGroup, [0.16, 0.29, 0.29], [-0.65, 0.56, 0], materials.skinLight);
box(headGroup, [0.16, 0.29, 0.29], [0.65, 0.56, 0], materials.skinLight);
// Eye whites.
const leftEye = box(
headGroup,
[0.34, 0.3, 0.075],
[-0.26, 0.63, 0.525],
materials.eyeWhite,
false
);
const rightEye = box(
headGroup,
[0.34, 0.3, 0.075],
[0.26, 0.63, 0.525],
materials.eyeWhite,
false
);
// Movable pupils.
const leftPupil = new THREE.Group();
leftPupil.position.set(-0.26, 0.63, 0.575);
headGroup.add(leftPupil);
box(leftPupil, [0.115, 0.16, 0.055], [0, 0, 0], materials.pupil, false);
box(leftPupil, [0.035, 0.04, 0.02], [-0.025, 0.045, 0.04], materials.glint, false);
const rightPupil = new THREE.Group();
rightPupil.position.set(0.26, 0.63, 0.575);
headGroup.add(rightPupil);
box(rightPupil, [0.115, 0.16, 0.055], [0, 0, 0], materials.pupil, false);
box(rightPupil, [0.035, 0.04, 0.02], [-0.025, 0.045, 0.04], materials.glint, false);
// Brows, nose, and mouth.
box(headGroup, [0.32, 0.055, 0.05], [-0.26, 0.84, 0.56], materials.hair, false);
box(headGroup, [0.32, 0.055, 0.05], [0.26, 0.84, 0.56], materials.hair, false);
box(headGroup, [0.14, 0.18, 0.17], [0, 0.56, 0.58], materials.skinLight);
box(headGroup, [0.11, 0.045, 0.04], [-0.12, 0.33, 0.55], materials.mouth, false);
box(headGroup, [0.11, 0.045, 0.04], [0, 0.33, 0.55], materials.mouth, false);
box(headGroup, [0.11, 0.045, 0.04], [0.12, 0.33, 0.55], materials.mouth, false);
// ------------------------------------------------------------
// Fixed target and authored attention marker
// ------------------------------------------------------------
const targetGroup = new THREE.Group();
targetGroup.position.set(2.3, 0, 1.9);
scene.add(targetGroup);
box(targetGroup, [1.35, 0.34, 1.35], [0, 0.17, 0], materials.pedestalDark);
box(targetGroup, [0.94, 0.32, 0.94], [0, 0.5, 0], materials.pedestal);
box(targetGroup, [0.72, 0.72, 0.72], [0, 1.02, 0], materials.target);
box(targetGroup, [0.38, 0.24, 0.38], [0, 1.5, 0], materials.targetCap);
const targetAnchor = new THREE.Object3D();
targetAnchor.position.set(0, 1.08, 0);
targetGroup.add(targetAnchor);
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(0, 2.13, 0);
targetGroup.add(labelAnchor);
// Four voxel-style corner brackets around the target.
const markerGroup = new THREE.Group();
markerGroup.position.set(0, 1.08, 0);
markerGroup.rotation.y = 0.18;
targetGroup.add(markerGroup);
const markerMaterial = materials.cyan.clone();
const cornerPositions = [
[-1, 1],
[1, 1],
[-1, -1],
[1, -1]
];
cornerPositions.forEach(([sx, sy]) => {
box(
markerGroup,
[0.24, 0.035, 0.035],
[sx * 0.53, sy * 0.57, 0],
markerMaterial,
false
);
box(
markerGroup,
[0.035, 0.24, 0.035],
[sx * 0.64, sy * 0.48, 0],
markerMaterial,
false
);
});
// ------------------------------------------------------------
// Dashed authored gaze/attention ray
// ------------------------------------------------------------
const rayGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
new THREE.Vector3()
]);
const rayMaterial = new THREE.LineDashedMaterial({
color: 0x64eaff,
dashSize: 0.12,
gapSize: 0.085,
transparent: true,
opacity: 0,
depthTest: false,
depthWrite: false
});
const attentionRay = new THREE.Line(rayGeometry, rayMaterial);
attentionRay.renderOrder = 10;
scene.add(attentionRay);
// ------------------------------------------------------------
// Authored animation timeline
// ------------------------------------------------------------
const REST_END = 1.2;
const GAZE_END = 1.95;
const HEAD_END = 3.05;
let animationStart = performance.now() + 350;
const targetWorldPosition = new THREE.Vector3();
const headCenterWorld = new THREE.Vector3();
const targetDirection = new THREE.Vector3();
const headQuaternion = new THREE.Quaternion();
const inverseHeadQuaternion = new THREE.Quaternion();
const eyeMidpoint = new THREE.Vector3();
const targetPosition = new THREE.Vector3(2.3, 1.08, 1.9);
const characterPosition = new THREE.Vector3(-1.6, 0, 0);
const eyeApproximateHeight = 2.71;
const horizontalDistance = Math.hypot(
targetPosition.x - characterPosition.x,
targetPosition.z - characterPosition.z
);
const targetYaw = Math.atan2(
targetPosition.x - characterPosition.x,
targetPosition.z - characterPosition.z
);
const targetPitch = -Math.atan2(
targetPosition.y - eyeApproximateHeight,
horizontalDistance
);
const idleYaw = 0.08;
const idlePitch = 0;
function smoothstep(edge0, edge1, value) {
const x = THREE.MathUtils.clamp((value - edge0) / (edge1 - edge0), 0, 1);
return x * x * (3 - 2 * x);
}
function setUI(time, gazeAmount, headAmount) {
fillRest.style.width = `${THREE.MathUtils.clamp(time / REST_END, 0, 1) * 100}%`;
fillGaze.style.width = `${THREE.MathUtils.clamp((time - REST_END) / (GAZE_END - REST_END), 0, 1) * 100}%`;
fillHead.style.width = `${THREE.MathUtils.clamp((time - GAZE_END) / (HEAD_END - GAZE_END), 0, 1) * 100}%`;
fillHold.style.width = `${THREE.MathUtils.clamp((time - HEAD_END) / 0.8, 0, 1) * 100}%`;
eyeMetric.textContent = `${Math.round(gazeAmount * 100)}%`;
headMetric.textContent = `${Math.round(headAmount * 100)}%`;
let activeTimeline = 0;
let activeStep = 0;
if (time < REST_END) {
phaseStatus.textContent = "Rest / Idle";
phaseTitle.textContent = "Waiting for the cue";
phaseDescription.textContent =
"The character is idle. The target remains fixed at its world position.";
} else if (time < GAZE_END) {
activeTimeline = 1;
activeStep = 0;
phaseStatus.textContent = "Gaze / Eyes";
phaseTitle.textContent = "Eyes acquire the target";
phaseDescription.textContent =
"The pupils shift first. The head remains still so the gaze change reads clearly.";
} else if (time < HEAD_END) {
activeTimeline = 2;
activeStep = 1;
phaseStatus.textContent = "Rotate / Head";
phaseTitle.textContent = "Head follows the gaze";
phaseDescription.textContent =
"After eye acquisition, the head rotates and pitches toward the fixed target.";
} else {
activeTimeline = 3;
activeStep = 2;
phaseStatus.textContent = "Hold / Attention";
phaseTitle.textContent = "Attention is held";
phaseDescription.textContent =
"The target stays fixed while the character maintains the authored attention pose.";
}
timelineCells.forEach((cell, index) => {
cell.classList.toggle("active", index === activeTimeline);
});
stepEls.forEach((step, index) => {
step.classList.toggle("active", index === activeStep);
});
}
replayButton.addEventListener("click", () => {
animationStart = performance.now() + 150;
headGroup.rotation.set(idlePitch, idleYaw, 0);
leftPupil.position.set(-0.26, 0.63, 0.575);
rightPupil.position.set(0.26, 0.63, 0.575);
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
function animate(now) {
const time = Math.max(0, (now - animationStart) / 1000);
// Phase 1: pupil movement only.
const gazeAmount = smoothstep(REST_END, GAZE_END, time);
// Phase 2: head rotation begins only after eye acquisition.
const headAmount = smoothstep(GAZE_END, HEAD_END, time);
headGroup.rotation.x = THREE.MathUtils.lerp(idlePitch, targetPitch, headAmount);
headGroup.rotation.y = THREE.MathUtils.lerp(idleYaw, targetYaw, headAmount);
characterRoot.updateWorldMatrix(true, true);
targetGroup.updateWorldMatrix(true, true);
targetAnchor.getWorldPosition(targetWorldPosition);
headGroup.localToWorld(headCenterWorld.set(0, 0.57, 0));
targetDirection
.copy(targetWorldPosition)
.sub(headCenterWorld)
.normalize();
headGroup.getWorldQuaternion(headQuaternion);
inverseHeadQuaternion.copy(headQuaternion).invert();
targetDirection.applyQuaternion(inverseHeadQuaternion);
// Convert the target direction into a restrained pupil offset.
const depth = Math.max(Math.abs(targetDirection.z), 0.2);
const desiredX = THREE.MathUtils.clamp((targetDirection.x / depth) * 0.12, -0.095, 0.095);
const desiredY = THREE.MathUtils.clamp((targetDirection.y / depth) * 0.1, -0.075, 0.075);
const pupilX = desiredX * gazeAmount;
const pupilY = desiredY * gazeAmount;
leftPupil.position.set(-0.26 + pupilX, 0.63 + pupilY, 0.575);
rightPupil.position.set(0.26 + pupilX, 0.63 + pupilY, 0.575);
materials.eyeWhite.emissiveIntensity = 0.12 + gazeAmount * 0.38;
// Authored attention ray, beginning with the eye-acquisition cue.
eyeMidpoint.set(0, 0.63, 0.58);
headGroup.localToWorld(eyeMidpoint);
const rayPositions = rayGeometry.attributes.position;
rayPositions.setXYZ(0, eyeMidpoint.x, eyeMidpoint.y, eyeMidpoint.z);
rayPositions.setXYZ(
1,
targetWorldPosition.x,
targetWorldPosition.y,
targetWorldPosition.z
);
rayPositions.needsUpdate = true;
attentionRay.computeLineDistances();
rayMaterial.opacity = gazeAmount * 0.58;
// Only the marker pulses; the target itself remains fixed.
const pulse = 1 + Math.sin(now * 0.0032) * 0.035;
markerGroup.scale.setScalar(pulse);
markerMaterial.opacity = 0.58 + Math.sin(now * 0.0032) * 0.15;
setUI(time, gazeAmount, headAmount);
// Project the target label into screen space.
const projected = labelAnchor.getWorldPosition(new THREE.Vector3()).project(camera);
const rect = stage.getBoundingClientRect();
const labelX = (projected.x * 0.5 + 0.5) * rect.width;
const labelY = (-projected.y * 0.5 + 0.5) * rect.height;
targetLabel.style.left = `${labelX}px`;
targetLabel.style.top = `${labelY - 24}px`;
targetLabel.style.visibility = projected.z > 1 ? "hidden" : "visible";
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
updateCamera();
requestAnimationFrame(animate);
</script>
</body>
</html>
```