vrm-c / UniVRM

UniVRM is a gltf-based VRM format implementation for Unity. English is here https://vrm.dev/en/ . 日本語 はこちら https://vrm.dev/
https://vrm.dev/en
MIT License
2.64k stars 427 forks source link

Duplicate meshes lose their skin on export #965

Open lyuma opened 3 years ago

lyuma commented 3 years ago

Describe the bug

If multiple SkinnedMeshRenderer objects reference the same mesh, only one of them will export a skin in glTF. The other copies export as non-skinned meshes.

To Reproduce

This bug was not present in UniGLTF 0.66. It happens only in UniGLTF 0.74.

e.g. Steps to reproduce the behavior:

  1. Import the following GLB file: duplicate_skinned_mesh_combined.zip
  2. Add the imported prefab to the scene.
  3. In the Animation window, play the Animation to make sure it is imported correctly. It should animate two skinned cylinders.
  4. Select the root object.
  5. UniGLTF -> Export UniGLTF-2.10.0
  6. Confirm the Export. Save into the Unity project. For reference, here is the bad file produced by the glTF export: duplicate_skinned_mesh_combined_reexp.zip
  7. After the newly exported file is imported, add the newly imported prefab to the scene,.
  8. Select CylinderLeft. It will have a SkinnedMeshRenderer component
  9. Select CylinderRight. It will be MeshRenderer + MeshFilter.
  10. Play the animation. Only one cylinder is animated.

Files: Original input GLB file Incorrect Export GLB from UniGLTF

Expected behavior

Currently, it seems that a map is created from Mesh to SkinnedMeshRenderer. This map is used to resolve the corresponding skin object. However, it will fail if multiple SkinnedMeshRenderers share the same mesh.

Instead, I expect each SkinnedMeshRenderer object to create its own glTF skin object, even if the mesh is shared.

In UniVRM 0.66, the duplicate meshes would create different GLTF meshes. This is less ideal, but technically valid. Reverting to this behavior would also solve this issue.

Screenshots

Here is a screenshot showing one copy of the mesh being skinned, and the other mesh being non-skinned: image

Validation report for the original input GLB file showing no warnings or errors: image

Environments (please complete the following information):

Additional context

ousttrue commented 3 years ago

ToDo: animation