The user wants a WebGL-based prototyping harness for:
- Previewing immersive interactions
- Measuring frame budgets (performance monitoring)
- Exporting accessibility annotations
This is a developer/designer tool, so I'll create a sophisticated single-page application with:
- WebGL Canvas - For rendering 3D interactive scenes
- Performance Monitor - Real-time frame budget tracking (FPS, frame time, GPU estimates)
- Interaction System - Click, hover, drag interactions in 3D space
- Accessibility Panel - Annotations for screen readers, ARIA labels export
- Export Functionality - JSON export of accessibility annotations
Design approach:
- Dark theme with high contrast (professional tool aesthetic)
- Multiple panels: Canvas area, Performance metrics, Interaction log, Accessibility annotations
- Animated elements: Floating particles, smooth transitions, glowing effects
- Real-time 3D scene with interactive objects
Let me build this comprehensive tool:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL Prototyping Harness</title>
<style>
/* Modern dark theme with accent colors */
</style>
</head>
<body>
<!-- Tool panels -->
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<script type="module">
// Three.js implementation
</script>
</body>
</html>
Key features to implement:
- 3D scene with multiple interactive objects
- Raycasting for mouse interaction
- Performance metrics panel (FPS, frame time, draw calls)
- Frame budget visualization
- Accessibility annotation system
- Export to JSON functionality
- Smooth animations and transitions
- Particle system for visual flair
Let me code this comprehensively.
WebGL Prototyping Harness Design
This is a comprehensive developer tool for:
- Immersive 3D Preview - Interactive WebGL scene with hover/click/drag interactions
- Performance Monitoring - Real-time FPS, frame budget, and render statistics
- Accessibility Export - Annotation system with JSON export capability
Key Features:
- Real-time frame budget visualization with color-coded warnings
- Interactive 3D objects with accessibility labels
- Performance threshold indicators
- Exportable accessibility annotations (ARIA-compatible)
- Floating particle background for visual polish
- Draggable camera controls
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebGL Prototyping Harness</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0d0d12;
--bg-secondary: #16161e;
--bg-tertiary: #1e1e28;
--accent-cyan: #00d4aa;
--accent-orange: #ff6b35;
--accent-purple: #8b5cf6;
--text-primary: #f0f0f5;
--text-secondary: #9898a6;
--border-color: #2a2a38;
--success: #22c55e;
--warning: #f59e0b;
--danger: #ef4444;
}
body {
font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
background: var(--bg-primary);
color: var(--text-primary);
overflow: hidden;
height: 100vh;
}
.app-container {
display: grid;
grid-template-columns: 1fr 320px;
grid-template-rows: 56px 1fr;
height: 100vh;
gap: 1px;
background: var(--border-color);
}
.header {
grid-column: 1 / -1;
background: var(--bg-secondary);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 20px;
border-bottom: 1px solid var(--border-color);
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 32px;
height: 32px;
background: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
.logo-icon svg {
width: 18px;
height: 18px;
fill: var(--bg-primary);
}
.logo-text {
font-size: 14px;
font-weight: 600;
letter-spacing: 0.5px;
}
.header-actions {
display: flex;
gap: 12px;
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 6px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
font-family: inherit;
display: flex;
align-items: center;
gap: 6px;
}
.btn-primary {
background: var(--accent-cyan);
color: var(--bg-primary);
}
.btn-primary:hover {
background: #00eebb;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0, 212, 170, 0.3);
}
.btn-secondary {
background: var(--bg-tertiary);
color: var(--text-primary);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background: #282834;
border-color: var(--accent-cyan);
}
.canvas-container {
background: var(--bg-primary);
position: relative;
overflow: hidden;
}
#webgl-canvas {
display: block;
width: 100%;
height: 100%;
}
.canvas-overlay {
position: absolute;
top: 16px;
left: 16px;
display: flex;
flex-direction: column;
gap: 8px;
pointer-events: none;
}
.interaction-hint {
background: rgba(22, 22, 30, 0.9);
backdrop-filter: blur(8px);
padding: 8px 12px;
border-radius: 6px;
font-size: 11px;
color: var(--text-secondary);
border: 1px solid var(--border-color);
}
.interaction-hint strong {
color: var(--accent-cyan);
}
.fps-badge {
position: absolute;
top: 16px;
right: 16px;
background: rgba(22, 22, 30, 0.9);
backdrop-filter: blur(8px);
padding: 8px 14px;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
border: 1px solid var(--border-color);
}
.fps-badge.good { color: var(--success); border-color: var(--success); }
.fps-badge.warn { color: var(--warning); border-color: var(--warning); }
.fps-badge.bad { color: var(--danger); border-color: var(--danger); }
.sidebar {
background: var(--bg-secondary);
display: flex;
flex-direction: column;
overflow: hidden;
}
.panel {
border-bottom: 1px solid var(--border-color);
}
.panel-header {
padding: 14px 16px;
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
transition: background 0.2s;
}
.panel-header:hover {
background: var(--bg-tertiary);
}
.panel-title {
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-secondary);
}
.panel-toggle {
width: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
color: var(--text-secondary);
transition: transform 0.3s;
}
.panel.collapsed .panel-toggle {
transform: rotate(-90deg);
}
.panel-content {
padding: 0 16px 16px;
display: flex;
flex-direction: column;
gap: 12px;
max-height: 400px;
overflow-y: auto;
}
.panel.collapsed .panel-content {
display: none;
}
.metric-row {
display: flex;
justify-content: space-between;
align-items: center;
}
.metric-label {
font-size: 12px;
color: var(--text-secondary);
}
.metric-value {
font-size: 13px;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.metric-bar {
height: 4px;
background: var(--bg-tertiary);
border-radius: 2px;
overflow: hidden;
margin-top: 6px;
}
.metric-bar-fill {
height: 100%;
border-radius: 2px;
transition: width 0.3s, background 0.3s;
}
.frame-budget {
background: var(--bg-tertiary);
border-radius: 8px;
padding: 12px;
}
.budget-header {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}
.budget-time {
font-size: 20px;
font-weight: 700;
}
.budget-target {
font-size: 11px;
color: var(--text-secondary);
display: flex;
align-items: center;
gap: 4px;
}
.budget-visual {
height: 24px;
background: var(--bg-primary);
border-radius: 4px;
position: relative;
overflow: hidden;
}
.budget-fill {
height: 100%;
border-radius: 4px;
position: relative;
transition: width 0.2s;
}
.budget-marker {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background: var(--text-secondary);
opacity: 0.5;
}
.annotation-item {
background: var(--bg-tertiary);
border-radius: 8px;
padding: 12px;
border-left: 3px solid var(--accent-purple);
}
.annotation-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.annotation-type {
font-size: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--accent-purple);
}
.annotation-id {
font-size: 10px;
color: var(--text-secondary);
}
.annotation-label {
font-size: 13px;
font-weight: 500;
margin-bottom: 4px;
}
.annotation-desc {
font-size: 11px;
color: var(--text-secondary);
line-height: 1.5;
}
.annotation-role {
display: inline-block;
margin-top: 8px;
padding: 3px 8px;
background: var(--bg-primary);
border-radius: 4px;
font-size: 10px;
color: var(--accent-cyan);
}
.log-item {
display: flex;
gap: 10px;
padding: 8px;
background: var(--bg-tertiary);
border-radius: 6px;
font-size: 11px;
}
.log-time {
color: var(--text-secondary);
white-space: nowrap;
}
.log-event {
color: var(--accent-cyan);
}
.log-event.hover { color: var(--accent-orange); }
.log-event.click { color: var(--accent-cyan); }
.log-event.drag { color: var(--accent-purple); }
.empty-state {
text-align: center;
padding: 24px;
color: var(--text-secondary);
font-size: 12px;
}
.scrollbar-thin::-webkit-scrollbar {
width: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
background: transparent;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
background: var(--border-color);
border-radius: 3px;
}
.tooltip {
position: absolute;
background: var(--bg-secondary);
border: 1px solid var(--accent-cyan);
padding: 8px 12px;
border-radius: 6px;
font-size: 12px;
pointer-events: none;
opacity: 0;
transition: opacity 0.2s;
z-index: 100;
max-width: 200px;
}
.tooltip.visible {
opacity: 1;
}
.tooltip-title {
font-weight: 600;
margin-bottom: 4px;
}
.tooltip-desc {
color: var(--text-secondary);
font-size: 11px;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.recording {
animation: pulse 1s infinite;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--success);
}
.status-dot.active {
animation: pulse 1s infinite;
}
</style>
</head>
<body>
<div class="app-container">
<header class="header">
<div class="logo">
<div class="logo-icon">
<svg viewBox="0 0 24 24"><path d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/></svg>
</div>
<span class="logo-text">WebGL Prototyping Harness</span>
</div>
<div class="header-actions">
<button class="btn btn-secondary" id="clearLog">Clear Log</button>
<button class="btn btn-primary" id="exportBtn">Export Annotations</button>
</div>
</header>
<main class="canvas-container">
<canvas id="webgl-canvas"></canvas>
<div class="canvas-overlay">
<div class="interaction-hint"><strong>Click</strong> objects to select</div>
<div class="interaction-hint"><strong>Drag</strong> to rotate camera</div>
<div class="interaction-hint"><strong>Scroll</strong> to zoom</div>
</div>
<div class="fps-badge good" id="fpsBadge">60 FPS</div>
<div class="tooltip" id="tooltip">
<div class="tooltip-title"></div>
<div class="tooltip-desc"></div>
</div>
</main>
<aside class="sidebar">
<div class="panel" id="performancePanel">
<div class="panel-header">
<span class="panel-title">Performance Metrics</span>
<span class="panel-toggle">▼</span>
</div>
<div class="panel-content scrollbar-thin">
<div class="frame-budget">
<div class="budget-header">
<span class="budget-time" id="frameTime">0.00ms</span>
<span class="budget-target">Target: 16.67ms (60fps)</span>
</div>
<div class="budget-visual">
<div class="budget-fill" id="budgetFill"></div>
<div class="budget-marker" style="left: 60%;"></div>
</div>
</div>
<div class="metric-row">
<span class="metric-label">Frames Per Second</span>
<span class="metric-value" id="fpsValue">0</span>
</div>
<div class="metric-bar">
<div class="metric-bar-fill" id="fpsBar" style="width: 0%; background: var(--success);"></div>
</div>
<div class="metric-row">
<span class="metric-label">Draw Calls</span>
<span class="metric-value" id="drawCalls">0</span>
</div>
<div class="metric-row">
<span class="metric-label">Triangles</span>
<span class="metric-value" id="triangles">0</span>
</div>
<div class="metric-row">
<span class="metric-label">Memory (MB)</span>
<span class="metric-value" id="memory">0</span>
</div>
<div class="metric-row">
<span class="metric-label">GPU Estimate</span>
<span class="metric-value" id="gpuEstimate">--</span>
</div>
</div>
</div>
<div class="panel" id="annotationsPanel">
<div class="panel-header">
<span class="panel-title">Accessibility Annotations</span>
<span class="panel-toggle">▼</span>
</div>
<div class="panel-content scrollbar-thin" id="annotationsList">
<!-- Populated by JS -->
</div>
</div>
<div class="panel" id="logPanel">
<div class="panel-header">
<span class="panel-title">Interaction Log</span>
<span class="panel-toggle">▼</span>
</div>
<div class="panel-content scrollbar-thin" id="logList">
<div class="empty-state">No interactions recorded</div>
</div>
</div>
</aside>
</div>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
// Accessibility annotations data
const accessibilityAnnotations = [
{
id: 'obj-001',
type: 'Interactive Element',
label: 'Primary Action Button',
description: 'Main CTA for user activation. Triggers form submission.',
role: 'button',
tabIndex: 0,
ariaLabel: 'Submit form and continue to next step'
},
{
id: 'obj-002',
type: 'Information Display',
label: 'Data Visualization Sphere',
description: 'Represents quantitative data through size and color mapping.',
role: 'img',
ariaLabel: 'Chart showing 78% completion rate'
},
{
id: 'obj-003',
type: 'Navigation Control',
label: 'Menu Toggle',
description: 'Expands navigation drawer when activated.',
role: 'menuitem',
tabIndex: 0,
ariaLabel: 'Open main navigation menu'
},
{
id: 'obj-004',
type: 'Status Indicator',
label: 'Progress Indicator',
description: 'Shows current operation status and completion percentage.',
role: 'progressbar',
ariaLabel: 'Loading progress at 45 percent'
},
{
id: 'obj-005',
type: 'Interactive Element',
label: 'Settings Control',
description: 'Opens configuration panel for user preferences.',
role: 'button',
tabIndex: 0,
ariaLabel: 'Open settings panel'
}
];
// State
const state = {
fps: 0,
frameTime: 0,
frames: 0,
lastTime: performance.now(),
interactionLog: [],
selectedObject: null
};
// DOM Elements
const canvas = document.getElementById('webgl-canvas');
const fpsBadge = document.getElementById('fpsBadge');
const frameTimeEl = document.getElementById('frameTime');
const budgetFill = document.getElementById('budgetFill');
const fpsValue = document.getElementById('fpsValue');
const fpsBar = document.getElementById('fpsBar');
const drawCallsEl = document.getElementById('drawCalls');
const trianglesEl = document.getElementById('triangles');
const memoryEl = document.getElementById('memory');
const gpuEstimateEl = document.getElementById('gpuEstimate');
const annotationsList = document.getElementById('annotationsList');
const logList = document.getElementById('logList');
const tooltip = document.getElementById('tooltip');
// Three.js Setup
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d0d12);
const camera = new THREE.PerspectiveCamera(60, canvas.clientWidth / canvas.clientHeight, 0.1, 1000);
camera.position.set(0, 2, 8);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: 'high-performance'
});
renderer.setSize(canvas.clientWidth, canvas.clientHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Controls
const controls = new OrbitControls(camera, canvas);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
controls.maxDistance = 20;
controls.minDistance = 3;
// Raycaster
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(5, 10, 5);
scene.add(directionalLight);
const pointLight1 = new THREE.PointLight(0x00d4aa, 1, 15);
pointLight1.position.set(-4, 3, 2);
scene.add(pointLight1);
const pointLight2 = new THREE.PointLight(0xff6b35, 0.8, 15);
pointLight2.position.set(4, -2, 3);
scene.add(pointLight2);
// Interactive objects
const interactiveObjects = [];
// Create materials
const materials = {
cyan: new THREE.MeshStandardMaterial({
color: 0x00d4aa,
metalness: 0.3,
roughness: 0.4,
emissive: 0x00d4aa,
emissiveIntensity: 0.1
}),
orange: new THREE.MeshStandardMaterial({
color: 0xff6b35,
metalness: 0.3,
roughness: 0.4,
emissive: 0xff6b35,
emissiveIntensity: 0.1
}),
purple: new THREE.MeshStandardMaterial({
color: 0x8b5cf6,
metalness: 0.3,
roughness: 0.4,
emissive: 0x8b5cf6,
emissiveIntensity: 0.1
}),
white: new THREE.MeshStandardMaterial({
color: 0xf0f0f5,
metalness: 0.5,
roughness: 0.2
})
};
// Object 1: Main button
const buttonGeom = new THREE.BoxGeometry(1.5, 0.6, 0.3);
const buttonMesh = new THREE.Mesh(buttonGeom, materials.cyan.clone());
buttonMesh.position.set(-2.5, 0, 0);
buttonMesh.userData = {
annotationId: 'obj-001',
originalColor: 0x00d4aa,
label: 'Primary Action Button'
};
scene.add(buttonMesh);
interactiveObjects.push(buttonMesh);
// Object 2: Data sphere
const sphereGeom = new THREE.SphereGeometry(0.8, 32, 32);
const sphereMesh = new THREE.Mesh(sphereGeom, materials.orange.clone());
sphereMesh.position.set(0, 0, 0);
sphereMesh.userData = {
annotationId: 'obj-002',
originalColor: 0xff6b35,
label: 'Data Visualization Sphere'
};
scene.add(sphereMesh);
interactiveObjects.push(sphereMesh);
// Object 3: Menu toggle (torus)
const torusGeom = new THREE.TorusGeometry(0.5, 0.2, 16, 32);
const torusMesh = new THREE.Mesh(torusGeom, materials.purple.clone());
torusMesh.position.set(2.5, 0, 0);
torusMesh.userData = {
annotationId: 'obj-003',
originalColor: 0x8b5cf6,
label: 'Menu Toggle'
};
scene.add(torusMesh);
interactiveObjects.push(torusMesh);
// Object 4: Progress indicator (cylinder)
const cylinderGeom = new THREE.CylinderGeometry(0.4, 0.4, 1.2, 32);
const cylinderMesh = new THREE.Mesh(cylinderGeom, materials.white.clone());
cylinderMesh.position.set(-2.5, -2, 0);
cylinderMesh.userData = {
annotationId: 'obj-004',
originalColor: 0xf0f0f5,
label: 'Progress Indicator'
};
scene.add(cylinderMesh);
interactiveObjects.push(cylinderMesh);
// Object 5: Settings (dodecahedron)
const dodecaGeom = new THREE.DodecahedronGeometry(0.6);
const dodecaMesh = new THREE.Mesh(dodecaGeom, materials.cyan.clone());
dodecaMesh.position.set(2.5, -2, 0);
dodecaMesh.userData = {
annotationId: 'obj-005',
originalColor: 0x00d4aa,
label: 'Settings Control'
};
scene.add(dodecaMesh);
interactiveObjects.push(dodecaMesh);
// Particle system for background
const particleCount = 300;
const particlePositions = new Float32Array(particleCount * 3);
const particleSizes = new Float32Array(particleCount);
for (let i = 0; i < particleCount; i++) {
particlePositions[i * 3] = (Math.random() - 0.5) * 30;
particlePositions[i * 3 + 1] = (Math.random() - 0.5) * 20;
particlePositions[i * 3 + 2] = (Math.random() - 0.5) * 20 - 5;
particleSizes[i] = Math.random() * 3 + 1;
}
const particleGeom = new THREE.BufferGeometry();
particleGeom.setAttribute('position', new THREE.BufferAttribute(particlePositions, 3));
particleGeom.setAttribute('aSize', new THREE.BufferAttribute(particleSizes, 1));
const particleMaterial = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uColor: { value: new THREE.Color(0x00d4aa) }
},
vertexShader: `
attribute float aSize;
uniform float uTime;
varying float vAlpha;
void main() {
vec3 pos = position;
pos.y += sin(uTime * 0.5 + position.x) * 0.3;
pos.x += cos(uTime * 0.3 + position.z) * 0.2;
vec4 mvPosition = modelViewMatrix * vec4(pos, 1.0);
gl_Position = projectionMatrix * mvPosition;
gl_PointSize = aSize * (100.0 / -mvPosition.z);
vAlpha = 0.3 + 0.3 * sin(uTime + position.x * 0.5);
}
`,
fragmentShader: `
uniform vec3 uColor;
varying float vAlpha;
void main() {
float dist = length(gl_PointCoord - vec2(0.5));
if (dist > 0.5) discard;
float alpha = vAlpha * (1.0 - dist * 2.0);
gl_FragColor = vec4(uColor, alpha);
}
`,
transparent: true,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const particles = new THREE.Points(particleGeom, particleMaterial);
scene.add(particles);
// Grid helper
const gridHelper = new THREE.GridHelper(20, 20, 0x2a2a38, 0x1e1e28);
gridHelper.position.y = -3;
scene.add(gridHelper);
// Render annotations list
function renderAnnotations() {
annotationsList.innerHTML = accessibilityAnnotations.map(ann => `
<div class="annotation-item" data-id="${ann.id}">
<div class="annotation-header">
<span class="annotation-type">${ann.type}</span>
<span class="annotation-id">${ann.id}</span>
</div>
<div class="annotation-label">${ann.label}</div>
<div class="annotation-desc">${ann.description}</div>
<span class="annotation-role">role: ${ann.role}</span>
</div>
`).join('');
}
// Log interaction
function logInteraction(type, target) {
const time = new Date().toLocaleTimeString();
const entry = { time, type, target };
state.interactionLog.unshift(entry);
if (state.interactionLog.length > 20) {
state.interactionLog.pop();
}
updateLogDisplay();
}
function updateLogDisplay() {
if (state.interactionLog.length === 0) {
logList.innerHTML = '<div class="empty-state">No interactions recorded</div>';
return;
}
logList.innerHTML = state.interactionLog.map(log => `
<div class="log-item">
<span class="log-time">${log.time}</span>
<span class="log-event ${log.type}">${log.type.toUpperCase()}</span>
<span>${log.target}</span>
</div>
`).join('');
}
// Mouse events
let hoveredObject = null;
canvas.addEventListener('mousemove', (e) => {
const rect = canvas.getBoundingClientRect();
mouse.x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
mouse.y = -((e.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObjects(interactiveObjects);
if (intersects.length > 0) {
const obj = intersects[0].object;
if (hoveredObject !== obj) {
if (hoveredObject) {
hoveredObject.material.emissiveIntensity = 0.1;
hoveredObject.scale.setScalar(1);
}
hoveredObject = obj;
obj.material.emissiveIntensity = 0.4;
obj.scale.setScalar(1.1);
logInteraction('hover', obj.userData.label);
}
// Show tooltip
const ann = accessibilityAnnotations.find(a => a.id === obj.userData.annotationId);
if (ann) {
tooltip.querySelector('.tooltip-title').textContent = ann.label;
tooltip.querySelector('.tooltip-desc').textContent = ann.description;
tooltip.style.left = `${e.clientX - canvas.parentElement.offsetLeft + 15}px`;
tooltip.style.top = `${e.clientY - 70}px`;
tooltip.classList.add('visible');
}
canvas.style.cursor = 'pointer';
} else {
if (hoveredObject) {
hoveredObject.material.emissiveIntensity = 0.1;
hoveredObject.scale.setScalar(1);
hoveredObject = null;
}
tooltip.classList.remove('visible');
canvas.style.cursor = 'grab';
}
});
canvas.addEventListener('click', (e) => {
if (hoveredObject) {
state.selectedObject = hoveredObject;
logInteraction('click', hoveredObject.userData.label);
// Visual feedback
const originalScale = hoveredObject.scale.x;
hoveredObject.scale.setScalar(1.3);
setTimeout(() => {
hoveredObject.scale.setScalar(originalScale);
}, 150);
// Highlight annotation
document.querySelectorAll('.annotation-item').forEach(el => {
el.style.borderLeftColor = el.dataset.id === hoveredObject.userData.annotationId
? 'var(--accent-cyan)'
: 'var(--accent-purple)';
});
}
});
// Performance tracking
let lastFrameTime = performance.now();
const frameTimes = [];
function updatePerformance() {
const now = performance.now();
const delta = now - lastFrameTime;
lastFrameTime = now;
frameTimes.push(delta);
if (frameTimes.length > 60) frameTimes.shift();
const avgFrameTime = frameTimes.reduce((a, b) => a + b, 0) / frameTimes.length;
const fps = Math.round(1000 / avgFrameTime);
const safeFrameTime = Number.isFinite(avgFrameTime) ? Math.max(0, avgFrameTime) : 0;
state.fps = fps;
state.frameTime = safeFrameTime;
// Update UI
frameTimeEl.textContent = `${safeFrameTime.toFixed(2)}ms`;
fpsValue.textContent = fps;
fpsBadge.textContent = `${fps} FPS`;
const budgetPercent = Math.min((safeFrameTime / 16.67) * 100, 100);
const clampedPercent = Number.isFinite(budgetPercent) ? Math.max(0, Math.min(100, budgetPercent)) : 0;
budgetFill.style.width = `${clampedPercent}%`;
let barColor = 'var(--success)';
let badgeClass = 'good';
if (safeFrameTime > 16.67) {
barColor = 'var(--danger)';
badgeClass = 'bad';
} else if (safeFrameTime > 12) {
barColor = 'var(--warning)';
badgeClass = 'warn';
}
budgetFill.style.background = barColor;
fpsBar.style.width = `${Math.min(fps / 60 * 100, 100)}%`;
fpsBar.style.background = barColor;
fpsBadge.className = `fps-badge ${badgeClass}`;
// Renderer info
const info = renderer.info;
drawCallsEl.textContent = info.render.calls;
trianglesEl.textContent = info.render.triangles.toLocaleString();
// Memory (if available)
if (performance.memory) {
const mb = (performance.memory.usedJSHeapSize / 1048576).toFixed(1);
memoryEl.textContent = mb;
} else {
memoryEl.textContent = 'N/A';
}
// GPU estimate
const gpuTime = (safeFrameTime * 0.6).toFixed(2);
gpuEstimateEl.textContent = `~${gpuTime}ms`;
}
// Animation loop
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Update particle system
particleMaterial.uniforms.uTime.value = elapsed;
// Animate objects
interactiveObjects.forEach((obj, i) => {
obj.rotation.y = elapsed * 0.3 + i;
obj.position.y = Math.sin(elapsed + i * 1.5) * 0.2 + (obj.position.y > -1 ? 0 : -2);
});
// Animate lights
pointLight1.position.x = Math.sin(elapsed * 0.5) * 4;
pointLight2.position.z = Math.cos(elapsed * 0.3) * 4;
controls.update();
renderer.render(scene, camera);
updatePerformance();
}
// Export functionality
document.getElementById('exportBtn').addEventListener('click', () => {
const exportData = {
metadata: {
exportedAt: new Date().toISOString(),
tool: 'WebGL Prototyping Harness',
version: '1.0.0'
},
scene: {
objects: interactiveObjects.map(obj => ({
id: obj.userData.annotationId,
position: obj.position.toArray(),
rotation: obj.rotation.toArray().slice(0, 3),
scale: obj.scale.toArray()
}))
},
accessibility: accessibilityAnnotations,
performance: {
averageFPS: state.fps,
averageFrameTime: state.frameTime,
recommendations: state.frameTime > 16.67
? ['Consider reducing draw calls', 'Optimize shader complexity', 'Use instancing for repeated geometries']
: ['Performance within acceptable range']
},
interactionLog: state.interactionLog
};
const blob = new Blob([JSON.stringify(exportData, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `webgl-prototype-${Date.now()}.json`;
a.click();
URL.revokeObjectURL(url);
logInteraction('click', 'Export Button');
});
// Clear log
document.getElementById('clearLog').addEventListener('click', () => {
state.interactionLog = [];
updateLogDisplay();
});
// Panel toggles
document.querySelectorAll('.panel-header').forEach(header => {
header.addEventListener('click', () => {
header.parentElement.classList.toggle('collapsed');
});
});
// Resize handler
function onResize() {
const container = canvas.parentElement;
const width = container.clientWidth;
const height = container.clientHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
}
window.addEventListener('resize', onResize);
// Initialize
renderAnnotations();
animate();
</script>
</body>
</html>
How to Use This Tool:
Immersive Interactions
- Hover over 3D objects to see tooltips and highlight effects
- Click objects to select them and highlight their annotation
- Drag to rotate the camera view
- Scroll to zoom in/out
Performance Monitoring
- Real-time FPS counter with color-coded status (green/yellow/red)
- Frame budget visualization showing time vs 16.67ms target
- Draw calls and triangle count from WebGL renderer
- Memory usage and GPU time estimates
Accessibility Annotations
- Each interactive object has associated ARIA-compatible metadata
- View role, label, description, and tabIndex information
- Click export to download complete JSON with accessibility data
Export
Click "Export Annotations" to download a comprehensive JSON file containing:
- All accessibility annotations with ARIA attributes
- Scene object positions and transforms
- Performance metrics and recommendations
- Interaction log history