import rhinoscriptsyntax as rs
import random
import math
def cenPt(_ptL):
ptL = _ptL
xL = []
yL = []
zL = []
for i in range (0,len(ptL)):
#pt = rs.PointCoordinates(ptL[i])
Xval = ptL[i][0]
xL.append(Xval)
Yval = ptL[i][1]
yL.append(Yval)
Zval = ptL[i][2]
zL.append(Zval)
cenPt = rs.AddPoint([math.fsum(xL)/len(xL),math.fsum(yL)/len(yL),math.fsum(zL)/len(zL)])
return cenPt
srf = rs.GetObject('select surface',8)
attractor = rs.GetObject('attractor',1)
shellThick = rs.GetReal('shell scale')
uDom = rs.SurfaceDomain(srf,0)
vDom = rs.SurfaceDomain(srf,1)
uDivide = 30
vDivide = 30
Ustep = (uDom[1]-uDom[0])/int(uDivide)
Vstep = (vDom[1]-vDom[0])/int(vDivide)
rs.EnableRedraw(False)
ptL = []
normalList = []
rowList = []
vectorScale = -2
for i in rs.frange(uDom[0],uDom[1],Ustep):
colList = []
tempNorm = []
for j in rs.frange(vDom[0],vDom[1]+Vstep,Vstep):
eval = rs.EvaluateSurface(srf,i,j)
colList.append(eval)
normal = rs.SurfaceNormal(srf,(i,j))
normal = rs.VectorUnitize(normal)
normal = rs.VectorScale(normal,vectorScale)
normPt = rs.VectorAdd(eval,normal)
tempNorm.append(normPt)
normalList.append(tempNorm)
rowList.append(colList)
maxDist = 0
for i in range (0,len(rowList)-3,4):
for j in range (0,len(rowList[i])-2,2):
cen = cenPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
dist = rs.Distance(cen,attractor)
if dist>maxDist:
maxDist = dist
for i in range (0,len(rowList)-3,4):
for j in range (0,len(rowList[i])-2,2):
tmpL = []
tmpL2 = []
tmpL3 = []
tmpL4 = []
tmpL5 = []
tmpL6 = []
poly = rs.AddPolyline((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
offset = rs.AddPolyline((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
offsetCirc = rs.AddCurve((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
rs.ObjectLayer(offset,"Bottom")
rs.ObjectLayer(offsetCirc,"Bottom")
tmpL2.append(offset)
tmpL2.append(offsetCirc)
tmpL3.append(offset)
tmpL3.append(poly)
polyBase = rs.ScaleObject(poly,cenPt(rs.CurveEditPoints(poly)),[shellThick,shellThick,shellThick],True)
polyBase = rs.AddCurve(rs.CurveEditPoints(polyBase),3)
tmpL.append(poly)
# tmpL4.append(poly)
# tmpL4.append(polyBase)
tmpL5.append(polyBase)
tmpL5.append(offsetCirc)
cen = cenPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
dist = rs.Distance(cen,attractor)/maxDist
norm = rs.SurfaceNormal(srf,rs.SurfaceClosestPoint(srf,cen))
copyVect = rs.VectorUnitize(norm)
copyVect = rs.VectorScale(copyVect,math.pow(dist,3)*50)
polyScale = rs.ScaleObject(poly,cen,[.2/dist,.2/dist,.2/dist],True)
circ = rs.AddCurve(rs.CurveEditPoints(polyScale))
circ = rs.ScaleObject(circ,cen,[.3/dist,.3/dist,.3/dist])
circ = rs.MoveObject(circ,rs.VectorScale(copyVect,1.4))
tmpL.append(circ)
# tmpL.append(polyBase)
center = cenPt(rs.CurveEditPoints(polyScale))
move = rs.MoveObject(polyScale,copyVect)
moveScale = rs.ScaleObject(move,cenPt(rs.CurveEditPoints(move)),[shellThick,shellThick,shellThick],True)
tmpL6.append(moveScale)
tmpL6.append(polyBase)
# tmpL.append(move)
tmpL.append(moveScale)
# tmpL.append(circ)
nip = rs.AddLoftSrf(tmpL)
# shell = rs.AddLoftSrf(tmpL2)
shell2 = rs.AddLoftSrf(tmpL3)
# shell3 = rs.AddLoftSrf(tmpL4)
shell4 = rs.AddLoftSrf(tmpL5)
shell5 = rs.AddLoftSrf(tmpL6)
#
#for i in range (0,len(normalList)-3,4):
# for j in range (0,len(normalList[i])-2,2):
# cen = rs.PointCoordinates(cenPt((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2])))
# hex = rs.AddPolyline((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
# hexL.append(hex)
for i in range (2,len(rowList)-3,4):
for j in range (1,len(rowList[i])-2,2):
cen = cenPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
dist = rs.Distance(cen,attractor)
if dist>maxDist:
maxDist = dist
for i in range (2,len(rowList)-3,4):
for j in range (1,len(rowList[i])-2,2):
tmpL = []
tmpL2 = []
tmpL3 = []
tmpL4 = []
tmpL5 = []
tmpL6 = []
poly = rs.AddPolyline((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
offset = rs.AddPolyline((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
offsetCirc = rs.AddCurve((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
rs.ObjectLayer(offset,"Bottom")
rs.ObjectLayer(offsetCirc,"Bottom")
tmpL2.append(offset)
tmpL2.append(offsetCirc)
tmpL3.append(offset)
tmpL3.append(poly)
polyBase = rs.ScaleObject(poly,cenPt(rs.CurveEditPoints(poly)),[shellThick,shellThick,shellThick],True)
polyBase = rs.AddCurve(rs.CurveEditPoints(polyBase),3)
tmpL.append(poly)
# tmpL4.append(poly)
# tmpL4.append(polyBase)
tmpL5.append(polyBase)
tmpL5.append(offsetCirc)
cen = cenPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
dist = rs.Distance(cen,attractor)/maxDist
norm = rs.SurfaceNormal(srf,rs.SurfaceClosestPoint(srf,cen))
copyVect = rs.VectorUnitize(norm)
copyVect = rs.VectorScale(copyVect,math.pow(dist,3)*50)
polyScale = rs.ScaleObject(poly,cen,[.2/dist,.2/dist,.2/dist],True)
circ = rs.AddCurve(rs.CurveEditPoints(polyScale))
circ = rs.ScaleObject(circ,cen,[.3/dist,.3/dist,.3/dist])
circ = rs.MoveObject(circ,rs.VectorScale(copyVect,1.4))
tmpL.append(circ)
# tmpL.append(polyBase)
center = cenPt(rs.CurveEditPoints(polyScale))
move = rs.MoveObject(polyScale,copyVect)
moveScale = rs.ScaleObject(move,cenPt(rs.CurveEditPoints(move)),[shellThick,shellThick,shellThick],True)
tmpL6.append(moveScale)
tmpL6.append(polyBase)
# tmpL.append(move)
tmpL.append(moveScale)
# tmpL.append(circ)
nip = rs.AddLoftSrf(tmpL)
# shell = rs.AddLoftSrf(tmpL2)
shell2 = rs.AddLoftSrf(tmpL3)
# shell3 = rs.AddLoftSrf(tmpL4)
shell4 = rs.AddLoftSrf(tmpL5)
shell5 = rs.AddLoftSrf(tmpL6)
3D Print
No comments:
Post a Comment