Skip to main content
Version: 0.2

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

  1. Diagnostics logger (src/diag/logger.ts): imported first. It patches console.*, installs error/unhandledrejection handlers, and mounts the floating panel. See Diagnostics Logger.
  2. Renderer (src/renderer.ts): createRenderer() returns a WebGLRenderer and the 'webgl2' backend tag.
  3. Scene (src/scene.ts): initRendering() attaches the canvas, sets up the camera, OrbitControls, Stats, helpers, and the on-canvas status bar.
  4. Assets (src/loaders.ts): loadAllAssets() loads the brain OBJ mesh and the electric sprite texture, returning the extracted vertices.
  5. Brain (src/brain.ts): createBrain() initializes the WASM module, constructs the World from the vertices, and builds the neuron, axon, and particle geometry bound to WASM memory.
  6. Global handle: the Brain is stashed on window.neuralNet for the UI and any external integrations.
  7. Scene attach + GUI: the brain meshes are added to the scene and initGui() mounts the lil-gui panel.
  8. Run loop: runLoop(brain) starts the requestAnimationFrame loop.

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.