guybrush77 / rapidobj

A fast, header-only, C++17 library for parsing Wavefront .obj files.
MIT License
159 stars 14 forks source link

Triangulate causing missing triangles? #18

Open blitz-research opened 1 year ago

blitz-research commented 1 year ago

Hi,

Trianglulate used on this file appears to be causing triangles to go missing:

https://murena.io/s/Z6MSrKkCf2Mr72Y

Screenshot showing some of the missing triangles outlined in red here:

triangulate_bug

If I skip the triangulate step and do my own simple triangulate while loading (which effectively just treats all faces like a triangle fan), everything loads correctly.

[edit] Ok, it looks like triangulate is flipping some triangles. If I force the material to be double sided, the missing triangles re-appear.

Changing lines 6983-ish to this (which basically just duplicates my loader code) fixes the problem with this model:

        dst->indices[idst + 0] = index0;
        dst->indices[idst + 1] = index1;
        dst->indices[idst + 2] = index2; // d02_is_less ? index2 : index3;
        dst->indices[idst + 3] = index0; // d02_is_less ? index0 : index1;
        dst->indices[idst + 4] = index2;
        dst->indices[idst + 5] = index3;

Not sure what d02_is_less is supposed to do though so probably not that simple. [/edit]

Bye, Mark

guybrush77 commented 1 year ago

Thanks for the report and investigation. I will take a closer look, probably this weekend.