几何造型
AnyCAD三维控件支持多种建模/造型方法,比如基本体造型、基于草图特征造型、布尔运算等。这类造型算法操作的都几何拓扑TopoShape。
1. 拓扑对象
TopoShape用于表示几何拓扑对象,可以表示顶点、边、面,也可以表示体、复合体。通过TopoShape::GetShapeType方法可以得到其表达的类型。
namespace AnyCAD.Foundation
{
public enum EnumTopoShapeType
{
Topo_COMPOUND = 0,
Topo_COMPSOLID = 1,
Topo_SOLID = 2,
Topo_SHELL = 3,
Topo_FACE = 4,
Topo_WIRE = 5,
Topo_EDGE = 6,
Topo_VERTEX = 7,
Topo_SHAPE = 8
}
}
获取子拓扑结构
使用TopoShape::GetChildren方法可以获取指定类型的子拓扑结构的对象列表,比如获取一个体所有的面,一个面所有的边;
使用TopoShape::FindChild可以得到指定索引和类型的子拓扑对象。
var shape = ....// 来源不明的物体
// 得到第一个面
var face = shape.FindChild(EnumTopoShapeType.Topo_FACE, 0);
// 遍历这个面所有的边
var edges = face.GetChildren(EnumTopoShapeType.Topo_EDGE);
获取直接的孩子拓扑结构
TopoExplor::GetSubShapes可以获取所有的孩子节点。
var shape = ....// 来源不明的物体
var children = TopoExplor.GetSubShapes(shape);
foreach (var child in children)
{
//...
}
2. 基本体造型
2.1 三维基本体
使用ShapeBuilder可以创建常见的三维基本体,比如球体(Sphere)、盒体(Box)、圆柱体(Cylinder)、圆锥体(Cone)、圆管体(Tube)等
基本体 | ShapeBuilder方法 |
---|---|
球体 | TopoShape MakeSphere(GPnt center, double radius) |
盒体 | TopoShape MakeBox(GAx2 ax, double dx, double dy, double dz) |
圆柱体 | TopoShape MakeCylinder(GAx2 ax, double radius, double height, double angle) |
圆锥体 | TopoShape MakeCone(GAx2 ax, double radius, double radiusTop, double height, double angle) |
圆管体 | TopoShape MakeTube(GPnt center, GDir dir, double innerRadius, double thickness, double len) |
创建并显示不同棱数目的棱锥:
var material = MeshStandardMaterial.Create("my-material");
material.SetRoughness(0.75f);
material.SetMetalness(0.1f);
material.SetColor(ColorTable.Hex(0xFFC107));
for (uint ii = 0; ii < 10; ++ii)
{
TopoShape shape = ShapeBuilder.MakePyramid(new GAx2(new GPnt(ii * 11, 0, 0), GP.DZ()), ii + 3, 5, 5 + ii);
var node = BrepSceneNode.Create(shape, material, null);
render.ShowSceneNode(node);
}
2.2 三维曲线、平面几何对象
使用CurveBuilder可以创建常见的曲线和曲面,比如直线、圆(弧)线、椭圆(弧)线、多折线,平面等
曲线对象 | CurveBuilder方法 |
---|---|
直线 | TopoShape MakeLine(GPnt start, GPnt end) |
圆 | TopoShape MakeCircle(GPnt center, double radius, GDir zdir) |
椭圆 | TopoShape MakeEllipse(GPnt center, double majorRadius, double minorRadius, GDir xdir, GDir zdir) |
圆弧 | TopoShape MakeArcOfCircle(...) |
椭圆弧 | TopoShape MakeArcOfEllipse(GElips elips, double start, double end) |
B-Spline | TopoShape MakeBSpline(...) |
多折线 | TopoShape MakePolygon(GPntList points, bool bClosed) |
弹簧线 | TopoShape MakeSpiral(double radius, double interval, double count, GAx3 ax) |
平面对象 | CurveBuilder方法 |
---|---|
平面 | TopoShape MakePlanarFace(GPln plane, double minU, double maxU, double minV, double maxV) |
填充多边形 | TopoShape MakePolygonFace(GPntList points) |
圆角矩形 | TopoShape MakeRectangle(GAx2 coord, double len, double width, double radius, bool bFiled) |
2.3 Wire
多条相连的线可以组成Wire。
Wire一般用来表示面的边界,比如外边界、内孔的边界。 Wire也可以表示一条由多个边组成的复杂的路径。
功能 | CurveBuilder方法 |
---|---|
单条边的Wire | TopoShape MakeWire(TopoShape edge) |
多条边的Wire | TopoShape MakeWire(TopoShapeList edges) |
打一个孔 | TopoShape AddHole(TopoShape face, TopoShape wireOfHole) |
打多个孔 | TopoShape AddHoles(TopoShape face, TopoShapeList wiresOfHoles) |
3. 特征造型
特征造型是近二十年来发展起来的一种新的造型方法,它是CAD第三次技术革命(参数化技术)的里程碑。 FeatureTool提供了常用的特征操作,包括拉伸(Extrude)、扫掠(Sweep)、放样(Loft)、倒直角(Chamfer)、倒圆角(Fillet)、抽壳(Thickness)、偏置(Offset)等。
namespace AnyCAD.Foundation
{
public class FeatureTool
{
// 对所有的边倒直角
public static TopoShape Chamfer(TopoShape shape, double dis1, double dis2);
// 对指定的边倒直角
public static TopoShape Chamfer(TopoShape shape, Uint32List edgeIdx, DoubleList dis1, DoubleList dis2);
public static TopoShape Evolved(TopoShape section, TopoShape path, EnumGeomJoinType joinType, bool bSolid);
public static TopoShape Extrude(TopoShape base_, double height, GDir _dir);
// 对所有的边倒圆角
public static TopoShape Fillet(TopoShape shape, double radius);
// 对指定的边倒圆角
public static TopoShape Fillet(TopoShape shape, Uint32List edgeIdx, DoubleList radius);
// 放样
public static TopoShape Loft(TopoShape wireA, TopoShape wireB, bool bSolid);
public static TopoShape Loft(TopoShapeList sketches, bool bSolid, bool bCheckCompatibility);
public static TopoShape OffsetShape(TopoShape shape, double offset, EnumGeomJoinType jointType);
// 曲线偏置
public static TopoShape OffsetWire(TopoShape wire, double offset, double altitude, EnumGeomJoinType jointType, bool openning);
// 回转扫掠
public static TopoShape Revol(TopoShape base_, GAx1 ax, double angle);
// 扫掠
public static TopoShape Sweep(TopoShape section, TopoShape path, EnumGeomFillTrihedron type);
public static TopoShape SweepByEvolution(TopoShape section, TopoShape path, TopoShape evolutionSpline, bool bSolid);
public static TopoShape SweepByFrenet(TopoShape section, TopoShape path, EnumSweepTransitionMode mode, bool bSolid);
public static TopoShape SweepByFrenet(TopoShape section, TopoShape path, EnumSweepTransitionMode mode, bool bSolid, bool wthContact, bool wthCorrection);
public static TopoShape SweepByFrenet(TopoShape section, TopoShape path, EnumSweepTransitionMode mode, bool bSolid, bool wthContact);
public static TopoShape SweepByFrenet2(TopoShapeList sections, TopoShape path, EnumSweepTransitionMode mode, bool bSolid);
// 对指定的面抽壳
public static TopoShape Thickness(TopoShape solid, double offset, Uint32List faceIdx);
//....
}
}
使用FeatureTool.SweepByFrenet构造直角弯管
4. 布尔运算
BooleanTool提供了交(Common)、差(Cut)、并(Fuse)三种布尔运算工具
namespace AnyCAD.Foundation
{
public class BooleanTool
{
// A & B
public static TopoShape Common(TopoShape shapeA, TopoShape shapeB);
// A - B
public static TopoShape Cut(TopoShape shapeA, TopoShape shapeB);
// A + B
public static TopoShape Fuse(TopoShape shapeA, TopoShape shapeB);
}
}
5. 投影
ProjectionTool 提供了点到曲线、点到曲面、曲线到曲面、曲线到平面的投影计算。
namespace AnyCAD.Foundation
{
public class ProjectionTool
{
// 点到曲线
public static ProjCurveResult ProjectOnCurve(GPnt point, TopoShape curve, double tolerance);
// 点到曲面
public static ProjSurfaceResult ProjectOnSurface(GPnt point, TopoShape surface, double tolerance);
// 点到平面
public static TopoShape ProjectOnPlane(TopoShape curve, GPnt planePosition, GDir planeDir, GDir projDir);
public static TopoShape ProjectOnPlane(TopoShape curve, GPnt planePosition, GDir planeDir);
// 曲线到曲面
public static TopoShape ProjectOnSurface(TopoShape curve, TopoShape surface, bool faceBoundaries);
public static TopoShape ProjectOnSurface(TopoShape curve, TopoShape surface);
}
}
6. 小结
从大类上可以把几何造型方法分成两大类:
- 根据参数从无到有创建模型
- ShapeBuilder
- CurveBuilder
- 在已有模型的基础上创建
- FeatureTool
- BooleanTool
- ProjectionTool