I would like to create a cube that has a texture and a color on it in three.js at the same time.
I want to change the color when the cube is selected. That's why it needs a color.
Will a black and white texture with a color on top allow me to change the color of the texture?
I would like to create a cube that has a texture and a color on it in three.js at the same time.
I want to change the color when the cube is selected. That's why it needs a color.
Will a black and white texture with a color on top allow me to change the color of the texture?
Share Improve this question edited Sep 13, 2016 at 9:49 jwpfox 5,26011 gold badges48 silver badges42 bronze badges asked Sep 10, 2016 at 15:41 Matthew AndersonMatthew Anderson 731 silver badge9 bronze badges1 Answer
Reset to default 4The color of a material has always an effect on the appearance of the object even there is an texture on it. The default color value is white and the texture looks just normal. But if you set the color to red, the texture will turn reddish (e.g. if you have a black/white texture, you will get a black/red texture).
var geometry = new THREE.BoxGeometry( 1, 1, 1 );
var material = new THREE.MeshLambertMaterial(); // default color is 0xffffff
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
var loader = new THREE.TextureLoader();
loader.load('texture.jpg',
function ( texture ) {
material.map: texture;
});
// onclick: set color
material.color.set(0xff0000);