UNPKG

@polygonjs/polygonjs

Version:

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

68 lines (67 loc) 2.39 kB
"use strict"; import { ATTRIBUTE_CLASSES_WITHOUT_CORE_GROUP } from "./../../../core/geometry/Constant"; import { TypedSopNode } from "./_Base"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { AttribClassMenuEntriesWithoutCoreGroup } from "./../../../core/geometry/Constant"; import { AttribIdSopOperation } from "../../operations/sop/AttribId"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; const DEFAULT = AttribIdSopOperation.DEFAULT_PARAMS; class AttribIdSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param the attribute class (geometry or object) */ this.class = ParamConfig.INTEGER(DEFAULT.class, { menu: { entries: AttribClassMenuEntriesWithoutCoreGroup } }); /** @param sets to true to create the id attribute */ this.id = ParamConfig.BOOLEAN(DEFAULT.id); /** @param name of id attribute */ this.idName = ParamConfig.STRING(DEFAULT.idName, { visibleIf: { id: 1 } }); /** @param sets to true to create the id attribute */ this.idn = ParamConfig.BOOLEAN(DEFAULT.idn); /** @param name of the position attribute */ /** @param name of idn attribute */ this.idnName = ParamConfig.STRING(DEFAULT.idnName, { visibleIf: { idn: 1 } }); } } const ParamsConfig = new AttribIdSopParamsConfig(); export class AttribIdSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.ATTRIB_ID; } initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState([InputCloneMode.FROM_NODE]); } cook(inputCoreGroups) { this._operation = this._operation || new AttribIdSopOperation(this.scene(), this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } // // // API UTILS // // setAttribClass(attribClass) { if (ATTRIBUTE_CLASSES_WITHOUT_CORE_GROUP.includes(attribClass)) { this.p.class.set(ATTRIBUTE_CLASSES_WITHOUT_CORE_GROUP.indexOf(attribClass)); } else { console.warn(`${attribClass} is not possible on this node`); } } attribClass() { return ATTRIBUTE_CLASSES_WITHOUT_CORE_GROUP[this.pv.class]; } }