编程语言
首页 > 编程语言> > RhinoPython镂空曲面

RhinoPython镂空曲面

作者:互联网

#coding:utf-8
import rhinoscriptsyntax as rs

def SrfPts(srf,intU,intV):
    ptDict={}

    #设定曲面的UV区间
    Udomain=rs.SurfaceDomain(srf,0)
    Vdomain=rs.SurfaceDomain(srf,1)
    print "Udomain:",Udomain
    print "Vdomain:",Vdomain

    #设定曲面UV方向的步长
    stepU=(Udomain[1]-Udomain[0])/intU
    stepV=(Udomain[1]-Udomain[0])/intV
    print "stepU:",stepU
    print "stepV:",stepV

    for i in range(intU+1):
        for j in range(intV+1):
            u=Udomain[0]+stepU*i
            v=Vdomain[0]+stepV*j

            point=rs.EvaluateSurface(srf,u,v)
            ptDict[(i,j)]=point
            # rs.AddPoint(point)

    for i in range(intU+1):
        for j in range(intV+1):
            if i>0 and j>0:
                center=findMidPt(ptDict[i,j],ptDict[i-1,j-1])
                curve1=rs.AddCurve((ptDict[i,j],center,ptDict[i,j-1]),3)
                curve2=rs.AddCurve((ptDict[i,j-1],center,ptDict[i-1,j-1]),3)
                curve3=rs.AddCurve((ptDict[i-1,j-1],center,ptDict[i-1,j]),3)
                curve4=rs.AddCurve((ptDict[i-1,j],center,ptDict[i,j]),3)

                outline=rs.JoinCurves([curve1,curve2,curve3,curve4],True)
                innerline=rs.AddCurve((ptDict[(i,j)],ptDict[(i,j-1)],ptDict[(i-1,j-1)],
                ptDict[(i-1,j)],ptDict[i,j]),3)
                rs.ScaleObject(innerline,center,(0.4,0.4,0.4))

                sweepline=rs.AddLine(ptDict[i,j-1],rs.CurveStartPoint(innerline))
                rs.AddSweep2([outline,innerline],[sweepline])
                rs.DeleteObject(sweepline)

            # rs.AddTextDot((i,j),ptDict[(i,j)])
            # rs.AddPoint(ptDict[i,j])


def findMidPt(point1,point2):
    midPt=((point1[0]+point2[0])/2,
    (point1[1]+point2[1])/2,
    (point1[2]+point2[2])/2,)
    return midPt


def main():
    strSrf=rs.GetObject("select a surface",rs.filter.surface)
    intU=rs.GetInteger("How many u intervals",8)
    intV=rs.GetInteger("How many v intervals",8)
    # rs.HideObject(strSrf)

    SrfPts(strSrf,intU,intV)

main()

 

标签:ptDict,RhinoPython,center,Udomain,rs,intU,intV,曲面,镂空
来源: https://blog.csdn.net/AVE2016/article/details/118916330