polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
41 lines (40 loc) • 996 B
JavaScript
export class HelperController {
constructor(node, _helper_constructor, _name) {
this.node = node;
this._helper_constructor = _helper_constructor;
this._name = _name;
}
initializeNode() {
this.node.flags.display.add_hook(() => {
this.update();
});
}
get helper() {
if (this.node.flags.display.active()) {
return this._helper = this._helper || this._create_helper();
}
}
get visible() {
return this.node.flags.display.active() && this.node.pv.showHelper;
}
_create_helper() {
const helper = new this._helper_constructor(this.node, this._name);
helper.build();
return helper;
}
update() {
if (this.visible) {
if (!this._helper) {
this._helper = this._create_helper();
}
if (this._helper) {
this.node.light.add(this._helper.object);
this._helper.update();
}
} else {
if (this._helper) {
this.node.light.remove(this._helper.object);
}
}
}
}