[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28935] trunk/blender/release/scripts/ modules/add_object_utils.py: add new object py module.

Campbell Barton ideasman42 at gmail.com
Sun May 23 14:38:49 CEST 2010


Revision: 28935
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28935
Author:   campbellbarton
Date:     2010-05-23 14:38:49 +0200 (Sun, 23 May 2010)

Log Message:
-----------
add new object py module.
- added view align from twisted torus script and return the object's base.

Modified Paths:
--------------
    trunk/blender/release/scripts/modules/add_object_utils.py

Modified: trunk/blender/release/scripts/modules/add_object_utils.py
===================================================================
--- trunk/blender/release/scripts/modules/add_object_utils.py	2010-05-23 12:14:07 UTC (rev 28934)
+++ trunk/blender/release/scripts/modules/add_object_utils.py	2010-05-23 12:38:49 UTC (rev 28935)
@@ -19,7 +19,22 @@
 # <pep8 compliant>
 
 import bpy
+import mathutils
 
+def _align_matrix(context):
+    # TODO, local view cursor!
+    location = mathutils.TranslationMatrix(context.scene.cursor_location)
+
+    if context.user_preferences.edit.object_align == 'VIEW' and context.space_data.type == 'VIEW_3D':
+        rotation = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
+    else:
+        rotation = mathutils.Matrix()
+
+    align_matrix = location * rotation
+
+    return align_matrix
+
+
 def add_object_data(obdata, context):
 
     scene = context.scene
@@ -36,9 +51,9 @@
     if context.space_data and context.space_data.type == 'VIEW_3D':
         base.layers_from_view(context.space_data)
 
-    # TODO, local view cursor!
-    obj_new.location = scene.cursor_location
 
+    obj_new.matrix = _align_matrix(context)
+
     obj_act = scene.objects.active
 
     if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
@@ -55,3 +70,5 @@
         scene.objects.active = obj_new
         if context.user_preferences.edit.enter_edit_mode:
             bpy.ops.object.mode_set(mode='EDIT')
+
+    return base





More information about the Bf-blender-cvs mailing list