KhronosGroup / COLLADA2GLTF

COLLADA to glTF converter
Other
536 stars 157 forks source link

Linestrips and other primitive types are not supported #65

Open bjbrewster opened 7 years ago

bjbrewster commented 7 years ago

LINE_STRIPS, TRIANGLE_STRIPS and TRIANGLE_FANS do not appear to be supported.

Suprisingly, Converter Limitations Wiki does not mention the lack of supported types.

The converter currently supports LINES, TRIANGLES, POLYLIST, and POLYGONS primitive types where the last two are converted to TRIANGLES. See convert/meshConverter.cpp.

LINES was the most recently added type when this project was under glTF project (https://github.com/KhronosGroup/glTF/pull/302) and can be used as a guide to add other types.

It is trivial to allow LINE_STRIPS but most of the work seems to be in helpers/geometryHelpers.cpp to support splitting the primitive's mesh into separate meshes when source mesh is too big (limit num indices to < 65536). On investigation, I believe this method contains bugs such as primitiveCompleted is set to true to close a sub mesh at the end of the loop but never reset to false so additional sub meshes will closed with very little data in them.

I was going to add full support for the missing types but I have no confidence in making changes without unit tests or even a set of COLLADA models and expected glTF output files to compare the result.

bjbrewster commented 7 years ago

I'm having another stab at this. I'm initially adding support for linestrips but will add TRIANGLE_STRIPS/FANS later on once I understand the code better.

It's tempting to just triangulate TRIANGLE_FANS like the converter does for POLYGONS and POLYLIST as fans are usually small primitives. Triangle strips are often used for terrain rendering and in high res models - often created by mesh optimisation libs that group as many triangles into strips as possible.

Related issues: https://github.com/KhronosGroup/glTF/issues/129 https://github.com/KhronosGroup/glTF/issues/135

lasalvavida commented 7 years ago

@bjbrewster, just a heads up glTF does support line strips, triangle strips and triangle fans as a primitive mode, so you don't need to do any extra processing or triangulation, just set the correct mode.

The 2.0 branch already does this, but a contribution adding the support for 1.0 would be welcome.

bjbrewster commented 7 years ago

@lasalvavida thanks for the heads up. Enabling LINE_STRIPS mode is trivial. I just have to add support to the geometry helper that splits the mesh when more then 65K vertices.