Game Development Community

Having Problems writing sequences

by James Urquhart · in Torque Game Engine · 08/28/2003 (7:37 am) · 1 replies

I am currently writing an exporter for blender, but i have come across a stumbling block when i am writing the sequences. The animation just doesn't do anything, even though it is supposed to rotate a bone, deforming a cylinder mesh. =/

The actual exporter reads in a text file, and this seems to work pretty well. But writing the actual sequence data to the DTS is another more difficult problem.

Currently, the part of the text file relating to the sequence data looks like :

s ambient 1 5.000000 0 144 3
b 0 0
t 0.591116 -0.377658 0.000000
r 0.999981 0.006241 0.000041 -0.000000
x
b 1 0
t -0.002700 2.955626 0.000000
r 0.999932 -0.011698 -0.000065 0.000000
x
b 2 0
t -0.049614 3.021038 0.000000
r 1.000000 0.000000 0.000000 0.000000
x
<...Similar b -> x blocks till frame count is 143 ...>
x

everything from the s to the last x is a sequence block. Its name is "ambient", flags are "1", framerate is "5" fps, start frame is 0, the number of frames is 144, and the node count is 3 (3 nodes are used)

Can anyone suggest what i am doing wrong? =/
To recap, the mesh just sits there and does not deform whe i load it in the "-show" tool, even though the "ambient" anim is playing.

(if your wondering, i used the milkshape exporter as a base for this code)

#1
08/28/2003 (7:38 am)
More importantly, here is the code that reads in this data and makes the sequence :

void ExporterShape::AddNodeTranslation(FILE *fp, float scaleFactor, Sequence s)
   {
     char buffer[256];
     Point *translations;
     Quaternion *rotations;
     char ch;
     int bIndex, frame;
     float vertex[3];
     float qvertex[4];
     bool bClosed;
     bClosed = false;

     fscanf(fp, "%d %d", &bIndex, &frame);

     int tindex = 0;
     int rindex = 0;

     while (!feof(fp) && !bClosed)
     {
     ch = fgetc(fp);
     switch (ch) {
       case 't':
         fscanf(fp, "%f %f %f", &vertex[0], &vertex[1], &vertex[2]);
         s.matters.translation[bIndex] = true;
         translations = &nodeTranslations[s.baseTranslation + tindex * s.numKeyFrames];
         translations[frame] = nodeDefTranslations[bIndex] + nodeDefRotations[bIndex].apply(Point(vertex[0],vertex[1],vertex[2]) * scaleFactor);
         tindex++;
         fgets(buffer, 100, fp);
       break;
       case 'r':
         fscanf(fp, "%f %f %f %f", &qvertex[0], &qvertex[1], &qvertex[2], &qvertex[3]);
         s.matters.rotation[bIndex] = true;
         rotations = &nodeRotations[s.baseTranslation + rindex * s.numKeyFrames];
         rotations[frame] = Quaternion(qvertex[0],qvertex[1],qvertex[2],qvertex[3]) * nodeDefRotations[bIndex];
         rindex++;
         fgets(buffer, 100, fp);
       break;
       case 'x':
         bClosed = true;
       break;
       default:
       break;
     }

   }
   	 fgets(buffer, 100, fp);
  }

   void ExporterShape::AddSequence(FILE *fp, float scaleFactor)
   {
     Sequence s;
     char buffer[256];
     int i,j,flags,nodeCount;
     float fps;
     bool bClosed;
     bClosed = false;
     char ch;

     fscanf(fp, "%s %d %f %d %d %d", &buffer, &flags, &fps, &i, &j,&nodeCount);
     printf("Writing Sequence %s\n",buffer);
     fgets(buffer, 100, fp);
     /* FORMAT: <name> <flags> <fps> <Start Frame> <End Frame> <Node Count> */

     s.flags           = flags;
     s.nameIndex       = addName("ambient") ;
     s.numKeyFrames    = j - i; // j is bigger than i!!
     s.duration        = float(s.numKeyFrames) / fps;
     s.baseTranslation = nodeTranslations.size() ;
     s.baseRotation    = nodeRotations.size();

     // Count how many nodes are affected by the sequence and
     // set the sequence.matter arrays to indicate which ones.
     s.matters.translation.assign (nodes.size(), false);
     s.matters.rotation.assign    (nodes.size(), false);

     // Add the node translations to the global tables
     nodeTranslations.resize (nodeTranslations.size() + nodeCount * s.numKeyFrames);
     nodeRotations.resize (nodeTranslations.size());

     while (!feof(fp) && !bClosed)
     {
       ch = fgetc(fp);
       switch (ch) {
       case 'b':
         this->AddNodeTranslation(fp, scaleFactor, s);
       break;
       case 'x':
         bClosed = true;
       break;
       default:
         fgets(buffer, 100, fp);
       break;
       }
     }

     printf("Read Sequence\n");

     /*  */

     sequences.push_back(s);
   }