@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
53 lines (52 loc) • 1.62 kB
JavaScript
"use strict";
import { CSGSopNode } from "./_BaseCSG";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { vector3ToCsgVec3 } from "../../../core/geometry/modules/csg/CsgVecToVector";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { transforms } from "@jscad/modeling";
const { center } = transforms;
class CSGCenterSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param x */
this.x = ParamConfig.BOOLEAN(1);
/** @param y */
this.y = ParamConfig.BOOLEAN(1);
/** @param z */
this.z = ParamConfig.BOOLEAN(1);
/** @param relativeTo */
this.relativeTo = ParamConfig.VECTOR3([0, 0, 0]);
}
}
const ParamsConfig = new CSGCenterSopParamsConfig();
export class CSGCenterSopNode extends CSGSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this._relativeTo = [0, 0, 0];
this._axes = [true, true, true];
}
static type() {
return SopType.CSG_CENTER;
}
initializeNode() {
this.io.inputs.setCount(1);
}
cook(inputCoreGroups) {
vector3ToCsgVec3(this.pv.relativeTo, this._relativeTo);
this._axes[0] = this.pv.x;
this._axes[1] = this.pv.y;
this._axes[2] = this.pv.z;
const options = {
axes: this._axes,
relativeTo: this._relativeTo
};
const inputObjects = inputCoreGroups[0].csgObjects();
if (inputObjects) {
const newObjects = inputObjects.map((o) => center(options, o.csgGeometry()));
this.setCSGGeometries(newObjects);
} else {
this.setCSGObjects([]);
}
}
}