Use Motion Capture Data .bip .bvh with bullet

shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Use Motion Capture Data .bip .bvh with bullet

Post by shomy2k11 »

Hi,
I'm designing a 3D game for the iPhone and would like to know to things.

1. how do i load a .bip or .bvh file that contains motion capture data
2. how do i apply it to softbody/rigidbody in bullet?
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

This is quite interesting that BVH in bullet means Bounding Volume Hierarchy, rather than the format of motion capture data.

This topic is what I am thinking in these days, but I didn't get time to do some work on it.

What I would do is to map the rotation angles in BVH file to each joint constraints of your ragdoll character. This seems reasonable. I will try to work something out.

If anyone already did some work, that would be great to post it here and share with us....

Cheers.
shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Re: Use Motion Capture Data .bip .bvh with bullet

Post by shomy2k11 »

I did find quite a few resources. But my knowledge of bullet is still quite limited. I'd appreciate some assistance. There are tons of files all over the net. But as you know you will not always find what you are looking for. I'm specifically looking for motion capture to animate the spider from one of the bullet demos.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

Do you refer to the DynamicsControl Demo?

It would be strange if you apply human motion capture data to them, I would doubt if this works because of the different skeletal structure
User avatar
Yann
Posts: 52
Joined: Wed Sep 28, 2011 8:36 am
Location: France

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Yann »

Hi,
I'm actually coupling Bullet to our animation engine, so doing quite similar things theses days.
For now, I managed to read .bvh/.fbx/.s4d motion files in our animation engine and then applying it on a bullet ragdoll.
For this purpose, you have to set all rigid bodies in kinematic mode :

Code: Select all

_bodies[bodyIndex]->setCollisionFlags( _bodies[bodyIndex]->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT)

Then during the update loop, all you have to do is to set the desired position/orientation in the motion state:

Code: Select all

_bodies[bodyIndex]->getMotionState()->setWorldTransform(_tmp_btTransform);
Now this is only a 'kinematic' mode, which means your character will have an effect in the physic world, but the physic world will have no effect on the character.
I'm actually trying to do the same with constraints and motors, and it's clearly not the same kind of deal.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

hello, Great work ! I am doing the motion synthesis as well, but with the method of dynamic controller design.

Is it possible to contribute your code to the forum? If it doesn't violate the copyright of your animation engine.

Thanks !
User avatar
Yann
Posts: 52
Joined: Wed Sep 28, 2011 8:36 am
Location: France

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Yann »

Well, I'll try to isolate the parts that I can post here ;)

If you want to be able to works with any .bvh file, the main problem is to build the rigid body architecture that will mimic the same skeleton than the one described in the .bvh file. That part is done by our animation engine and I won't be able to give you lots of details about it.
But I'll post more details about the other parts of the process as soon as I can.
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

First thank you very much for sharing your code, I will put my dynamic controller here later, suppose this December should be ok for the first version.

if you want to create a ragdoll that has the same skeletal structure as the BVH file, that's trouble. But with the same skeletal structure, you avoid the problem of motion retargetting, which has been studied for more than 10 years in academics. But the default skeletal structure in BVH is almost the same. You can narrow your input scope and select the BVH file that uses the default skeleton, this will save the labour to build different skeletons.

Many Thanks for your sharing !
shomy2k11
Posts: 24
Joined: Thu Sep 08, 2011 1:59 am

Re: Use Motion Capture Data .bip .bvh with bullet

Post by shomy2k11 »

Hi Yann,
please do so asap. I learn best by "example code" hehehe :)

By giving me the means to learn this integration step i'll be 90% complete with PC develpment. Imagine i'm designing an iphone game on a linux PC with no crappy video acceleration. All for the bold i guess. I'll post screenshots to this forum soon.
User avatar
Yann
Posts: 52
Joined: Wed Sep 28, 2011 8:36 am
Location: France

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Yann »

What is the part you're having trouble with, exactly ?
Parsing the bvh file ? -> here is an article that may help you: http://web.archive.org/web/201107181305 ... f/BVH.html

Note that there is no 'default' skeleton in bvh, depending on where you'll get your data, it may be completely different. In our case, we manage to transform the animation from any biped skeleton into a representation we already know.
For this part I can't give the code (took us long time to develop), I can just give you advices if you need, and answer all your questions.

Then when you have a skeleton you know, you just have to create rigid bodies/shapes the same way as it is done in the ragdoll sample. I made one noticeable difference in my case: I putted each bone into a compound, to handle the difference between the center of rotation in .bvh (beginning of the joint) and in bullet (center of the joint). Here is how (it uses mainly our math library, but i guess names speak for themselves):

Code: Select all

_shapes[boneIndex] = new btCylinderShapeZ(btVector3(btScalar(_bodyWidthRadius), btScalar(0.6*_bodyWidthRadius), btScalar(boneLength/2.)));
//compute the volume and mass of a cylinder
mass=btScalar(_bodyDensity*golaem::math::getPi()*sqr(_bodyWidthRadius)*0.5*boneLength);
boneCenterOrientation = tmpPosture.getWorldOri(*proximalBone);
math::Vector3r constraintPositionInBoneCoordinateSystem(returnedBoneCenterOrientation.inverse()*(constraintPosition-boneCenterOrientation));

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//set a compound shape, that allow to have same positions for graphical bones and physical ones
if(math::approxDiff<double>(constraintPositionInBoneCoordinateSystem.norm2(),0, GLM_EPSILON))
{
	btCompoundShape* currentShapeInCompound = new btCompoundShape(false);
	btTransform offset;
	offset.setIdentity();
	offset.setOrigin(convert(-constraintPositionInBoneCoordinateSystem));	//center of bone position in compound coordinate system (ie. constraint)
	currentShapeInCompound->addChildShape(offset, _shapes[boneIndex]);
	currentShapeInCompound->recalculateLocalAabb();
	_shapes[boneIndex]=currentShapeInCompound;
	boneCenterPosition=constraintPosition;
	constraintPositionInBoneCoordinateSystem=math::Vector3r::getNullVector();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//rigid body
btTransform transform;
transform.setOrigin(convert(boneCenterPosition));
transform.setRotation(convert(boneCenterOrientation));
_bodies[boneIndex] = localCreateRigidBody(mass, transform, _shapes[boneIndex]);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//joint with father
btTransform bodyTransform, parentBodyTransform;
bodyTransform.setRotation(convert(boneCenterOrientation) * convert(boneCenterOrientation.inverse()));
bodyTransform.setOrigin(convert(constraintPositionInBoneCoordinateSystem));
parentBodyTransform.setRotation(btQuaternion(0,0,0,1));
parentBodyTransform.setOrigin(convert(boneCenterOrientation.inverse()*(constraintPosition-boneCenterPosition)));

btConeTwistConstraint* coneC = new btConeTwistConstraint(*_bodies[boneIndex], *_bodies[parentBoneIndex], bodyTransform, parentBodyTransform);

//_softness: 0->1, recommend ~0.8->1. Describes % of limits where movement is free. Beyond this softness %, the limit is gradually enforced until the "hard" (1.0) limit is reached.
//_biasFactor: 0->1?, recommend 0.3 +/-0.3 or so. Strength with which constraint resists zeroth order (angular, not angular velocity) limit violation.
//_relaxationFactor: 0->1, recommend to stay near 1. The lower the value, the less the constraint will fight velocities which violate the angular limits.
coneC->setLimit(SIMD_PI*0.1f, SIMD_PI, SIMD_PI, 0.9f, 0.3f, 0.8f);
_dynamicWorld->addConstraint(coneC, true);	//true to disable collisions between linked rigid bodies
Well, as i said, everything looks like the ragdoll sample, except for the part with the compound shape.

And the last part is about applying the bone's position and orientation on the bodies, here is approximation how i do:
At init time:

Code: Select all

for(int bodyIndex=0; bodyIndex<RigidBodiesIndex::END; ++bodyIndex)
{
	if(_bodies[bodyIndex]!=NULL)
	{
		_bodies[bodyIndex]->setCollisionFlags( _bodies[bodyIndex]->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
	}
}
And at runtime:

Code: Select all

//RigidBodiesIndex::BODYPART_PELVIS,
currentBone=_hierarchicalSkeleton->getBone(HierarchicalBoneMappingList::root);
_tmp_btTransform.setOrigin(convert(myPosture.getWorldPos(*currentBone)));
_tmp_btTransform.setRotation(convert(myPosture.getWorldOri(*currentBone)));
_bodies[RigidBodiesIndex::BODYPART_PELVIS]->getMotionState()->setWorldTransform(_tmp_btTransform);

//and this for each bone.

I'm not sure if all this is very useful for you, just let me know ;)
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

Hi, Yann,

this is the BVH specification I found: http://www.character-studio.net/bvh_fil ... cation.htm

When you refer to biped skeleton, do you mean that this BVH file is not limited to human motion capture data, and it is extended to any motion that is saved as the frame/skeleton structure ? Because in my previous understanding, BVH file is used for motion capture, and it is just for human motion.
User avatar
Yann
Posts: 52
Joined: Wed Sep 28, 2011 8:36 am
Location: France

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Yann »

Dr.Shepherd wrote:Hi, Yann,

this is the BVH specification I found: http://www.character-studio.net/bvh_fil ... cation.htm

When you refer to biped skeleton, do you mean that this BVH file is not limited to human motion capture data, and it is extended to any motion that is saved as the frame/skeleton structure ? Because in my previous understanding, BVH file is used for motion capture, and it is just for human motion.
Well, this format specification looks like a limitation of the original file format.
As I said before, it all depends on where you get your .bvh files from. If they follow this specification, then fine. But the .bvh original file specification allow far more possibilities. It would work for quadrupeds also (I got a capture of a horse, another of a lion...), and the skeleton structure may be different depending on who made the motion capture. Most studios use almost the same markers, but some universities sometimes use different ones, or use more/less bones...
That's in the same time the pro AND the cons of the .bvh file format: you may do anything with it... But then it's difficult to have something that will works with every possible .bvh.

So it all depends on where you will get your files from ;)
User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm

Re: Use Motion Capture Data .bip .bvh with bullet

Post by Dr.Shepherd »

Yann wrote: Well, this format specification looks like a limitation of the original file format.
As I said before, it all depends on where you get your .bvh files from. If they follow this specification, then fine. But the .bvh original file specification allow far more possibilities. It would work for quadrupeds also (I got a capture of a horse, another of a lion...), and the skeleton structure may be different depending on who made the motion capture. Most studios use almost the same markers, but some universities sometimes use different ones, or use more/less bones...
That's in the same time the pro AND the cons of the .bvh file format: you may do anything with it... But then it's difficult to have something that will works with every possible .bvh.

So it all depends on where you will get your files from ;)
Ok, this makes sense. Thanks for discussing ! and definitely your code !

Cheers man !