Option Explicit 'Script written by rwr 'Script is open source 'Script version Saturday, August 16, 2009 12:58:23 PM '------------------------------------------------------------------------------ ' Purpose: Creates a counter fold folded-plate on a context surface '------------------------------------------------------------------------------ Call Main() Sub Main() Dim strsrf : strsrf = rhino.getobject("select a surface to populate",8) If IsNull(strSrf) Then Exit Sub Dim uDiv : uDiv = Rhino.GetInteger("divisions in U direction", 25) Dim vDiv : vDiv = Rhino.GetInteger("divisions in V direction", 3) 'declare offset height variable and value Dim height : height = Rhino.GetReal ("offset height",30) Dim uDomain : uDomain = Rhino.SurfaceDomain(strsrf,0) Dim vDomain : vDomain = Rhino.SurfaceDomain(strsrf,1) Dim ustep : ustep = (uDomain(1)-uDomain(0))/uDiv Dim vstep : vstep = (vDomain(1)-vDomain(0))/vDiv Dim u, v 'Rhino.EnableRedraw(False) For u = 0 To uDomain(1)-ustep Step ustep For v = 0 To vDomain(1)-vstep Step vstep Dim uvPoint, arrData, proPoint1, proPoint2, proPoint3, proPoint4, proPoint5, proPoint6, proPoint7, proPoint8, proPoint9 'call srfCurvature function uvPoint = Array (u,v) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint1 = offsetCalc(arrData, 0) 'call srfCurvature function uvPoint = Array (u,v+vstep/2) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint2 = offsetCalc(arrData, height) 'call srfCurvature function uvPoint = Array (u+ustep/2,v+vstep/2) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint3 = offsetCalc(arrData, 0) 'call srfCurvature function uvPoint = Array (u+ustep/2,v) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint4 = offsetCalc(arrData, height) 'call srfCurvature function uvPoint = Array (u+ustep,v) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint5 = offsetCalc(arrData, 0) 'call srfCurvature function uvPoint = Array (u+ustep,v+vstep/2) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint6 = offsetCalc(arrData, height) 'call srfCurvature function uvPoint = Array (u,v+vstep) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint7 = offsetCalc(arrData, 0) 'call srfCurvature function uvPoint = Array (u+ustep/2,v+vstep) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint8 = offsetCalc(arrData, height) 'call srfCurvature function uvPoint = Array (u+ustep,v+vstep) arrData = srfCurvature (strsrf, uvPoint) 'call offsetCalc function, offset distance is 'height' proPoint9 = offsetCalc(arrData, 0) 'create planar surfaces through 3 points Dim strSrf1, strSrf2, strSrf3, strSrf4, strSrf5, strSrf6, strSrf7, strSrf8 strSrf1 = rhino.AddSrfPt(array(proPoint1, proPoint2, proPoint3)) strSrf2 = rhino.AddSrfPt(array(proPoint1, proPoint3, proPoint4)) strSrf3 = rhino.AddSrfPt(array(proPoint4, proPoint3, proPoint5)) strSrf4 = rhino.AddSrfPt(array(proPoint5, proPoint3, proPoint6)) strSrf5 = rhino.AddSrfPt(array(proPoint2, proPoint7, proPoint3)) strSrf6 = rhino.AddSrfPt(array(proPoint3, proPoint7, proPoint8)) strSrf7 = rhino.AddSrfPt(array(proPoint3, proPoint8, proPoint9)) strSrf8 = rhino.AddSrfPt(array(proPoint3, proPoint9, proPoint6)) Next Next 'Rhino.EnableRedraw(True) End Sub Function srfCurvature (strsrf, uvPoint) Dim arrPoint, arrParam 'evaluate point arrPoint = Rhino.EvaluateSurface (strsrf, uvPoint) 'returns the UV parameter of the point on the surface that is closest to the current uv step arrParam = Rhino.SurfaceClosestPoint(strsrf, arrPoint) If IsArray(arrParam) Then 'returns the curvature of a surface at a U,V parameter srfCurvature = Rhino.SurfaceCurvature(strsrf, arrParam) If IsArray(srfCurvature) Then End If End If End Function Function offsetCalc(arrData, height) Dim vscaled vscaled = VectorScale(arrData(1),height) offsetCalc = VectorAdd(vscaled,arrData(0)) End Function 'function by RMA, "vectors.rvb" Function VectorAdd(v1, v2) VectorAdd = Null If Not IsArray(v1) Or (UBound(v1) <> 2) Then Exit Function If Not IsArray(v2) Or (UBound(v2) <> 2) Then Exit Function VectorAdd = Array(v1(0) + v2(0), v1(1) + v2(1), v1(2) + v2(2)) End Function 'function by RMA, "vectors.rvb" Function VectorScale(v, d) VectorScale = Null If Not IsArray(v) Or (UBound(v) <> 2) Then Exit Function If Not IsNumeric(d) Then Exit Function VectorScale = Array(v(0) * d, v(1) * d, v(2) * d) End Function