自修订版54(更新2)以来MeshFaceMaterial的问题

时间:2012-12-28 20:03:34

标签: three.js

由于我使用的是版本54而不是版本48,因此我在脚本中得到了这个例外:

Uncaught TypeError: Cannot read property 'map' of undefined three.js:18155
bufferGuessUVType three.js:18155
initMeshBuffers three.js:17963
addObject three.js:21674
initWebGLObjects three.js:21608
render three.js:21145
...
THREE.JSONLoader.createModel three.js:9892
xhr.onreadystatechange

我将几何与THREE.GeometryUtils.merge合并。然后我使用合并的几何来构造网格。对于此网格,我使用MeshFaceMaterial来应用面的材质。因为r54最终会出现异常。如果我使用其他材料,它可以工作......但是我不能使用原始面孔的材料。

更新:所有面都指向材质geometry.faces[i].materialIndex,但几何图形不再包含材质数组。

更新: 我只是想合并几何并保留他们的材料:)我认为这将是解决方案但是面部的materialIndex将不会在合并时更新。我发布这个例子以某种方式解释我需要什么。

mesh1 = new THREE.Mesh(new THREE.PlaneGeometry(2,2), new THREE.MeshBasicMaterial({ color: 0xFF0000}));
mesh2 = new THREE.Mesh(new THREE.PlaneGeometry(2,2), new THREE.MeshBasicMaterial({ color: 0x0000FF}));
mesh2.position.y = 3;
THREE.GeometryUtils.merge(mergedGeo, mesh1);
THREE.GeometryUtils.merge(mergedGeo, mesh2);
scene.add(new THREE.Mesh(mergedGeo, new THREE.MeshFaceMaterial([mesh1.material, mesh2.material])));

我可以实现一个自己的逻辑来将合并的面链接到正确的材质,但这有点令人沮丧,因为它在早期版本中有效。

1 个答案:

答案 0 :(得分:10)

自r52以来migration page 中有详细说明,现在就像这样:

new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materialsArray ) );

编辑:在合并之前,您需要为每个几何图形设置材质索引

THREE.GeometryUtils.setMaterialIndex( mesh1.geometry, 0 );
THREE.GeometryUtils.setMaterialIndex( mesh2.geometry, 1 );
相关问题