[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [671] trunk/py/scripts/addons: - batch one of add mesh updates
Florian Meyer
florianfelix at web.de
Sun May 16 18:04:45 CEST 2010
Revision: 671
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=671
Author: testscreenings
Date: 2010-05-16 18:04:45 +0200 (Sun, 16 May 2010)
Log Message:
-----------
- 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.
Modified Paths:
--------------
trunk/py/scripts/addons/add_mesh_3d_function_surface.py
trunk/py/scripts/addons/add_mesh_archimedean_solids.py
trunk/py/scripts/addons/add_mesh_gears.py
trunk/py/scripts/addons/add_mesh_gemstones.py
trunk/py/scripts/addons/add_mesh_pipe_joint.py
trunk/py/scripts/addons/add_mesh_spindle.py
trunk/py/scripts/addons/add_mesh_sqorus.py
Modified: trunk/py/scripts/addons/add_mesh_3d_function_surface.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_3d_function_surface.py 2010-05-16 09:57:01 UTC (rev 670)
+++ trunk/py/scripts/addons/add_mesh_3d_function_surface.py 2010-05-16 16:04:45 UTC (rev 671)
@@ -130,18 +130,18 @@
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 @@
# 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,10 +203,9 @@
ob_new.selected = True
# Place the object at the 3D cursor location.
- ob_new.location = scene.cursor_location
+ # apply viewRotaion
+ ob_new.matrix = align_matrix
- apply_object_align(context, ob_new)
-
if obj_act and obj_act.mode == 'EDIT':
if not edit:
# We are in EditMode, switch to ObjectMode.
@@ -342,6 +341,7 @@
min=0.01,
max=100.0,
unit="LENGTH")
+ align_matrix = Matrix()
def execute(self, context):
edit = self.properties.edit
@@ -401,7 +401,7 @@
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 @@
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 @@
description="V Wrap around",
default=False)
+ align_matrix = Matrix()
+
def execute(self, context):
props = self.properties
@@ -610,7 +616,7 @@
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,7 +636,12 @@
return {'FINISHED'}
+ def invoke(self, context, event):
+ self.align_matrix = align_matrix(context)
+ self.execute(context)
+ return {'FINISHED'}
+
################################
import space_info
Modified: trunk/py/scripts/addons/add_mesh_archimedean_solids.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_archimedean_solids.py 2010-05-16 09:57:01 UTC (rev 670)
+++ trunk/py/scripts/addons/add_mesh_archimedean_solids.py 2010-05-16 16:04:45 UTC (rev 671)
@@ -54,18 +54,18 @@
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 @@
# 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,10 +127,9 @@
ob_new.selected = True
# Place the object at the 3D cursor location.
- ob_new.location = scene.cursor_location
+ # apply viewRotaion
+ ob_new.matrix = align_matrix
- apply_object_align(context, ob_new)
-
if obj_act and obj_act.mode == 'EDIT':
if not edit:
# We are in EditMode, switch to ObjectMode.
@@ -1179,6 +1178,7 @@
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 @@
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,7 +1202,12 @@
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).'''
bl_idname = 'mesh.primitive_cuboctahedron_add'
@@ -1225,6 +1230,7 @@
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 @@
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,7 +1253,12 @@
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.'''
bl_idname = 'mesh.primitive_rhombicuboctahedron_add'
@@ -1265,6 +1276,7 @@
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 @@
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,7 +1297,12 @@
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.'''
bl_idname = 'mesh.primitive_truncated_octahedron_add'
@@ -1307,6 +1324,7 @@
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 @@
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,7 +1348,12 @@
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.'''
bl_idname = 'mesh.primitive_truncated_cuboctahedron_add'
@@ -1357,6 +1380,7 @@
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 @@
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,7 +1406,12 @@
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
bl_idname = "INFO_MT_mesh_archimedean_solids_add"
Modified: trunk/py/scripts/addons/add_mesh_gears.py
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list