diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 18:14:04 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 18:14:04 +0300 |
commit | 10ad28fcf0e011fae094d8c20362ee7f28fc4df6 (patch) | |
tree | 613c9dcf67d6c4062b8c3baa31b75391bfcc6713 /add_mesh_gears.py | |
parent | 489bf0ee72290e4c0b4cae861672d20896a7b658 (diff) |
remove boiler plate add-object code and use python module as add_torus uses.
there are some known issues with this but much easier to fix bugs in the one place.
Diffstat (limited to 'add_mesh_gears.py')
-rw-r--r-- | add_mesh_gears.py | 73 |
1 files changed, 7 insertions, 66 deletions
diff --git a/add_mesh_gears.py b/add_mesh_gears.py index 22ae5286..a623ce48 100644 --- a/add_mesh_gears.py +++ b/add_mesh_gears.py @@ -69,24 +69,11 @@ import mathutils from math import * from bpy.props import * -# calculates the matrix for the new object -# depending on user pref -def align_matrix(context): - loc = mathutils.Matrix.Translation(context.scene.cursor_location) - obj_align = context.user_preferences.edit.object_align - if (context.space_data.type == 'VIEW_3D' - and obj_align == 'VIEW'): - rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4() - else: - rot = mathutils.Matrix() - align_matrix = loc * rot - return align_matrix - # Create a new mesh (object) from verts/edges/faces. # verts/edges/faces ... List of vertices/edges/faces for the # new mesh (as used in from_pydata). # name ... Name of the new mesh (& object). -def create_mesh_object(context, verts, edges, faces, name, align_matrix): +def create_mesh_object(context, verts, edges, faces, name): scene = context.scene obj_act = scene.objects.active @@ -99,45 +86,8 @@ def create_mesh_object(context, verts, edges, faces, name, align_matrix): # Update mesh geometry after adding stuff. mesh.update() - # Deselect all objects. - bpy.ops.object.select_all(action='DESELECT') - - # Always create new object - ob_new = bpy.data.objects.new(name, mesh) - - # Link new object to the given scene and select it. - scene.objects.link(ob_new) - ob_new.select = True - - # Place the object at the 3D cursor location. - # apply viewRotaion - ob_new.matrix_world = align_matrix - - - if obj_act and obj_act.mode == 'EDIT': - # We are in EditMode, switch to ObjectMode. - bpy.ops.object.mode_set(mode='OBJECT') - - # Select the active object as well. - obj_act.select = True - - # Apply location of new object. - scene.update() - - # Join new object into the active. - bpy.ops.object.join() - - # Switching back to EditMode. - bpy.ops.object.mode_set(mode='EDIT') - - ob_new = obj_act - - else: - # We are in ObjectMode. - # Make the new object the active one. - scene.objects.active = ob_new - - return ob_new + import add_object_utils + return add_object_utils.object_data_add(context, mesh, operator=None) # A very simple "bridge" tool. @@ -709,7 +659,6 @@ class AddGear(bpy.types.Operator): min=0.0, max=100.0, default=0.0) - align_matrix = mathutils.Matrix() def draw(self, context): layout = self.layout @@ -744,7 +693,8 @@ class AddGear(bpy.types.Operator): crown=self.crown) # Actually create the mesh object from this geometry data. - obj = create_mesh_object(context, verts, [], faces, "Gear", self.align_matrix) + base = create_mesh_object(context, verts, [], faces, "Gear") + obj = base.object # Create vertex groups from stored vertices. tipGroup = obj.vertex_groups.new('Tips') @@ -755,10 +705,6 @@ class AddGear(bpy.types.Operator): return {'FINISHED'} - def invoke(self, context, event): - self.align_matrix = align_matrix(context) - self.execute(context) - return {'FINISHED'} class AddWormGear(bpy.types.Operator): '''Add a worm gear mesh.''' @@ -811,7 +757,6 @@ class AddWormGear(bpy.types.Operator): min=0.0, max=100.0, default=0.0) - align_matrix = mathutils.Matrix() def draw(self, context): layout = self.layout @@ -842,8 +787,8 @@ class AddWormGear(bpy.types.Operator): crown=self.crown) # Actually create the mesh object from this geometry data. - obj = create_mesh_object(context, verts, [], faces, "Worm Gear", - self.align_matrix) + base = create_mesh_object(context, verts, [], faces, "Worm Gear") + obj = base.object # Create vertex groups from stored vertices. tipGroup = obj.vertex_groups.new('Tips') @@ -854,10 +799,6 @@ class AddWormGear(bpy.types.Operator): return {'FINISHED'} - def invoke(self, context, event): - self.align_matrix = align_matrix(context) - self.execute(context) - return {'FINISHED'} class INFO_MT_mesh_gears_add(bpy.types.Menu): # Define the "Gears" menu |