diff --git a/mesh_utils.py b/mesh_utils.py deleted file mode 100644 index e03e0abade38be87e83476c6b706d30fc892d1c9..0000000000000000000000000000000000000000 --- a/mesh_utils.py +++ /dev/null @@ -1,126 +0,0 @@ -# ##### BEGIN GPL LICENSE BLOCK ##### -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -import bpy - - -# Stores the values of a list of properties in a -# property group (named like the operator) in the object. -# Could (in theory) be used for non-objects. -# Note: Replaces any existing property group with the same name! -def store_recall_properties(ob, op, prop_list): - if ob and op and prop_list: - # Store new recall properties. - prop_list['recall_op'] = op.bl_idname - ob['recall'] = prop_list - - -# 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 - - 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() - - -# Create a new mesh (object) from verts/edges/faces. -# verts/edges/faces ... List of vertices and faces for the new mesh. -# 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): - '''Creates Meshes (& Objects) for the given lists of vertices and faces.''' - - scene = context.scene - obj_act = scene.objects.active - - if edit and not obj_act: - return None - - # Create new mesh - mesh = bpy.data.meshes.new(name) - - # Make a mesh from a list of verts/edges/faces. - mesh.from_pydata(verts, edges, faces) - - # Update mesh geometry after adding stuff. - mesh.update() - - # Deselect all objects. - bpy.ops.object.select_all(action='DESELECT') - - if edit: - # Replace geometry of existing object - ob_new = obj_act - - if obj_act.mode == 'OBJECT': - # Remove existing vertices. - # @todo There is probably a better/faster way (delete(mesh)?). - bpy.ops.object.mode_set(mode='EDIT') - bpy.ops.mesh.select_all(action='SELECT') - bpy.ops.mesh.delete(type='VERT') - bpy.ops.object.mode_set(mode='OBJECT') - - ob_new.data = mesh - - ob_new.selected = True - - else: - # 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.selected = True - - # Place the object at the 3D cursor location. - ob_new.location = scene.cursor_location - - apply_object_align(context, ob_new) - - if obj_act and obj_act.mode == 'EDIT': - if not edit: - # We are in EditMode, switch to ObjectMode. - bpy.ops.object.mode_set(mode='OBJECT') - - # Select the active object as well. - obj_act.selected = 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