polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
64 lines (63 loc) • 2.34 kB
JavaScript
import {TypedSopNode} from "./_Base";
import {ROTATION_ORDERS, TransformTargetType, TRANSFORM_TARGET_TYPES} from "../../../core/Transform";
import {TransformSopOperation} from "../../../core/operations/sop/Transform";
import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig";
const DEFAULT = TransformSopOperation.DEFAULT_PARAMS;
class TransformSopParamConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.applyOn = ParamConfig.INTEGER(DEFAULT.applyOn, {
menu: {
entries: TRANSFORM_TARGET_TYPES.map((target_type, i) => {
return {name: target_type, value: i};
})
}
});
this.group = ParamConfig.STRING(DEFAULT.group, {
visibleIf: {applyOn: TRANSFORM_TARGET_TYPES.indexOf(TransformTargetType.GEOMETRIES)}
});
this.rotationOrder = ParamConfig.INTEGER(DEFAULT.rotationOrder, {
menu: {
entries: ROTATION_ORDERS.map((order, v) => {
return {name: order, value: v};
})
}
});
this.t = ParamConfig.VECTOR3(DEFAULT.t);
this.r = ParamConfig.VECTOR3(DEFAULT.r);
this.s = ParamConfig.VECTOR3(DEFAULT.s);
this.scale = ParamConfig.FLOAT(DEFAULT.scale, {range: [0, 10]});
this.pivot = ParamConfig.VECTOR3(DEFAULT.pivot, {
visibleIf: {applyOn: TRANSFORM_TARGET_TYPES.indexOf(TransformTargetType.GEOMETRIES)}
});
}
}
const ParamsConfig2 = new TransformSopParamConfig();
export class TransformSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.params_config = ParamsConfig2;
}
static type() {
return "transform";
}
static displayedInputNames() {
return ["geometries or objects to transform"];
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState(TransformSopOperation.INPUT_CLONED_STATE);
this.scene().dispatchController.onAddListener(() => {
this.params.onParamsCreated("params_label", () => {
this.params.label.init([this.p.applyOn], () => {
return TRANSFORM_TARGET_TYPES[this.pv.applyOn];
});
});
});
}
cook(input_contents) {
this._operation = this._operation || new TransformSopOperation(this.scene(), this.states);
const core_group = this._operation.cook(input_contents, this.pv);
this.setCoreGroup(core_group);
}
}