Prompt specification
Build or customize the Three.js 3D scene "One graduate crosses the stage" 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: One graduate crosses the stage
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/one-graduate-crosses-the-stage-x3870
Scene Description Prompt:
Animate a participant leaving their seat, receiving a certificate, and returning by a separate route; the certificate remains visibly associated with the same person. Use Three.js from cdnjs in a single HTML file, with low-poly forms.
Working Three.js Starter (one-graduate-crosses-the-stage-x3870):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Participant 07 — Certificate Handoff</title>
<style>
:root {
--ink: #102331;
--panel: rgba(13, 30, 43, 0.88);
--blue: #37b9ff;
--orange: #ff9d43;
--cream: #fff8e8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dbe8ef;
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: white;
}
.title-card {
position: absolute;
top: 20px;
left: 20px;
max-width: min(440px, calc(100vw - 40px));
padding: 16px 18px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 14px 40px rgba(15, 35, 50, 0.22);
backdrop-filter: blur(12px);
}
.eyebrow {
margin-bottom: 6px;
color: #9edfff;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 3vw, 30px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 8px;
color: #c8d7df;
font-size: 13px;
line-height: 1.45;
}
.status {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding: 8px 11px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.09);
color: #f4fbff;
font-size: 12px;
font-weight: 700;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--blue);
box-shadow: 0 0 0 4px rgba(55, 185, 255, 0.14);
}
.bottom-card {
position: absolute;
right: 20px;
bottom: 20px;
left: 20px;
display: flex;
align-items: center;
gap: 18px;
padding: 13px 16px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 15px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(15, 35, 50, 0.2);
backdrop-filter: blur(12px);
}
.legend {
display: flex;
flex: 0 0 auto;
gap: 15px;
color: #d9e6ec;
font-size: 11px;
font-weight: 700;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.legend i {
display: block;
width: 22px;
height: 4px;
border-radius: 4px;
}
.legend .in {
background: var(--blue);
}
.legend .out {
background: var(--orange);
}
.progress-track {
position: relative;
flex: 1;
height: 6px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.12);
}
.progress-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--orange));
}
button {
pointer-events: auto;
flex: 0 0 auto;
border: 0;
border-radius: 10px;
padding: 9px 14px;
color: var(--ink);
background: white;
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #e9f8ff;
}
button:active {
transform: translateY(0);
}
.controls-hint {
position: absolute;
right: 20px;
top: 20px;
padding: 9px 12px;
border-radius: 10px;
color: #284453;
background: rgba(255, 255, 255, 0.78);
font-size: 11px;
font-weight: 700;
box-shadow: 0 8px 24px rgba(20, 50, 70, 0.12);
}
@media (max-width: 680px) {
.title-card {
top: 12px;
left: 12px;
padding: 13px 14px;
}
.subtitle {
display: none;
}
.controls-hint {
display: none;
}
.bottom-card {
right: 12px;
bottom: 12px;
left: 12px;
gap: 10px;
padding: 11px;
}
.legend {
display: none;
}
.status {
margin-top: 10px;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Ceremony Route Visualization</div>
<h1>Participant 07</h1>
<div class="subtitle">
The teal-jacketed participant leaves the highlighted seat, receives the
certificate onstage, and returns along a separate orange route.
</div>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">Preparing ceremony…</span>
</div>
</section>
<div class="controls-hint">Drag to orbit · Scroll to zoom</div>
<section class="bottom-card">
<div class="legend">
<span><i class="in"></i>Incoming route</span>
<span><i class="out"></i>Separate return</span>
</div>
<div class="progress-track">
<div class="progress-fill" id="progressFill"></div>
</div>
<button id="replayButton" type="button">Replay</button>
</section>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe8ef);
scene.fog = new THREE.Fog(0xdbe8ef, 18, 38);
const camera = new THREE.PerspectiveCamera(
46,
innerWidth / innerHeight,
0.1,
80
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe9f7ff, 0x5b6670, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3dd, 3.0);
sun.position.set(7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9edfff, 0.75);
fill.position.set(-8, 5, -4);
scene.add(fill);
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
const V = (x = 0, y = 0, z = 0) => new THREE.Vector3(x, y, z);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smoothstep(a, b, x) {
const t = clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
function angleLerp(a, b, t) {
const delta = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + delta * t;
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
flatShading: true,
...options
});
}
function box(parent, size, position, mat) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
mat
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, radiusTop, radiusBottom, height, position, mat, sides = 6) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, sides),
mat
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, position, mat, widthSegments = 8, heightSegments = 6) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, widthSegments, heightSegments),
mat
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
draw(context, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeCertificateTexture() {
return makeCanvasTexture(768, 512, (ctx, w, h) => {
ctx.fillStyle = "#fff9e9";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#087f78";
ctx.lineWidth = 22;
ctx.strokeRect(24, 24, w - 48, h - 48);
ctx.strokeStyle = "#efb84b";
ctx.lineWidth = 6;
ctx.strokeRect(47, 47, w - 94, h - 94);
ctx.textAlign = "center";
ctx.fillStyle = "#173845";
ctx.font = "bold 70px sans-serif";
ctx.fillText("CERTIFICATE", w / 2, 155);
ctx.font = "bold 31px sans-serif";
ctx.fillStyle = "#087f78";
ctx.fillText("PARTICIPANT 07", w / 2, 245);
ctx.font = "25px sans-serif";
ctx.fillStyle = "#385967";
ctx.fillText("ACHIEVEMENT IN PARTICIPATION", w / 2, 310);
ctx.font = "22px sans-serif";
ctx.fillText("CEREMONY 2026", w / 2, 390);
});
}
function makeBadgeTexture() {
return makeCanvasTexture(256, 160, (ctx, w, h) => {
ctx.fillStyle = "#fff4bd";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#153743";
ctx.font = "bold 96px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("07", w / 2, h / 2 + 4);
});
}
function makeSignTexture() {
return makeCanvasTexture(1024, 256, (ctx, w, h) => {
ctx.fillStyle = "#103847";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = "#8ee6ff";
ctx.font = "bold 90px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText("CEREMONY 2026", w / 2, h / 2);
});
}
function makeWorldLabel(text, color = "#ffffff") {
const texture = makeCanvasTexture(512, 128, (ctx, w, h) => {
ctx.fillStyle = "rgba(15, 37, 50, 0.88)";
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = color;
ctx.font = "bold 56px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, w / 2, h / 2 + 2);
});
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(2.4, 0.6, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Floor, stage and furniture
// -------------------------------------------------------------------------
const groundMat = material(0xd8e0df);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
groundMat
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const stageMat = material(0x216778);
const stageTopMat = material(0x2e7b8b);
const trimMat = material(0xf0b64b);
box(scene, V(9, 0.6, 3.4), V(0, 0.3, -4), stageMat);
box(scene, V(9.08, 0.08, 3.48), V(0, 0.64, -4), stageTopMat);
box(scene, V(8.9, 0.12, 0.08), V(0, 0.38, -2.27), trimMat);
const backdropMat = material(0x173f50);
box(scene, V(8.9, 4.0, 0.18), V(0, 2.55, -5.72), backdropMat);
const signTexture = makeSignTexture();
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(6.3, 1.55),
new THREE.MeshBasicMaterial({ map: signTexture })
);
sign.position.set(0, 3.45, -5.61);
scene.add(sign);
// Left-side approach steps.
box(scene, V(1.35, 0.2, 0.42), V(-2, 0.1, -1.55), stageMat);
box(scene, V(1.35, 0.4, 0.42), V(-2, 0.2, -1.93), stageMat);
// Right-side exit steps.
box(scene, V(1.35, 0.6, 0.42), V(3.2, 0.3, -2.1), stageMat);
box(scene, V(1.35, 0.4, 0.42), V(3.2, 0.2, -1.7), stageMat);
box(scene, V(1.35, 0.2, 0.42), V(3.2, 0.1, -1.3), stageMat);
const chairWood = material(0x8a5b42);
const chairCushion = material(0x436d7a);
const chairMetal = material(0x374750);
function makeChair(x, z, highlighted = false) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const cushionMat = highlighted
? material(0x16a8b6, { emissive: 0x063f45, emissiveIntensity: 0.35 })
: chairCushion;
box(group, V(0.82, 0.13, 0.78), V(0, 0.52, 0), cushionMat);
box(group, V(0.82, 0.82, 0.12), V(0, 0.96, 0.34), highlighted ? cushionMat : chairWood);
for (const sx of [-0.31, 0.31]) {
for (const sz of [-0.25, 0.25]) {
box(group, V(0.08, 0.52, 0.08), V(sx, 0.25, sz), chairMetal);
}
}
return group;
}
const seatXs = [-4, -2, 0, 2, 4];
seatXs.forEach((x) => makeChair(x, 5.0, x === -2));
seatXs.forEach((x) => makeChair(x, 7.2));
// Podium behind the presenter.
box(scene, V(1.5, 1.15, 0.72), V(-1.5, 1.18, -4.85), material(0x9b5a43));
box(scene, V(1.65, 0.12, 0.82), V(-1.5, 1.8, -4.85), trimMat);
// -------------------------------------------------------------------------
// Low-poly characters
// -------------------------------------------------------------------------
function makeCharacter(options = {}) {
const {
jacket = 0x607786,
trousers = 0x354652,
skin = 0xd89b73,
hair = 0x3b2b28,
shoe = 0x26343b,
cap = null,
badge = false
} = options;
const root = new THREE.Group();
const rig = new THREE.Group();
root.add(rig);
const jacketMat = material(jacket);
const trouserMat = material(trousers);
const skinMat = material(skin);
const hairMat = material(hair);
const shoeMat = material(shoe);
// Torso.
box(rig, V(0.68, 0.78, 0.38), V(0, 0.42, 0), jacketMat);
box(rig, V(0.54, 0.18, 0.40), V(0, 0.06, 0), trouserMat);
// Neck and head.
cylinder(rig, 0.10, 0.11, 0.18, V(0, 0.92, 0), skinMat, 6);
sphere(rig, 0.29, V(0, 1.17, 0), skinMat, 8, 6);
// Hair/cap.
if (cap !== null) {
cylinder(rig, 0.28, 0.31, 0.13, V(0, 1.40, 0), material(cap), 8);
box(rig, V(0.47, 0.055, 0.32), V(0, 1.36, -0.22), material(cap));
} else {
sphere(rig, 0.295, V(0, 1.27, 0.035), hairMat, 8, 5);
box(rig, V(0.50, 0.13, 0.12), V(0, 1.35, -0.22), hairMat);
}
// Low-poly facial features.
sphere(rig, 0.025, V(-0.09, 1.20, -0.267), material(0x142028), 6, 4);
sphere(rig, 0.025, V(0.09, 1.20, -0.267), material(0x142028), 6, 4);
box(rig, V(0.065, 0.065, 0.07), V(0, 1.10, -0.29), skinMat);
// Arms. Local +X is the character's right arm.
function makeArm(x) {
const shoulder = new THREE.Group();
shoulder.position.set(x, 0.73, 0);
rig.add(shoulder);
sphere(shoulder, 0.13, V(0, 0, 0), jacketMat, 6, 4);
cylinder(shoulder, 0.105, 0.095, 0.36, V(0, -0.18, 0), jacketMat, 6);
const elbow = new THREE.Group();
elbow.position.set(0, -0.36, 0);
shoulder.add(elbow);
sphere(elbow, 0.095, V(0, 0, 0), jacketMat, 6, 4);
cylinder(elbow, 0.085, 0.075, 0.31, V(0, -0.155, 0), skinMat, 6);
const hand = new THREE.Group();
hand.position.set(0, -0.34, 0);
elbow.add(hand);
sphere(hand, 0.095, V(0, 0, 0), skinMat, 6, 4);
return { shoulder, elbow, hand };
}
const armL = makeArm(-0.43);
const armR = makeArm(0.43);
// Legs with simple knee joints.
function makeLeg(x) {
const thigh = new THREE.Group();
thigh.position.set(x, 0, 0);
rig.add(thigh);
cylinder(thigh, 0.13, 0.12, 0.42, V(0, -0.21, 0), trouserMat, 6);
const shin = new THREE.Group();
shin.position.set(0, -0.42, 0);
thigh.add(shin);
cylinder(shin, 0.11, 0.095, 0.40, V(0, -0.20, 0), trouserMat, 6);
box(shin, V(0.23, 0.13, 0.38), V(0, -0.41, -0.08), shoeMat);
return { thigh, shin };
}
const legL = makeLeg(-0.18);
const legR = makeLeg(0.18);
if (badge) {
const badgeTexture = makeBadgeTexture();
const badgePlane = new THREE.Mesh(
new THREE.PlaneGeometry(0.30, 0.19),
new THREE.MeshBasicMaterial({ map: badgeTexture })
);
badgePlane.position.set(0, 0.55, -0.201);
badgePlane.rotation.y = Math.PI;
rig.add(badgePlane);
}
return {
root,
rig,
armL,
armR,
legL,
legR
};
}
function setSeated(character, amount = 1) {
character.rig.position.y = -0.38 * amount;
character.legL.thigh.rotation.x = lerp(0, 1.35, amount);
character.legR.thigh.rotation.x = lerp(0, 1.35, amount);
character.legL.shin.rotation.x = lerp(0, -1.30, amount);
character.legR.shin.rotation.x = lerp(0, -1.30, amount);
character.armL.shoulder.rotation.x = lerp(0, 0.18, amount);
character.armR.shoulder.rotation.x = lerp(0, 0.18, amount);
character.armL.elbow.rotation.x = lerp(0, -0.10, amount);
character.armR.elbow.rotation.x = lerp(0, -0.10, amount);
}
// The focal participant.
const participant = makeCharacter({
jacket: 0x12a8b6,
trousers: 0x263d49,
skin: 0xd99d74,
hair: 0x382a29,
shoe: 0x1c2b31,
cap: 0xf3bc45,
badge: true
});
scene.add(participant.root);
const participantStart = V(-2, 0, 4.95);
participant.root.position.copy(participantStart);
// Presenter.
const presenter = makeCharacter({
jacket: 0x9b4d53,
trousers: 0x303b49,
skin: 0xc98c67,
hair: 0x322723,
shoe: 0x202a30
});
presenter.root.position.set(-1.5, 0.61, -4.12);
presenter.root.rotation.y = Math.PI;
scene.add(presenter.root);
// Static audience members.
const audienceColors = [
[0x677d91, 0x394a58],
[0x8a6a93, 0x3d4254],
[0x798c69, 0x3c4742],
[0xb17961, 0x45434a],
[0x597f94, 0x333f4d]
];
for (let row = 0; row < 2; row++) {
for (let i = 0; i < seatXs.length; i++) {
if (row === 0 && i === 1) continue;
const colors = audienceColors[(i + row) % audienceColors.length];
const spectator = makeCharacter({
jacket: colors[0],
trousers: colors[1],
skin: [0xe0ad83, 0xb97855, 0x8d5f46][(i + row) % 3],
hair: [0x342724, 0x594337][(i + row) % 2]
});
spectator.root.position.set(
seatXs[i],
0,
row === 0 ? 5.05 : 7.25
);
setSeated(spectator, 1);
scene.add(spectator.root);
}
}
// -------------------------------------------------------------------------
// Routes
// -------------------------------------------------------------------------
const incomingPath = {
points: [
V(-2, 0, 4.95),
V(-2, 0, 2.4),
V(-2, 0, -1.25),
V(-2, 0.21, -1.55),
V(-2, 0.41, -1.90),
V(-2, 0.61, -2.25),
V(-1.5, 0.61, -2.55),
V(-1.5, 0.61, -2.82)
]
};
const returnPath = {
points: [
V(-1.5, 0.61, -2.82),
V(-0.8, 0.61, -2.55),
V(3.2, 0.61, -2.35),
V(3.2, 0.61, -2.10),
V(3.2, 0.41, -1.70),
V(3.2, 0.21, -1.30),
V(4.0, 0, -0.95),
V(4.0, 0, 2.80),
V(2.0, 0, 3.15),
V(0.3, 0, 3.20),
V(-2, 0, 4.70)
]
};
function preparePath(path) {
path.cumulative = [0];
path.total = 0;
for (let i = 1; i < path.points.length; i++) {
path.total += path.points[i].distanceTo(path.points[i - 1]);
path.cumulative.push(path.total);
}
}
preparePath(incomingPath);
preparePath(returnPath);
function samplePath(path, progress) {
const distance = clamp(progress, 0, 1) * path.total;
let segment = 0;
while (
segment < path.cumulative.length - 2 &&
distance > path.cumulative[segment + 1]
) {
segment++;
}
const start = path.points[segment];
const end = path.points[segment + 1];
const segmentLength = path.cumulative[segment + 1] - path.cumulative[segment];
const local = segmentLength > 0
? (distance - path.cumulative[segment]) / segmentLength
: 0;
return {
position: start.clone().lerp(end, local),
tangent: end.clone().sub(start).normalize()
};
}
function createRoute(path, color, labelText, labelPosition) {
const routeMat = material(color, {
emissive: color,
emissiveIntensity: 0.18
});
// Dashed route markers.
for (let i = 0; i < path.points.length - 1; i++) {
const a = path.points[i];
const b = path.points[i + 1];
const direction = b.clone().sub(a);
const length = direction.length();
const count = Math.max(1, Math.ceil(length / 0.62));
const dashLength = Math.min(0.34, length / count * 0.62);
for (let j = 0; j < count; j++) {
const t = (j + 0.5) / count;
const position = a.clone().lerp(b, t);
position.y += 0.025;
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.10, 0.025, dashLength),
routeMat
);
dash.position.copy(position);
dash.quaternion.setFromUnitVectors(V(0, 0, 1), direction.clone().normalize());
dash.receiveShadow = true;
scene.add(dash);
}
}
// Direction arrows.
const arrowLocations = [0.16, 0.38, 0.62, 0.84];
for (const u of arrowLocations) {
const sample = samplePath(path, u);
const next = samplePath(path, Math.min(1, u + 0.015));
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.15, 0.42, 3),
routeMat
);
arrow.position.copy(sample.position);
arrow.position.y += 0.10;
arrow.quaternion.setFromUnitVectors(
V(0, 1, 0),
next.tangent.clone().normalize()
);
scene.add(arrow);
}
const label = makeWorldLabel(labelText, `#${new THREE.Color(color).getHexString()}`);
label.position.copy(labelPosition);
scene.add(label);
}
createRoute(
incomingPath,
0x37b9ff,
"INCOMING",
V(-2, 0.48, 2.85)
);
createRoute(
returnPath,
0xff9d43,
"SEPARATE RETURN",
V(4, 0.48, 1.65)
);
// -------------------------------------------------------------------------
// Certificate
// -------------------------------------------------------------------------
const certificate = new THREE.Group();
certificate.visible = false;
scene.add(certificate);
const certBackMat = material(0x087f78);
const certPaperMat = material(0xfff8e8);
box(certificate, V(0.96, 0.70, 0.075), V(), certBackMat);
box(certificate, V(0.88, 0.62, 0.085), V(), certPaperMat);
const certTexture = makeCertificateTexture();
const certFaceFront = new THREE.Mesh(
new THREE.PlaneGeometry(0.82, 0.53),
new THREE.MeshBasicMaterial({ map: certTexture })
);
certFaceFront.position.z = -0.045;
certFaceFront.rotation.y = Math.PI;
certificate.add(certFaceFront);
const certFaceBack = new THREE.Mesh(
new THREE.PlaneGeometry(0.82, 0.53),
new THREE.MeshBasicMaterial({ map: certTexture })
);
certFaceBack.position.z = 0.045;
certificate.add(certFaceBack);
// Matching participant-color ribbon on both sides.
const ribbonMat = material(0x12a8b6, {
emissive: 0x063e43,
emissiveIntensity: 0.25
});
box(certificate, V(0.085, 0.60, 0.012), V(0, 0, -0.055), ribbonMat);
box(certificate, V(0.085, 0.60, 0.012), V(0, 0, 0.055), ribbonMat);
const seal = cylinder(
certificate,
0.09,
0.09,
0.025,
V(0.29, -0.20, -0.065),
material(0xefb84b),
10
);
seal.rotation.x = Math.PI / 2;
const clasp = box(
certificate,
V(0.16, 0.06, 0.11),
V(0, 0.34, 0),
material(0xf0b64b)
);
// -------------------------------------------------------------------------
// Animation state
// -------------------------------------------------------------------------
const DURATION = 18;
const TRANSFER_TIME = 6.55;
let elapsed = 0;
let transferred = false;
let previousTime = performance.now();
const statusText = document.getElementById("statusText");
const progressFill = document.getElementById("progressFill");
const replayButton = document.getElementById("replayButton");
function resetAnimation() {
elapsed = 0;
transferred = false;
certificate.visible = false;
presenter.armL.hand.attach(certificate);
certificate.position.set(0, -0.3, -0.05);
certificate.quaternion.identity();
certificate.scale.set(1, 1, 1);
participant.root.position.copy(participantStart);
participant.root.rotation.set(0, 0, 0);
setSeated(participant, 1);
presenter.armL.shoulder.rotation.set(0, 0, 0);
presenter.armL.elbow.rotation.set(0, 0, 0);
presenter.armR.shoulder.rotation.set(0, 0, 0);
presenter.armR.elbow.rotation.set(0, 0, 0);
statusText.textContent = "Participant 07 rises from seat 07";
}
function updateParticipant(t) {
let sitAmount;
if (t < 1.2) {
sitAmount = 1;
} else if (t < 2.0) {
sitAmount = 1 - smoothstep(1.2, 2.0, t);
} else if (t < 12.8) {
sitAmount = 0;
} else {
sitAmount = smoothstep(12.8, 14.0, t);
}
let walkAmount = 0;
const walkPhase = t * 9.5;
if (t >= 2.0 && t < 6.0) {
const progress = (t - 2.0) / 4.0;
const sample = samplePath(incomingPath, progress);
participant.root.position.copy(sample.position);
const yaw = Math.atan2(-sample.tangent.x, -sample.tangent.z);
participant.root.rotation.y = angleLerp(
participant.root.rotation.y,
yaw,
0.18
);
walkAmount =
smoothstep(2.0, 2.2, t) *
(1 - smoothstep(5.7, 6.0, t));
} else if (t >= 6.0 && t < 7.2) {
participant.root.position.copy(incomingPath.points.at(-1));
participant.root.rotation.y = angleLerp(
participant.root.rotation.y,
0,
0.16
);
} else if (t >= 7.2 && t < 12.8) {
const progress = (t - 7.2) / 5.6;
const sample = samplePath(returnPath, progress);
participant.root.position.copy(sample.position);
const yaw = Math.atan2(-sample.tangent.x, -sample.tangent.z);
participant.root.rotation.y = angleLerp(
participant.root.rotation.y,
yaw,
0.18
);
walkAmount =
smoothstep(7.2, 7.38, t) *
(1 - smoothstep(12.62, 12.8, t));
} else if (t >= 12.8) {
participant.root.position.copy(returnPath.points.at(-1));
participant.root.position.z = lerp(4.70, 4.95, sitAmount);
participant.root.rotation.y = angleLerp(
participant.root.rotation.y,
0,
smoothstep(12.8, 13.8, t)
);
} else {
participant.root.position.copy(participantStart);
participant.root.rotation.y = 0;
}
// Walking legs.
const leftSwing = Math.sin(walkPhase) * 0.56 * walkAmount;
const rightSwing = Math.sin(walkPhase + Math.PI) * 0.56 * walkAmount;
participant.legL.thigh.rotation.x = lerp(leftSwing, 1.35, sitAmount);
participant.legR.thigh.rotation.x = lerp(rightSwing, 1.35, sitAmount);
participant.legL.shin.rotation.x = lerp(
Math.max(0, -Math.sin(walkPhase)) * 0.72 * walkAmount,
-1.30,
sitAmount
);
participant.legR.shin.rotation.x = lerp(
Math.max(0, -Math.sin(walkPhase + Math.PI)) * 0.72 * walkAmount,
-1.30,
sitAmount
);
participant.rig.position.y = -0.38 * sitAmount;
// Normal arm swing.
const leftArmSwing = Math.sin(walkPhase + Math.PI) * 0.34 * walkAmount;
const rightArmSwing = Math.sin(walkPhase) * 0.34 * walkAmount;
participant.armL.shoulder.rotation.x = lerp(leftArmSwing, 0.18, sitAmount);
participant.armL.elbow.rotation.x = lerp(0, -0.08, sitAmount);
participant.armR.shoulder.rotation.x = rightArmSwing;
participant.armR.elbow.rotation.x = 0;
// Reach toward the presenter, receive, then hold the certificate.
if (t >= 5.85 && t < 6.55) {
const reach = smoothstep(5.85, 6.45, t);
participant.armR.shoulder.rotation.x = lerp(rightArmSwing, 1.12, reach);
participant.armR.elbow.rotation.x = lerp(0, -0.10, reach);
} else if (t >= 6.55 && t < 7.25) {
const retract = smoothstep(6.65, 7.25, t);
participant.armR.shoulder.rotation.x = lerp(1.12, 0.18, retract);
participant.armR.elbow.rotation.x = lerp(-0.10, -0.05, retract);
} else if (t >= 7.25) {
participant.armR.shoulder.rotation.x = 0.18;
participant.armR.elbow.rotation.x = -0.05;
}
}
function updatePresenter(t) {
let shoulderAngle = 0;
let elbowAngle = 0;
if (t >= 5.65 && t < 6.55) {
const extend = smoothstep(5.65, 6.35, t);
shoulderAngle = lerp(0, 1.12, extend);
elbowAngle = lerp(0, -0.10, extend);
} else if (t >= 6.55 && t < 7.25) {
const retract = smoothstep(6.65, 7.25, t);
shoulderAngle = lerp(1.12, 0, retract);
elbowAngle = lerp(-0.10, 0, retract);
}
presenter.armL.shoulder.rotation.x = shoulderAngle;
presenter.armL.elbow.rotation.x = elbowAngle;
}
const cameraWorldPosition = V();
const cameraWorldQuaternion = new THREE.Quaternion();
const handWorldPosition = V();
const handWorldQuaternion = new THREE.Quaternion();
const inverseHandQuaternion = new THREE.Quaternion();
const desiredWorldPosition = V();
const desiredLocalPosition = V();
const desiredWorldQuaternion = new THREE.Quaternion();
const desiredLocalQuaternion = new THREE.Quaternion();
function trackCertificateToHand(hand) {
hand.getWorldPosition(handWorldPosition);
hand.getWorldQuaternion(handWorldQuaternion);
camera.getWorldPosition(cameraWorldPosition);
camera.getWorldQuaternion(cameraWorldQuaternion);
// Keep the board immediately beneath the hand and facing the viewer.
desiredWorldPosition.copy(handWorldPosition);
desiredWorldPosition.y -= 0.31;
desiredWorldPosition.addScaledVector(
cameraWorldPosition.clone().sub(handWorldPosition).normalize(),
0.035
);
inverseHandQuaternion.copy(handWorldQuaternion).invert();
desiredLocalPosition.copy(desiredWorldPosition).sub(handWorldPosition);
desiredLocalPosition.applyQuaternion(inverseHandQuaternion);
desiredLocalQuaternion
.copy(inverseHandQuaternion)
.multiply(cameraWorldQuaternion);
certificate.position.lerp(desiredLocalPosition, 0.22);
certificate.quaternion.slerp(desiredLocalQuaternion, 0.22);
}
function getStatus(t) {
if (t < 1.2) return "Participant 07 rises from seat 07";
if (t < 2.0) return "Standing up and turning toward the stage";
if (t < 5.85) return "Walking the blue incoming route";
if (t < 7.25) return "Receiving the certificate from the presenter";
if (t < 12.8) return "Returning via the separate orange route";
if (t < 14.0) return "Returning to seat 07";
return "Participant 07 seated with the certificate";
}
function updateAnimation(t, dt) {
updateParticipant(t);
updatePresenter(t);
if (!transferred && t >= TRANSFER_TIME) {
// Preserve world position while changing ownership from the presenter
// to the participant's hand.
participant.armR.hand.attach(certificate);
transferred = true;
}
certificate.visible = t >= 5.70;
scene.updateMatrixWorld(true);
if (transferred) {
trackCertificateToHand(participant.armR.hand);
} else {
trackCertificateToHand(presenter.armL.hand);
}
const newStatus = getStatus(t);
if (statusText.textContent !== newStatus) {
statusText.textContent = newStatus;
}
progressFill.style.width = `${(t / DURATION) * 100}%`;
}
// -------------------------------------------------------------------------
// Custom orbit controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const cameraTarget = V(0, 0.95, -0.55);
const spherical = new THREE.Spherical(16.2, 1.05, 0.57);
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
spherical.phi = clamp(spherical.phi, 0.35, 1.38);
spherical.radius = clamp(spherical.radius, 8.5, 25);
const offset = V().setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(offset);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", (event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
}, { passive: false });
renderer.domElement.addEventListener("dblclick", () => {
spherical.set(16.2, 1.05, 0.57);
updateCamera();
});
replayButton.addEventListener("click", resetAnimation);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
updateCamera();
resetAnimation();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
elapsed = Math.min(DURATION, elapsed + dt);
updateAnimation(elapsed, dt);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```