Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import bpy
  2. blender249 = True
  3. blender280 = (2,80,0) <= bpy.app.version
  4.  
  5. try:
  6. import Blender
  7. except:
  8. blender249 = False
  9.  
  10. if not blender280:
  11. if blender249:
  12. try:
  13. import export_fbx
  14. except:
  15. print('error: export_fbx not found.')
  16. Blender.Quit()
  17. else :
  18. try:
  19. import io_scene_fbx.export_fbx
  20. except:
  21. print('error: io_scene_fbx.export_fbx not found.')
  22. # This might need to be bpy.Quit()
  23. raise
  24.  
  25. # Find the Blender output file
  26. import os
  27. outfile = os.getenv("UNITY_BLENDER_EXPORTER_OUTPUT_FILE")
  28.  
  29. # Do the conversion
  30. print("Starting blender to FBX conversion " + outfile)
  31.  
  32. if blender280:
  33. import bpy.ops
  34. bpy.ops.export_scene.fbx(filepath=outfile,
  35. check_existing=False,
  36. use_selection=False,
  37. use_active_collection=False,
  38. object_types= {'ARMATURE','CAMERA','LIGHT','MESH','EMPTY'},
  39. use_mesh_modifiers=True,
  40. mesh_smooth_type='OFF',
  41. use_custom_props=True,
  42. apply_scale_options='FBX_SCALE_ALL')
  43. elif blender249:
  44. mtx4_x90n = Blender.Mathutils.RotationMatrix(-90, 4, 'x')
  45. export_fbx.write(outfile,
  46. EXP_OBS_SELECTED=False,
  47. EXP_MESH=True,
  48. EXP_MESH_APPLY_MOD=True,
  49. EXP_MESH_HQ_NORMALS=True,
  50. EXP_ARMATURE=True,
  51. EXP_LAMP=True,
  52. EXP_CAMERA=True,
  53. EXP_EMPTY=True,
  54. EXP_IMAGE_COPY=False,
  55. ANIM_ENABLE=True,
  56. ANIM_OPTIMIZE=False,
  57. ANIM_ACTION_ALL=True,
  58. GLOBAL_MATRIX=mtx4_x90n)
  59. else:
  60. # blender 2.58 or newer
  61. import math
  62. from mathutils import Matrix
  63. # -90 degrees
  64. mtx4_x90n = Matrix.Rotation(-math.pi / 2.0, 4, 'X')
  65.  
  66. class FakeOp:
  67. def report(self, tp, msg):
  68. print("%s: %s" % (tp, msg))
  69.  
  70. exportObjects = ['ARMATURE', 'EMPTY', 'MESH']
  71.  
  72. minorVersion = bpy.app.version[1];
  73. if minorVersion <= 58:
  74. # 2.58
  75. io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile,
  76. global_matrix=mtx4_x90n,
  77. use_selection=False,
  78. object_types=exportObjects,
  79. mesh_apply_modifiers=True,
  80. ANIM_ENABLE=True,
  81. ANIM_OPTIMIZE=False,
  82. ANIM_OPTIMIZE_PRECISSION=6,
  83. ANIM_ACTION_ALL=True,
  84. batch_mode='OFF',
  85. BATCH_OWN_DIR=False)
  86. else:
  87. # 2.59 and later
  88. kwargs = io_scene_fbx.export_fbx.defaults_unity3d()
  89. io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, **kwargs)
  90. # HQ normals are not supported in the current exporter
  91.  
  92. print("Finished blender to FBX conversion " + outfile)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement