tobj icon indicating copy to clipboard operation
tobj copied to clipboard

Add support for point and line primitives

Open virtualritz opened this issue 3 years ago • 7 comments

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 avatar Apr 28 '21 01:04 virtualritz

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

virtualritz avatar Apr 29 '21 12:04 virtualritz

Partial support now in 3.0.0 which includes your PR?

Twinklebear avatar May 12 '21 02:05 Twinklebear

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.

virtualritz avatar May 12 '21 11:05 virtualritz

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.

Twinklebear avatar May 12 '21 14:05 Twinklebear

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 avatar May 12 '21 14:05 virtualritz

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.

virtualritz avatar May 12 '21 14:05 virtualritz

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

Twinklebear avatar May 12 '21 15:05 Twinklebear