[Closed] SDK – problems with loop that Export at keyframe X
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," <k t=\"%i\" x=\"%f\" y=\"%f\" z=\"%f\"/>
",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.
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
", totalKeyframeTime);
mprintf("Tick time = %i
", tempticktime);
fprintf(s_pStreammma," <Bone id=\"%i\">
",currbone);
fprintf(s_pStreammma, " <position num=\"%i\">
",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," <k t=\"%i\" x=\"%f\" y=\"%f\" z=\"%f\"/>
",v, objTrans2.x,objTrans2.y,objTrans2.z);
}
}
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
}
}
//......