1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
21
###############################################################################
22
#234567890123456789012345678901234567890123456789012345678901234567890123456789
23
#--------1---------2---------3---------4---------5---------6---------7---------
26
# ##### BEGIN COPYRIGHT BLOCK #####
28
# initial script copyright (c)2011-2013 Alexander Nussbaumer
30
# ##### END COPYRIGHT BLOCK #####
39
# import io_scene_ms3d stuff
40
from io_scene_ms3d.ms3d_strings import (
51
###############################################################################
52
def enable_edit_mode(enable, blender_context):
53
if blender_context.active_object is None \
54
or not blender_context.active_object.type in {'MESH', 'ARMATURE', }:
62
if ops.object.mode_set.poll():
63
ops.object.mode_set(mode=modeString)
66
###############################################################################
67
def enable_pose_mode(enable, blender_context):
68
if blender_context.active_object is None \
69
or not blender_context.active_object.type in {'ARMATURE', }:
77
if ops.object.mode_set.poll():
78
ops.object.mode_set(mode=modeString)
81
###############################################################################
82
def select_all(select):
84
actionString = 'SELECT'
86
actionString = 'DESELECT'
88
if ops.object.select_all.poll():
89
ops.object.select_all(action=actionString)
91
if ops.mesh.select_all.poll():
92
ops.mesh.select_all(action=actionString)
94
if ops.pose.select_all.poll():
95
ops.pose.select_all(action=actionString)
98
###############################################################################
99
def pre_setup_environment(porter, blender_context):
100
# inject undo to porter
102
porter.undo = blender_context.user_preferences.edit.use_global_undo
103
blender_context.user_preferences.edit.use_global_undo = False
105
# inject active_object to self
106
porter.active_object = blender_context.scene.objects.active
108
# change to a well defined mode
109
enable_edit_mode(True, blender_context)
111
# enable face-selection-mode
112
blender_context.tool_settings.mesh_select_mode = (False, False, True)
114
# change back to object mode
115
enable_edit_mode(False, blender_context)
117
blender_context.scene.update()
120
###############################################################################
121
def post_setup_environment(porter, blender_context):
122
# restore active object
123
blender_context.scene.objects.active = porter.active_object
125
if not blender_context.scene.objects.active \
126
and blender_context.selected_objects:
127
blender_context.scene.objects.active \
128
= blender_context.selected_objects[0]
130
# restore pre operator undo state
131
blender_context.user_preferences.edit.use_global_undo = porter.undo
134
###############################################################################
135
def get_edge_split_modifier_add_if(blender_mesh_object):
136
blender_modifier = blender_mesh_object.modifiers.get(
137
ms3d_str['OBJECT_MODIFIER_SMOOTHING_GROUP'])
139
if blender_modifier is None:
140
blender_modifier = blender_mesh_object.modifiers.new(
141
ms3d_str['OBJECT_MODIFIER_SMOOTHING_GROUP'],
143
blender_modifier.show_expanded = False
144
blender_modifier.use_edge_angle = False
145
blender_modifier.use_edge_sharp = True
147
blender_mesh_object.data.show_edge_seams = True
148
blender_mesh_object.data.show_edge_sharp = True
150
return blender_modifier
153
###########################################################################
154
def rotation_matrix(v_track, v_up):
155
## rotation matrix from two vectors
156
## http://gamedev.stackexchange.com/questions/20097/how-to-calculate-a-3x3-rotation-matrix-from-2-direction-vectors
157
## http://www.fastgraph.com/makegames/3drotation/
158
matrix = Matrix().to_3x3()
176
###############################################################################
177
def matrix_difference(mat_src, mat_dst):
178
mat_dst_inv = mat_dst.inverted()
179
return mat_dst_inv * mat_src
182
###############################################################################
183
def set_sence_to_metric(blender_context):
186
blender_context.scene.unit_settings.system = 'METRIC'
187
blender_context.scene.unit_settings.system_rotation = 'DEGREES'
188
blender_context.scene.unit_settings.scale_length = 0.001 # 1.0mm
189
blender_context.scene.unit_settings.use_separate = False
190
blender_context.tool_settings.normal_size = 1.0 # 1.0mm
192
# set all 3D views to texture shaded
193
# and set up the clipping
194
for screen in blender_context.blend_data.screens:
195
for area in screen.areas:
196
if (area.type != 'VIEW_3D'):
199
for space in area.spaces:
200
if (space.type != 'VIEW_3D'):
203
#space.viewport_shade = 'SOLID'
204
space.show_textured_solid = True
205
space.clip_start = 0.1 # 0.1mm
206
space.clip_end = 1000000.0 # 1km
207
#screen.scene.game_settings.material_mode = 'MULTITEXTURE'
216
###############################################################################
218
###############################################################################
219
#234567890123456789012345678901234567890123456789012345678901234567890123456789
220
#--------1---------2---------3---------4---------5---------6---------7---------
221
# ##### END OF FILE #####