更改使用face3创建的网格的颜色 [英] Change the color of mesh created using face3

查看:63
本文介绍了更改使用face3创建的网格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用第3面和第3个js创建了一个网格.但是所需的颜色不会在网格上反射.这是我使用的代码.

I have created a mesh using face 3 and three js. But the desired colour is not reflecting on the mesh. Here is the code used by me.

var geometry = new THREE.Geometry();
var f = 0;
for (var i = 0; i < data.real.length; i++, f += 4) {
    var o2 = i == data.real.length - 1 ? 0 : i + 1;
    var tl = data.real[i];
    var tr = data.real[o2];
    var bl = data.zeroAxis[i];
    var br = data.zeroAxis[o2];

    geometry.vertices.push(tl, tr, br, bl);
    geometry.faces.push(new THREE.Face3(f, f + 1, f + 2));
    face.materials = [ new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } ) ];

    geometry.faces.push(new THREE.Face3(f, f + 3, f + 2));
}
var material = new THREE.MeshPhongMaterial({
    color : new THREE.Color(0x008000),
    side : THREE.DoubleSide,
    transparent : true,
    opacity : 0.5
});
var object = new THREE.Mesh(geometry, material);
object.position.set(0, 0, 0);
this.plot = object;
this.tb.scene.add(object);
this.tb.render();

推荐答案

感谢您的答复,我使用以下代码解决了上述问题.

Thanks for the reply, I resolved the above problem using the following code.

var normal = new THREE.Vector3(0, 1, 0); // optional
    var color = new THREE.Color(color); // optional
    var materialIndex = 0; // optional
    geometry.faces.push(new THREE.Face3(f, f + 1, f + 2, normal, color,
            materialIndex));
    geometry.faces.push(new THREE.Face3(f, f + 2, f + 3, normal, color,
            materialIndex));

请提出改进​​建议.

这篇关于更改使用face3创建的网格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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