Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit)

Yes you can! If the imported model has exactly the same skeleton structure and joint rotation as the BVH it should work just fine.

In BVH all joints are always Quaternion.identity in the resting pose, in other words, not rotated. If the model imported by Unity has a skeleton with rotated joints the animation will appear incorrect since BVH base all rotations in the AnimationClip from Quaternion.identity. I tried to make a method that adapted a BVH to an already existing skeleton but it was tricky to make it work without some rotations being flipped the wrong way so I couldn't include it in the final version of the product.

I'm currently working on a different product that skins a mesh from a skeleton during runtime, it'll ensure that the joints have the correct rotation. I'm making good progress but I don't know when it's finished. I recommend that you download the demo of BvhImporterExporter and see if you can achieve what you need. The most important thing is that the model's mesh was skinned to the skeleton when the joints wasn't rotated, then the AnimationClip created from BVH will move the skeleton correctly!

Check your model in Unity (make sure it's in its rest pose - you can uncheck "import animation" for the model in the inspector). If all the GameObjects that make up the skeleton have Transform rotation [0,0,0] you're good to go! Assuming that the skeleton has the same structure as the BVH of course (matching bone names).

I saw in your demo that I can create an animation clip out of BVH file. So my questions are: 1) Is there any way that I can store it into unity assets? 2) Can I apply the clip to my animation controller? If yes, how?

1) There might be a way but right now I haven't implemented such a feature. I can see how it would be useful though and will be looking into it if I make an update! It's likely it will be an editor-only feature though and not not available in the demo.

2) Using the Mecanim system is possible but not simple. You have to create an Animator Controller in Unity and set it up with dummy animations, which means no previews (make blank states, set their motion to any AnimationClip you've got in your project). You also prepare an Animator Override Controller (AOC). Then during runtime you replace the original dummy clips in the AOC with the real ones created using BvhImporterExporter ("bvh.makeAnimationClip(pathToSkeletonGO:"MySkeletonGOName", legacy:false);"). Finally you instruct the Animator to use the override ("myAnimator.runtimeAnimatorController = AOC;").

Sticking with legacy might be just as simple or even simpler unless you intend to do some advanced stuff. The legacy Animation system is not deprecated even though Mecanim has been around since 2012 when Unity 4.0 was released. After trying to work with Mecanim from code I understand why, the Animation system has better access from code so Mecanim isn't a replacement (yet at least). I haven't for example found a way to create an Animator Controller from scratch via code during runtime, it seems to be an impossible task outside the editor.