haestflod Posted July 10, 2016 Share Posted July 10, 2016 Hi, I have an .obj file that has bad normals. It's exported from 3ds max a long time ago and z is up and y is forward (XZY) instead of XYZ which causes huge issues for my lighting. Related topic I think made a long time ago: http://forums.cgsociety.org/archive/index.php?t-305628.html So I'm wondering if there's anything I can do with babylon to try and fix this? Unity for example has "calculate Normals" (Normals & Tangets -> Normals -> calculate) that solves it. Importing & Exporting and disable "autosmooth" in blender also worked. Three.js auto-solved it when importing the obj. I tried the BABYLON.VertexData.ComputeNormals and it did not solve it for me. I did solve it myself by rotating the normals with this: var rotationQuat = BABYLON.Quaternion.RotationYawPitchRoll(0, Math.PI * 1.5, 0); So for the question again is there any way that I could have used babylon's existing API to solve the bad normals? Here's a playground with the model and a directional light: http://www.babylonjs-playground.com/#1S9WC2#3 Here's an imgur picture I took of my project using a shadermaterial rendering the normal values: http://imgur.com/a/466NV As you can see in the picture "up" is positive Z and forward is positive Y which is why the directional light does not work. Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 11, 2016 Share Posted July 11, 2016 Why not just use Blender to clean the mesh ? (import mesh, switch to edit mode and select all the faces, ctrl+f > recalcultate normals ; job done !) Quote Link to comment Share on other sites More sharing options...
haestflod Posted July 11, 2016 Author Share Posted July 11, 2016 I know that is one possibility I even wrote it in the post that using blender is one solution to the problem. This is the solution I went with in the end aswell. ( I have a lot of models that have the same issue ) But I was curious if there is a way to solve it with babylon to get a better understanding of babylon. My custom solution to the problem so far is: Check a face to get upvector (all y vertice points are the same) If the upvector is Z then rotate all the normals with the quaternion Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 11, 2016 Share Posted July 11, 2016 You can ask the VertexData to compute normals: var normals = []; BABYLON.VertexData.ComputeNormals(handledMesh.positions, handledMesh.indices, normals); Quote Link to comment Share on other sites More sharing options...
haestflod Posted July 13, 2016 Author Share Posted July 13, 2016 Thanks, that was it. I did 1 thing different this time adding this line after ComputeNormals(). m.setVerticesData( BABYLON.VertexBuffer.NormalKind, normals ); When I tried it few days ago this is the code I used and I guess I must have thought it'd be automatically updated. var positions = m.getVerticesData(BABYLON.VertexBuffer.PositionKind); // Now I used [] like Deltakosh wrote. var normals = m.getVerticesData(BABYLON.VertexBuffer.NormalKind); BABYLON.VertexData.ComputeNormals(positions, m.getIndices(), normals); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2016 Share Posted July 13, 2016 This should work did you check if your faces are in the right order? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.