Skip to content

Instantly share code, notes, and snippets.

@Arahnoid
Last active April 21, 2019 23:23
Show Gist options
  • Select an option

  • Save Arahnoid/d4d697c702fd941c992f to your computer and use it in GitHub Desktop.

Select an option

Save Arahnoid/d4d697c702fd941c992f to your computer and use it in GitHub Desktop.
3D Max Color convert functions #3dmax
/**
* 3D Max
* COLOR CONVERT FUNCTIONS
* Source: http://www.emoticode.net/maxscript/color-convert-functions.html
*/
--CONVERT RGB (0-255) TO HEXSTRING
fn RGBtoHEX clrRGB = (bit.intAsHex clrRGB.r)+(bit.intAsHex clrRGB.g)+(bit.intAsHex clrRGB.b)
RGBtoHEX (color 80 170 178)
-->"50aab2"
--CONVERT HEXSTRING TO RGB (0-255)
fn HEXtoRGB hexString =
(
local clr, hexValue = true, hexChars = "AaBbCcDdEeFe0123456789"
if hexString[1] == "#" do trimleft hexString "#"
if ((for c in 1 to hexString.count where findstring hexChars hexString[c] == undefined collect hexString[c]).count != 0) do hexValue = false
if (hexValue == true and hexString.count == 6) do
(
local clrArr = for i = 1 to 5 where mod i 2 != 0 collect (append hexString[i] hexString[i+1])
clr = (color (bit.hexAsInt clrArr[1]) (bit.hexAsInt clrArr[2]) (bit.hexAsInt clrArr[3]))
) ; return clr
)
HEXtoRGB "50aab2"
-->(color 80 170 178)
--CONVERT RGB (0-255) TO FLOAT POINT COLOR
fn RGBtoFPC clrRGB = (color (clrRGB.r/255) (clrRGB.g/255) (clrRGB.b/255))
RGBtoFPC (color 80 170 178)
-->(color 0.313726 0.666667 0.698039)
--CONVERT FLOAT POINT COLOR TO RGB (0-255)
fn FPCtoRGB clrFPC = (color (clrFPC.r*255) (clrFPC.g*255) (clrFPC.b*255))
FPCtoRGB (color 0.313726 0.666667 0.698039)
-->(color 80 170 178)
--CONVERT DOTNET COLOR TO RGB (0-255)
fn DOTNETtoMXSRGB dnClr = (local clr ; clr = if classof dnClr.r == Integer do (color dnClr.r dnClr.g dnClr.b) ; clr)
DOTNETtoMXSRGB ((dotNetClass "System.Drawing.Color").LightGray)
-->(color 211 211 211)
--CONVERT DOTNET COLOR TO FLOAT POINT COLOR
fn DOTNETtoMXSFPC dnClr = (local clr ; clr = if classof dnClr.r == Integer do (color ((dnClr.r as Float)/255) ((dnClr.g as Float)/255) ((dnClr.b as Float)/255)) ; clr)
DOTNETtoMXSFPC ((dotNetClass "System.Drawing.Color").LightGray)
-->(color 0.827451 0.827451 0.827451)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment