@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
57 lines (56 loc) • 2.07 kB
JavaScript
;
import { CADSopNode } from "./_BaseCAD";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { step } from "../../../core/geometry/modules/cad/CadConstant";
import { CadLoader } from "../../../core/geometry/modules/cad/CadLoader";
import { CadLoaderSync } from "../../../core/geometry/modules/cad/CadLoaderSync";
import { cadEdgeCreate } from "../../../core/geometry/modules/cad/toObject3D/CadEdge";
class CADEllipseSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param major radius */
this.majorRadius = ParamConfig.FLOAT(1, {
range: [0, 2],
rangeLocked: [true, false],
step
});
/** @param minor radius */
this.minorRadius = ParamConfig.FLOAT(1, {
range: [0, 2],
rangeLocked: [true, false],
step
});
/** @param axis */
this.axis = ParamConfig.VECTOR3([0, 1, 0]);
/** @param center */
this.center = ParamConfig.VECTOR3([0, 0, 0]);
}
}
const ParamsConfig = new CADEllipseSopParamsConfig();
export class CADEllipseSopNode extends CADSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.CAD_ELLIPSE;
}
async cook(inputCoreGroups) {
const oc = await CadLoader.core(this);
const axis1 = CadLoaderSync.gp_Ax1;
const dir = CadLoaderSync.gp_Dir;
dir.SetCoord_2(this.pv.axis.x, this.pv.axis.y, this.pv.axis.z);
axis1.SetDirection(dir);
const axis = CadLoaderSync.gp_Ax2;
axis.SetAxis(axis1);
const majorRadius = Math.max(this.pv.majorRadius, this.pv.minorRadius);
const minorRadius = Math.min(this.pv.majorRadius, this.pv.minorRadius);
const ellipse = new oc.Geom_Ellipse_2(axis, majorRadius, minorRadius);
const t = CadLoaderSync.gp_Vec;
t.SetCoord_2(this.pv.center.x, this.pv.center.y, this.pv.center.z);
ellipse.Translate_1(t);
const edge = cadEdgeCreate(oc, ellipse);
this.setCADShape(edge);
}
}