OBJLoader returns geometries of type BufferGeometry. Calling .computeFaceNormals() on a BufferGeometry has not effect. The method only exists because of backwards compatibility.
Besides, .computeVertexNormals() has no parameters. Hence, calling the method with true as first parameter has no effect.
In general, it’s best to export your model with smooth normals from a DCC tool.
@prisoner849@Mugen87 Ah, okay, there were a bunch of Google results showing n.geometry.computeVertexNormals()/n.geometry.computeVertexNormals(true), but I guess both are outdated.
I just want to download OBJ files I may find on the net and use them, with no DCC tool.
It does only work with an indexed BufferGeometry and if duplicate vertices are actually merged/eliminated. three.js does not provide a method that transforms a non-indexed to an indexed geometry right now.
If you have an indexed geometry, you can then call BufferGeometry.computeVertexNormals().
BTW: Material.flatShading is set to false by default. So three.js always performs smooth shading. You can force flat shading by set the respective material property of if you provide flat vertex normals.
So basically if I call BufferGeometry.computeVertexNormals() and don’t see a difference, then I can assume it’s not indexed? So in this case I’d have no choice but to use a DCC to correct it?
What about the old Geometry stuff? Can I opt to use that somehow, and if so would that work (disregarding performance loss)? Or did the older Geometry classes have the same problem?
It’s best to check if geometry.index is null. If so, using Blender or a similar tool is the easiest solution.
No, since Geometry does have a method .mergeVertices(). I think sooner or later BufferGeometry needs a similar functionality. For now try this:
var tempGeometry = new THREE.Geometry().fromBufferGeometry( geometry );
tempGeometry.mergeVertices();
tempGeometry.computeVertexNormals();
geometry = new THREE.BufferGeometry().fromGeometry( tempGeometry );
I have the same problem. I tried to use your function but it returns this error: “Uncaught TypeError: THREE.Geometry is not a constructor”.
Can you help me? How can I solve it? Thanks!!