在立方体three.js上使用纹理和颜色 [英] Use a texture and a color on a cube three.js

查看:750
本文介绍了在立方体three.js上使用纹理和颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一时间在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.

我想在选择多维数据集时更改颜色。这就是为什么它需要一种颜色。

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

这篇关于在立方体three.js上使用纹理和颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆