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

Multi-scene export fails #1086

Closed
spiraloid opened this issue Jun 8, 2020 · 7 comments · Fixed by #1098
Closed

Multi-scene export fails #1086

spiraloid opened this issue Jun 8, 2020 · 7 comments · Fixed by #1098
Labels
Animation bug Something isn't working exporter This involves or affects the export process
Milestone

Comments

@spiraloid
Copy link

spiraloid commented Jun 8, 2020

Describe the bug

a gltf exported from a .blend file that has multiple scenes in it will export every scene into the gltf, regardless if any objects are active. This will cause it the be larger file and cause it to not load correctly with three.js GLTFLoader. etc. Note: The export problems will only occurs when the active scene in blender is not the first scene.

it's also compounded by the fact that some gltf viewers will error and some will load just first scene, so you can think it's working when it's not.

also, there are bunch of secondary issues that seem related to this.

an assert when combining NLA strips
export_nla_strips=False will cause an assert when I have a blend file with multiple scenes and one of the scenes has no action associated with any of it's objects. I shored up this edge case and found other issues all stemming from this central issue.

an assert when applying modifiers
export_apply=True causes an assert. if only one scene is present, this works. if two scenes are present, and any scene but first scene is set to be the active scene, the crash on export will happen.

To Reproduce
Steps to reproduce the behavior:
load the attached blend file and run the script in the text editor. there are 4 scenes in the file. the first has no animation. the gltf gather action script is failing, likely because it wasn't expecting multiple scenes.

note the line comment at:

export_nla_strips=False # <-- Set False will crash or produce duplicate actions

you can also get it to happen in the GUI if you try and export from a scene and uncheck "Group by NLA Track" (same bool)

Expected behavior
I expect to be able to export all scenes and have only action per .glb file, and not have the hidden data from every other scene in the .blend file cluttering up the gltf file.

if no animated elements exist for one of the scenes, I expect it to still export without animation, or create an empy action animation. I do not expect it to crash. I'm writing a hack workaround to save a single keyframe in each scene before export to avoid this error. Be good if it were fixed properly given the awesomeness of GLTF and its likely ubiquity.

.blend file/ .gltf
gltf_crash.zip

Version

  • OS: Windows 10
  • Blender Version 2.90.0 alpha

Additional context
I also note that I get the same error with apply modifiers. (see comment in text text editor of the blend file to make it happen)

note, if you animate anything in the cube scene (the fist scene, without any animation), the scenes will export and the error will not happen. however, if you inspect in the exported GLTF files, there will be 4 duplicate actions all named "action" instead of just the one action as expected.

@spiraloid
Copy link
Author

spiraloid commented Jun 8, 2020

The error in case you want to jump right to line 39 of gltf2_blender_gather.py.

RuntimeError: Error: Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\__init__.py", line 506, in execute
    return gltf2_blender_export.save(context, export_settings)
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\blender\exp\gltf2_blender_export.py", line 42, in save
    json, buffer = __export(export_settings)
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\blender\exp\gltf2_blender_export.py", line 55, in __export
    __gather_gltf(exporter, export_settings)
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\blender\exp\gltf2_blender_export.py", line 64, in __gather_gltf
    active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\blender\exp\gltf2_blender_gather.py", line 39, in gather_gltf2
    animations += __gather_animations(blender_scene, export_settings)
  File "C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\addons\io_scene_gltf2\blender\exp\gltf2_blender_gather.py", line 100, in __gather_animations
    animations[merged_tracks[merged_anim_track][0]].name = merged_anim_track
IndexError: list index out of range

location: C:\Program Files\Blender Foundation\blender-2.90.0-c7329da14b22-windows64\2.90\scripts\modules\bpy\ops.py:201


Error: Python script failed, check the message in the system console

@spiraloid spiraloid reopened this Jun 9, 2020
@julienduroure julienduroure added Animation bug Something isn't working exporter This involves or affects the export process labels Jun 9, 2020
@julienduroure julienduroure added this to the Blender 2.90 milestone Jun 9, 2020
@spiraloid
Copy link
Author

spiraloid commented Jun 9, 2020

it seems like trying to export a .glb is totally broken when multiple scenes are present. I suspect the following code might be usefull.

            # turn off all collections in all scenes.
            for scene in bpy.data.scenes:
                bpy.context.window.scene = scene
                scene_collections = scene.collection.children
                for col in scene_collections:
                    col_name = col.name
                    bpy.context.view_layer.layer_collection.children[col_name].exclude = True

            # turn on each scene's export collection for export.
            for scene in bpy.data.scenes:
                bpy.context.window.scene = scene    
                scene_collections = scene.collection.children
                for col in scene_collections:
                    col_name = col.name
                    if "Export" in col_name:
                        bpy.context.view_layer.layer_collection.children[col_name].exclude = False



@spiraloid spiraloid changed the title Multi-scene export fails w "export_nla_strips=False" and no anim in a scene. Multi-scene export fails w "export_nla_strips=False" and no anim in a scene or apply modifiers active. Jun 15, 2020
@spiraloid
Copy link
Author

the oddest part about this bug is if I delete all the other scenes from the blender file, then purge all orphan data, and then export with the exact same settings, the exported glb file loads fine....

@spiraloid
Copy link
Author

spiraloid commented Jun 15, 2020

interesting clue about why my gltf files won't load.

it looks like blender is exporting every scene in the .blend file into each GLTF file, regardless if it's the active scene or not -or if the objects are visible. I think that might explain the chaos I'm seeing. since only the first scene draws, it can look fine when the glb file loads. But it's a false positive.

if I ascii hack the multi scene gltf file to have only one scene, the three GTLFLoader can load it just fine.

perhaps an "export only active scene" option might be worth considering.

image

@spiraloid
Copy link
Author

spiraloid commented Jun 15, 2020

Ok. I think I found where the problem is. here's the ascii gltf comparison between the exact same cube scene exported from a blend file with only one scene present in the .blend file.
(p.0001.w100h100_single_scene.gltf)

the second file is exported with the exact same settings but from a .blend file with multiple scenes present.
(p.0001.w100h100_multi_scene.gltf)

what's interesting is that both files look identical in https://gltf-viewer.donmccurdy.com/ and https://threejs.org/editor/ but the multi scene exported file will not load in the three GLTFLoader.

single_vs_multi_scene_export.zip

@spiraloid spiraloid changed the title Multi-scene export fails w "export_nla_strips=False" and no anim in a scene or apply modifiers active. Multi-scene export fails Jun 15, 2020
@javagl
Copy link

javagl commented Jun 15, 2020

It's not strictly related to the Blender IO, but there has been some discussion about "Multiple Scenes" in general at KhronosGroup/glTF-Sample-Models#242 (comment) , also pointing to KhronosGroup/glTF#1542 (I'm just mentioning this to avoid putting too much effort into something that might become obsolete at some point, but I'm not up to date with the latest discussions here, admittedly...)

@julienduroure
Copy link
Collaborator

Well,

The crash is not linked to multiscene...
Open default cube, export gltf unchecking "group by NLA" --> crash

A check is missing...

julienduroure added a commit that referenced this issue Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Animation bug Something isn't working exporter This involves or affects the export process
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants