UNPKG

@polygonjs/polygonjs

Version:

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

69 lines (68 loc) 2.49 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { AttribClassMenuEntries, ATTRIBUTE_CLASSES } from "../../../core/geometry/Constant"; import { AttribPromoteSopOperation, ATTRIB_PROMOTE_MODES } from "../../operations/sop/AttribPromote"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; const DEFAULT = AttribPromoteSopOperation.DEFAULT_PARAMS; class AttribPromoteSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param the group this applies to */ this.group = ParamConfig.STRING(DEFAULT.group); /** @param class the attribute is from (object or geometry) */ this.classFrom = ParamConfig.INTEGER(DEFAULT.classFrom, { menu: { entries: AttribClassMenuEntries } }); /** @param class the attribute should be promoted to (object or geometry) */ this.classTo = ParamConfig.INTEGER(DEFAULT.classTo, { menu: { entries: AttribClassMenuEntries } }); /** @param mode used to promote the attribute (min, max or first_found) */ this.mode = ParamConfig.INTEGER(DEFAULT.mode, { menu: { entries: ATTRIB_PROMOTE_MODES.map((name, value) => ({ name, value })) } }); /** @param name of the attribute to promote */ this.name = ParamConfig.STRING(DEFAULT.name); } } const ParamsConfig = new AttribPromoteSopParamsConfig(); export class AttribPromoteSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.ATTRIB_PROMOTE; } initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(AttribPromoteSopOperation.INPUT_CLONED_STATE); } cook(inputCoreGroups) { this._operation = this._operation || new AttribPromoteSopOperation(this.scene(), this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } setAttribClassFrom(attribClass) { this.p.classFrom.set(ATTRIBUTE_CLASSES.indexOf(attribClass)); } attribClassFrom() { return ATTRIBUTE_CLASSES[this.pv.classFrom]; } setAttribClassTo(attribClass) { this.p.classTo.set(ATTRIBUTE_CLASSES.indexOf(attribClass)); } attribClassTo() { return ATTRIBUTE_CLASSES[this.pv.classTo]; } setPromoteMode(mode) { this.p.mode.set(ATTRIB_PROMOTE_MODES.indexOf(mode)); } }