[Bf-extensions-cvs] [fd6bfbb4] master: glTF importer: better retrieve camera & lights names

Julien Duroure noreply at git.blender.org
Fri Mar 27 18:57:09 CET 2020


Commit: fd6bfbb44af49a97db2ad35ba4f54d83ffec26a4
Author: Julien Duroure
Date:   Fri Mar 27 18:41:43 2020 +0100
Branches: master
https://developer.blender.org/rBAfd6bfbb44af49a97db2ad35ba4f54d83ffec26a4

glTF importer: better retrieve camera & lights names

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/imp/gltf2_blender_camera.py
M	io_scene_gltf2/blender/imp/gltf2_blender_light.py
M	io_scene_gltf2/blender/imp/gltf2_blender_node.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 6e3484e0..af0610c1 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 2, 53),
+    "version": (1, 2, 54),
     'blender': (2, 82, 7),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
index ffe79b54..e97bd0b8 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_camera.py
@@ -48,5 +48,4 @@ class BlenderCamera():
         if hasattr(pycamera, "zfar"):
             cam.clip_end = pycamera.zfar
 
-        obj = bpy.data.objects.new(pycamera.name, cam)
-        return obj
+        return cam
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_light.py b/io_scene_gltf2/blender/imp/gltf2_blender_light.py
index be1c6c40..e626123c 100644
--- a/io_scene_gltf2/blender/imp/gltf2_blender_light.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_light.py
@@ -28,23 +28,23 @@ class BlenderLight():
         """Light creation."""
         pylight = gltf.data.extensions['KHR_lights_punctual']['lights'][light_id]
         if pylight['type'] == "directional":
-            obj = BlenderLight.create_directional(gltf, light_id)
+            light = BlenderLight.create_directional(gltf, light_id)
         elif pylight['type'] == "point":
-            obj = BlenderLight.create_point(gltf, light_id)
+            light = BlenderLight.create_point(gltf, light_id)
         elif pylight['type'] == "spot":
-            obj = BlenderLight.create_spot(gltf, light_id)
+            light = BlenderLight.create_spot(gltf, light_id)
 
         if 'color' in pylight.keys():
-            obj.data.color = pylight['color']
+            light.color = pylight['color']
 
         if 'intensity' in pylight.keys():
-            obj.data.energy = pylight['intensity']
+            light.energy = pylight['intensity']
 
         # TODO range
 
-        set_extras(obj.data, pylight.get('extras'))
+        set_extras(light, pylight.get('extras'))
 
-        return obj
+        return light
 
     @staticmethod
     def create_directional(gltf, light_id):
@@ -54,8 +54,7 @@ class BlenderLight():
             pylight['name'] = "Sun"
 
         sun = bpy.data.lights.new(name=pylight['name'], type="SUN")
-        obj = bpy.data.objects.new(pylight['name'], sun)
-        return obj
+        return sun
 
     @staticmethod
     def create_point(gltf, light_id):
@@ -65,8 +64,7 @@ class BlenderLight():
             pylight['name'] = "Point"
 
         point = bpy.data.lights.new(name=pylight['name'], type="POINT")
-        obj = bpy.data.objects.new(pylight['name'], point)
-        return obj
+        return point
 
     @staticmethod
     def create_spot(gltf, light_id):
@@ -76,7 +74,6 @@ class BlenderLight():
             pylight['name'] = "Spot"
 
         spot = bpy.data.lights.new(name=pylight['name'], type="SPOT")
-        obj = bpy.data.objects.new(pylight['name'], spot)
 
         # Angles
         if 'spot' in pylight.keys() and 'outerConeAngle' in pylight['spot']:
@@ -89,4 +86,4 @@ class BlenderLight():
         else:
             spot.spot_blend = 1.0
 
-        return obj
+        return spot
diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_node.py b/io_scene_gltf2/blender/imp/gltf2_blender_node.py
index 6ce91ea3..8c732949 100755
--- a/io_scene_gltf2/blender/imp/gltf2_blender_node.py
+++ b/io_scene_gltf2/blender/imp/gltf2_blender_node.py
@@ -60,10 +60,12 @@ class BlenderNode():
             obj = BlenderNode.create_mesh_object(gltf, pynode, name=vnode.name)
         elif vnode.camera_node_idx is not None:
             pynode = gltf.data.nodes[vnode.camera_node_idx]
-            obj = BlenderCamera.create(gltf, pynode.camera)
+            cam = BlenderCamera.create(gltf, pynode.camera)
+            obj = bpy.data.objects.new(vnode.name, cam)
         elif vnode.light_node_idx is not None:
             pynode = gltf.data.nodes[vnode.light_node_idx]
-            obj = BlenderLight.create(gltf, pynode.extensions['KHR_lights_punctual']['light'])
+            light = BlenderLight.create(gltf, pynode.extensions['KHR_lights_punctual']['light'])
+            obj = bpy.data.objects.new(vnode.name, light)
         elif vnode.is_arma:
             armature = bpy.data.armatures.new(vnode.arma_name)
             obj = bpy.data.objects.new(vnode.name, armature)



More information about the Bf-extensions-cvs mailing list