Small World Engine is the "Preact of 3D Engines". It is an ultra-lightweight, high-performance, and strict TypeScript 3D game engine for the web. Built for the era of WebGPU and Playable Ads, it provides a modern Physically Based Rendering (PBR) pipeline and a robust Behavior System—delivering the architectural elegance of a real game engine at a fraction of the bundle size of traditional frameworks.
Read our full Vision & Strategy (VISION.md).
OrbitController, FPSController, ZoomController) are standard Behavior components attached via camera.addBehavior(). Features procedural effects like camera shake and flash.MathPool), BindGroup & Pipeline Caching (WebGPU), and zero-allocation hot paths to eliminate Garbage Collection pressure.FlickerBehavior, PulsatingBehavior, ProximitySensorBehavior, RainbowBehavior, BobbingBehavior, RotatorBehavior, HoverBehavior, DraggableBehavior, etc.) directly to 3D objects, cameras, or materials. Includes a built-in, type-safe, zero-allocation Finite State Machine (FSM) framework (StateMachine & StateMachineBehavior) to cleanly manage game actor lifecycles.InteractionManager allowing objects to instantly react to mouse/touch pointer events (onPointerEnter, onPointerClick, onPointerDown, onPointerMove, etc.). Pickable elements are queried via highly performant $O(\log n)$ Octrees and resolved to exact pixels via the Möller-Trumbore intersection algorithm.Object3D architecture.Texture.fromUrl()).glMatrix. Small World features a bespoke, highly-optimized mathematics library for vectors and matrices, tailored exactly for our right-handed coordinate system.frustum.intersectsVolume(obj.bounds)), Scene Graph, and Resource Management—entirely from scratch. This keeps the footprint tiny and performance at the absolute maximum.Install the package via NPM:
npm install small-world
The engine provides an Application base class that handles the render loop and hardware initialization automatically.
small-world.json)By default, the engine looks for a configuration file at /config/small-world.json.
{
"canvasId": "SmallWorld",
"rendererType": "BEST",
"projection": "PERSPECTIVE",
"fullscreen": true,
"renderer": [
{
"type": "WEB_GPU",
"attributes": { "antialias": true }
}
]
}
import { Application, Cube, Color, StandardMaterial, Object3D, OrbitController, ZoomController, Texture } from "small-world";
class MyGame extends Application {
protected async setupScene(): Promise<void> {
// 1. Load a texture and create a PBR material
const albedoTex = await Texture.fromUrl("./assets/textures/diffuse.png");
const geometry = new Cube({ size: 2 }).getGeometryData();
const material = new StandardMaterial({
map: albedoTex,
color: Color.DODGERBLUE,
metallic: 0.7,
roughness: 0.2,
});
// 2. Wrap in an Object3D and add to scene
const cube = new Object3D("MyCube");
cube.geometry = geometry;
cube.material = material;
cube.position.set(0, 1, 0);
this.scene.add(cube);
// 3. Configure the camera and attach behaviors (controllers)
this.camera.position.set(5, 5, 5);
this.camera.target.set(0, 0, 0);
// Camera controllers are now behaviors!
this.camera.addBehavior(new OrbitController());
this.camera.addBehavior(new ZoomController());
}
protected override update(deltaTime: number): void {
// Logic executed every frame
}
}
// Start the application
const game = new MyGame();
game.start();
.nvmrc. If you use nvm, simply run nvm use in the root directory.npm install
npm run dev
npm run build:lib
For an isolated development environment, this project includes a Dev Container configuration for VS Code.
src/core: Core engine logic (Application, Object3D, Scene, Input, Color).src/core/behaviors: Modular runtime behavior components (e.g. Proximity Sensors, Oscillators).src/core/cameras: Camera strategies, projections, effects, and modular controllers.src/core/fsm: Type-safe, zero-allocation Finite State Machine utility.src/core/materials: Material definitions and PBR shader assets.src/core/lights: Light source implementations (Standard & PBR).src/geometry: Geometric primitives and terrain logic.src/math: Linear algebra, vectors, matrices, and object pooling.src/loaders: Asset loading pipeline (OBJ, MTL, Textures).src/renderers: Implementation of WebGL1, WebGL2, and WebGPU backends.
src/core/renderers/shaders/source: Core shader assets directly bundled with the engine.examples: Interactive functional showcases showcasing engine capabilities.public/engine: Static assets including models, textures, and levels used across examples.The engine includes several browser-based tools to help generate assets directly on the client side without relying on external software:
public/tools/pbr-gen.html): Generate Normal, Specular, AO, and Height maps from a single diffuse image.public/tools/splatter-gen.html): Generate procedural splatters and decals.public/tools/ibl-gen.html): Generate Image-Based Lighting (Irradiance and Radiance) environment maps.This project uses TypeDoc for automated API reference generation and VitePress for developer guides and tutorials.
Generate API Reference:
npm run docs:api
This automatically extracts all classes, interfaces, and methods from the TypeScript source and generates a static HTML site under docs/public/api.
Start the VitePress Dev Server:
npm run docs:dev
This serves the developer documentation locally. You can browse the guides and the newly generated API documentation.
This project is licensed under the MIT License.