@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
62 lines (61 loc) • 2.75 kB
JavaScript
"use strict";
import { TypedSopNode } from "./_Base";
import { AttribCopySopOperation } from "../../operations/sop/AttribCopy";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { ATTRIBUTE_CLASSES, AttribClass, AttribClassMenuEntries } from "../../../core/geometry/Constant";
const DEFAULT = AttribCopySopOperation.DEFAULT_PARAMS;
class AttribCopySopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param the attribute class (geometry or object) */
this.class = ParamConfig.INTEGER(DEFAULT.class, {
menu: {
entries: AttribClassMenuEntries
}
});
/** @param name of the attribute to copy */
this.name = ParamConfig.STRING(DEFAULT.name);
/** @param toggle if you want to copy to another name */
this.tnewName = ParamConfig.BOOLEAN(DEFAULT.tnewName);
/** @param the new name of the attribute */
this.newName = ParamConfig.STRING(DEFAULT.newName, { visibleIf: { tnewName: 1 } });
/** @param this defines which component the copy starts from. If you want to copy the whole attribute, leave it at 0. If you want to copy only the y component, set it to 1. If you want to copy the z component, set it to 2. Note that this only makes sense if you copy from an attribute that has enough components to copy from. So setting it to 2 (for z) to copy from a vector2 attribute will raise an error. */
this.srcOffset = ParamConfig.INTEGER(DEFAULT.srcOffset, {
range: [0, 3],
rangeLocked: [true, true],
visibleIf: { class: ATTRIBUTE_CLASSES.indexOf(AttribClass.POINT) }
});
/** @param this defines which component the attribute is copied to */
this.destOffset = ParamConfig.INTEGER(DEFAULT.destOffset, {
range: [0, 3],
rangeLocked: [true, true],
visibleIf: { class: ATTRIBUTE_CLASSES.indexOf(AttribClass.POINT) }
});
}
}
const ParamsConfig = new AttribCopySopParamsConfig();
export class AttribCopySopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.ATTRIB_COPY;
}
initializeNode() {
this.io.inputs.setCount(1, 2);
this.io.inputs.initInputsClonedState(AttribCopySopOperation.INPUT_CLONED_STATE);
}
cook(input_contents) {
this._operation = this._operation || new AttribCopySopOperation(this.scene(), this.states, this);
const core_group = this._operation.cook(input_contents, this.pv);
this.setCoreGroup(core_group);
}
setAttribClass(attribClass) {
this.p.class.set(ATTRIBUTE_CLASSES.indexOf(attribClass));
}
attribClass() {
return ATTRIBUTE_CLASSES[this.pv.class];
}
}