Explorar o código

Merge pull request #5844 from repsac/io_three

Minor cleanup of the Python package.
Mr.doob %!s(int64=10) %!d(string=hai) anos
pai
achega
30b74a40e1

+ 0 - 0
utils/exporters/blender/addons/io_three/exporter/exceptions.py → utils/exporters/blender/addons/io_three/exceptions.py


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

@@ -1,22 +1,15 @@
 import os
 import sys
 import traceback
-from .. import constants
-from . import (
-    scene, 
-    geometry, 
-    api, 
-    exceptions, 
-    logger, 
-    base_classes
-)
+from .. import constants, logger, exceptions
+from . import scene, geometry, api, base_classes
 
 
 def _error_handler(func):
     
     def inner(filepath, options, *args, **kwargs):
         level = options.get(constants.LOGGING, constants.DEBUG)
-        logger.init(level=level)
+        logger.init('io_three.export.log', level=level)
         api.init()
         
         try:
@@ -65,9 +58,12 @@ def export_geometry(filepath, options, node=None):
     if node is None:
         node = api.active_object()
         if node is None:
-            raise exceptions.SelectionError('Nothing selected')
+            msg = 'Nothing selected'
+            logger.error(msg)
+            raise exceptions.SelectionError(msg)
         if node.type != 'MESH':
-            raise exceptions.GeometryError('Not a valid mesh object')
+            msg = 'Not a valid mesh object'
+            raise exceptions.GeometryError(msg)
     
     mesh = api.object.mesh(node, options)
     parent = base_classes.BaseScene(filepath, options)

+ 2 - 3
utils/exporters/blender/addons/io_three/exporter/base_classes.py

@@ -1,6 +1,5 @@
 import uuid
-from .. import constants 
-from .exceptions import ThreeValueError
+from .. import constants, exceptions 
 
 
 class BaseClass(constants.BASE_DICT):
@@ -18,7 +17,7 @@ class BaseClass(constants.BASE_DICT):
     def __setitem__(self, key, value):
         if not isinstance(value, constants.VALID_DATA_TYPES):
             msg = 'Value is an invalid data type: %s' % type(value)
-            raise ThreeValueError(msg) 
+            raise exceptions.ThreeValueError(msg) 
         constants.BASE_DICT.__setitem__(self, key, value)
 
     @property

+ 16 - 17
utils/exporters/blender/addons/io_three/exporter/geometry.py

@@ -1,6 +1,6 @@
 import os
-from .. import constants
-from . import base_classes, io, logger, api
+from .. import constants, logger
+from . import base_classes, io, api
 
 
 FORMAT_VERSION = 3
@@ -23,7 +23,8 @@ class Geometry(base_classes.BaseNode):
         logger.info('Setting %s to "%s"', node, geo_type)
 
         self._defaults[constants.TYPE] = geo_type
-        base_classes.BaseNode.__init__(self, node, parent=parent,
+        base_classes.BaseNode.__init__(self, node, 
+            parent=parent,
             type=geo_type)
 
     @property
@@ -59,27 +60,25 @@ class Geometry(base_classes.BaseNode):
         bitset = lambda x,y: x & ( 1 << y )
         face_count = 0
 
+        masks = (constants.MASK[constants.UVS],
+            constants.MASK[constants.NORMALS],
+            constants.MASK[constants.COLORS])
+
         while offset < length:
             bit = faces[offset]
             offset += 1
             face_count += 1
-            is_quad = bitset(bit, constants.MASK[constants.QUAD])
-            has_material = bitset(bit, constants.MASK[constants.MATERIALS])
-            has_uv = bitset(bit, constants.MASK[constants.UVS])
-            has_normal = bitset(bit, constants.MASK[constants.NORMALS])
-            has_color = bitset(bit, constants.MASK[constants.COLORS])
 
+            is_quad = bitset(bit, constants.MASK[constants.QUAD])
             vector = 4 if is_quad else 3
             offset += vector
 
-            if has_material:
+            if bitset(bit, constants.MASK[constants.MATERIALS]):
                 offset += 1
-            if has_uv:
-                offset += vector
-            if has_normal:
-                offset += vector
-            if has_color:
-                offset += vector
+
+            for mask in masks:
+                if bitset(bit, mask):
+                    offset += vector
 
         return face_count
 
@@ -109,7 +108,6 @@ class Geometry(base_classes.BaseNode):
             data[constants.MATERIALS] = self[constants.MATERIALS].copy()
         except KeyError:
             logger.debug('No materials to copy')
-            pass
 
         return data
 
@@ -323,7 +321,8 @@ class Geometry(base_classes.BaseNode):
 
         if self.options.get(constants.COLORS):
             logger.info('Parsing %s', constants.COLORS)
-            self[constants.COLORS] = api.mesh.vertex_colors(self.node)
+            self[constants.COLORS] = api.mesh.vertex_colors(
+                self.node)
         
         if self.options.get(constants.FACE_MATERIALS):
             logger.info('Parsing %s', constants.FACE_MATERIALS)

+ 2 - 2
utils/exporters/blender/addons/io_three/exporter/image.py

@@ -1,6 +1,6 @@
 import os
-from .. import constants
-from . import base_classes, io, api, logger
+from .. import constants, logger
+from . import base_classes, io, api
 
 
 class Image(base_classes.BaseNode):

+ 2 - 2
utils/exporters/blender/addons/io_three/exporter/io.py

@@ -1,6 +1,6 @@
 import shutil
-from .. import constants
-from . import _json, logger
+from .. import constants, logger
+from . import _json
 
 
 def copy_registered_textures(dest, registration):

+ 2 - 2
utils/exporters/blender/addons/io_three/exporter/material.py

@@ -1,5 +1,5 @@
-from .. import constants
-from . import base_classes, utilities, logger, api
+from .. import constants, logger
+from . import base_classes, utilities, api
 
 
 class Material(base_classes.BaseNode):

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

@@ -1,5 +1,5 @@
-from .. import constants
-from . import base_classes, logger, api
+from .. import constants, logger
+from . import base_classes, api
 
 
 class Object(base_classes.BaseNode):

+ 1 - 2
utils/exporters/blender/addons/io_three/exporter/scene.py

@@ -1,12 +1,11 @@
 import os
-from .. import constants
+from .. import constants, logger
 from . import (
     base_classes,
     texture,
     material,
     geometry, 
     object,
-    logger,
     io,
     api
 )

+ 2 - 2
utils/exporters/blender/addons/io_three/exporter/texture.py

@@ -1,5 +1,5 @@
-from .. import constants
-from . import base_classes, image, api, logger
+from .. import constants, logger
+from . import base_classes, image, api
 
 
 class Texture(base_classes.BaseNode):

+ 3 - 4
utils/exporters/blender/addons/io_three/exporter/logger.py → utils/exporters/blender/addons/io_three/logger.py

@@ -2,11 +2,10 @@ import os
 import logging
 import tempfile
 
-from .. import constants
+from . import constants
 
 LOG_FILE = None
 LOGGER = None
-FILE_NAME = 'io_three.export.log'
 
 LEVELS = {
     constants.DEBUG: logging.DEBUG,
@@ -16,9 +15,9 @@ LEVELS = {
     constants.CRITICAL: logging.CRITICAL
 }
 
-def init(level=constants.DEBUG):
+def init(filename, level=constants.DEBUG):
     global LOG_FILE
-    LOG_FILE = os.path.join(tempfile.gettempdir(), FILE_NAME)
+    LOG_FILE = os.path.join(tempfile.gettempdir(), filename)
     with open(LOG_FILE, 'w'):
         pass