Skip to content
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

Avoid Redundant Mesh Exports for Multiple Geometry Modifiers #2446

Open
PMZeroSkyline opened this issue Dec 18, 2024 · 7 comments
Open

Avoid Redundant Mesh Exports for Multiple Geometry Modifiers #2446

PMZeroSkyline opened this issue Dec 18, 2024 · 7 comments

Comments

@PMZeroSkyline
Copy link

Summary: When exporting to GLTF 2.0 format, if multiple geometry node modifiers reference the same mesh through properties, the current exporter generates multiple copies of the same mesh, one for each modifier. This results in redundant meshes being included in the exported GLTF file. The requested feature is to optimize the export process so that the referenced mesh is only exported once, and subsequent references in different geometry node modifiers simply point to the original mesh.

Detailed Description: In scenarios where a single mesh is referenced multiple times through different geometry node modifiers (e.g., in a procedural setup or instances), the current exporter exports multiple identical copies of the same mesh for each reference. This redundancy can lead to larger file sizes and unnecessary duplication in the GLTF output.

It would be more efficient if the exporter could recognize when multiple geometry node modifiers refer to the same mesh (via properties), and instead of exporting the mesh multiple times, it would export it once and reference it in the node hierarchy. This would reduce the size of the exported GLTF file and improve the performance when loading the model in a 3D viewer or engine.

Expected Behavior:

If a mesh is referenced by multiple geometry node modifiers (via property references), the exporter should export the mesh once.
In the GLTF file, the mesh should be defined only once, and each reference to it (from different geometry node modifiers) should point to the original mesh.
The exporter should handle this optimization automatically without requiring manual adjustments from the user.

Benefits:

Smaller GLTF file sizes.
Faster export times due to reduced duplication.
Better memory management when the GLTF file is loaded into a 3D engine or viewer.

Example Scenario:

Mesh Mesh_A is referenced by geometry modifier 1 and geometry modifier 2 through a property link.
Current exporter generates two separate copies of Mesh_A in the GLTF file.
With the requested feature, the exporter would only include Mesh_A once, and both geometry modifiers would reference the same mesh.

Additional Notes:

This feature would be especially helpful for complex procedural node setups or instances that reuse the same geometry multiple times.
The GLTF format already supports referencing objects such as meshes via their ID or URI, so this optimization should be straightforward to implement.
@julienduroure
Copy link
Collaborator

Hello,
Please provide an example of .blend file, with your export settings saved inside the file.

Note that exporting Geometry Node instances is experimental. The GN node datamodel is far from being compatible with glTF Specification, so we will not be able to fully support all Blender features

@julienduroure julienduroure added the question Further information is requested label Dec 18, 2024
@PMZeroSkyline
Copy link
Author

Hello, thanks for your reply

Describe
When geometry nodes expose an "object" parameter, redundant meshes appear.

To Reproduce
export directly as a glTF file and check the resulting file. In the "meshes" section, should see multiple identical copies of the same mesh

.blend file/ .gltf (mandatory)
exporting_geometry_node_instances.zip

Version
OS: windows 10
Blender Version 4.3

@julienduroure julienduroure removed the question Further information is requested label Jan 9, 2025
@MattiasFredriksson
Copy link
Contributor

.blend file/ .gltf (mandatory) exporting_geometry_node_instances.zip

Modified the example a bit to make some of the mentioned issues clearer, exported .gltf should have 3 suzanne mesh entries/copies in this case (2 from the geonode instancers and 1 for the instanced object).

exporting_geometry_node_instances.zip

Is this being actively worked on or is it possible to see if I can solve it? And/or are there any known complications?

@julienduroure
Copy link
Collaborator

Hello,
There is no active development on this subject for now.
Geometry Node export is experimental, and depsgraph & mesh evaluation API probably need some update on Blender core & API side to be able to be fully managed on export side.
These 2 subjects are not actively on the table for now, even if we this is something that we want to tackle at some point, without any planning, budget nor deadline for now

@MattiasFredriksson
Copy link
Contributor

MattiasFredriksson commented Feb 13, 2025

depsgraph & mesh evaluation API probably need some update on Blender core & API side to be able to be fully managed on export side.

Yes, was trying to identify what the issue was and it seems like the ´datablock´ entry for the instanced is a copy with it's own session_uid and I was unable to find a reference to the original datablock it was an instance of.

These 2 subjects are not actively on the table for now, even if we this is something that we want to tackle at some point, without any planning, budget nor deadline for now

Yes, I don't think they are a general priority as of now. I'm trying to see if there is a way to provide decent support for exporting GN generated geometry though. Gltf export seems to be one of the better/simpler options for it so I'll continue look into it and see if can improve the current behavior.

@julienduroure
Copy link
Collaborator

Sure, any help (code, analysis, test cases, investigation etc...) are always welcome!

@MattiasFredriksson
Copy link
Contributor

MattiasFredriksson commented Feb 18, 2025

Created a PR with a possible fix to the issue.

Important note is that the 'as instance' option must be set in ObjectInfo node (see image). Otherwise the GN instances will be of a copy of the original object and will break the relationship (there are many other ways to copy the data in GN but this one is perhaps not as obvious as other ways). This was unset in the testfiles in the thread so they still wont export correctly even with the fix!

Image

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