UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

64 lines (63 loc) 1.97 kB
"use strict"; import { CSGSopNode } from "./_BaseCSG"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { vector2ToCsgVec2 } from "../../../core/geometry/modules/csg/CsgVecToVector"; import { step } from "../../../core/geometry/modules/csg/CsgConstant"; import { primitives } from "@jscad/modeling"; const { ellipse } = primitives; class CSGEllipseSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param radius */ this.radius = ParamConfig.VECTOR2([1, 1]); /** @param segments */ this.segments = ParamConfig.INTEGER(32, { range: [4, 128], rangeLocked: [true, false] }); /** @param center */ this.center = ParamConfig.VECTOR2([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(Math.PI, { range: [0, 2 * Math.PI], rangeLocked: [true, true], step, visibleIf: { open: 1 } }); } } const ParamsConfig = new CSGEllipseSopParamsConfig(); export class CSGEllipseSopNode extends CSGSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; this._center = [0, 0]; this._radius = [0, 0]; } static type() { return SopType.CSG_ELLIPSE; } cook(inputCoreGroups) { vector2ToCsgVec2(this.pv.center, this._center); vector2ToCsgVec2(this.pv.radius, this._radius); const { segments, open, startAngle, endAngle } = this.pv; const geo = ellipse({ center: this._center, radius: this._radius, segments, startAngle: open ? startAngle : 0, endAngle: open ? endAngle : 0 }); this.setCSGGeometry(geo); } }