更改立方体面的颜色 [英] Change the colors of a cube's faces
本文介绍了更改立方体面的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我实际上发现了这个问题,但它说material.color
不存在.我需要知道如何更改我正在绘制的立方体各个面的颜色:
I actually found this question, but it says material.color
doesn't exist. I need to know how to change the colors of the various faces of a cube I'm drawing:
var newCube = new THREE.Mesh(new three.CubeGeometry(size, size, size), new three.MeshNormalMaterial({ vertexColors: three.FaceColors }));
推荐答案
此答案仅适用于 r.125 之前的 Three.js 版本.
以下是设置和更改立方体表面颜色的方法:
Here is how you set and change the colors of a cube's faces:
var geometry = new THREE.BoxGeometry( size, size, size );
for ( var i = 0; i < geometry.faces.length; i ++ ) {
geometry.faces[ i ].color.setHex( Math.random() * 0xffffff );
}
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, vertexColors: true } );
如果geometry.faces[i].color
在几何体渲染后发生变化,你必须设置geometry.colorsNeedUpdate = true
.
If geometry.faces[i].color
is changed after the geometry has been rendered, you must set geometry.colorsNeedUpdate = true
.
three.js r.124
three.js r.124
这篇关于更改立方体面的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文