Using skeletons from models to make dynamic animations in-game
by Will Burton · in Torque Game Engine · 07/26/2003 (9:32 pm) · 9 replies
I know it's possible. This is not the question. I have a plan do to it. However, even though I've had it a year, I am new to torque.
Plan:
1. design models multipart so thet each piece of biped it directly represented by an indivual part. (1 sphere for 1 ankle)
2. add invisible "hit triangles" to models in key locations (triangle place on top of a shoduler)
3. create pre-animations using biped or bones.
3. write math functions to calculate adjustments for animations to move body part(s), within bounds, to touch specific "hit triangles" (is there math functions I can wrap around to do this?)
Questions:
Is there an easier way?
Can I call on the skeletal structure itself from torque? How?
How are additional animations added into torque?
Plan:
1. design models multipart so thet each piece of biped it directly represented by an indivual part. (1 sphere for 1 ankle)
2. add invisible "hit triangles" to models in key locations (triangle place on top of a shoduler)
3. create pre-animations using biped or bones.
3. write math functions to calculate adjustments for animations to move body part(s), within bounds, to touch specific "hit triangles" (is there math functions I can wrap around to do this?)
Questions:
Is there an easier way?
Can I call on the skeletal structure itself from torque? How?
How are additional animations added into torque?
#2
I was thinking of creating a new dsq for the player made animations, then loading it into the model. But I dont know how I would set the positions for a dynamic IK system for when the player is playing..
Also, for an IK system, I need to know the length of each bone, but I cant seem to find where (if at all) it is stored.
All I need is a lead and I can figure it out, but I seem to have hit a wall.
Dylan
08/07/2003 (3:42 am)
Have you figured much of this out? I was wanting to add a primitive IK system for arm animations when then player uses an object (lever etc), Then maybe extend it so that players could create their own animations ingame. (for a rpg, the users could create their own attack moves etc). Ive looked into both TSShape etc, and I have a thorough understanding of how the animation works now (I think ;) the docs dont have jack about it) but I dont see a way for setting the translation/rotation for the nodes (bones). I was thinking of creating a new dsq for the player made animations, then loading it into the model. But I dont know how I would set the positions for a dynamic IK system for when the player is playing..
Also, for an IK system, I need to know the length of each bone, but I cant seem to find where (if at all) it is stored.
All I need is a lead and I can figure it out, but I seem to have hit a wall.
Dylan
#3
By using something like: getNodeTransform("Bip01 Head"); you can get the transfomr for the head node. I imagine that you could EASILY write a function to set a node transform.
Once you have the node transforms, you can calculate the lengths of the bones, their positions, rotations, etc. All the necessary info is contained in the matrix, and it can be easily modified with existing math functions to do tihngs like translate or rotate a bone.
In otehr words, yes, IK would be possible, all the tools are there. You just need to go ahead and code it in. :)
08/07/2003 (6:50 am)
There is a getNodeTransform function in shapebase. Take a look at it.By using something like: getNodeTransform("Bip01 Head"); you can get the transfomr for the head node. I imagine that you could EASILY write a function to set a node transform.
Once you have the node transforms, you can calculate the lengths of the bones, their positions, rotations, etc. All the necessary info is contained in the matrix, and it can be easily modified with existing math functions to do tihngs like translate or rotate a bone.
In otehr words, yes, IK would be possible, all the tools are there. You just need to go ahead and code it in. :)
#4
And here's a gotcha to look out for. Max aligns bones on the X axis, whereas Torque usually aligns objects on the Y axis (so pitch and roll are interchanged between Max and Torque). My code is a cheat because I was just controlling a single node, so I aligned the model with the bone's local Y axis.
I remember seeing somewhere that Discreet had published a free, simple IK solver suitable for use in games.
08/07/2003 (9:28 am)
I'm not doing anything as ambitious as even simple in-game IK solver, but I've boiled down the essence of what I'm doing in the following pseudocode.// Find the node. I have this in the datablock class since the node is invariant
// across instances.
animNode = shape->findNode("node name");
// Tell the engine that the program is taking control of this code. I have this
// in the class' onNewDataBlock.
mShapeInstance->setNodeAnimationState
(mDataBlock->animNode, TSShapeInstance::MaskNodeHandsOff);
// Call something like this client side to set model position.
// If there are 'interesting' nodes downstream (like weapon mount nodes)
// also call server side so they are positioned correctly.
MatrixF * mat = &mShapeInstance->mNodeTransforms[node];
Point3F defaultPos = mDataBlock->shape->defaultTranslations[node];
mat->set(EulerF(mPitch-mPitchRate*dt, .0f, mYaw-mYawRate*dt), defaultPos);
mShapeInstance->setDirty(TSShapeInstance::TransformDirty);
mShapeInstance->animate();If you want something similar in fully working code, try Paul Dana's turret resource. Your IK solver would need to calculate the correct bone positions -- I'm just using pitch and yaw to control a single node (Paul's resource controls pitch and yaw independently, and so will provide an example of controlling multiple nodes).And here's a gotcha to look out for. Max aligns bones on the X axis, whereas Torque usually aligns objects on the Y axis (so pitch and roll are interchanged between Max and Torque). My code is a cheat because I was just controlling a single node, so I aligned the model with the bone's local Y axis.
I remember seeing somewhere that Discreet had published a free, simple IK solver suitable for use in games.
#5
08/08/2003 (1:08 am)
Interesting. Thanks for the help guys, youve given me that extra bit I needed to get going somewhere with this :D I'll look into it a bit more and if I get anywhere, Ill give you some credit when I make it a resource :D
#6
08/08/2003 (1:14 am)
Hmm I cant seem to find anything about this Discreet IK solver.. any links?
#7
08/08/2003 (1:49 am)
You'll have to google it (try searching on 'discreet open source IK solver') and then dig down. I just remember reading about it, but never looked into it.
#8
EDIT: After looking around, it seems that the Open Source project for MAX was integrated into GMAX.
08/08/2003 (4:46 am)
Bah, It seems Discreet have discontinued that open source thing (well, the website for it isnt working and every reference for it is with max 4). But while I was searching for that I found a very useful site about IK theory so it wasnt a waste after all :D.EDIT: After looking around, it seems that the Open Source project for MAX was integrated into GMAX.
#9
03/22/2005 (11:04 pm)
I know this is old, but I found this thread while doing research on this very same problem. Here is a cool resource on IK solver theory, it might help. There is some source there along with info on what it does.
Associate Ben Garney