How to compute or rotate normals for obj with bad normals

Recommended Posts

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:



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:


Here's an imgur picture I took of my project using a shadermaterial rendering the normal values:


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.

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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);


Share this post

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.