在three.js中改变立方体的颜色 [英] Changing color of cube in three.js

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

问题描述

我正在尝试根据变量更改立方体的颜色.我创建了两个立方体,我想根据它们之间的距离改变它们的颜色.

I'm trying to change the color of a cube based on a variable. I created two cubes and I want to change their color depending on the distance between them.

立方体是这样创建的:

geometry = new THREE.CubeGeometry( 50, 50, 50 );
material = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
cube = new THREE.Mesh( geometry, material );
scene.add( cube );

现在我尝试了这样的事情:

Now I tried something like this:

if(distance > 20)
{
cube.material.color = 0xffffff;
}

但它不起作用.我查看了示例,但找不到任何合适的内容.

But it does not work. I looked in the examples but couldn't find anything appropriate.

推荐答案

您没有正确指定颜色值.

You are not specifying the color value correctly.

cube.material.color.setHex( 0xffffff );

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

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