Author Topic: Is Animation.getKeyFrames().length always the exact size of the total number...  (Read 3557 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
...of keyframes? You should put that in the docs.

For now, I'm going to assume that it is. ; )

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
This is an animation splitter. The following code, instead of naming the first clip the first animation's name, names the second animation that. The second gets the first one's name, the third the second's, and so forth. The first clip seems to get an automatic name of "complete:"

Code: [Select]
     Mesh[] keyFrames = singleStream.getKeyFrames();
     Animation animations = new Animation(keyFrames.length);
     int numberOfAnimations, totalFramesInMax = 0;
     for (numberOfAnimations = 0; numberOfAnimations < nameFields.length && nameFields[numberOfAnimations].getText().trim().length() > 0; numberOfAnimations++)
totalFramesInMax += Integer.parseInt(numberOfFramesFields[numberOfAnimations].getText().trim());
     double divider = (double)totalFramesInMax/(double)keyFrames.length;
     System.out.println("Total Frames in Max: "+totalFramesInMax +" Divider: "+divider +" Number of KeyFrames: "+keyFrames.length);
     for (int i = 0; i < numberOfAnimations; i++) {
final int animationFrames = Integer.parseInt(numberOfFramesFields[i].getText().trim());
final int totalFrames = keyFrames.length;
animations.createSubSequence(nameFields[i].getText().trim());
for (int kf = 0; kf < animationFrames/divider; kf++)
     animations.addKeyFrame(keyFrames[kf]);
System.out.println("Finished for: "+nameFields[i].getText());
     }
     model.setAnimationSequence(animations);

Is this a jpct bug?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
IIRC, it's by design. The docs say:

Quote
The sub-sequence will be numbered starting from 1. 0 is a special case as is represents the animation as a whole.

Isn't that what you are experiencing?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
OK, but if it's by design that the animation in slot 0, as printed by the following code, is "complete," then my problem is that the last animation sub-sequence isn't being created. But there are no complaints about the amount of frames and my method prints a message after finishing its parsing.

Code: [Select]
     private void print() {
Animation animation = model.getAnimationSequence();
String[] animationNames = new String[animation.getSequenceCount()];
for (int i = 0; i < animationNames.length; i++) {
     animationNames[i] = animation.getName(i);
     System.out.println("Animation: "+animationNames[i] +", start: "+animation.getSequenceBorders(i+1)[0] +" end: "+animation.getSequenceBorders(i+1)[1]);
}
     }

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Some things use the 0, some don't. This print works. The above parsing had but one problem: it was always restarting the keyframes (I just added a delta at the end of the inner loop).

Code: [Select]
     private void printAnimations() {
System.out.println("****************Animations****************");
Animation animation = model.getAnimationSequence();
animationNames = new String[animation.getSequenceCount()];
for (int i = 0; i < animationNames.length; i++) {
     animationNames[i] = animation.getName(i+1);//i+1
     int[] borders = animation.getSequenceBorders(animation.getSequence(animationNames[i]));
     System.out.println("Animation: "+animationNames[i] +", start: "+borders[0] +" end: "+borders[1]);
}
System.out.println("****************Animations****************\n");
      }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
I think that I don't understand your actual problem. The idea is: You create a new sub sequence, add all the keyframes, continue with the next one. If you animate a sequence, it's limited to that sequence's animations unless you animate 0, which includes all keyframes. What's the actual issue with that?
« Last Edit: June 18, 2018, 07:52:31 am by EgonOlsen »

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
 Since I've already solved it, there's no problem. But what I did there was a splitter: the MD2 exporter exports all animations as a single stream. My program splits them and saves a serialized copy.