FERRETGame engine over Babylon.js
Ferret

@ferret/game

createGame: wires platform, Babylon engine, scene, world, display, input and physics into a running game.

7 exports · source in packages/game/src

Functions

createGame function

function createGame(opts: GameOptions): Game

Wire the usual pieces for a game: platform (OS Beroun or browser), Babylon engine, scene, world, display (render scale, quality, FOV), input and physics. The game then adds its own services, levels and entities and calls start(). On OS Beroun the engine is made the way /lib/beroun-3d.js does it (the console's 640x480 at density 1, no antialiasing).

packages/game/src/index.ts:62

createGameAsync function

async function createGameAsync(opts: GameAsyncOptions): Promise<GameAsync>

createGame with the engine chosen at run time: WebGPU when asked for (gpu: 'webgpu' or ?gpu=webgpu) and the browser has an adapter, else the WebGL2 engine exactly as createGame makes it. A game runs unchanged on either. Never on OS Beroun (no WebGPU there).

packages/game/src/index.ts:87

Interfaces

Game interface

interface Game
engine: BABYLON.AbstractEngine
scene: BABYLON.Scene
world: World
host: SceneHostthe scene host: second worlds on the shared engine (a game's interlude during a travel)
platform: FerretPlatform
display: Display
input: InputService
physics: PhysicsService
touch?: TouchControls
quality?: QualityServicethe quality regulator (absent when quality: false)
xr?: XrServicethe VR session service, once loaded: only when xr was set and the browser has WebXR (the package is fetched then, not before)
xrReady: Promise<XrService | undefined>resolves when the VR service is added (or at once when it is not wanted)
start(): voidRun the render loop (and with it the fixed-step simulation).
stop(): void
dispose(): void

packages/game/src/index.ts:34

GameAsync interface

interface GameAsync extends Game
gpu: GpuMode
gpuNote?: string

packages/game/src/index.ts:81

GameAsyncOptions interface

interface GameAsyncOptions extends GameOptions
gpu?: GpuMode'webgpu' runs on WebGPU where the browser has an adapter (else WebGL2); default 'webgpu' with an automatic fall back to WebGL2 when the browser has no working WebGPU (scenes made before 2026-11-20 pin 'webgl2'), and ?gpu= on the page overrides it
twgslUrl?: stringwhere the WebGPU shader translator (twgsl.js and twgsl.wasm) is served from; default lib/twgsl/ beside the page
webgpuShaders?: 'glsl' | 'wgsl''glsl' (default): the engine's materials stay on GLSL, translated by twgsl, so Ferret's GLSL plugins and shaders work; 'wgsl': Babylon's native WGSL materials (the GLSL plugins then cannot attach)

packages/game/src/index.ts:73

GameOptions interface

interface GameOptions
canvas: HTMLCanvasElement
input: Omit<InputOptions, 'defaultKind'> & { defaultKind?: InputOptions['defaultKind'] }
platform?: FerretPlatform
storageKey?: stringkey for browser storage (one per game)
physicsLayers?: string[]
tier?: QualityTier
touchControls?: booleanTouch controls on phones and tablets (default true)
clearColor?: [number, number, number]
powerPreference?: 'high-performance' | 'low-power' | 'default'which graphics card the browser is asked for: 'high-performance' (the discrete one on a laptop; the default on desktops), 'low-power' (the integrated one; the default on phones, tablets and OS Beroun). A request only: the browser and the system may decide otherwise
fov?: { baseVertical?: number; minHorizontal?: number }the camera's field of view: the vertical one (radians) at wide aspects, and the horizontal one it never falls below (a game that matches another engine's 90 degrees passes both)
xr?: XrOptionsVR through WebXR: { enabled: true } adds the xr service where the browser has WebXR; elsewhere (OS Beroun) nothing is added
quality?: QualityOptions | falseThe quality regulator: on by default, it holds the frame rate (the headset's during a VR session, else targetHz, 60) by giving up the least visible quality of the side that holds the frame. false leaves it out. The page switch ?quality=off stops it, ?quality=high|medium|low fixes every knob at the top, the middle or the bottom of its range.

packages/game/src/index.ts:9

Types

GpuMode type

type GpuMode = 'webgl2' | 'webgpu'

the graphics API a game asks for: the page switch ?gpu=webgpu (or webgl2) wins over the option; the default is WebGPU with a fall back to WebGL2 (owner 2026-11-20); scenes made before that pin 'webgl2'

packages/game/src/index.ts:72