Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 30 May 2006
Offline Last Active Jul 13 2014 02:09 PM

#5110448 How to compute the bounding volume for an animated (skinned) mesh ?

Posted by Buckshag on 19 November 2013 - 06:46 AM

It depends a bit on how your animation system works, but what works well for static boxes is to just take the bounds of the mesh, and get maximum of width/height/depth and size the box in all dimensions with that amount. So the same as mentioned above but without using any keyframes.


Some methods of calculating bounds that I implemented:

1.) Contain all node/bone global positions

2.) Contain all (skinned) vertex positions

3.) Contain all OBB's of each node/bone

4.) Static box that moves with the position of the actor (method as described above)


The method using keyframes would only work if you do not blend or combine motions or do not do any procedural things. Or you would have to pass your full motion database through it. But this is quite overkill. Also if you choose to go with this method, you most likely will sample your animation curves when importing them from the software you exported with. For example if you load an FBX or use an exporter from Max or Maya you sample the transforms every n frames and possibly optimize that data. This means that it is highly unlikely that you would hit a case where you export just 2 keyframes for a 360 degree rotation.

#4868559 Programmatic walk animation

Posted by Buckshag on 03 October 2011 - 08:12 AM

These kind of animation system are often called physical based animation systems.
You can see it as a physics ragdoll, which also has specified muscles, which are basically motors.
So let's say you have a knee joint that can rotate a given amount of degrees over one axis. And you specify the same for a bunch of other joints.

Now you could specify a goal you try to reach, for example to make the character walk, you have to say something like:
"for every time one of your feet hits the ground, you get 1 penalty points. And for every meter you move forward, you get 1 reward point.".

Now from this point on there are several possibilities. Different AI algorithms can be used to iteratively try to find the most optimal solution, to achieve the maximum reward amount. Each iteration, which is also called a learning or training phase, the character will walk better. In the beginning it will start with random rotational forces on the motors, and it will directly fall on the ground. But slowly it will maximize the reward and your character can walk.

As you can imagine though, it is pretty tricky to use this in games, because each game might need different "behaviors" or however you wish to call them. Like a walking behavior needs to be trained with a given reward structure, but a balancing behavior would need something else again. Also the walk animation won't look as natural as a motion captured animation.

This kind of technology is often used in Robotics, where people train their robots in offline simulations, so that they don't damage the real robots. I've also seen it being used by dinosaur researchers, where they try to figure out how specific dinosaurs would have walked/moved, and how fast they could have be.

Some things you might google for are "physically based character animation", "machine learning" and "reinforcement learning".

I hope this information helps a bit with getting you started :)

#4866134 Skinning Issues

Posted by Buckshag on 26 September 2011 - 10:58 AM

m_skeleton.m_joints[parent].m_worldMatrix * m_transformMatrices[iJoint][m_transformIndex];

Did you try switching these two as well? So like

m_transformMatrices[iJoint][m_transformIndex] * m_skeleton.m_joints[parent].m_worldMatrix

Can you draw your skeleton in lines? You first need to be sure your bone transformations in world space are correct.
Then we can see if its the skinning algorithm or that already.

If you really can't figure it out maybe I can give it a debugging try if you can send the code.

#4866025 Skinning Issues

Posted by Buckshag on 26 September 2011 - 06:00 AM

What you wrote seems correct, the description.
A simple idea, just to double check, but did you try changing your multiplication from: worldMatrix * inverseBindPoseMatrix into inverseBindPoseMatrix * worldMatrix ?

And do you pass them correctly to the shader? Row vs column major.(in case you do it on the gpu)

#4858627 fading between animations in using vertex skinning

Posted by Buckshag on 07 September 2011 - 07:54 AM

You are right about the slerping, and this is generally done on the CPU.
What you basically do is slerp or normalized lerp (nlerp) between the quaternions in local space.
With local space I mean that the bone rotations and positions should be relative to their parent bone.
Slerping is quite expensive, so often a normalized lerp is used. It performs very well.

Animation can still be one of the most CPU intensive things in games, depending of course on the complexity of the blends and amount of characters/bones etc.
In new games some characters will have very complex blend trees, with over 50-100 operations such as blends, sampling motions, inverse kinematics, etc.

To blend two animations, basically the steps are as follows:
1.) Sample the animation local space transformations in quats and position vectors
2.) Sample animation 2 the same way
3.) nlerp/slerp between those local transformations (from motion 1 and 2)
4.) build a local space matrix for each bone, from the position and rotation
5.) perform forward kinematics on the local space matrices to calculate the world space matrices
6.) perform skinning (can be done on gpu)
7.) render (gpu)

To blend between two motions you simply change your interpolation value.
The easiest system to do this is by making a set of layers. Each layer containing one animation.
Then you start at the bottom layer, and blend towards the layer on top, and the output of that blending again to the layer that is on top of that.

You can also go more advanced and build a more complex blend graph. But a simple transition between two motions is nothing more than the slerping between the local transforms of 2 motions.

Hope that helps a bit, if not just ask :)

#4808132 Tips to cache skeletal animation frames

Posted by Buckshag on 08 May 2011 - 10:33 AM

You should have a look into skinning inside a vertex shader.
That way you can push a lot more character and you do not need Cal3D to process the vertex data each update, but only let it update the bone transformation matrices.

I don't know Cal3D, but I assume it is possible with that library.

Or are there any specific reasons why you want to do this on the CPU instead of on the GPU?

#4807773 Simple universal mesh file format recommendations

Posted by Buckshag on 07 May 2011 - 01:48 PM

I think you have the option between the following formats:

1.) .obj which is very limited in what it can store, but it might be enough for your file format as that seems pretty simple as well.
2.) Collada, as you mentioned.
3.) FBX, using the FBX SDK.

I think these are the three most supported formats out there.
Pretty much all 3D software should support those.

The .obj file format is probably the easiest way to implement.

#4805085 [solved] Remap Rotation Matrix Axis System?

Posted by Buckshag on 01 May 2011 - 10:08 AM

You can solve it on different ways.

You can try to multiply the device matrix with a conversion matrix to convert it into your coordinate system.

Try multiplying it with this matrix:
1  0  0
0  0  1
0 -1  0

Another way would be to just swap the second and third rows and columns in the matrix and to negate the z axis inside it.

Edit: It should be second and third rows AND columns, not just the rows. Just in case anyone ever reads this again :)

#3944827 Quaternion + change of coordinate system

Posted by Buckshag on 21 April 2007 - 04:07 AM

I'm not sure if this is really a mathematically correct explanation but how you can see it is that swapping the y and z would also change you from right handed coordinates to left handed coordinates. If you would rotate x radians/degrees inside a right handed coordinate system this would be similar to -x degrees in left handed because of the difference in clockwise and counter clockwise rotations between those systems.

So if you rotate x degrees in right handed it would go clockwise, while doing the same thing in a left handed system would go counter clockwise. Might be the other way around too. And we change between left and right handed system here, but still want to end up in the same geometric output. That's why we have to invert the w, which is like the rotation angle around the quaternion xyz axis.

I'm not 100% sure if this is exactly the right explaination though. Probably someone with more math knowledge can give a more detailed description here. I just know if you think this way it works :)

The sign of w defines the hemisphere of the quaternion that's used. So inverting the w would change the hemisphere, which I think comes down to the clockwise/counterclockwise thing.

#3940669 Quaternion + change of coordinate system

Posted by Buckshag on 16 April 2007 - 10:34 PM

I'm not sure if all you try to do is convert your quaternion into the other coordinate system you mentioned. But if that is the case, all you need to do is swap the y and z and invert the w.

So you get like:

newQuat.x = orgQuat.x;
newQuat.y = orgQuat.z; // swap y and z
newQuat.z = orgQuat.y;
newQuat.w = -orgQuat.w;

Forgive me if I misunderstood the problem :)