Twinklebear / tobj

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

Add support for point and line primitives #39

Open virtualritz opened 3 years ago

virtualritz commented 3 years ago

The code already handles Lines but just stashes them as normal faces (as triangles even, if triangulate_faces is on). Points need to be added and then two more indices.

virtualritz commented 3 years ago

The reordering branch in my fork has support for points but still only as degenerate faces for now.

Twinklebear commented 3 years ago

Partial support now in 3.0.0 which includes your PR?

virtualritz commented 3 years ago

Actually, not really. What I m thinking now is this:

  1. Add support for the p and l elements.
  2. Remove the filter_out_* flags and Add an keep_degenerate_faces flag instead.
  3. Add a treat_degenerate_faces_as_other_elements that allows treating f elements with one or two indices only as if they were p or l elements.

The last point is for the case where you have an OBJ file that contains degenerate faces which are meant to represent points or lines. I dunno if this is actually common enough in the wild to warrant adding more code to allow these to be represented as such.

In general, we probably want to better model what is in an OBJ using maybe an enum?

enum Entity {
    Points(Mesh)
    Lines(Mesh)
    Mesh(Mesh)
    Curves(tbd)
    Surface(tbd)
}

P.S. Regarding Curves/Surface – I am working on a wrapper around the Ayam core to bring first class NURBS support to Rust. While I also have a rudimentary wrapper around OpenNURBS I think using OBJ files containing (trimmed) NURBS (e.g. exported from Rhino or Maya) is way easier to test this wrapper. So I will likely add support for that soon and at that point the how (see above) becomes relevant.

Twinklebear commented 3 years ago

The degenerate faces thing I haven't run into, but I also pretty much just use triangulated meshes exported from Blender. I think your proposed changes and the enum sound good. Then in the case of degenerate faces when not specifying to treat them as other elements we'd return an error back to the user.

A NURBS crate would be cool to have in Rust! From the tobj side we can add support for importing them as well but leave the actual NURBS interpretation to another standalone crate.

virtualritz commented 3 years ago

Then in the case of degenerate faces when not specifying to treat them as other elements we'd return an error back to the user.

Hmm, I understand the reasoning. But we have functionality to filter them out already. I.e. I would expect them to get filtered out when keep_degenerate_faces is set to false (by default). Silently. I.e. no error. Maybe we have use use an degenerate_face_handling enum in the LoadSettings instead:

enum DegenerateFaceHandling {
    Keep,
    FilterOut,
    /// Convert to points or lines (once we support them)
    Convert,
    /// Inflate to triangles.
    Inflate,
}
virtualritz commented 3 years ago

A NURBS crate would be cool to have in Rust! From the tobj side we can add support for importing them as well but leave the actual NURBS interpretation to another standalone crate.

I do not have time to write one. I just started working on an OpenNURBS wrapper until I realized there is actually no code for polygonal meshing meshing in the lib. The best OSS alternative seems to be Ayam. And it's author has recently gotten back to work on it (maybe the lockdown) and it is no longer under GPL. And the API is C.

Twinklebear commented 3 years ago

Oh yeah, not one from scratch in Rust that's a ton of work, a wrapper over something that's working well in C or C++ is good