@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
49 lines (48 loc) • 1.55 kB
JavaScript
;
import { CADSopNode } from "./_BaseCAD";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { InputCloneMode } from "../../poly/InputCloneMode";
import { cadTransform } from "../../../core/geometry/modules/cad/operations/CadTransform";
class CADTransformSopParamConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param translate */
this.t = ParamConfig.VECTOR3([0, 0, 0]);
/** @param rotation */
this.r = ParamConfig.VECTOR3([0, 0, 0]);
/** @param scale (as a float) */
this.s = ParamConfig.FLOAT(1, {
range: [0, 2],
step: 0.01
});
/** @param pivot */
this.pivot = ParamConfig.VECTOR3([0, 0, 0]);
}
}
const ParamsConfig = new CADTransformSopParamConfig();
export class CADTransformSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_TRANSFORM;
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState(InputCloneMode.FROM_NODE);
}
cook(inputCoreGroups) {
const coreGroup0 = inputCoreGroups[0];
const newObjects = [];
const cadObjects = coreGroup0.cadObjects();
if (cadObjects) {
for (const cadObject of cadObjects) {
cadTransform(cadObject, this.pv.t, this.pv.r, this.pv.s, this.pv.pivot);
newObjects.push(cadObject);
}
}
this.setCADObjects(newObjects);
}
}