Array_Material

skin

Option Explicit

Call loftCurve
Sub loftCurve()
   
 Dim crvObjects : crvObjects = Rhino.GetObjects(“Pick curve(s)”, 4)
 If IsNull(crvObjects) Then Exit Sub
 
 Dim minR : minR = 3
 Dim maxR : maxR = 3
 
 Dim crvCurvature, crvTangent, crv,pt, ptparam,Wigglez
 Dim crvDomain
 Dim crvLength
 Dim intSamples, dist, mid
 Dim t, Radius, i, r
 Dim WinD,j,n,d,closestpt, winpt, Endpt, k, stp,plane
 Dim sphere,WorldXY,wigglex,wiggley
 Dim Elip,divs,newdivs(),NewLine,p,vect
 Dim toppt,botpt,matsVector,NegmatsVector,Meat,negcrvTangent,dough,Newpt
 ‘Call rhino.enableRedraw(False)

 

 For i = 0 To Ubound(crvObjects)
  Rhino.EnableRedraw(False)

  crvDomain = Rhino.CurveDomain(crvObjects(i)) 
  crvLength = Rhino.CurveLength(crvObjects(i))
  dist= Rhino.CurveLength (crvObjects(i))
  Endpt = Rhino.CurveEndPoint (crvObjects(i))
  ‘Rhino.AddPoint Endpt
 
  crv = crvObjects(i)
  pt= Rhino.CurveStartPoint (crv)
  
  ‘Endpt = Rhino.CurveEndPoint (crv)
  
  stp = 0
  If dist < 1 Then
   pt = Rhino.CurveMidPoint (crvObjects(i))
   For j=0 To Ubound (crvObjects)
    If j<>i Then
     closestpt= Rhino.CurveClosestPoint (crvObjects(j),pt)
     closestpt = Rhino.EvaluateCurve (crvObjects(j),closestpt)
     d=Rhino.Distance (pt, closestpt)
     If n=0 Then
      winD= d
      winpt = closestpt
      n=n+1
     Else
      If d<winD Then
       winD= d 
       winpt = closestpt
      End If
     End If
    End If
   Next
   r=winD
   Rhino.Addsphere pt, r
  Else
   Do
    n=0
    ptparam = Rhino.CurveClosestPoint (crv,pt)
    pt = Rhino.EvaluateCurve (crv,ptparam)
   
    If abs (ptparam – crvDomain(1)) < .01 Then
     stp = 1
    End If
    crvTangent = Rhino.CurveTangent (crv,ptparam)
    plane = Rhino.PlaneFromNormal (pt,crvTangent)
    For j=0 To Ubound (crvObjects)
     If j<>i Then
      closestpt= Rhino.CurveClosestPoint (crvObjects(j),pt)
      closestpt = Rhino.EvaluateCurve (crvObjects(j),closestpt)
      d=Rhino.Distance (pt, closestpt)
      If n=0 Then
       winD= d
       winpt = closestpt
       n=n+1
      Else
       If d<winD Then
        winD= d 
        winpt = closestpt
       End If
      End If
     End If
    Next
    r=winD*0.7
    
    If r > 2 Then
     
     r = 2
    End If
    If r < .4 Then
     r = .4
     
    End If

    
    Wigglez = plane(3)
    Wigglez = Rhino.VectorUnitize (Wigglez)
    Wigglez = Rhino.VectorScale (Wigglez, random(-.3*r,.3*r))
    
    wigglex = plane(1)
    wigglex = Rhino.VectorUnitize (wigglex)
    wigglex = Rhino.VectorScale (wigglex,random(-.8*r,0.8*r))
    
    wiggley = plane(2)
    wiggley = Rhino.VectorUnitize (wiggley)
    wiggley = Rhino.VectorScale (wiggley,random(-.8*r,0.8*r))
    
    Newpt = Rhino.PointAdd(pt,Wigglez)
    Newpt = Rhino.PointAdd(pt,wigglex)
    Newpt = Rhino.PointAdd(pt,wiggley)
    plane = Rhino.MovePlane (plane,Newpt)
    Elip = Rhino.AddEllipse (plane, random(r,1.5*r),random(r,1.5*r))
    divs = Rhino.DivideCurve (Elip, 6)
    For p=0 To Ubound (divs)
     
     ReDim Preserve newDivs (p)
     vect= Rhino.VectorCreate(Newpt,divs(p))
     vect=Rhino.VectorScale (vect,random(-.6,.6))
     
     newdivs(p) = Rhino.PointAdd (divs(p),vect)
     newdivs(p) = Rhino.PointAdd (newdivs(p),Wigglez)
    Next
    ReDim Preserve newDivs(p)
    newDivs(p) = newDivs(0)
    NewLine = Rhino.AddInterpCurve (newDivs)
    Rhino.RebuildCurve NewLine
    crvTangent = Rhino.VectorUnitize (crvTangent)
    crvTangent = Rhino.VectorScale (crvTangent,random(.7*r,r))
    toppt = Rhino.PointAdd (Newpt,crvTangent)
    negcrvTangent = Rhino.VectorReverse (crvTangent)
    ‘negcrvTangent = Rhino.VectorScale (crvTangent,.5)
    botpt = Rhino.PointAdd (Newpt,negcrvTangent)
    matsVector = Rhino.VectorCreate (Newpt,newdivs(0))
    NegmatsVector = Rhino.VectorReverse (matsVector)
    NegmatsVector = Rhino.VectorScale (NegmatsVector, 0.8)
    Meat = Rhino.AddInterpCurveEx (array(toppt,newdivs(0),botpt),,,,NegmatsVector,matsVector)
    dough = Rhino.AddRailRevSrf (Meat,NewLine,array(toppt,botpt))
    Rhino.DeleteObjects array(NewLine,Meat,Elip)
    
    
    
    
    
    
    
    Rhino.RotateObject dough ,pt,random(-20,20),wigglex
    Rhino.RotateObject dough ,pt,random(-20,20),wiggley
    If stp =1 Then
     Exit Do
    End If
    crvTangent = Rhino.VectorUnitize (crvTangent)
    crvTangent = Rhino.VectorScale (crvTangent, r*0.4)
    pt= Rhino.PointAdd (pt, crvTangent)
   
  
   Loop
  End If
  Rhino.EnableRedraw(True)
 Next
  
  
  
  
  
  
  
  
 
 ‘================================================================================================
 ‘Call rhino.enableRedraw(True)
 ‘================================================================================================
 

End Sub

Function random(min,max)
 Randomize
 random = (max-min) * Rnd + min
End Function

Function random(min,max)
 Randomize
 random = (max-min) * Rnd + min
End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s