Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-02-27 17:16:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-02-27 17:16:32 +0300
commit52f92b4cb18b24c44c42bfecc55c19e4ed2eb90d (patch)
treea3b6dfec7ae0048a49f2a55b5deea07bc142f4b9
parent87acf919a5023e690e67bfbf3846081a70838bea (diff)
lazy load modules for more scripts.
-rw-r--r--release/scripts/modules/bpy/utils.py20
-rw-r--r--release/scripts/op/add_mesh_torus.py3
-rw-r--r--release/scripts/op/fcurve_euler_filter.py5
-rw-r--r--release/scripts/op/uvcalc_smart_project.py67
-rw-r--r--release/scripts/op/vertexpaint_dirt.py21
-rw-r--r--release/scripts/ui/space_userpref.py3
6 files changed, 70 insertions, 49 deletions
diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py
index 76278ca8fa1..fde3db17c75 100644
--- a/release/scripts/modules/bpy/utils.py
+++ b/release/scripts/modules/bpy/utils.py
@@ -38,22 +38,26 @@ import addon_utils
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 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
: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 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
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 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
try:
unregister()
except:
+ import traceback
traceback.print_exc()
def test_reload(mod):
@@ -147,6 +152,7 @@ def load_scripts(reload_scripts=False, refresh_scripts=False):
try:
return imp.reload(mod)
except:
+ import traceback
traceback.print_exc()
def test_register(mod):
@@ -424,7 +430,6 @@ def _bpy_module_classes(module, is_registered=False):
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 @@ def register_module(module, verbose=False):
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 register_module(module, verbose=False):
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 @@ def unregister_module(module, verbose=False):
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")
diff --git a/release/scripts/op/add_mesh_torus.py b/release/scripts/op/add_mesh_torus.py
index db4f90f05d1..c3c7d92bded 100644
--- a/release/scripts/op/add_mesh_torus.py
+++ b/release/scripts/op/add_mesh_torus.py
@@ -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
diff --git a/release/scripts/op/fcurve_euler_filter.py b/release/scripts/op/fcurve_euler_filter.py
index b7d456dd525..a6d5289d6f8 100644
--- a/release/scripts/op/fcurve_euler_filter.py
+++ b/release/scripts/op/fcurve_euler_filter.py
@@ -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]
diff --git a/release/scripts/op/uvcalc_smart_project.py b/release/scripts/op/uvcalc_smart_project.py
index 8cdf593f98d..7ee7c119c4e 100644
--- a/release/scripts/op/uvcalc_smart_project.py
+++ b/release/scripts/op/uvcalc_smart_project.py
@@ -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 @@ global USER_FILL_HOLES_QUALITY
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 @@ def testNewVecLs2DRotIsBetter(vecs, mat=-1, bestAreaSoFar = -1):
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 @@ def mergeUvIslands(islandList):
# 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 @@ def packIslands(islandList):
#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 @@ class thickface(object):
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,6 +800,21 @@ def main(context, island_margin, projection_limit):
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 @@ def main(context, island_margin, projection_limit):
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 @@ def main(context, island_margin, projection_limit):
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()
diff --git a/release/scripts/op/vertexpaint_dirt.py b/release/scripts/op/vertexpaint_dirt.py
index d5060e913ae..82bc25e1b47 100644
--- a/release/scripts/op/vertexpaint_dirt.py
+++ b/release/scripts/op/vertexpaint_dirt.py
@@ -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 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
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,7 +139,9 @@ def applyVertexDirt(me, blur_iterations, blur_strength, clamp_dirt, clamp_clean,
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):
@@ -162,6 +157,8 @@ class VertexPaintDirt(bpy.types.Operator):
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 @@ class VertexPaintDirt(bpy.types.Operator):
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 --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py
index a1fb82b8930..93985591824 100644
--- a/release/scripts/ui/space_userpref.py
+++ b/release/scripts/ui/space_userpref.py
@@ -19,7 +19,6 @@
# <pep8 compliant>
import bpy
import os
-import shutil
import addon_utils
from bpy.props import StringProperty, BoolProperty, EnumProperty
@@ -1073,6 +1072,8 @@ class WM_OT_addon_install(bpy.types.Operator):
def execute(self, context):
import traceback
import zipfile
+ import shutil
+
pyfile = self.filepath
# dont use bpy.utils.script_paths("addons") because we may not be able to write to it.