[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35222] trunk/blender/release/scripts: lazy load modules for more scripts.

Campbell Barton ideasman42 at gmail.com
Sun Feb 27 15:16:33 CET 2011


Revision: 35222
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35222
Author:   campbellbarton
Date:     2011-02-27 14:16:32 +0000 (Sun, 27 Feb 2011)
Log Message:
-----------
lazy load modules for more scripts.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/bpy/utils.py
    trunk/blender/release/scripts/op/add_mesh_torus.py
    trunk/blender/release/scripts/op/fcurve_euler_filter.py
    trunk/blender/release/scripts/op/uvcalc_smart_project.py
    trunk/blender/release/scripts/op/vertexpaint_dirt.py
    trunk/blender/release/scripts/ui/space_userpref.py

Modified: trunk/blender/release/scripts/modules/bpy/utils.py
===================================================================
--- trunk/blender/release/scripts/modules/bpy/utils.py	2011-02-27 14:08:33 UTC (rev 35221)
+++ trunk/blender/release/scripts/modules/bpy/utils.py	2011-02-27 14:16:32 UTC (rev 35222)
@@ -38,22 +38,26 @@
 
 
 def _test_import(module_name, loaded_modules):
-    import traceback
-    import time
+    use_time = _bpy.app.debug
+
     if module_name in loaded_modules:
         return None
     if "." in module_name:
         print("Ignoring '%s', can't import files containing multiple periods." % module_name)
         return None
 
-    t = time.time()
+    if use_time:
+        import time
+        t = time.time()
+
     try:
         mod = __import__(module_name)
     except:
+        import traceback
         traceback.print_exc()
         return None
 
-    if _bpy.app.debug:
+    if use_time:
         print("time %s %.4f" % (module_name, time.time() - t))
 
     loaded_modules.add(mod.__name__)  # should match mod.__name__ too
@@ -99,7 +103,6 @@
     :arg refresh_scripts: only load scripts which are not already loaded as modules.
     :type refresh_scripts: bool
     """
-    import traceback
     import time
 
     t_main = time.time()
@@ -124,6 +127,7 @@
             try:
                 register()
             except:
+                import traceback
                 traceback.print_exc()
         else:
             print("\nWarning! '%s' has no register function, this is now a requirement for registerable scripts." % mod.__file__)
@@ -134,6 +138,7 @@
             try:
                 unregister()
             except:
+                import traceback
                 traceback.print_exc()
 
     def test_reload(mod):
@@ -147,6 +152,7 @@
         try:
             return imp.reload(mod)
         except:
+            import traceback
             traceback.print_exc()
 
     def test_register(mod):
@@ -424,7 +430,6 @@
 
 
 def register_module(module, verbose=False):
-    import traceback
     if verbose:
         print("bpy.utils.register_module(%r): ..." % module)
     for cls, path, line in _bpy_module_classes(module, is_registered=False):
@@ -435,6 +440,7 @@
         except:
             print("bpy.utils.register_module(): failed to registering class '%s.%s'" % (cls.__module__, cls.__name__))
             print("\t", path, "line", line)
+            import traceback
             traceback.print_exc()
     if verbose:
         print("done.\n")
@@ -443,7 +449,6 @@
 
 
 def unregister_module(module, verbose=False):
-    import traceback
     if verbose:
         print("bpy.utils.unregister_module(%r): ..." % module)
     for cls, path, line in _bpy_module_classes(module, is_registered=True):
@@ -454,6 +459,7 @@
         except:
             print("bpy.utils.unregister_module(): failed to unregistering class '%s.%s'" % (cls.__module__, cls.__name__))
             print("\t", path, "line", line)
+            import traceback
             traceback.print_exc()
     if verbose:
         print("done.\n")

Modified: trunk/blender/release/scripts/op/add_mesh_torus.py
===================================================================
--- trunk/blender/release/scripts/op/add_mesh_torus.py	2011-02-27 14:08:33 UTC (rev 35221)
+++ trunk/blender/release/scripts/op/add_mesh_torus.py	2011-02-27 14:16:32 UTC (rev 35222)
@@ -19,10 +19,11 @@
 # <pep8 compliant>
 import bpy
 import mathutils
-from math import cos, sin, pi
 
 
 def add_torus(major_rad, minor_rad, major_seg, minor_seg):
+    from math import cos, sin, pi
+
     Vector = mathutils.Vector
     Quaternion = mathutils.Quaternion
 

Modified: trunk/blender/release/scripts/op/fcurve_euler_filter.py
===================================================================
--- trunk/blender/release/scripts/op/fcurve_euler_filter.py	2011-02-27 14:08:33 UTC (rev 35221)
+++ trunk/blender/release/scripts/op/fcurve_euler_filter.py	2011-02-27 14:16:32 UTC (rev 35222)
@@ -18,18 +18,17 @@
 
 # <pep8 compliant>
 
-from math import *
 import bpy
-from mathutils import *
 
 
 def main(context):
+    from math import pi
+
     def cleanupEulCurve(fcv):
         keys = []
 
         for k in fcv.keyframe_points:
             keys.append([k.handle_left.copy(), k.co.copy(), k.handle_right.copy()])
-        print(keys)
 
         for i in range(len(keys)):
             cur = keys[i]

Modified: trunk/blender/release/scripts/op/uvcalc_smart_project.py
===================================================================
--- trunk/blender/release/scripts/op/uvcalc_smart_project.py	2011-02-27 14:08:33 UTC (rev 35221)
+++ trunk/blender/release/scripts/op/uvcalc_smart_project.py	2011-02-27 14:16:32 UTC (rev 35222)
@@ -23,9 +23,7 @@
 # <pep8 compliant>
 
 from mathutils import Matrix, Vector, geometry
-import time
 import bpy
-from math import cos, radians
 
 DEG_TO_RAD = 0.017453292519943295 # pi/180.0
 SMALL_NUM = 0.000000001
@@ -36,14 +34,10 @@
 USER_FILL_HOLES = None
 USER_FILL_HOLES_QUALITY = None
 
-dict_matrix = {}
-
 def pointInTri2D(v, v1, v2, v3):
-    global dict_matrix
-
     key = v1.x, v1.y, v2.x, v2.y, v3.x, v3.y
 
-    # Commented because its slower to do teh bounds check, we should realy cache the bounds info for each face.
+    # Commented because its slower to do the bounds check, we should realy cache the bounds info for each face.
     '''
     # BOUNDS CHECK
     xmin= 1000000
@@ -268,21 +262,6 @@
     h = maxy-miny
     return (w*h, w,h), vecs # Area, vecs
 
-# Takes a list of faces that make up a UV island and rotate
-# until they optimally fit inside a square.
-ROTMAT_2D_POS_90D = Matrix.Rotation( radians(90.0), 2)
-ROTMAT_2D_POS_45D = Matrix.Rotation( radians(45.0), 2)
-
-RotMatStepRotation = []
-rot_angle = 22.5 #45.0/2
-while rot_angle > 0.1:
-    RotMatStepRotation.append([\
-     Matrix.Rotation( radians(rot_angle), 2),\
-     Matrix.Rotation( radians(-rot_angle), 2)])
-
-    rot_angle = rot_angle/2.0
-
-
 def optiRotateUvIsland(faces):
     global currentArea
 
@@ -464,7 +443,7 @@
 
 
                     # if targetIsland[3] > (sourceIsland[2]) and\ #
-                    # print USER_FREE_SPACE_TO_TEST_QUALITY, 'ass'
+                    # print USER_FREE_SPACE_TO_TEST_QUALITY
                     if targetIsland[2] > (sourceIsland[1] * USER_FREE_SPACE_TO_TEST_QUALITY) and\
                     targetIsland[4] > sourceIsland[4] and\
                     targetIsland[5] > sourceIsland[5]:
@@ -734,7 +713,7 @@
     #print '\tPacking UV Islands...'
 #XXX	Window.DrawProgressBar(0.7, 'Packing %i UV Islands...' % len(packBoxes) )
 
-    time1 = time.time()
+    # time1 = time.time()
     packWidth, packHeight = geometry.box_pack_2d(packBoxes)
 
     # print 'Box Packing Time:', time.time() - time1
@@ -793,6 +772,27 @@
         self.area = face.area
         self.edge_keys = face.edge_keys
 
+
+def main_consts():
+    from math import radians
+
+    global ROTMAT_2D_POS_90D
+    global ROTMAT_2D_POS_45D
+    global RotMatStepRotation
+
+    ROTMAT_2D_POS_90D = Matrix.Rotation( radians(90.0), 2)
+    ROTMAT_2D_POS_45D = Matrix.Rotation( radians(45.0), 2)
+
+    RotMatStepRotation = []
+    rot_angle = 22.5 #45.0/2
+    while rot_angle > 0.1:
+        RotMatStepRotation.append([\
+         Matrix.Rotation( radians(rot_angle), 2),\
+         Matrix.Rotation( radians(-rot_angle), 2)])
+
+        rot_angle = rot_angle/2.0
+
+
 global ob
 ob = None
 def main(context, island_margin, projection_limit):
@@ -800,7 +800,22 @@
     global USER_FILL_HOLES_QUALITY
     global USER_STRETCH_ASPECT
     global USER_ISLAND_MARGIN
+    
+    from math import cos
+    import time
 
+    global dict_matrix
+    dict_matrix = {}
+
+
+    # Constants:
+    # Takes a list of faces that make up a UV island and rotate
+    # until they optimally fit inside a square.
+    global ROTMAT_2D_POS_90D
+    global ROTMAT_2D_POS_45D
+    global RotMatStepRotation
+    main_consts()
+
 #XXX objects= bpy.data.scenes.active.objects
     objects = context.selected_editable_objects
 
@@ -868,7 +883,7 @@
 
     time1 = time.time()
 
-    # Tag as False se we dont operate on teh same mesh twice.
+    # Tag as False se we dont operate on the same mesh twice.
 #XXX	bpy.data.meshes.tag = False
     for me in bpy.data.meshes:
         me.tag = False
@@ -1074,6 +1089,8 @@
     if is_editmode:
         bpy.ops.object.mode_set(mode='EDIT')
 
+    dict_matrix.clear()
+
 #XXX	Window.DrawProgressBar(1.0, "")
 #XXX	Window.WaitCursor(0)
 #XXX	Window.RedrawAll()

Modified: trunk/blender/release/scripts/op/vertexpaint_dirt.py
===================================================================
--- trunk/blender/release/scripts/op/vertexpaint_dirt.py	2011-02-27 14:08:33 UTC (rev 35221)
+++ trunk/blender/release/scripts/op/vertexpaint_dirt.py	2011-02-27 14:16:32 UTC (rev 35222)
@@ -30,16 +30,9 @@
 #               but results are far more accurate
 #
 
-import bpy
-import math
-import time
-
-from mathutils import Vector
-from bpy.props import *
-
-
 def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean, dirt_only):
-##    Window.WaitCursor(1)
+    from mathutils import Vector
+    from math import acos
 
     #BPyMesh.meshCalcNormals(me)
 
@@ -76,7 +69,7 @@
         vec /= tot_con
 
         # angle is the acos of the dot product between vert and connected verts normals
-        ang = math.acos(no.dot(vec))
+        ang = acos(no.dot(vec))
 
         # enforce min/max
         ang = max(clamp_dirt, ang)
@@ -146,9 +139,11 @@
                 col[1] = tone * col[1]
                 col[2] = tone * col[2]
 
-##    Window.WaitCursor(0)
 
+import bpy
+from bpy.props import FloatProperty, IntProperty, BoolProperty
 
+
 class VertexPaintDirt(bpy.types.Operator):
 
     bl_idname = "paint.vertex_color_dirt"
@@ -162,6 +157,8 @@
     dirt_only = BoolProperty(name="Dirt Only", description="Dont calculate cleans for convex areas", default=False)
 
     def execute(self, context):
+        import time
+        from math import radians
         obj = context.object
 
         if not obj or obj.type != 'MESH':
@@ -172,7 +169,7 @@
 
         t = time.time()
 
-        applyVertexDirt(mesh, self.blur_iterations, self.blur_strength, math.radians(self.dirt_angle), math.radians(self.clean_angle), self.dirt_only)
+        applyVertexDirt(mesh, self.blur_iterations, self.blur_strength, radians(self.dirt_angle), radians(self.clean_angle), self.dirt_only)
 
         print('Dirt calculated in %.6f' % (time.time() - t))
 


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list