@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
69 lines (68 loc) • 2.4 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 CADSphereSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param radius */
this.radius = 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 thetaMin */
this.thetaMin = ParamConfig.FLOAT(`1.5*$PI`, {
range: [1.5 * Math.PI, 2.5 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { closed: false }
});
/** @param thetaMax */
this.thetaMax = ParamConfig.FLOAT(`2.5*$PI`, {
range: [1.5 * Math.PI, 2.5 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { closed: false }
});
/** @param phi */
this.phi = ParamConfig.FLOAT(`2*$PI`, {
range: [0, 2 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { closed: false }
});
}
}
const ParamsConfig = new CADSphereSopParamsConfig();
export class CADSphereSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_SPHERE;
}
async cook(inputCoreGroups) {
const oc = await CadLoader.core(this);
const axis = cadAxis(this.pv.axis);
const api = this.pv.closed ? new oc.BRepPrimAPI_MakeSphere_9(axis, this.pv.radius) : (() => {
const thetaMin = Math.min(this.pv.thetaMin, this.pv.thetaMax);
const thetaMax = Math.max(this.pv.thetaMin, this.pv.thetaMax);
return new oc.BRepPrimAPI_MakeSphere_12(axis, this.pv.radius, thetaMin, thetaMax, this.pv.phi);
})();
const shape = cadShapeTranslate(api.Shape(), this.pv.center);
api.delete();
this.setCADShape(shape);
}
}