Ludo
Ludo

Reputation: 5280

How to change the color of a Mesh already in a scene

I am trying to build my first application using the great Three.js library.

I have some cubes with the same color, i would like to change the color of the cube the user click on.

Can we cange the color of a Cube after instanciating it, or do we have to delete it and create a new one ?

Here is what i am trying to do, i can change the position but not the color:

//...

var cube = new THREE.Mesh(geometry, cubeMaterial);
cube.scale.y = 1;
cube.scale.x = 2;
cube.position.x = 0;
cube.position.y = 25;
cube.position.z = 25;
buildings.push(cube)

//...

 buildings.forEach(function(building) {
        if (1) {
            building.color = 0xffffff; //Doesn't change anything
            building.position.x = 300; //Works
        }
    });
    render();

Upvotes: 0

Views: 117

Answers (1)

gaitat
gaitat

Reputation: 12642

building.material.color.setHex( 0xffffff );

Upvotes: 1

Related Questions