Skip to content

Deduplicate Meshes does not preserve Materials of Mesh Instances with differing Materials #836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
3 of 7 tasks
ludwigseibt opened this issue Apr 9, 2025 · 4 comments
Open
3 of 7 tasks
Assignees

Comments

@ludwigseibt
Copy link

Describe the bug 💬

When exporting a .glb from Blender that has several instanced cubes with different materials (the materials are assigned to the objects, not the object data), we produce a .glb with duplicated meshes that could be deduplicated. Essentially we are not using instances anymore. We could use the "Deduplicate Resources: Meshes" feature to get rid of these duplicates, but unfortunately when doing that, the material assignments are lost. Read through the steps to reproduce below, to better understand what I mean.

Does the .glTF Format allow for instances with different materials? If yes, than this would be a bug in the Blender exporter, correct?

I am aware of the material variants extension.

In any case, this report is about the "Deduplicate" feature messing up the material assignments.

Steps to reproduce 🔢

How to creata .glb that has this issue with Blender:

  1. Instance a cube several times in Blender.
  2. Assign a different material to each instance by linking the materials to object, not object data. This is the button to the right of the material name.
  3. Note that object data is still shared.
  4. Export .glb with standard settings.

How to reproduce the Problem in Unity:

  1. Import the .glb we created before with default settings.
  2. Note that several meshes with the same name have been imported, while only one would be neccessary.
  3. Use "Deduplicate Resources: Meshes".
  4. The meshes are now shared, but the material assignments have changed.

The material Assignments should be retained.

Files to reproduce the issue ♻

No response

Editor Version 🎲

6000.0

Render Pipeline and version

17.0.4

UnityGLTF Version

2.16.0-pre.2

Operating System 👩‍💻

Windows

When does this problem happen?

  • Editor Import
  • Runtime Import
  • Editor Export
  • Runtime Export

Additional Info 📜

No response

Validations 🩹

@hybridherbst
Copy link
Collaborator

hybridherbst commented Apr 9, 2025

Hm, I'm not sure if I can follow the Blender explanation.

When using "duplicate linked" and then assigning materials via Object overrides, the resulting GLB looks completely correct to me – it has 1 (shared) mesh and 3 materials, in this case:

Image

But I can confirm that it behaves incorrectly on import in UnityGLTF – it creates 3 meshes with deduplication set to "None" (it should only create one) and the materials get messed up with "Deduplicate: Meshes". Thanks for the report! This is unexpected – those code paths are quite well tested – so it's likely a regression.

Test file: InstancedMeshes.glb.zip

@ludwigseibt
Copy link
Author

Hey, thanks. Its not a bug in the Blender exporter then. I did not find any other tool to confirm, that the duplication is in the exported glTF. The only Bug is the one in the UnityGLTF Importer.

Which tool did you use to inspect your .glb? I would like to check mine.

@hybridherbst
Copy link
Collaborator

hybridherbst commented Apr 15, 2025

Hi again, the tool I used here is https://viewer.needle.tools. Clicking on "File Info" will show meshes and materials in the file. If you need even more low-level data, you can click on "JSON" to see the actual glTF JSON from the file, and can navigate into meshes, materials and so on.

Would you mind checking if the referenced PR fixes your issue?
(the PR does currently not improve the initial import – which I agree should already only have one mesh. It does fix the bug that when deduplicating you end up with wrong materials.)

@ludwigseibt
Copy link
Author

Hey. Thanks for the update. The PR does fix the deduplication issue. Good job.

I think this issue should probably remain open until the initial duplication of the meshes in the importer is also fixed. Go ahead and close it if you prefer to make a separate issue out of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants