2010-05-23 12:14:07 +00:00
|
|
|
# ##### 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 #####
|
|
|
|
|
|
|
|
# <pep8 compliant>
|
|
|
|
|
|
|
|
import bpy
|
2010-05-23 12:38:49 +00:00
|
|
|
import mathutils
|
|
|
|
|
2010-06-09 19:12:03 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
def add_object_align_init(context, operator):
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
if operator and operator.properties.is_property_set("location") and operator.properties.is_property_set("rotation"):
|
2010-08-11 16:40:36 +00:00
|
|
|
location = mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location))
|
2010-05-30 17:18:16 +00:00
|
|
|
rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4()
|
2010-05-23 12:38:49 +00:00
|
|
|
else:
|
2010-05-30 17:18:16 +00:00
|
|
|
# TODO, local view cursor!
|
2010-08-11 16:40:36 +00:00
|
|
|
location = mathutils.Matrix.Translation(context.scene.cursor_location)
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
if context.user_preferences.edit.object_align == 'VIEW' and context.space_data.type == 'VIEW_3D':
|
|
|
|
rotation = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
|
|
|
|
else:
|
|
|
|
rotation = mathutils.Matrix()
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
# set the operator properties
|
|
|
|
if operator:
|
|
|
|
operator.properties.location = location.translation_part()
|
|
|
|
operator.properties.rotation = rotation.to_euler()
|
2010-05-23 12:38:49 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
return location * rotation
|
2010-05-23 12:14:07 +00:00
|
|
|
|
2010-05-30 17:18:16 +00:00
|
|
|
|
|
|
|
def add_object_data(context, obdata, operator=None):
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
scene = context.scene
|
|
|
|
|
|
|
|
# ugh, could be made nicer
|
|
|
|
for ob in scene.objects:
|
2010-07-15 16:56:04 +00:00
|
|
|
ob.select = False
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
obj_new = bpy.data.objects.new(obdata.name, obdata)
|
|
|
|
|
|
|
|
base = scene.objects.link(obj_new)
|
2010-07-15 16:56:04 +00:00
|
|
|
base.select = True
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
if context.space_data and context.space_data.type == 'VIEW_3D':
|
|
|
|
base.layers_from_view(context.space_data)
|
|
|
|
|
2010-07-03 17:39:29 +00:00
|
|
|
obj_new.matrix_world = add_object_align_init(context, operator)
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2010-07-15 16:56:04 +00:00
|
|
|
obj_act.select = True
|
2010-09-07 15:17:42 +00:00
|
|
|
scene.update() # apply location
|
2010-05-23 12:14:07 +00:00
|
|
|
#scene.objects.active = obj_new
|
|
|
|
|
2010-09-07 15:17:42 +00:00
|
|
|
bpy.ops.object.join() # join into the active.
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
|
|
|
else:
|
|
|
|
scene.objects.active = obj_new
|
2010-08-17 13:14:41 +00:00
|
|
|
if context.user_preferences.edit.use_enter_edit_mode:
|
2010-05-23 12:14:07 +00:00
|
|
|
bpy.ops.object.mode_set(mode='EDIT')
|
2010-05-23 12:38:49 +00:00
|
|
|
|
|
|
|
return base
|