SceneAppController
An AppController derivative that wraps a SceneRenderer for convenient scene-based rendering. Handles the app lifecycle (init, frame, display) and automatically forwards all input events to the scene renderer.
This is the recommended approach for most applications — it automates init, render queue management and frame rendering.
import SceneAppController from "bg2e-js/ts/render/SceneAppController.js";
class MyApp extends SceneAppController { async init() { super.init(); // ← Always call super first
// Create scene, set environment and camera... }}Setup Pattern
Section titled “Setup Pattern”const canvas = new Canvas(canvasElem, new WebGLRenderer());canvas.domElement.style.width = "100vw";canvas.domElement.style.height = "100vh";
const appController = new MyApp();
const mainLoop = new MainLoop(canvas, appController);await mainLoop.run(); // FrameUpdate.AUTO by defaultMethods
Section titled “Methods”init() (Override this)
Section titled “init() (Override this)”The main initialization hook. Called after mainLoop.run() starts and before the first frame:
async init() { super.init(); // Load default shader (PBRLightIBL), load camera, load environment
const sceneRoot = this.createScene(); // ← Define your custom scene}This method:
- Sets default state on the renderer (
enableDepth,viewportsynced to canvas, clear color dark gray). - Binds key/mouse input handlers:
keydown,keyup,mousedown,mousemove,dragstart,wheel. - Initializes the scene renderer (load camera, load environment, set render root + cameras).