diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-05-30 21:18:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-05-30 21:18:16 +0400 |
commit | a9867c226ba92790d990a906f6a11b8a03e18f1d (patch) | |
tree | 4f30958925caf60538e68f18fedfd38f6801613e | |
parent | 0882438832bb9a3d9a3b4b8341a6095b2357d5bc (diff) |
add torus now works like other C add-object operators, location and rotation are initialized and kept even when settings are changed after.
-rw-r--r-- | release/scripts/modules/add_object_utils.py | 28 | ||||
-rw-r--r-- | release/scripts/op/add_mesh_torus.py | 6 |
2 files changed, 23 insertions, 11 deletions
diff --git a/release/scripts/modules/add_object_utils.py b/release/scripts/modules/add_object_utils.py index e4130d9136a..350191af807 100644 --- a/release/scripts/modules/add_object_utils.py +++ b/release/scripts/modules/add_object_utils.py @@ -21,21 +21,29 @@ import bpy import mathutils -def _align_matrix(context): - # TODO, local view cursor! - location = mathutils.TranslationMatrix(context.scene.cursor_location) +def add_object_align_init(context, operator): - 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 and operator.properties.is_property_set("location") and operator.properties.is_property_set("rotation"): + location = mathutils.TranslationMatrix(mathutils.Vector(operator.properties.location)) + rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4() else: - rotation = mathutils.Matrix() + # TODO, local view cursor! + location = mathutils.TranslationMatrix(context.scene.cursor_location) - align_matrix = location * rotation + 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() - return align_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(obdata, context): + +def add_object_data(context, obdata, operator=None): scene = context.scene @@ -52,7 +60,7 @@ def add_object_data(obdata, context): base.layers_from_view(context.space_data) - obj_new.matrix = _align_matrix(context) + obj_new.matrix = add_object_align_init(context, operator) obj_act = scene.objects.active diff --git a/release/scripts/op/add_mesh_torus.py b/release/scripts/op/add_mesh_torus.py index d79cbcf3e64..16bf4e1c92c 100644 --- a/release/scripts/op/add_mesh_torus.py +++ b/release/scripts/op/add_mesh_torus.py @@ -102,6 +102,10 @@ class AddTorus(bpy.types.Operator): description="Total Interior Radius of the torus", default=0.5, min=0.01, max=100.0) + # generic transform props + location = FloatVectorProperty(name="Location") + rotation = FloatVectorProperty(name="Rotation") + def execute(self, context): props = self.properties @@ -123,7 +127,7 @@ class AddTorus(bpy.types.Operator): mesh.update() import add_object_utils - add_object_utils.add_object_data(mesh, context) + add_object_utils.add_object_data(context, mesh, operator=self) return {'FINISHED'} |