UNPKG

@polygonjs/polygonjs

Version:

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

58 lines (57 loc) 2.43 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { InputCloneMode } from "../../poly/InputCloneMode"; import { ScatterSopOperation } from "../../operations/sop/Scatter"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; const DEFAULT = ScatterSopOperation.DEFAULT_PARAMS; class ScatterSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param number of points to create */ this.pointsCount = ParamConfig.INTEGER(DEFAULT.pointsCount, { range: [0, 1e3], rangeLocked: [true, false] }); /** @param seed */ this.seed = ParamConfig.INTEGER(DEFAULT.seed, { range: [0, 100], rangeLocked: [true, false] }); /** @param attribute which will influence the distribution of points */ this.useWeightAttribute = ParamConfig.BOOLEAN(DEFAULT.useWeightAttribute); /** @param attribute which will influence the distribution of points */ this.weightAttribute = ParamConfig.STRING(DEFAULT.weightAttribute, { visibleIf: { useWeightAttribute: 1 } }); /** @param toggle on to transfer attribute from the input geometry to the created points */ this.transferAttributes = ParamConfig.BOOLEAN(DEFAULT.transferAttributes); /** @param names of the attributes to transfer */ this.attributesToTransfer = ParamConfig.STRING(DEFAULT.attributesToTransfer, { visibleIf: { transferAttributes: 1 } }); /** @param add an id attribute, starting at 0, incrementing by 1 for each point (0,1,2,3...) */ this.addIdAttribute = ParamConfig.BOOLEAN(DEFAULT.addIdAttribute); /** @param add an idn attribute, which is the id normalized between 0 and 1 */ this.addIdnAttribute = ParamConfig.BOOLEAN(DEFAULT.addIdnAttribute); } } const ParamsConfig = new ScatterSopParamsConfig(); export class ScatterSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.SCATTER; } initializeNode() { this.io.inputs.setCount(1); this.io.inputs.initInputsClonedState(InputCloneMode.NEVER); } cook(inputCoreGroups) { this._operation = this._operation || new ScatterSopOperation(this.scene(), this.states, this); const coreGroup = this._operation.cook(inputCoreGroups, this.pv); this.setCoreGroup(coreGroup); } }