Anim8or Community
General Category => ASL Scripts => Topic started by: NickE on March 20, 2011, 09:07:09 am
-
Attached below is a working BVH file import program for Anim8or. For those that are not familiar, BVH is a motion capture file format that describes a skeleton made up of joints (points) and a timeline of XYZ Euler angles that describe the rotation of the joints. See http://www.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/BVH.html (http://www.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/BVH.html) for an overview of the description.
Anim8or differs widely from the BVH file format in that Anim8or's Figure Mode uses bones for the skeleton where the orientation of the bones is described by a quaternion. The Sequence Mode uses XYZ Euler angles to describe the change in orientation of the bone relative to the initial orientation of the bone set in Figure Mode. In Anim8or, the rotation of the bones, when unconstrained, goes from -360 to +360 degrees. Conversion to and from quaternions and Euler angles requires the use of trigonometric functions. The atan2 function, for example, goes from -180 to 180 degrees. A small change in angle in the BVH file across one of these trigonometric limits can trigger Anim8or to flip the bone 180 degrees.
Anim8or has bugs in calculating the frames between keys. Sometimes it will interpolate wildly.
Scene Mode has a bug (or maybe it is intentional) where the root bone orientation is completely ignored. Since the root bone orientation is the orientation of the entire figure, the bug is overcome by keying the root bone orientation into the orientation controller of the figure in Scene Mode.
Sequence Mode has no translational motion abilities, so the BVH translation is keyed into the position controller of the figure in Scene Mode.
The program can currently read in a BVH file and create an Anim8or project file (an8). This means it generates a skeleton in Figure Mode, a sequence that uses the skeleton, and a scene containing the figure and the sequence. It keys the orientation and position for the figure directly in scene mode. For reference, the program also generates a simple line object in the same position as the skeleton. I found this useful for getting the size and posture of the object to be skinned close.
BVH files sometimes have issues as well. Most of the Carnegie-Mellon BVH repository files have zero-offset joints. This introduces some small error when these zero-offset joints have rotations. Many BVH files have skeletons of very small scale. I have added a scaling function to the program to allow you to modify the overall scale of the skeleton. Many of the BVH file have frames-per-second (FPS) of 30, 60, or 120. I have added the ability to change the FPS. Please realize that the recalculation of the FPS requires computational interpolation of the motion. I am using simple linear interpolation in that calculation that introduces some error. To reduce the number of keys (to reduce file loading time), the program allows you to choose how often to key the original motion as well as put in a tolerance factor to not key when there is change less than this tolerance factor. In BVH files that have a lot of fast motion, you will need to key more often. One martial arts BVH file I tested required every frame to be keyed or significant motion error occurred. Loading that 650 frame Anim8or file takes about 4 minutes on my computer. Some BVH files have a first frame that is zero motion (original skeleton pose). There is an option in the program to skip this frame in the sequence and scene.
Some minor tweaking in Anim8or is often necessary due to the fact that trigonometric functions change rapidly near the limits. This relatively easy to do. A BVH file I tested that had a runner turning a 90 degree turn worked fine except the right upper arm was slightly off. A small adjustment in Figure Mode was all that was necessary.
While the program works pretty well for what it does, the results of the program are not readily portable or incorporated into existing projects. The final product is in Scene Mode.
The program is written in VB6, so you might need to download some runtime libraries if your computer does not already have them.
Please play with the program and give me your feedback and ideas on how to make this more useful to Anim8or users.
Some hasty examples done with figures from BobIt's figure plugin are posted on youtube:
Chinese Martial Arts: youtube.com/watch?v=KG9hBBvjoDo[/youtube]]http://www. (http://www.[youtube)
Hooker Walk: youtube.com/watch?v=3_AjJkl6qzk[/youtube]]http://www. (http://www.[youtube)
Thank you.
-
hi Nicke :)
good idea
im try but in open in anim8or has "Error reading file" importing/open..
can you show me "step by step" how maker this?
thanks
-
wowwee....checking it out.
-
Very usefull tool. Since I also use anim8or at my work, not only for personal project, this could be gold.
Btw, very usefull would be to have the possibility to import/export the camera, would be great for after effects, for example.
-
tried a few bvh files but all movements were a bit chaotic.
then i tried this one
and it imported into anim80r, the arms dont do what they should but its still great.
i tried to convert the bvh exported by the latest version of make human alpha 1 - 6.
but it says 'runtime error 11 division by zero' ..dont know if thats of any interest,
-
Your guy seems kinda happy, captaindrewi :)
I usualy set key every frame to be sure the movements are as natural as they can be, avoiding strange behavior.
BTW. I made some animations, and the project file is 40MB, with converted bvh file and my character. But I must say it looks amazing.
-
wow, this looks awesome, cant wait to try it! just wondering though how would one go about making a bvh file (what kinds of motion capture equipment/ software etc. would be needed)? if any one has any tips they would be much appreciated.
-
bv hacker might help.http://www.bvhacker.com/ (http://www.bvhacker.com/)in that once you have a bvh file ,you could edit/set it up it any way you want.there are links to free bvh files at bv hacker site.
i have played with 'bvh 2 an8' and have managed to import a number of bvh files successfully into anim8or but
how can one attach an object so that upper and lower body parts are influenced by the skeleton?
as one can't attach objects to the root bone
UPDATE....i have had my memory jogged now....'insert bone' above the root...via 'build' in the top menu bar.
-
Yes, you're right. Unfortunately, you can not attach one single mesh to the skeletton. I made a few animations, but my character was a robot, so this solved the problem. I attached each member separatly. When it comes to one single mesh, it is a problem.
Maybe NickE can help with this problem.
-
Dan a single mesh seems to work....after adding the extra bone to the root i added a 'bob it figure' to it and organised bone influences pretty quickly.
Roughly arranged but functioning.
-
can u export the bvh 2?
-
I have attached an updated version of the BVH Import program. It automatically adds a bone to attach a single mesh. This bone is called "0_object_bone". When in Figure Mode, if you click on "List Items" button, it will be the first bone in the list. Click on that item in the list to select it, and then do the "Build>Add Object" to attach the mesh to this "root" bone. Then it is just a matter of weight painting.
The program is also a little bit more intelligent about keeping the axes from flipping. It doesn't always work, but it is a lot better.
Feedback is always appreciated.
-
UPDATED!!! i target your error...
all export using ","....
ex. 0,2323 <--- this is the error cause..
Correct 0.2323 <--- ok.
1.- Open an8 file in notepad
2.- search and replace all "," for "." in anim8or file exported and...
3.- works fine.. ;)
WOW! nickE you are..
Edited...
Extreme useful tool..
but i have error..
1. Bvh file to convert: C:\Documents and Settings\admin\Mis documentos\chinesemartialart.bvh
2. an8 file output:C:\Documents and Settings\admin\Mis documentos\test.an8
3. click in convert..
4. open in anim8or and....
Error :P
title. "just so you'd know" : "Error readyng file"
where i can get "vb runtime libraries"
-
Had a brief go.importing a random cmu bvh.
worked fine.
-
Thanks Nick. Haven't tried it yet, but me being the pack rat that I am I got both anyways for possible future use. Leroy.
-
Thank you very much for this converter . After change "," to "." it worked :)
-
A user (Daniel) found a set of BVH files that could not be converted with the current version. Those files had 6 channels for each bone as opposed to the normal 3 channels. It was causing the program to crash. An updated version is attached.
Feedback is appreciated.
-
Is there a possibility you could release source for this?
-
The source code is for Visual Studio 2013 (available free).
Enjoy!
-
Thanks :) I do not know if will help, but I am trying to convert euler angles to anim8or relative to bone. Not sure how bvh stored them, but I'm having problems in the final step, which is mapping euler angles to instead axis-angles of the bone XYZ. How perfect did you get that conversion going? (Maybe bvh isn't stored that way, as euler).
-
SubDrag,
Can you please be more specific about what you are trying to do? Euler angles relative to what? Is there a source format you are using?
-
Yeah, FBX -> an8. I have everything but the final step, which is to take the bones absolute orientation, and map the Euler angles per keyframe I have, to the 3 axis-angle anim8or uses. I thought you would have done something similar with BVH.
It is what anim8or has in its file as "floatkey" under "jointangle" and then "track"
-
All the math you need is in the BVH2Anim8or code. I have also attached a SMD2Anim8or source. It does something very similar.
Anim8or does not use a 3 axis-angle format. Anim8or uses quaternions to encode the orientation of the bone relative to its parent.
Do you have a link to the FBX format specification where it describes the reference frame for the bone orientations?
Please read the thread http://www.anim8or.com/smf/index.php/topic,5005.msg37381.html#msg37381 (http://www.anim8or.com/smf/index.php/topic,5005.msg37381.html#msg37381) for some discussion of the math required.
-
Ah, I'm talking about the actual animation track (got the bones proper, I use a bone, and then a 0-sized bone in anim8or). I'm not sure about spec, I use the FBX SDK api, but FBX is stored as relative offsets by joint, and each rotation at a joint is Euler X Y Z (in that order). The translation to and from anim8or of skeleton I have working. It's the animation keyframe tracks that I am trying to convert. In FBX, each joint rotation is stored in euler angles are not relative to the bone, they are normal, unlike anim8or which appears relative to the bone, which appears to me to be 3 angle rotations, of a coordinate axis aligning with the bone (essentially, transformation of (0,1,0) into bone orientation), which seems like multiplication of 3 axis-angles or something.
I don't see it in SMDA2Anim8or, but it must be in the bvh one somewhere, the angles of the animation at each joint, into anim8or format
For example, a 0-sized bone with absolute resolved orientation quaternion of:
x 0.52577096
y 0.084030904
z 0.40771002
w 0.74180597
, and euler rotation 58.6767 33.600 138.3259 in FBX. That translates to in anim8or 30 60 40 (this is goal, to find out these numbers using math for general case). Well, the part I am trying to figure out is how to automatically go from those Euler angles, with known orientation that I already figured out, into anim8or animation angles.
-
The missing pieces of required information is the reference frames for the rotations. Does FBX use a right-handed or left-handed reference frame? Are the skeletal orientation given in the global reference frame, object reference frame, or local reference frame? Are the keyframe joint rotations given in the global reference frame, object reference frame, or local reference frame?
Since you already have the Anim8or skeleton constructed from the FBX file, you have some knowledge of the FBX reference frame. Otherwise the skeleton would be distorted or rotated. So, essentially what you need to do is transform the FBX Euler rotation angles from whatever reference frame they are in to the Anim8or local bone reference frame (the rotation of the bone relative to the parent).
The BVH2Anim8or source code routine "Calc_Figure_Orientation" calculates the each bone orientation relative to its parent bone. The root bone (the ultimate parent) is located in the Anim8or global reference frame Left-Handed (0,1,0). The routine "Calc_NetOrient" calculates the each bone orientation relative to the Anim8or global reference frame. The routine "Calc_Sequence_Motion" transforms the BVH keyframe joint rotations to the Anim8or local bone reference frame.
I know this is very confusing and extremely frustrating. While writing the BVH2Anim8or and SMD2Anim8or converters, I kept having to remind myself "What frame I am in? What frame do the actions take place? What frame does Anim8or need?"
-
Thanks, that is complicated, I'll have to try and make sense of it. FBX is left-handed, XYZ euler. Skeleton translation is relative to parent. It's probably the same as BVH, though I'm not that familiar with BVH. As you mentioned, just the last step is heavily thwarting.
-
Hi again, I was able to get what I wanted to do, though a different way, but it is not working perfectly. I think there is a problem with your BVH convertor also, as I was trying to see if it did better. It does not do well on my BVH test.
Source:
http://www.mediafire.com/download/y78hcvzapvh4hne/animation.fbx
BVH attempt:
http://www.mediafire.com/download/i140norhf31gd48/DefaultAnimation.bvh
http://www.mediafire.com/download/49225tchu0ckdv6/DefaultAnimation.an8
My attempt (using my tool):
http://www.mediafire.com/download/k9311miosdl9d4w/myanimationconvertattempt.an8
-
There are 6 ways to convert Euler angles into a quaternion, depending on the order that the X Y and Z angles are applied. Unfortunately I don't remember which order Anim8or uses! I'll post the code it uses when I get back from Italy but that won't be until mid July.
There are also some misconceptions in some of these posts about how Anim8or works which I 'll address as well. It's too difficult to write much on my tablet or I'd do it now :)
-
Ah great, I cant wait for Sub to get GoldenEye animations working with An8.
Trev
-
That's great Steve, I'm close, but no cigar on the port! It would be great, then can get animations in, and out, of anim8or between it and FBX (At least...the simple ones I do).
@NickE, I am having problems getting your tool to work. This one crashes anim8or when converted, can you take a look:
http://goldeneyevault.com/priv/endorphintest.bvh
-
I'll post the code it uses
Have you thought of publishing Anim8or on something like Github?
-
Can you look at this bvh to see why it's not cooperating like your two examples, using your tool.
Here is for sure a valid bvh, I can look at it fine in bvhacker, but it looks off in anim8or after conversion.
http://goldeneyevault.com/priv/animationdamjump.bvh
(http://i.gyazo.com/91eeba606a5ae237ae850e79b52cf8aa.png)
(http://i.gyazo.com/cd59b07d2ca71d02f5c7a0ab345d518d.png)
-
SubDrag,
The file from the link is working fine for me. I have attached the latest version of the program (executable and source) and the an8 file from the conversion. The latest version is smarter about white space in the bvh file than the previous version. I found that GoldenEye bvh files tend to use multiple spaces as a separator rather than the single space or tab. In the previous version, multiple spaces as a separator would cause parsing errors.
The only parameter I changed in BVH2Animator is the scale factor to 0.15, so the figure (originally at 638) would not be so large (more like 100).
-
Hi NickE, that is an improvement to the version I had, but there is still an issue actually in conversion.
This is what the bvh looks like in bvhacker:
In the file you posted, the legs cross or something weird at some point:
(http://i.gyazo.com/f899ff862b6162a1431e40aa14c5652a.png)
-
Ok, so, Ill post our little solution to the problem we found.
First the Problem is that AN8 has Gimble Lock at ZY while most other software has Gimble Lock at XY.
Now, an8 actually proves to be far supirior since the liklyhood of getting GimbleLock is reduced as not many things run the ZY axis.
(It should be noted that an8 uses quaternuions internally which do NOT suffer gimble lock, however this is not the problem)
HOWEVER this proves to be a real problem when directly importing animations made in other software, since as other software approach gimble lock the start to add values to both X and Z which themselves do nothing. An8 however shows these values literally and so you get weird effects.
So, our solution was to move the Gimble Lock back to the XY axis by adding 3 bones at each joint. (originally was 5 as seen in image, however quaternuions do not suffer gimble lock and so the 2 rotations could be combined)
(http://fgfc.ddns.net/PerfectGold/GE%20Modeling/GoldenEye%20Animations/Implementational%20Testing/An8GEBoneWorkaroundZXY.jpg)
First we take whatever direction the bone is coming from and point it X+
(Image shows z90, this is variable depending on original bone orientation, i.e. had the bone already been pointing X+ then it would rotate 0. If the bone was pointing X- then the bone would rotate 180)
Then we rotate it Y90 (these 2 operations being combined in quaternuions)
Then we add the 'Joint' as a 0 legnth fat bone. (this sets the bone dialoge angles to 0,0,0)
Then we undo all before.
Rotate -Y90
Rotate back to original cource pointing to next bone. (in image the next bone was directly above the first, so we rotate -Z90. Had the next bone been to the right we would rotate 0, had the bone been to the left slightly then we would rotate 100 etc.
All connecting bones are 0 legnth and 0 diameter.
One final consideration and we are done.
Ignore all lables in the bone Orientation Dialoge, the Order is Z, X, Y, Not P Y R.
Attached is an example of a working animation direct from GoldenEye.
(http://fgfc.ddns.net/perfectgold/ge%20modeling/GoldenEye%20Animations/walkturnanimationextrabones.gif)
Trev
P.S. can anyone tell me if the atached .an8 shows the guard in scene mode?
He works in sequence mode but in scene mode his model is invisible, all I can see is his skeleton working
If he is invisible then does anyone know why?
(clearly something went wrong since the animation pictured above, which actually shows him)
P.S.S Doesnt matter I found it... Sub put him on the root bone accidently in the latest version.
The root bone is useless grrr
(http://fgfc.ddns.net/perfectgold/ge%20modeling/GoldenEye%20Animations/WalkTurn_Scene.gif)
-
What version of Anim8or are you using? I found a much more robust Rotation Matrix to Quaternion algorithm that the one you see everywhere on the web (and that Anim8or has been using since it's inception). It's in build 1178 and onwards and may fix the problem that you're seeing.
If you're interested in to algorithm, here's a link:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
(http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/)
-
Personally Im using the latest beta. 1179.
As I kinda atated above, its the fact that as other software aproches gimble lock they add values to X and Z (eg, 90 90 -90)
The result in those apps is that nothing changes, the rotation = 0 90 0
However, since an8 does not lock out, it takes the values literally and so rotates the character 'oddly'.
This was the solution we came up with to overcome the limitation from GoldenEye (and xsi and blender etc)
Trev
P.S. Not sure if you saw the images, my PC was off yesterday at 02:40 UTC
-
OK, thanks. I misread your post and thought Anim8or was locking up. Before build 1178 it could do that because some tools use rotation matrices internally and occasionally returned a default neutral quaternion.
-
**I should note this working in bvh2anim8or, but I'd like to understand why mine isn't working.
Actually it only works for simpler models though. More complicated and I can't get the bone orientation correct (nothing to do with actual rotation keyframes, just talking bone structure now). I am using normalized Quat::RotateFromTo (root bone at 0,1,0) of absolute position of current - absolute position of previous, to go from previous bone to current, and assign that quaternion, but clearly something goes wrong at some point, to go from previous bone to next. Maybe your logic is slightly different somehow?
The issue seems to be (in my code) that sometimes the quaternion is backwards.
For example,
orientation { (-0.164697 0.000000 -0.000000 0.986344) } Wrong
vs
orientation { (0.16470 0.00000 0.00000 -0.98634) } Right
When startLink = {x=0.00000000 y=40.600006 z=-532.50000 ...}
And endLink = {x=0.00000000 y=-54.827942 z=-210.49976 ...}
Then Quat RotFromTo startLink to endLink basically
Quat MUST_USE_RESULT Quat::RotateFromTo(const float3 &sourceDirection, const float3 &targetDirection)
{
assume(sourceDirection.IsNormalized());
assume(targetDirection.IsNormalized());
float angle = sourceDirection.AngleBetweenNorm(targetDirection);
assume(angle >= 0.f);
// If sourceDirection == targetDirection, the cross product comes out zero, and normalization would fail. In that case, pick an arbitrary axis.
float3 axis = sourceDirection.Cross(targetDirection);
float oldLength = axis.Normalize();
if (oldLength == 0)
axis = float3(1, 0, 0);
return Quat(axis, angle);
}
Code is:
if (length > 0)
{
if (realParent == NULL) // From TopJoint
{
quat = Quat::RotateFromTo(float3(0,1,0), bone->boneEnd->positionAbsolute.Normalized());
length = bone->boneEnd->positionAbsolute.Length();
}
else
{
float3 startLink = realParent->boneEnd->positionAbsolute - ((realParent->boneStart == 0) ? float3(0,0,0) : realParent->boneStart->positionAbsolute);
float3 endLink = bone->boneEnd->positionAbsolute - bone->boneStart->positionAbsolute;
quat = Quat::RotateFromTo( startLink.Normalized(), endLink.Normalized() );
length = (bone->boneEnd->positionAbsolute - bone->boneStart->positionAbsolute).Length();
}
}
else
{
quat = Quat(0, 0, 0, 1);
}
-
SubDrag: There a common problem when generating a series of quaternions to be used as orientations representing positions in an animation:
Q1, Q2, ... Qn-1, Qn.
As you stated there are two possible quaternions for each orientation, which I'll call Q and Q'. As orientations they are equivalent. But when used pairwise to generate rotations they are very different and need to be considered pair-wise..
If you want the animation to rotate using the shortest angle (i.e. from New York to London across the Atlantic) then each pair of consecutive quaternions Qk-1, Qk needs to be the "closest" distance, for lack of a better term. If they aren't, you will go from New York to London via the Pacific and Indian oceans.
So assume that you have generated Q1, ... Qk-1 and you want to add q as the next value. How can you tell which to use, q or q'? Compute the dot product:
dot(Qk-1, q) = Qk-1.x*q.x + Qk-1.y*q.y + Qk-1.z*q.z + Qk-1.w*q.w
If it is > 0 you need to use Qk = q, otherwise use Qk = q'.
If it is = 0 then there is no shortest path - the orientations are exactly opposite so there is not enough information for a solution. There needs to be another data point between those tow orientations.
-
Thanks Steve, that makes sense in terms of why they are different, though I hadn't realized bone definitions used rotations instead of effective orientations.
-
Well, they are both. An orientation is a particular point in time, a key. A rotation is what happens between two orientations, how motion is generated between two fixed orientations.
-
Forgot to update this when sub posted his new version of Obj2an8, it works now.
Here is a Skedar animation direct from Perfect Dark
(http://fgfc.ddns.net/perfectgold/ge%20modeling/GoldenEye%20Animations/SkedarSomersault.gif)
These work with the gimble lock bones as described above.
Now, for going back into GE/PD im not sure how to do the bones. Since an8 does not suffer gimble lock it seems slightly pointless to do all the rotations.
Actually, I just tested again and this build still locks out in GUI in the YZ plane so I guess I have to make all these bones manually for new objects.
Trev
Trev
-
Hello, :)
Can somebody share alink to the last stable version of this tool (BVH2Anim8or) to convert a bhv file to a an8 file (with joints/bones and animation)
Thanks,
-
The file in NickE's post dated July 03, 2015, 03:26:30 pm
is the most recent one.
-
@Claude>>Thanks for the confirmation.
Is this tool supposed to work correctly or is it wip ?
Because when i try to convert a bhv to an an8 with this tool, i get an error, see : http://rd-stuff.fr/screenshot-BHV2Anim8or-error.jpg
Thanks,
-
Post your BVH file and the parameters you're using.
I'm sure NickE will try to help next time is around.
He was on the forum an hour ago.
-
RemiD,
Like Claude posted, if you post the BHV file and parameters, I will take a look. Often, these issue happen because so many different BVH generators write slightly differing formats that the parser does not anticipate or the file is simply malformed.
NickE
-
Ok, here is the bhv biovision file : http://rd-stuff.fr/MasterLiuPerformance-1200to3200-bhvbiovision.bvh
I have managed to import this bhv animation with Ultimate unwrap 3d and with Fragmotion and with Blender and the tpose skeleton seems ok but the animated skeleton seems weirdly scaled stretched... (but the animation seems correct) I am trying to determine if this weird scaling stretching comes from an error in the exporter (of a software which exports motion captured animations in bhv biovision) or from the importer.
If you have an idea, please let me know.
Thanks,
-
Just to let you know that i have solved the weird scaling stretching of the skeleton while it is animating (you have to remove all translation/position keys of all joints/bones except those of the root joint/bone)
However i still have the error when trying to convert the bhv file to an an8 file using BVH2Anim8or.
(i don't really need to use anim8or but it would be good to fix this bug anyway for the others users, as you want...)
Good luck,
-
@NickE Hey, man. Any new updates for BVH2an8 soon?
Anim8or has a great ik now, so I believe this could also solve the little problems the imported character's had.
-
Daniel,
Have you run into BVH files the BVH2an8 cannot handle? If so, please post them, and I will see what I can do.
Thank you,
NickE
-
I haven't had such problems. Your converter is simply amazing. I used it a lot in the past, and I would even send you a beer on Paypal. :) I'm only referring to the "jiggle" I had in some movements a while back, which I had to manually correct. I remember that had to do with the IK system anim8or had back then.
I'll get my new laptop in a couple of days and make some new tests.