# Tweening Questions

This topic is 1571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all!

I started to look into tweening since it looked like a fun and sort of quick way to get some basic animations going on my meshes.

Well, due to the sake of simplicity I decided to implement it on the CPU side first with dynamic buffers. While performance is pitifull, thats to be expected when pushing data back and forth from the CPU to the GPU.

However, I've run into a issue that makes me ask

The OBJ format. I've heard that the blender exporter (correct me if im wrong) will rearrange the vertices from export to export. thus negating any tweening attempts. Since I most comfortable with the OBJ format is there a way around it (I see in the mesh export options in blender, keep vertex order) or is this just wishful thinking. If you think OBJ is a no go. What format do you recommend?

Also, my implementation is based on Advanced Animation with DirectX, i just stuffed all the values into XNA types.

I'm including my tweening implementation just in case I missed something silly that someone could hint to. (And also as a validation that this isn't completely off XD) And also because my meshes when tweening wig out and start rendering crazy polygonal shapes and colors! Also as if I'm referencing out-of bounds garbage memory and passing it to D3D

float time = 0.0f;
float length = 5.0f;

if (isMoving)
{
Time += 5.0f * dt;
if (Time > 5.0f) Time = 0.0f;
}
//Note: vertices[x].at(x) represents a vector of pointers which hold all the info of each subset of the overall mesh

scalar = Time / length;

D3D11_MAPPED_SUBRESOURCE ms;
for (int i = 0; i < mCount; i++) //mCount = subsetMeshCount
{
verticesResult.resize(verticeCount[i]);
for (int j = 0; j < verticeCount[i]; j++)
{
//Interpolate Positions
/////////////////////////////////////////////
float value = (1.0f - scalar);
vecSource *= value;

vecTarget *= scalar;

XMStoreFloat3(&verticesResult.at(j).pos, (vecSource + vecTarget));

//Iterpolate Normals
//////////////////////////////////////////////
value = (1.0f - scalar);
vecSourceNorm *= value;

vecTargetNorm *= scalar;
XMStoreFloat3(&verticesResult.at(j).norm, (vecSourceNorm + vecTargetNorm));

verticesResult.at(j).norm               = vertices[i].at(j).norm;

//Pass along Materials
///////////////////////////////////////////////
verticesResult.at(j).color                = vertices[i].at(j).color;
}

//Lock the dynamic buffer (block the GPU)
///////////////////////////////////////////////////

//Grab a pointer to the data, pass along update vertice info, and remap the buffer
////////////////////////////////////////////////////////////////////////////////////
VertexM *v = reinterpret_cast<VertexM*>(ms.pData);
*v          = verticesResult[0];
bro->devcon->Unmap(vertexBuffer[i], NULL);
}


Any replies are appreciated

-Marcus

Edited by markypooch

##### Share on other sites
What format do you recommend?

If you fell yourself comfortable with all the things that obj file can introduce. Try using Assimp/FBX SDK/wateva to load for example a *.fbx scene files. Those file formats can store huge amount of different types of gemoetry/animations/ect., but it will be fine if you slowly start form those basic things like static meshes/the scene graph/trnasforms, basic node animation and so on. Later on you will probably want your own converter form *fbx/dae/wateva to your own custom format, but those are long and abstract talks.

Edited by imoogiBG

##### Share on other sites

If you are using Visual Studio 2012/2013 it natively supports *.fbx, compiling them into a *.cmo file which can then be read using the DirectXTK library.

The animations that are saved within the FBX are then available to you. Just need to apply the transforms correctly based on the current time etc...

Although it is in C#, my book linked below has a chapter dedicated to implementing animation with Direct3D (Chapter 4 - Animating Meshes with Vertex Skinning). Using an FBX -> CMO, it shows how to perform interpolation between frames using quaternions and spherical interpolation (Slerp).

The basic approach is:

// animation loaded from FBX/CMO file
foreach (keyFrame in animation)
{
if (keyFrame.Time <= time) {
// use this keyFrame transform for the appropriate bone index
transforms[keyFrame.BoneIndex] = keyFrame.Transform;
}
else
{
// perform interpolation towards next future keyFrame
}
}

// Apply bone transforms (i.e. apply transform of parent upon each child bone)

// Convert from bind pose into bone space using inverse of bind pose


Some screenshots showing incorrect and correct bone transforms:

[sharedmedia=gallery:images:5182]
[sharedmedia=gallery:images:5181]

Edited by spazzarama

##### Share on other sites

Ok, so I see a strong push for .fbx.

Well, thanks to assimp it should be rather simple to just re-export and reload my mesh as a .fbx.

I see you both are recommending skeletal animation over tweening.

My main reasoning for tweening was to get something up and going (in the animation department) fast!

But other then that, I'm sure I can opt-out for skeletal animation instead. Assimp will handle all the bone and skeletal loading for me.

My only real challenge then is to actually get it up and going. (I've never done anything more complicated then standard matrice transformations and rotations on single meshes)

Thanks for the replies (And especially for the book link!)

-Marcus

P.s. The image were you show the polarity's between a proper animated mesh and the un-proper. The latter could be used for a glitch level ;)

Edited by markypooch

##### Share on other sites

P.s. The image were you show the polarity's between a proper animated mesh and the un-proper. The latter could be used for a glitch level ;)

Wait until you see what that looks like during an animation!

Skeletal animation just makes it so easy once you have it set up! Using Blender, Maya or whatever to do your hardcore animation work and then just bring that in.

Assuming you are importing all your animations correctly, it really is as simple as the pseudo code above - oh and then some shader code of course.

##### Share on other sites

Well I'll have to do it then (as opposed to try to do it)

Ill start by importing my meshes as .fbx today. And go from there.

I'll follow along with the e-book. C# in my opinon looks like Java, which I can translate Java to C++ well enough.

Once again thanks for pointing out some resources. I suppose Ill keep my static meshes. (i.e. Trees, hedges, and statues) in OBJ. While anything I animate I'll

just use .fbx

-Marcus

##### Share on other sites

One other point to consider is that tweening requires an enormous amount of vertex memory, since you are essentially creating a keyframe that includes every vertex.  If you make a 10 frame animation, then you have 10x the number of vertices to store!  Skeletal animation drastically reduces the amount of required memory, and trades it for a little bit more runtime computation - but it is still very much worth it.

If you aren't at all familiar with skinning, then check out the old Cg Tutorial chapter on it, which is where I first learned about it: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter06.html

##### Share on other sites

Just a status update, thought you guys might like to know.

Though I haven't implmented Skinning yet, I did tweening to work after I implemented a hardware

version (did my tweening in HLSL) So I must have been doing something silly with the dynamic buffers.

Kinda off topic but the results aren't bad. (I still plan on doing skinning)

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 11
• 10
• 12
• ### Forum Statistics

• Total Topics
632571
• Total Posts
3007127

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!