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:
Diffstat (limited to 'release/scripts/modules/add_object_utils.py')
-rw-r--r--release/scripts/modules/add_object_utils.py36
1 files changed, 28 insertions, 8 deletions
diff --git a/release/scripts/modules/add_object_utils.py b/release/scripts/modules/add_object_utils.py
index 44efc8f2ada..10707734bc4 100644
--- a/release/scripts/modules/add_object_utils.py
+++ b/release/scripts/modules/add_object_utils.py
@@ -23,28 +23,47 @@ import mathutils
def add_object_align_init(context, operator):
+ space_data = context.space_data
+ if space_data.type != 'VIEW_3D':
+ space_data = None
- if operator and operator.properties.is_property_set("location") and operator.properties.is_property_set("rotation"):
+ # location
+ if operator and operator.properties.is_property_set("location"):
location = mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location))
- rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4()
else:
- # TODO, local view cursor!
- location = mathutils.Matrix.Translation(context.scene.cursor_location)
+ if space_data: # local view cursor is detected below
+ location = mathutils.Matrix.Translation(space_data.cursor_location)
+ else:
+ location = mathutils.Matrix.Translation(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()
+ if operator:
+ operator.properties.location = location.to_translation()
+
+ # rotation
+ view_align = (context.user_preferences.edit.object_align == 'VIEW')
+ view_align_force = False
+ if operator:
+ if operator.properties.is_property_set("view_align"):
+ view_align = view_align_force = operator.view_align
+ else:
+ operator.properties.view_align = view_align
+
+ if operator and operator.properties.is_property_set("rotation") and not view_align_force:
+ rotation = mathutils.Euler(operator.properties.rotation).to_matrix().to_4x4()
+ else:
+ if view_align and space_data:
+ rotation = space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
else:
rotation = mathutils.Matrix()
# set the operator properties
if operator:
- operator.properties.location = location.translation_part()
operator.properties.rotation = rotation.to_euler()
return location * rotation
-def add_object_data(context, obdata, operator=None):
+def object_data_add(context, obdata, operator=None):
scene = context.scene
@@ -65,6 +84,7 @@ def add_object_data(context, obdata, operator=None):
obj_act = scene.objects.active
if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
+ bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
obj_act.select = True