在脚本中,我从仅获取几何图形的位置加载obj文件,在主场景中定义了材质后,我添加了一个由几何图形组成的网格,并定义了材质,这适用于多个obj文件,但具有相同的材质在以下屏幕截图中可以看到两个截然不同的渲染结果:
对我来说,正确的渲染是第二个,两次从Rhinoceros用相同的选项导出obj,但是两个中只有一个具有一些“空脸”,我该如何解决?
objLoader.load('obj-url', function(object) {
var temp = new THREE.Geometry();
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
temp.fromBufferGeometry(child.geometry);
}
});
setPlanarUVA(temp);
temp = new THREE.Mesh(temp, material);
temp.needsUpdate = true;
scene.add(temp);
self.g.needsUpdate = true;
function setPlanarUVA(geometry, side) {
var self = this,
gData = this.g.gData;
geometry.computeBoundingBox();
var max = geometry.boundingBox.max,
min = geometry.boundingBox.min,
faces = geometry.faces,
offset = new THREE.Vector2(0 - min.z, 0 - min.y),
range = new THREE.Vector2(max.z - min.z, max.y - min.y);
geometry.faceVertexUvs[0] = [];
for (var i = 0; i < faces.length; i++) {
//salvo i vertici della faccia che sto processando
var v1 = geometry.vertices[faces[i].a],
v2 = geometry.vertices[faces[i].b],
v3 = geometry.vertices[faces[i].c];
var v1_y = (((v1.y + offset.x) / range.y)),
v2_y = (((v2.y + offset.x) / range.y)),
v3_y = (((v3.y + offset.x) / range.y));
geometry.faceVertexUvs[0].push([
new THREE.Vector2((v1.z + offset.x) / range.x, v1_y),
new THREE.Vector2((v2.z + offset.x) / range.x, v2_y),
new THREE.Vector2((v3.z + offset.x) / range.x, v3_y)
]);
}
}