Blender 3.6, exporter 4.3.3, 'Sampling rate' not ignored when 'Sampling Animations' deselected

Version:
Blender 3.6.19
Blender Exporter 4.3.3

Frequency:
Consistently

Severity:
Low

Bug description:
I believe this stems from the Khronos gltf exporter and not the MSFS2024 plugin. I don’t know whether anything can be done to mitigate the issue on the MSFS2024 side, but I’m posting this here to share my findings.

When ‘Sampling Animations’ is disabled, the value of the ‘Sampling rate’ still has a direct impact on the performance of the exporter. I believe this is due to redundant looping by the value of the ‘Sampling Rate’ within
gltf2_blender_gather_animation_sampling_cache.py->get_cache_data()
and
gltf2_blender_gather_object_keyframes.py->gather_object_sampled_keyframes()

In the case of
gltf2_blender_gather_object_keyframes.py->gather_object_sampled_keyframes()
the loop is unnecessary and can be removed altogether as the frame value is not touched within the called function.

A workaround is to set a high value for the sampling rate (though less than the length of your animations). Hope this helps anyone struggling with poor performance from the exporter.

Repro steps:

Adjust ‘Sampling Rate’ under ‘Sampling Animations’, Observe low of ‘Sampling Rate’ values hurt performance even with ‘Sampling Animations’ disabled.

Thanks,
Chris.

1 Like

This is a great find - too bad Blender 3.6.x has reached it’s end of life for bug fixes - just last month. Need to check if this is an issue for 4.2.x LTS or NOW 4.5.x LTS (but the exporter does not work with 4.5 due to Blender breaking changes again)

Yes, the same issue is present in 4.2.8, (the only version I have on hand).

I also found another major performance issue with this version too (not present in 3.6), again entirely in the Khronos exporter code. Within gltf2_blender_gather_animation_sampling_cache.py, there is a check to show/hide other objects in the viewport, this is an expensive operation that is carried out even when ‘Sampling Animations’ is disabled.

Even if you disable Viewport hiding in your export settings (recommended) there is no check in the code when it comes to unhiding the objects, which is also a very expensive operation. Simply modifying the script to add this check and disabling Viewport Hiding gives a massive speedup (5X+ in my case).

in gltf2_blender_gather_animation_sampling_cache.py->get_cache_data() Change

for node, obj in [(n, n.blender_object) for n in export_settings['vtree'].nodes.values() if n.blender_type in
                  [VExportNode.OBJECT, VExportNode.ARMATURE, VExportNode.COLLECTION]]:
    obj.hide_viewport = node.default_hide_viewport

to

    if export_settings['gltf_optimize_disable_viewport'] is True:
        for node, obj in [(n, n.blender_object) for n in export_settings['vtree'].nodes.values() if n.blender_type in
                          [VExportNode.OBJECT, VExportNode.ARMATURE, VExportNode.COLLECTION]]:
            obj.hide_viewport = node.default_hide_viewport
1 Like

the latest 4.2.12 has

    need_to_enable_again = False
    if export_settings['gltf_optimize_disable_viewport'] is True and len(obj_uuids) == 1:
        need_to_enable_again = True
        # Before baking, disabling from viewport all meshes
        for obj in [n.blender_object for n in export_settings['vtree'].nodes.values() if n.blender_type in
                    [VExportNode.OBJECT, VExportNode.ARMATURE, VExportNode.COLLECTION]]:
            if obj is None:
                continue
            obj.hide_viewport = True
        export_settings['vtree'].nodes[obj_uuids[0]].blender_object.hide_viewport = False
    # Work for drivers on shapekeys is already done at start of animation export

Yes, but it’s the check further down when unhiding that isn’t carried out. Looks like the need_to_enable_again variable was created for this purpose but never actually used.

I guess it should be:

    # And now, restoring meshes in viewport
    if need_to_enable_again:
        for node, obj in [(n, n.blender_object) for n in export_settings['vtree'].nodes.values() if n.blender_type in
                          [VExportNode.OBJECT, VExportNode.ARMATURE, VExportNode.COLLECTION]]:
            obj.hide_viewport = node.default_hide_viewport

I asked Khronons (julien) about this.

2 Likes

Hello,

This is indeed a Khronos issue, and unfortunately there is nothing we can do except to wait for a fix from Khronos.

Regards,
Boris