PLY: Improve robustness and performance of the new PLY importer #105842

Merged
Aras Pranckevicius merged 10 commits from aras_p/blender:ply-importer into main 2023-03-17 12:20:56 +01:00

10 Commits

Author SHA1 Message Date
Aras Pranckevicius f15f92fa6f PLY: fix linux build error/warnings
buildbot/vexp-code-patch-coordinator Build done. Details
2023-03-17 12:08:54 +02:00
Aras Pranckevicius fafca64d00 PLY: cleanup, comments, index validation
buildbot/vexp-code-patch-coordinator Build done. Details
2023-03-17 11:40:07 +02:00
Aras Pranckevicius 711a0ea7f2 PLY: do not use exceptions in inner loops, fix exporter face indexing
Using exceptions to indicate errors from "hot" code paths does
incur non-trivial overhead. Instead, report errors using oldskool
method of returning error messages.
2023-03-17 10:54:41 +02:00
Aras Pranckevicius 7fb7a5852b PLY: optimize importing by having flat index buffer instead of an array for each face 2023-03-17 10:54:41 +02:00
Aras Pranckevicius 1a8d3adfeb PLY: optimize importing by avoiding tiny file reads
Conceptually similar to OBJ importer, this one reads input file in
chunks (64kb), and then parses lines (header or ascii ply files)
or reads binary data from that, refilling the buffer as necessary.

Pure parsing performance is about 2x faster (tested on a Mac).
2023-03-17 10:54:41 +02:00
Aras Pranckevicius e504dab2af PLY: support "tristrips" element 2023-03-17 10:54:41 +02:00
Aras Pranckevicius a007a81f2f PLY: handle case where face element is not only a single vertex indices property
Both binary and ascii cases, added test coverage
2023-03-17 10:54:41 +02:00
Aras Pranckevicius 20e8222c44 PLY: improve binary parser robustness
- Was assuming that positions/normals/UVs are floats and colors are
  bytes.
- Was assuming that faces are always byte list size and int32 indices.
- Was assuming that edge vertex indices are always int32.

Added a bunch of tests that cover the above, that were returning
wrong data or crashing previously.

It should now be faster too, due to reading not one property at a time,
but whole row or list at a time.

Also the whole code is merged together between ascii and binary into
ply_import_data.cc/hh, since it shares most of the "figure out
property indices" logic.

There's also a test case with big endian binary file; coverage of
that was completely non-existent before.
2023-03-17 10:54:41 +02:00
Aras Pranckevicius 1522d4b82a PLY: improve ascii parser robustness and performance
- Was not handling type alias names (float32, uint32, int8 etc.),
- Was assuming that elements always follow in this order: vertex,
  face, edge. This is common but not always the case.
- Was not handling whitespace that is not literal ASCII space character
  (but e.g. a tab instead).
- Was not checking for partially present properties (e.g. if just "nx"
  is present but not "ny" and "nz", it was still assuming whole
  normal is there).
- Was assuming that positions/normals/UVs are always floats, and colors
  are always uchars. But e.g. positions are sometimes doubles,
  or colors are floats. Now that is handled.

Added a bunch of tests that cover the above, that were returning
wrong data or crashing previously.

It's now faster too, due to no longer splitting each input line
into a vector of std::string objects.
2023-03-17 10:53:44 +02:00
Aras Pranckevicius 5d5e326e91 PLY: simplify import tests
Instead of loading dummy .blend file and importing a ply file
into that, test only the "read ply file and import into a PlyData
object" bit.

Also rename the PLY import suite/fixture name to start with "ply_"
so that it's the same prefix as for export tests.
2023-03-17 10:52:12 +02:00