Skip to content

NgtCanvas

NgtCanvas from angular-three/dom provides the DOM-based implementation of THREE.js rendering using HTMLCanvasElement. This is the standard way to integrate THREE.js into your Angular applications.

Usage

import { NgtCanvas } from 'angular-three/dom';
@Component({
selector: 'app-root',
template: `
<ngt-canvas>
<app-scene-graph *canvasContent />
</ngt-canvas>
`,
imports: [NgtCanvas]
})
export class AppComponent {}

The canvas content must be wrapped with the structural directive *canvasContent. This directive ensures the THREE.js scene graph is only rendered after the HTMLCanvasElement is properly initialized with its WebGL context.

Features

  • DOM-based Rendering: Uses the standard HTMLCanvasElement for WebGL rendering
  • Automatic Resize Handling: The canvas automatically responds to size changes of its container, maintaining the correct aspect ratio and dimensions
  • Zone Management: All rendering is performed outside of NgZone (noop if your application is zoneless) for optimal performance
  • Event Management: Pointer events are handled efficiently with configurable event sources and prefixes

Inputs

inputtypedescription
glNgtGLOptionsWebGL renderer options. Can also be different renderer instance or a factory that returns a renderer instance. i.e: WebGPURenderer
sizeNgtSizeCanvas size configuration
shadowsboolean | NgtShadowsEnable/configure shadows (false)
legacybooleanEnable legacy color mode (false)
linearbooleanEnable linear color space (false)
flatbooleanEnable flat shading (false)
orthographicbooleanUse orthographic camera (false)
frameloopNgtFrameloopFrame loop mode ('always'). Check out On-demand rendering
performancePartial<NgtPerformance>Performance configuration
dprNgtDprDevice pixel ratio range ([1, 2])
raycasterPartial<THREE.Raycaster>Raycaster configuration
sceneTHREE.Scene | Partial<THREE.Scene>Scene configuration
cameraNgtCamera | NgtCameraParametersCamera configuration
eventsFunctionEvent system factory
eventSourceHTMLElement | ElementRef<HTMLElement>Custom event source element
eventPrefixNgtEventPrefixEvent coordinate prefix (offset)
lookAtNgtVector3Camera initial lookAt position

Outputs

outputtypedescription
createdNgtStateEmits when the canvas is initialized
pointerMissedObservable<void>Emits when a pointer event misses all objects