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

Faces list contains indices for the raw parsed vertices, not interleaved (repeated) vertices #143

Open
laralex opened this issue Sep 7, 2022 · 3 comments

Comments

@laralex
Copy link

laralex commented Sep 7, 2022

With the test object:

o Simple
v 1.0 2.0 3.0
v 3.0 5.0 6.0
v 7.0 8.0 9.0
vt 0.0 1.0
vt 1.0  0.0
vt 0.0 0.0
vn 0.0 0.0 1.0
f 2/3/1 1/2/1 3/1/1
f 2/1/1 1/3/1 3/2/1

The interleaved array of vertices is generated correctly:

[0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 5.0, 6.0]
[1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 2.0, 3.0]
[0.0, 1.0, 0.0, 0.0, 1.0, 7.0, 8.0, 9.0]
[0.0, 1.0, 0.0, 0.0, 1.0, 3.0, 5.0, 6.0]
[0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 2.0, 3.0]
[1.0, 0.0, 0.0, 0.0, 1.0, 7.0, 8.0, 9.0]

The faces reported with scene.mesh_list[0].faces are:

[[1, 0, 2], [1, 0, 2]]

meaning that they don't index the interleaved array, because the second face should be [4, 3, 5]

Any ideas how to achieve interleaved indexing, without it I cannot render in OpenGL using glDrawElements by pushing the interleaved array into a VBO, and faces into an EBO (index buffer)

@einarf
Copy link
Member

einarf commented Sep 9, 2022

Just draw with glDrawArrays. The obj format is so obscure you can't really do index buffer in all cases. If you have an obj file with one object that could be fine.

@laralex
Copy link
Author

laralex commented Sep 10, 2022

Thanks for pointing that out, glDrawArrays works. Yet for the lack of a Python library that would make an index array from OBJ, I ended up implementing a simple OBJ parser myself. At least for a 1 object per file, that works fine indeed, and saves about 15% of GPU memory

@einarf
Copy link
Member

einarf commented Sep 11, 2022

Yup. That should work ok for single object file. The problem with multi-object files is that a face can reference a vertex index in a previous object. The index is global for the entire file.

This library also create gltf-like version of the obj file when you use cache=True option. It creates a json file referring to locations in a data file. You can then just dump the bytes into a buffer and draw with glDrawArrays. Loading the object(s) will be near instant.

I don't know many cases today were saving memory for mesh data is that important.

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

2 participants