如何更改obj文件的面部颜色?

时间:2013-03-05 08:31:14

标签: colors three.js vertex

此代码使用Three.js库在画布中创建一个3d对象。我想为保存在json文件中的几何体的顶点或面着色。

var loader = new THREE.JSONLoader();
var callbackMale = function (geometry, materials) {
    // the face's indices are labeled with these characters 
    for (var i = 0; i < 100; i++) {
        var faceIndices = ['a', 'b', 'c', 'd'];
        var face = geometry.faces[i];
        // determine if face is a tri or a quad
        var numberOfSides = (face instanceof THREE.Face3) ? 3 : 4;
        // assign color to each vertex of current face
        for (var j = 0; j < numberOfSides; j++) {
            var vertexIndex = face[faceIndices[j]];
            // initialize color variable
            var color = new THREE.Color(0xffffff);
            color.setRGB(Math.random(), Math.random(), Math.random());
            face.vertexColors[j] = color;
        }
        geometry.dynamic = true;
        geometry.needsUpdate = true;
        createScene(geometry, materials, 90, FLOOR, 50, 105)
    }
}; // fine callBack
loader.load("brain.js", callbackMale);

0 个答案:

没有答案