# 快速上手

环境搭建一节中,我们已经完成了环境设置,本节将简要介绍ARS的使用流程。

# 1. 几何拓扑对象

比如在XOY平面上创建一个30 X 40、圆角半径位5的矩形,可以如下实现:

  • 创建TopoShape对象
  • 显示为绿色
    TopoShape rect = SketchBuilder.MakeRectangle(GP.XOY(), 30, 40, 5, false);

    mRenderView.ShowShape(rect, Vector3.Green);
1
2
3

# 1.1 TopoShape

TopoShape 表示几何拓扑对象,可以是顶点、边、面、体、复合体等,是物体的边界表达(Boundary Representation,BREP)

维基百科:

In solid modeling and computer-aided design, boundary representation—often abbreviated as B-rep or BREP—is a method for representing shapes using the limits. A solid is represented as a collection of connected surface elements, the boundary between solid and non-solid.

Boundary representation of models are composed of two parts: topology and geometry (surfaces, curves and points). The main topological items are: faces, edges and vertices. A face is a bounded portion of a surface; an edge is a bounded piece of a curve and a vertex lies at a point. Other elements are the shell (a set of connected faces), the loop (a circuit of edges bounding a face) and loop-edge links (also known as winged edge links or half-edges) which are used to create the edge circuits. The edges are like the edges of a table, bounding a surface portion.

# 1.2 SketchBuilder

SketchBuilder 包含了常见的三维平面基本体对象创建方法,包括点、直线段、圆弧曲线、长方形、多边形、BSpline等。

# 1.3 ShapeBuilder

ShapeBuilder 包含了常见的三维立体对象的创建方法,包括球体、长方体、圆柱体、圆锥、管子等。

# 1.4 试一试

调用SketchBuilder和ShapeBuilder创建一下常见的平面图形和立体图形。

# 2. 显示对象

TopoShape本身不能直接用于显示,RenderControl.ShowShape方法内部会通过BufferShape把TopoShape转换成BufferGeometry对象,挂接到BrepSceneNode对象上,添加到场景Scene中才能显示。引用关系如下:

显示TopoShape

BufferShape跟TopoShape是一一对应,但同一个BufferShape可以放在不同的BrepSceneNode中。因此,具有相同形状的几何对象,但位置不一样的话,可以利用这个机制实现实例绘制。

TopoShape实例绘制

示例,使用实例技术快速创建1000个球:

    var shape = ShapeBuilder.MakeSphere(new GPnt(), 1);
    var bufferShape = new BufferShape(shape);
    bufferShape.Build(); // 初始化

    float distance = 3.0f;
    int halfCount = 5;

    var scene = mRenderView.GetScene();
    for (int ii = -halfCount; ii < halfCount; ++ii)
        for (int jj = -halfCount; jj < halfCount; ++jj)
            for (int kk = -halfCount; kk < halfCount; ++kk)
            {
                var node = new BrepSceneNode(bufferShape);
                node.SetTransform(Matrix4.makeTranslation(ii * distance, jj * distance, kk * distance));
                scene.AddNode(node);
            }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 2.1 BufferGeometry

BufferGeometry描述了可以用于显示的图元,包括点、线段、三角网格(Mesh)。TopoShape本质上是转成了BufferGeometry才显示的。

BufferGeometry挂接到PrimitiveSceneNode上后,添加到场景中便可显示。

BufferGeometry与Scene关系

TIP

使用BufferGeometry可以描述任意形状的物体(点、线、面)。可以使用自己的顶点、法线、纹理贴图坐标等信息构造显示对象。

# 2.2 GeometryBuilder

GeometryBuilder封装了快速创建显示基本体,包括Box、Sphere、Cylinder、Plane等。

示例:创建一个圆台体

    var geom = GeometryBuilder.CreateCylinder(10, 3, 10);
    var cylPrim = new PrimitiveSceneNode(geom, EnumPrimitiveType.TRIANGLES);
    // 设置为灰色
    var materail = mRenderView.GetMaterial(Vector3.LightGray, 0);
    cylPrim.SetMaterial(materail);
    cylPrim.SetTransform(Matrix4.makeTranslation(-30, 0, 0));
    mRenderView.ShowSceneNode(cylPrim);
1
2
3
4
5
6
7

效果如下:

圆台体

示例: 使用GeometryBuilder.CreatePoints构造自定义的点云

点云

# 3 小结

本小结简单介绍了创建几何对象TopoShape和显示对象BufferGeometry,以及如何通过SceneNode把几何对象和显示对象挂接到场景中显示。

# 4 思考问题

    1. 几何对象和显示对象的区别和联系是什么?
    1. 显示对象的应用场景是什么?
    1. 几何对象的应用场景是什么?
Last Updated: 9/30/2020, 10:28:51 PM