2012-11-13 40 views
0

我有一個循環,我創建具有不同幾何形狀的多個網格,因爲每個網格都有一個紋理:具有一個幾何圖形和不同紋理的多重網格。錯誤

var geoCube = new THREE.CubeGeometry(voxelSize, voxelSize, voxelSize); 
var geometry = new THREE.Geometry(); 

for(var i = 0; i < voxels.length; i++){ 
    var voxel = voxels[i]; 
    var object; 
    color = voxel.color; 
    texture = almacen.textPlaneTexture(voxel.texto,color,voxelSize); 
    //Return the texture with a color and a text for each face of the geometry 
    material = new THREE.MeshBasicMaterial({ map: texture });      
    object = new THREE.Mesh(geoCube, material); 

    THREE.GeometryUtils.merge(geometry, object); 
} 

//Add geometry merged at scene 
mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial()); 
mesh.geometry.computeFaceNormals(); 
mesh.geometry.computeVertexNormals(); 
mesh.geometry.computeTangents(); 

scene.add(mesh); 

但現在我有這個錯誤在JavaScript代碼three.js所

遺漏的類型錯誤:無法讀取的不確定

財產 '地圖' 在功能:

function bufferGuessUVType (material) { 
} 

更新:

最後,我已經刪除了合併的解決方案,並且我可以爲所有體素使用唯一的幾何體。儘管我認爲如果使用合併網格,應用程序的性能會更好。

回答

0

某些方法期望材料陣列位於網格面材中。例如:

function getBufferMaterial(object, geometryGroup) { 

    return object.material instanceof THREE.MeshFaceMaterial 
     ? object.material.materials[ geometryGroup.materialIndex ] 
     : object.material; 

}; 

它可能通過引用材質數組來處理幾何體和網格面材質。那麼,在創建網格線會看起來像:

mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(geometry.materials)); 

和循環處理中的體素:

​​

在幾何每個面也需要有一個materialIndex分配還是會有是一個錯誤。如果知道每個體素有多少個面,則循環遍歷geometry.faces []並分配materialIndex可能是一種好方法。

1

對於R53 +代碼應該是這樣的:

var geoCube = new THREE.CubeGeometry(voxelSize, voxelSize, voxelSize); 
var geometry = new THREE.Geometry(); 
var materials = []; 

for(var i = 0; i < voxels.length; i++){ 

    for (var j = 0; j < geoCube.faces.length; j ++) { 
    geoCube.faces[ j ].materialIndex = i; 
    } 

    var object = new THREE.Mesh(geoCube); 
    // here I assume you'll me positioning the object. 
    THREE.GeometryUtils.merge(geometry, object); 

    var voxel = voxels[i]; 
    var texture = almacen.textPlaneTexture(voxel.texto,voxel.color,voxelSize); 
    materials.push(new THREE.MeshBasicMaterial({ map: texture })); 

} 

// Add geometry to scene 

var mesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials)); 
mesh.geometry.computeFaceNormals(); 
mesh.geometry.computeVertexNormals(); 

scene.add(mesh); 
相關問題