zeux/meshoptimizer

gltfpack: Preserve custom vertex attributes during optimization

FreakTheMighty opened this issue · 4 comments

It would be helpful to preserve custom attributes when using gltfpack. Currently, if I pass a glb in with a custom _ID vertex attribute, the resulting file has that attribute stripped. Instead, I'd like to see those attributes preserved, and when simplification is applied the indexes that survive simplification should be copied to the new model.

Attached are two glbs with custom _ID vertex attributes.

Archive.zip

zeux commented

Yeah, I had a similar request related to _BATCHID from glTF files. gltfpack in general can't reasonably support completely custom attributes because it requires knowledge about the attribute meaning to be able to pack/compress/optimize it, however it feels very reasonable to support IDs specifically. I was planning on doing this as part of eventual support for EXT_mesh_features but there's probably no specific reason why it can't be done for ID attributes separately.

Potential patch for copying the ID attributes. 55d7092

@zeux I'm not entirely understanding why we can't generically handle vertex attributes - I'm probably missing something.

If a user has a custom vertex attribute of a specific type, I'd expect that whichever vertexes are removed, the corresponding indexes for that attribute would also be removed. Is it more complicated than that?

zeux commented

It's not about copying or removal, it's about whether to preserve the type, how to encode the attribute and which compression filters to use, and how/whether to modify the attribute under various transformations. gltfpack performs a full scene reassembly so it ideally needs to know the semantics behind every component of the scene to perform it correctly and optimally. It's possible to encode every attribute as vec4 of floats with no compression, but that defeats the purpose of using gltfpack and may still misbehave under certain transformations like mesh merging depending on what the attribute means.