Home › Forums › Programming › Color Picker – Change Diffuse Material
- This topic has 8 replies, 3 voices, and was last updated 5 years, 5 months ago by
Yuri Kovelenov.
-
AuthorPosts
-
2019-09-13 at 10:09 am #18674
hoody
ParticipantHey 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
2019-09-13 at 11:29 am #18681yasse
CustomerHello, 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.
2019-09-13 at 12:57 pm #18686hoody
ParticipantHey thank you for the answer. I´m still not lucky.
can you take a look on my puzzle?
2019-09-13 at 2:44 pm #18699yasse
CustomerHere 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
2019-09-13 at 3:20 pm #18704hoody
ParticipantHey. thanks agan for taking your time.
do you mean like that (screenshot)? This only changes my color into some kind of grey.
2019-09-13 at 3:57 pm #18711Yuri Kovelenov
Staff2019-09-14 at 2:43 pm #18722yasse
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 :)
2019-09-25 at 5:03 pm #19280hoody
ParticipantHey Guys, just wanted to say – it worked.
Thank you!
2019-09-26 at 7:19 am #19308Yuri Kovelenov
Staff -
AuthorPosts
- You must be logged in to reply to this topic.