2010. 9. 3. 19:45
RhinoScript 뭔지 모르지만 예문
2010. 9. 3. 19:45 in Rhino3D/Rhino Script
- 'RandRail.rvb
- 'Marius Watz, http://workshop.evolutionzone.com
- Option Explicit
- Sub Main
- Dim doRender : doRender=1
- Dim num : num=100
- Dim pt, curve(100)
- Call rhino.enableRedraw(False)
- Rhino.Print "--------------------------"
- ' delete any existing objects
- Dim oldScene:oldScene=Rhino.AllObjects()
- If isArray(oldScene) Then
- Rhino.DeleteObjects Rhino.AllObjects()
- Rhino.DeleteObjects Rhino.LightObjects()
- End If
- ' Set up scene
- Dim light
- light=Rhino.AddPointLight (Array(0,-200,0))
- light=Rhino.AddPointLight (Array(-100,-100,0))
- Rhino.RenderColor 1, RGB(50,50,50)
- Rhino.RenderResolution Array(1200,900)
- Rhino.RenderAntialias 2
- ' Create random curves
- Dim cp(3),mult, i
- For i=0 To num
- mult=random(0.75,1.25)
- cp(0)=Array(0,0,0)
- If Rnd>0.5 Then
- cp(1)=Array(0,random(30,50),0)
- Else
- cp(1)=Array(0,random(-30,20),0)
- End If
- If Rnd>0.5 Then
- cp(2)=Array(random(-50,50)*mult,random(30,50),random(-50,50)*mult)
- Else
- cp(2)=Array(random(-50,50)*mult,random(-30,20),random(-50,50)*mult)
- End If
- cp(3)=Array(random(-50,50)*mult,random(-50,50),random(-50,50)*mult)
- curve(i)=Rhino.AddCurve(cp)
- ' Rhino.AddSphere cp(2), dblRadius
- Next
- ' Create random rounded profile
- Dim numRot : numRot=Int(random(7,18))
- Dim j, rndCurve(10),profPt(),deg,offs
- ReDim profPt(numRot)
- For j=0 To Ubound(rndCurve)
- For i=0 To numRot
- deg=(2*Rhino.Pi/numRot)*i
- offs=random(5,7)*0.2
- If i Mod 2=0 Then
- offs=random(7,12)*0.2
- End If
- profPt(i)=Array(Cos(deg)*offs, 0 ,Sin(deg)*offs)
- Next
- rndCurve(j)=Rhino.AddCurve(profPt)
- Next
- ' Create random RailRefSrf and ExtrudeCurve surfaces
- Dim railAxis(1)
- railAxis(0)=Array(0,0,0)
- railAxis(1)=Array(0,1,0)
- Dim srf,profCurve
- For i=0 To num
- profCurve=rndCurve(Int(random(0,Ubound(rndCurve))))
- srf=Rhino.AddRailRevSrf(curve(i),profCurve,railAxis)
- applyRndMaterial(srf)
- ' srf=Rhino.ExtrudeCurve(profCurve,curve(i))
- ' applyRndMaterial(srf)
- Next
- If doRender=1 Then
- renderView()
- End If
- Call rhino.enableRedraw(True)
- End Sub
- ' Set random materials
- Function applyRndMaterial(obj)
- Dim prob,col,material
- material=Rhino.AddMaterialToObject (obj)
- ' Coloring: Pink, Orange
- prob=random(0,100)
- If prob<30 Then
- Rhino.MaterialColor material, RGB(255, 0, Int(random(100,150)))
- ElseIf prob<90 Then
- Rhino.MaterialColor material, RGB(255, Int(random(100,254)),0)
- Else
- Rhino.MaterialColor material, RGB(255, 255, 255)
- End If
- End Function
- Function random(min,max)
- random=Rnd*(max-min)+min
- End Function
- ' Render current viewport
- Function renderView()
- Dim view,filename
- view = Rhino.CurrentView
- Rhino.Command "_-Render"
- filename=getRenderFileName("RandRail")
- Dim cmd : cmd="_-SaveRenderWindowAs " & Chr(34) & filename & Chr(34)
- Rhino.Command cmd
- End Function
- ' Get auto-incremented filename
- Function getRenderFileName(scriptName)
- Dim index,done, doc, file, temp,imgNum
- done=-1
- index=0
- Do While done=-1
- doc=Rhino.WorkingFolder & "\" & scriptName & padStr(scriptName,index) & ".png"
- file=Rhino.FindFile(doc)
- If IsNull(file)=True Then
- done=1
- Else
- index=index+1
- End If
- Loop
- getRenderFileName=doc
- End Function
- Function padStr(prefix,val)
- Dim l : l=Len(val)
- If l<1 Then
- padStr="000" & val
- ElseIf l<2 Then
- padStr="00" & val
- ElseIf l<3 Then
- padStr="0" & val
- Else
- padStr="" & val
- End If
- End Function
- Main