Skip to content
bg2 engine

VitscnjLoaderPlugin

Loads .vitscnj scene files. Deserializes node trees with components and recursively loads embedded model resources (.bg2/.vwglb) via a Bg2LoaderPlugin dependency.

import VitscnjLoaderPlugin from 'bg2e-js/ts/db/VitscnjLoaderPlugin.ts';
import Loader, { registerLoaderPlugin } from 'bg2e-js/ts/db/Loader.ts';
registerLoaderPlugin(new VitscnjLoaderPlugin({ bg2ioPath: "bg2io/" }));
const loader = new Loader();
const root = await loader.loadNode("../resources/test-scene.vitscnj");

Supported extensions: ["vitscnj"]

Supported resource types: Node

See also: index, loader-plugin

constructor({ bg2ioPath, preferedDrawableFormat, materialImportCallback })
ParameterTypeDefaultDescription
bg2ioPathstring | null"bg2io"Path to the bg2io WASM files directory.
preferedDrawableFormat"vwglb" | "bg2""bg2"Preferred drawable format for loading embedded resources like .vwglb or .bg2. Sets a global preference accessible via VitscnjLoaderPlugin.PreferredDrawableFormat().
materialImportCallback(matData: any) => any | undefinedSame callback as in Bg2LoaderPlugin, applied to materials loaded from bg2/vwglb resources within the scene.

NOTE: The bg2ioPath should point to the directory where the bg2io.js and bg2io.wasm files are located in your final distribution. If you are using Vite, you can use the copyBg2eAssets plugin to copy these files to a specific directory in your dist folder, and then set bg2ioPath to that directory name (e.g., "bg2io/" if you copy them to dist/bg2io/). If you use the default value of bg2ioPath in the copyBg2eAssets plugin, which is bg2io/, then you can omit the bg2ioPath parameter since it defaults to "bg2io/".

VitscnjLoaderPlugin.PreferredDrawableFormat(): Returns the global preferred drawable format value ("bg2" or "vwglb").

  • The scene file contains an array of top-level node data objects
  • Each node has a name, optional enabled and steady flags, nested children, and serializable components
  • The loader automatically sets its dependencies (Bg2LoaderPlugin) which are registered before the scene plugin