Jump to content

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 }


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...