KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.5k stars 320 forks source link

Perf on node tree traversal #2140

Open julienduroure opened 9 months ago

julienduroure commented 9 months ago

With this file: https://github.com/KhronosGroup/glTF-Blender-IO/files/11376083/vrm1_0.zip Without exporting animation (that is another subject)

Materials exported are really simple, without any textures. The node tree is quite complex, but not compatible with glTF.

We may have some performance enhancement for these cases (complex node setup not compatible)

HailToDodongo commented 3 weeks ago

Are there any update on this? Since blender 4.1 up to the latest beta either vertex colors or gltf export has been broken for me and other people (referring to the issue in #2278) Meaning that any models with more complex node setups are unable to be exported without freezing blender.

I'm mainly asking since i need to decide to either write a custom exporter and abandon gtlf, or wait for a fix. Right now i have to recommend people to keep using blender 4.0 because of this which is not ideal.

julienduroure commented 3 weeks ago

@HailToDodongo This ticket and the one you are referencing are about performance, not vertex color. Vertex Color "issue" is fixed in 4.2, cf #2233

I think the performance about navigating in material node tree is here from the beginning. If you noticed some performance drop between 4.0 and 4.1, can you please create a new ticket with you test blend file?

HailToDodongo commented 3 weeks ago

Ah sorry, by vertex colors i meant the change in behaviour in 4.1 that also caused issues. This was indeed fixed in 4.2. As for performance (or rather the inability to export at all since 4.1) the model in #2278 also has this problem, the issue there is describing that.

I just wasn't sure where to comment, since a few issues where linked together as duplicates.

julienduroure commented 3 weeks ago

4.1 introduces node group traversal, where 4.0 and prior does not go inside node group. That explains why the file export instantly in 4.0, because the node tree is full of blender group. But nothing is retrieve and exporting in glTF material.

4.1 can go inside node groups. It takes time (like any other node traversal), but can retrieve more information to export. In case you now that no material data can be retrieve, I suggest to not export any materials.

glTF specification can not handle all blender node tree, so you may want to adapt your node tree to get data, or ignore material at export.

HailToDodongo commented 3 weeks ago

The issue with omitting materials is that i'm still interested in custom properties attached to it. The plugin mostly uses nodes for visualization only (partially emulating N64 hardware), whereas the actual materials settings are in custom properties. Later the gltf file is used in a converter to further process it where the gltf material itself doesn't matter.

Although i can fully understand that this is not an official use-case and why this is something you may not want to support. It's just that gltf is a really convenient way to get data out of blender, and is easy to parse later. And up until 4.1 it did work just fine.

julienduroure commented 3 weeks ago

Ah, I see.

One solution is to create a new option beside materials / placeholder / None, to enable export a very basic material, based on viewport display data (so without the need to traverse the node tree)

image

This will also enabling custom properties export

HailToDodongo commented 3 weeks ago

Yeah that would solve it i think How complex do you think this change would be? otherwise i could attempt adding it myself, since it would probably not be the highest prio (although i have not looked deeper at the plugin code yet)

julienduroure commented 3 weeks ago

Base work available here: #2390

Lilaa3 commented 3 weeks ago

I actually implemented a hack in the plugin to change the node connections to only have vertex colors before an export. Works quite well for now, and I only really needed it to do that. If I may suggest something, a way to hook BEFORE certain operations to hint at what the addon should be doing for addon-related materials would be really helpful, for example I could specify that this material needs this vertex color layer to be COLOR_0, or that this is the fake vertex alpha layer that needs to be merged into COLOR_0. Not exactly a feature request tho since I'll still target older versions, just an idea.