Use a texture and a color on a cube three.js

本小妞迷上赌 提交于 2019-12-02 15:13:16

问题


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?


回答1:


The 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);


来源:https://stackoverflow.com/questions/39427721/use-a-texture-and-a-color-on-a-cube-three-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!