Created
March 6, 2017 08:03
-
-
Save AndersDeleuran/8fe9d1a9e76ce42c27cbe930f2d78330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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