Custom Renderer
Catalogue
Angular Three Custom Renderer maintains a single catalogue of entities to render. By default, the catalogue is empty.
extend
In order to populate the catalogue, call the extend
function and pass in a Record
of entities. Angular Three then maps the catalogue to Custom Elements tags with the following naming convention:
CUSTOM_ELEMENTS_SCHEMA
The CUSTOM_ELEMENTS_SCHEMA
is required to use Angular Three elements as Angular does not support custom schemas at the moment.
Property Bindings
We can use property bindings to pass data to any of the NGT elements’ properties.
Shortcuts
Some THREE.js entities have different methods to update their values due to performance and how WebGL works. For example, THREE.Vector3
has a set
method that accepts a tuple of [x, y, z]
instead.
On the other hand, if we pass in a THREE.Vector3
instance, the current THREE.Vector3
will call copy
and pass in the new instance instead.
This characteristic is baked into the Angular Three Custom Renderer so it is more intuitive to pass values to these properties.
NgtVector*
NgtVector2
, NgtVector3
, and NgtVector4
are shortcuts types for THREE.Vector2
, THREE.Vector3
, and THREE.Vector4
respectively.
NgtEuler
and NgtQuaternion
Similar to NgtVector*
, these types are shortcuts for THREE.Euler
and THREE.Quaternion
respectively.
ColorRepresentation
Similar to NgtVector*
, any elements that accept a color
property can accept a ColorRepresentation
type. This is
a THREE.js type and Angular Three Custom Renderer will apply the value properly.
NGT Properties
Aside from the elements’ own properties, there are a few properties that are specific to the Angular Three Custom Renderer.
parameters
All custom elements accept a parameters
property that accepts an object of properties to pass to the underlying entity.
attach
This property is used to specify a property on the parent that this element should be attached to. Attaching takes into account the life-cycle of the elements and will automatically detach when the elements are destroyed.
Static Value
If the property on the parent is a static value, use Attribute Binding to bind a static string
to the attach
property.
This is equivalent to:
Nested Path
We can attach to a nested property on the parent by using a dot-separated path.
This is equivalent to:
Dynamic Value
We can pass a dynamic value to attach
property by using Property Binding syntax [attach]
. When this is the case, attach
accepts Array<string | number>
as well as string
This is equivalent to:
NgtAttachFunction
Optionally, we can pass a NgtAttachFunction
to attach
property. We are responsible for attaching and detaching the elements.
priority
See Render Priority for more information.
Event Bindings
Pointer Events
Event Name | Description |
---|---|
click | If observed, emits when the object is clicked. |
contextmenu | If observed, emits when the object is right-clicked. |
dblclick | If observed, emits when the object is double clicked. |
pointerup | If observed, emits when the pointer moves up while on the object. |
pointerdown | If observed, emits when the pointer moves down while on the object. |
pointerover | If observed, emits when the pointer is over the object. |
pointerout | If observed, emits when the pointer gets on then out of the object. |
pointerenter | If observed, emits when the pointer gets on the object. |
pointerleave | If observed, emits when the pointer gets on then out of the object. |
pointermove | If observed, emits when the pointer moves while on the object. |
pointermissed | If observed, emits when the pointer misses the object. |
pointercancel | If observed, emits when the current pointer event gets cancelled. |
wheel | If observed, emits when the wheel is acted on when on the object. |
beforeRender
To register a callback in the animation loop, listen to the beforeRender
event on a NGT element.
When the element is destroyed, the callback will be removed automatically.
Render Priority
By default, NGT renders the scene on every frame.
If we need to control this process, we can pass priority
as Attribute Binding with number-string values
to any object whose (beforeRender)
is being listened to.
When a priority
is set, we are responsible to render our scene.
attached
This event is emitted when the element is attached or added to the parent.
updated
This event is emitted when the element is updated.