在three.js中更改cube的颜色 [英] Changing color of cube in three.js

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

问题描述

我想根据变量更改多维数据集的颜色。我创建了两个立方体,我想根据它们之间的距离更改它们的颜色。

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

现在我尝试这样:

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

但它不工作。

推荐答案

您没有正确指定颜色值。

You are not specifying the color value correctly.

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

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

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