Twinklebear / tobj

Tiny OBJ Loader in Rust
MIT License
233 stars 47 forks source link

Add support for n-gons #22

Closed virtualritz closed 4 years ago

virtualritz commented 4 years ago

Many geometries found in OBJs are not made out of triangles and this is a feature. If I load an OBJ to send to an high end offline renderer, the last thing I want is probably triangles (as such I also do not want the reader to convert the OBJ to triangles, on-the-fly, as tobj does).

Basically the mesh returned would then consist of:

mesh.positions
mesh.facevertices // number of vertices per each face (u32)
mesh.indices
virtualritz commented 4 years ago

I quickly made a file in Wings3D – this is an all quad model. Feel free to use however you want.

knotty02.zip

Twinklebear commented 4 years ago

Hey @virtualritz , yeah this can be added as an option telling tobj not to triangulate. Then it can just give you back the face vertex counts of the quads/polygons directly. Thanks for the test model!

virtualritz commented 4 years ago

Yes, this would be super useful. I am using tobj here (have a play).

Twinklebear commented 4 years ago

Very cool! I'll ping you on this issue when I've added support and released and updated crate

virtualritz commented 4 years ago

Cheers!

Twinklebear commented 4 years ago

Should be done in 1ae79e6d1ada57950e4589b32921b28c704e7140 , I'll cut a release shortly. This is a breaking change for the API since I'm just adding a bool option to load_obj which will set whether or not to triangulate the loaded faces

The number of indices used by each face are now stored in Mesh::num_face_indices, check out the print mesh example. This is the same as tinyobjloader, though I named the list of verts/indices used per-face as num_face_indices instead of num_face_vertices

Twinklebear commented 4 years ago

Let me know if you run into any issues!

virtualritz commented 4 years ago

Yeah, cool. I am trying this in a few hours. Will let you know.

virtualritz commented 4 years ago

Done.

A two line change. Nice one. The commit only looks big because of Rustfmt stuff.

virtualritz commented 4 years ago

You should update the README since your crate is actually the only one in the whole Rust universe that doesn't triangulate on import (if not asked to).

Twinklebear commented 4 years ago

That's a good point! I'll update it