Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Meyer <florianfelix@web.de>2010-05-16 20:04:45 +0400
committerFlorian Meyer <florianfelix@web.de>2010-05-16 20:04:45 +0400
commitd61abf20a2960bfa3099b3fc7f1699d0e3f82af7 (patch)
tree04f3e02308744124a0a443fb33be53803ba1a7e3 /add_mesh_gemstones.py
parent66d24dd19c662d0e8b3f68466403bc7416f1a131 (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_gemstones.py')
-rw-r--r--add_mesh_gemstones.py44
1 files changed, 26 insertions, 18 deletions
diff --git a/add_mesh_gemstones.py b/add_mesh_gemstones.py
index a9c1c34b..ba61df8b 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