@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
55 lines (54 loc) • 2.02 kB
JavaScript
;
import { TypedSopNode } from "./_Base";
import {
InstanceUpdateMode,
InstanceUpdateSopOperation,
INSTANCE_UPDATE_MODES
} from "../../operations/sop/InstanceUpdate";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
const DEFAULT = InstanceUpdateSopOperation.DEFAULT_PARAMS;
class InstanceUpdateSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param defines what this node updates, either the instanced geometry or the instance points. */
this.mode = ParamConfig.INTEGER(DEFAULT.mode, {
menu: {
entries: INSTANCE_UPDATE_MODES.map((name, value) => {
return { value, name };
})
}
});
/** @param which attributes will be updated on the instanced geometry */
this.geoAttributes = ParamConfig.STRING(DEFAULT.geoAttributes, {
visibleIf: { mode: INSTANCE_UPDATE_MODES.indexOf(InstanceUpdateMode.GEO) }
});
/** @param which attributes will be updated ont the instance points */
this.pointAttributes = ParamConfig.STRING(DEFAULT.pointAttributes, {
visibleIf: { mode: INSTANCE_UPDATE_MODES.indexOf(InstanceUpdateMode.POINTS) }
});
}
}
const ParamsConfig = new InstanceUpdateSopParamsConfig();
export class InstanceUpdateSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.INSTANCE_UPDATE;
}
initializeNode() {
super.initializeNode();
this.io.inputs.setCount(2);
this.io.inputs.initInputsClonedState(InstanceUpdateSopOperation.INPUT_CLONED_STATE);
}
setMode(mode) {
this.p.mode.set(INSTANCE_UPDATE_MODES.indexOf(mode));
}
cook(input_contents) {
this._operation = this._operation || new InstanceUpdateSopOperation(this.scene(), this.states, this);
const core_group = this._operation.cook(input_contents, this.pv);
this.setCoreGroup(core_group);
}
}