最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use a texture and a color on a cube three.js - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

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);
发布评论

评论列表(0)

  1. 暂无评论