diff --git a/add_mesh_3d_function_surface.py b/add_mesh_3d_function_surface.py index 0737024cbede6a93473969041356160e8a1a5d01..a56660c68861bd3515376a84963691566ff69754 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 diff --git a/add_mesh_archimedean_solids.py b/add_mesh_archimedean_solids.py index 85872165a7c56ec8b5e884f63176a5bf73f8e0b2..b67d4b79a9727aefecaa28438970f8fbeeb45639 100644 --- a/add_mesh_archimedean_solids.py +++ b/add_mesh_archimedean_solids.py @@ -54,18 +54,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. @@ -74,7 +74,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 @@ -127,9 +127,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: @@ -1179,6 +1178,7 @@ class AddTruncatedTetrahedron(bpy.types.Operator): star_ngons = BoolProperty(name='Star N-Gon', description='Create star-shaped hexagons.', default=False) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -1191,7 +1191,7 @@ class AddTruncatedTetrahedron(bpy.types.Operator): return {'CANCELLED'} obj = create_mesh_object(context, verts, [], faces, - 'TrTetrahedron', props.edit) + 'TrTetrahedron', props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1202,6 +1202,11 @@ class AddTruncatedTetrahedron(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + class AddCuboctahedron(bpy.types.Operator): '''Add a mesh for a cuboctahedron (truncated cube).''' @@ -1225,6 +1230,7 @@ class AddCuboctahedron(bpy.types.Operator): star_ngons = BoolProperty(name='Star N-Gon', description='Create star-shaped octagons.', default=False) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -1236,7 +1242,7 @@ class AddCuboctahedron(bpy.types.Operator): if not verts: return {'CANCELLED'} - obj = create_mesh_object(context, verts, [], faces, name, props.edit) + obj = create_mesh_object(context, verts, [], faces, name, props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1247,6 +1253,11 @@ class AddCuboctahedron(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + class AddRhombicuboctahedron(bpy.types.Operator): '''Add a mesh for a rhombicuboctahedron.''' @@ -1265,6 +1276,7 @@ class AddRhombicuboctahedron(bpy.types.Operator): min=0.01, max=1.99, default=sqrt(2.0) / (1.0 + sqrt(2) / 2.0)) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -1275,7 +1287,7 @@ class AddRhombicuboctahedron(bpy.types.Operator): return {'CANCELLED'} obj = create_mesh_object(context, verts, [], faces, - 'Rhombicuboctahedron', props.edit) + 'Rhombicuboctahedron', props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1285,6 +1297,11 @@ class AddRhombicuboctahedron(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + class AddTruncatedOctahedron(bpy.types.Operator): '''Add a mesh for a truncated octahedron.''' @@ -1307,6 +1324,7 @@ class AddTruncatedOctahedron(bpy.types.Operator): star_ngons = BoolProperty(name='Star N-Gon', description='Create star-shaped hexagons.', default=False) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -1319,7 +1337,7 @@ class AddTruncatedOctahedron(bpy.types.Operator): return {'CANCELLED'} obj = create_mesh_object(context, verts, [], faces, - 'TrOctahedron', props.edit) + 'TrOctahedron', props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1330,6 +1348,11 @@ class AddTruncatedOctahedron(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + class AddTruncatedCuboctahedron(bpy.types.Operator): '''Add a mesh for a truncated cuboctahedron.''' @@ -1357,6 +1380,7 @@ class AddTruncatedCuboctahedron(bpy.types.Operator): star_ngons = BoolProperty(name='Star N-Gon', description='Create star-shaped octagons.', default=False) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -1370,7 +1394,7 @@ class AddTruncatedCuboctahedron(bpy.types.Operator): return {'CANCELLED'} obj = create_mesh_object(context, verts, [], faces, - 'TrCuboctahedron', props.edit) + 'TrCuboctahedron', props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1382,6 +1406,11 @@ class AddTruncatedCuboctahedron(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_archimedean_solids_add(bpy.types.Menu): # Define the "Archimedean Solids" menu diff --git a/add_mesh_gears.py b/add_mesh_gears.py index 221b7fb4ca3aecb1608e35b18afc74e7fb739502..8bf8b815180d47000d44f5efb7fd99aff662f40c 100644 --- a/add_mesh_gears.py +++ b/add_mesh_gears.py @@ -77,8 +77,8 @@ def align_matrix(context): rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4() else: rot = mathutils.Matrix() - newMatrix = loc * rot - return newMatrix + align_matrix = loc * rot + return align_matrix # Stores the values of a list of properties and the # operator id in a property group ('recall_op') inside the object. @@ -106,7 +106,7 @@ def store_recall_properties(ob, op, op_args): # 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, newMatrix): +def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix): scene = context.scene obj_act = scene.objects.active @@ -160,7 +160,7 @@ def create_mesh_object(context, verts, edges, faces, name, edit, newMatrix): # Place the object at the 3D cursor location. # apply viewRotaion - ob_new.matrix = newMatrix + ob_new.matrix = align_matrix if obj_act and obj_act.mode == 'EDIT': @@ -764,7 +764,7 @@ class AddGear(bpy.types.Operator): min=0.0, max=100.0, default=0.0) - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def draw(self, context): props = self.properties @@ -801,7 +801,7 @@ class AddGear(bpy.types.Operator): crown=props.crown) # Actually create the mesh object from this geometry data. - obj = create_mesh_object(context, verts, [], faces, "Gear", props.edit, self.newMatrix) + obj = create_mesh_object(context, verts, [], faces, "Gear", props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -830,7 +830,7 @@ class AddGear(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} @@ -890,7 +890,7 @@ class AddWormGear(bpy.types.Operator): min=0.0, max=100.0, default=0.0) - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def draw(self, context): props = self.properties @@ -924,7 +924,7 @@ class AddWormGear(bpy.types.Operator): # Actually create the mesh object from this geometry data. obj = create_mesh_object(context, verts, [], faces, "Worm Gear", - props.edit, self.newMatrix) + props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -952,7 +952,7 @@ class AddWormGear(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} diff --git a/add_mesh_gemstones.py b/add_mesh_gemstones.py index a9c1c34b35f8cb0eefacd402e513458e213ea07d..ba61df8bf3e503b2934de08bb08a8cc8a6f8cc7f 100644 --- a/add_mesh_gemstones.py +++ b/add_mesh_gemstones.py @@ -53,19 +53,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. # verts/edges/faces ... List of vertices/edges/faces for the @@ -73,7 +72,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 @@ -126,9 +125,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: @@ -376,6 +374,7 @@ class AddDiamond(bpy.types.Operator): min=0.01, max=9999.0, default=0.8) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -386,7 +385,7 @@ class AddDiamond(bpy.types.Operator): props.pavilion_height) obj = create_mesh_object(context, verts, [], faces, - "Diamond", props.edit) + "Diamond", props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -400,6 +399,10 @@ class AddDiamond(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} class AddGem(bpy.types.Operator): """Add a diamond gem""" @@ -438,6 +441,7 @@ class AddGem(bpy.types.Operator): min=0.01, max=9999.0, default=0.8) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -450,7 +454,7 @@ class AddGem(bpy.types.Operator): props.pavilion_height, props.crown_height) - obj = create_mesh_object(context, verts, [], faces, "Gem", props.edit) + obj = create_mesh_object(context, verts, [], faces, "Gem", props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -464,6 +468,10 @@ class AddGem(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_gemstones_add(bpy.types.Menu): # Define the "Gemstones" menu @@ -507,4 +515,4 @@ def unregister(): space_info.INFO_MT_mesh_add.remove(menu_func) if __name__ == "__main__": - register() + register() \ No newline at end of file diff --git a/add_mesh_pipe_joint.py b/add_mesh_pipe_joint.py index 803d79e52380711f7324b4edf30beb5693bc920d..016e487747581ee2d951eeff6b3ad67cbe5f4b63 100644 --- a/add_mesh_pipe_joint.py +++ b/add_mesh_pipe_joint.py @@ -156,15 +156,15 @@ def align_matrix(context): rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4() else: rot = mathutils.Matrix() - newMatrix = loc * rot - return newMatrix + 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). # edit ... Replace existing mesh data. # Note: Using "edit" will destroy/delete existing mesh data. -def create_mesh_object(context, verts, edges, faces, name, edit, newMatrix): +def create_mesh_object(context, verts, edges, faces, name, edit, align_matrix): scene = context.scene obj_act = scene.objects.active @@ -217,7 +217,7 @@ def create_mesh_object(context, verts, edges, faces, name, edit, newMatrix): ob_new.selected = True # Place the object at the 3D cursor location. - ob_new.matrix = newMatrix + ob_new.matrix = align_matrix if obj_act and obj_act.mode == 'EDIT': if not edit: @@ -358,7 +358,7 @@ class AddElbowJoint(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def execute(self, context): edit = self.properties.edit @@ -419,7 +419,7 @@ class AddElbowJoint(bpy.types.Operator): faces.extend(createFaces(loop2, loop3, closed=True)) obj = create_mesh_object(context, verts, [], faces, - "Elbow Joint", edit, self.newMatrix) + "Elbow Joint", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -434,7 +434,7 @@ class AddElbowJoint(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} @@ -492,7 +492,7 @@ class AddTeeJoint(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def execute(self, context): edit = self.properties.edit @@ -620,7 +620,7 @@ class AddTeeJoint(bpy.types.Operator): faces.extend(createFaces(loopJoint2, loopArm, closed=True)) faces.extend(createFaces(loopJoint3, loopMainEnd, closed=True)) - obj = create_mesh_object(context, verts, [], faces, "Tee Joint", edit, self.newMatrix) + obj = create_mesh_object(context, verts, [], faces, "Tee Joint", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -636,7 +636,7 @@ class AddTeeJoint(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} @@ -698,7 +698,7 @@ class AddWyeJoint(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def execute(self, context): edit = self.properties.edit @@ -837,7 +837,7 @@ class AddWyeJoint(bpy.types.Operator): faces.extend(createFaces(loopJoint2, loopArm1, closed=True)) faces.extend(createFaces(loopJoint3, loopArm2, closed=True)) - obj = create_mesh_object(context, verts, [], faces, "Wye Joint", edit, self.newMatrix) + obj = create_mesh_object(context, verts, [], faces, "Wye Joint", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -854,7 +854,7 @@ class AddWyeJoint(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} @@ -927,7 +927,7 @@ class AddCrossJoint(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def execute(self, context): edit = self.properties.edit @@ -1117,7 +1117,7 @@ class AddCrossJoint(bpy.types.Operator): faces.extend(createFaces(loopJoint4, loopArm3, closed=True)) obj = create_mesh_object(context, verts, [], faces, - "Cross Joint", edit, self.newMatrix) + "Cross Joint", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1136,7 +1136,7 @@ class AddCrossJoint(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} @@ -1175,7 +1175,7 @@ class AddNJoint(bpy.types.Operator): min=0.01, max=100.0, unit="LENGTH") - newMatrix = mathutils.Matrix() + align_matrix = mathutils.Matrix() def execute(self, context): edit = self.properties.edit @@ -1300,7 +1300,7 @@ class AddNJoint(bpy.types.Operator): createFaces(loopsJoints[loopIdx], loopsEndCircles[loopIdx], closed=True)) - obj = create_mesh_object(context, verts, [], faces, "N Joint", edit, self.newMatrix) + obj = create_mesh_object(context, verts, [], faces, "N Joint", edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -1314,7 +1314,7 @@ class AddNJoint(bpy.types.Operator): return {'FINISHED'} def invoke(self, context, event): - self.newMatrix = align_matrix(context) + self.align_matrix = align_matrix(context) self.execute(context) return {'FINISHED'} diff --git a/add_mesh_spindle.py b/add_mesh_spindle.py index 9d870ca25610993bdb4cae45d723918a3fd31040..65846565d4cd6f8358bf979f35dd929be325e897 100644 --- a/add_mesh_spindle.py +++ b/add_mesh_spindle.py @@ -52,7 +52,7 @@ Usage: import bpy import mathutils -from mathutils import Vector, RotationMatrix +from mathutils import Vector, RotationMatrix, TranslationMatrix, Matrix from math import pi from bpy.props import FloatProperty, IntProperty, BoolProperty @@ -77,18 +77,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. @@ -97,7 +97,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 @@ -150,9 +150,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: @@ -339,6 +338,7 @@ class AddSpindle(bpy.types.Operator): min=-9999.0, max=9999.0, default=0.5) + align_matrix = Matrix() def execute(self, context): props = self.properties @@ -350,7 +350,7 @@ class AddSpindle(bpy.types.Operator): props.cap_height) obj = create_mesh_object(context, verts, [], faces, "Spindle", - props.edit) + props.edit, self.align_matrix) # Store 'recall' properties in the object. recall_args_list = { @@ -363,6 +363,11 @@ class AddSpindle(bpy.types.Operator): return {'FINISHED'} + def invoke(self, context, event): + self.align_matrix = align_matrix(context) + self.execute(context) + return {'FINISHED'} + # Register the operator menu_func = (lambda self, context: self.layout.operator(AddSpindle.bl_idname,