Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computeVertexNormals doen't work correctly with mesh loaded using OBJ Loader #8378

Closed
2 of 10 tasks
slavielle opened this issue Mar 16, 2016 · 11 comments
Closed
2 of 10 tasks

Comments

@slavielle
Copy link

Description of the problem

I'm using computeVertexNormals on mesh from OBJ and VRML Loader in order to have a smooth shading applied.

It works with VRML Loader but it don't using OBJ Loader with exactly the same mesh.

You can see how normal looks like in the 2 cases :

cone-obj-normals
cone-vrml-normals

VRML is smooth shaded and normals (even if inside the mesh) are mingled for one given vertex.
OBJ mesh normals are diverging for one given vertex and consequently mesh is not smooth shaded.

The question is ... why ?

One difference I have noticed is loaded mesh use geometry in VRML case and BufferGeometry in OBJ case.

Thanks in advance for answers

Three.js version
  • Dev
  • [x ] r74
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • [] All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, ...)
@WestLangley
Copy link
Collaborator

OBJLoader returns non-indexed BufferGeometry (a.k.a., triangle soup), which does not share vertices, so the computed vertex normals will be face-orthogonal.

BTW, even if vertices are shared, if you call computeVertexNormals(), you have to be careful not to share vertices on hard edges. So your cone example will be a bit tricky. You must duplicate vertices at the tip of the cone, for example. It would be better to specify proper normals in your model.

@mrdoob Should OBJLoader return indexed BufferGeometry, instead?

Related: #7201

@slavielle
Copy link
Author

Thanks for the answer

I guessed it was something like that.... (BufferGeometry which does not share vertices), but it looks like a problem to me: In the OBJ format, vertices are described as shared (indexed), so the loaded mesh doesn’t fit the geometry described in the OBJ file somehow. Using non-indexed BufferGeometry doesn’t allow using computeVertexNormals + smooth shading on loaded geometries ... a bit inconvenient. Besides having different behaviors on mesh depending on the file format (VRML/OBJ) is a bit weird.

I don’t have a good grasp about what using indexed or non-indexed BufferGeometry involves deep indside three js/WebGL. It should make sense for some reason ... but in worse case, couldn't we have it as an option for loaders?

Thanks to point me out the "crease angle" problem ... should be great to have this in computeVertexNormals method as a parameter ;) but it's not the point.

Thanks a lot

@mrdoob
Copy link
Owner

mrdoob commented Mar 17, 2016

@mrdoob Should OBJLoader return indexed BufferGeometry, instead?

The reason it doesn't return indexed is because the obj format doesn't map well to indexed. In obj, vertices, normals and colors don't share the same index.

@WestLangley
Copy link
Collaborator

In obj, vertices, normals and colors don't share the same index.

Ah, yes.

@slavielle
Copy link
Author

Thanks for the answer,

I see what you mean about different indexes ...

Example of a face in my OBJ:

f 6/9/13 5/7/13 14/1/13

with vertex-index/texture-uv-index/normal-index for every vertex of the described face...for example for texture in indexed BufferGeometry, you must have one uv indexed value corresponding to one indexed vertex and that not necessary the case in OBJ format, i'm i right ?

a few questions :

  • is this problem is the same for normals in indexed BufferGeometry (one indexed normal for one indexed vertex)
  • for uv maps is this limitation due to three.js or WebGL ?

For UV maps, it looks like a defect to me : I don't understand why all faces sharing a vertex should refer to the same point in uv map.

@mrdoob
Copy link
Owner

mrdoob commented Mar 17, 2016

It's a limitation of WebGL.

@slavielle
Copy link
Author

Ok, So it makes sense to me now ... but :) ... destroying vertices index information when loading OBJ seems to still a problem.

In fact, back to the issue, that means you could never have a smooth shading on OBJ using computeVertexNormals nor any computed method : If normals are not correctly set in the OBJ file, its over right ?

vertices Index information shouldn't be kept somewhere ?

@WestLangley
Copy link
Collaborator

As I said,

It would be better to specify proper normals in your model.

@slavielle
Copy link
Author

yeah in a perfect world, it would :)

@mrdoob
Copy link
Owner

mrdoob commented Mar 17, 2016

You could compute the normals in Blender and re-export.

@slavielle
Copy link
Author

Ok i'll do that, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants