diff options
author | Florian Meyer <florianfelix@web.de> | 2010-05-16 20:04:45 +0400 |
---|---|---|
committer | Florian Meyer <florianfelix@web.de> | 2010-05-16 20:04:45 +0400 |
commit | d61abf20a2960bfa3099b3fc7f1699d0e3f82af7 (patch) | |
tree | 04f3e02308744124a0a443fb33be53803ba1a7e3 /add_mesh_3d_function_surface.py | |
parent | 66d24dd19c662d0e8b3f68466403bc7416f1a131 (diff) |
- batch one of add mesh updates
- removed view alignment in the object creation
- added view alignment through align_matrix in the invoke
- if the 'VIEW' alignment preference is set and the object properties are changed
the object is rotated always to the view alignment of the view when the operator was called.
--> doesn't snap to new view rotation when orbiting around object and changing properties.
Diffstat (limited to 'add_mesh_3d_function_surface.py')
-rw-r--r-- | add_mesh_3d_function_surface.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/add_mesh_3d_function_surface.py b/add_mesh_3d_function_surface.py index 0737024c..a56660c6 100644 --- a/add_mesh_3d_function_surface.py +++ b/add_mesh_3d_function_surface.py @@ -130,18 +130,18 @@ def store_recall_properties(ob, op, op_args): ob['recall'] = recall_properties -# Apply view rotation to objects if "Align To" for -# new objects was set to "VIEW" in the User Preference. -def apply_object_align(context, ob): - obj_align = bpy.context.user_preferences.edit.object_align - +# calculates the matrix for the new object +# depending on user pref +def align_matrix(context): + loc = TranslationMatrix(context.scene.cursor_location) + obj_align = context.user_preferences.edit.object_align if (context.space_data.type == 'VIEW_3D' and obj_align == 'VIEW'): - view3d = context.space_data - region = view3d.region_3d - viewMatrix = region.view_matrix - rot = viewMatrix.rotation_part() - ob.rotation_euler = rot.invert().to_euler() + rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4() + else: + rot = Matrix() + align_matrix = loc * rot + return align_matrix # Create a new mesh (object) from verts/edges/faces. @@ -150,7 +150,7 @@ def apply_object_align(context, ob): # name ... Name of the new mesh (& object). # edit ... Replace existing mesh data. # Note: Using "edit" will destroy/delete existing mesh data. -def create_mesh_object(context, verts, edges, faces, name, edit): +def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix): scene = context.scene obj_act = scene.objects.active @@ -203,9 +203,8 @@ def create_mesh_object(context, verts, edges, faces, name, edit): ob_new.selected = True # Place the object at the 3D cursor location. - ob_new.location = scene.cursor_location - - apply_object_align(context, ob_new) + # apply viewRotaion + ob_new.matrix = align_matrix if obj_act and obj_act.mode == 'EDIT': if not edit: @@ -342,6 +341,7 @@ class AddZFunctionSurface(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") + align_matrix = Matrix() def execute(self, context): edit = self.properties.edit @@ -401,7 +401,7 @@ class AddZFunctionSurface(bpy.types.Operator): edgeloop_prev = edgeloop_cur - obj = create_mesh_object(context, verts, [], faces, "Z Function", edit) + obj = create_mesh_object(context, verts, [], faces, "Z Function", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -415,6 +415,10 @@ class AddZFunctionSurface(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} def xyz_function_surface_faces(self, x_eq, y_eq, z_eq, range_u_min, range_u_max, range_u_step, wrap_u, @@ -589,6 +593,8 @@ class AddXYZFunctionSurface(bpy.types.Operator): description="V Wrap around", default=False) + align_matrix = Matrix() + def execute(self, context): props = self.properties @@ -610,7 +616,7 @@ class AddXYZFunctionSurface(bpy.types.Operator): return {'CANCELLED'} obj = create_mesh_object(context, verts, [], faces, - "XYZ Function", props.edit) + "XYZ Function", props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -630,6 +636,11 @@ class AddXYZFunctionSurface(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + ################################ import space_info |