|
| 1 | +/* |
| 2 | +Toolbox Aid |
| 3 | +David Quesenberry |
| 4 | +04/16/2026 |
| 5 | +StressTest3DScene.js |
| 6 | +*/ |
| 7 | +import { Scene } from '/src/engine/scene/index.js'; |
| 8 | +import { Theme, ThemeTokens } from '/src/engine/theme/index.js'; |
| 9 | +import { drawFrame, drawPanel } from '/src/engine/debug/index.js'; |
| 10 | +import { |
| 11 | + applyPhase16CameraMode, |
| 12 | + createPhase16ViewState, |
| 13 | + createProjectionViewport, |
| 14 | + drawDepthBackdrop, |
| 15 | + drawGroundGrid, |
| 16 | + drawPhase16DebugOverlay, |
| 17 | + drawWireBox, |
| 18 | + stepPhase16ViewToggles, |
| 19 | +} from '../shared/threeDWireframe.js'; |
| 20 | + |
| 21 | +const theme = new Theme(ThemeTokens); |
| 22 | +const GRID_COLUMNS = 25; |
| 23 | +const GRID_ROWS = 40; |
| 24 | +const OBJECT_COUNT = GRID_COLUMNS * GRID_ROWS; |
| 25 | + |
| 26 | +export default class StressTest3DScene extends Scene { |
| 27 | + constructor() { |
| 28 | + super(); |
| 29 | + this.viewState = createPhase16ViewState(); |
| 30 | + this.viewport = { |
| 31 | + x: 40, |
| 32 | + y: 170, |
| 33 | + width: 860, |
| 34 | + height: 320, |
| 35 | + focalLength: 440, |
| 36 | + }; |
| 37 | + this.simTime = 0; |
| 38 | + this.cameraYaw = 0.48; |
| 39 | + this.waveSpeed = 1.5; |
| 40 | + this.waveAmplitude = 0.35; |
| 41 | + this.boxes = this.buildBoxes(); |
| 42 | + this.lastDrawCount = 0; |
| 43 | + } |
| 44 | + |
| 45 | + buildBoxes() { |
| 46 | + const boxes = []; |
| 47 | + const spacingX = 0.9; |
| 48 | + const spacingZ = 0.95; |
| 49 | + const startX = -((GRID_COLUMNS - 1) * spacingX) * 0.5; |
| 50 | + const startZ = 6; |
| 51 | + |
| 52 | + for (let row = 0; row < GRID_ROWS; row += 1) { |
| 53 | + for (let col = 0; col < GRID_COLUMNS; col += 1) { |
| 54 | + const index = row * GRID_COLUMNS + col; |
| 55 | + boxes.push({ |
| 56 | + x: startX + col * spacingX, |
| 57 | + y: -0.2, |
| 58 | + z: startZ + row * spacingZ, |
| 59 | + width: 0.55, |
| 60 | + height: 0.55, |
| 61 | + depth: 0.55, |
| 62 | + phase: index * 0.03, |
| 63 | + color: (row + col) % 3 === 0 ? '#38bdf8' : ((row + col) % 3 === 1 ? '#a78bfa' : '#34d399'), |
| 64 | + }); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + return boxes; |
| 69 | + } |
| 70 | + |
| 71 | + setCamera3D(camera3D) { |
| 72 | + this.camera3D = camera3D; |
| 73 | + this.syncCamera(); |
| 74 | + } |
| 75 | + |
| 76 | + syncCamera() { |
| 77 | + if (!this.camera3D) { |
| 78 | + return; |
| 79 | + } |
| 80 | + const focusPoint = { x: 0, y: 0.6, z: 24 }; |
| 81 | + const basePose = { |
| 82 | + position: { |
| 83 | + x: Math.sin(this.cameraYaw) * 22, |
| 84 | + y: 12.5, |
| 85 | + z: focusPoint.z - Math.cos(this.cameraYaw) * 23, |
| 86 | + }, |
| 87 | + rotation: { |
| 88 | + x: -0.52, |
| 89 | + y: this.cameraYaw, |
| 90 | + z: 0, |
| 91 | + }, |
| 92 | + }; |
| 93 | + applyPhase16CameraMode(this.camera3D, this.viewState, basePose, focusPoint); |
| 94 | + } |
| 95 | + |
| 96 | + step3DPhysics(dt, engine) { |
| 97 | + const input = engine.input; |
| 98 | + stepPhase16ViewToggles(this.viewState, input); |
| 99 | + if (input?.isDown('KeyQ')) this.cameraYaw -= 0.9 * dt; |
| 100 | + if (input?.isDown('KeyE')) this.cameraYaw += 0.9 * dt; |
| 101 | + if (input?.isDown('ArrowUp')) this.waveAmplitude = Math.min(0.8, this.waveAmplitude + 0.6 * dt); |
| 102 | + if (input?.isDown('ArrowDown')) this.waveAmplitude = Math.max(0.1, this.waveAmplitude - 0.6 * dt); |
| 103 | + |
| 104 | + this.simTime += dt; |
| 105 | + this.syncCamera(); |
| 106 | + } |
| 107 | + |
| 108 | + render(renderer) { |
| 109 | + drawFrame(renderer, theme, [ |
| 110 | + 'Sample 1612 - 3D Stress Test', |
| 111 | + 'Renders 1,000 animated wireframe objects to pressure 3D visibility throughput.', |
| 112 | + 'Wave amplitude: Up/Down | Orbit camera: Q/E | Camera mode: C | Debug: V', |
| 113 | + ]); |
| 114 | + |
| 115 | + renderer.strokeRect(this.viewport.x, this.viewport.y, this.viewport.width, this.viewport.height, '#d8d5ff', 2); |
| 116 | + drawDepthBackdrop(renderer, this.viewport); |
| 117 | + |
| 118 | + const cameraState = this.camera3D?.getState?.() ?? { |
| 119 | + position: { x: 10, y: 12, z: -4 }, |
| 120 | + rotation: { x: -0.52, y: this.cameraYaw, z: 0 }, |
| 121 | + }; |
| 122 | + const projectionViewport = createProjectionViewport(this.viewport); |
| 123 | + drawGroundGrid(renderer, { minX: -12, maxX: 12, minZ: 6, maxZ: 46, y: -0.2, step: 2 }, cameraState, projectionViewport); |
| 124 | + |
| 125 | + this.lastDrawCount = 0; |
| 126 | + for (let i = 0; i < this.boxes.length; i += 1) { |
| 127 | + const box = this.boxes[i]; |
| 128 | + const wave = Math.sin(this.simTime * this.waveSpeed + box.phase) * this.waveAmplitude; |
| 129 | + drawWireBox( |
| 130 | + renderer, |
| 131 | + { x: box.x, y: box.y + wave, z: box.z }, |
| 132 | + { width: box.width, height: box.height, depth: box.depth }, |
| 133 | + cameraState, |
| 134 | + projectionViewport, |
| 135 | + box.color, |
| 136 | + { lineWidth: 1.35, depthCueEnabled: true } |
| 137 | + ); |
| 138 | + this.lastDrawCount += 1; |
| 139 | + } |
| 140 | + |
| 141 | + drawPanel(renderer, 620, 34, 300, 176, 'Stress Runtime', [ |
| 142 | + `Objects configured: ${OBJECT_COUNT}`, |
| 143 | + `Objects drawn: ${this.lastDrawCount}`, |
| 144 | + `Grid: ${GRID_COLUMNS} x ${GRID_ROWS}`, |
| 145 | + `Wave speed: ${this.waveSpeed.toFixed(2)}`, |
| 146 | + `Wave amplitude: ${this.waveAmplitude.toFixed(2)}`, |
| 147 | + `Camera yaw: ${this.cameraYaw.toFixed(2)}`, |
| 148 | + ]); |
| 149 | + |
| 150 | + drawPhase16DebugOverlay(renderer, this.viewport, this.viewState, [ |
| 151 | + `Sim time: ${this.simTime.toFixed(2)} s`, |
| 152 | + 'Density profile: full-grid render each frame', |
| 153 | + ]); |
| 154 | + } |
| 155 | +} |
0 commit comments