LWJGL Skeletal Animation 3D

Started by DeltaDrizz, April 26, 2015, 14:55:56

Previous topic - Next topic

DeltaDrizz

Hey,

I wanna implement simple animations into my game. I found the gpwiki page for skeletal animation, but I can't really do sth with it, 'cause its C. Can anyone give me an veeery detailed explanation?

Greetings :)

quew8

So firstly skeletal animation is not a "simple animation" technique. What I would say is that much better to understand the technique properly because your implementation is going to depend a lot on what you've got already. The basic idea is this:


  • You have a skeleton comprised of several joints.
  • Each joint has a matrix associated with it.
  • Define the matrices to describe the shape of the skeleton.
  • Each vertex of the skin has a weighting for each joint which determines how biased it is to that joint.
  • The position of the vertex is determined as a linear combination of the transforms of each of the joints based on the weighting.

That's the basic outline but the actual joint transformations must be performed in "joint space" which complicates things a bit. For a more precise outline of the technical aspects I recommend reading the COLLADA specification's programming guide which gives a good description: https://www.khronos.org/files/collada_spec_1_5.pdf. Take a look here at the section titled "Skin Deformation (or Skinning) in COLLADA"

Once you understand the technique, you have to think about how you are going to implement it. Use shaders. You will need some extra vertex attributes to describe the weights and which joints these weights refer to. You will need an array of uniform matrices to describe the joint matrices. And there a few other uniform matrices that need to be defined for each skeleton. So you can see why it is important to understand what you are doing.

DeltaDrizz

Hello, I'm again here. Can anyone provide me with source code for Java? I searched long time on the internet and didn't found any(!) source for Skeletal Animation (non .class Files). I promise, that I will not copy and paste it (its aldo not possible, have my own engine) because I want to learn (<---!!!) how the whole thing works. If you send me a private message, tell me before here.

Greetings

abcdef

Have a look here

http://www.java-gaming.org/index.php/topic,1177.

Or google "skeletal animation opengl java"

Before anyone gives you their code you should at least try to do something yourself. Research the subject more and try and understand the basics.Then post specific questions for the bits you don't understand.


quew8

Firstly, ditto what @abcdef says. Throwing yourself into it and then asking specific questions will always be more productive and will often be quicker too. If nothing else you'll probably find yourself asking fewer questions.

As far as code for skeletal animation goes, the most you'll probably get is some shader code. Everything else will be very specific to a particular use case. Shaders will also be specific, but less so. A highly optimized shader is another matter entirely. So you see that skeletal animation isn't really something you can just knock out some general code which will cover any situation.

DeltaDrizz

The main part I don't understand is how to do the things with the joints, e.g. rendering single bones next to anothet for getting one (firstly static) skeleton. (So the bones are "bound" together)

abcdef

The easiest way is to just visualise yourself. Stand up straight and rotate your hip so you look left. In this motion your waist, sholders, arms, hands, neck and head all rotate together because the waist moves everything. If you then reset and rotate your waist again, but rather than just rotating your waist you raise your arm too you find there is a difference to the previous rotation. Here your neck and head move exactly the same as before but your hand at the end of your arm takes a different trajectory due to you rotating the waist and additional moving the arm up.

The point of that little example is to demonstrate 2 things

1) Each part of your body has a parent except for the upper most body part, the root body part.
2) Each part of your body moves when it's parent move, you can then chain these movements all the way up the heirachy to the root body part

So when ever you move a body part, you need to iterate the changes to its children body parts and then all their body parts and so on.

Hope this helps, you can now implement this how ever you wish :)

DeltaDrizz

And when I have to do the movement part, I have to use interpolation, right? But when I use SLERP, it takes in quaternion, quaternion, time. But which quaternion belongs to the parent and which to the child?

Thanks for your help :D

abcdef

you are getting things mixed up a bit, the SLERP is not between the parent and child its for a single body part only.

For the Arm :

T=0 : Quaternion A
T=5 : Quaternion B

Any time between 0 and 5 (depends on your animation speed) need to be a bit of A and a bit of B. The SLERP determines this via a set formula.

The way the movements get cascaded down is via a transformation matrix. This contains rotation, scaling and translation. Have a read up on that.

If you have the waist transformation ("TransW") and the arm transformation ("TransA") you want to first apply the waist then you want to apply the arm. The final arm transformation is a combination of both transformations. Firt applying the waist movement then applying the arm movement

Arm Transformation*Waist Transformation*Original Arm Position

As you can guess, if the chain of body parts is longer you just keep applying thigns in a simialr way

DeltaDrizz

I'm so far, that I have a Bone 'system'. The problem is, when the rootbone rotates, the children wouldn't rotate with it, because I work with relative coordinates to the parent, in my example the childBone's x position is parent.pos.x + 15. Do I have to do the thing with the transformation matrix here? Can I get a pseudo code example here? Thanks, Delta :D

abcdef

Read up on the transformation matrix more, there are youtube videos which explain the translation, scale and rotation components and how they fit in to 4x4 matrix.

DeltaDrizz

I know how the transformation matrix works, but I don't know how to let e.g. Object1 rotate around Object2, I think I have to use some maths for this right?

fergal

Can someone explain the matrices needed for, and give a step-by-step guide on, calculating the rotation of a given vertex V, if V is influenced by three bones with the following influences:

Bone9 - 0.25
Bone10 - 0.25
Bone11 - 0.5

All three bones have a number of parent bones

What information do I need to have in order to calculate the rotation of V? The bind pose of each bone? Or the inverted bind pose of each bone? What other matrices do I need?


quew8

Firstly, you can't really calculate the rotation of a vertex. For each joint the vertex is influenced by, you transform the vertex into bind-space with the bind-shape-matrix, then transform with the joint specific inverse-bind-pose-matrix and joint-matrix. Then you use the joint weights to take a weighted average and that is the final position.

Go to page 33 here: https://www.khronos.org/files/collada_spec_1_4.pdf. There is an equation for transforming a vertex and nice definitions of the various terms and even some helpful hints.