ksons/gltf-blender-importer

Importer duplicates accessors in memory for every mesh that references it, causing extreme memory usage

Closed this issue · 3 comments

There is a problem regarding shared accessors. If you have a single accessor containing all vertices for the .gltf file, but there are multiple meshes, then all vertices in that accessor will get loaded into every mesh. This is a big problem when you have a big .gltf with hundreds of meshes. For instance, we had a .gtlf with 150k tris, but when loading it, the importer would load 260 million verts because of the duplication. This caused Blender to sit at a whopping 10GB memory usage, in an empty scene with just that model.

Here is a simple example of 2 boxes. The caps are separate meshes, and the body is a single mesh. So 3 submeshes per box for body and caps, 48 vertices total in the accessor. This means 2348=288 vertices loaded in Blender, where we would only expect 48 vertices loaded.
incorrect.zip

This problem came to light when exporting using the Sketchup GLTF exporter by CentaurMare. This plugin puts all vertices in a single accessor to save a bit of file size. The author of that plugin was very helpful, and we had some back and forth to come to this conclusion. The author says he discussed the problem on https://gitter.im/KhronosGroup/glTF to check if shared accessors like that are part of the .gltf spec. Consensus was that it is, and so it should be a bug in the importer in Blender rather than the exporter in Sketchup. Maybe worth noting is that the official Unity GLTF importer exhibits the exact same issue as the Blender importer, I have made a report there as well.

Ah, I see what you mean. If there are four vertices, but the indices array is [0,1,2], we should only "draw" the first three vertices, but we draw them all.

Can you try my iss29 branch and see if it's fixed there?

I am extremely swamped at work right now, I can hopefully check it out next week. Thanks for looking into it.

Hi,

I tried the branch, and it appears to be working fine now. No more crazy high vertex counts or memory usage, and I don't see any obvious problems with the models themselves. Thanks!