PDA

View Full Version : SDK - problems with loop that Export at keyframe X


stigatle
03-26-2012, 08:46 AM
I'm running into some very stupid problem,
All I want is for my loop to run through X key frames and export the position of the current object.
It does loop fine, but it always returns the value on frame 0.

My loop is like this:
(the totalKeyframeTime variable is the amount of frames to export).
the reason for (AnimBegin + v) is to make it count from the X startframe for this animation.

I get my bone node like this:
before the loop.

for(int v = 0; v < totalKeyframeTime; ++v)
{
Point3 ang;
TimeValue tval;
tval = TimeValue(animBegin +v);
GetCOREInterface()->SetTime(tval);
Matrix3 nodeTM2 = boneNode->GetNodeTM(GetCOREInterface()->GetTime());
Matrix3 objTM2 = boneNode->GetObjectTM(GetCOREInterface()->GetTime());
Point3 objTrans2 = objTM2.GetTrans();
fprintf(s_pStreammma,"\t\t\t<k t=\"%i\" x=\"%f\" y=\"%f\" z=\"%f\"/>\n",v, objTrans2.x,objTrans2.y,objTrans2.z);
}

I am obviously missing something, or doing it wrong, so if you have any hints then I'd certainly appreciate it.

thanks in advance.

stigatle
03-26-2012, 10:01 AM
I solved my own question by converting the time to ticks.
I mistakenly thought that I could send in the frame number.


example code:

for (int currbone=0;currbone<jointCount;currbone++)
{
int time = GetCOREInterface()->GetTime();

INode* boneNode = skin->GetBone(currbone);
int totalKeyframeTime = animEnd - (animBegin);

int ticks = GetTicksPerFrame();
//4800 ticks per frame.
int tempticktime = GetCOREInterface()->GetTime() * ticks;

mprintf("Total keyframe time = %i\n", totalKeyframeTime);
mprintf("Tick time = %i\n", tempticktime);

fprintf(s_pStreammma,"\t<Bone id=\"%i\">\n",currbone);
fprintf(s_pStreammma, "\t\t<position num=\"%i\">\n",totalKeyframeTime);

for(int v = 0; v < totalKeyframeTime; ++v)
{
Point3 ang;
TimeValue tval;
tval = TimeValue(animBegin +v);
GetCOREInterface()->SetTime(tval * ticks);
Matrix3 nodeTM2 = boneNode->GetNodeTM(GetCOREInterface()->GetTime());
Matrix3 objTM2 = boneNode->GetObjectTM(GetCOREInterface()->GetTime());
Point3 objTrans2 = objTM2.GetTrans();
fprintf(s_pStreammma,"\t\t\t<k t=\"%i\" x=\"%f\" y=\"%f\" z=\"%f\"/>\n",v, objTrans2.x,objTrans2.y,objTrans2.z);
}
}

Klunk
03-28-2012, 08:08 AM
I handle the same thing from the IGame wrapper, could easily use "trad" SDK methods, as so...

void DumpBoneAnimation(IGameNode* child)
{
// these are initialized else where but you can get the gist

TimeValue startFrame = pIgame->GetSceneStartTime();
TimeValue endFrame = pIgame->GetSceneEndTime();
TimeValue tickperFrame = pIgame->GetSceneTicks();

int k;
TimeValue t;
Point3 position;
AffineParts affparts;
float rotation[3];


for (k = 0, t = startFrame; t <= endFrame; t += tickperFrame,k++)
{
// the parent case

if(child->GetNodeParent() == NULL) // this is the root node
{

// this should be the root node so just compute its position & orientation

Matrix3 node_tm = child->GetMaxNode()->GetNodeTM(t);
node_tm.NoScale(); // Clear these out because they **** things up
position = node_tm.GetTrans();
decomp_affine(node_tm, &affparts);
QuatToEuler(affparts.q, rotation);

// process rotation and position here

}
else
{

// compute the bone positions and angles in its parents space

Matrix3 node_tm = child->GetMaxNode()->GetNodeTM(t);
Matrix3 parent_node_tm = child->GetNodeParent()->GetMaxNode()->GetNodeTM(t);
node_tm.NoScale(); // Clear these out because they **** things up
parent_node_tm.NoScale();
Matrix3 local_tm = node_tm * Inverse(parent_node_tm);
position = local_tm.GetTrans();
decomp_affine(local_tm, &affparts);
QuatToEuler(affparts.q, rotation);

// process rotation and position here


}
}
//......

CGTalk Moderation
03-28-2012, 08:08 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.