edyj / blender-to-unity-fbx-exporter Goto Github PK
View Code? Open in Web Editor NEWFBX exporter addon for Blender compatible with Unity's coordinate and scaling system.
License: MIT License
FBX exporter addon for Blender compatible with Unity's coordinate and scaling system.
License: MIT License
Thank you very much for this addon, it really makes with importing Blender models into Unity a lot easier!
While all the individual object's positions and rotations are correct, it seems like I still need to rotate the whole model by 180° on the Y-axis in Unity to make it face in the right direction.
So I tried making a fix for it (the comments in the code should hopefully be self explanatory, although I am not 100% sure about why some of my code segments seem to be required for it to work correctly).
Maybe there is a better way, but this seems to work in all scenarios I tested (including more than one child object).
This is the code starting from line 130.
I have also attached the full file below (although as .txt, as .py files are not supported for uploading in this case):
# Reset parent's inverse so we can work with local transform directly
reset_parent_inverse(ob)
# Create a copy of the local matrix and set a X-90/Z-180 matrix
mat_original = ob.matrix_local.copy()
rot_x = mathutils.Matrix.Rotation(math.radians(-90.0), 4, 'X')
rot_z = mathutils.Matrix.Rotation(math.radians(-180.0), 4, 'Z')
ob.matrix_local = rot_x @ rot_z
# Apply the rotation to the object
apply_rotation(ob)
if (ob.parent):
# Reapply the previous local transform with an X+90 and Y+180 rotation
ob.matrix_local = mat_original @ mathutils.Matrix.Rotation(math.radians(90.0), 4, 'X') @ mathutils.Matrix.Rotation(math.radians(180.0), 4, 'Y')
else:
# Reapply the previous local transform with only an X+90 rotation
ob.matrix_local = mat_original @ mathutils.Matrix.Rotation(math.radians(90.0), 4, 'X')
# Correct position by inverting X and Y values
loc_or = ob.location
ob.location = (-loc_or.x, -loc_or.y, loc_or.z)
# Correct rotation by inverting Y value
rot_or = ob.rotation_euler
ob.rotation_euler = (rot_or.x, -rot_or.y, rot_or.z)
Hope this helps and of course please let me know if you have any suggestions or if there might be a better way!
I have a rigged character I'm trying to get published to asset store. When I export FBX the rig (I think) it is being scaled up by 100 so in Unity when character is animated, things don't go so well.
Without using this exporter, character moves correctly but rigging is -89.98 on X and scale is 100,100,100. All the body meshes have correct 1,1,1 scale.
My goal is to have it pass the "Fix Orientation" issue in the Unity Package Validator.
Blender 2.91 with Unity 2018.4, have also tried with U2019.4 (similar result)
If anyone else is having problems with how Blender exports the objects in the active scene. Specifically the nature that causes all organized objects in their collection folders to end up parented to a single game object when imported to Unity, I created a new feature for this tool to overcome that issue.
Pull Reqest
It would be great if Blender collections translated to empty object in Unity, cloning the exact same hierarchy from Blender to Unity: we would avoid reorganizing once again the objects in Unity. I don't know if such feature is possible to add, but I try to ask for it anyway.
Great job so far, keep going!
I tested this issue with default cube created blendshape and just export. Blendshape not showing in Unity.
Currently this great tool's resulting fbx bones all point 'upward' towards their proceeding bones.
It would be awesome if one could choose another orientation standard at export, such as 'forward'.
Please add scaling parameter like in basic fbx exporter D:
The animation works when using the built in fbx exporter in blender but not with the unity fbx exporter. Are there specific settings I should change in blender or Unity to fix this issue?
Thank you for this tool! It does work on generic meshes but not in objects with armatures.
Attached is a simple scene with suzanne and a bone. The rotation still has to be -90 inside unity for a correct pose.
suzanne.zip
Trying to use the cars from the Transportation add-on for Blender in Unity with the Edy's Vehicle Physics. Though, when i use this Blender-to-Unity-FBX-exporter is get the following strange behaviour, on any car i try to export to Unity.
The versions of Blender and Unity I'm using:
See screenshots for an instant understanding of the problem.
Here you see the vehicle after importing it into Unity:
Here is the vehicle from Transportation add-on in Blender, all fresh no edits made:
I've tried to follow the instructions provided in the Readme of this git, though, i can't get it working. With the rotation I noticed the Wheelcolliders from the Vehicle Physics add-on are not working on the road..
In order to be feature complete with the Unity fbx importer the exporter should include a default option to include tangent space for those features that would required it.
I've encountered an exception when trying to export the scene right after removing one of the objects.
How to reproduce:
1) Open an empty blender scene
2) In object mode add two Cube objects.
3) Remove one.
4) Try to export without selecting any object. (File > Export > Unity FBX)
Throws an exception "context is incorrect".
Screenshot - https://i.imgur.com/teWwMKt.png
I'm using Blender version 2.90.1
When I use this importer, my model is no longer being influenced by the armature in Unity. When I try to play the animations in the model import settings, nothing happens. This is not the case when I export as .fbx the normal way, or when I save as .blend. I've tried toggling some of the options in the export window but nothing has fixed this. Am I missing something or is this not currently working?
EDIT: I should add that the armature is still animating it just isn't affecting the model.
Why aren't materials also being exported with this plugin?
Hi, i think it wold be amazing if theres an option to export custom properties, they are getting lost in the way.
thanks!!
Cris
I tried two different downloads: One of only the .py file and a second of the whole .zip.
When the first did not install, I tried the second.
Edit > Pref > Addons > Install seemed to proceed normally, even with a message at the bottom saying it was loading.
I see no error message. The Addon is not in the list. Search for "fbx" only shows the default Blender FBX exporter.
Do I need to disable that one, perhaps? Can they co-exist?
Am I doing something wrong?
Hi,
it would be super cool to have a batch export feature, exporting by Collections or By Parents.
I have a problem where I am working on an VRChat avatar that I just so happened to have downloaded and worked on some customizations to it to:
Due to the above, it would be great if I could then tell the exporter "Use the original fbx file that will be overwritten on export to provide the very options that I need for the export." Also simple mesh merging should not require armature changes?
When exporting, my model had a +90 degree rotation on the X-axis, but in Unity, it was zeroed. After messing around, I found that the "Fake User" option was causing the problem. After disabling it, the rotation was fixed.
I don't know if this is intended or not, but just wanted to point it out. I also tried to reproduce it in a new file and it still happened.
I'm using Blender 3.3.1
Why dose not have texture(image) after export FBX?
When exporting a skinned mesh, only the animations of the armature itself are exported, but the weight painting and vertex groups on the mesh are lost.
I've been testing out your exporter and it's working great for me in 2.82a. Meshes, armatures and animations seem to export properly. The only problem is textures are not embedded, instead using relative paths.
I would fix this using the standard FBX exporter by setting Path Mode to Copy and the Embed Textures toggle as shown:
Of the features in the standard exporter, I use this one most often. Do you have any plans to adopt it? Thanks.
For some reason it just refuses to export the FBX
As the title suggests, if a model is exported without any armatures but with blendshape data the resulting export will have removed the blendshape data from the mesh.
Just adding a weird behavior that I noticed, tested with the same model from issue #14.
For the tail bones to appear with a custom pose in Unity, I have to export the model in Blender in a very specific way:
It seems I have to FIRST select the armature, THEN the 3D object, then export (using any export options).
That was the only way that worked, for the tail bones to be positioned correctly in Unity, with the custom curved pose.
Else (like if I selected the 3D object first, then the armature), the tail appears in a different pose, the "default pose" of the tail bones.
I don't know if that's intended, or if it's a bug with the exporter.
I'm trying to do everything according to the tutorial. This error is displayed in the console. The file is not saved.
Logs:
"Preparing 3D model for Unity...
Converting to meshes: [bpy.data.objects['Cube'], bpy.data.objects['Cube.002'], bpy.data.objects['Cylinder'], bpy.data.objects['Cylinder.001'], bpy.data.objects['Cylinder.002'], bpy.data.objects['Cube.009'], bpy.data.objects['Cube.011'], bpy.data.objects['Cube.007'], bpy.data.objects['Cylinder.004'], bpy.data.objects['Cylinder.005'], bpy.data.objects['Cylinder.006'], bpy.data.objects['Cylinder.007'], bpy.data.objects['Cylinder.008'], bpy.data.objects['Cube.008'], bpy.data.objects['Cube.010'], bpy.data.objects['Cube.012'], bpy.data.objects['Cylinder.003'], bpy.data.objects['Cylinder.009'], bpy.data.objects['Cylinder.010'], bpy.data.objects['Cube.015'], bpy.data.objects['Cube.013']]
Cube MESH
Cube.002 MESH
Cube.007 MESH
Cube.008 MESH
Cube.009 MESH
Cube.010 MESH
Cube.011 MESH
Cube.012 MESH
Cube.013 MESH
Cube.015 MESH
Cylinder MESH
Cylinder.001 MESH
Cylinder.002 MESH
Cylinder.003 MESH
Cylinder.004 MESH
Cylinder.005 MESH
Cylinder.006 MESH
Cylinder.007 MESH
Cylinder.008 MESH
Cylinder.009 MESH
Cylinder.010 MESH
Invoking default FBX Exporter: {'filepath': 'C:\Users\cptfrosty\Desktop\Fiber Optic Cleaver.fbx', 'apply_scale_options': 'FBX_SCALE_UNITS', 'object_types': {'EMPTY', 'ARMATURE', 'MESH'}, 'use_active_collection': False, 'use_selection': False, 'use_armature_deform_only': False, 'add_leaf_bones': False, 'primary_bone_axis': 'Y', 'secondary_bone_axis': 'X', 'use_tspace': True, 'use_triangles': True}
Converting py args to operator properties: : keyword "use_triangles" unrecognized
File not saved."
Hello,
I noticed that the children of an instanced collection get an unneeded 90 degrees rotation over the X-axis.
Clearing this childs rotation in unity gets me what I need.
It seems that the exported objects when placed at the scale of 100, 100, 100 explicitly on the mesh entry itself render too big in Unity after exported.
Hi,
I am trying your exporter, but it crashes with my model. At the end I get an segmentation fault.
`FBX export prepare: Wrapping Objects...
Done (0.015395 sec)
FBX export prepare: Wrapping Data (lamps, cameras, empties)...
Done (0.000637 sec)
FBX export prepare: Wrapping Meshes...
Done (0.002220 sec)
FBX export prepare: Wrapping ShapeKeys...
Done (0.000052 sec)
FBX export prepare: Wrapping Armatures...
Done (0.000227 sec)
FBX export prepare: Wrapping World...
Done (0.000081 sec)
FBX export prepare: Wrapping Materials...
Done (0.001132 sec)
FBX export prepare: Wrapping Textures...
Done (0.000772 sec)
FBX export prepare: Wrapping Animations...
Done (0.000346 sec)
FBX export prepare: Generating templates...
Done (0.000075 sec)
FBX export prepare: Generating Connections...
Done (0.005486 sec)
FBX export fetch empties (31)...
Done (0.000445 sec)
FBX export fetch lamps (0)...
Done (0.000020 sec)
FBX export fetch cameras (0)...
Done (0.000037 sec)
FBX export fetch meshes (201)...
Done (0.759288 sec)
FBX export fetch objects (326)...
Done (0.059263 sec)
FBX export fetch remaining...
Done (0.001688 sec)
FBX export fetch animations...
Done (0.000027 sec)
export finished in 0.9175 sec.
Writing: /tmp/Lider.crash.txt
Segmentation fault (core dumped)
`
This is on Blender 2.83.
The writing of the file seems to work, but after that Blender just quits.
I often forget to press Alt+S to save the current texture I'm painting. So it's very disheartening when the exporter just resets the texture to its currently saved state right after exporting.
Object in blender at rotation 0,0,0 is facing -Y with +X to it's left.
When imported to unity, object at rotation 0,0,0 is facing +Z with -X to it's left. (rotation difference of 180 degrees on the up-axis)
The object in blender has position/rotation/scale all applied so they're at 0,0,0 for pos/rot and 1,1,1 for scale
I'm not familiar with Blender but when testing this addon I noticed exporting collection that contains Empty objects results in a error:
Traceback (most recent call last):
File "C:\Program Files\Blender Foundation\Blender 2.90\2.90\scripts\modules\bpy\ops.py", line 201, in call
ret = op_call(self.idname_py(), None, kw)
RuntimeError: Operator bpy.ops.object.convert.poll() failed, context is incorrect
location: :-1
Just selecting the mesh objects and using Selected Objects Only works but the rotations are not correct. Is there a way around this or is the solution just not to use empty objects? Thanks.
Hi!
When exporting a humanoid with bones and animations into unity and ticking the "loop time" checkbox in the unity import settings the animation will not loop for me (the animation still only plays once). The loop works when I make a standard exported fbx but it does not work when I use your script nor if I use the experimental "apply transform" setting when exporting a standard fbx. Is this a known issue? I really love your script and would so like to be able to fix this issue. Please say if you need example files from me.
I tryed to install the addon as described on the front page, the console tells me it has been installed.
It got copyed indeed but i can't activate it, since its not showing up inside blender in the add-ons tab
Would be nice to have 2 options:
Remove Armature bone - removes that extra bone created by Blender on export.
That issue has been there for eternity without being addressed officially, tho there's only one addon that does that.
Bake animations - base feature of the default exporter
thanks for the exporter! I've noticed it creates and exports unnecessary "_end" bones, the equivalent of turning on "Add leaf bones" in the regular fbx exporter, could this be added as an option?
Project which causes the issue : https://gitlab.com/JoBarthel/wings
Steps to reproduce :
Actual result :
My character has a tail bone chain. In one of the bones I apply a Spline IK constraint, linked to a Bezier curve.
The character armature is exporting correctly to Unity, except for the last bones of her tail.
I'm guessing it's an issue with the Spline IK constraint applied to the bone.
Tested with Blender 2.90.1, Unity 2020.2.0b5
I attached the Blender project used in this test:
tail-splineIK-issue.zip
The character armature in Blender: (notice the tail)
The exported result in Unity: (tail bends weirdly at the end)
The bone's Spline IK constraint properties: (the last bone, the tip of the tail, isn't part of the Spline IK chain)
I've noticed that there's not prompt if you want to overwrite a file.
while usually annoying it is a necessary safety feature in my opinion.
it would be good to have because not everybody makes backups.
but it also wouldn't be the first time those prompts have been haphazardly skipped either.
also, a drop down where you can save export profiles for different scenarios like the default exporter has would be appreciated.
while the export options are limited, having a drop down saves just those few clicks.
not entirely necessary but completely awesome to have!
After clicking the Export Unity FBX button the window is closed but no file has been create, not even an empty one.
Hi,
I found some kind of bug in the sript. When I Export selected items theirs rotation is incremented by 90 degrees after the script finish. Looks like some temporary rotation problem. The rotations stack up every time You export.
Blender 2.83.2, script 1.2 and 1.2.2
Exporting a model with a broken/unassigned modifier attached will prevent any shapekeys from exporting.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.