diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..aacc0db --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Andrés Leone Gámez + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 686f160..b0a6a6b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # blendToFbxExporterForUnity -Created by Krzysztof Żarczyński (@iamsed) on 16.11.15. -http://blog.kzarczynski.com/2015/11/wanted-to-use-unity-cloud-build-but-all-my-blender-models-disappeared-solution/ +Created by Krzysztof Żarczyński (@iamsed) on Nov 16, 2015. (Archived April 8, 2016) +https://web.archive.org/web/20160804175703/http://kzarczynski.com/2015/11/wanted-to-use-unity-cloud-build-but-all-my-blender-models-disappeared-solution The script exports multiple files from Blender into fbx models. It searches the path recursively and creates .fbx files next to the .blend files, then it renames corresponding Unity *.blend.meta files to *.fbx.meta to keep editor references, then it deletes the .blend files (make your own backup somewhere outside of the project path). diff --git a/args-Unity-BlenderToFBX.py b/args-Unity-BlenderToFBX.py index b76fffd..167600e 100644 --- a/args-Unity-BlenderToFBX.py +++ b/args-Unity-BlenderToFBX.py @@ -1,22 +1,27 @@ +import bpy blender249 = True +blender280 = (2,80,0) <= bpy.app.version import sys -try: import Blender +try: + import Blender except: blender249 = False - import bpy -if blender249: - try: import export_fbx - except: - print('error: export_fbx not found.') - Blender.Quit() -else: - try: import io_scene_fbx.export_fbx - except: - print('error: io_scene_fbx.export_fbx not found.') - # This might need to be bpy.Quit() - raise +if not blender280: + if blender249: + try: + import export_fbx + except: + print('error: export_fbx not found.') + Blender.Quit() + else : + try: + import io_scene_fbx.export_fbx + except: + print('error: io_scene_fbx.export_fbx not found.') + # This might need to be bpy.Quit() + raise # Accept command line arguments and load the contents of the .blend file infile = sys.argv[5] @@ -27,7 +32,20 @@ # Do the conversion print("Starting blender to FBX conversion " + outfile) -if blender249: +if blender280: + import bpy.ops + bpy.ops.export_scene.fbx(filepath=outfile, + check_existing=False, + use_selection=False, + use_active_collection=False, + object_types= {'ARMATURE','CAMERA','LIGHT','MESH','OTHER','EMPTY'}, + use_mesh_modifiers=True, + mesh_smooth_type='OFF', + use_custom_props=True, + bake_anim_use_nla_strips=False, + bake_anim_use_all_actions=False, + apply_scale_options='FBX_SCALE_ALL') +elif blender249: mtx4_x90n = Blender.Mathutils.RotationMatrix(-90, 4, 'x') export_fbx.write(outfile, EXP_OBS_SELECTED=False, @@ -50,15 +68,13 @@ # -90 degrees mtx4_x90n = Matrix.Rotation(-math.pi / 2.0, 4, 'X') - print("moo") - class FakeOp: def report(self, tp, msg): print("%s: %s" % (tp, msg)) exportObjects = ['ARMATURE', 'EMPTY', 'MESH'] - - minorVersion = bpy.app.version[1]; + + minorVersion = bpy.app.version[1]; if minorVersion <= 58: # 2.58 io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, @@ -74,7 +90,22 @@ def report(self, tp, msg): BATCH_OWN_DIR=False) else: # 2.59 and later - kwargs = io_scene_fbx.export_fbx.defaults_unity3d() + kwargs = dict( + global_matrix=Matrix.Rotation(-math.pi / 2.0, 4, 'X'), + use_selection=False, + #object_types={'ARMATURE', 'EMPTY', 'MESH'}, + object_types={'EMPTY', 'CAMERA', 'LAMP', 'ARMATURE', 'MESH'}, + #mesh_smooth_type='FACE', + mesh_smooth_type='OFF', + use_mesh_modifiers=True, + use_armature_deform_only=False, + use_anim=True, + use_anim_optimize=False, + use_anim_action_all=True, + use_mesh_edges=False, + batch_mode='OFF', + use_default_take=True, + ) io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, **kwargs) # HQ normals are not supported in the current exporter diff --git a/blendToFbxExporter.py b/blendToFbxExporter.py index b17f807..aadb2c2 100644 --- a/blendToFbxExporter.py +++ b/blendToFbxExporter.py @@ -1,8 +1,8 @@ # # blendToFbxExporter.py # -# Created by Krzysztof Żarczyński (@iamsed) on 16.11.15. -# http://blog.kzarczynski.com/ +# Created by Krzysztof Żarczyński (@iamsed) on Nov 16, 2015. (Archived April 8, 2016) +# https://web.archive.org/web/20160804175703/http://kzarczynski.com/2015/11/wanted-to-use-unity-cloud-build-but-all-my-blender-models-disappeared-solution # Copyright (c) 2015 Krzysztof Żarczyński. All rights reserved. # @@ -40,7 +40,8 @@ if os.path.isfile(outfilename): alreadyHaveFBX.append(infile) else: - proc = ("{pathToBlender} --background --python {pathToBlenderToFBX} -- {infile} {outfile}").format( + print('Running blendToFbxExporter pt5a, looking at:\n' + infile) + proc = ("\"{pathToBlender}\" --background --python {pathToBlenderToFBX} -- \"{infile}\" \"{outfile}\"").format( pathToBlender=pathToBlender, pathToBlenderToFBX=pathToBlenderToFBX, infile=infile,