[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2714] contrib/py/scripts/addons/ io_scene_ms3d: more tiny code cleanups,

Alexander Nussbaumer alpha-beta-release at gmx.net
Sat Dec 3 15:00:11 CET 2011


Revision: 2714
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2714
Author:   beta-tester
Date:     2011-12-03 14:00:09 +0000 (Sat, 03 Dec 2011)
Log Message:
-----------
more tiny code cleanups,

mod: class __init__(self, ...) default parameter handling
mod: droped some tuple constructions: replaced with regular expression "tuple[(].*[[](.*)[]].*[)]" with "(\1)"

Modified Paths:
--------------
    contrib/py/scripts/addons/io_scene_ms3d/__README__.txt
    contrib/py/scripts/addons/io_scene_ms3d/__init__.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_spec.py
    contrib/py/scripts/addons/io_scene_ms3d/ms3d_utils.py

Modified: contrib/py/scripts/addons/io_scene_ms3d/__README__.txt
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/__README__.txt	2011-12-03 13:49:37 UTC (rev 2713)
+++ contrib/py/scripts/addons/io_scene_ms3d/__README__.txt	2011-12-03 14:00:09 UTC (rev 2714)
@@ -92,6 +92,10 @@
 
 
 changelog:
+changed: (0, 3, 3, "beta (2011-12-03 00:00)")
+mod: class __init__(self, ...) default parameter handling
+mod: droped some tuple constructions: replaced with regular expression "tuple[(].*[[](.*)[]].*[)]" with "(\1)"
+
 changed: (0, 3, 3, "beta (2011-12-02 00:00)")
 add: importer adds additionally smoothingGroups as vertex_groups "ms3d_smoothingGroup{1...32}"
 fix: export smoothingGroups start index to 1

Modified: contrib/py/scripts/addons/io_scene_ms3d/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/__init__.py	2011-12-03 13:49:37 UTC (rev 2713)
+++ contrib/py/scripts/addons/io_scene_ms3d/__init__.py	2011-12-03 14:00:09 UTC (rev 2714)
@@ -62,7 +62,7 @@
         "name": "MilkShape3D MS3D format (.ms3d)",
         "description":  "Import / Export MilkShape3D MS3D files (conform with v1.8.4)",
         "author": "Alexander Nussbaumer",
-        "version": (0, 3, 3, "beta (2011-12-02 00:00)"),
+        "version": (0, 3, 3, "beta (2011-12-03 00:00)"),
         "blender": (2, 6, 0),
         "api": 41226,
         "location": "File > Import-Export",

Modified: contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py	2011-12-03 13:49:37 UTC (rev 2713)
+++ contrib/py/scripts/addons/io_scene_ms3d/ms3d_export.py	2011-12-03 14:00:09 UTC (rev 2714)
@@ -199,6 +199,7 @@
         #DEBUG_print("WriteMs3d")
 
         t1 = time.time()
+        t2 = None
 
         try:
             # setup environment
@@ -216,6 +217,8 @@
             self.Ms3dFromBlender(blenderContext, ms3dTemplate)
             #DEBUG_print("WriteMs3d - data injected")
 
+            t2 = time.time()
+
             # write ms3d file to disk
             self.file = io.FileIO(self.filepath, "w")
             #DEBUG_print("WriteMs3d - file opend to write")
@@ -231,17 +234,20 @@
             ms3d_utils.PostSetupEnvironment(self, False)
 
         except Exception:
-            for i in range(len(sys.exc_info())):
-                print("WriteMs3d - exception in try block '{0}'".format(sys.exc_info()[i]))
+            type, value, traceback = sys.exc_info()
+            print("WriteMs3d - exception in try block\n  type: '{0}'\n  value: '{1}'".format(type, value, traceback))
 
+            if t2 is None:
+                t2 = time.time()
+
             raise
 
         else:
             #DEBUG_print("WriteMs3d - passed try block")
             pass
 
-        t2 = time.time()
-        print("elapsed time: {0:.4}s".format(t2 - t1))
+        t3 = time.time()
+        print("elapsed time: {0:.4}s (converter: ~{1:.4}s, disk io: ~{2:.4}s)".format((t3 - t1), (t2 - t1), (t3 - t2)))
 
         return {"FINISHED"}
 
@@ -497,8 +503,6 @@
 
     ###############################################################################
     def CreateNormal(self,  matrixObject, blenderVertex):
-        ms3dNormal = [None for i in range(3)]
-
         mathVector = mathutils.Vector(blenderVertex.normal)
 
         # apply its object matrix (translation, rotation, scale)
@@ -541,7 +545,7 @@
                 return None
 
             # no order-translation needed
-            tx = tuple([0, 1, 2])
+            tx = (0, 1, 2)
 
         elif (l == 4):
             # it is a quad geometry
@@ -550,10 +554,10 @@
 
             if (subIndex == 0):
                 # order-translation for 1'st triangle
-                tx = tuple([0, 1, 3])
+                tx = (0, 1, 3)
             else:
                 # order-translation for 2'nd triangle
-                tx = tuple([3, 1, 2])
+                tx = (3, 1, 2)
 
         else:
             # it is any unhandled geometry
@@ -587,7 +591,7 @@
                 ])
 
         # put the normales
-        ms3dTriangle._vertexNormals = tuple([n0, n1, n2])
+        ms3dTriangle._vertexNormals = (n0, n1, n2)
 
         # if uv's present
         if (blenderMesh.uv_textures):
@@ -619,8 +623,8 @@
             #DEBUG_print("uv's present 2")
 
             # put the uv-coordinates
-            ms3dTriangle._s = tuple([s0, s1, s2])
-            ms3dTriangle._t = tuple([t0, t1, t2])
+            ms3dTriangle._s = (s0, s1, s2)
+            ms3dTriangle._t = (t0, t1, t2)
 
         return ms3dTriangle
 
@@ -706,7 +710,7 @@
             smoothGroup += 1
             if (smoothGroup > ms3d_spec.MAX_SMOOTH_GROUP):
                 smoothGroup = 1
-                
+
         #DEBUG_print("GenerateSmoothGroups smoothGroupFaces= {0}".format(smoothGroupFaces))
 
         return smoothGroupFaces

Modified: contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py	2011-12-03 13:49:37 UTC (rev 2713)
+++ contrib/py/scripts/addons/io_scene_ms3d/ms3d_import.py	2011-12-03 14:00:09 UTC (rev 2714)
@@ -229,24 +229,12 @@
         #DEBUG_print("ReadMs3d")
 
         t1 = time.time()
+        t2 = None
 
         try:
             # setup environment
             ms3d_utils.PreSetupEnvironment(self)
 
-            # inject dictionaries
-            # handle internal ms3d names to external blender names
-            # to prevent potential name collisions on multiple imports
-            # with same names but different content
-            self.dict_armatures = {}
-            self.dict_bones = {}
-            self.dict_groups = {}
-            self.dict_images = {}
-            self.dict_materials = {}
-            self.dict_meshes = {}
-            self.dict_objects = {}
-            self.dict_textures = {}
-
             #DEBUG_print("ReadMs3d - entering try block")
 
             # create an empty ms3d template
@@ -268,6 +256,21 @@
             self.file.close()
             #DEBUG_print("ReadMs3d - file closed")
 
+            t2 = time.time()
+
+            # inject dictionaries
+            # handle internal ms3d names to external blender names
+            # to prevent potential name collisions on multiple imports
+            # with same names but different content
+            self.dict_armatures = {}
+            self.dict_bones = {}
+            self.dict_groups = {}
+            self.dict_images = {}
+            self.dict_materials = {}
+            self.dict_meshes = {}
+            self.dict_objects = {}
+            self.dict_textures = {}
+
             # inject ms3d data to blender
             self.BlenderFromMs3d(blenderContext, ms3dTemplate)
             #DEBUG_print("ReadMs3d - data injected")
@@ -276,17 +279,20 @@
             ms3d_utils.PostSetupEnvironment(self, self.prop_unit_mm)
 
         except Exception:
-            for i in range(len(sys.exc_info())):
-                print("ReadMs3d - exception in try block '{0}'".format(sys.exc_info()[i]))
+            type, value, traceback = sys.exc_info()
+            print("ReadMs3d - exception in try block\n  type: '{0}'\n  value: '{1}'".format(type, value, traceback))
 
+            if t2 is None:
+                t2 = time.time()
+
             raise
 
         else:
             #DEBUG_print("ReadMs3d - passed try block")
             pass
 
-        t2 = time.time()
-        print("elapsed time: {0:.4}s".format(t2 - t1))
+        t3 = time.time()
+        print("elapsed time: {0:.4}s (disk io: ~{1:.4}s, converter: ~{2:.4}s)".format((t3 - t1), (t2 - t1), (t3 - t2)))
 
         return {"FINISHED"}
 
@@ -462,11 +468,11 @@
         blenderImage, setupImage = self.GetImage(ms3dMaterial, alphamap, allow_create=allow_create)
         if setupImage:
             pass
-    
+
         blenderTexture, setupTexture = self.GetTexture(ms3dMaterial, alphamap, blenderImage, allow_create=allow_create)
         if setupTexture:
             blenderTexture.image = blenderImage
-        
+
             if (alphamap):
                 blenderTexture.use_preview_alpha = True
 
@@ -613,7 +619,7 @@
         # remove double and deserted vertices
         ms3d_utils.EnableEditMode(True)
 
-    
+
         if (ms3d_utils.PROP_ITEM_OBJECT_JOINT in self.prop_objects):
             #bpy.ops.object.modifier_add(type='ARMATURE')
             pass
@@ -711,7 +717,7 @@
             # duplicate selected faces
             if bpy.ops.mesh.duplicate.poll():
                 bpy.ops.mesh.duplicate()
-                
+
             # put selected to vertex_group
             blenderVertexGroup = bpy.context.active_object.vertex_groups.new(prop(PROP_NAME_SMOOTH_GROUP).format(smoothGroupKey))
             bpy.context.active_object.vertex_groups.active = blenderVertexGroup
@@ -921,7 +927,7 @@
     ###########################################################################
     def GetMaterial(self, ms3dMaterial):
         nameMaterial = ms3dMaterial.name
-        
+
         # already available
         blenderMaterial = self.dict_materials.get(nameMaterial)
         if (blenderMaterial):

Modified: contrib/py/scripts/addons/io_scene_ms3d/ms3d_spec.py
===================================================================
--- contrib/py/scripts/addons/io_scene_ms3d/ms3d_spec.py	2011-12-03 13:49:37 UTC (rev 2713)
+++ contrib/py/scripts/addons/io_scene_ms3d/ms3d_spec.py	2011-12-03 14:00:09 UTC (rev 2714)
@@ -320,8 +320,8 @@
 
     def __init__(
             self,
-            defaultId = None,
-            defaultVersion = None
+            defaultId=HEADER,
+            defaultVersion=4
             ):
         """
         initialize
@@ -333,12 +333,6 @@
         """
         #DEBUG_print("ms3d_header_t.__init__", PRINT_LEVEL1)
 
-        if (not defaultId):
-            defaultId = HEADER
-
-        if (not defaultVersion):
-            defaultVersion = 4
-
         self.id = defaultId
         self.version = defaultVersion
 
@@ -386,16 +380,12 @@
             "referenceCount",
             )
 
-    @property
-    def vertex(self):
-        return self._vertex
-
     def __init__(
             self,
-            defaultFlags=None,
-            defaultVertex=None,
-            defaultBoneId=None,
-            defaultReferenceCount=None
+            defaultFlags=FLAG_NONE,

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list