@babylonjs/lite

中文文档
1.38.2发布于 2026/11/06Apache-2.0TypeScriptES Module近 30 天下载 1.6万

A lightweight, tree-shakable, WebGPU-first rendering library derived from Babylon.js.

原始使用文档
文档目录8 节
  1. Installation
  2. Quick start
  3. OpenUSD
  4. Documentation
  5. Optional navigation
  6. Headless simulation (null engine)
  7. Right-handed coordinate system
  8. License

Babylon Lite

A lightweight, tree-shakable, WebGPU-first rendering library derived from Babylon.js. Import only what you use and ship a minimal bundle.

Installation

npm install @babylonjs/lite

Quick start

import { createEngine, createSceneContext, createDefaultCamera, createHemisphericLight, addToScene, loadGltf, registerScene, startEngine } from "@babylonjs/lite";

async function main(): Promise<void> {
    const canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;

    const engine = await createEngine(canvas);
    const scene = createSceneContext(engine);

    addToScene(scene, await loadGltf(engine, "https://playground.babylonjs.com/scenes/BoomBox.glb"));
    addToScene(scene, createHemisphericLight([0, 1, 0], 1.0));
    createDefaultCamera(scene);

    await registerScene(scene);
    await startEngine(engine);
}

main().catch(console.error);

OpenUSD

loadUsd() loads .usd, .usda, .usdc, and .usdz with the same protocol-versioned OpenUSD WebAssembly extractor used by Babylon.js, then materializes the command/data buffers as native Lite entities:

import { addToScene, loadUsd } from "@babylonjs/lite";

const asset = await loadUsd(engine, "/assets/model.usdz");
addToScene(scene, asset);

For composed stages, pass every external layer, payload, and texture through the virtual files map while preserving authored paths:

const asset = await loadUsd(engine, rootLayer, {
    rootFileName: "Package/Scenes/Main.usda",
    files: {
        "Package/Layers/Geometry.usdc": geometryLayer,
        "Package/Textures/Albedo.png": albedo,
    },
});

The worker, glue, WASM, and data bundle default to the Babylon.js CDN. Set runtimeBaseUrl to a directory containing all four protocol-v5 files to self-host them.

Documentation

Full documentation is available at https://doc.babylonjs.com/lite/.

Optional navigation

Navcat navigation loads offline-baked JSON and runs pure-JavaScript path/surface queries without Wasm. Generation, off-mesh mutation and CPU debug geometry are independently optional. The existing Recast backend remains available. See the Navcat lab demo for filters, mesh replacement and disposal/reload.

Headless simulation (null engine)

Babylon Lite can run without a GPU or canvas for server-side physics, deterministic simulation, or CI — the Lite analogue of Babylon.js NullEngine. Use createNullEngine() instead of createEngine(), and drive the loop yourself with stepScene():

import { createNullEngine, stepScene, createSceneContext } from "@babylonjs/lite";

const engine = createNullEngine(); // no device, no canvas — synchronous
const scene = createSceneContext(engine, { defaultRenderTask: false });

// ...add physics bodies / onBeforeRender callbacks...

for (let i = 0; i < 180; i++) stepScene(engine, scene, 1000 / 60); // simulate 3s

It needs no WebGPU and runs on plain Node (recommended), Deno, Web Workers, or CI. Rendering is out of scope. See the Headless (Null Engine) guide for details, supported runtimes, and limitations.

Right-handed coordinate system

Babylon Lite is left-handed by default. To render right-handed, like Babylon.js with scene.useRightHandedSystem = true, add the babylon-lite-rh resolve condition to your bundler. Your code does not change, and the handedness is a constant the minifier folds away: with Rolldown, which builds the lab scenes, a left-handed bundle is byte-for-byte the one built before this option existed. esbuild keeps the handedness checks and a few small helpers, so its bundles grow slightly.

The modules in lib/ import #coordinate-system, a package import declared in this package's imports map. Bundlers that read imports (Vite, webpack 5, esbuild, Rolldown, Rollup with @rollup/plugin-node-resolve) resolve it; native browser ESM and bundlers without imports support do not. The prebuilt dist/index.js has no such import and is left-handed.

// vite.config.ts
import { defineConfig, defaultClientConditions } from "vite";

export default defineConfig({
    resolve: { conditions: [...defaultClientConditions, "babylon-lite-rh"] },
});

Every engine in that bundle is right-handed. See the Right-Handed Coordinate System guide for webpack, esbuild and Rollup, and for the features covered so far.

License

Apache-2.0

@babylonjs/lite is a derivative of Babylon.js (Apache-2.0). It bundles a small number of third-party runtime libraries (manifold-3d, @recast-navigation/*, text-shaper, navcat, mathcat) whose code ships inside the published package. Their license texts — together with those of the upstream native components embedded in their WebAssembly (Recast & Detour and the Emscripten runtime) — are reproduced in NOTICE.txt.

Development-only tooling (build, test, and lint frameworks) is not part of the published package and therefore carries no redistribution obligations.

版本与发布记录

@babylonjs/lite 共发布 49 个版本,首次发布于 2026/06/04;过去 12 个月发布了 49 个版本。

版本发布日期距今
1.38.2latest2026/11/061 天前
1.38.12026/11/052 天前
1.38.0-previewpreview2026/11/043 天前
1.38.02026/11/025 天前
1.37.22026/10/299 天前
1.37.12026/10/2810 天前

关于 @babylonjs/lite 的常见问题

@babylonjs/lite 是什么?

A lightweight, tree-shakable, WebGPU-first rendering library derived from Babylon.js.

如何安装 @babylonjs/lite?

在项目目录运行 npm install @babylonjs/lite,或使用 pnpm add / yarn add / bun add。

@babylonjs/lite 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@babylonjs/lite 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@babylonjs/lite 可以商用吗?

@babylonjs/lite 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@babylonjs/lite 的下载量有多少?

根据 npm 官方下载统计,@babylonjs/lite 在 2026/10/08 – 2026/11/06 这 30 天内被下载 15,623 次,日均约 521 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@babylonjs/lite 还在维护吗?

最新版本 1.38.2 发布于 2026/11/06(1 天前);至今共发布 49 个版本,其中过去 12 个月发布了 49 个;首次发布于 2026/06/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。