Repository: khronosgroup/gltf-blender-io
Issue: Export overwrites objects from other scenes when called from operator

Hello! First of all, thank you all for the work you do in maintaining and working on the GLTF exporter - it's a real life-saver when it comes to getting data out of Blender in a comfortable and customizeable way. Really appreciate it!

As for the core issue, I'm running into this problem with my add-on that makes use of the GLTF exporter for my homemade 3D renderer, [Tetra3D](https://github.com/SolarLune/tetra3d). I'm running Blender 3.2.1, with the packaged GLTF exporter.

When I export a GLTF file from the menu, the resulting file seems to be fine. However, when I call to export a GLTF file from the exporter operator (either triggered through GUI button press or through a save_post handler), the exporter doesn't export the right objects in the right slots (in this particular example, collection instances across multiple scenes). I believe at its core, the GLTF exporter isn't looking at the scene it should be when exporting through an operator, and may be tied to issue #1073 - I'm not sure on this one.

Here's a simple example blend file that exemplifies the issue - I have a Cube in Scene A, and in Scene B a collection instance of that same Cube.

[exportTest.zip](https://github.com/KhronosGroup/glTF-Blender-IO/files/9169767/exportTest.zip)

If you export the blend file as a GLTF file from the menu, you'll get something like this:

```
"asset" : {
        "generator" : "Khronos glTF Blender I/O v3.2.43",
        "version" : "2.0"
    },
    "scene" : 0,
    "scenes" : [
        {
            "name" : "Scene A",
            "nodes" : [
                0
            ]
        },
        {
            "name" : "Scene B",
            "nodes" : [
                2
            ]
        }
    ],
    "nodes" : [
        {
            "mesh" : 0,
            "name" : "Cube"
        },
        {
            "mesh" : 0,
            "name" : "Cube"
        },
        {
            "children" : [
                1
            ],
            "name" : "Instanced",
            "translation" : [
                4.643479347229004,
                0,
                0
            ]
        }
    ],
...
```

Which is, to my understanding, correct. However, the bug arises when exporting through the `bpy.ops.export_scene.gltf()` operator. So, I've also packaged in the blend file a script that you can run in the text editor that will add a "test export" button to the object's Properties panel, which you can press to export the GLTF file through code (to a file named `exportTest.gltf`) and thereby recreate the bug. Pressing the button will export the GLTF file as before, but the contents will be incorrect and change depending on which scene you have selected.

If you have Scene A selected, you'll get this output:

```
    "asset" : {
        "generator" : "Khronos glTF Blender I/O v3.2.43",
        "version" : "2.0"
    },
    "scene" : 1,
    "scenes" : [
        {
            "name" : "Scene A",
            "nodes" : [
                0
            ]
        },
        {
            "name" : "Scene B",
            "nodes" : [
                1
            ]
        }
    ],
    "nodes" : [
        {
            "mesh" : 0,
            "name" : "Cube"
        },
        {
            "mesh" : 0,
            "name" : "Cube"
        }
    ],
...
```

Note that the instanced collection is no longer there. 

If you have Scene B selected, you'll get the following output:

```
    "asset" : {
        "generator" : "Khronos glTF Blender I/O v3.2.43",
        "version" : "2.0"
    },
    "scene" : 1,
    "scenes" : [
        {
            "name" : "Scene A",
            "nodes" : [
                1
            ]
        },
        {
            "name" : "Scene B",
            "nodes" : [
                3
            ]
        }
    ],
    "nodes" : [
        {
            "mesh" : 0,
            "name" : "Cube"
        },
        {
            "children" : [
                0
            ],
            "name" : "Instanced",
            "translation" : [
                4.643479347229004,
                0,
                0
            ]
        },
        {
            "mesh" : 0,
            "name" : "Cube"
        },
        {
            "children" : [
                2
            ],
            "name" : "Instanced",
            "translation" : [
                4.643479347229004,
                0,
                0
            ]
        }
    ],
...
```
Note here that both objects have been replaced with instanced collections. 

Also, in both of the above outputs, the "scene" property is incorrect and points to the last scene in the blend file, rather than whichever one you have selected when running the operator.

As an aside, in my own testing, I don't believe this is a problem if you run the operator with the mouse hovering over the 3D view, which may help to indicate where the issue may lie. 

Changed files:
addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py

diff --git a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
index 1e803f61..64d6f467 100644
--- a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
+++ b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_tree.py
@@ -114,7 +114,8 @@ class VExportTree:
             blender_children.setdefault(bobj, [])
             blender_children.setdefault(bparent, []).append(bobj)
 
-        for blender_object in [obj.original for obj in depsgraph.scene_eval.objects if obj.parent is None]:
+        scene_eval = blender_scene.evaluated_get(depsgraph=depsgraph)
+        for blender_object in [obj.original for obj in scene_eval.objects if obj.parent is None]:
             self.recursive_node_traverse(blender_object, None, None, Matrix.Identity(4), blender_children)
 
     def recursive_node_traverse(self, blender_object, blender_bone, parent_uuid, parent_coll_matrix_world, blender_children, armature_uuid=None, dupli_world_matrix=None):