Leaf Srf |

### DayTwo_Leaf Paneling

The Leaf Surface investigates the python scripting possibilities to accommodate a fairly simple paneling principle. Panels are bent in the diagonal axis according to their distance parameters to the point of attraction. A surface, populated with these customized elements can create and interesting structure with smooth transitions between closed and open /bent/ quads.CODE:

import rhinoscriptsyntax as rs

#obtain surface from rhino

srf = rs.GetObject("Pick the reference surface",8)

attractor = rs.GetObject("Please pick a Point of attraction",1)

attractorCoord = rs.PointCoordinates(attractor)

#surface domain

uDomain = rs.SurfaceDomain(srf, 0)

vDomain = rs.SurfaceDomain(srf, 1)

#print uDomain,vDomain

uLength = uDomain[1] - uDomain[0]

vLength = vDomain[1] - vDomain[0]

subdivU = 20

subdivV = 20

stepU = uLength/subdivU

stepV = vLength/subdivV

#surface sampling

#main list which will contain sub-list/rows

mainList = []

mainListNormals = []

listDistances = []

rs.EnableRedraw(False)

for i in rs.frange(uDomain[0],uDomain[1]+0.01,stepU):

for j in rs.frange(vDomain[0],vDomain[1]+0.01,stepV):

ptCoord = rs.EvaluateSurface(srf,i,j)

Pt = rs.AddPoint(ptCoord)

distance = rs.Distance(attractor,Pt)

rs.DeleteObject(Pt)

listDistances.append(distance)

listDistances.sort()

distMin = listDistances[0]

distMax = listDistances[len(listDistances)-1]

if distMin > distMax:

distMax = listDistances[0]

distMin = listDistances[len(listDistances)-1]

treshold = (distMax-distMin)*0.5

print distMin

print distMax

for i in rs.frange(uDomain[0],uDomain[1]+0.01,stepU):

#sub-list containing pts

subList = []

subListNormals = []

for j in rs.frange(vDomain[0],vDomain[1]+0.01,stepV):

ptCoord = rs.EvaluateSurface(srf,i,j) #3d coordinates Pt

NormalCoord = rs.SurfaceNormal(srf,[i,j])#3d coordinates Pt offset

PtN = rs.AddPoint(NormalCoord)

Pt = rs.AddPoint(ptCoord) #3d point ID

PtN = rs.VectorUnitize(PtN)

distance = rs.Distance(attractor,Pt)

if (distMax-distance)<treshold:

PtNormal = Pt

else:

PtN = rs.VectorScale(PtN,(distMax-distance-treshold)**2/250)

PtNormal = rs.VectorAdd(Pt,PtN)

subList.append(Pt)

subListNormals.append(PtNormal)

mainListNormals.append(subListNormals)

mainList.append(subList)

#-----------------------------------------------------------------------------

#Paneling

filletRad = 0.5

for i in range(0,len(mainList)-1):

for j in range(0,len(mainList[i])-1):

Pt00 = mainList[i][j]

# Pt01 = mainList[i+1][j]

Pt02 = mainList[i+1][j+1]

# Pt03 = mainList[i][j+1]

# Pts = [Pt00,Pt01,Pt02,Pt03,Pt00]

# rs.AddCurve(Pts,1)

# Pt00N = mainListNormals[i][j]

Pt01N = mainListNormals[i+1][j]

# Pt02N = mainListNormals[i+1][j+1]

Pt03N = mainListNormals[i][j+1]

# PtsN = [Pt00N,Pt01N,Pt02N,Pt03N,Pt00N]

Pts001 = [Pt00,Pt01N]

Pts002 = [Pt01N,Pt02]

Pts011 = [Pt02,Pt03N]

Pts012 = [Pt03N,Pt00]

crv01 = rs.AddCurve(Pts001,2)

crv02 = rs.AddCurve(Pts002,2)

crv11 = rs.AddCurve(Pts011,2)

crv12 = rs.AddCurve(Pts012,2)

#add fillets

strFilletCrv00 = rs.AddFilletCurve(crv12,crv01,filletRad)

strFilletCrv10 = rs.AddFilletCurve(crv11,crv02,filletRad)

#evaluate fillets for points

dblFilletCrvDomain00 = rs.CurveDomain(strFilletCrv00)

FilletPt00 = rs.EvaluateCurve(strFilletCrv00,dblFilletCrvDomain00[0])

FilletPt01 = rs.EvaluateCurve(strFilletCrv00,dblFilletCrvDomain00[1])

dblFilletCrvDomain10 = rs.CurveDomain(strFilletCrv10)

FilletPt10 = rs.EvaluateCurve(strFilletCrv10,dblFilletCrvDomain10[0])

FilletPt11 = rs.EvaluateCurve(strFilletCrv10,dblFilletCrvDomain10[1])

#add new lines inbetween the quad corners and the fillet ends

crv01 = rs.AddCurve([Pt03N,FilletPt00],3)

crv02 = rs.AddCurve([Pt01N,FilletPt01],3)

crv11 = rs.AddCurve([Pt03N,FilletPt10],3)

crv12 = rs.AddCurve([Pt01N,FilletPt11],3)

#join the fillets and curves and loft them to a surface

joinedCrv01 = rs.JoinCurves([crv01,strFilletCrv00,crv02],True)

joinedCrv02 = rs.JoinCurves([crv11,strFilletCrv10,crv12],True)

# print joinedCrv01[0]

rs.RebuildCurve(joinedCrv01[0],3,30)

rs.RebuildCurve(joinedCrv02[0],3,30)

rs.AddLoftSrf([joinedCrv01[0],joinedCrv02[0]])

rs.EnableRedraw(True)