A problem with setting the color. MeshPhongMaterial

I use google translator.

Hello.
I have a problem with setting the color. (MeshPhongMaterial)

The link pro-house.site:3012.

Description of the problem:

  1. material in 3d editor. color code 0x775B44. shown in the picture:
    blender-color

  2. Correct initialization of 3d scene in the browser. The colors suit me. The link to the application pro-house.site:3012 . Result on the image:
    correct-color

3.Then the problem arises. Select the roof in the menu on the left, then click on the last color in the list. The color is the same as in the 3d editor 0x775B44. Nothing should happen, but the color changes to not correct. Shown in the images:
incorrect-clor

564651354687

code:
Снимок экрана от 2017-12-28 11-21-03

Tell me please. What do I do wrong? How can I fix it?
I will be very grateful.

It should work, what’s the value of your color?
Try this
object.material.color = ‘blue’;

This is not valid format of parameter for .setHex(). It has to be of a hex value, here you pass it as a string.
You can try the other .setXXX() methods of THREE.Color().

For example:

var color = new THREE.Color();
color.setStyle('#' + '0000ff'); // the result string is '#0000ff'
console.log(color);
2 Likes

You can just use .set by the way, it’s smart enough to figure out the input:

material.color.set( 0xff0000 ) // will set the colour to red
1 Like

Not very rare kind of topics on SO about color values ))

I already tried that. Now once again I tried. Does not work.
object.material.color.setStyle(’#’+color);

Without having your code or a live code example, I can look into my crystal ball and give you a random answer.

What value of your color variable?

The color is taken here (html): data-color=“ff0000”

script:

// color = string (ff0000)
function updateColor(obj, color){
var object = scene.getObjectByName(obj);
if(object){
object.material.color.setHex(‘0x’+color);
object.material.map = null;
object.material.needsUpdate = true;
}
};

So does not work either.
Maybe because instead of hex 0xff0000, the string “0xff0000” is passed?

Take a look at this jsfiddle.

And once again. Read carefully and very attentively about .setXXX() methods of THREE.Color() and what types of paremeters they accept.

do you see the difference between “0x” and “#”?

I reread the documentation, everything is clear. When loading and initializing the scene, the default colors are rusty. Then, the selected color values are parsed. Active colors are set on 3D objects and they are not correct.
I hope the translator translates plainly.

I perfectly understand the difference between “0x” and “#”.
I can see by the code that the colors are specified by the line #. Under any function, the installation is not correct, for example, setStyle(’#ff0000’).

On the left is a menu where you can select the color;

menu code?

Hey. I updated the post. Clearly presented the problem.