Boot sequence
The app boots from src/main.ts. The module order matters: the diagnostics
logger is imported first so any boot-time error is captured.
src/main.ts
import './diag/logger'
import './brain-ui'
import './events'
import { scene, initRendering } from './scene'
import { createRenderer } from './renderer'
import { loadAllAssets } from './loaders'
import { createBrain } from './brain'
import { initGui } from './gui'
import { runLoop } from './run'
The async boot() function then runs:
src/main.ts
async function boot(): Promise<void> {
const { renderer, backend } = await createRenderer()
initRendering(renderer, backend)
const assets = await loadAllAssets()
const brain = await createBrain(assets, renderer, backend)
;(window as any).neuralNet = brain
console.log(`[EXEPERT Brain] Travel backend: ${brain.travelBackend}`)
const loadingEl = document.getElementById('loading')
if (loadingEl) loadingEl.style.display = 'none'
scene.add(brain.meshComponents)
initGui(brain)
runLoop(brain)
}
Step by step
- Diagnostics logger (
src/diag/logger.ts): imported first. It patchesconsole.*, installserror/unhandledrejectionhandlers, and mounts the floating panel. See Diagnostics Logger. - Renderer (
src/renderer.ts):createRenderer()returns aWebGLRendererand the'webgl2'backend tag. - Scene (
src/scene.ts):initRendering()attaches the canvas, sets up the camera,OrbitControls,Stats, helpers, and the on-canvas status bar. - Assets (
src/loaders.ts):loadAllAssets()loads the brain OBJ mesh and the electric sprite texture, returning the extracted vertices. - Brain (
src/brain.ts):createBrain()initializes the WASM module, constructs theWorldfrom the vertices, and builds the neuron, axon, and particle geometry bound to WASM memory. - Global handle: the
Brainis stashed onwindow.neuralNetfor the UI and any external integrations. - Scene attach + GUI: the brain meshes are added to the scene and
initGui()mounts the lil-gui panel. - Run loop:
runLoop(brain)starts therequestAnimationFrameloop.
If boot() rejects, the catch handler logs the error and hides the loading
overlay so the failure is visible rather than stuck on a spinner.