此代码使用 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);