@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
57 lines (56 loc) • 1.97 kB
JavaScript
;
import { CADSopNode } from "./_BaseCAD";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { step } from "../../../core/geometry/modules/cad/CadConstant";
import { CadLoader } from "../../../core/geometry/modules/cad/CadLoader";
import { cadShapeTranslate } from "../../../core/geometry/modules/cad/toObject3D/CadShapeCommon";
import { cadAxis } from "../../../core/geometry/modules/cad/CadMath";
import { SopType } from "../../poly/registers/nodes/types/Sop";
class CADTubeSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param radius */
this.radius = ParamConfig.FLOAT(1, {
range: [0, 2],
rangeLocked: [true, false],
step
});
/** @param height */
this.height = ParamConfig.FLOAT(1, {
range: [0, 2],
rangeLocked: [true, false],
step
});
/** @param center */
this.center = ParamConfig.VECTOR3([0, 0, 0]);
/** @param axis */
this.axis = ParamConfig.VECTOR3([0, 1, 0]);
/** @param closed */
this.closed = ParamConfig.BOOLEAN(true);
/** @param angle */
this.angle = ParamConfig.FLOAT(`2*$PI`, {
range: [0, 2 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { closed: false }
});
}
}
const ParamsConfig = new CADTubeSopParamsConfig();
export class CADTubeSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_TUBE;
}
async cook(inputCoreGroups) {
const oc = await CadLoader.core(this);
const axis = cadAxis(this.pv.axis);
const api = this.pv.closed ? new oc.BRepPrimAPI_MakeCylinder_3(axis, this.pv.radius, this.pv.height) : new oc.BRepPrimAPI_MakeCylinder_4(axis, this.pv.radius, this.pv.height, this.pv.angle);
const shape = cadShapeTranslate(api.Shape(), this.pv.center);
api.delete();
this.setCADShape(shape);
}
}