diff --git a/add_curve_torus_knots.py b/add_curve_torus_knots.py index bba2afd049f9b6d98a62c5de90e87ce28c2d529c..d4ea3914d4482dcae219f44ca969b40d55b872d1 100644 --- a/add_curve_torus_knots.py +++ b/add_curve_torus_knots.py @@ -37,7 +37,7 @@ bl_info = { import bpy from bpy.props import * from math import sin, cos, pi -from add_utils import * +from bpy_extras.object_utils import AddObjectHelper, object_data_add ######################################################################## @@ -93,7 +93,7 @@ def create_torus_knot(self, context): #curve_data.offset = self.geo_width # removed, somehow screws things up all of a sudden curve_data.resolution_u = self.geo_res - new_obj = add_object_data(context, curve_data, operator=self) + new_obj = object_data_add(context, curve_data, operator=self) class torus_knot_plus(bpy.types.Operator, AddObjectHelper): diff --git a/add_mesh_extra_objects/add_mesh_pyramid.py b/add_mesh_extra_objects/add_mesh_pyramid.py index 69a530f42fe7c2537745017b8d6bcf7b556a758d..11875778ced98304fe052be9fad3996f007df4b0 100644 --- a/add_mesh_extra_objects/add_mesh_pyramid.py +++ b/add_mesh_extra_objects/add_mesh_pyramid.py @@ -32,8 +32,7 @@ bl_info = { import bpy from bpy.props import IntProperty, FloatProperty - -from add_utils import AddObjectHelper, add_object_data +from bpy_extras.object_utils import AddObjectHelper, object_data_add def makePyramid(initial_size, step_height, step_width, number_steps): @@ -105,7 +104,7 @@ def add_pyramid_object(self, context): mesh_data = bpy.data.meshes.new(name="Pyramid") mesh_data.from_pydata(verts, [], faces) mesh_data.update() - res = add_object_data(context, mesh_data, operator=self) + res = object_data_add(context, mesh_data, operator=self) class AddPyramid(bpy.types.Operator, AddObjectHelper): diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py index 10549a025162cc753a83438190c61720c997cee3..f69bc37861c7e7688aee23aaec1f4ee10c628d4e 100644 --- a/io_import_images_as_planes.py +++ b/io_import_images_as_planes.py @@ -42,7 +42,7 @@ from bpy.props import (BoolProperty, FloatProperty, ) -from add_utils import AddObjectHelper, add_object_data +from bpy_extras.object_utils import AddObjectHelper, object_data_add from bpy_extras.io_utils import ImportHelper from bpy_extras.image_utils import load_image @@ -174,7 +174,7 @@ def create_image_plane(self, context, material): mesh_data = bpy.data.meshes.new(img.name) mesh_data.from_pydata(verts, [], faces) mesh_data.update() - add_object_data(context, mesh_data, operator=self) + object_data_add(context, mesh_data, operator=self) plane = context.scene.objects.active plane.data.uv_textures.new() plane.data.materials.append(material) diff --git a/modules/add_utils.py b/modules/add_utils.py deleted file mode 100644 index 39aed56d1c17500ca1baab22f2b890da4801aab8..0000000000000000000000000000000000000000 --- a/modules/add_utils.py +++ /dev/null @@ -1,137 +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 ##### -######################################################## -# -# Before changing this file please discuss with admins. -# -######################################################## -# <pep8 compliant> - -import bpy -import mathutils -from bpy.props import FloatVectorProperty - - -class AddObjectHelper: - '''Helper Class for Add Object Operators''' - location = FloatVectorProperty(name='Location', description='Location of new Object') - rotation = FloatVectorProperty(name='Rotation', description='Rotation of new Object') - - -#Initialize loc, rot of operator -def add_object_align_init(context, operator): - '''Initialize loc, rot of operator - context: Blender Context - operator: the active Operator (self) - Initializes the Operators location and rotation variables - according to user preferences (align to view) - See AddObjectHelper class - Returns Matrix - ''' - if (operator - and operator.properties.is_property_set("location") - and operator.properties.is_property_set("rotation")): - location = mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location)) - rotation = mathutils.Euler(operator.properties.rotation).to_matrix().to_4x4() - else: - # TODO, local view cursor! - location = mathutils.Matrix.Translation(context.scene.cursor_location) - - if context.user_preferences.edit.object_align == 'VIEW' and context.space_data.type == 'VIEW_3D': - rotation = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4() - else: - rotation = mathutils.Matrix() - - # set the operator properties - if operator: - operator.properties.location = location.to_translation() - operator.properties.rotation = rotation.to_euler() - - return location * rotation - - -def add_object_data(context, obdata, operator=None): - '''Create Object from data - - context: Blender Context - obdata: Object data (mesh, curve, camera,...) - operator: the active operator (self) - - Returns the Object - ''' - - scene = context.scene - - # ugh, could be made nicer - for ob in scene.objects: - ob.select = False - - obj_new = bpy.data.objects.new(obdata.name, obdata) - obj_new.update_tag() - - base = scene.objects.link(obj_new) - base.select = True - - if context.space_data and context.space_data.type == 'VIEW_3D': - base.layers_from_view(context.space_data) - - obj_new.matrix_world = add_object_align_init(context, operator) - - obj_act = scene.objects.active - - if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type: - bpy.ops.object.mode_set(mode='OBJECT') - - obj_act.select = True - scene.update() # apply location - #scene.objects.active = obj_new - - bpy.ops.object.join() # join into the active. - - bpy.ops.object.mode_set(mode='EDIT') - else: - scene.objects.active = obj_new - if context.user_preferences.edit.use_enter_edit_mode: - bpy.ops.object.mode_set(mode='EDIT') - - return base - - -def flatten_vector_list(ls): - '''flatten a list of vetcors to use in foreach_set and the like''' - if not ls: - return None - - return [i for v in ls for i in v] - - -def list_to_vector_list(list, dimension=3): - '''make Vector objects out of a list''' - #test if list contains right number of elements - - result = [] - for i in range(0, len(list), dimension): - try: - vec = mathutils.Vector([list[i + ind] for ind in range(dimension)]) - except: - print('Number of elemnts doesnt match into the vectors.') - return None - - result.append(vec) - - return result