Sign in to follow this  

How to translate RGB color to new BABYLON.Color3(x, x, x) ?

Recommended Posts


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 }


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.