二、添加3D形状
几何体的生成主要依赖MeshBuilder类添加和管理,包含如下方法:
目录
几何体
1、立方体 AddBox
2、球体 AddShpere
3、圆环 AddTorus
4、锥体或截锥体 AddCone
5、圆柱体 AddCylinder
6、空心管道 AddPipe
7、圆截面管道 AddTube
8、挤压二维截面 AddExtrudeGeometry
9、多截面放样生成复杂曲面 AddLoftedGeometry
10、规则二十面体 AddRegularIcosahedron
11、光滑球体 AddSubdivisionShpere
12、三角形 AddTriangle、多边形AddQuad,AddPolygon
13、添加椭球体 AddEllipsoid
14、添加带方向的单位面AddFacePZ
15、金字塔 AddPyramid
16、添加箭头
法线、切线及辅助方
几何体
1、立方体 AddBox
void AddBox(Vector3 center, float xlength, float ylength, float zlength, BoxFaces faces = BoxFaces.All)
- 生成一个轴对齐盒子。
center
: 盒子中心点。xlength
,ylength
,zlength
: 盒子在各轴方向的长度。faces
: 指定生成哪些面,默认全部。- 支持重载使用 BoundingBox
2、球体 AddShpere
public void AddSphere(Vector3 center, float radius = 1, int thetaDiv = 32, int phiDiv = 32)
- 生成球体,内部调用 AddEllipsoid。
thetaDiv
: 水平方向分割数,≥ 2。phiDiv
: 垂直方向分割数,≥ 2。
3、圆环 AddTorus
public void AddTorus(float torusDiameter, float tubeDiameter, int thetaDiv = 36, int phiDiv = 24)
- 生成圆环,支持自交圆环。
torusDiameter
: 圆环直径,不能为0。tubeDiameter
: 管道直径,不能为0。thetaDiv
,phiDiv
: 分割数。
4、锥体或截锥体 AddCone
public void AddCone(Vector3 origin, Vector3 direction, float baseRadius, float topRadius, float height, bool baseCap, bool topCap, int thetaDiv)
- 生成锥体或截锥体。
direction
不必归一化。baseCap
、topCap
控制是否封闭底部和顶部。-
builder.AddCone(new Vector3(0, 0, 0), new Vector3(0, 0, 1), 10, 32, 30, true, true, 8);
5、圆柱体 AddCylinder
public void AddCylinder(Vector3 p1, Vector3 p2, float radius = 1, int thetaDiv = 32, bool cap1 = true, bool cap2 = true)