UNPKG

@polygonjs/polygonjs

Version:

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

63 lines (62 loc) 2.15 kB
"use strict"; 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 CADConeSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param base radius */ this.baseRadius = ParamConfig.FLOAT(0.5, { range: [0, 2], rangeLocked: [true, false], step }); /** @param top radius */ this.topRadius = ParamConfig.FLOAT(0, { 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 phi */ this.phi = ParamConfig.FLOAT(`2*$PI`, { range: [0, 2 * Math.PI], rangeLocked: [true, true], step, visibleIf: { closed: false } }); } } const ParamsConfig = new CADConeSopParamsConfig(); export class CADConeSopNode extends CADSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CAD_CONE; } async cook(inputCoreGroups) { const oc = await CadLoader.core(this); const axis = cadAxis(this.pv.axis); const api = this.pv.closed ? new oc.BRepPrimAPI_MakeCone_3(axis, this.pv.baseRadius, this.pv.topRadius, this.pv.height) : new oc.BRepPrimAPI_MakeCone_4(axis, this.pv.baseRadius, this.pv.topRadius, this.pv.height, this.pv.phi); const shape = cadShapeTranslate(api.Shape(), this.pv.center); api.delete(); this.setCADShape(shape); } }