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.

Color Picker – Change Diffuse Material

Home Forums Programming Color Picker – Change Diffuse Material

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #18674
    hoody
    Participant

    Hey Guys – already found some information in other threads but cant seem to figure out what im doing wrong.

    I want do change the diffuse color of an object by using a color picker input that i created.

    The Id for the color picker is “picker”

    currently Im facing these 2 issues:

    1.My code (for simple diffuse Shader in Blender):

    eventHTMLElem(‘change’, ‘picker’, true, function(event) {

    let rbg = changeToRBG(event.target.value)
    console.log(rbg)

    var vals = rbg.substring(rbg.indexOf(‘(‘) +1, rbg.length -1).split(‘,’)
    console.log(vals[0]+” “+vals[1]+” “+vals[2])

    setMaterialColor(‘mat_sohlenrand’, ‘Diffuse BSDF Color’, vals[0], vals[1], vals[2]);
    });

    function changeToRBG(val){
    return “rgb(” + val.match(/[A-Za-z0-9]{2}/g).map(function(v) {
    return parseInt(v, 16)
    }).join(“,”) + “)”;
    }

    With this code, using the regular diffuse shader, i can change the colors with my color picker – but the colors dont match (look different than the colors that i selcted in the color picker) or some become just white

    2. My code for diffuse with RGB Node input:

    eventHTMLElem(‘change’, ‘picker’, true, function(event) {

    let rbg = changeToRBG(event.target.value)
    console.log(rbg)

    var vals = rbg.substring(rbg.indexOf(‘(‘) +1, rbg.length -1).split(‘,’)
    console.log(vals[0]+” “+vals[1]+” “+vals[2])

    setMaterialColor(‘mat_sohlenrand’, ‘RGB‘, vals[0], vals[1], vals[2]);
    });

    function changeToRBG(val){
    return “rgb(” + val.match(/[A-Za-z0-9]{2}/g).map(function(v) {
    return parseInt(v, 16)
    }).join(“,”) + “)”;
    }

    with this code, using the “RGB Node” in Blender, nothing happens.

    I also attached screenshots for these two cases.

    I hope you can help me resolve the problem.

    thanks

    #18681
    yasse
    Customer

    Hello, I Hope you doing good, i have used the color picker, and i can confirm you it can work perfectly, in my case i needed to adjust two colors at once : so here what looked my node (see attached node-material) and also included the puzzle editor, the R, G, B are the value from your color picker.

    #18686
    hoody
    Participant

    Hey thank you for the answer. I´m still not lucky.

    can you take a look on my puzzle?

    #18699
    yasse
    Customer

    Here you had to take the value of R, G, B varriable, in my case it was two color picker, so try to make in the set color, the same variable stored earlier from the value, i hope is it clear ? here you did stored R G B and you used R2 G2 B2

    #18704
    hoody
    Participant

    Hey. thanks agan for taking your time.

    do you mean like that (screenshot)? This only changes my color into some kind of grey.

    #18711

    Hi,

    you don’t need to convert to number for the second time, neither to add 0. Just put variables alone in the R, G, B slots.

    Make sure your color component values are between 0 and 1 (you can print them to console to check).

    Chief 3D Verger | LinkedIn | Twitter

    #18722
    yasse
    Customer

    @hoody, Yes exactly I think it’s because the color value RGB you made them to 255,255,255 you need to add function to devide by 255, in order to have value from 0–1 in order to take effect, exactly as Mr Yuri said :D :)

    Good luck :)

    #19280
    hoody
    Participant

    Hey Guys, just wanted to say – it worked.

    Thank you!

    #19308

    great! :good:

    Chief 3D Verger | LinkedIn | Twitter

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