[Bf-extensions-cvs] [b3514b67] master: glTF importer: make first root node active even if there are some armature in scene
Julien Duroure
noreply at git.blender.org
Tue May 7 11:15:53 CEST 2019
Commit: b3514b6710228dea6dbebbb13034d6214accb81e
Author: Julien Duroure
Date: Tue May 7 10:44:50 2019 +0200
Branches: master
https://developer.blender.org/rBAb3514b6710228dea6dbebbb13034d6214accb81e
glTF importer: make first root node active even if there are some armature in scene
===================================================================
M io_scene_gltf2/blender/imp/gltf2_blender_gltf.py
===================================================================
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."""
More information about the Bf-extensions-cvs
mailing list