@configura/babylon-scene-kit
v0.2.4
Published
Keywords
Readme
@configura/babylon-scene-kit
A lightweight wrapper around Babylon.js that bootstraps a fully-featured 3D scene with opinionated defaults. Provides engine setup, lighting, shadows, post-processing pipelines, environment, and render-loop control through a single createSceneKit() call.
SceneKit imports the Babylon runtime feature modules needed by its built-in environment helper, IBL, and default post-process pipeline. Consumers loading their own model formats or creating additional Babylon systems still need to register the relevant loaders/runtime packages for those paths.
Requirements
- Babylon.js 9.x — the package declares
@babylonjs/core ^9.9.1as a peer dependency. @babylonjs/inspectoris optional and only needed if you callshowInspector().
Default Features
All features are enabled by default and can be configured or disabled via options:
- Default Rendering Pipeline (bloom, tone mapping)
- SSAO2
- Global directional lighting
- 3-point light rig with camera follow light
- Environment Helper (ground, skybox)
- Image-based lighting (IBL) via
.envcubemap - Shadow generators
Usage
import { ArcRotateCamera } from "@babylonjs/core/Cameras/arcRotateCamera";
import { Vector3 } from "@babylonjs/core/Maths/math.vector";
import { createSceneKit } from "@configura/babylon-scene-kit";
const canvas = document.querySelector("canvas")!;
const kit = await createSceneKit<ArcRotateCamera>({
canvas,
camera: (scene, element) => {
const camera = new ArcRotateCamera(
"camera",
Math.PI / 4,
Math.PI / 3,
10,
Vector3.Zero(),
scene,
);
camera.attachControl(element, true);
return camera;
},
});
kit.scheduleRender();Render Modes
"on-demand"(default) — nothing renders unless you callkit.scheduleRender(). Ideal for static product views that only update on interaction."continuous"— renders every frame viaengine.runRenderLoop. Switch at runtime withkit.setRenderMode("continuous").
Shadow Policy
Control per-mesh shadow behavior without touching the shadow generators directly:
import { setShadowPolicy } from "@configura/babylon-scene-kit";
// Disable shadows on a specific mesh
setShadowPolicy(mesh, { cast: false, receive: false });Inspector
await kit.showInspector(); // dynamically imports @babylonjs/inspector
kit.hideInspector();Requires @babylonjs/inspector installed as a dependency in the consuming app.
Cleanup
kit.destroy(); // disposes scene, engine, lights, shadows, event listenersGround modes
environment.groundMode selects visible (default), shadowOnly, or none and
controls ground creation. environment.helperOptions accepts BabylonJS options
except createGround. Visible mode respects enableGroundShadow and
enableGroundMirror; shadow-only mode enables shadows and disables mirrors, with
opacity 0.6 by default (groundOpacity overrides it). None mode creates no
ground. environment.enabled: false disables the ground and skybox. mainColor
takes precedence over groundColor and skyboxColor.
After geometry changes, call kit.environmentHelper?.updateOptions({}) and schedule
a render. This refreshes the shadow-only plane using Babylon's ground calculation.
Directional projections extend the far depth to cover shadows on the environment
ground, whether visible or shadow-only. This fitting does not depend on the filter;
it prevents receiver-depth clipping with PCF and PCSS. A small tolerance prevents
depth-boundary rounding errors, and Babylon retains its normal X/Y fitting.
Custom projections and fixed bounds retain caller control.
