##########################################################
# Custom Blender -> Unity Pipeline
#
http://www.mimimi-productions.com, 2012
# Version: 1.0
#
# Thanks to kastoria for his support!
#
http://www.blenderartists.org##########################################################
# Fixes the -90 degree (x-axis) problem for Unity.
# Artists and coders simply work as they should.
# -> No more custom rotation-fixes in Unity or Blender.
##########################################################
# Rotation matrix of -90 around the X-axis
rot_x_neg90 = Matrix.Rotation(-math.pi/2.0, 4, 'X')
# Iterate the objects in the file, only root level and rotate them
for obj in bpy.data.objects:
if obj.parent != None:
continue
obj.matrix_world = rot_x_neg90 * obj.matrix_world
# apply all(!) transforms
for obj in bpy.data.objects:
bpy.ops.object.transform_apply(rotation=True)
# custom args
kwargs = dict( # we dont need the rotation in the exporter anymore
#global_matrix=Matrix.Rotation(-math.pi / 2.0, 4, 'X'),
use_selection=False,
# not sure if we really need 'EMPTY' in our workflow, but we usually don't need the animation-helpers
object_types={'ARMATURE', 'MESH'},
use_mesh_modifiers=True,
use_anim=True,
use_anim_optimize=False,
use_anim_action_all=True,
batch_mode='OFF',
# never used, especially for non-animated objects
use_default_take=False,
)
# export!
io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, **kwargs)