[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33880] trunk/blender/release/scripts/op: use slicing for exporters for some speedup, no functional change.

Campbell Barton ideasman42 at gmail.com
Fri Dec 24 05:24:34 CET 2010


Revision: 33880
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33880
Author:   campbellbarton
Date:     2010-12-24 05:24:33 +0100 (Fri, 24 Dec 2010)

Log Message:
-----------
use slicing for exporters for some speedup, no functional change.
3ds also uses non tuple __slots__ and had unused default values for some classes.

Modified Paths:
--------------
    trunk/blender/release/scripts/op/io_mesh_ply/export_ply.py
    trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py
    trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py

Modified: trunk/blender/release/scripts/op/io_mesh_ply/export_ply.py
===================================================================
--- trunk/blender/release/scripts/op/io_mesh_ply/export_ply.py	2010-12-24 04:21:05 UTC (rev 33879)
+++ trunk/blender/release/scripts/op/io_mesh_ply/export_ply.py	2010-12-24 04:24:33 UTC (rev 33880)
@@ -113,7 +113,7 @@
             uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4 # XXX - crufty :/
         if vertexColors:
             col = active_col_layer[i]
-            col = col.color1, col.color2, col.color3, col.color4
+            col = col.color1[:], col.color2[:], col.color3[:], col.color4[:]
 
         f_verts = f.vertices
 
@@ -176,7 +176,7 @@
     file.write('end_header\n')
 
     for i, v in enumerate(ply_verts):
-        file.write('%.6f %.6f %.6f ' % tuple(mesh_verts[v[0]].co)) # co
+        file.write('%.6f %.6f %.6f ' % mesh_verts[v[0]].co[:]) # co
         if use_normals:
             file.write('%.6f %.6f %.6f ' % v[1]) # no
         if use_uv_coords:

Modified: trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py	2010-12-24 04:21:05 UTC (rev 33879)
+++ trunk/blender/release/scripts/op/io_scene_3ds/export_3ds.py	2010-12-24 04:24:33 UTC (rev 33880)
@@ -120,9 +120,9 @@
 class _3ds_short(object):
     '''Class representing a short (2-byte integer) for a 3ds file.
     *** This looks like an unsigned short H is unsigned from the struct docs - Cam***'''
-    __slots__ = 'value'
+    __slots__ = ('value', )
     def __init__(self, val=0):
-        self.value=val
+        self.value = val
 
     def get_size(self):
         return SZ_SHORT
@@ -135,9 +135,9 @@
 
 class _3ds_int(object):
     '''Class representing an int (4-byte integer) for a 3ds file.'''
-    __slots__ = 'value'
-    def __init__(self, val=0):
-        self.value=val
+    __slots__ = ('value', )
+    def __init__(self, val):
+        self.value = val
 
     def get_size(self):
         return SZ_INT
@@ -150,8 +150,8 @@
 
 class _3ds_float(object):
     '''Class representing a 4-byte IEEE floating point number for a 3ds file.'''
-    __slots__ = 'value'
-    def __init__(self, val=0.0):
+    __slots__ = ('value', )
+    def __init__(self, val):
         self.value=val
 
     def get_size(self):
@@ -166,8 +166,8 @@
 
 class _3ds_string(object):
     '''Class representing a zero-terminated string for a 3ds file.'''
-    __slots__ = 'value'
-    def __init__(self, val=""):
+    __slots__ = ('value', )
+    def __init__(self, val):
         self.value=val
 
     def get_size(self):
@@ -183,7 +183,7 @@
 class _3ds_point_3d(object):
     '''Class representing a three-dimensional point for a 3ds file.'''
     __slots__ = 'x','y','z'
-    def __init__(self, point=(0.0,0.0,0.0)):
+    def __init__(self, point):
         self.x, self.y, self.z = point
 
     def get_size(self):
@@ -216,8 +216,8 @@
 
 class _3ds_point_uv(object):
     '''Class representing a UV-coordinate for a 3ds file.'''
-    __slots__ = 'uv'
-    def __init__(self, point=(0.0,0.0)):
+    __slots__ = ('uv', )
+    def __init__(self, point):
         self.uv = point
 
     def __cmp__(self, other):
@@ -236,7 +236,7 @@
 class _3ds_rgb_color(object):
     '''Class representing a (24-bit) rgb color for a 3ds file.'''
     __slots__ = 'r','g','b'
-    def __init__(self, col=(0,0,0)):
+    def __init__(self, col):
         self.r, self.g, self.b = col
 
     def get_size(self):
@@ -251,7 +251,7 @@
 
 class _3ds_face(object):
     '''Class representing a face for a 3ds file.'''
-    __slots__ = 'vindex'
+    __slots__ = ('vindex', )
     def __init__(self, vindex):
         self.vindex = vindex
 

Modified: trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2010-12-24 04:21:05 UTC (rev 33879)
+++ trunk/blender/release/scripts/op/io_scene_fbx/export_fbx.py	2010-12-24 04:24:33 UTC (rev 33880)
@@ -1436,12 +1436,14 @@
         i=-1
 
         for v in me_vertices:
-            if i==-1:
-                file.write('%.6f,%.6f,%.6f' % tuple(v.co));	i=0
+            if i == -1:
+                file.write('%.6f,%.6f,%.6f' % v.co[:])
+                i = 0
             else:
-                if i==7:
-                    file.write('\n\t\t');	i=0
-                file.write(',%.6f,%.6f,%.6f'% tuple(v.co))
+                if i == 7:
+                    file.write('\n\t\t')
+                    i = 0
+                file.write(',%.6f,%.6f,%.6f'% v.co[:])
             i+=1
 
         file.write('\n\t\tPolygonVertexIndex: ')
@@ -1508,11 +1510,11 @@
         i=-1
         for v in me_vertices:
             if i==-1:
-                file.write('%.15f,%.15f,%.15f' % tuple(v.normal));	i=0
+                file.write('%.15f,%.15f,%.15f' % v.normal[:]);	i=0
             else:
                 if i==2:
                     file.write('\n			 ');	i=0
-                file.write(',%.15f,%.15f,%.15f' % tuple(v.normal))
+                file.write(',%.15f,%.15f,%.15f' % v.normal[:])
             i+=1
         file.write('\n\t\t}')
 
@@ -1558,15 +1560,7 @@
 
         file.write('\n\t\t}')
 
-        # small utility function
-        # returns a slice of data depending on number of face verts
-        # data is either a MeshTextureFace or MeshColor
-        def face_data(data, face):
-            totvert = len(f.vertices)
 
-            return data[:totvert]
-
-
         # Write VertexColor Layers
         # note, no programs seem to use this info :/
         collayers = []
@@ -1585,21 +1579,21 @@
                 i = -1
                 ii = 0 # Count how many Colors we write
 
-                for f, cf in zip(me_faces, collayer.data):
-                    colors = [cf.color1, cf.color2, cf.color3, cf.color4]
+                for fi, cf in enumerate(collayer.data):
+                    if len(me_faces[fi].vertices) == 4:
+                        colors = cf.color1[:], cf.color2[:], cf.color3[:], cf.color4[:]
+                    else:
+                        colors = cf.color1[:], cf.color2[:], cf.color3[:]
 
-                    # determine number of verts
-                    colors = face_data(colors, f)
-
                     for col in colors:
                         if i==-1:
-                            file.write('%.4f,%.4f,%.4f,1' % tuple(col))
+                            file.write('%.4f,%.4f,%.4f,1' % col)
                             i=0
                         else:
                             if i==7:
                                 file.write('\n\t\t\t\t')
                                 i=0
-                            file.write(',%.4f,%.4f,%.4f,1' % tuple(col))
+                            file.write(',%.4f,%.4f,%.4f,1' % col)
                         i+=1
                         ii+=1 # One more Color
 
@@ -1646,7 +1640,7 @@
                             i=0
                         else:
                             if i==7:
-                                file.write('\n			 ')
+                                file.write('\n\t\t\t ')
                                 i=0
                             file.write(',%.6f,%.6f' % tuple(uv))
                         i+=1





More information about the Bf-blender-cvs mailing list