Incremental Transformation of UV Panel System Across A Surface [Python Scripting]

incrimental transformation of panel system across surface

This script will vary the transformation panelized system based on the UV coordinates of a surface accoring to the position of each panel on the surface using python in rhino.

 

 


#Generate a varied panelized system on a surface with an incrimental transformation based on the uv positioning
#Jeremy Luebker 2013.04.12
#jluebker.wordpress.com (jeremy.luebker@gmail.com)
import rhinoscriptsyntax as rs

memberPopulation = []

class Member(object):
    
    def __init__(self, SRF, BASESRF):
        self.srf = SRF
        self.baseSrf = BASESRF
        



class PanSyst(object):
    
    def __init__(self,SRTSRF,PANMIN,PANMAX):
        self.SrtSrf = SRTSRF
        self.PanMin = PANMIN
        self.PanMax = PANMAX
        
        self.DivSrf = []
        self.PanSrfs = []
        self.srfCent = []
        #self.srfNorm = []
        #self.srfTan = []
        #self.Dist1 = []
        #self.Dist2 = []
        
        self.GenPan()
        self.setupTopology()
        
    
    
    def GenPan(self):
        
        Pt = {}
        
        #gen srf pts
        self.intU = 6
        self.intV = 4
        
        #find surface domain
        UDomain = rs.SurfaceDomain(self.SrtSrf, 0)
        VDomain = rs.SurfaceDomain(self.SrtSrf, 1)
        
        #set step
        Ustep = (UDomain[1] - UDomain[0]) / self.intU
        Vstep = (VDomain[1] - VDomain[0]) / self.intV
        
        #loop to plot points
        for i in range(self.intU + 1):
            for j in range(self.intV + 1):
                
                #define u and v values based on step
                u = UDomain[0] + Ustep * i
                v = VDomain[0] + Vstep * j
                
                #evaluate surface
                Pt[(i,j)] = rs.EvaluateSurface(self.SrtSrf, u, v)
                
        #create surfaces
        for i in range(self.intU + 1):
            for j in range(self.
            intV + 1):
                if i > 0 and j > 0:
                    DivSrf = rs.AddSrfPt((Pt[(i,j)], Pt[(i-1,j)], Pt[(i-1,j-1)], Pt[(i,j-1)]))
                    rs.HideObject(DivSrf)
                    self.DivSrf.append(DivSrf)
                    
                    #closest point
                    srfCent=rs.SurfaceAreaCentroid(DivSrf)
                    self.srfCent.append(srfCent)
                    
                    closestPt=rs.SurfaceClosestPoint(DivSrf,srfCent[0])
                    #print closestPt
                    
                    ptOnSrf = rs.EvaluateSurface(DivSrf, closestPt[0], closestPt[1])
                    #rs.AddPoint(ptOnSrf)
                    
                    norm = rs.SurfaceNormal(DivSrf, closestPt)
                    
                    unitnorm = rs.VectorUnitize(norm)
                    
                    #need two distance based on uv positions or ij
                    #print i,j
                    unit1 = ((self.PanMin/(self.intU + self.intV)) * (i + j))
                    unit2 = ((self.PanMax/(self.intU + self.intV)) * (i + j))
                    #print unit1, unit2
                    
                    dist1 = rs.VectorScale(unitnorm, unit1)
                    dist2 = rs.VectorScale(unitnorm, unit2)
                    
                    point1 = rs.PointAdd(ptOnSrf, dist1)
                    point2 = rs.PointAdd(ptOnSrf, dist2)
                    #rs.AddPoint(point1)
                    #rs.AddPoint(point2)
                    
                    
                    
                    #####   Generate Panels    ######
                    pt0 = Pt[(i-1,j)]
                    pt1 = Pt[(i-1,j-1)]
                    pt2 = Pt[(i,j-1)]
                    pt3 = Pt[(i,j)]
                    
                    #test
                    #rs.AddPoint(pt0)
                    #rs.AddPoint(pt1)
                    #rs.AddPoint(pt2)
                    #rs.AddPoint(pt3)
                    
                    
                    #EdgeCrv1
                    EdgeCrv1MidCoor = self.MidPt(pt3,pt2)
                    EdgeCrv1MidPt = rs.AddPoint(EdgeCrv1MidCoor)
                    
                    newEdgeCrv1Mid = rs.PointAdd(EdgeCrv1MidPt, dist1)
                    self.EdgeCrv1 = rs.AddInterpCurve((pt3, newEdgeCrv1Mid, pt2))
                    rs.DeleteObjects(EdgeCrv1MidPt)
                    
                    #EdgeCrv2
                    EdgeCrv2MidCoor = self.MidPt(pt2,pt1)
                    EdgeCrv2MidPt = rs.AddPoint(EdgeCrv2MidCoor)
                    
                    newEdgeCrv2Mid = rs.PointAdd(EdgeCrv2MidPt, dist1)
                    self.EdgeCrv2 = rs.AddInterpCurve((pt2, newEdgeCrv2Mid, pt1))
                    rs.DeleteObjects(EdgeCrv2MidPt)
                    
                    #EdgeCrv3
                    temppt0 = rs.AddPoint(pt0)
                    temppt1 = rs.AddPoint(pt1)
                    
                    vec = rs.VectorCreate(pt0,pt1)
                    normVec = rs.VectorUnitize(vec)
                    revVec = rs.VectorReverse(normVec)
                    
                    pt01 = rs.CopyObject(temppt0,revVec*4)
                    
                    newpt01 = rs.PointAdd(pt01, dist2)
                    newpt0 = rs.PointAdd(temppt0, dist2)
                    
                    self.EdgeCrv3 = rs.AddInterpCurve((temppt1,newpt01,newpt0),3,1)
                    rs.DeleteObjects((temppt0,temppt1,pt01))
                    
                    #EdgeCrv4
                    temppt0 = rs.AddPoint(pt0)
                    temppt3 = rs.AddPoint(pt3)
                    
                    vec = rs.VectorCreate(pt0,pt3)
                    normVec = rs.VectorUnitize(vec)
                    revVec = rs.VectorReverse(normVec)
                    
                    pt01 = rs.CopyObject(temppt0,revVec*4)
                    
                    newpt01 = rs.PointAdd(pt01, dist2)
                    newpt0 = rs.PointAdd(temppt0, dist2)
                    
                    self.EdgeCrv4 = rs.AddInterpCurve((temppt3,newpt01,newpt0),3,1)
                    rs.DeleteObjects((temppt0,temppt3,pt01))
                    
                    #rs.DeleteObjects(pts)
                    self.PanSrfs.append(rs.AddEdgeSrf((self.EdgeCrv1,self.EdgeCrv2,self.EdgeCrv3,self.EdgeCrv4)))
                
        
    def setupTopology(self):
        #loop through surfaces
        for i in range(len(self.PanSrfs)):
            memberPopulation.append(Member(self.PanSrfs[i], self.DivSrf[i]))
    
    def MidPt(self, aP1, aP2):
        
        MidPt = None
        MidPt = [(aP1[0] + aP2[0]) / 2,
        (aP1[1] + aP2[1]) / 2,
        (aP1[2] + aP2[2]) / 2]
        return MidPt
        



def main():
    
    #get surface
    SrtSrf = rs.GetObject('select a surface', rs.filter.surface)
    
    #ask user for panMin
    panMin = rs.GetReal('enter a panel minimum height in inches', 6, 0, 8)
    
    #ask user for panMax
    panMax = rs.GetReal('enter a panel maximum height in inches', 14, 3, 20)
    
    
    #rs.HideObject(SrtSrf)
    
    rs.EnableRedraw(False)
    
    #initiate PanSyst
    PanSyst(SrtSrf,panMin,panMax,)
    
    rs.EnableRedraw(True)

if (__name__ == "__main__"):
    main()

Advertisements

~ by jluebker on April 11, 2013.

3 Responses to “Incremental Transformation of UV Panel System Across A Surface [Python Scripting]”

  1. very interesting information, thanks. lista de email lista de email lista de email lista de email lista de email

    Like

  2. how long do you take to write an article or a post like this one? lista de email lista de email lista de email lista de email lista de email

    Like

    • Hi, this was part of an on going to project. i could take me a couple hours to mock something up. then days to weeks to flesh it out, depending on the availability of time. thanks for your interest.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: