# # 快速上手

## # 1. 几何拓扑对象

• 创建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 包含了常见的三维立体对象的创建方法，包括球体、长方体、圆柱体、圆锥、管子等。

## # 2. 显示对象

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

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

``````    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));
}

``````
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上后，添加到场景中便可显示。

TIP

### # 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

## # 4 思考问题

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