Răsfoiți Sursa

Fixed a bug where the Blender API was reliant on the object and data node names being the same

repsac 10 ani în urmă
părinte
comite
584ac47446

+ 1 - 1
utils/exporters/blender/addons/io_three/__init__.py

@@ -42,7 +42,7 @@ SETTINGS_FILE_EXPORT = 'three_settings_export.js'
 bl_info = {
     'name': "Three.js Format",
     'author': "repsac, mrdoob, yomotsu, mpk, jpweeks",
-    'version': (1, 3, 0),
+    'version': (1, 3, 1),
     'blender': (2, 7, 3),
     'location': "File > Export",
     'description': "Export Three.js formatted JSON files.",

+ 12 - 0
utils/exporters/blender/addons/io_three/exporter/api/__init__.py

@@ -23,6 +23,18 @@ def batch_mode():
     return bpy.context.area is None
 
 
+def data(node):
+    """
+
+    :param node: name of an object node
+    :returns: the data block of the node
+
+    """
+    try:
+        return bpy.data.objects[node].data
+    except KeyError:
+        pass
+
 def init():
     """Initializing the api module. Required first step before
     initializing the actual export process.

+ 22 - 12
utils/exporters/blender/addons/io_three/exporter/object.py

@@ -13,34 +13,44 @@ class Object(base_classes.BaseNode):
         else:
             self._root_setup()
 
+    @property
+    def data(self):
+        """
+
+        :return: returns the data block of the node
+
+        """
+        return api.data(self.node)
+
+
     def _init_camera(self):
         """Initialize camera attributes"""
         logger.debug("Object()._init_camera()")
-        self[constants.FAR] = api.camera.far(self.node)
-        self[constants.NEAR] = api.camera.near(self.node)
+        self[constants.FAR] = api.camera.far(self.data)
+        self[constants.NEAR] = api.camera.near(self.data)
 
         if self[constants.TYPE] == constants.PERSPECTIVE_CAMERA:
-            self[constants.ASPECT] = api.camera.aspect(self.node)
-            self[constants.FOV] = api.camera.fov(self.node)
+            self[constants.ASPECT] = api.camera.aspect(self.data)
+            self[constants.FOV] = api.camera.fov(self.data)
         elif self[constants.TYPE] == constants.ORTHOGRAPHIC_CAMERA:
-            self[constants.LEFT] = api.camera.left(self.node)
-            self[constants.RIGHT] = api.camera.right(self.node)
-            self[constants.TOP] = api.camera.top(self.node)
-            self[constants.BOTTOM] = api.camera.bottom(self.node)
+            self[constants.LEFT] = api.camera.left(self.data)
+            self[constants.RIGHT] = api.camera.right(self.data)
+            self[constants.TOP] = api.camera.top(self.data)
+            self[constants.BOTTOM] = api.camera.bottom(self.data)
 
     #@TODO: need more light attributes. Some may have to come from
     #       custom blender attributes.
     def _init_light(self):
         """Initialize light attributes"""
         logger.debug("Object()._init_light()")
-        self[constants.COLOR] = api.light.color(self.node)
-        self[constants.INTENSITY] = api.light.intensity(self.node)
+        self[constants.COLOR] = api.light.color(self.data)
+        self[constants.INTENSITY] = api.light.intensity(self.data)
 
         if self[constants.TYPE] != constants.DIRECTIONAL_LIGHT:
-            self[constants.DISTANCE] = api.light.distance(self.node)
+            self[constants.DISTANCE] = api.light.distance(self.data)
 
         if self[constants.TYPE] == constants.SPOT_LIGHT:
-            self[constants.ANGLE] = api.light.angle(self.node)
+            self[constants.ANGLE] = api.light.angle(self.data)
 
     def _init_mesh(self):
         """Initialize mesh attributes"""

BIN
utils/exporters/blender/tests/blend/scene_orthographic_camera.blend


BIN
utils/exporters/blender/tests/blend/scene_perspective_camera.blend


BIN
utils/exporters/blender/tests/blend/scene_spot_light.blend