Skip to main content

Canvas

The root of a NGT 3D scene is the NgtCanvas component

<ngt-canvas [sceneGraph]="SceneGraph" [camera]="cameraOptions" />

Inputs

namedescriptiontypedefault
sceneGraph(required) A component that will be rendered as the Root THREE.SceneType<any>
sceneGraphInputsAn object that will be used as Inputs for the sceneGraph componentRecord<string, any>{}
compoundPrefixesAn array of prefixes of HTML tags that NGT will treat as Compoundstring[][]
glA THREE.js Renderer instance of options that go into the default Renderer. It also accepts a callback that returns a THREE.js Renderer instanceNgtGLOptions-
sizeDimensions to fit the THREE.js Renderer to. Will measure <canvas> dimentions if omittedNgtSize-
shadowsEnables PCFsoft shadows. Can accept gl.shadowMap options for fine-tuningboolean, Partial<THREE.WebGLShadowMap>false
legacyDisables THREE.js r139 ColorManagementbooleanfalse
linearSwitch off automatic sRGB encoding and gamma correctionbooleanfalse
flatUse NoToneMapping instead of ACESFilmicToneMappingbooleanfalse
orthographicCreates an OrthographicCamera insteadbooleanfalse
frameloopR3F's render mode. Set to demand to only render when there are changes to the Scene Graphalways, demand, neveralways
performancePerformance options for adaptive environmentPartial<Omit<NgtPerformance, 'regress'>>-
dprTarget pixel ratio. Can clamp between a range [min, max]NgtDpr[1, 2]
raycasterOptions that go into the default RaycasterPartial<THREE.Raycaster>-
cameraA Camera instance or options that go into the default Cameracheck source-
eventsR3F event manager to manage elements' pointer events(store: NgtRxStore<NgtState>) => NgtEventManager<HTMLElement>-
eventSourceThe target where events are bound toHTMLElement, ElementRef<HTMLElement>NgtCanvas host element
eventPrefixThe event prefix that is cast into Canvas pointer x/y eventsoffset, client, page, layer, screenoffset
lookAtDefault coordinate for the camera to look atTHREE.Vector3, Parameters<THREE.Vector3['set']>-
export type NgtGLRenderer = {
render: (scene: THREE.Scene, camera: THREE.Camera) => void;
};

export type NgtGLOptions =
| NgtGLRenderer
| ((canvas: HTMLCanvasElement) => NgtGLRenderer)
| Partial<NgtProperties<THREE.WebGLRenderer> | THREE.WebGLRendererParameters>
| undefined;

export type NgtSize = {
width: number;
height: number;
top: number;
left: number;
};

export interface NgtPerformance {
/** Current performance normal, between min and max */
current: number;
/** How low the performance can go, between 0 and max */
min: number;
/** How high the performance can go, between min and max */
max: number;
/** Time until current returns to max in ms */
debounce: number;
/** Sets current to min, puts the system in regression */
regress: () => void;
}

export type NgtDpr = number | [min: number, max: number];

Outputs

namedescription
createdEmits after the NgtCanvas is created with all the internal building blocks
pointerMissedIf observed, NGT will set the internal pointermissed event and will emit whenever the Raycaster missed an object

Canvas defaults

NgtCanvas sets up a translucent THREE.WebGLRenderer with the following constructor arguments:

  • antialias = true
  • alpha = true
  • powerReference = 'high-performance'

and the following properties:

  • outputEncoding = THREE.sRGBEncoding

  • toneMapping = THREE.ACESFilmicToneMapping

  • A THREE.PCFSoftShadowMap if shadows is true

  • A THREE.PerspectiveCamera, or a THREE.OrthographicCamera if orthographic is true

  • A THREE.Scene

  • A THREE.Raycaster

  • A window:resize listener that will update the THREE.Renderer and `THREE.Camera`` when the container is resized.

From THREE.js 0.139+, THREE.ColorManagement.legacyMode is set to false to enable automatic conversion of colors based on the Renderer's configured color space. For more on this topic, check THREE.js Color Management