[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41100] branches/bmesh/blender: svn merge ^/trunk/blender -r41075:41099

Campbell Barton ideasman42 at gmail.com
Tue Oct 18 03:09:04 CEST 2011


Revision: 41100
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41100
Author:   campbellbarton
Date:     2011-10-18 01:09:00 +0000 (Tue, 18 Oct 2011)
Log Message:
-----------
svn merge ^/trunk/blender -r41075:41099

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41075

Modified Paths:
--------------
    branches/bmesh/blender/CMakeLists.txt
    branches/bmesh/blender/doc/manpage/blender.1
    branches/bmesh/blender/doc/python_api/rst/info_best_practice.rst
    branches/bmesh/blender/doc/python_api/rst/info_gotcha.rst
    branches/bmesh/blender/intern/ghost/intern/GHOST_SystemSDL.h
    branches/bmesh/blender/intern/ghost/intern/GHOST_WindowSDL.h
    branches/bmesh/blender/intern/tools/credits_svn_gen.py
    branches/bmesh/blender/release/datafiles/splash.png
    branches/bmesh/blender/release/scripts/modules/addon_utils.py
    branches/bmesh/blender/release/scripts/modules/animsys_refactor.py
    branches/bmesh/blender/release/scripts/modules/blend_render_info.py
    branches/bmesh/blender/release/scripts/modules/bpy/__init__.py
    branches/bmesh/blender/release/scripts/modules/bpy/ops.py
    branches/bmesh/blender/release/scripts/modules/bpy/utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/anim_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/image_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/io_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/keyconfig_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/mesh_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/object_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_extras/view3d_utils.py
    branches/bmesh/blender/release/scripts/modules/bpy_types.py
    branches/bmesh/blender/release/scripts/modules/console_python.py
    branches/bmesh/blender/release/scripts/modules/console_shell.py
    branches/bmesh/blender/release/scripts/modules/rna_info.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/anim.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/console.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/object.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/uvcalc_follow_active.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/uvcalc_lightmap.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/uvcalc_smart_project.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/vertexpaint_dirt.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/view3d.py
    branches/bmesh/blender/release/scripts/startup/bl_operators/wm.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_animviz.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_data_armature.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_data_bone.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_material.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_object_constraint.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_physics_common.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/properties_texture.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/space_logic.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/space_userpref.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/space_userpref_keymap.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/space_view3d.py
    branches/bmesh/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/bmesh/blender/release/scripts/templates/gamelogic_module.py
    branches/bmesh/blender/source/blender/blenkernel/BKE_animsys.h
    branches/bmesh/blender/source/blender/blenkernel/BKE_blender.h
    branches/bmesh/blender/source/blender/blenkernel/BKE_utildefines.h
    branches/bmesh/blender/source/blender/blenkernel/intern/cloth.c
    branches/bmesh/blender/source/blender/blenkernel/intern/fcurve.c
    branches/bmesh/blender/source/blender/blenkernel/intern/seqeffects.c
    branches/bmesh/blender/source/blender/blenkernel/intern/softbody.c
    branches/bmesh/blender/source/blender/blenlib/intern/path_util.c
    branches/bmesh/blender/source/blender/blenloader/intern/readfile.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_marking.c
    branches/bmesh/blender/source/blender/editors/animation/anim_channels_edit.c
    branches/bmesh/blender/source/blender/editors/datafiles/splash.png.c
    branches/bmesh/blender/source/blender/editors/include/ED_anim_api.h
    branches/bmesh/blender/source/blender/editors/mesh/bmesh_selecthistory.c
    branches/bmesh/blender/source/blender/editors/mesh/meshtools.c
    branches/bmesh/blender/source/blender/editors/physics/particle_edit.c
    branches/bmesh/blender/source/blender/editors/sculpt_paint/paint_image.c
    branches/bmesh/blender/source/blender/editors/space_outliner/outliner_edit.c
    branches/bmesh/blender/source/blender/editors/space_sequencer/sequencer_select.c
    branches/bmesh/blender/source/blender/editors/space_view3d/view3d_edit.c
    branches/bmesh/blender/source/blender/editors/space_view3d/view3d_fly.c
    branches/bmesh/blender/source/blender/imbuf/intern/IMB_indexer.h
    branches/bmesh/blender/source/blender/makesrna/intern/rna_image_api.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_screw.c
    branches/bmesh/blender/source/blender/modifiers/intern/MOD_simpledeform.c
    branches/bmesh/blender/source/blender/python/intern/bpy_props.c
    branches/bmesh/blender/source/blender/python/intern/bpy_rna.c
    branches/bmesh/blender/source/blender/python/intern/bpy_rna.h
    branches/bmesh/blender/source/blender/python/mathutils/mathutils_Euler.c
    branches/bmesh/blender/source/blender/render/intern/include/raycounter.h
    branches/bmesh/blender/source/blender/render/intern/raytrace/bvh.h
    branches/bmesh/blender/source/blender/windowmanager/intern/wm_operators.c
    branches/bmesh/blender/source/darwin/blender.app/Contents/Info.plist
    branches/bmesh/blender/source/darwin/set_simulation_threads_applescript.scpt
    branches/bmesh/blender/source/gameengine/Converter/BL_ArmatureObject.cpp
    branches/bmesh/blender/source/gameengine/Expressions/ConstExpr.cpp
    branches/bmesh/blender/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp

Added Paths:
-----------
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Info.plist
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/MacOS/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/MacOS/applet
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/PkgInfo
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/Scripts/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/Scripts/main.scpt
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/applet.icns
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/applet.rsrc
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/description.rtfd/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/description.rtfd/TXT.rtf
    branches/bmesh/blender/source/tools/spell_check_source.py
    branches/bmesh/blender/source/tools/spell_check_source_config.py

Removed Paths:
-------------
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Info.plist
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/MacOS/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/MacOS/applet
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/PkgInfo
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/Scripts/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/Scripts/main.scpt
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/applet.icns
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/applet.rsrc
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/description.rtfd/
    branches/bmesh/blender/source/darwin/set_simulation_threads.app/Contents/Resources/description.rtfd/TXT.rtf

Property Changed:
----------------
    branches/bmesh/blender/
    branches/bmesh/blender/doc/python_api/examples/mathutils.Color.py
    branches/bmesh/blender/release/
    branches/bmesh/blender/source/blender/editors/space_outliner/


Property changes on: branches/bmesh/blender
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/blender:39992-41075
   + /trunk/blender:39992-41099

Modified: branches/bmesh/blender/CMakeLists.txt
===================================================================
--- branches/bmesh/blender/CMakeLists.txt	2011-10-17 17:57:21 UTC (rev 41099)
+++ branches/bmesh/blender/CMakeLists.txt	2011-10-18 01:09:00 UTC (rev 41100)
@@ -774,7 +774,7 @@
 		set(PLATFORM_LINKFLAGS_DEBUG "/NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libc.lib")
 
 	else()
-		# keep GCC spesific stuff here
+		# keep GCC specific stuff here
 		if(CMAKE_COMPILER_IS_GNUCC)
 			set(PLATFORM_LINKLIBS "-lshell32 -lshfolder -lgdi32 -lmsvcrt -lwinmm -lmingw32 -lm -lws2_32 -lz -lstdc++ -lole32 -luuid -lwsock32")
 			set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing")

Modified: branches/bmesh/blender/doc/manpage/blender.1
===================================================================
(Binary files differ)


Property changes on: branches/bmesh/blender/doc/python_api/examples/mathutils.Color.py
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Modified: branches/bmesh/blender/doc/python_api/rst/info_best_practice.rst
===================================================================
--- branches/bmesh/blender/doc/python_api/rst/info_best_practice.rst	2011-10-17 17:57:21 UTC (rev 41099)
+++ branches/bmesh/blender/doc/python_api/rst/info_best_practice.rst	2011-10-18 01:09:00 UTC (rev 41100)
@@ -2,8 +2,9 @@
 Best Practice
 *************
 
+When writing you're own scripts python is great for new developers to pick up and become productive, but you can also pick up odd habits or at least write scripts that are not easy for others to understand.
 
-TODO: Intro text
+For you're own work this is of course fine, but if you want to collaborate with others or have you're work included with blender there are practices we encourage.
 
 
 Style Conventions
@@ -61,5 +62,233 @@
 Script Efficiency
 =================
 
-TODO: Campbell
+List Manipulation (General Python Tips)
+---------------------------------------
 
+
+Searching for list items
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+In Python there are some handy list functions that save you having to search through the list.
+
+Even though you're not looping on the list data **python is**, so you need to be aware of functions that will slow down your script by searching the whole list.
+
+.. code-block:: python
+
+   my_list.count(list_item)
+   my_list.index(list_item)
+   my_list.remove(list_item)
+   if list_item in my_list: ...
+
+
+Modifying Lists
+^^^^^^^^^^^^^^^
+In python we can add and remove from a list, This is slower when the list length is modifier, especially at the start of the list, since all the data after the index of modification needs to be moved up or down 1 place.
+
+The most simple way to add onto the end of the list is to use ``my_list.append(list_item)`` or ``my_list.extend(some_list)`` and the fastest way to remove an item is ``my_list.pop()`` or ``del my_list[-1]``.
+
+To use an index you can use ``my_list.insert(index, list_item)`` or ``list.pop(index)`` for list removal, but these are slower.
+
+Sometimes its faster (but more memory hungry) to just rebuild the list.
+
+
+Say you want to remove all triangle faces in a list.
+
+Rather than...
+
+.. code-block:: python
+
+   faces = mesh.faces[:]  # make a list copy of the meshes faces
+   f_idx = len(faces)     # Loop backwards
+   while f_idx:           # while the value is not 0
+       f_idx -= 1
+
+       if len(faces[f_idx].vertices) == 3:
+           faces.pop(f_idx)  # remove the triangle
+
+
+It's faster to build a new list with list comprehension.
+
+.. code-block:: python
+
+   faces = [f for f in mesh.faces if len(f.vertices) != 3]
+
+
+Adding List Items
+^^^^^^^^^^^^^^^^^
+
+If you have a list that you want to add onto another list, rather then...
+
+.. code-block:: python
+
+   for l in some_list:
+       my_list.append(l)
+
+Use...
+
+.. code-block:: python
+
+   my_list.extend([a, b, c...])
+
+
+Note that insert can be used when needed, but it is slower than append especially when inserting at the start of a long list.
+
+This example shows a very sub-optimal way of making a reversed list.
+
+
+.. code-block:: python
+
+   reverse_list = []
+   for list_item in some_list:
+       reverse_list.insert(0, list_item)
+
+
+Removing List Items
+^^^^^^^^^^^^^^^^^^^
+
+Use ``my_list.pop(index)`` rather than ``my_list.remove(list_item)``
+
+This requires you to have the index of the list item but is faster since ``remove()`` will search the list.
+
+Here is an example of how to remove items in 1 loop, removing the last items first, which is faster (as explained above).
+
+.. code-block:: python
+
+   list_index = len(my_list)
+
+   while list_index:
+       list_index -= 1
+       if my_list[list_index].some_test_attribute == 1:
+           my_list.pop(list_index)
+
+
+This example shows a fast way of removing items, for use in cases were where you can alter the list order without breaking the scripts functionality. This works by swapping 2 list items, so the item you remove is always last.
+
+.. code-block:: python
+
+   pop_index = 5
+
+   # swap so the pop_index is last.
+   my_list[-1], my_list[pop_index] = my_list[pop_index], my_list[-1]
+
+   # remove last item (pop_index)
+   my_list.pop()
+
+
+When removing many items in a large list this can provide a good speedup.
+
+
+Avoid Copying Lists
+^^^^^^^^^^^^^^^^^^^
+
+When passing a list/dictionary to a function, it is faster to have the function modify the list rather then returning a new list so python dosn't have tp duplicate the list in memory.
+
+Functions that modify a list in-place are more efficient then functions that create new lists.
+
+
+This is generally slower so only use for functions when it makes sense not to modify the list in place.
+
+>>> my_list = some_list_func(my_list)
+
+
+This is generally faster since there is no re-assignment and no list duplication.
+
+>>> some_list_func(vec)
+
+
+Also note that passing a sliced list makes a copy of the list in python memory
+
+>>> foobar(my_list[:])
+
+If my_list was a large array containing 10000's of items, a copy could use a lot of extra memory.
+
+
+Writing Strings to a File (Python General)
+------------------------------------------
+
+Here are 3 ways of joining multiple strings into 1 string for writing
+
+This really applies to any area of your code that involves a lot of string joining.
+
+
+Pythons string addition, *don't use if you can help it, especially when writing data in a loop.*
+
+>>> file.write(str1 + " " + str2 + " " + str3 + "\n")
+
+
+String formatting. Use this when you're writing string data from floats and int's
+
+>>> file.write("%s %s %s\n" % (str1, str2, str3))
+
+
+Pythons string joining function. To join a list of strings
+
+>>> file.write(" ".join([str1, str2, str3, "\n"]))
+
+
+join is fastest on many strings, string formatting is quite fast too (better for converting data types). String arithmetic is slowest.
+
+
+Parsing Strings (Import/Exporting)
+----------------------------------
+
+Since many file formats are ASCII, the way you parse/export strings can make a large difference in how fast your script runs.
+
+When importing strings to make into blender there are a few ways to parse the string.
+
+Parsing Numbers
+^^^^^^^^^^^^^^^
+
+Use ``float(string)`` rather than ``eval(string)``, if you know the value will be an int then ``int(string)``,  float() will work for an int too but its faster to read ints with int().
+
+Checking String Start/End
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+If your checking the start of a string for a keyword, rather than...
+
+>>> if line[0:5] == "vert ": ...
+
+Use...
+
+>>> if line.startswith("vert "):
+
+Using ``startswith()`` is slightly faster (approx 5%) and also avoids a possible error with the slice length not matching the string length.
+
+my_string.endswith("foo_bar") can be used for line endings too.
+
+if your unsure whether the text is upper or lower case use lower or upper string function.
+
+>>> if line.lower().startswith("vert ")
+
+
+Use try/except Sparingly
+------------------------
+
+The **try** statement useful to save time writing error checking code.
+
+However **try** is significantly slower then an **if** since an exception has to be set each time, so avoid using **try** in areas of your code that execute in a loop and runs many times.
+
+There are cases where using **try** is faster than checking weather the condition will raise an error, so it is worth experimenting.
+
+
+Value Comparison
+----------------
+
+Python has two ways to compare values ``a == b`` and ``a is b``, The difference is that ``==`` may run the objects comparison function ``__cmp__()`` where as ``is`` compares identity, that both variables reference the same item in memory. 
+
+In cases where you know you are checking for the same value which is referenced from multiple places, ``is`` is faster.
+
+
+Time You're Code
+----------------
+
+While developing a script its good to time it to be aware of any changes in performance, this can be done simply.
+
+.. code-block:: python
+
+   import time
+   time_start = time.time()
+
+   # do something...
+
+   print("My Script Finished: %.4f sec" % time.time() - time_start)

Modified: branches/bmesh/blender/doc/python_api/rst/info_gotcha.rst
===================================================================
--- branches/bmesh/blender/doc/python_api/rst/info_gotcha.rst	2011-10-17 17:57:21 UTC (rev 41099)
+++ branches/bmesh/blender/doc/python_api/rst/info_gotcha.rst	2011-10-18 01:09:00 UTC (rev 41100)
@@ -223,6 +223,26 @@
 This is mainly an issue with editmode since pose data can be manipulated without having to be in pose mode, however for operator access you may still need to enter pose mode.
 
 
+Relative File Paths
+===================
+
+Blenders relative file paths are not compatible with standard python modules such as ``sys`` and ``os``.
+
+Built in python functions don't understand blenders ``//`` prefix which denotes the blend file path.
+
+A common case where you would run into this problem is when exporting a material with assosiated image paths.
+
+>>> bpy.path.abspath(image.filepath)
+
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list