Option explicit 'component surface array 'Chicho Goldberg 'TopPopCola 'modified from 'skin panel prototype 'joshua vermillion Dim sourceSurface, uDiv, vDiv, height Dim uStep, vStep Dim uVal, vVal Dim ap1 ,ap2 Dim ap1n, ap2n Dim parentLayer Sub panel Dim i, j ,k Dim sourceCurves sourceSurface = Rhino.GetObject("Select a surface to populate", 8,, True) 'sourceCurves = Rhino.GetObjects("Select curves", 4,, True) parentLayer = Rhino.GetString("Enter layer name", 1) uDiv = Rhino.GetInteger("Enter the number of divisions in the U direction", 40, 1) vDiv = Rhino.GetInteger("Enter the number of divisions in the V direction", 40, 1) height = Rhino.GetReal("Enter a height/width (0-1)", .5) 'Rhino.Command "SelNone" 'Rhino.LastCreatedObjects True Rhino.Command "Reparameterize 0 1 0 1 " ReDim ap1 ((uDiv-1),(vDiv-1)) ReDim ap2 ((uDiv-1),(vDiv-1)) ReDim ap1n ((uDiv-1),(vDiv-1)) ReDim ap2n ((uDiv-1),(vDiv-1)) 'Redimension the arrays that will hold all the values of U and V to the number of tiles in each direction ReDim uVal(uDiv) ReDim vVal(vDiv) 'Find the step value, i.e. the distance between tiles in each direction. (note: this is not the euclidian distance, it is the distance measured in UV space) uStep = 1/uDiv vStep = 1/vDiv rhino.EnableRedraw vbFalse 'Fill the arrays with the actual values of U and V at each step For i = 0 To uDiv uVal(i) = i * uStep Next For i = 0 To vDiv vVal(i) = i * vStep Next 'Start looping through each u and v division and create the tile within For i = 0 To uDiv-1 For j = 0 To vDiv-1 component i,j Next Next Dim YN:YN= Rhino.MessageBox ("Delete construction curves?" , 4) If YN =6 Then Rhino.PurgeLayer ("construction") 'Rhino.DeleteObjects (sourceSurface) End If rhino.EnableRedraw vbTrue End Sub panel Function component (i,j) checkLayerParent(parentLayer) Dim componentColor : componentColor = RGB(125,125,125) 'top left corner Dim a0 : a0 = Rhino.EvaluateSurface(sourceSurface, Array(uVal(i), vVal(j))) 'top right corner Dim f0 : f0 = Rhino.EvaluateSurface(sourceSurface, Array(uVal(i)+uVal(1), vVal(j))) 'bottome left corner Dim a5 : a5 = Rhino.EvaluateSurface(sourceSurface, Array(uVal(i), vVal(j)+ vVal(1))) 'bottom right corner Dim f5 : f5 = Rhino.EvaluateSurface(sourceSurface, Array(uVal(i)+uVal(1), vVal(j)+vVal(1))) 'find normal to center point Dim b2 : b2 = Rhino.SurfaceCurvature(sourceSurface, Array(uVal(i)+(uVal(1)*(.5)) , vVal(j)+vVal(1)*(.5))) 'find point ap1 given height normal to point b2 Dim calHe : calHe= height 'assign the pyramid tip's point in space based on offsetting a point normal to the surface ap1(i,j) = offsetCalc(b2, height) ap2(i,j) = offsetCalc(b2,-height) CheckLayerParent "construction" 'draw lines Dim a0ap1 : a0ap1 = Rhino.AddLine(a0 , ap1(i,j)) Dim f0ap1 : f0ap1 = Rhino.AddLine(f0 , ap1(i,j)) Dim f5ap1 : f5ap1 = Rhino.AddLine(f5 , ap1(i,j)) Dim a5ap1 : a5ap1 = Rhino.AddLine(a5 , ap1(i,j)) Dim a0ap1Down : a0ap1Down = Rhino.AddLine(a0 , ap2(i,j)) Dim f0ap1Down : f0ap1Down = Rhino.AddLine(f0 , ap2(i,j)) Dim f5ap1Down : f5ap1Down = Rhino.AddLine(f5 , ap2(i,j)) Dim a5ap1Down : a5ap1Down = Rhino.AddLine(a5 , ap2(i,j)) CheckLayer "Component" , componentColor 'draw surfaces edgeSurface a0ap1Down, f0ap1Down edgeSurface f0ap1Down, f5ap1Down edgeSurface f5ap1Down,a5ap1Down edgeSurface a5ap1Down, a0ap1Down edgeSurface a0ap1, f0ap1 edgeSurface f0ap1, f5ap1 edgeSurface f5ap1,a5ap1 edgeSurface a5ap1 ,a0ap1 End Function Function edgeSurface(edge1,edge2) Dim f : f = Rhino.CurveDirectionsMatch(edge1,edge2) Dim rEdge Dim arr If f = False Then rEdge= Rhino.ReverseCurve(edge1) arr = Array(edge1, rEdge ) End If If f = True Then arr = Array(edge1, edge2 ) End If Rhino.AddEdgeSrf(arr) End Function ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'This fucntion finds the coordinate of a point normal to, and at a from, a point on the surface Function offsetCalc(oData, height) Dim vscaled vscaled = VectorScale(oData(1),height) offsetCalc = VectorAdd(vscaled,oData(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 '-------------------------------------------------------------------------------------------------------------------- 'This function checks if the current layer is and if it isn't, makes it so. If the layer doesn't ' exist then it creates it with the name . Function CheckLayerParent(layername) If Rhino.IsLayer(layername) Then Rhino.CurrentLayer(layername) Else Rhino.AddLayer layername Rhino.CurrentLayer(layername) End If End Function Function CheckLayer(layername,color) If Rhino.IsLayerChildOf(parentLayer, layername+"_"+parentLayer) Then Rhino.CurrentLayer(layername+"_"+parentLayer) Else Rhino.AddLayer layername+"_"+parentLayer,color,,,parentLayer Rhino.CurrentLayer(layername+"_"+parentLayer) End If End Function