Prompt specification
Build or customize the Three.js 3D scene "Eyes-closed reaching teaching 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: Eyes-closed reaching teaching scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/eyes-closed-reaching-teaching-scene-x1015
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring proprioception. Compose a stylized arm reaching toward a marked position with visual cues optionally hidden; highlight conceptual internal feedback rather than claiming a realistic motor-control simulation. Voxel style.
Working Three.js Starter (eyes-closed-reaching-teaching-scene-x1015):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Reach — Conceptual Proprioception</title>
<style>
:root {
color-scheme: dark;
--bg: #07111c;
--panel: rgba(12, 25, 39, 0.78);
--panel-border: rgba(183, 224, 238, 0.16);
--text: #e8f2f5;
--muted: #91a7b4;
--cyan: #56e6df;
--amber: #ffbd66;
--soft: #c9d6dc;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 64% 42%, #142a3a 0%, #091522 48%, #050c14 100%);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
#scene:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -4px;
}
#interface {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.glass {
background: var(--panel);
border: 1px solid var(--panel-border);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
content: "";
border-radius: 1px;
background: var(--cyan);
box-shadow: 0 0 16px rgba(86, 230, 223, 0.75);
}
h1 {
margin: 12px 0 8px;
font-size: clamp(32px, 4.2vw, 52px);
font-weight: 650;
line-height: 0.98;
letter-spacing: -0.055em;
}
#title-card p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.status-line {
display: flex;
align-items: center;
gap: 10px;
margin-top: 16px;
padding-top: 14px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--soft);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.status-light {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 14px rgba(255, 189, 102, 0.8);
animation: status-pulse 1.6s ease-in-out infinite;
}
@keyframes status-pulse {
50% {
opacity: 0.45;
transform: scale(0.8);
}
}
#controls {
position: absolute;
top: 24px;
right: 24px;
width: 300px;
padding: 17px;
border-radius: 18px;
pointer-events: auto;
}
.panel-heading {
margin: 0 0 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
min-height: 39px;
border-bottom: 1px solid rgba(255, 255, 255, 0.055);
color: var(--soft);
font-size: 12px;
}
.control-name {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(86, 230, 223, 0.35);
}
.swatch.amber {
background: var(--amber);
box-shadow: 0 0 10px rgba(255, 189, 102, 0.35);
}
.swatch.trace {
background: #8dc7d8;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 34px;
height: 19px;
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.switch span {
position: absolute;
inset: 0;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 20px;
background: rgba(255, 255, 255, 0.08);
cursor: pointer;
transition: 160ms ease;
}
.switch span::after {
position: absolute;
top: 3px;
left: 3px;
width: 11px;
height: 11px;
content: "";
border-radius: 50%;
background: #8295a1;
transition: 160ms ease;
}
.switch input:checked + span {
border-color: rgba(86, 230, 223, 0.45);
background: rgba(86, 230, 223, 0.17);
}
.switch input:checked + span::after {
background: var(--cyan);
transform: translateX(15px);
box-shadow: 0 0 10px rgba(86, 230, 223, 0.6);
}
.switch input:focus-visible + span {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
button {
min-height: 36px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(86, 230, 223, 0.35);
background: rgba(86, 230, 223, 0.1);
}
button:active {
transform: translateY(1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#concept {
position: absolute;
bottom: 24px;
left: 24px;
width: min(370px, calc(100vw - 48px));
padding: 17px 19px;
border-radius: 16px;
}
#concept h2 {
margin: 0 0 7px;
font-size: 13px;
font-weight: 650;
}
#concept p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.65;
}
#concept strong {
color: var(--soft);
font-weight: 650;
}
#legend {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
gap: 16px;
padding: 11px 14px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.world-label {
position: absolute;
z-index: 4;
display: none;
padding: 5px 8px;
border: 1px solid rgba(86, 230, 223, 0.22);
border-radius: 6px;
background: rgba(6, 18, 29, 0.76);
color: var(--cyan);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.11em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
}
.world-label span {
display: block;
margin-top: 4px;
color: #76939f;
font-size: 7px;
font-weight: 600;
letter-spacing: 0.08em;
}
.world-label.target {
border-color: rgba(255, 189, 102, 0.3);
color: var(--amber);
}
#hint {
position: absolute;
top: 50%;
left: 50%;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 9px;
background: rgba(4, 12, 20, 0.45);
color: rgba(205, 220, 227, 0.55);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 500ms ease;
}
#fallback {
position: fixed;
inset: 0;
display: none;
place-items: center;
padding: 30px;
background: #07111c;
color: var(--text);
text-align: center;
z-index: 20;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
h1 {
margin-top: 9px;
font-size: 34px;
}
#title-card p {
font-size: 11px;
}
.status-line {
margin-top: 10px;
padding-top: 10px;
}
#controls {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 12px 14px;
}
.control-row {
min-height: 32px;
}
.button-row {
margin-top: 9px;
}
#concept {
right: 12px;
bottom: 184px;
left: 12px;
width: auto;
padding: 12px 14px;
}
#concept p {
font-size: 10px;
line-height: 1.5;
}
#legend,
#hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
.status-light {
animation: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
role="application"
aria-label="Interactive voxel arm reaching toward a marked position. Drag to orbit, scroll to zoom, and use arrow keys to rotate."
></canvas>
<div id="interface">
<section id="title-card" class="glass">
<div class="eyebrow">Body perception / study 04</div>
<h1>Reach, felt.</h1>
<p>
A voxel arm and a marked position, overlaid with an illustrative
internal position estimate.
</p>
<div class="status-line" aria-live="polite">
<span class="status-light"></span>
<span id="status-text">Orienting the limb</span>
</div>
</section>
<section id="controls" class="glass" aria-label="Scene controls">
<p class="panel-heading">Visual cue visibility</p>
<div class="control-row">
<span class="control-name">
<span class="swatch"></span>
Internal feedback
</span>
<label class="switch">
<input id="internal-toggle" type="checkbox" checked>
<span aria-hidden="true"></span>
</label>
</div>
<div class="control-row">
<span class="control-name">
<span class="swatch amber"></span>
Marked position
</span>
<label class="switch">
<input id="target-toggle" type="checkbox" checked>
<span aria-hidden="true"></span>
</label>
</div>
<div class="control-row">
<span class="control-name">
<span class="swatch trace"></span>
Reach trace
</span>
<label class="switch">
<input id="trace-toggle" type="checkbox" checked>
<span aria-hidden="true"></span>
</label>
</div>
<div class="button-row">
<button id="toggle-cues" type="button">Hide all cues</button>
<button id="replay" type="button">Replay reach</button>
</div>
</section>
<section id="concept" class="glass">
<h2>Conceptual proprioception</h2>
<p>
<strong>This is a visual metaphor, not a realistic motor-control
simulation.</strong> The cyan lattice represents a simplified internal
estimate of limb configuration. No muscles, tendons, nerves, sensory
noise, or motor-control physics are modeled.
</p>
</section>
<aside id="legend" class="glass" aria-label="Color legend">
<span class="legend-item">
<span class="swatch"></span>
Internal estimate
</span>
<span class="legend-item">
<span class="swatch amber"></span>
External marker
</span>
<span class="legend-item">
<span class="swatch trace"></span>
Body voxels
</span>
</aside>
<div id="label-shoulder" class="world-label">
Shoulder <span>position anchor</span>
</div>
<div id="label-elbow" class="world-label">
Elbow <span>bend cue</span>
</div>
<div id="label-wrist" class="world-label">
Wrist <span>orientation cue</span>
</div>
<div id="label-target" class="world-label target">
Marked position <span>external reference</span>
</div>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
</div>
<div id="fallback">
<p>This scene requires WebGL to render.</p>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const fallback = document.querySelector("#fallback");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
fallback.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setClearColor(0x07111c, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x07111c, 9, 19);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
// ------------------------------------------------------------------
// Camera controls: intentionally implemented here, without addons.
// ------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(-0.15, 1.05, -0.05);
const desiredCamera = {
theta: 0.72,
phi: 1.1,
radius: 8.8
};
const currentCamera = {
theta: desiredCamera.theta,
phi: desiredCamera.phi,
radius: desiredCamera.radius
};
function resetCamera() {
desiredCamera.theta = 0.72;
desiredCamera.phi = 1.1;
desiredCamera.radius = 8.8;
}
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 9);
currentCamera.theta +=
(desiredCamera.theta - currentCamera.theta) * smoothing;
currentCamera.phi +=
(desiredCamera.phi - currentCamera.phi) * smoothing;
currentCamera.radius +=
(desiredCamera.radius - currentCamera.radius) * smoothing;
const sinPhi = Math.sin(currentCamera.phi);
camera.position.set(
cameraTarget.x +
currentCamera.radius * sinPhi * Math.sin(currentCamera.theta),
cameraTarget.y +
currentCamera.radius * Math.cos(currentCamera.phi),
cameraTarget.z +
currentCamera.radius * sinPhi * Math.cos(currentCamera.theta)
);
camera.lookAt(cameraTarget);
}
let dragging = false;
let previousPointer = { x: 0, y: 0 };
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer.x = event.clientX;
previousPointer.y = event.clientY;
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.5,
1.47
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius + event.deltaY * 0.006,
5.1,
13
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
desiredCamera.theta += 0.1;
break;
case "ArrowRight":
desiredCamera.theta -= 0.1;
break;
case "ArrowUp":
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - 0.08,
0.5,
1.47
);
break;
case "ArrowDown":
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi + 0.08,
0.5,
1.47
);
break;
case "+":
case "=":
desiredCamera.radius = Math.max(
5.1,
desiredCamera.radius - 0.5
);
break;
case "-":
desiredCamera.radius = Math.min(
13,
desiredCamera.radius + 0.5
);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
// ------------------------------------------------------------------
// Lighting and materials
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xbcefff,
0x172334,
1.8
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2dc, 3.2);
keyLight.position.set(-3.5, 7, 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 = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x56e6df, 1.25);
rimLight.position.set(5, 3.5, -4);
scene.add(rimLight);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xe5ecef,
roughness: 0.52,
metalness: 0.08
});
const bodyAlternateMaterial = new THREE.MeshStandardMaterial({
color: 0xaebec7,
roughness: 0.58,
metalness: 0.12
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0x526b7b,
roughness: 0.38,
metalness: 0.24
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x26394a,
roughness: 0.72,
metalness: 0.12
});
const cyanMaterial = new THREE.MeshBasicMaterial({
color: 0x56e6df,
transparent: true,
opacity: 0.82,
depthTest: false,
toneMapped: false
});
const amberMaterial = new THREE.MeshStandardMaterial({
color: 0xffbd66,
emissive: 0xa34d08,
emissiveIntensity: 0.8,
roughness: 0.38,
metalness: 0.1
});
const traceMaterial = new THREE.MeshBasicMaterial({
color: 0x8dc7d8,
transparent: true,
opacity: 0.52,
depthTest: false,
toneMapped: false
});
function makeBox(material, scale, position) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.copy(scale);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
// ------------------------------------------------------------------
// Voxel platform
// ------------------------------------------------------------------
const platform = new THREE.Group();
scene.add(platform);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x111e2b,
roughness: 0.84,
metalness: 0.08
});
platform.add(
makeBox(
baseMaterial,
new THREE.Vector3(9.35, 0.3, 6.35),
new THREE.Vector3(0, -0.24, 0)
)
);
const tileGeometry = new THREE.BoxGeometry(0.46, 0.08, 0.46);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0.03,
vertexColors: true
});
const columns = 19;
const rows = 13;
const tileCount = columns * rows;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount
);
const matrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = 0; z < rows; z++) {
for (let x = 0; x < columns; x++) {
const worldX = (x - (columns - 1) / 2) * 0.46;
const worldZ = (z - (rows - 1) / 2) * 0.46;
matrix.makeTranslation(worldX, -0.035, worldZ);
tiles.setMatrixAt(tileIndex, matrix);
const variation = Math.sin(x * 2.17 + z * 1.31) * 0.025;
tileColor.setHSL(0.57, 0.26, 0.13 + variation);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
tiles.receiveShadow = true;
platform.add(tiles);
// Distant voxel pylons add depth while preserving the block aesthetic.
const pylonPositions = [
[-3.85, -2.35],
[-2.85, -2.45],
[3.55, 2.25],
[3.9, 1.5]
];
for (const [x, z] of pylonPositions) {
const levels = 2 + ((Math.abs(x * z) | 0) % 3);
for (let i = 0; i < levels; i++) {
platform.add(
makeBox(
supportMaterial,
new THREE.Vector3(0.34, 0.34, 0.34),
new THREE.Vector3(x, 0.13 + i * 0.34, z)
)
);
}
}
// ------------------------------------------------------------------
// Stylized voxel arm
// ------------------------------------------------------------------
const arm = new THREE.Group();
scene.add(arm);
const shoulder = new THREE.Vector3(-2.55, 1.1, 0.35);
const elbowStart = new THREE.Vector3(-1.36, 0.58, 0.31);
const elbowEnd = new THREE.Vector3(-0.91, 1.15, 0.1);
const wristStart = new THREE.Vector3(-0.25, 0.78, 0.27);
const wristEnd = new THREE.Vector3(0.55, 1.78, -0.15);
const handStart = new THREE.Vector3(0.18, 1.01, 0.25);
const handEnd = new THREE.Vector3(1.47, 2.12, -0.38);
const targetPosition = new THREE.Vector3(1.76, 2.2, -0.44);
const elbow = elbowStart.clone();
const wrist = wristStart.clone();
const handTip = handStart.clone();
// Shoulder support.
arm.add(
makeBox(
supportMaterial,
new THREE.Vector3(0.88, 0.24, 0.82),
new THREE.Vector3(shoulder.x, 0.12, shoulder.z)
)
);
for (let i = 0; i < 3; i++) {
arm.add(
makeBox(
supportMaterial,
new THREE.Vector3(0.3, 0.3, 0.3),
new THREE.Vector3(
shoulder.x,
0.38 + i * 0.28,
shoulder.z
)
)
);
}
const shoulderJoint = makeBox(
jointMaterial,
new THREE.Vector3(0.43, 0.43, 0.43),
shoulder
);
arm.add(shoulderJoint);
const elbowJoint = makeBox(
jointMaterial,
new THREE.Vector3(0.34, 0.34, 0.34),
elbow
);
arm.add(elbowJoint);
const wristJoint = makeBox(
jointMaterial,
new THREE.Vector3(0.29, 0.29, 0.29),
wrist
);
arm.add(wristJoint);
function createLimbSegment(steps, cubeSize) {
const group = new THREE.Group();
const offset = cubeSize * 0.52;
for (let step = 0; step < steps; step++) {
const material =
step % 3 === 1 ? bodyAlternateMaterial : bodyMaterial;
for (const y of [-offset, offset]) {
for (const z of [-offset, offset]) {
const voxel = new THREE.Mesh(cubeGeometry, material);
voxel.scale.setScalar(cubeSize);
voxel.castShadow = true;
voxel.receiveShadow = true;
group.add(voxel);
}
}
}
arm.add(group);
return group;
}
const upperArm = createLimbSegment(9, 0.22);
const forearm = createLimbSegment(8, 0.2);
const xAxis = new THREE.Vector3(1, 0, 0);
const segmentDirection = new THREE.Vector3();
const segmentMidpoint = new THREE.Vector3();
function positionLimbSegment(group, start, end, steps, cubeSize) {
segmentDirection.subVectors(end, start);
const length = segmentDirection.length();
segmentMidpoint.copy(start).add(end).multiplyScalar(0.5);
group.position.copy(segmentMidpoint);
group.quaternion.setFromUnitVectors(
xAxis,
segmentDirection.normalize()
);
const stepLength = (length - cubeSize) / Math.max(1, steps - 1);
group.children.forEach((voxel, index) => {
const step = Math.floor(index / 4);
const corner = index % 4;
const offset = cubeSize * 0.52;
const localX =
-length / 2 + cubeSize / 2 + step * stepLength;
const localY = corner < 2 ? -offset : offset;
const localZ = corner % 2 === 0 ? -offset : offset;
voxel.position.set(localX, localY, localZ);
});
}
// Block-built hand, oriented along the wrist-to-fingertip direction.
const hand = new THREE.Group();
const palm = makeBox(
bodyMaterial,
new THREE.Vector3(0.34, 0.26, 0.3),
new THREE.Vector3(0.16, 0, 0)
);
hand.add(palm);
for (const z of [-0.09, 0, 0.09]) {
const finger = makeBox(
bodyAlternateMaterial,
new THREE.Vector3(
z === 0 ? 0.31 : 0.26,
0.085,
0.085
),
new THREE.Vector3(z === 0 ? 0.47 : 0.44, -0.025, z)
);
hand.add(finger);
}
arm.add(hand);
// ------------------------------------------------------------------
// External marked position
// ------------------------------------------------------------------
const targetGroup = new THREE.Group();
targetGroup.position.copy(targetPosition);
scene.add(targetGroup);
const bracketSize = 0.31;
for (const sx of [-1, 1]) {
for (const sy of [-1, 1]) {
targetGroup.add(
makeBox(
amberMaterial,
new THREE.Vector3(0.055, 0.2, 0.055),
new THREE.Vector3(
sx * bracketSize,
sy * (bracketSize - 0.07),
0
)
)
);
targetGroup.add(
makeBox(
amberMaterial,
new THREE.Vector3(0.18, 0.055, 0.055),
new THREE.Vector3(
sx * (bracketSize - 0.07),
sy * bracketSize,
0
)
)
);
}
}
const targetCore = makeBox(
amberMaterial,
new THREE.Vector3(0.15, 0.15, 0.15),
new THREE.Vector3(0, 0, 0)
);
targetGroup.add(targetCore);
const targetPulse = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(0.61, 0.61, 0.61)
),
new THREE.LineBasicMaterial({
color: 0xffbd66,
transparent: true,
opacity: 0.75,
depthTest: false,
toneMapped: false
})
);
targetPulse.renderOrder = 5;
targetGroup.add(targetPulse);
const beaconMaterial = new THREE.MeshBasicMaterial({
color: 0xffbd66,
transparent: true,
opacity: 0.34,
toneMapped: false
});
for (let i = 0; i < 6; i++) {
const beacon = new THREE.Mesh(cubeGeometry, beaconMaterial);
beacon.scale.setScalar(0.065);
beacon.position.set(0, -0.5 - i * 0.3, 0);
targetGroup.add(beacon);
}
const targetLight = new THREE.PointLight(0xffa743, 1.5, 4.5, 2);
targetGroup.add(targetLight);
// ------------------------------------------------------------------
// Conceptual internal feedback
// ------------------------------------------------------------------
const feedbackGroup = new THREE.Group();
scene.add(feedbackGroup);
const estimateCount = 30;
const estimateVoxels = [];
for (let i = 0; i < estimateCount; i++) {
const voxel = new THREE.Mesh(cubeGeometry, cyanMaterial);
voxel.scale.setScalar(0.055);
voxel.renderOrder = 8;
feedbackGroup.add(voxel);
estimateVoxels.push(voxel);
}
const feedbackFrames = [];
for (let i = 0; i < 3; i++) {
const frame = new THREE.LineSegments(
new THREE.EdgesGeometry(
new THREE.BoxGeometry(0.49, 0.49, 0.49)
),
new THREE.LineBasicMaterial({
color: 0x56e6df,
transparent: true,
opacity: 0.62,
depthTest: false,
toneMapped: false
})
);
frame.renderOrder = 8;
feedbackGroup.add(frame);
feedbackFrames.push(frame);
}
const packetMaterial = new THREE.MeshBasicMaterial({
color: 0xb8fffb,
transparent: true,
opacity: 0.95,
depthTest: false,
toneMapped: false
});
const packets = [];
for (let i = 0; i < 3; i++) {
const packet = new THREE.Mesh(cubeGeometry, packetMaterial);
packet.scale.setScalar(0.105);
packet.renderOrder = 9;
feedbackGroup.add(packet);
packets.push(packet);
}
// Optional dotted trace from the current fingertips to the marker.
const traceGroup = new THREE.Group();
scene.add(traceGroup);
const traceCount = 9;
const traceVoxels = [];
for (let i = 0; i < traceCount; i++) {
const voxel = new THREE.Mesh(cubeGeometry, traceMaterial);
voxel.scale.setScalar(0.058);
voxel.renderOrder = 7;
traceGroup.add(voxel);
traceVoxels.push(voxel);
}
const pathPoints = [
shoulder,
elbow,
wrist,
handTip
];
function samplePath(points, t, output) {
const lengths = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const length = points[i].distanceTo(points[i + 1]);
lengths.push(length);
total += length;
}
let distance = THREE.MathUtils.clamp(t, 0, 1) * total;
for (let i = 0; i < lengths.length; i++) {
if (distance <= lengths[i] || i === lengths.length - 1) {
const localT = lengths[i] === 0
? 0
: distance / lengths[i];
output.copy(points[i]).lerp(points[i + 1], localT);
return output;
}
distance -= lengths[i];
}
output.copy(points[points.length - 1]);
return output;
}
// ------------------------------------------------------------------
// UI controls
// ------------------------------------------------------------------
const internalToggle = document.querySelector("#internal-toggle");
const targetToggle = document.querySelector("#target-toggle");
const traceToggle = document.querySelector("#trace-toggle");
const toggleCuesButton = document.querySelector("#toggle-cues");
const replayButton = document.querySelector("#replay");
const statusText = document.querySelector("#status-text");
const hint = document.querySelector("#hint");
function applyCueVisibility() {
feedbackGroup.visible = internalToggle.checked;
targetGroup.visible = targetToggle.checked;
traceGroup.visible = traceToggle.checked;
const anyVisible =
internalToggle.checked ||
targetToggle.checked ||
traceToggle.checked;
toggleCuesButton.textContent = anyVisible
? "Hide all cues"
: "Show all cues";
}
internalToggle.addEventListener("change", applyCueVisibility);
targetToggle.addEventListener("change", applyCueVisibility);
traceToggle.addEventListener("change", applyCueVisibility);
toggleCuesButton.addEventListener("click", () => {
const anyVisible =
internalToggle.checked ||
targetToggle.checked ||
traceToggle.checked;
internalToggle.checked = !anyVisible;
targetToggle.checked = !anyVisible;
traceToggle.checked = !anyVisible;
applyCueVisibility();
});
let startTime = performance.now();
replayButton.addEventListener("click", () => {
startTime = performance.now();
});
applyCueVisibility();
// ------------------------------------------------------------------
// Projected HTML labels
// ------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-shoulder"),
position: shoulder,
visible: () => internalToggle.checked,
offsetX: -50,
offsetY: 25
},
{
element: document.querySelector("#label-elbow"),
position: elbow,
visible: () => internalToggle.checked,
offsetX: -54,
offsetY: 2
},
{
element: document.querySelector("#label-wrist"),
position: wrist,
visible: () => internalToggle.checked,
offsetX: -56,
offsetY: -28
},
{
element: document.querySelector("#label-target"),
position: targetPosition,
visible: () => targetToggle.checked,
offsetX: 45,
offsetY: -30
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
if (!label.visible()) {
label.element.style.display = "none";
continue;
}
projected.copy(label.position).project(camera);
const onScreen =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
if (!onScreen) {
label.element.style.display = "none";
continue;
}
const x =
(projected.x * 0.5 + 0.5) * window.innerWidth +
label.offsetX;
const y =
(-projected.y * 0.5 + 0.5) * window.innerHeight +
label.offsetY;
label.element.style.display = "block";
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// ------------------------------------------------------------------
// Resize
// ------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------------
// Animation
// ------------------------------------------------------------------
const clock = new THREE.Clock();
const sample = new THREE.Vector3();
const tracePoint = new THREE.Vector3();
let previousFrame = performance.now();
let hintFaded = false;
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function setStatus(text) {
if (statusText.textContent !== text) {
statusText.textContent = text;
}
}
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min((now - previousFrame) / 1000, 0.05);
previousFrame = now;
const elapsed = (now - startTime) / 1000;
const rawProgress = reducedMotion
? 1
: THREE.MathUtils.clamp((elapsed - 0.25) / 2.4, 0, 1);
const reachProgress = easeInOutCubic(rawProgress);
elbow.lerpVectors(elbowStart, elbowEnd, reachProgress);
wrist.lerpVectors(wristStart, wristEnd, reachProgress);
handTip.lerpVectors(handStart, handEnd, reachProgress);
if (!reducedMotion && elapsed > 2.65) {
const sway = Math.sin((elapsed - 2.65) * 1.15);
elbow.y += sway * 0.012;
wrist.y += Math.sin((elapsed - 2.65) * 1.15 + 0.45) * 0.016;
handTip.y += sway * 0.018;
}
positionLimbSegment(
upperArm,
shoulder,
elbow,
9,
0.22
);
positionLimbSegment(
forearm,
elbow,
wrist,
8,
0.2
);
elbowJoint.position.copy(elbow);
wristJoint.position.copy(wrist);
const handDirection = handTip.clone().sub(wrist).normalize();
hand.position.copy(wrist);
hand.quaternion.setFromUnitVectors(xAxis, handDirection);
pathPoints[0] = shoulder;
pathPoints[1] = elbow;
pathPoints[2] = wrist;
pathPoints[3] = handTip;
// Cyan estimate lattice.
estimateVoxels.forEach((voxel, index) => {
const t = index / (estimateCount - 1);
samplePath(pathPoints, t, sample);
voxel.position.copy(sample);
});
feedbackFrames[0].position.copy(shoulder);
feedbackFrames[1].position.copy(elbow);
feedbackFrames[2].position.copy(wrist);
feedbackFrames.forEach((frame, index) => {
const pulse = reducedMotion
? 1
: 1 + Math.sin(elapsed * 2.2 + index) * 0.055;
frame.scale.setScalar(pulse);
});
// Illustrative packets moving along the internal map.
packets.forEach((packet, index) => {
const t = reducedMotion
? 0.52
: (elapsed * 0.23 + index / packets.length) % 1;
samplePath(pathPoints, t, sample);
packet.position.copy(sample);
const packetPulse = reducedMotion
? 1
: 0.8 + Math.sin(elapsed * 5 + index * 2) * 0.25;
packet.scale.setScalar(0.105 * packetPulse);
});
// Dotted conceptual reach trace.
traceVoxels.forEach((voxel, index) => {
const t = (index + 1) / (traceCount + 1);
tracePoint.copy(handTip).lerp(targetPosition, t);
voxel.position.copy(tracePoint);
});
targetPulse.rotation.y = reducedMotion ? 0 : elapsed * 0.22;
const targetScale = reducedMotion
? 1
: 1 + Math.sin(elapsed * 2.4) * 0.065;
targetPulse.scale.setScalar(targetScale);
targetCore.rotation.x = reducedMotion ? 0 : elapsed * 0.55;
targetCore.rotation.y = reducedMotion ? 0 : elapsed * 0.75;
if (rawProgress < 0.22) {
setStatus("Orienting the limb");
} else if (rawProgress < 0.9) {
setStatus("Reaching toward the mark");
} else {
setStatus("Mark in perceptual alignment");
}
updateCamera(delta);
updateLabels();
if (!hintFaded && elapsed > 7) {
hint.style.opacity = "0";
hintFaded = true;
}
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```