injectLoader
injectLoader
is a utility function that abstracts the process of loading 3D assets.
It accepts:
- A function that returns a
THREE.Loader
constructor - A function that returns a
string
orstring[]
- An option object that accepts the following properties:
extensions
: A function that accepts aTHREE.Loader
and returns nothing. It is used to extend the loader with additional functionality.onLoad
: A function that accepts the loaded data and returns nothing. It is called after the loader has finished loading the data.onProgress
: A function that accepts aProgressEvent
and returns nothing. It is called when the loader emits a progress event.injector
: AnInjector
instance. It is used to set the Injection Context for the loader
1import { injectLoader } from 'angular-three';2
3@Component({4 template: `5 @if (gltfResult(); as gltf) {6 <ngt-primitive *args="[gltf.scene]" />7 }8 `,9})10export class Experience {11 gltfResult = injectLoader(() => GLTFLoader, () => 'path/to/model.glb');12}