Prompt specification
Build or customize the Three.js 3D scene "Conversation Turn as a Passed Token" 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: Conversation Turn as a Passed Token
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/conversation-turn-as-a-passed-token-x3390
Scene Description Prompt:
Conversation turn as a passed token. Animate a group passing a speaking token around a table. Explain the token as an explicit meeting convention rather than a literal property of all conversations. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (conversation-turn-as-a-passed-token-x3390):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>A Turn, Passed Around</title>
<style>
:root {
color-scheme: light;
--ink: #18312d;
--muted: #61716d;
--paper: rgba(250, 248, 242, 0.92);
--line: rgba(24, 49, 45, 0.14);
--accent: #ef6b45;
--accent-dark: #bd4527;
--shadow: 0 16px 45px rgba(39, 55, 51, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
background: #e9e4da;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.masthead {
position: absolute;
top: 24px;
left: 26px;
width: min(440px, calc(100vw - 52px));
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 11px;
border: 1px solid rgba(24, 49, 45, 0.12);
border-radius: 999px;
background: rgba(250, 248, 242, 0.78);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(239, 107, 69, 0.14);
}
h1 {
margin: 13px 0 7px;
max-width: 430px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 4.4vw, 64px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
text-wrap: balance;
}
.masthead p {
max-width: 420px;
margin: 0;
color: #4e625e;
font-size: 14px;
line-height: 1.55;
}
.convention-card {
position: absolute;
top: 24px;
right: 24px;
width: min(350px, calc(100vw - 48px));
padding: 19px 20px 18px;
border: 1px solid var(--line);
border-radius: 20px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.card-kicker {
margin-bottom: 8px;
color: var(--accent-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.convention-card h2 {
margin: 0 0 8px;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
line-height: 1.08;
letter-spacing: -0.025em;
}
.convention-card p {
margin: 0;
color: #536560;
font-size: 12.5px;
line-height: 1.55;
}
.convention-card strong {
color: var(--ink);
}
.qualifier {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #687873;
font-size: 11.5px;
line-height: 1.45;
}
.qualifier b {
color: var(--ink);
}
.dock {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
align-items: stretch;
gap: 10px;
width: min(690px, calc(100vw - 32px));
transform: translateX(-50%);
pointer-events: auto;
}
.speaker-card {
flex: 1 1 290px;
min-width: 0;
padding: 14px 17px 13px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.speaker-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
#floorLabel {
color: var(--accent-dark);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#speakerName {
overflow: hidden;
margin-top: 3px;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
font-weight: 500;
line-height: 1.05;
text-overflow: ellipsis;
white-space: nowrap;
}
#speakerRole {
overflow: hidden;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
}
.progress-track {
height: 3px;
margin-top: 11px;
overflow: hidden;
border-radius: 999px;
background: rgba(24, 49, 45, 0.1);
}
#progressFill {
width: 100%;
height: 100%;
border-radius: inherit;
background: var(--accent);
transform: scaleX(0);
transform-origin: left center;
}
.turn-dots {
display: flex;
gap: 6px;
margin-top: 9px;
}
.turn-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: #c9ceca;
transition:
transform 180ms ease,
background 180ms ease,
box-shadow 180ms ease;
}
.turn-dot.active {
transform: scale(1.35);
background: var(--accent);
box-shadow: 0 0 0 4px rgba(239, 107, 69, 0.13);
}
.turn-dot.next {
background: #efaa91;
}
.buttons {
display: flex;
flex-direction: column;
gap: 7px;
pointer-events: auto;
}
button {
min-width: 126px;
padding: 9px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(250, 248, 242, 0.92);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 8px 22px rgba(39, 55, 51, 0.09);
transition:
transform 120ms ease,
background 120ms ease,
box-shadow 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf7;
box-shadow: 0 11px 25px rgba(39, 55, 51, 0.13);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 3px solid rgba(239, 107, 69, 0.3);
outline-offset: 2px;
}
button.primary {
border-color: transparent;
background: var(--ink);
color: #fffdf7;
}
button.primary:hover {
background: #25443e;
}
.control-hint {
position: absolute;
right: 24px;
bottom: 25px;
color: rgba(24, 49, 45, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.name-tag {
position: absolute;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(24, 49, 45, 0.1);
border-radius: 999px;
background: rgba(250, 248, 242, 0.82);
color: #314944;
font-size: 9px;
font-weight: 800;
white-space: nowrap;
box-shadow: 0 5px 14px rgba(39, 55, 51, 0.09);
transform: translate(-50%, -50%);
transition:
border-color 180ms ease,
background 180ms ease,
opacity 180ms ease;
}
.name-tag::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--person-color);
}
.name-tag.active {
border-color: rgba(239, 107, 69, 0.45);
background: rgba(255, 251, 243, 0.96);
}
@media (max-width: 820px) {
.masthead {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
h1 {
max-width: 320px;
font-size: 39px;
}
.masthead p {
max-width: 320px;
font-size: 12px;
}
.convention-card {
top: auto;
right: 12px;
bottom: 139px;
left: 12px;
width: auto;
padding: 13px 15px;
border-radius: 16px;
}
.convention-card h2 {
font-size: 18px;
}
.convention-card p,
.qualifier {
font-size: 10.5px;
}
.qualifier {
margin-top: 8px;
padding-top: 8px;
}
.dock {
bottom: 12px;
width: calc(100vw - 24px);
gap: 7px;
}
.speaker-card {
padding: 11px 13px;
}
#speakerName {
font-size: 18px;
}
.buttons {
gap: 5px;
}
button {
min-width: 96px;
padding: 7px 9px;
font-size: 10px;
}
.control-hint {
display: none;
}
}
@media (max-width: 520px) {
.masthead p {
display: none;
}
.convention-card .qualifier {
display: none;
}
.convention-card p {
margin-bottom: 0;
}
.dock {
flex-direction: column;
}
.buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
button {
min-width: 0;
}
.convention-card {
bottom: 181px;
}
.name-tag {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Animated meeting scene showing a speaking token passed between six people around a table"
></canvas>
<div id="labels" aria-hidden="true"></div>
<main class="ui">
<header class="masthead">
<div class="eyebrow">Structured turn-taking</div>
<h1>A turn, passed around.</h1>
<p>
A visible token makes the current floor holder and the next turn easy to
follow.
</p>
</header>
<aside class="convention-card" aria-label="Explanation of the token convention">
<div class="card-kicker">Meeting convention</div>
<h2>One token, one visible turn.</h2>
<p>
<strong>In this meeting,</strong> only the person holding the token has
the floor. They pass it to invite the next response.
</p>
<div class="qualifier">
<b>This is a chosen facilitation tool—not a literal property of every
conversation.</b> Many discussions use turn-taking without a physical
token.
</div>
</aside>
<section class="dock" aria-label="Animation controls">
<div class="speaker-card">
<div class="speaker-top">
<div>
<div id="floorLabel">Current speaker</div>
<div id="speakerName">Maya Chen</div>
<div id="speakerRole">Product lead</div>
</div>
</div>
<div class="progress-track" aria-hidden="true">
<div id="progressFill"></div>
</div>
<div id="turnDots" class="turn-dots" aria-hidden="true"></div>
</div>
<div class="buttons">
<button id="passButton" class="primary" type="button">Pass token</button>
<button id="pauseButton" type="button" aria-pressed="false">Pause</button>
<button id="restartButton" type="button">Restart</button>
</div>
</section>
<div class="control-hint">DRAG TO ORBIT · SCROLL TO ZOOM · SPACE TO PAUSE</div>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
scene.fog = new THREE.Fog(0xe9e4da, 12, 25);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let cameraAzimuth = 0.67;
let cameraPolar = 1.02;
let cameraRadius = 9.1;
function updateCamera() {
const horizontal = cameraRadius * Math.sin(cameraPolar);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z + horizontal * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff9ed, 0x78877e, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4dc, 3.4);
keyLight.position.set(4.5, 9, 5.5);
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 = 20;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e5e6, 1.35);
fillLight.position.set(-5, 5, -4);
scene.add(fillLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xded8cc,
roughness: 0.95,
metalness: 0,
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const rugMaterial = new THREE.MeshStandardMaterial({
color: 0xaebfba,
roughness: 1,
metalness: 0,
});
const rug = new THREE.Mesh(
new THREE.CylinderGeometry(4.55, 4.55, 0.045, 64),
rugMaterial
);
rug.position.y = 0.005;
rug.receiveShadow = true;
scene.add(rug);
// -------------------------------------------------------------------------
// Table
// -------------------------------------------------------------------------
const tableTopMaterial = new THREE.MeshStandardMaterial({
color: 0xd9ad70,
roughness: 0.72,
metalness: 0,
});
const tableEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xa86f3f,
roughness: 0.76,
metalness: 0,
});
const tableTop = new THREE.Mesh(
new THREE.CylinderGeometry(2.12, 2.12, 0.23, 64),
tableTopMaterial
);
tableTop.position.y = 1.15;
tableTop.castShadow = true;
tableTop.receiveShadow = true;
scene.add(tableTop);
const tableUnder = new THREE.Mesh(
new THREE.CylinderGeometry(1.86, 1.86, 0.14, 64),
tableEdgeMaterial
);
tableUnder.position.y = 0.99;
tableUnder.castShadow = true;
scene.add(tableUnder);
const rim = new THREE.Mesh(
new THREE.TorusGeometry(2.105, 0.035, 8, 64),
tableEdgeMaterial
);
rim.rotation.x = Math.PI / 2;
rim.position.y = 1.255;
scene.add(rim);
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0x506761,
roughness: 0.78,
metalness: 0.05,
});
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.24, 0.31, 0.92, 20),
pedestalMaterial
);
pedestal.position.y = 0.52;
pedestal.castShadow = true;
scene.add(pedestal);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.92, 0.98, 0.12, 32),
pedestalMaterial
);
base.position.y = 0.1;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// A small solid centerpiece: cylinder vase and spherical foliage.
const vase = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.23, 0.36, 16),
new THREE.MeshStandardMaterial({
color: 0xeee2cc,
roughness: 0.75,
})
);
vase.position.set(0, 1.445, 0);
vase.castShadow = true;
scene.add(vase);
const foliage = new THREE.Mesh(
new THREE.SphereGeometry(0.31, 12, 8),
new THREE.MeshStandardMaterial({
color: 0x5e8d73,
roughness: 0.9,
})
);
foliage.scale.set(1, 0.78, 1);
foliage.position.set(0, 1.73, 0);
foliage.castShadow = true;
scene.add(foliage);
// -------------------------------------------------------------------------
// People
// -------------------------------------------------------------------------
const participants = [
{
name: "Maya Chen",
role: "Product lead",
shirt: 0x327c78,
skin: 0xd9a57c,
hair: 0x272a28,
},
{
name: "Theo Brooks",
role: "Research",
shirt: 0xc5654f,
skin: 0x8d5b43,
hair: 0x322a24,
},
{
name: "Amina Yusuf",
role: "Engineering",
shirt: 0xd5a83e,
skin: 0xa9704f,
hair: 0x3c2d27,
},
{
name: "Leo Martins",
role: "Product design",
shirt: 0x5476a4,
skin: 0xe0b18b,
hair: 0x4b3528,
},
{
name: "Nora Singh",
role: "Operations",
shirt: 0x8d678d,
skin: 0xc98e64,
hair: 0x292523,
},
{
name: "Eli Park",
role: "Accessibility",
shirt: 0x69945d,
skin: 0xe4b793,
hair: 0x252729,
},
];
const chairMaterial = new THREE.MeshStandardMaterial({
color: 0x526660,
roughness: 0.86,
metalness: 0,
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x293331,
roughness: 0.85,
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x202321,
roughness: 0.7,
});
const labelsRoot = document.querySelector("#labels");
function addBox(parent, dimensions, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(...dimensions),
material
);
mesh.position.set(...position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
material,
segments = 16
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material
);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createPerson(data, index) {
const group = new THREE.Group();
const startAngle = 2.36;
const angle = startAngle + (index * Math.PI * 2) / participants.length;
const radius = 2.91;
group.position.set(
Math.sin(angle) * radius,
0,
Math.cos(angle) * radius
);
// Local +Z points toward the center of the table.
group.rotation.y = angle + Math.PI;
scene.add(group);
// Chair.
addBox(
group,
[0.86, 0.15, 0.76],
[0, 0.64, -0.18],
chairMaterial
);
addBox(
group,
[0.86, 0.92, 0.13],
[0, 1.15, -0.57],
chairMaterial
);
for (const x of [-0.32, 0.32]) {
for (const z of [-0.42, 0.05]) {
addBox(
group,
[0.09, 0.62, 0.09],
[x, 0.32, z],
chairMaterial
);
}
}
// Seated legs and shoes.
const trouserMaterial = new THREE.MeshStandardMaterial({
color: 0x3e4946,
roughness: 0.9,
});
for (const x of [-0.17, 0.17]) {
addBox(
group,
[0.25, 0.24, 0.62],
[x, 0.86, 0.2],
trouserMaterial
);
addBox(
group,
[0.23, 0.58, 0.23],
[x, 0.48, 0.5],
trouserMaterial
);
addBox(
group,
[0.25, 0.16, 0.4],
[x, 0.16, 0.57],
darkMaterial
);
}
// Torso.
const shirtMaterial = new THREE.MeshStandardMaterial({
color: data.shirt,
roughness: 0.83,
metalness: 0,
});
const torso = addCylinder(
group,
0.36,
0.42,
0.78,
[0, 1.39, 0.04],
shirtMaterial,
10
);
addCylinder(
group,
0.12,
0.12,
0.15,
[0, 1.84, 0.04],
new THREE.MeshStandardMaterial({
color: data.skin,
roughness: 0.82,
}),
12
);
// Head and simple facial features.
const headPivot = new THREE.Group();
headPivot.position.set(0, 2.08, 0.04);
group.add(headPivot);
const skinMaterial = new THREE.MeshStandardMaterial({
color: data.skin,
roughness: 0.78,
});
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.3, 16, 12),
skinMaterial
);
head.castShadow = true;
headPivot.add(head);
const hairMaterial = new THREE.MeshStandardMaterial({
color: data.hair,
roughness: 0.96,
});
const hair = new THREE.Mesh(
new THREE.SphereGeometry(
0.305,
16,
10,
0,
Math.PI * 2,
0,
Math.PI * 0.53
),
hairMaterial
);
hair.position.y = 0.018;
hair.castShadow = true;
headPivot.add(hair);
for (const x of [-0.092, 0.092]) {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.026, 8, 6),
eyeMaterial
);
eye.position.set(x, 0.025, 0.272);
headPivot.add(eye);
}
const nose = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 8, 6),
skinMaterial
);
nose.scale.set(0.8, 0.9, 1.2);
nose.position.set(0, -0.025, 0.302);
headPivot.add(nose);
addBox(
headPivot,
[0.095, 0.018, 0.018],
[0, -0.115, 0.267],
eyeMaterial,
false
);
// Arms with pivots so the token hand can gesture.
const armMaterial = new THREE.MeshStandardMaterial({
color: data.shirt,
roughness: 0.85,
});
const handMaterial = new THREE.MeshStandardMaterial({
color: data.skin,
roughness: 0.8,
});
function createArm(x) {
const pivot = new THREE.Group();
pivot.position.set(x, 1.7, 0.03);
group.add(pivot);
const shoulder = new THREE.Mesh(
new THREE.SphereGeometry(0.14, 10, 8),
shirtMaterial
);
shoulder.castShadow = true;
pivot.add(shoulder);
const sleeve = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.105, 0.48, 10),
armMaterial
);
sleeve.position.y = -0.24;
sleeve.castShadow = true;
pivot.add(sleeve);
const forearm = new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.085, 0.22, 10),
skinMaterial
);
forearm.position.y = -0.56;
forearm.castShadow = true;
pivot.add(forearm);
const hand = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 10, 8),
handMaterial
);
hand.position.y = -0.69;
hand.castShadow = true;
pivot.add(hand);
return pivot;
}
const rightArm = createArm(0.4);
const leftArm = createArm(-0.4);
// Speaker ring beneath each chair.
const ringMaterial = new THREE.MeshStandardMaterial({
color: data.shirt,
emissive: data.shirt,
emissiveIntensity: 0.2,
roughness: 0.65,
transparent: true,
opacity: 0.08,
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.025, 8, 48),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0, 0.055, -0.1);
group.add(ring);
const label = document.createElement("div");
label.className = "name-tag";
label.style.setProperty("--person-color", `#${data.shirt.toString(16).padStart(6, "0")}`);
label.textContent = data.name.split(" ")[0];
labelsRoot.appendChild(label);
return {
...data,
group,
torso,
headPivot,
rightArm,
leftArm,
ring,
label,
};
}
participants.forEach((data, index) => {
data.index = index;
Object.assign(data, createPerson(data, index));
});
// -------------------------------------------------------------------------
// Speaking token
// -------------------------------------------------------------------------
const token = new THREE.Group();
const tokenMaterial = new THREE.MeshStandardMaterial({
color: 0xef6b45,
emissive: 0x7a1d0d,
emissiveIntensity: 0.16,
roughness: 0.52,
metalness: 0.02,
});
const tokenPuck = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.235, 0.085, 32),
tokenMaterial
);
tokenPuck.castShadow = true;
token.add(tokenPuck);
const tokenRing = new THREE.Mesh(
new THREE.TorusGeometry(0.175, 0.027, 8, 32),
new THREE.MeshStandardMaterial({
color: 0xffd08a,
roughness: 0.45,
})
);
tokenRing.rotation.x = Math.PI / 2;
tokenRing.position.y = 0.047;
tokenRing.castShadow = true;
token.add(tokenRing);
// Three small solid bars suggest a speech signal.
for (const x of [-0.07, 0, 0.07]) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.034, 0.032, 0.1),
new THREE.MeshStandardMaterial({
color: 0xffd08a,
roughness: 0.5,
})
);
bar.position.set(x, 0.064, 0);
bar.castShadow = true;
token.add(bar);
}
scene.add(token);
// -------------------------------------------------------------------------
// Turn-taking state
// -------------------------------------------------------------------------
const SPEAK_DURATION = 3.4;
const PASS_DURATION = 1.35;
let speakerIndex = 0;
let nextIndex = 1;
let phase = "speaking";
let phaseTime = 0;
let paused = false;
let elapsed = 0;
const passFrom = new THREE.Vector3();
const passTo = new THREE.Vector3();
const speakerName = document.querySelector("#speakerName");
const speakerRole = document.querySelector("#speakerRole");
const floorLabel = document.querySelector("#floorLabel");
const progressFill = document.querySelector("#progressFill");
const turnDots = document.querySelector("#turnDots");
const dots = participants.map((participant) => {
const dot = document.createElement("span");
dot.className = "turn-dot";
turnDots.appendChild(dot);
return dot;
});
function holdPoint(index) {
const point = new THREE.Vector3(0.4, 1.42, 0.55);
return participants[index].group.localToWorld(point);
}
function updateUI() {
const shownIndex = phase === "passing" ? nextIndex : speakerIndex;
const shown = participants[shownIndex];
speakerName.textContent = shown.name;
speakerRole.textContent = shown.role;
floorLabel.textContent =
phase === "passing" ? "Passing to" : "Current speaker";
dots.forEach((dot, index) => {
dot.classList.toggle("active", index === speakerIndex);
dot.classList.toggle("next", phase === "passing" && index === nextIndex);
});
participants.forEach((participant) => {
participant.label.classList.toggle(
"active",
participant.index === speakerIndex ||
(phase === "passing" && participant.index === nextIndex)
);
});
}
function beginPass() {
if (phase === "passing") return;
phase = "passing";
phaseTime = 0;
passFrom.copy(holdPoint(speakerIndex));
passTo.copy(holdPoint(nextIndex));
updateUI();
}
function completePass() {
speakerIndex = nextIndex;
nextIndex = (speakerIndex + 1) % participants.length;
phase = "speaking";
phaseTime = 0;
updateUI();
}
function restart() {
speakerIndex = 0;
nextIndex = 1;
phase = "speaking";
phaseTime = 0;
paused = false;
pauseButton.textContent = "Pause";
pauseButton.setAttribute("aria-pressed", "false");
token.position.copy(holdPoint(speakerIndex));
updateUI();
}
const pauseButton = document.querySelector("#pauseButton");
document.querySelector("#passButton").addEventListener("click", beginPass);
document.querySelector("#restartButton").addEventListener("click", restart);
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
updateUI();
token.position.copy(holdPoint(speakerIndex));
// -------------------------------------------------------------------------
// Custom camera controls: drag to orbit, wheel/pinch to zoom
// -------------------------------------------------------------------------
const pointers = new Map();
let previousPinchDistance = null;
function currentPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return null;
const dx = values[0].x - values[1].x;
const dy = values[0].y - values[1].y;
return Math.hypot(dx, dy);
}
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
canvas.setPointerCapture(event.pointerId);
if (pointers.size === 2) {
previousPinchDistance = currentPinchDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar + dy * 0.005,
0.58,
1.36
);
previousPinchDistance = null;
} else if (pointers.size === 2) {
const distance = currentPinchDistance();
if (distance && previousPinchDistance) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (previousPinchDistance / distance),
6.4,
12.8
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = null;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.007,
6.4,
12.8
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
} else if (event.code === "ArrowRight") {
beginPass();
} else if (event.code === "KeyR") {
restart();
}
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
participants.forEach((participant) => {
projected.set(
participant.group.position.x,
2.64,
participant.group.position.z
);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
participant.label.style.left = `${x}px`;
participant.label.style.top = `${y}px`;
participant.label.style.opacity = visible ? "1" : "0";
});
}
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (!paused) {
phaseTime += delta;
if (phase === "speaking" && phaseTime >= SPEAK_DURATION) {
beginPass();
} else if (phase === "passing" && phaseTime >= PASS_DURATION) {
completePass();
}
}
// Animate the token and the current speaker's gestures.
if (phase === "speaking") {
token.position.copy(holdPoint(speakerIndex));
token.position.y += Math.sin(elapsed * 3.1) * 0.022;
} else {
const t = THREE.MathUtils.clamp(phaseTime / PASS_DURATION, 0, 1);
const eased = t * t * (3 - 2 * t);
token.position.lerpVectors(passFrom, passTo, eased);
token.position.y += Math.sin(Math.PI * t) * 0.86;
const pulse = 1 + Math.sin(Math.PI * t) * 0.08;
token.scale.setScalar(pulse);
}
token.rotation.y += delta * (phase === "passing" ? 4.2 : 1.25);
token.rotation.z = Math.sin(elapsed * 1.7) * 0.055;
participants.forEach((participant) => {
const isSpeaker = participant.index === speakerIndex;
const isNext = phase === "passing" && participant.index === nextIndex;
const rightTarget = isSpeaker
? -1.02
: isNext
? -0.7
: -0.16;
const leftTarget = isSpeaker ? -0.42 : -0.13;
participant.rightArm.rotation.x = THREE.MathUtils.damp(
participant.rightArm.rotation.x,
rightTarget,
7,
delta
);
participant.leftArm.rotation.x = THREE.MathUtils.damp(
participant.leftArm.rotation.x,
leftTarget,
7,
delta
);
const speakingAmount = isSpeaker ? 1 : isNext ? 0.45 : 0;
const nod = Math.sin(elapsed * 3.4 + participant.index) *
0.055 *
speakingAmount;
participant.headPivot.rotation.x = THREE.MathUtils.damp(
participant.headPivot.rotation.x,
0.025 + nod,
8,
delta
);
participant.headPivot.rotation.z = Math.sin(
elapsed * 0.8 + participant.index
) *
0.012;
participant.torso.scale.y =
1 + Math.sin(elapsed * 1.7 + participant.index) * 0.006;
const ringTarget = isSpeaker ? 0.9 : isNext ? 0.34 : 0.07;
participant.ring.material.opacity = THREE.MathUtils.damp(
participant.ring.material.opacity,
ringTarget,
7,
delta
);
const ringScale =
isSpeaker ? 1 + Math.sin(elapsed * 3.2) * 0.055 : 1;
participant.ring.scale.setScalar(ringScale);
});
const progress =
phase === "speaking"
? THREE.MathUtils.clamp(phaseTime / SPEAK_DURATION, 0, 1)
: THREE.MathUtils.clamp(phaseTime / PASS_DURATION, 0, 1);
progressFill.style.transform = `scaleX(${progress})`;
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
// -------------------------------------------------------------------------
// Resize handling
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
});
</script>
</body>
</html>
```