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

Fix obj file loading #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

NarinderS
Copy link

@NarinderS NarinderS commented Feb 13, 2024

Fixes #83.

When loading obj files, the attrib.normals vector only contains the unique normals present in the mesh. To associate a normal to a vertex you have to use the face indices structure. In the current code, the following obj file causes an out of bounds array access:

o Plane
v 0.000000 0.000000 0.000000
v 0.353553 0.353553 0.000000
v 0.353553 -0.353553 0.000000
vn -0.0000 -0.0000 1.0000
s 0
f 2//1 1//1 3//1

I think this issue is present with UV coordinate loading as well.

@NarinderS
Copy link
Author

NarinderS commented Feb 13, 2024

One thing missing from this is how to deal with vertices with multiple normals, for example:

o Plane
v 0.000000 0.000000 0.000000
v 0.353553 0.353553 0.000000
v 0.353553 -0.353553 0.000000
v 0.044583 -0.475301 0.307226
vn -0.0000 -0.0000 1.0000
vn 0.5022 0.5022 0.7040
s 0
f 2//1 1//1 3//1
f 1//2 4//2 3//2

Here vertex 1 and 3 have two normals, and I think only face or averaged normals make sense here?

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

Successfully merging this pull request may close these issues.

Incorrect vertex normals when loading obj file
1 participant