RhinoCommon 使用点(点云)构建Mesh
2020-08-05 本文已影响0人
锦囊喵
https://csharp.hotexamples.com/examples/-/Rhino/-/php-rhino-class-examples.html
如何使用RhinoCommon 使用点(点云)构建Mesh,以下为参考代码
public static Rhino.Commands.Result AddMesh(Rhino.RhinoDoc doc)
{
Rhino.Geometry.Mesh mesh = new Rhino.Geometry.Mesh();
mesh.Vertices.Add(0.0, 0.0, 1.0); //0
mesh.Vertices.Add(1.0, 0.0, 1.0); //1
mesh.Vertices.Add(2.0, 0.0, 1.0); //2
mesh.Vertices.Add(3.0, 0.0, 0.0); //3
mesh.Vertices.Add(0.0, 1.0, 1.0); //4
mesh.Vertices.Add(1.0, 1.0, 2.0); //5
mesh.Vertices.Add(2.0, 1.0, 1.0); //6
mesh.Vertices.Add(3.0, 1.0, 0.0); //7
mesh.Vertices.Add(0.0, 2.0, 1.0); //8
mesh.Vertices.Add(1.0, 2.0, 1.0); //9
mesh.Vertices.Add(2.0, 2.0, 1.0); //10
mesh.Vertices.Add(3.0, 2.0, 1.0); //11
mesh.Faces.AddFace(0, 1, 5, 4);
mesh.Faces.AddFace(1, 2, 6, 5);
mesh.Faces.AddFace(2, 3, 7, 6);
mesh.Faces.AddFace(4, 5, 9, 8);
mesh.Faces.AddFace(5, 6, 10, 9);
mesh.Faces.AddFace(6, 7, 11, 10);
mesh.Normals.ComputeNormals();
mesh.Compact();
if (doc.Objects.AddMesh(mesh) != Guid.Empty)
{
doc.Views.Redraw();
return Rhino.Commands.Result.Success;
}
return Rhino.Commands.Result.Failure;
}
以上代码生成的mesh,各个面都是四边形;若要生成三边形,请参考以下代码:
import rhinoscriptsyntax as rs
vertices = []
vertices.append((0.0,0.0,0.0))
vertices.append((5.0, 0.0, 0.0))
vertices.append((10.0, 0.0, 0.0))
vertices.append((0.0, 5.0, 0.0))
vertices.append((5.0, 5.0, 0.0))
vertices.append((10.0, 5.0, 0.0))
vertices.append((0.0, 10.0, 0.0))
vertices.append((5.0, 10.0, 0.0))
vertices.append((10.0, 10.0, 0.0))
faceVertices = []
faceVertices.append((0,1,4,4))
faceVertices.append((2,4,1,1))
faceVertices.append((0,4,3,3))
faceVertices.append((2,5,4,4))
faceVertices.append((3,4,6,6))
faceVertices.append((5,8,4,4))
faceVertices.append((6,4,7,7))
faceVertices.append((8,7,4,4))
rs.AddMesh( vertices, faceVertices )