幾何體的生成主要依賴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)