[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2232] trunk/py/scripts/addons: use sets rather then tuples for if checks, python optimizes this case.

Campbell Barton ideasman42 at gmail.com
Mon Aug 8 07:23:00 CEST 2011


Revision: 2232
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2232
Author:   campbellbarton
Date:     2011-08-08 05:23:00 +0000 (Mon, 08 Aug 2011)
Log Message:
-----------
use sets rather then tuples for if checks, python optimizes this case.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_export_directx_x.py
    trunk/py/scripts/addons/io_import_scene_dxf.py
    trunk/py/scripts/addons/io_mesh_ply/import_ply.py
    trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
    trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
    trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
    trunk/py/scripts/addons/object_grease_scatter.py
    trunk/py/scripts/addons/render_povray/render.py
    trunk/py/scripts/addons/render_renderfarmfi.py
    trunk/py/scripts/addons/rigify/__init__.py
    trunk/py/scripts/addons/rigify/ui.py
    trunk/py/scripts/addons/space_view3d_copy_attributes.py
    trunk/py/scripts/addons/space_view3d_math_vis/utils.py
    trunk/py/scripts/addons/space_view3d_spacebar_menu.py

Modified: trunk/py/scripts/addons/io_export_directx_x.py
===================================================================
--- trunk/py/scripts/addons/io_export_directx_x.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_export_directx_x.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -107,11 +107,11 @@
         print("Generating Object list for export... (Root parents only)")
     if Config.ExportMode == 1:
         Config.ExportList = [Object for Object in Config.context.scene.objects
-                             if Object.type in ("ARMATURE", "EMPTY", "MESH")
+                             if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}
                              and Object.parent is None]
     else:
         ExportList = [Object for Object in Config.context.selected_objects
-                      if Object.type in ("ARMATURE", "EMPTY", "MESH")]
+                      if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
         Config.ExportList = [Object for Object in ExportList
                              if Object.parent not in ExportList]
     if Config.Verbose:
@@ -184,7 +184,7 @@
 
 def GetObjectChildren(Parent):
     return [Object for Object in Parent.children
-            if Object.type in ("ARMATURE", "EMPTY", "MESH")]
+            if Object.type in {'ARMATURE', 'EMPTY', 'MESH'}]
 
 #Returns the vertex count of Mesh, counting each vertex for every face.
 def GetMeshVertexCount(Mesh):

Modified: trunk/py/scripts/addons/io_import_scene_dxf.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_dxf.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_import_scene_dxf.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -2247,7 +2247,7 @@
     f_faces = []
     f_vn = 0
     for ent in entities:
-        if ent.drawtype in ('Mesh','Curve'):
+        if ent.drawtype in {'Mesh', 'Curve'}:
             (verts, edges, faces, vn) = ent.build()
             if not toggle & T_DrawOne:
                 drawGeometry(verts, edges, faces)

Modified: trunk/py/scripts/addons/io_mesh_ply/import_ply.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_ply/import_ply.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_mesh_ply/import_ply.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -235,7 +235,7 @@
             if -1 in colindices:
                 colindices = None
             else:  # if not a float assume uchar
-                colmultiply = [1.0 if el.properties[i].numeric_type in ('f', 'd') else (1.0 / 256.0) for i in colindices]
+                colmultiply = [1.0 if el.properties[i].numeric_type in {'f', 'd'} else (1.0 / 256.0) for i in colindices]
 
         elif el.name == b'face':
             findex = el.index(b'vertex_indices')

Modified: trunk/py/scripts/addons/io_scene_3ds/import_3ds.py
===================================================================
--- trunk/py/scripts/addons/io_scene_3ds/import_3ds.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_scene_3ds/import_3ds.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -214,7 +214,7 @@
 def add_texture_to_material(image, texture, material, mapto):
     #print('assigning %s to %s' % (texture, material))
 
-    if mapto not in ("COLOR", "SPECULARITY", "ALPHA", "NORMAL"):
+    if mapto not in {'COLOR', 'SPECULARITY', 'ALPHA', 'NORMAL'}:
         print('/tError:  Cannot map to "%s"\n\tassuming diffuse color. modify material "%s" later.' % (mapto, material.name))
         mapto = "COLOR"
 

Modified: trunk/py/scripts/addons/io_scene_fbx/export_fbx.py
===================================================================
--- trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_scene_fbx/export_fbx.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -972,7 +972,7 @@
         if light_type > 2:
             light_type = 1  # hemi and area lights become directional
 
-        if light.type in ('HEMI', ):
+        if light.type == 'HEMI':
             do_light = not (light.use_diffuse or light.use_specular)
             do_shadow = False
         else:

Modified: trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/io_scene_x3d/export_x3d.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -1254,7 +1254,7 @@
 
             if obj_type == 'CAMERA':
                 writeViewpoint(ident, obj, obj_matrix, scene)
-            elif obj_type in ('MESH', 'CURVE', 'SURF', 'FONT'):
+            elif obj_type in {'MESH', 'CURVE', 'SURF', 'FONT'}:
                 if (obj_type != 'MESH') or (use_apply_modifiers and obj.is_modified(scene, 'PREVIEW')):
                     try:
                         me = obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW')

Modified: trunk/py/scripts/addons/object_grease_scatter.py
===================================================================
--- trunk/py/scripts/addons/object_grease_scatter.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/object_grease_scatter.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -26,13 +26,14 @@
     "version": (0, 1),
     "blender": (2, 5, 8),
     "api": 36079,
-    "location": "File > Export > Cameras & Markers (.py)",
-    "description": "Export Cameras & Markers (.py)",
+    "location": "3D View, Toolbar",
+    "description": ("Scatter a group of objects onto the active mesh using "
+                    "the grease pencil lines"),
     "warning": "",
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
-        "Scripts/Object/Grease_Scatter",
-    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
-        "func=detail&aid=TODO",
+    "wiki_url": ("http://wiki.blender.org/index.php/Extensions:2.5/Py/"
+                 "Scripts/Object/Grease_Scatter"),
+    "tracker_url": ("https://projects.blender.org/tracker/index.php?"
+                    "func=detail&aid=TODO"),
     "support": 'OFFICIAL',
     "category": "Object"}
 
@@ -115,20 +116,19 @@
         scene.objects.link(obj_new)
 
     ray = o.ray_cast
+    closest_point = o.closest_point_on_mesh
     #ray = C.scene.ray_cast
 
     DEBUG = False
 
     def fix_point(p):
-        for d in dirs:
-            # print(p)
-            hit, no, ind = ray(p, p + d)
-            if ind != -1:
-                if DEBUG:
-                    return [p, no, None]
-                else:
-                    # print("good", hit, no)
-                    return [hit, no, None]
+        hit, no, ind = closest_point(p)
+        if ind != -1:
+            if DEBUG:
+                return [p, no, None]
+            else:
+                # print("good", hit, no)
+                return [hit, no, None]
 
         # worry!
         print("bad!", p, BAD_NORMAL)
@@ -373,11 +373,11 @@
                     pass
 
         _main(self,
-            DENSITY=self.properties.density,
-            SCALE=self.properties.scale,
-            RAND_LOC=self.properties.rand_loc,
-            RAND_ALIGN=self.properties.rand_align
-        )
+              DENSITY=self.properties.density,
+              SCALE=self.properties.scale,
+              RAND_LOC=self.properties.rand_loc,
+              RAND_ALIGN=self.properties.rand_align,
+              )
         return {'FINISHED'}
 
     def invoke(self, context, event):

Modified: trunk/py/scripts/addons/render_povray/render.py
===================================================================
--- trunk/py/scripts/addons/render_povray/render.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/render_povray/render.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -645,7 +645,7 @@
 
             # Sun shouldn't be attenuated. Hemi and area lights have no falloff attribute so they
             # are put to type 2 attenuation a little higher above.
-            if lamp.type not in ('SUN', 'AREA', 'HEMI'):
+            if lamp.type not in {'SUN', 'AREA', 'HEMI'}:
                 tabWrite("fade_distance %.6f\n" % (lamp.distance / 5.0))
                 if lamp.falloff_type == 'INVERSE_SQUARE':
                     tabWrite("fade_power %d\n" % 2)  # Use blenders lamp quad equivalent
@@ -682,7 +682,7 @@
             meta = ob.data
 
             # important because no elements will break parsing.
-            elements = [elem for elem in meta.elements if elem.type in ('BALL', 'ELLIPSOID')]
+            elements = [elem for elem in meta.elements if elem.type in {'BALL', 'ELLIPSOID'}]
 
             if elements:
                 tabWrite("blob {\n")
@@ -839,7 +839,7 @@
 
             # XXX I moved all those checks here, as there is no need to compute names
             #     for object we won’t export here!
-            if ob.type in ('LAMP', 'CAMERA', 'EMPTY', 'META', 'ARMATURE', 'LATTICE'):
+            if ob.type in {'LAMP', 'CAMERA', 'EMPTY', 'META', 'ARMATURE', 'LATTICE'}:
                 continue
 
             try:

Modified: trunk/py/scripts/addons/render_renderfarmfi.py
===================================================================
--- trunk/py/scripts/addons/render_renderfarmfi.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/render_renderfarmfi.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -565,7 +565,7 @@
     if ore.hash=='' and (ore.username=='' or ore.password==''):
         bpy.errors.append('missing_creds')
     
-    if '' in (ore.title, ore.longdesc, ore.shortdesc):
+    if '' in {ore.title, ore.longdesc, ore.shortdesc}:
         bpy.errors.append('missing_desc')
     
     setStatus('username', ore.hash=='' and ore.username=='')
@@ -604,7 +604,7 @@
         s = completed[sid]['title']
         # t = completed[sid]['timestamps']  # UNUSED
         sinfo = OreSession(sid, s) 
-        if queue in ('completed', 'active'):
+        if queue in {'completed', 'active'}:
             sinfo.frames = completed[sid]['framesRendered']
         sinfo.startframe = completed[sid]['startFrame']
         sinfo.endframe = completed[sid]['endFrame']

Modified: trunk/py/scripts/addons/rigify/__init__.py
===================================================================
--- trunk/py/scripts/addons/rigify/__init__.py	2011-08-08 03:04:40 UTC (rev 2231)
+++ trunk/py/scripts/addons/rigify/__init__.py	2011-08-08 05:23:00 UTC (rev 2232)
@@ -56,7 +56,7 @@
 

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list