Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RegisterPluginVersion(1,0,1)
- Dim info As String = "Color Control RGB or RGBA (int, float, hex)."
- Dim f As Array[String]
- f.Push("R G B A(int)")
- f.Push("R G B A(float)")
- f.Push("RGBA(hex)")
- Dim m As Array[String]
- m.Push("COLOR")
- m.Push("AMBIENT")
- m.Push("DIFFUSE")
- m.Push("SPECULAR")
- m.Push("EMISSION")
- Sub OnInitParameters()
- RegisterInfoText(info)
- RegisterParameterContainer("Container", "Remote Container")
- RegisterRadioButton("ColorFormat", "Color Format", 0, f)
- RegisterRadioButton("PropertyMode", "Color Property Mode", 0, m)
- RegisterParameterString("colorInt", "R G B A(int): ", "", 50, 100, "")
- RegisterParameterString("colorFloat", "R G B A(float): ", "", 50, 100, "")
- RegisterParameterString("colorHex", "RGBA(hex): ", "", 50, 100, "")
- RegisterPushButton("btnRandom", " RANDOM ", 10)
- End Sub
- Sub OnInit()
- Dim c = GetParameterContainer("Container")
- If Not c.Valid Then
- c = this
- End If
- Dim rgbInt As Color = IntToRgb(GetParameterString("colorInt"))
- Dim rgbFloat As Color = FloatToRgb(GetParameterString("colorFloat"))
- Dim rgbHex As Color = HextToRgb(GetParameterString("colorHex"))
- Select Case GetParameterInt("ColorFormat")
- Case 0
- SendGuiParameterShow("colorInt", SHOW)
- SendGuiParameterShow("colorFloat", HIDE)
- SendGuiParameterShow("colorHex", HIDE)
- SetColor(c,rgbInt)
- Case 1
- SendGuiParameterShow("colorInt", HIDE)
- SendGuiParameterShow("colorFloat", SHOW)
- SendGuiParameterShow("colorHex", HIDE)
- SetColor(c,rgbFloat)
- Case 2
- SendGuiParameterShow("colorInt", HIDE)
- SendGuiParameterShow("colorFloat", HIDE)
- SendGuiParameterShow("colorHex", SHOW)
- SetColor(c,rgbHex)
- End Select
- End Sub
- Sub SetColor(c As Container, rgba As Color)
- Select Case GetParameterInt("PropertyMode")
- Case 0
- c.Material.Color = rgba
- Case 1
- c.Material.Ambient = rgba
- Case 2
- c.Material.Diffuse = rgba
- Case 3
- c.Material.Specular = rgba
- Case 4
- c.Material.Emission = rgba
- End Select
- c.Material.Alpha = rgba.Alpha
- End Sub
- Sub OnExecAction(buttonId As Integer)
- If buttonId = 10 Then
- Select Case GetParameterInt("ColorFormat")
- Case 0
- this.ScriptPluginInstance.SetParameterString("colorInt", RandomIntString())
- Case 1
- this.ScriptPluginInstance.SetParameterString("colorFloat", RandomFloatString())
- Case 2
- this.ScriptPluginInstance.SetParameterString("colorHex", RandomHexString())
- End Select
- End If
- End Sub
- Sub OnGuiStatus()
- OnInit()
- End sub
- Sub OnParameterChanged(parameterName As String)
- OnInit()
- End Sub
- '-------------------------------------------------------------------------------
- Function HextToRgb(s As String) As Color
- s.Substitute("[^0-9a-fA-F]", "",true)
- Dim r As Integer = 0
- Dim g As Integer = 0
- Dim b As Integer = 0
- Dim a As Integer = 255
- Dim tmp As Color
- Select Case s.Length
- Case 1
- r = HexToInt(s.GetSubstring(0,1))
- Case 2
- r = HexToInt(s.GetSubstring(0,2))
- Case 3
- r = HexToInt(s.GetSubstring(0,2))
- g = HexToInt(s.GetSubstring(2,1))
- Case 4
- r = HexToInt(s.GetSubstring(0,2))
- g = HexToInt(s.GetSubstring(2,2))
- Case 5
- r = HexToInt(s.GetSubstring(0,2))
- g = HexToInt(s.GetSubstring(2,2))
- b = HexToInt(s.GetSubstring(4,1))
- Case 6
- r = HexToInt(s.GetSubstring(0,2))
- g = HexToInt(s.GetSubstring(2,2))
- b = HexToInt(s.GetSubstring(4,2))
- Case Is >= 7
- r = HexToInt(s.GetSubstring(0,2))
- g = HexToInt(s.GetSubstring(2,2))
- b = HexToInt(s.GetSubstring(4,2))
- a = HexToInt(s.GetSubstring(6,2))
- End Select
- tmp.SetRGBA8(r,g,b,a)
- HextToRgb = tmp
- End Function
- Function HexToInt(s As String) As Integer
- Select Case s.Length
- Case 1
- HexToInt = StrToInt(s.Left(1))
- Case 2
- HexToInt = (StrToInt(s.Left(1))*16) + StrToInt(s.Right(1))
- End Select
- End Function
- Function StrToInt(s As String) As Integer
- s.Substitute("[Aa]", "10", false)
- s.Substitute("[Bb]", "11", false)
- s.Substitute("[Cc]", "12", false)
- s.Substitute("[Dd]", "13", false)
- s.Substitute("[Ee]", "14", false)
- s.Substitute("[Ff]", "15", false)
- StrToInt = CInt(s)
- End Function
- '-------------------------------------------------------------------------------
- Function IntToRgb(s As String) As Color
- Dim arr As Array[String]
- Dim r As Integer = 0
- Dim g As Integer = 0
- Dim b As Integer = 0
- Dim a As Integer = 255
- Dim tmp As Color
- s.TclSplit(arr)
- Select Case arr.Size
- Case 1
- r = CInt(arr[0])
- Case 2
- r = CInt(arr[0])
- g = CInt(arr[1])
- Case 3
- r = CInt(arr[0])
- g = CInt(arr[1])
- b = CInt(arr[2])
- Case Is >= 4
- r = CInt(arr[0])
- g = CInt(arr[1])
- b = CInt(arr[2])
- a = CInt(arr[3])
- End Select
- tmp.SetRGBA8(r,g,b,a)
- IntToRgb = tmp
- End Function
- '-------------------------------------------------------------------------------
- Function FloatToRgb(s As String) As Color
- Dim arr As Array[String]
- Dim r As Double = 0
- Dim g As Double = 0
- Dim b As Double = 0
- Dim a As Double = 1
- Dim tmp As Color
- s.TclSplit(arr)
- Select Case arr.Size
- Case 1
- r = CDbl(arr[0])
- Case 2
- r = CDbl(arr[0])
- g = CDbl(arr[1])
- Case 3
- r = CDbl(arr[0])
- g = CDbl(arr[1])
- b = CDbl(arr[2])
- Case Is >= 4
- r = CDbl(arr[0])
- g = CDbl(arr[1])
- b = CDbl(arr[2])
- a = CDbl(arr[3])
- End Select
- tmp.SetRGBA(r,g,b,a)
- FloatToRgb = tmp
- End Function
- '-------------------------------------------------------------------------------
- Function RandomHexString() As String
- Dim s As String = "ABCDEFabcdef0123456789"
- Dim n As Integer = s.Length - 1
- RandomHexString = "#"
- 'R
- RandomHexString &= s.GetSubstring(Random(n),1)
- RandomHexString &= s.GetSubstring(Random(n),1)
- 'G
- RandomHexString &= s.GetSubstring(Random(n),1)
- RandomHexString &= s.GetSubstring(Random(n),1)
- 'B
- RandomHexString &= s.GetSubstring(Random(n),1)
- RandomHexString &= s.GetSubstring(Random(n),1)
- End Function
- Function RandomIntString() As String
- RandomIntString = CStr(Random(255)) & " " & CStr(Random(255)) & " " & CStr(Random(255))
- End Function
- Function RandomFloatString() As String
- RandomFloatString = DoubleToString(Random(),4) & " " & DoubleToString(Random(),4) & " " & DoubleToString(Random(),4)
- End Function
Add Comment
Please, Sign In to add comment