Weld positions before generating mesh levels of detail
Simplification can only collapse an edge when the faces around it share
its vertices, so a position that appears more than once in the vertex
buffer pins every edge that touches it. A mesh exported with one vertex
per triangle corner therefore has no collapsible edge at all,
simplifyMesh() returns the input unchanged, and the loop breaks on the
very first iteration without producing a single level: importing the
Khronos Suzanne sample with --generateMeshLevelsOfDetail silently
produced nothing. Weld by position first, simplify that, and translate
the resulting indexes back to the original vertex numbering that the
vertex buffer being written out uses; Suzanne then yields ten levels,
from 6141 indexes down to 12. The meshoptimizer vertex remapping this
needs is only compiled into Quick3DUtils, so generateVertexRemap(),
remapVertexBuffer() and remapIndexBuffer() are exported next to the
existing simplifyMesh() wrapper.
Welding a position that was split only to carry different normals is
safe because the level's normals are recalculated afterwards, but that
is exactly what recalculateLodNormals=false turns off. The normals join
the weld key in that case, so a hard edge stays pinned instead of
leaving every face around it reading whichever of them the weld happened
to pick; such a mesh then yields fewer levels, or none. Attributes the
key does not cover still have to settle on one value, which is inherent
to simplifying across a seam and only affects the coarser levels.
A test imports a mesh stored with one vertex per triangle corner, in a
smoothly shaded and a faceted version, and covers both option paths.
Pick-to: 6.12 6.11 6.8
Change-Id: Ia027803ce4e1394843efa7d1bd603f0f1f0cd8f3
Reviewed-by: Christian Strømme <christian.stromme@qt.io>