UNPKG

@needle-tools/facefilter

Version:

Needle Engine FaceFilter

49 lines 1.64 kB
import { Behaviour } from "@needle-tools/engine"; import { FacefilterUtils } from "./utils"; /** * Make the object an occluder for the face filter */ export class NeedleOcclusionMesh extends Behaviour { onEnable() { console.debug("Create Occluder"); FacefilterUtils.makeOccluder(this.gameObject); } } export class NeedleBackgroundMesh extends Behaviour { _previousParent = null; awake() { this._previousParent = this.gameObject.parent; } onBeforeRender() { // The following is super ugly and just a hack // We reparent the mesh into the camera for one render call // then reparent back // But since the filter is removed during onBeforeRender the onAfterRender is not called anymore // And we do not receive a callback when the filter becomes inactive // So we need to check if the mesh is still in the scene... // Urgh if (!this.isInScene()) { return; } this.gameObject.matrixAutoUpdate = false; this._previousParent = this.gameObject.parent; this.context.mainCamera.add(this.gameObject); } onAfterRender() { this.context.mainCamera.remove(this.gameObject); if (this._previousParent) { this._previousParent.add(this.gameObject); } } isInScene() { let current = this._previousParent; while (current) { if (current === this.context.scene) { return true; } current = current.parent; } return false; } } //# sourceMappingURL=HelperComponents.js.map