Tuesday, April 24, 2012

surface hexagon double tesselation


import rhinoscriptsyntax as rs


surface = rs.GetObject("surface",8)


udivisions = 10
vdivisions = 10


Udomain = rs.SurfaceDomain(surface,0)
Vdomain = rs.SurfaceDomain(surface,1)


ustep = (Udomain[1]-Udomain[0])/udivisions
vstep = (Vdomain[1]-Vdomain[0])/vdivisions


listofpoints = []
listofnormals = []


normalscale = 3


for i in rs.frange(Udomain[0],Udomain[1],ustep):
    columnslist = []
    normaltemplist = []
    for j in rs.frange(Vdomain[0],Vdomain[1],vstep):
        
        pt = rs.EvaluateSurface(surface,i,j)
        normalvector = rs.SurfaceNormal(surface,[i,j])
        normalvector = rs.VectorUnitize(normalvector)
        normalvector = rs.VectorScale(normalvector,normalscale)
        
        normalpt = rs.VectorAdd(pt,normalvector)
        
        columnslist.append(pt)
        normaltemplist.append(normalpt)
        rs.AddPoint(normalpt)
    
    listofnormals.append(normaltemplist)
    listofpoints.append(columnslist)




for i in range (0,len(listofpoints)-3,4):
    for j in range(0,len(listofpoints[i])-2,2):
        hexpoints = [listofpoints[i][j+1],listofpoints[i+1][j+2],listofpoints[i+2][j+2],listofpoints[i+3][j+1],listofpoints[i+2][j],listofpoints[i+1][j],listofpoints[i][j+1]]
        rs.AddSrfPt([hexpoints[0],hexpoints[1],hexpoints[2],hexpoints[3]])
        rs.AddSrfPt([hexpoints[3],hexpoints[4],hexpoints[5],hexpoints[0]])
        rs.AddCurve(hexpoints,1)


for i in range (0,len(listofnormals)-3,4):
    for j in range(0,len(listofnormals[i])-2,2):
        hexpoints = [listofnormals[i][j+1],listofnormals[i+1][j+2],listofnormals[i+2][j+2],listofnormals[i+3][j+1],listofnormals[i+2][j],listofnormals[i+1][j],listofnormals[i][j+1]]
        rs.AddSrfPt([hexpoints[0],hexpoints[1],hexpoints[2],hexpoints[3]])
        rs.AddSrfPt([hexpoints[3],hexpoints[4],hexpoints[5],hexpoints[0]])
        rs.AddCurve(hexpoints,1)


for i in range (2,len(listofpoints)-3,4):
    for j in range(1,len(listofpoints[i])-2,2):
        hexpoints = [listofpoints[i][j+1],listofpoints[i+1][j+2],listofpoints[i+2][j+2],listofpoints[i+3][j+1],listofpoints[i+2][j],listofpoints[i+1][j],listofpoints[i][j+1]]
        rs.AddSrfPt([hexpoints[0],hexpoints[1],hexpoints[2],hexpoints[3]])
        rs.AddSrfPt([hexpoints[3],hexpoints[4],hexpoints[5],hexpoints[0]])
        rs.AddCurve(hexpoints,1)
        
for i in range (2,len(listofnormals)-3,4):
    for j in range(1,len(listofnormals[i])-2,2):
        hexpoints = [listofnormals[i][j+1],listofnormals[i+1][j+2],listofnormals[i+2][j+2],listofnormals[i+3][j+1],listofnormals[i+2][j],listofnormals[i+1][j],listofnormals[i][j+1]]
        rs.AddSrfPt([hexpoints[0],hexpoints[1],hexpoints[2],hexpoints[3]])
        rs.AddSrfPt([hexpoints[3],hexpoints[4],hexpoints[5],hexpoints[0]])
        rs.AddCurve(hexpoints,1)

No comments:

Post a Comment