Summary: RhinoScript 를 사용하여 개체의 색깔을 바꾸는 방법을 소개합니다.
많은 개체의 색상을 지정할 때, Rhino 의 Properties 명령을 사용하면 속도가 다소 느려지는 것 같습니다. 이 명령을 사용하지 않고 개체의 색상을 변경하는 방법을 찾고 있습니다. 여러 개의 개체에 색상을 랜덤으로 지정하는 방법도 알고 싶습니다. 또한, Rhino 에서 두 개의 색상을 선택하여 블렌드 컬러를 생성할 수 있게 되면 좋겠습니다. 이러한 작업이 가능합니까?
이와 같은 모든 작업은 RhinoScript 의 GetColor 와 ObjectColor 메서드를 사용하시면 됩니다.
다음의 샘플 스크립트에는 다음과 같은 하위 루틴이 있습니다:
스크립트만을 사용하려면 다음의 스크립트를 다운로드하시기 바랍니다.
스크립트를 실행하려면 바탕화면에 압축 파일을 풀고, 마우스로 끌어 실행 중인 Rhino 에 가져가 마우스를 놓으면 됩니다. 세 개의 명령이 추가됩니다: SetObjectColor, SetObjectColorRandom, SetObjectColorGraded.
여기서부터는 스크립트 소스 코드입니다.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ObjectColor.rvb -- February 2009 ' If this code works, it was written by Dale Fugier. ' If not, I don't know who wrote it. ' Works with Rhino 4.0. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Randomize ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Sets object colors ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub SetObjectColor Dim objects, color objects = Rhino.GetObjects("Select objects to change colors", 0, True, True) If IsNull(objects) Then Exit Sub color = Rhino.GetColor If IsNull(color) Then Exit Sub Rhino.ObjectColor objects, color End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Set random object colors ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub SetObjectColorRandom Dim objects, red, green, blue, i objects = Rhino.GetObjects("Select objects for randomly color change", 0, True, True) If IsNull(objects) Then Exit Sub Rhino.EnableRedraw False For i = 0 To UBound(objects) red = Int(255 * Rnd) green = Int(255 * Rnd) blue = Int(255 * Rnd) Rhino.ObjectColor objects(i), RGB(red, green, blue) Next Rhino.EnableRedraw True End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Sets gradient object colors (based on the order picked) ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub SetObjectColorGraded Dim objects, color0, color1, color, i, bound Dim red, red0, red1 Dim green, green0, green1 Dim blue, blue0, blue1, percent objects = Rhino.GetObjects("Select objects for gradient color change", 0, True, True) If IsNull(objects) Then Exit Sub color0 = Rhino.GetColor If IsNull(color0) Then Exit Sub color1 = Rhino.GetColor If IsNull(color1) Then Exit Sub ' Extract red-green-blue components red0 = color0 And &HFF red1 = color1 And &HFF green0 = (color0 \ &H100) And &HFF green1 = (color1 \ &H100) And &HFF blue0 = (color0 \ &H10000) And &HFF blue1 = (color1 \ &H10000) And &HFF bound = UBound(objects) Rhino.EnableRedraw False For i = 0 To bound ' A linearly interpreted gradient just calculates the new RGB values by applying a ' target value percent of the linear range to the each RGB component range. percent = i/bound red = red0 + Int(percent * (red1 - red0)) green = green0 + Int(percent * (green1 - green0)) blue = blue0 + Int(percent * (blue1 - blue0)) Rhino.ObjectColor objects(i), RGB(red, green, blue) Next Rhino.EnableRedraw True End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Rhino.AddStartupScript Rhino.LastLoadedScriptFile Rhino.AddAlias "SetObjectColor", "_NoEcho _-RunScript (SetObjectColor)" Rhino.AddAlias "SetObjectColorRandom", "_NoEcho _-RunScript (SetObjectColorRandom)" Rhino.AddAlias "SetObjectColorGraded", "_NoEcho _-RunScript (SetObjectColorGraded)"