简体   繁体   English

在立方体three.js上使用纹理和颜色

[英]Use a texture and a color on a cube three.js

I would like to create a cube that has a texture and a color on it in three.js at the same time. 我想在three.js中创建一个同时具有纹理和颜色的立方体。

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? 顶部有颜色的黑白纹理是否可以让我改变纹理的颜色?

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 (eg 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM