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()

RhinoPython镂空曲面

 

上一篇:Nginx配置域名统一http跳转带www的https链接


下一篇:关于tool层的导入,以及全局的变量限制