Deduplicate images, samplers, textures - #48
Conversation
a915d11 to
eb3e9fd
Compare
|
Hmm, nope, using pointers here for texture dedupe was a bad idea. Effectively, what was done here in the earlier version of the PR - I now have to do on the client side. have to deduplicate the textures myself before sending them to I think this using pointers is a wrong approach in principle. This approach actually means no real deduplication within the library, because if the pointers are pointing to the same object - deduplication was already done by the client. So the heavy lifting was done, and the all that library is doing is not screwing it all up. I think the library should in fact do this heavy lifting and do real deduplication - object comparison and reuse the same object index in GLTF if the values are the same, even if the actual instances in memory are different. With meshes the approach was different purely because of technical limitations - comparing large meshes directly by vector attribute values is prohibitively expensive. So that was pushed onto the client where the logic and metadata around the scene creation allow to avoid direct comparisons. For all other objects - comparison is not technically difficult and should be done by the library. I'll make another PR. |
* Deduplicate images, samplers and textures when adding a tex * Fix tests * Address comments * Change test to check for no-empty-sampler state * Rollback unnecessary changes
This PR adds logic to
writer.AddTexture()method to check and reuse existing resources if they are identical to newly added, instead of adding more.Images are compared by URIs only, since byte buffer embedding is not supported yet.
Samplers are compared by four numeric values they have.
Textures are compared by source (image) and sampler indices, and by the extensions map.
ChildOfRootPropertyvalues are not checked for any objects.This change of behaviour required minor changes in the extension tests - the textures in the extensions now need to be actually different so they are given different indices. An empty texture is identical to any other empty texture, so I made them non-empty.