# 几何对象 ​

## 1. 几何拓扑对象 ​

csharp
``````TopoShape rect = SketchBuilder.MakeRectangle(GP.XOY(), 30, 40, 5, false);

// 显示出来
mRenderView.ShowShape(rect, ColorTable.Green);``````

### 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. 几何显示对象 ​

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

csharp
``````var shape = ShapeBuilder.MakeSphere(new GPnt(), 1);
var bufferShape = new BufferShape(shape, null, null, 0.01);//可以自己指定显示精度
bufferShape.Build(); // 初始化

float distance = 3.0f;
int halfCount = 5;

var scene = mRenderView.Scene;
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));
// 加到场景中
}``````

### 2.1 BufferGeometry ​

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

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

TIP

### 2.2 GeometryBuilder ​

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

csharp
``````// 构造形状
var geom = GeometryBuilder.CreateCylinder(10, 3, 10);
// 设置为灰色
var materail = mRenderView.GetMaterial(ColorTable.LightGray, 0);
var cylPrim = new PrimitiveSceneNode(geom, materail);
// 设置位置
cylPrim.SetTransform(Matrix4.makeTranslation(-30, 0, 0));
mRenderView.ShowSceneNode(cylPrim);``````

## 4 思考问题 ​

1. 几何对象和显示对象的区别和联系是什么？
1. 显示对象的应用场景是什么？
1. 几何对象的应用场景是什么？