We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Changing base color using HTML color code

Home Forums Programming Changing base color using HTML color code

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #7732
    dragosburian
    Customer

    Hi everybody,

    Is there any way in which you can get the base color of a material changed by using an HTML color code using puzzles? If not, which would be the way to go with this issue? Thank you!

    #7733

    Is there any way in which you can get the base color of a material changed by using an HTML color code using puzzles? If not, which would be the way to go with this issue? Thank you!

    It’s not possible.

    Co-founder and lead graphics specialist at Soft8Soft.

    #7734
    Yorick
    Customer

    Hi Mikhail, since we are paying for priority support, can you suggest another way to do this?

    We discussed with Yuri via video conference beforehand that changing colour of a 3D element based on input from our application is something that we need. Chancing colour seems to more straightforward than scaling/stretching to us.

    Do you have any ideas that could help us, or or you planning on adding this development?

    #7738

    We discussed with Yuri via video conference beforehand that changing colour of a 3D element based on input from our application is something that we need. Chancing colour seems to more straightforward than scaling/stretching to us.

    For now I think it’s can be only implemented using javascript. You can ask Yuri do add this feature: you will need to things: first is node to Get color from HTML object and second is node that can change RGB color in RGB color node in a material, this two are not presented now in puzzle. If you decide to do it via JavaScript it’s better to write in programming sub-forum.

    Co-founder and lead graphics specialist at Soft8Soft.

    #7740

    Hi,

    It is possible to change a material’s color via JavaScript API.
    For node based materials use the following approach:

    
    var object = app.scene.getObjectByName("MyObj");
    var mat = object.material;
    var index = mat.nodeRGBMap['RGB.001']; // 'RGB.001' is the name of an RGB node
    mat.nodeRGB[index] = new v3d.Vector4(1, 0, 0, 1); // new color in RGBA format
    

    If you are using standard or Verge3D PBR materials, simply update its color property:

    
    var object = app.scene.getObjectByName("MyObj");
    var mat = object.material;
    mat.color = new v3d.Color(1, 0, 0);
    

    Chief 3D Verger | LinkedIn | Twitter

    #7837
    dragosburian
    Customer

    Hi,

    By RGB node, do you refer to the name of that node in Blender(e.g. Base Color in case of the Principled BSDF) or is there an index I can find?
    Also, By using the second approach using Principled shader, it just won’t change the colors alothough I have no error and the mat.color gets updated with the values but does nothing. Am I mising anything?

    #7849

    By RGB node, do you refer to the name of that node in Blender

    Yes, you can check for the name in Blender node editor.

    By using the second approach using Principled shader

    This approach only valid for standard or glTF-compliant PBR shaders. Principled shader is considered to be a generic node-based shader so the first approach should be used in this case.

    Chief 3D Verger | LinkedIn | Twitter

    #7864
    dragosburian
    Customer

    And in the case of me having a hex color (e.g. #20ca24). How do I apply that color to the Principled BSDF shader?

    #7865

    you can convert HEX color to Vector4 as follows

    hex = Math.floor(hex);
    
    var x = (hex >> 16 & 255) / 255;
    var y = (hex >> 8 & 255) / 255;
    var z = (hex & 255) / 255;
    
    color = new Vector4(x,y,z,1.0)

    Chief 3D Verger | LinkedIn | Twitter

    #7868
    dragosburian
    Customer

    Done that, still no effect in the player

    #7870

    what node structure you got?

    Chief 3D Verger | LinkedIn | Twitter

    #7871
    dragosburian
    Customer

    Principled

    #7873

    This API only works with a dedicated RGB node:

    Attachments:
    You must be logged in to view attached files.

    Chief 3D Verger | LinkedIn | Twitter

    #7875
    dragosburian
    Customer

    And the code remains the same?

    #7876

    yes it should work but you need to supply correct node name to API

    Chief 3D Verger | LinkedIn | Twitter

Viewing 15 posts - 1 through 15 (of 23 total)
  • You must be logged in to reply to this topic.