import rhinoscriptsyntax as rs
crv = rs.GetObjects("Select curves in order")
att_pt1 = rs.GetObject("Select attractor pt 1")
#att_pt2 = rs.GetObject("Select attractor pt 2")
#CREATE LOFTED SURFACE FROM CURVES
#(Curves should be of same degree and to be selected IN ORDER)
srf = rs.AddLoftSrf(crv)
ud=rs.SurfaceDomain(srf,0)
vd=rs.SurfaceDomain(srf,1)
print ud
print vd
lenu=ud[1]-ud[0]
lenv=vd[1]-vd[0]
print lenu
print lenv
#if rs.IsSurface(srf):
#u = ud[1]/2.0
#v = vd[1]/2.0
#point = rs.EvaluateSurface(srf, u, v)
#
#rs.AddPoints(point)
pts=[]
for i in rs.frange(ud[0],ud[1]+1,lenu/40):
plist=[]
for j in rs.frange(vd[0],vd[1]+lenv/40,lenv/40):
plist.append(rs.EvaluateSurface(srf,i,j))
pts.append(plist)
#rs.DeleteDocumentData(pts)
#rlist=[]
#rlist.append(plist)
#for i in range(0,len(rlist)):
# for j in range(0,len(rlist[i])):
# rs.AddPoint(rlist[i][j])
pline=[]
cpts=[]
def CP(p):
for i in range(0,len(p)):
x=(p[0][0]+p[1][0]+p[2][0]+p[3][0]+p[4][0]+p[5][0])/6
y=(p[0][1]+p[1][1]+p[2][1]+p[3][1]+p[4][1]+p[5][1])/6
z=(p[0][2]+p[1][2]+p[2][2]+p[3][2]+p[4][2]+p[5][2])/6
fakesrf = rs.AddSrfPt([p[0],p[1],p[2],p[3]])
ud=rs.SurfaceDomain(fakesrf,0)
vd=rs.SurfaceDomain(fakesrf,1)
n=rs.SurfaceNormal(fakesrf,[ud[1],vd[1]])
n=rs.VectorUnitize(n)
rs.DeleteObject(fakesrf)
return [[x,y,z],n]
for i in range(0,(len(pts)-2),2):
for j in range(1,(len(pts[i])-3),4):
p=[pts[i+1][j+0],pts[i+2][j+1],pts[i+2][j+2],pts[i+1][j+3],pts[i+0][j+2],pts[i+0][j+1],pts[i+1][j+0]]
pline=rs.AddPolyline(p)
retlist = CP(p)
dist = rs.Distance(att_pt1,retlist[0])
v=rs.VectorScale(retlist[1],(dist*100))
midpt=retlist[0]
newpline=rs.CopyObject(pline,-(retlist[1]*dist)/3)
newpline=rs.RotateObject(newpline,midpt,30)
newpline=rs.ScaleObject(newpline,midpt,(.2,.2,.2))
rs.AddLoftSrf([pline,newpline])
#rs.CopyObject(pline,
#npt = nf(midpt)
#normals.append(rs.SurfaceNormal(srf,midpt)
#cpts.append(rs.AddPoints(CP))
#extracted_pts.append(rs.CurvePoints(pline))
#rs.CurvePoints(
#print extracted_pts
pline_two=[]
for i in range(1,(len(pts)-2),2):
for j in range(3,(len(pts[i])-3),4):
p=[pts[i+1][j+0],pts[i+2][j+1],pts[i+2][j+2],pts[i+1][j+3],pts[i+0][j+2],pts[i+0][j+1],pts[i+1][j+0]]
pline=rs.AddPolyline(p)
retlist = CP(p)
midpt=retlist[0]
newpline=rs.CopyObject(pline,-(retlist[1]*dist)/3)
newpline=rs.RotateObject(newpline,midpt,30)
newpline=rs.ScaleObject(newpline,midpt,(.2,.2,.2))
rs.AddLoftSrf([pline,newpline])
No comments:
Post a Comment