I'm trying establish why I can't smooth shade geometry loaded with OBJLoader.
var loader = new THREE.OBJLoader(manager);
loader.load('/manmodel/js/man.obj', function (object, materials) {
console.log(object);
console.log(materials);
man = object;
man.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.geometry.computeFaceNormals();
child.geometry.computeVertexNormals( true );
child.material = new THREE.MeshPhongMaterial({
color: 'white',
shading: THREE.SmoothShading // <----------- THIS IS THE PROBLEM
});
}
});
man.position.y = -10;
scene.add(man);
});
This is the result:
If I remove the line computeFaceNormals() the model renders the same. If I remove computeVertexNormals( true ) the object renders with no lighting (black) - so I know this is doing something.
If I change the color attribute of the MeshPhongMaterial in this code, the color changes, so I also know that this is working.
I have tried to use the vertex and normal helpers to establish what the problem is, but they fail because with BufferGeometry the faces and verticices are not stored as arrays.
I have also tried modifying the man.obj file to change the 's' values from 'off' to 1. This did nothing.
As I will be loading several .obj files for different human figures, generated in Blender, and each is currently around 2MB, I prefer to do the shading on the browser than to 'bake' it into the file if this would increase file size.
THE QUESTION(s): Am I missing something here? OR, Is there a way to load the .obj file as standard Geometry, compute the normals, apply the shading, and then save as BufferGeometry?
ps. I may also need the normals for ray tracing further down the line.