Skip to content

Instantly share code, notes, and snippets.

@AndersDeleuran
Created March 6, 2017 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndersDeleuran/8fe9d1a9e76ce42c27cbe930f2d78330 to your computer and use it in GitHub Desktop.
Save AndersDeleuran/8fe9d1a9e76ce42c27cbe930f2d78330 to your computer and use it in GitHub Desktop.
import Rhino as rc
def meshEndFaces(mesh):
""" Get indices of faces with only one neighbour """
endFaces = []
for i in range(mesh.Faces.Count):
af = mesh.Faces.AdjacentFaces(i)
if len(af) == 1:
endFaces.append(i)
return endFaces
def lowestEndFace(mesh):
""" Get index of lowest end face """
efA,efB = meshEndFaces(mesh)
efAZ = mesh.Faces.GetFaceCenter(efA).Z
efBZ = mesh.Faces.GetFaceCenter(efB).Z
if efAZ < efBZ:
ef = efA
else:
ef = efB
return ef
def orderMeshStripFaces(mesh):
""" Reorder the faces to start from the lowest end face (by Z values )"""
if mesh.Faces.Count > 1:
# Make new mesh and vertices to it
nMesh = rc.Geometry.Mesh()
nMesh.Vertices.AddVertices(mesh.Vertices.ToPoint3dArray())
# Add faces starting from lowest end face
vf = [lowestEndFace(mesh)]
for i in range(mesh.Faces.Count):
# Add face
nMesh.Faces.AddFace(mesh.Faces[vf[-1]])
# Get index of next face
fnb = mesh.Faces.AdjacentFaces(vf[-1])
nf = list(set(fnb) - set(vf))
if nf:
vf.append(nf[0])
# Set normals, color and return nMesh
nMesh.Normals.ComputeNormals()
nMesh.FaceNormals.ComputeFaceNormals()
if mesh.VertexColors.Count:
nMesh.VertexColors.CreateMonotoneMesh(mesh.VertexColors.Item[0])
return nMesh
else:
return mesh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment