@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
85 lines (84 loc) • 2.89 kB
JavaScript
"use strict";
import { CSGSopNode } from "./_BaseCSG";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { primitives } from "@jscad/modeling";
import { vector2ToCsgVec2, vector3ToCsgVec3 } from "../../../core/geometry/modules/csg/CsgVecToVector";
import { step } from "../../../core/geometry/modules/csg/CsgConstant";
import { csgVec2MultScalar } from "../../../core/geometry/modules/csg/math/CsgMathVec2";
const { cylinderElliptic } = primitives;
class CSGTubeEllipticSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param height */
this.height = ParamConfig.FLOAT(1, { range: [0, 10] });
/** @param start radius */
this.startRadius = ParamConfig.FLOAT(1, {
range: [0, 10],
rangeLocked: [true, false]
});
/** @param start radiuses */
this.startRadiuses = ParamConfig.VECTOR2([1, 1]);
/** @param end radius */
this.endRadius = ParamConfig.FLOAT(1, {
range: [0, 10],
rangeLocked: [true, false]
});
/** @param end radius */
this.endRadiuses = ParamConfig.VECTOR2([1, 1]);
/** @param segments */
this.segments = ParamConfig.INTEGER(32, {
range: [4, 128],
rangeLocked: [true, false]
});
/** @param center */
this.center = ParamConfig.VECTOR3([0, 0, 0]);
/** @param open */
this.open = ParamConfig.BOOLEAN(0);
/** @param start angle */
this.startAngle = ParamConfig.FLOAT(0, {
range: [0, 2 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { open: 1 }
});
/** @param end angle */
this.endAngle = ParamConfig.FLOAT("$PI", {
range: [0, 2 * Math.PI],
rangeLocked: [true, true],
step,
visibleIf: { open: 1 }
});
}
}
const ParamsConfig = new CSGTubeEllipticSopParamsConfig();
export class CSGTubeEllipticSopNode extends CSGSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this._center = [0, 0, 0];
this._startRadiuses = [0, 0];
this._endRadiuses = [0, 0];
}
static type() {
return SopType.CSG_TUBE_ELLIPTIC;
}
cook(inputCoreGroups) {
vector3ToCsgVec3(this.pv.center, this._center);
vector2ToCsgVec2(this.pv.startRadiuses, this._startRadiuses);
vector2ToCsgVec2(this.pv.endRadiuses, this._endRadiuses);
const { startRadius, endRadius, height, segments, open } = this.pv;
csgVec2MultScalar(this._startRadiuses, startRadius);
csgVec2MultScalar(this._endRadiuses, endRadius);
const geo = cylinderElliptic({
center: this._center,
height,
startRadius: this._startRadiuses,
endRadius: this._endRadiuses,
segments,
startAngle: open ? this.pv.startAngle : 0,
endAngle: open ? this.pv.endAngle : 0
});
this.setCSGGeometry(geo);
}
}