[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1507] trunk/py/scripts/addons: remove boiler plate add-object code and use python module as add_torus uses .
Campbell Barton
ideasman42 at gmail.com
Wed Jan 26 16:14:05 CET 2011
Revision: 1507
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1507
Author: campbellbarton
Date: 2011-01-26 15:14:04 +0000 (Wed, 26 Jan 2011)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/py/scripts/addons/add_mesh_ant_landscape.py
trunk/py/scripts/addons/add_mesh_extras.py
trunk/py/scripts/addons/add_mesh_gears.py
trunk/py/scripts/addons/add_mesh_gemstones.py
trunk/py/scripts/addons/add_mesh_solid.py
trunk/py/scripts/addons/add_mesh_twisted_torus.py
Modified: trunk/py/scripts/addons/add_mesh_ant_landscape.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_ant_landscape.py 2011-01-26 15:04:57 UTC (rev 1506)
+++ trunk/py/scripts/addons/add_mesh_ant_landscape.py 2011-01-26 15:14:04 UTC (rev 1507)
@@ -77,24 +77,11 @@
from math import *
-###------------------------------------------------------------
-# calculates the matrix for the new object depending on user pref
-def align_matrix(context):
- loc = 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 = 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
@@ -107,45 +94,9 @@
# Update mesh geometry after adding stuff.
mesh.update()
- # Deselect all objects.
- bpy.ops.object.select_all(action='DESELECT')
+ import add_object_utils
+ return add_object_utils.object_data_add(context, mesh, operator=None)
- # 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
-
# A very simple "bridge" tool.
# Connects two equally long vertex rows with faces.
# Returns a list of the new faces (list of lists)
@@ -489,9 +440,6 @@
bl_options = {'REGISTER', 'UNDO'}
bl_description = "Add landscape mesh"
- # align_matrix for the invoke
- align_matrix = Matrix()
-
# properties
AutoUpdate = BoolProperty(name="Mesh update",
default=True,
@@ -829,7 +777,7 @@
verts, faces = grid_gen( self.Subdivision, self.MeshSize, options )
# create mesh object
- obj = create_mesh_object(context, verts, [], faces, "Landscape", self.align_matrix)
+ obj = create_mesh_object(context, verts, [], faces, "Landscape")
# sphere, remove doubles
if self.SphereMesh !=0:
@@ -848,10 +796,6 @@
else:
return {'PASS_THROUGH'}
- def invoke(self, context, event):
- self.align_matrix = align_matrix(context)
- self.execute(context)
- return {'FINISHED'}
###------------------------------------------------------------
# Register
Modified: trunk/py/scripts/addons/add_mesh_extras.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_extras.py 2011-01-26 15:04:57 UTC (rev 1506)
+++ trunk/py/scripts/addons/add_mesh_extras.py 2011-01-26 15:14:04 UTC (rev 1507)
@@ -36,24 +36,11 @@
from math import *
from bpy.props import *
-# calculates the matrix for the new object
-# depending on user pref
-def align_matrix(context):
- loc = 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 = 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
@@ -66,46 +53,10 @@
# Update mesh geometry after adding stuff.
mesh.update()
- # Deselect all objects.
- bpy.ops.object.select_all(action='DESELECT')
+ import add_object_utils
+ return add_object_utils.object_data_add(context, mesh, operator=None)
- # 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
-
-
# A very simple "bridge" tool.
# Connects two equally long vertex rows with faces.
# Returns a list of the new faces (list of lists)
@@ -437,7 +388,6 @@
description="Enable to subdivide the faces on the outside." \
" This results in equally spaced vertices.",
default=True)
- align_matrix = Matrix()
def execute(self, context):
@@ -447,15 +397,10 @@
self.subdivide)
# Create mesh object (and meshdata)
- obj = create_mesh_object(context, verts, [], faces, "Sqorus",
- self.align_matrix)
+ obj = create_mesh_object(context, verts, [], faces, "Sqorus")
return {'FINISHED'}
- def invoke(self, context, event):
- self.align_matrix = align_matrix(context)
- self.execute(context)
- return {'FINISHED'}
class AddWedge(bpy.types.Operator):
'''Add a wedge mesh.'''
@@ -478,7 +423,6 @@
min=0.01,
max=9999.0,
default=2.00)
- align_matrix = Matrix()
def execute(self, context):
@@ -487,17 +431,11 @@
self.size_y,
self.size_z)
- obj = create_mesh_object(context, verts, [], faces, "Wedge",
- self.align_matrix)
+ obj = create_mesh_object(context, verts, [], faces, "Wedge")
return {'FINISHED'}
- def invoke(self, context, event):
- self.align_matrix = align_matrix(context)
- self.execute(context)
- return {'FINISHED'}
-
class AddStar(bpy.types.Operator):
'''Add a star mesh.'''
bl_idname = "mesh.primitive_star_add"
@@ -524,7 +462,6 @@
min=0.01,
max=9999.0,
default=0.5)
- align_matrix = Matrix()
def execute(self, context):
@@ -534,17 +471,11 @@
self.innter_radius,
self.height)
- obj = create_mesh_object(context, verts, [], faces, "Star",
- self.align_matrix)
+ obj = create_mesh_object(context, verts, [], faces, "Star")
return {'FINISHED'}
- def invoke(self, context, event):
- self.align_matrix = align_matrix(context)
- self.execute(context)
- return {'FINISHED'}
-
class AddTrapezohedron(bpy.types.Operator):
"""Add a trapezohedron"""
bl_idname = "mesh.primitive_trapezohedron_add"
@@ -561,15 +492,14 @@
height = FloatProperty(name = "Tip height",
description = "Height of the tip",
default = 1, min = 0.01, max = 100.0)
- align_matrix = Matrix()
+
def execute(self,context):
# generate mesh
verts,faces = trapezohedron(self.segments,
self.radius,
self.height)
- obj = create_mesh_object(context, verts, [], faces, "Trapazohedron",
- self.align_matrix)
+ obj = create_mesh_object(context, verts, [], faces, "Trapazohedron")
return {'FINISHED'}
Modified: trunk/py/scripts/addons/add_mesh_gears.py
===================================================================
--- trunk/py/scripts/addons/add_mesh_gears.py 2011-01-26 15:04:57 UTC (rev 1506)
+++ trunk/py/scripts/addons/add_mesh_gears.py 2011-01-26 15:14:04 UTC (rev 1507)
@@ -69,24 +69,11 @@
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,47 +86,10 @@
# Update mesh geometry after adding stuff.
mesh.update()
- # Deselect all objects.
- bpy.ops.object.select_all(action='DESELECT')
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list