• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Saad Manzur

Bones and Skeletons

4 posts in this topic

Can anyone give me some pointer on how to store bone structures and import animation in assimp, directx ? I cannot find any good information about it over the internet . I've got a term project on my hand on animation . Please give me some kind of example or anything..

0

Share this post


Link to post
Share on other sites

I'm not familiar with assimp, so I can't help you there. But with regard to storage, I found std::vector to work well, particularly for matrices, as std::vector guarantees contiguous memory for the data. Vectors work as well for the bone structures, animationset, animation and key frame structures. They deallocate themselves when they go out of scope.

0

Share this post


Link to post
Share on other sites

Suppose I stored the matrices. How do I get the position of the joints ? I want to draw the skeleton on the screen ? How to get the vertices of the joints ?

0

Share this post


Link to post
Share on other sites

Can anyone give me some pointer on how to store bone structures and import animation in assimp, directx ?

Beyond the assimp manual, see these for descriptions and code:

* <a href="http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html">Tutorial 38 - Skeletal Animation With Assimp</a>
* <a href="http://ephenationopengl.blogspot.com/2012/06/doing-animations-in-opengl.html">Doing animations in OpenGL (Ephenation OpenGL)</a>
0

Share this post


Link to post
Share on other sites

Hmm I haven't used assimp either and I don't know much of DirectX, but I can tell you how I did my experimental bone animation project in OpenGL.

 

I also searched the internet but I never came across something that clicked "dang, that's it!" - something that occasionally happens when I search for more usual stuff.

Still, with the help of the folks here in GameDev and very few obscure sites I found around (unfortunately I don't have them anymore, but I'll try to type what I got of useful from them) I managed to get a bone animation sample running.

 

First is, don't do the animation in your code/program. It's much much much slower. I've read (and then tested) about doing it in the shader and it indeed works much better.

Think of your data:

class Model
{
    public:
        float* vertexes;
        float* bonesWeights;
        Matrix4x4* bonesTransformations;
};

If you calculate each bone's transformation and modify the vertex data, you'll face two problems:

- It's slow because you'll be doing one vertex at a time and then updating the data.

- Because you're updating the vertex data, you're wasting memory because each model on screen will need to have it's own vertex buffer. If you don't change it's data, then you can have only a single vertex buffer and multiple models using it.

 

So the best course would be to do the vertex transformation at the shader level. From what I've read, they're already more suited for multi-threading and so the calculations go much faster.

Anyway, as for how to do it... this is for OpenGL so I'm not sure how similar it might be for DirectX, but I think you can get the concept and apply it if you know your stuff with DX Shaders.

 

Besides the usual Vector3 vertex_position, Vector2 vertex_UV and Vector3 vertex_normal in the shader, you'll need two more: Vector4 bones_weights and Vector4 bones_indexes.

Also you'll need an uniform Matrix4x4 called bone_animation[32] (or 64).

 

This bone_animation will hold your bones' data so you're limited by up to 32 bones per model. You can increase it if you want but it'll just be a waste of space if you're not really using it.

Another limitation (sorta of) is that each vertex can only be affected by UP TO FOUR bones. That's why you're using Vector4's for bones indexes and weights. You can use another variable if you want or even multiple, but then you would need to make some more additions to the code that might slow down a bit... still, it's up to you and depending on your needs.

 

Shader code logic:

void main()
{
    //the vertex basic data here
    vec3 vertexPosition = vertex_position; 

    //checking first bone, applying it's weight
    //I'm getting the Matrix4x4 containing the bone data, getting the index of the first bone and multiplying by it's weight.
    vertexPosition = vertexPosition * (bone_animation[bone_indexes.x] * bone_weight.x);
    //Do this for all 4 possible bones affecting this vertex
    vertexPosition = vertexPosition * (bone_animation[bone_indexes.y] * bone_weight.y);
    vertexPosition = vertexPosition * (bone_animation[bone_indexes.z] * bone_weight.z);
    vertexPosition = vertexPosition * (bone_animation[bone_indexes.w] * bone_weight.w);

    //By here this vertex has been fully skinned, multiply it as usual for your MVP matrix and you're done
    gl_Position = objectTransformationMatrix * vertex_position;
}

Oh by using this you also need to make sure of a few things, that the ROOT bone (index 0) is an identity matrix or that you pass some index for an identity matrix when there's no more bones affecting that vertex (so it just multiply by 1).

 

With this, for each model you have on screen you'll need to keep and track only their bones_animation and upload it to the card every frame instead of modifying their vertex data. That's why it's faster too.

This is called shader skinning and I think you can find the sources where I got this from on google, though at the time I googled them I found very few on it (that I could understand at least).

 

Now, this is the basic idea... you can get it a little bit faster if you change your data a bit. Instead of storing your bones transformations as matrices and uploading a float * 16 per animated model every frame, you can store only a vector3 and a vector4 and apply quaternion math to skin a vertex. You'll be uploading then float * 7 per model every frame then, and the shader will calculate everything else.

I couldn't which is faster on the shader (I haven't looked on debugging shaders yet), so it could be faster or slower... anyway, the idea is to use quaternion * vertex math to figure a vertex's rotated point and then translate it by the bone translation.

 

The shader code would be:

//uniform mat4 boneAnimation[32]; 
//mat4 containing all the bone transformations, unused for now

uniform vec3 boneTranslation[32]; //Only the translations of each bone
uniform vec4 boneRotation[32]; //And their rotations in quaternion form

//This is the function that will do the quaternion * vector3
void applySkin(in vec3 vertexPosition, in vec3 boneTranslation, in vec4 boneRotation, in float boneWeight, out vec3 updatedVertexPosition)
{
    vec3 cross;
    cross.x = (boneRotation.y * vertexPosition.z - vertexPosition.y * boneRotation.z) * 2;
    cross.y = (boneRotation.z * vertexPosition.x - vertexPosition.z * boneRotation.x) * 2;
    cross.z = (boneRotation.x * vertexPosition.y - vertexPosition.x * boneRotation.y) * 2;

    vec3 crossQuat;
    crossQuat.x = boneRotation.y * cross.z - cross.y * boneRotation.z;
    crossQuat.y = boneRotation.z * cross.x - cross.z * boneRotation.x;
    crossQuat.z = boneRotation.x * cross.y - cross.x * boneRotation.y;

    cross.x = cross.x * boneRotation.w;
    cross.y = cross.y * boneRotation.w;
    cross.z = cross.z * boneRotation.w;

    updatedVertexPosition = vertexPosition + ((cross + crossQuat + boneTranslation) * boneWeight);
}

void main()
{
    //same logic, multiply the vertex per all 4 possible bones affecting it
    //by the way if you want more than 4 here is where you'll have to adapt it and add another variable somewhere
    vec3 skinnedVertex;

    applySkin(vertex_position, boneTranslation[bone_indexes.x], boneRotation[bone_indexes.x], bone_weight.x, skinnedVertex);
    applySkin(vertex_position, boneTranslation[bone_indexes.y], boneRotation[bone_indexes.y], bone_weight.y, skinnedVertex);
    applySkin(vertex_position, boneTranslation[bone_indexes.z], boneRotation[bone_indexes.z], bone_weight.z, skinnedVertex);
    applySkin(vertex_position, boneTranslation[bone_indexes.w], boneRotation[bone_indexes.w], bone_weight.w, skinnedVertex);

    gl_Position = objectMVP * skinnedVertex;
}

This way you'll only need to worry about getting the data in the right format before, translations and rotations per bone and upload it every frame.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0