为了提高性能,我在这样的循环中将网格渲染到一个 THREE.Geometry() 对象:
build : function(){ // simplified
square = new THREE.Geometry();
face = 0;
for( r = 0; r < this["rows"]; r++)
for( c = 0; c < this["cols"]; c++)
// creates square
square.vertices.push(new THREE.Vector3( x, y, z));
square.vertices.push(new THREE.Vector3( x + w, y, z));
square.vertices.push(new THREE.Vector3( x + w, y - h, z));
square.vertices.push(new THREE.Vector3( x, y - h, z));
square.faces.push(new THREE.Face4(face + 0, face + 1, face + 2, face + 3));
face+=4;
// end of loops
// This adds material to the whole grid.
// How to do it to each individual square?
squareMaterial = new THREE.MeshBasicMaterial({
color:"white",
side:THREE.DoubleSide
});
grid = new THREE.Mesh(square, squareMaterial);
scene.add(grid);
可以说,我有一个函数可以从网格(网格)中选择一组顶点(一个正方形),然后如何仅将颜色应用于这组顶点(正方形)?