ngt-primitive
There are occasions where you have a pre-existing THREE.js object that you want to include in our Angular Three scene graph, you can use the ngt-primitive element to do this.
Usage
@Component({ template: ` <ngt-primitive *args="[object()]" /> `, imports: [NgtArgs]})export class Model {}ngt-primitiverequiresNgtArgswith the object to render.ngt-primitiveaccepts a[parameters]property that forwards properties to the underlying object.Attachingworks the same way withngt-primitive- Automatic disposal does not happen for
ngt-primitive
How it works
ngt-primitive coupled with NgtArgs acts as a flag for Angular Three renderer knows that this is some THREE.js object that the user provides so the renderer does not have to create anything. Then the renderer allows the object to follow the same flow as any other Custom Element on the template.
Most common use-case for ngt-primitive is to render a pre-made 3D model
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';import { NgtArgs } from 'angular-three';import { NgtsCameraControls } from 'angular-three-soba/controls';import { gltfResource } from 'angular-three-soba/loaders';import { NgtsCenter, NgtsEnvironment } from 'angular-three-soba/staging';
import littlestTokyo from './LittlestTokyo-transformed.glb' with { loader: 'file' };
@Component({ selector: 'app-scene-graph', template: ` <ngts-center> <ngt-primitive *args="[gltf.scene()]" [parameters]="{ scale: 0.0075 }" /> </ngts-center>
<ngts-environment [options]="{ preset: 'city' }" />
<ngts-camera-controls /> `, imports: [NgtArgs, NgtsCameraControls, NgtsEnvironment, NgtsCenter], schemas: [CUSTOM_ELEMENTS_SCHEMA], changeDetection: ChangeDetectionStrategy.OnPush,})export class SceneGraph { protected gltf = gltfResource(() => littlestTokyo);}Credits: THREE.js Animation Keyframes; Model Littlest Tokyo by Glen Fox