UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

70 lines (69 loc) 2.58 kB
import { AssetReference, type ProgressCallback } from "../engine/engine_addressables.js"; import { Behaviour } from "../engine-components/Component.js"; import { EventList } from "./EventList.js"; /** * NestedGltf loads and instantiates a glTF file when the component starts. * NestedGltf components are created by the Unity exporter when nesting Objects with the GltfObject component (in Unity). * Use this for lazy-loading content, modular scene composition, or dynamic asset loading. * * ![](https://cloud.needle.tools/-/media/lJKrr_2tWlqRFdFc46U4bQ.gif) * * The loaded glTF is instantiated as a sibling (child of parent) by default, * inheriting the transform of the GameObject with this component. * * **Features:** * - Automatic loading on start * - Progress callbacks for loading UI * - Preloading support for faster display * - Event callback when loading completes * * @example Load a glTF when object becomes active * ```ts * const nested = myPlaceholder.addComponent(NestedGltf); * nested.filePath = new AssetReference("models/furniture.glb"); * nested.loaded.addEventListener(({ instance }) => { * console.log("Loaded:", instance.name); * }); * ``` * * @example Preload for instant display * ```ts * // Preload during loading screen * await nested.preload(); * // Later, when object becomes active, it displays instantly * ``` * * @summary Loads and instantiates a nested glTF file * @category Asset Management * @group Components * @see {@link AssetReference} for asset loading utilities * @see {@link SceneSwitcher} for scene-level loading * @link https://engine.needle.tools/samples/hotspots */ export declare class NestedGltf extends Behaviour { /** Reference to the glTF file to load. Can be a URL or asset path. */ filePath?: AssetReference; /** * Event fired when the glTF has been loaded and instantiated. * Provides the component, loaded instance, and asset reference. */ loaded: EventList<{ component: NestedGltf; instance: any; asset: AssetReference; }>; /** * EXPERIMENTAL for cloud asset loading */ loadAssetInParent: boolean; private _isLoadingOrDoneLoading; /** Register a callback that will be called when the progress of the loading changes */ listenToProgress(evt: ProgressCallback): void; /** Begin loading the referenced gltf file in filePath */ preload(): Promise<ArrayBufferLike | null> | null; /** @internal */ start(): Promise<void>; /** @internal */ onDestroy(): void; private hash; }