UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

107 lines (106 loc) 4.01 kB
"use strict"; import { TypedObjNode } from "./_Base"; import { Group } from "three"; import { DisplayNodeController } from "../utils/DisplayNodeController"; import { NodeContext } from "../../poly/NodeContext"; import { FlagsControllerD } from "../utils/FlagsController"; import { HierarchyController } from "./utils/HierarchyController"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { ChildrenDisplayControllerSpecialized } from "./utils/ChildrenDisplayControllerSpecialized"; import { isBooleanTrue } from "../../../core/BooleanValue"; import { ObjType } from "../../poly/registers/nodes/types/Obj"; import { TransformedParamConfig, TransformController } from "./utils/TransformController"; import { ObjTesselationParamConfig } from "./utils/TesselationParams"; import { addCADTesselationParamsCallback } from "../../../core/geometry/modules/cad/utils/TesselationParamsConfig"; import { addCSGTesselationParamsCallback } from "../../../core/geometry/modules/csg/utils/TesselationParamsConfig"; import { addQUADTesselationParamsCallback } from "../../../core/geometry/modules/quad/utils/TesselationParamsConfig"; import { addTetTesselationParamsCallback } from "../../../core/geometry/modules/tet/utils/TesselationParamsConfig"; export function GeoParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param toggle off to hide */ this.display = ParamConfig.BOOLEAN(1); /** @param set render order */ this.renderOrder = ParamConfig.INTEGER(0, { range: [0, 10], rangeLocked: [true, false] }); } }; } class GeoObjParamConfig extends ObjTesselationParamConfig(GeoParamConfig(TransformedParamConfig(NodeParamsConfig))) { } const ParamsConfig = new GeoObjParamConfig(); export class GeoObjNode extends TypedObjNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this.hierarchyController = new HierarchyController(this); this.transformController = new TransformController(this); this.flags = new FlagsControllerD(this); // display_node and children_display controllers this.childrenDisplayController = new ChildrenDisplayControllerSpecialized(this); this.displayNodeController = new DisplayNodeController( this, this.childrenDisplayController.displayNodeControllerCallbacks() ); // this._childrenControllerContext = NodeContext.SOP; this._onChildAddBound = this._onChildAdd.bind(this); } static type() { return ObjType.GEO; } createObject() { const group = new Group(); group.matrixAutoUpdate = false; return group; } initializeNode() { this.lifecycle.onChildAdd(this._onChildAddBound); this.hierarchyController.initializeNode(); this.transformController.initializeNode(); this.childrenDisplayController.initializeNode(); const _updateSpecializedChildren = () => { this.childrenDisplayController.requestDisplayNodeContainer(); }; addCADTesselationParamsCallback(this, _updateSpecializedChildren); addCSGTesselationParamsCallback(this, _updateSpecializedChildren); addQUADTesselationParamsCallback(this, _updateSpecializedChildren); addTetTesselationParamsCallback(this, _updateSpecializedChildren); } createNode(node_class, options) { return super.createNode(node_class, options); } children() { return super.children(); } nodesByType(type) { return super.nodesByType(type); } // // // HOOK // // _onChildAdd(node) { var _a, _b; if (this.scene().loadingController.loaded()) { if (this.children().length == 1) { (_b = (_a = node.flags) == null ? void 0 : _a.display) == null ? void 0 : _b.set(true); } } } // // // COOK // // cook() { this.transformController.update(); this.object.visible = isBooleanTrue(this.pv.display); this.object.renderOrder = this.pv.renderOrder; this.cookController.endCook(); } }