saturday06 / VRM-Addon-for-Blender

VRM Importer, Exporter and Utilities for Blender 2.93 to 4.2
https://vrm-addon-for-blender.info
MIT License
1.33k stars 142 forks source link

Bug report: VRM0 Exporter: Lack of Sparse Accessor Support Resulting in Large File Sizes #559

Open madjin opened 2 months ago

madjin commented 2 months ago

Describe the bug

The current implementation of the VRM0 exporter does not support generating sparse accessors. When I import a VRM0 file with sparse accessors and then export without doing any changes the exported file size expands much larger.

image

To Reproduce

Steps to reproduce the behavior:

  1. Import VRM file that has sparse accessors (tested with vrm0 and vrm1)
  2. Export VRM file with default settings
  3. Notice that the exported VRM0 file does not contain sparse accessors and has a significantly larger file size compared to the original VRM0 file.

Here is a couple sample files with sparse accessors to test with:

1.vrm.zip

1996.vrm.zip

Expected behavior

Import and export to have the same file size if no changes were applied. For example, here's a couple other programs I tested to show that it's not the VRM file fault. The input and output are around the same size, unless sparse accessors were removed:

image

Expected Behavior:

Actual Behavior:

Screenshots

Perhaps might want to look into these files:

Screenshot from 2024-09-05 13-30-31

When I modify like 2131 in vrm1_exporter.py to set export_try_sparse_sk=True the filesize doubles still from 34M -> 62M

Desktop (please complete the following information)

Additional context

Lyuma mentions sparse accessors here: https://github.com/saturday06/VRM-Addon-for-Blender/issues/381#issuecomment-1838365762

(Via Claude 3 Opus): To address this issue, I suggest the following steps:

  1. In the export_vrm method of the Vrm0Exporter class, include the export_try_sparse_sk=True parameter when invoking the glTF exporter, similar to the VRM1 exporter.
  2. Update the mesh_to_bin_and_dict method in the Vrm0Exporter class to export sparse accessors when the data is suitable, following the glTF specification. This may involve modifying the logic to identify and generate sparse accessors based on the sparsity of the data.
  3. Ensure that any other relevant methods or classes in the VRM0 exporter are updated to handle sparse accessors correctly.