diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-05-07 11:44:50 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-05-07 11:44:50 +0300 |
commit | b3514b6710228dea6dbebbb13034d6214accb81e (patch) | |
tree | dcfb74a6a94a96a1e8c2b237c5c3a9defb312f14 /io_scene_gltf2/blender | |
parent | 745b87af35c7c5a7f8d83c610b869c60bc4dc215 (diff) |
glTF importer: make first root node active even if there are some armature in scene
Diffstat (limited to 'io_scene_gltf2/blender')
-rwxr-xr-x | io_scene_gltf2/blender/imp/gltf2_blender_gltf.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py index 625b5917..c3b511a2 100755 --- a/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_gltf.py @@ -29,13 +29,22 @@ class BlenderGlTF(): bpy.context.scene.render.engine = 'BLENDER_EEVEE' BlenderGlTF.pre_compute(gltf) + active_object_name_at_end = None if gltf.data.scenes is not None: for scene_idx, scene in enumerate(gltf.data.scenes): BlenderScene.create(gltf, scene_idx) + # keep active object name if needed (to be able to set as active object at end) + if gltf.data.scene is not None: + if scene_idx == gltf.data.scene: + active_object_name_at_end = bpy.context.view_layer.objects.active.name + else: + if scene_idx == 0: + active_object_name_at_end = bpy.context.view_layer.objects.active.name else: # special case where there is no scene in glTF file # generate all objects in current scene BlenderScene.create(gltf, None) + active_object_name_at_end = bpy.context.view_layer.objects.active.name # Armature correction # Try to detect bone chains, and set bone lengths @@ -80,6 +89,10 @@ class BlenderGlTF(): bpy.ops.object.mode_set(mode="OBJECT") + # Set active object + if active_object_name_at_end is not None: + bpy.context.view_layer.objects.active = bpy.data.objects[active_object_name_at_end] + @staticmethod def pre_compute(gltf): """Pre compute, just before creation.""" |