Skip to content

injectBeforeRender

injectBeforeRender is a function that allows the consumers to register a callback to be run in the animation loop.

It takes a callback that has access to the state of the canvas and the delta time since the last frame.

injectBeforeRender cleans up the callback when the component is destroyed. Alternatively, injectBeforeRender returns a clean up function that can be called manually.

import { Component, ElementRef, viewChild } from '@angular/core';
import { injectBeforeRender } from 'angular-three';
import { Mesh } from 'three';
@Component({
template: `
<ngt-mesh #mesh>
<!-- content -->
</ngt-mesh>
`
})
export class Experience {
meshRef = viewChild.required<ElementRef<Mesh>>('mesh');
constructor() {
injectBeforeRender(({ delta }) => {
const mesh = this.meshRef().nativeElement;
mesh.rotation.x += delta;
mesh.rotation.y += delta;
});
}
}