Organize mesh faces

List Navigation:
Hello all, I just wrote a script, but I am having trouble organizing my verticessrf to (3.1 KB) points for an appropriate match (squares of triangles), it works with inputs 4/4 only. Any ideas, also, in general how is this usually done?

If you are using Rhino 6, you could try a slightly different approach. Instead of manually creating data paths, you can use the built-in treehelpers. That way, you can structure your data in nested lists and let the tree helpers handle the data tree/path stuff. You could also store the points in a dictionary, with the point being the value, and the u and v, (or i and j) being the keys.
As far as how this is “usually” done…I can suggest one approach that I use, (but that is not to say that this is the ONLY/USUAL way to do this…)
1 - reparameterizing the surface into a domain that matches your U and V input,
2 - Create a grid of surface points
3 - walk through the grid and make some mesh faces

This is the major part of the code described above. (NOTE: This is taken from some other code I wrote for “stripping” things. Not guaranteed to work on every conceivable surface, but this is pretty reliable).

"""Mesh Surface UV - Create Mesh from Surface and UV input.
        srf: input surface
        U: U Division
        V: V Division
        FaceType: 0 = Quad, 1 = Tri
        grid: grid of points
        M: resulting UV Mesh"""

__author__ = "chanley"
__version__ = "2019.02.04"

import Rhino
import ghpythonlib.treehelpers as th

pts = {} # create dictionary to hold keys (i, j) and values (points)
grid = [] # list to recieve points, will be used for nested list->data tree

# set domain of surface to match U and V
def setDomain(): 
    UDomain = Rhino.Geometry.Interval(0,U)
    VDomain = Rhino.Geometry.Interval(0,V)
    srf.SetDomain(0, UDomain)
    srf.SetDomain(1, VDomain)

# nested loop to create structured grid of points
# (i,j) as keys, points as values in dict.
def makeUVGrid():
    for i in range(0,U+1):
        gcolumn = []
        for j in range(0,V+1):
            pts[(i,j)] = Rhino.Geometry.Surface.PointAt(srf,i,j)

def makeMesh():
    MeshFaces = []  #list of meshes, one mesh for each face
    # Walk through grid of points and make mesh quads/tri
    for i in range(0, U):
        for j in range(0, V):
            NewMeshFace = Rhino.Geometry.Mesh()
            if FaceType != 1:
                NewMeshFace.Faces.AddFace(0, 1, 2, 3)
                NewMeshFace.Faces.AddFace(0, 1, 2)
                NewMeshFace.Faces.AddFace(0, 2, 3)
    JoinedMesh = Rhino.Geometry.Mesh()
    return JoinedMesh

M = makeMesh()
grid = th.list_to_tree(grid)

srf to (150.1 KB)