From c7ea0d513887d81ea895b6e838e6f5867c9ab3b0 Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Wed, 3 Aug 2022 14:38:33 -0700 Subject: [PATCH 1/6] Updated Readme with archive to replace broken link, changed date format for legibility --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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). From a4d0a7f67182ab764158a37e3f1cc9c89c03a576 Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Wed, 3 Aug 2022 15:25:42 -0700 Subject: [PATCH 2/6] Comment header changed to show working url and more legible date format --- blendToFbxExporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blendToFbxExporter.py b/blendToFbxExporter.py index b17f807..cbb07d4 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. # From a8b6c530c74abc17035f063743ff5f9e104c8a77 Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Wed, 3 Aug 2022 15:36:25 -0700 Subject: [PATCH 3/6] switched to export_fbx_bin for modern blender command --- args-Unity-BlenderToFBX.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/args-Unity-BlenderToFBX.py b/args-Unity-BlenderToFBX.py index b76fffd..e314b01 100644 --- a/args-Unity-BlenderToFBX.py +++ b/args-Unity-BlenderToFBX.py @@ -7,14 +7,14 @@ import bpy if blender249: - try: import export_fbx + try: import export_fbx_bin except: - print('error: export_fbx not found.') + print('error: export_fbx_bin not found.') Blender.Quit() else: - try: import io_scene_fbx.export_fbx + try: import io_scene_fbx.export_fbx_bin except: - print('error: io_scene_fbx.export_fbx not found.') + print('error: io_scene_fbx.export_fbx_bin not found.') # This might need to be bpy.Quit() raise @@ -29,7 +29,7 @@ if blender249: mtx4_x90n = Blender.Mathutils.RotationMatrix(-90, 4, 'x') - export_fbx.write(outfile, + export_fbx_bin.write(outfile, EXP_OBS_SELECTED=False, EXP_MESH=True, EXP_MESH_APPLY_MOD=True, @@ -61,7 +61,7 @@ def report(self, tp, msg): minorVersion = bpy.app.version[1]; if minorVersion <= 58: # 2.58 - io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, + io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, global_matrix=mtx4_x90n, use_selection=False, object_types=exportObjects, @@ -74,8 +74,8 @@ def report(self, tp, msg): BATCH_OWN_DIR=False) else: # 2.59 and later - kwargs = io_scene_fbx.export_fbx.defaults_unity3d() - io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, **kwargs) + kwargs = io_scene_fbx.export_fbx_bin.defaults_unity3d() + io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, **kwargs) # HQ normals are not supported in the current exporter print("Finished blender to FBX conversion " + outfile) From 71186ba9ae7293d551c334216b1360165757edaa Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Wed, 3 Aug 2022 17:33:56 -0700 Subject: [PATCH 4/6] Check for Python version more accurately, since minor version reset with Python 3 --- args-Unity-BlenderToFBX.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/args-Unity-BlenderToFBX.py b/args-Unity-BlenderToFBX.py index e314b01..57a00e9 100644 --- a/args-Unity-BlenderToFBX.py +++ b/args-Unity-BlenderToFBX.py @@ -58,9 +58,15 @@ def report(self, tp, msg): exportObjects = ['ARMATURE', 'EMPTY', 'MESH'] + # Identify and display the python version + majorVersion = bpy.app.version[0]; minorVersion = bpy.app.version[1]; - if minorVersion <= 58: + pyVer = ".".join(str(i) for i in bpy.app.version); + print("Python version: " + pyVer); + + if majorVersion <= 2 and minorVersion <= 58: # 2.58 + print("<= v2.58") io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, global_matrix=mtx4_x90n, use_selection=False, @@ -74,6 +80,7 @@ def report(self, tp, msg): BATCH_OWN_DIR=False) else: # 2.59 and later + print(">= v2.59") kwargs = io_scene_fbx.export_fbx_bin.defaults_unity3d() io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, **kwargs) # HQ normals are not supported in the current exporter From 677fd1402c477296f55d2be04af31564ab14b100 Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Fri, 5 Aug 2022 15:38:05 -0700 Subject: [PATCH 5/6] Converted to forestrf Custom-Blender-Unity-Import-Settings code, added MIT license in accordance with adding that code --- LICENSE.txt | 21 ++++++++++ args-Unity-BlenderToFBX.py | 84 ++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 LICENSE.txt 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/args-Unity-BlenderToFBX.py b/args-Unity-BlenderToFBX.py index 57a00e9..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_bin - except: - print('error: export_fbx_bin not found.') - Blender.Quit() -else: - try: import io_scene_fbx.export_fbx_bin - except: - print('error: io_scene_fbx.export_fbx_bin 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,9 +32,22 @@ # 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_bin.write(outfile, + export_fbx.write(outfile, EXP_OBS_SELECTED=False, EXP_MESH=True, EXP_MESH_APPLY_MOD=True, @@ -50,24 +68,16 @@ # -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'] - - # Identify and display the python version - majorVersion = bpy.app.version[0]; - minorVersion = bpy.app.version[1]; - pyVer = ".".join(str(i) for i in bpy.app.version); - print("Python version: " + pyVer); - - if majorVersion <= 2 and minorVersion <= 58: + + minorVersion = bpy.app.version[1]; + if minorVersion <= 58: # 2.58 - print("<= v2.58") - io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, + io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, global_matrix=mtx4_x90n, use_selection=False, object_types=exportObjects, @@ -80,9 +90,23 @@ def report(self, tp, msg): BATCH_OWN_DIR=False) else: # 2.59 and later - print(">= v2.59") - kwargs = io_scene_fbx.export_fbx_bin.defaults_unity3d() - io_scene_fbx.export_fbx_bin.save(FakeOp(), bpy.context, filepath=outfile, **kwargs) + 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 print("Finished blender to FBX conversion " + outfile) From b4fdc635bb8497e47494c7d737efb1b59c8082cb Mon Sep 17 00:00:00 2001 From: Brian Handy Date: Wed, 10 Aug 2022 16:41:17 -0700 Subject: [PATCH 6/6] Fix for error from spaces in paths --- blendToFbxExporter.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blendToFbxExporter.py b/blendToFbxExporter.py index cbb07d4..aadb2c2 100644 --- a/blendToFbxExporter.py +++ b/blendToFbxExporter.py @@ -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,