olson-sean-k / plexus

Polygonal mesh processing.
https://plexus.rs
MIT License
163 stars 15 forks source link

Support indexing iterator expressions with variable arity. #7

Closed olson-sean-k closed 6 years ago

olson-sean-k commented 6 years ago

The IndexVertices trait can be used to index arbitrary streams of vertex data, but requires that the arity of the topology (polygons) is constant (i.e., all triangles or all quads). It should be possible to index streams with variable arity and, for example, generate a Mesh with a mix of triangles and quads. The UvSphere primitive generates both triangles and quads, but currently must be triangulated before conversion into a MeshBuffer or Mesh.

Provide a mechanism for preserving the original topology of such generators when indexing/converting into a Mesh. (Note that this really don't apply to MeshBuffer, which is meant mostly for rendering pipelines that typically expect a constant arity anyway.)

olson-sean-k commented 6 years ago

This should be addressed by 43d5dcc. That commit changes IndexVertices and related indexing traits so that indeces are emitted as polygons instead of raw usizes, which preserves topology and arity. This more closely mirrors the indexed polygons and unique vertices generated by primitives, and allows a primitive like UvSphere to be indexed and collected into a Mesh without needing to triangulate the topology first.

The MapVerticesInto trait has also been changed to support this and now relies on the associated type of Topology to discern the input vertex data.

MeshBuffer still enforces arity constraints because it only supports "flat" index buffers. Because triangulation is not required, it is no longer performed automatically in FromIndexer implementations.