Skip to content
Snippets Groups Projects
Commit 9216515d authored by Florian Meyer's avatar Florian Meyer
Browse files

- same view_align fix as in gears

parent 34be323f
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,18 @@ import mathutils ...@@ -67,6 +67,18 @@ import mathutils
from math import * from math import *
from bpy.props import * from bpy.props import *
# calculates the matrix for the new object
# depending on user pref
def align_matrix(context):
loc = mathutils.TranslationMatrix(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()
newMatrix = loc * rot
return newMatrix
# Stores the values of a list of properties and the # Stores the values of a list of properties and the
# operator id in a property group ('recall_op') inside the object. # operator id in a property group ('recall_op') inside the object.
...@@ -752,7 +764,7 @@ class AddGear(bpy.types.Operator): ...@@ -752,7 +764,7 @@ class AddGear(bpy.types.Operator):
min=0.0, min=0.0,
max=100.0, max=100.0,
default=0.0) default=0.0)
newMatrix = 'fromInvoke' newMatrix = mathutils.Matrix()
def draw(self, context): def draw(self, context):
props = self.properties props = self.properties
...@@ -818,14 +830,7 @@ class AddGear(bpy.types.Operator): ...@@ -818,14 +830,7 @@ class AddGear(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
loc = mathutils.TranslationMatrix(context.scene.cursor_location) self.newMatrix = align_matrix(context)
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.RotationMatrix()
self.newMatrix = loc * rot
self.execute(context) self.execute(context)
return {'FINISHED'} return {'FINISHED'}
...@@ -885,7 +890,7 @@ class AddWormGear(bpy.types.Operator): ...@@ -885,7 +890,7 @@ class AddWormGear(bpy.types.Operator):
min=0.0, min=0.0,
max=100.0, max=100.0,
default=0.0) default=0.0)
newMatrix = 'fromInvoke' newMatrix = mathutils.Matrix()
def draw(self, context): def draw(self, context):
props = self.properties props = self.properties
...@@ -947,14 +952,7 @@ class AddWormGear(bpy.types.Operator): ...@@ -947,14 +952,7 @@ class AddWormGear(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
loc = mathutils.TranslationMatrix(context.scene.cursor_location) self.newMatrix = align_matrix(context)
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.RotationMatrix()
self.newMatrix = loc * rot
self.execute(context) self.execute(context)
return {'FINISHED'} return {'FINISHED'}
......
...@@ -145,25 +145,26 @@ def store_recall_properties(ob, op, op_args): ...@@ -145,25 +145,26 @@ def store_recall_properties(ob, op, op_args):
# Apply view rotation to objects if "Align To" for # Apply view rotation to objects if "Align To" for
# new objects was set to "VIEW" in the User Preference. # new objects was set to "VIEW" in the User Preference.
def apply_object_align(context, ob): # Is now handled in the invoke functions
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 = mathutils.TranslationMatrix(context.scene.cursor_location)
obj_align = context.user_preferences.edit.object_align
if (context.space_data.type == 'VIEW_3D' if (context.space_data.type == 'VIEW_3D'
and obj_align == 'VIEW'): and obj_align == 'VIEW'):
view3d = context.space_data rot = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
region = view3d.region_3d else:
viewMatrix = region.view_matrix rot = mathutils.Matrix()
rot = viewMatrix.rotation_part() newMatrix = loc * rot
ob.rotation_euler = rot.invert().to_euler() return newMatrix
# Create a new mesh (object) from verts/edges/faces. # Create a new mesh (object) from verts/edges/faces.
# verts/edges/faces ... List of vertices/edges/faces for the # verts/edges/faces ... List of vertices/edges/faces for the
# new mesh (as used in from_pydata). # new mesh (as used in from_pydata).
# name ... Name of the new mesh (& object). # name ... Name of the new mesh (& object).
# edit ... Replace existing mesh data. # edit ... Replace existing mesh data.
# Note: Using "edit" will destroy/delete 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, newMatrix):
scene = context.scene scene = context.scene
obj_act = scene.objects.active obj_act = scene.objects.active
...@@ -216,9 +217,7 @@ def create_mesh_object(context, verts, edges, faces, name, edit): ...@@ -216,9 +217,7 @@ def create_mesh_object(context, verts, edges, faces, name, edit):
ob_new.selected = True ob_new.selected = True
# Place the object at the 3D cursor location. # Place the object at the 3D cursor location.
ob_new.location = scene.cursor_location ob_new.matrix = newMatrix
apply_object_align(context, ob_new)
if obj_act and obj_act.mode == 'EDIT': if obj_act and obj_act.mode == 'EDIT':
if not edit: if not edit:
...@@ -359,6 +358,7 @@ class AddElbowJoint(bpy.types.Operator): ...@@ -359,6 +358,7 @@ class AddElbowJoint(bpy.types.Operator):
min=0.01, min=0.01,
max=100.0, max=100.0,
unit="LENGTH") unit="LENGTH")
newMatrix = mathutils.Matrix()
def execute(self, context): def execute(self, context):
edit = self.properties.edit edit = self.properties.edit
...@@ -419,7 +419,7 @@ class AddElbowJoint(bpy.types.Operator): ...@@ -419,7 +419,7 @@ class AddElbowJoint(bpy.types.Operator):
faces.extend(createFaces(loop2, loop3, closed=True)) faces.extend(createFaces(loop2, loop3, closed=True))
obj = create_mesh_object(context, verts, [], faces, obj = create_mesh_object(context, verts, [], faces,
"Elbow Joint", edit) "Elbow Joint", edit, self.newMatrix)
# Store 'recall' properties in the object. # Store 'recall' properties in the object.
recall_args_list = { recall_args_list = {
...@@ -433,6 +433,10 @@ class AddElbowJoint(bpy.types.Operator): ...@@ -433,6 +433,10 @@ class AddElbowJoint(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
self.newMatrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class AddTeeJoint(bpy.types.Operator): class AddTeeJoint(bpy.types.Operator):
# Create the vertices and polygons for a simple tee (T) joint. # Create the vertices and polygons for a simple tee (T) joint.
...@@ -488,6 +492,7 @@ class AddTeeJoint(bpy.types.Operator): ...@@ -488,6 +492,7 @@ class AddTeeJoint(bpy.types.Operator):
min=0.01, min=0.01,
max=100.0, max=100.0,
unit="LENGTH") unit="LENGTH")
newMatrix = mathutils.Matrix()
def execute(self, context): def execute(self, context):
edit = self.properties.edit edit = self.properties.edit
...@@ -615,7 +620,7 @@ class AddTeeJoint(bpy.types.Operator): ...@@ -615,7 +620,7 @@ class AddTeeJoint(bpy.types.Operator):
faces.extend(createFaces(loopJoint2, loopArm, closed=True)) faces.extend(createFaces(loopJoint2, loopArm, closed=True))
faces.extend(createFaces(loopJoint3, loopMainEnd, closed=True)) faces.extend(createFaces(loopJoint3, loopMainEnd, closed=True))
obj = create_mesh_object(context, verts, [], faces, "Tee Joint", edit) obj = create_mesh_object(context, verts, [], faces, "Tee Joint", edit, self.newMatrix)
# Store 'recall' properties in the object. # Store 'recall' properties in the object.
recall_args_list = { recall_args_list = {
...@@ -630,6 +635,10 @@ class AddTeeJoint(bpy.types.Operator): ...@@ -630,6 +635,10 @@ class AddTeeJoint(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
self.newMatrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class AddWyeJoint(bpy.types.Operator): class AddWyeJoint(bpy.types.Operator):
'''Add a Wye-Joint mesh''' '''Add a Wye-Joint mesh'''
...@@ -689,6 +698,7 @@ class AddWyeJoint(bpy.types.Operator): ...@@ -689,6 +698,7 @@ class AddWyeJoint(bpy.types.Operator):
min=0.01, min=0.01,
max=100.0, max=100.0,
unit="LENGTH") unit="LENGTH")
newMatrix = mathutils.Matrix()
def execute(self, context): def execute(self, context):
edit = self.properties.edit edit = self.properties.edit
...@@ -827,7 +837,7 @@ class AddWyeJoint(bpy.types.Operator): ...@@ -827,7 +837,7 @@ class AddWyeJoint(bpy.types.Operator):
faces.extend(createFaces(loopJoint2, loopArm1, closed=True)) faces.extend(createFaces(loopJoint2, loopArm1, closed=True))
faces.extend(createFaces(loopJoint3, loopArm2, closed=True)) faces.extend(createFaces(loopJoint3, loopArm2, closed=True))
obj = create_mesh_object(context, verts, [], faces, "Wye Joint", edit) obj = create_mesh_object(context, verts, [], faces, "Wye Joint", edit, self.newMatrix)
# Store 'recall' properties in the object. # Store 'recall' properties in the object.
recall_args_list = { recall_args_list = {
...@@ -843,6 +853,10 @@ class AddWyeJoint(bpy.types.Operator): ...@@ -843,6 +853,10 @@ class AddWyeJoint(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
self.newMatrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class AddCrossJoint(bpy.types.Operator): class AddCrossJoint(bpy.types.Operator):
'''Add a Cross-Joint mesh''' '''Add a Cross-Joint mesh'''
...@@ -913,6 +927,7 @@ class AddCrossJoint(bpy.types.Operator): ...@@ -913,6 +927,7 @@ class AddCrossJoint(bpy.types.Operator):
min=0.01, min=0.01,
max=100.0, max=100.0,
unit="LENGTH") unit="LENGTH")
newMatrix = mathutils.Matrix()
def execute(self, context): def execute(self, context):
edit = self.properties.edit edit = self.properties.edit
...@@ -1102,7 +1117,7 @@ class AddCrossJoint(bpy.types.Operator): ...@@ -1102,7 +1117,7 @@ class AddCrossJoint(bpy.types.Operator):
faces.extend(createFaces(loopJoint4, loopArm3, closed=True)) faces.extend(createFaces(loopJoint4, loopArm3, closed=True))
obj = create_mesh_object(context, verts, [], faces, obj = create_mesh_object(context, verts, [], faces,
"Cross Joint", edit) "Cross Joint", edit, self.newMatrix)
# Store 'recall' properties in the object. # Store 'recall' properties in the object.
recall_args_list = { recall_args_list = {
...@@ -1120,6 +1135,10 @@ class AddCrossJoint(bpy.types.Operator): ...@@ -1120,6 +1135,10 @@ class AddCrossJoint(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
self.newMatrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class AddNJoint(bpy.types.Operator): class AddNJoint(bpy.types.Operator):
'''Add a N-Joint mesh''' '''Add a N-Joint mesh'''
...@@ -1156,6 +1175,7 @@ class AddNJoint(bpy.types.Operator): ...@@ -1156,6 +1175,7 @@ class AddNJoint(bpy.types.Operator):
min=0.01, min=0.01,
max=100.0, max=100.0,
unit="LENGTH") unit="LENGTH")
newMatrix = mathutils.Matrix()
def execute(self, context): def execute(self, context):
edit = self.properties.edit edit = self.properties.edit
...@@ -1280,7 +1300,7 @@ class AddNJoint(bpy.types.Operator): ...@@ -1280,7 +1300,7 @@ class AddNJoint(bpy.types.Operator):
createFaces(loopsJoints[loopIdx], createFaces(loopsJoints[loopIdx],
loopsEndCircles[loopIdx], closed=True)) loopsEndCircles[loopIdx], closed=True))
obj = create_mesh_object(context, verts, [], faces, "N Joint", edit) obj = create_mesh_object(context, verts, [], faces, "N Joint", edit, self.newMatrix)
# Store 'recall' properties in the object. # Store 'recall' properties in the object.
recall_args_list = { recall_args_list = {
...@@ -1293,6 +1313,10 @@ class AddNJoint(bpy.types.Operator): ...@@ -1293,6 +1313,10 @@ class AddNJoint(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event):
self.newMatrix = align_matrix(context)
self.execute(context)
return {'FINISHED'}
class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu): class INFO_MT_mesh_pipe_joints_add(bpy.types.Menu):
# Define the "Pipe Joints" menu # Define the "Pipe Joints" menu
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment