Skip to content

NgtsInstances

Credits: Instances from Drei

NgtsInstances efficiently renders many instances of the same geometry and material using a single draw call via THREE.InstancedMesh. This dramatically improves performance when rendering many identical objects.

Usage

import { NgtsInstances, NgtsInstance } from 'angular-three-soba/performances';
<ngts-instances [options]="{ limit: 100 }">
<ngt-box-geometry />
<ngt-mesh-standard-material />
@for (i of items; track i) {
<ngts-instance [options]="{ position: [i * 2, 0, 0], color: 'red' }" />
}
</ngts-instances>

NgtsInstance

A single instance within NgtsInstances. Each instance can be individually positioned, rotated, scaled, and colored.

Instance Options

PropertyDescription
positionPosition [x, y, z]
rotationRotation [x, y, z]
scaleScale (number or [x, y, z])
colorInstance color (overrides parent)

Dynamic Instances

@Component({
template: `
<ngts-instances [options]="{ limit: 1000 }">
<ngt-sphere-geometry *args="[0.5, 16, 16]" />
<ngt-mesh-standard-material />
@for (particle of particles(); track particle.id) {
<ngts-instance
[options]="{
position: particle.position,
scale: particle.scale,
color: particle.color
}"
/>
}
</ngts-instances>
`
})
export class ParticleSystem {
particles = signal<Particle[]>([]);
}

Performance Tips

  • Set limit to match your expected maximum instances
  • Use range to limit visible instances for culling
  • Set frames to a finite number if instances don’t move often
<!-- Static instances - only update once -->
<ngts-instances [options]="{ limit: 500, frames: 1 }">
<!-- ... -->
</ngts-instances>

Options

Properties

name type description
limit number Maximum number of instances, default to 1000
range number Limits the number of visible instances
frames number Number of frames to update transforms (Infinity = continuous), default to Infinity