Yo,
I''ve been working on my lwstodml converter, and I''ve come across a problem.
I''m reading keyframe data from the file, and it reads ok (or so it seems), but when I cycle through all the joints and keyframes, some time values are wrong, even though I definitely wrote them to the same memory address!
Here''s a snippet of code, which may help (and this time, I am opening my files correctly
)
Reading from the file:
for (int i=0; i<numChannels; i++)
{
//Skip Channel n and
//{ Envelope
fgets(buffer,255,in);
fgets(buffer,255,in);
//Get number of keys
fgets(buffer,255,in);
sscanf(buffer,"%d",&objectMotion.numKeys);
if (objectMotion.keys==NULL)
objectMotion.keys=new Keyframe[objectMotion.numKeys];
//Read key data
for (int j=0; j<objectMotion.numKeys; j++)
{
fgets(buffer,255,in);
float* value=NULL;
//Optimize!
switch (i)
{
case 0: //X
value=&objectMotion.keys[j].vPosition.x;
break;
case 1: //Y
value=&objectMotion.keys[j].vPosition.y;
break;
case 2: //Z
value=&objectMotion.keys[j].vPosition.z;
break;
case 3:
value=&objectMotion.keys[j].vRotation.x;
break;
case 4:
value=&objectMotion.keys[j].vRotation.y;
break;
case 5:
value=&objectMotion.keys[j].vRotation.z;
break;
default:
//Bit hacky. Skips through the whole key since we don''t
//want to know about scale data
continue;
}
char* keyData=strstr(buffer,"Key");
sscanf(keyData,"Key %f %f",value,&objectMotion.keys[j].time);
}
fgets(buffer,255,in); //Ignore behaviours
fgets(buffer,255,in); //Ignore }
}
fgets(buffer,255,in); //Ignore empty line after motion data
}
The code to print the keyframe data is just a simple for loop which cycles through all keyframe and data.
This is what the typical bone data from a lws file looks like:
AddBone
BoneName center_pivot
ShowBone 1 4
BoneActive 1
BoneRestPosition 0 0.121 -0.022
BoneRestDirection 0 0 0
BoneRestLength 0.027
BoneStrength 1
ScaleBoneStrength 1
BoneMotion
NumChannels 9
Channel 0
{ Envelope
13
Key 0 0 0 0 0 0 0 0 0
Key 0 0.16666667 0 0 0 0 0 0 0
Key 0 0.2 0 0 0 0 0 0 0
Key 0 2.0333333 0 0 0 0 0 0 0
Key 0 3.6666667 0 0 0 0 0 0 0
Key 0 4.6333332 0 0 0 0 0 0 0
Key 0 4.6666665 0 0 0 0 0 0 0
Key 0 4.8666668 0 0 0 0 0 0 0
Key 0 5.0666666 0 0 0 0 0 0 0
Key 0 5.1866665 0 0 0 0 0 0 0
Key 0 5.3466668 0 0 0 0 0 0 0
Key 0 5.4266667 0 0 0 0 0 0 0
Key 0 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 1
{ Envelope
13
Key 0.121 0 0 0 0 0 0 0 0
Key 0.121 0.16666667 0 0 0 0 0 0 0
Key 0.121 0.2 0 0 0 0 0 0 0
Key 0.121 2.0333333 0 0 0 0 0 0 0
Key 0.121 3.6666667 0 0 0 0 0 0 0
Key 0.121 4.6333332 0 0 0 0 0 0 0
Key 0.121 4.6666665 0 0 0 0 0 0 0
Key 0.121 4.8666668 0 0 0 0 0 0 0
Key 0.121 5.0666666 0 0 0 0 0 0 0
Key 0.121 5.1866665 0 0 0 0 0 0 0
Key 0.121 5.3466668 0 0 0 0 0 0 0
Key 0.121 5.4266667 0 0 0 0 0 0 0
Key 0.121 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 2
{ Envelope
13
Key -0.022 0 0 0 0 0 0 0 0
Key -0.022 0.16666667 0 0 0 0 0 0 0
Key -0.022 0.2 0 0 0 0 0 0 0
Key -0.022 2.0333333 0 0 0 0 0 0 0
Key -0.022 3.6666667 0 0 0 0 0 0 0
Key -0.022 4.6333332 0 0 0 0 0 0 0
Key -0.022 4.6666665 0 0 0 0 0 0 0
Key -0.022 4.8666668 0 0 0 0 0 0 0
Key -0.022 5.0666666 0 0 0 0 0 0 0
Key -0.022 5.1866665 0 0 0 0 0 0 0
Key -0.022 5.3466668 0 0 0 0 0 0 0
Key -0.022 5.4266667 0 0 0 0 0 0 0
Key -0.022 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 3
{ Envelope
13
Key 0 0 0 0 0 0 0 0 0
Key 0 0.16666667 0 0 0 0 0 0 0
Key 0 0.2 0 0 0 0 0 0 0
Key 0 2.0333333 0 0 0 0 0 0 0
Key 0 3.6666667 0 0 0 0 0 0 0
Key 0 4.6333332 0 0 0 0 0 0 0
Key 0 4.6666665 0 0 0 0 0 0 0
Key 0 4.8666668 0 0 0 0 0 0 0
Key 0 5.0666666 0 0 0 0 0 0 0
Key 0 5.1866665 0 0 0 0 0 0 0
Key 0 5.3466668 0 0 0 0 0 0 0
Key 0 5.4266667 0 0 0 0 0 0 0
Key 0 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 4
{ Envelope
13
Key 0 0 0 0 0 0 0 0 0
Key 0 0.16666667 0 0 0 0 0 0 0
Key 0 0.2 0 0 0 0 0 0 0
Key 0 2.0333333 0 0 0 0 0 0 0
Key 0 3.6666667 0 0 0 0 0 0 0
Key 0 4.6333332 0 0 0 0 0 0 0
Key 0 4.6666665 0 0 0 0 0 0 0
Key 0 4.8666668 0 0 0 0 0 0 0
Key 0 5.0666666 0 0 0 0 0 0 0
Key 0 5.1866665 0 0 0 0 0 0 0
Key 0 5.3466668 0 0 0 0 0 0 0
Key 0 5.4266667 0 0 0 0 0 0 0
Key 0 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 5
{ Envelope
13
Key 0 0 0 0 0 0 0 0 0
Key 0 0.16666667 0 0 0 0 0 0 0
Key 0 0.2 0 0 0 0 0 0 0
Key 0 2.0333333 0 0 0 0 0 0 0
Key 0 3.6666667 0 0 0 0 0 0 0
Key 0 4.6333332 0 0 0 0 0 0 0
Key 0 4.6666665 0 0 0 0 0 0 0
Key 0 4.8666668 0 0 0 0 0 0 0
Key 0 5.0666666 0 0 0 0 0 0 0
Key 0 5.1866665 0 0 0 0 0 0 0
Key 0 5.3466668 0 0 0 0 0 0 0
Key 0 5.4266667 0 0 0 0 0 0 0
Key 0 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 6
{ Envelope
13
Key 1 0 0 0 0 0 0 0 0
Key 1 0.16666667 0 0 0 0 0 0 0
Key 1 0.2 0 0 0 0 0 0 0
Key 1 2.0333333 0 0 0 0 0 0 0
Key 1 3.6666667 0 0 0 0 0 0 0
Key 1 4.6333332 0 0 0 0 0 0 0
Key 1 4.6666665 0 0 0 0 0 0 0
Key 1 4.8666668 0 0 0 0 0 0 0
Key 1 5.0666666 0 0 0 0 0 0 0
Key 1 5.1866665 0 0 0 0 0 0 0
Key 1 5.3466668 0 0 0 0 0 0 0
Key 1 5.4266667 0 0 0 0 0 0 0
Key 1 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 7
{ Envelope
13
Key 1 0 0 0 0 0 0 0 0
Key 1 0.16666667 0 0 0 0 0 0 0
Key 1 0.2 0 0 0 0 0 0 0
Key 1 2.0333333 0 0 0 0 0 0 0
Key 1 3.6666667 0 0 0 0 0 0 0
Key 1 4.6333332 0 0 0 0 0 0 0
Key 1 4.6666665 0 0 0 0 0 0 0
Key 1 4.8666668 0 0 0 0 0 0 0
Key 1 5.0666666 0 0 0 0 0 0 0
Key 1 5.1866665 0 0 0 0 0 0 0
Key 1 5.3466668 0 0 0 0 0 0 0
Key 1 5.4266667 0 0 0 0 0 0 0
Key 1 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
Channel 8
{ Envelope
13
Key 1 0 0 0 0 0 0 0 0
Key 1 0.16666667 0 0 0 0 0 0 0
Key 1 0.2 0 0 0 0 0 0 0
Key 1 2.0333333 0 0 0 0 0 0 0
Key 1 3.6666667 0 0 0 0 0 0 0
Key 1 4.6333332 0 0 0 0 0 0 0
Key 1 4.6666665 0 0 0 0 0 0 0
Key 1 4.8666668 0 0 0 0 0 0 0
Key 1 5.0666666 0 0 0 0 0 0 0
Key 1 5.1866665 0 0 0 0 0 0 0
Key 1 5.3466668 0 0 0 0 0 0 0
Key 1 5.4266667 0 0 0 0 0 0 0
Key 1 5.6666665 0 0 0 0 0 0 0
Behaviors 1 1
}
PivotRotation 0 0 -180
ParentItem 10000000
GoalObject 5
GoalStrength 1
I push_back the joints vector whenever I come across an AddBone char string, and there doesn''t seem to be any irregularities.
Here''s an example I got from my log data of what the problem is:
//After reading it from the file
0 0 0x890cf4 0
0 1 0x890d14 166
0 2 0x890d34 200
0 3 0x890d54 2033
0 4 0x890d74 3666
0 5 0x890d94 4633
0 6 0x890db4 4666
0 7 0x890dd4 4866
0 8 0x890df4 5066
0 9 0x890e14 5186
0 10 0x890e34 5346
0 11 0x890e54 5426
0 12 0x890e74 5666
//Printing it out later
0 0 0x890cf4 1
0 1 0x890d14 0
0 2 0x890d34 0
0 3 0x890d54 166
0 4 0x890d74 200
0 5 0x890d94 2033
0 6 0x890db4 3666
0 7 0x890dd4 4633
0 8 0x890df4 4666
0 9 0x890e14 4866
0 10 0x890e34 5066
0 11 0x890e54 5186
0 12 0x890e74 5346
Sorry for the really long post, but this issue has been bugging me for the past week or so, and I can''t see a reason why the values should change.
CloudNine