lindylex Posted June 19, 2016 Share Posted June 19, 2016 How do I translate RGB color to new BABYLON.Color3(x, x, x) ? I would like this color R : 33 G : 87 B : 179 it is also represented as html value #2157B3 converted to BABYLON.Color3(x, x, x) ? Thanks JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Samuel Girardin Posted June 19, 2016 Share Posted June 19, 2016 Hi, You can use this in typescript to convert a html color. But I'm almost sure babylon can handle that in a simpler way. HexToRGB(hex: string): BABYLON.Color3 { var r = HexToR(hex) / 255; var g = HexToG(hex) / 255; var b = HexToB(hex) / 255; return new BABYLON.Color3(r, g, b); } HexToR(h) { return parseInt((CutHex(h)).substring(0, 2), 16) } HexToG(h) { return parseInt((CutHex(h)).substring(2, 4), 16) } HexToB(h) { return parseInt((CutHex(h)).substring(4, 6), 16) } CutHex(h) { return (h.charAt(0) == "#") ? h.substring(1, 7) : h } JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
lindylex Posted June 19, 2016 Author Share Posted June 19, 2016 Samuel, thanks much for your assistance! Quote Link to comment Share on other sites More sharing options...
lindylex Posted June 20, 2016 Author Share Posted June 20, 2016 Samuel, I can do it like this. new BABYLON.Color4.FromHexString("#FD6304FF"); Thanks for helping. MrPancakes, rodrigezer, Dieterich and 1 other 2 2 Quote Link to comment Share on other sites More sharing options...
jerome Posted June 20, 2016 Share Posted June 20, 2016 if your initial values are just R,G, B integers lower or equal to 255, the r,g,b values expected by BJS are then : r = R / 255 g = G /255 b = B / 255 MrPancakes 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 20, 2016 Share Posted June 20, 2016 https://github.com/BabylonJS/Babylon.js/blob/master/src/Math/babylon.math.ts#L221 JackFalcon and jerome 2 Quote Link to comment Share on other sites More sharing options...
Vijay Kumar Posted June 20, 2016 Share Posted June 20, 2016 mesh..diffuseColor = new BABYLON.Color3( 33 / 255, 87 / 255,179/255); JackFalcon and MrPancakes 2 Quote Link to comment Share on other sites More sharing options...
lindylex Posted June 20, 2016 Author Share Posted June 20, 2016 Thanks everyone. This was confusing me greatly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.