Continuing my foray into the world of motion capture, I’ve been building up my own collection of mocap data files from various sources I find on the ‘net, with the hope of ultimately using them to animate a Mecanim rig in Unity. While I don’t think Mixamo will be worried quite yet(!), I have gathered enough BVH files such that loading them up individually into Blender and saving them to FBX necessary for import in Unity has become quite a chore.
So, I wrote a python script to automate the process, convert_fbx.py, as follows:
import bpy import sys #Get command line arguments argv = sys.argv argv = argv[argv.index("--") + 1:] # get all args after "—" bvh_in = argv[0] fbx_out = argv[0] + ".fbx" # Import the BVH file # See http://www.blender.org/documentation/blender_python_api_2_60_0/bpy.ops.import_anim.html bpy.ops.import_anim.bvh(filepath=bvh_in, filter_glob="*.bvh", global_scale=1, frame_start=1, use_fps_scale=False, use_cyclic=False, rotate_mode='NATIVE', axis_forward='-Z', axis_up='Y') # Export as FBX # See http://www.blender.org/documentation/blender_python_api_2_62_1/bpy.ops.export_scene.html bpy.ops.export_scene.fbx(filepath=fbx_out, axis_forward='-Z', axis_up='Y', use_anim=True, use_selection=True, use_default_take=False)
Then, create a batch file, bvh2fbx.bat, that loops through all BVH files in a directory and calls Blender from the command line with the script above, passing in the details of files to be converted:
FOR %%f IN (*.bvh) DO "c:\program files (x86)\blender foundation\blender\blender.exe" -b --python "c:\temp\convert_fbx.py" -- "%%f"
(Alter the path to the Blender executable and to where you saved the convert_fbx.py script as appropriate). Run the bvh2fbx.bat file from the commandline and you should get all BVH files in the directory automatically converted to FBX.
All that remains is to import them to Unity and add a Humanoid rig and they’re ready to use in an Animator!
Hi there.
Many thanks for sharing your experience with migrating the animation files.
Wondering you’ve had success with this approach and if you could kindly share your converted animation files that can be used with Mecanim.
Would greatly appreciate it.
Thanks,
-Anil
Yes, it works great (depending on the quality of the BVH file with which you started, obviously). I can’t post the converted animation files because they’re not licensed for me to redistribute, but there’s plenty of free and commerical BVH files on the net
wow.. its great…If you say I can make User Interface for this software.
Hi!
You may also be interested in Blend4Web which is designed as the primary tool for the browser game development in Blender.
http://www.blend4web.com
I get an error when using your script, does it matter what version of Blender you are using?
found bundled python: C:\Program Files\Blender Foundation\Blender\2.72\python
Traceback (most recent call last):
File “”, line 1, in
File “”, line 2
Type “copyright”, “credits” or “license()” for more information.
^
SyntaxError: invalid syntax
Blender quit
Nevermind, I got it to work.
Thanks for the script!
bsides
Hi, I’m using your py script and batch file to convert from bvh to fbx and I keep getting error: Object has no duplis. Any idea how to solve this?
Pingback: Motion to Motion | Caffeine & Code
Hello thanks for sharing this is very helpful!
Also I got some questions. How can I get the bvh files from its directory and run the bat file? Thank you for your help.