surface Components [class 20091208/11]
this script is pretty much same with the one in the previous post.
the additional function “cell” adds a cellular component on the surface.
Option Explicit
'Script written by onur yuce gun
'Script copyrighted by
'Script version Friday, December 11, 2009 11:25:09 AM
Call Main()
Sub Main()
rhino.AddLayer "border"
rhino.AddLayer "cell"
'get input surface
Dim srf
srf = Rhino.GetObject("select surface",8)
'get the division numbers for U and v directions
Dim uRes
Dim vRes
uRes = rhino.GetInteger ("enter u division number",10)
vRes = rhino.GetInteger ("enter v division number",10)
'call the function to evaluate the surface
Dim uvPt
uvPt = srfPt(srf, uRes, vRes)
Dim m
Dim n
Dim myCell
For m = 0 To uRes-1
For n = 0 To vRes-1
'cell is the fucntion defined at the bottom of the code
myCell = cell(uvPt(m,n),uvPt(m+1,n),uvPt(m+1,n+1),uvPt(m,n+1),floor((m+n)/4)+4 )
Next
Next
End Sub
Function srfPt(iSrf, iUNum, iVNum) 'inputs
'define domain variables
Dim domU_iSrf
Dim domV_iSrf
'find surface domain
domU_iSrf = Rhino.SurfaceDomain (iSrf,0)
domV_iSrf = Rhino.SurfaceDomain (iSrf,1)
'define uv parameter variables
Dim uParam
Dim vParam
Dim uvParam
'define variable For surface points
Dim pt
'convert pt into an array
ReDim pt(iuNum, ivNum)
Dim i,j
For i = 0 To iuNum
For j = 0 To ivNum
uParam = (domU_iSrf(1)/iuNum)*i
vParam = (domV_iSrf(1)/ivNum)*j
uvParam = Array(uParam,vParam)
pt(i,j) = rhino.EvaluateSurface (iSrf, uvParam)
rhino.AddPoint pt(i,j)
Next
Next
srfPt = pt
End Function
'this function creates a cell
Function cell(pt1,pt2,pt3,pt4,cellDiv)
Dim border
border = rhino.AddPolyline (Array(pt1,pt2,pt3,pt4,pt1))
rhino.ObjectLayer border, "border"
Dim divPts
divPts = Rhino.DivideCurve (border, cellDiv)
'rhino.Print UBound(divPts)
ReDim Preserve divPts(cellDiv)
divPts(cellDiv) = divPts(0)
Dim cellCrv
cellCrv = rhino.addCurve (divPts)
rhino.ObjectLayer cellCrv, "cell"
End Function
Advertisement


