我正在使用MTLLoader和OBJLoader将3D模型导入three.js。 .obj文件不包含法线,因此生成的模型看起来很块状。我试图通过将OBJLoader返回的BufferGeometry转换为Geometry对象,然后计算法线来使其平滑。这对于许多对象来说是完美的,但是其中一些turn almost completely black。
对此进行调查,我注意到在使黑色变为黑色的模型上,几乎每个顶点的顶点法线(由computeVertexNormals()计算)为(0,0,0),而在看起来正常的模型上,它们是介于-1和1。
这是我的代码:
function loadModel() {
// Load the materials first
mtlLoader.load('texture.mtl', function (materials) {
materials.preload();
// Load the object and attach the materials
objLoader
.setMaterials(materials)
.load('model.obj', function (object) {
object.children[0].geometry = new THREE.Geometry().fromBufferGeometry(object.children[0].geometry);
object.children[0].geometry.computeFaceNormals();
object.children[0].geometry.mergeVertices();
object.children[0].geometry.computeVertexNormals();
scene.add(object);
}, undefined, function (error) {
console.log(error);
});
}, undefined, function (error) {
console.log(error);
}
);
}
我该如何解决/预防这个问题?