@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
110 lines (109 loc) • 3.35 kB
JavaScript
"use strict";
import { Object3D } from "three";
import { TypedNode } from "../_Base";
import { NodeContext } from "../../poly/NodeContext";
import { Group } from "three";
import { Poly } from "../../Poly";
export var ObjNodeRenderOrder = /* @__PURE__ */ ((ObjNodeRenderOrder2) => {
ObjNodeRenderOrder2[ObjNodeRenderOrder2["MANAGER"] = 0] = "MANAGER";
ObjNodeRenderOrder2[ObjNodeRenderOrder2["CAMERA"] = 2] = "CAMERA";
ObjNodeRenderOrder2[ObjNodeRenderOrder2["LIGHT"] = 3] = "LIGHT";
return ObjNodeRenderOrder2;
})(ObjNodeRenderOrder || {});
export class TypedObjNode extends TypedNode {
constructor() {
super(...arguments);
this.renderOrder = 0 /* MANAGER */;
this._children_group = this._create_children_group();
this._attachableToHierarchy = true;
this._usedInScene = true;
}
static context() {
return NodeContext.OBJ;
}
_create_children_group() {
const group = new Group();
group.matrixAutoUpdate = false;
return group;
}
attachableToHierarchy() {
return this._attachableToHierarchy;
}
usedInScene() {
return this._usedInScene && this.disposed() == false;
}
// TODO call set_used_in_scene(false) when node is deleted
// set_used_in_scene(state: boolean) {
// this._used_in_scene = state;
// if (!this.scene.loading_controller.isLoading()) {
// const root = this.parent as ObjectsManagerNode;
// if (root) {
// root.update_object(this);
// }
// }
// }
addObjectToParent(parent) {
if (this.attachableToHierarchy()) {
parent.add(this.object);
Poly.onObjectsAddRemoveHooks.runOnAddHookOnObject(this._scene, this.object);
}
}
removeObjectFromParent() {
if (this.attachableToHierarchy()) {
const parent = this.object.parent;
if (parent) {
Poly.onObjectsAddRemoveHooks.runOnRemoveHookOnObject(this._scene, this.object);
parent.remove(this.object);
}
}
}
dispose() {
var _a;
super.dispose();
(_a = this.childrenDisplayController) == null ? void 0 : _a.dispose();
}
initializeBaseNode() {
this._object = this._create_object_with_attributes();
this.nameController.add_post_set_fullPath_hook(this.set_object_name.bind(this));
this.set_object_name();
}
childrenGroup() {
return this._children_group;
}
get object() {
return this._object;
}
_create_object_with_attributes() {
const object = this.createObject();
object.node = this;
object.add(this._children_group);
return object;
}
set_object_name() {
if (this._object) {
this._object.name = this.path();
this._children_group.name = `${this.path()}:parentedOutputs`;
}
}
createObject() {
const object = new Object3D();
object.matrixAutoUpdate = false;
return object;
}
isDisplayNodeCooking() {
var _a, _b, _c;
if ((_b = (_a = this.flags) == null ? void 0 : _a.display) == null ? void 0 : _b.active()) {
const displayNode = (_c = this.displayNodeController) == null ? void 0 : _c.displayNode();
if (displayNode) {
return displayNode.cookController.isCooking();
}
}
return false;
}
isDisplayed() {
var _a, _b;
return ((_b = (_a = this.flags) == null ? void 0 : _a.display) == null ? void 0 : _b.active()) || false;
}
}
export class BaseObjNodeClass extends TypedObjNode {
}