jPCT - a 3d engine for Java > Support

Is Animation.getKeyFrames().length always the exact size of the total number...

(1/2) > >>

AGP:
...of keyframes? You should put that in the docs.

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

AGP:
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: ---      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);

--- End code ---

Is this a jpct bug?

EgonOlsen:
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.

--- End quote ---

Isn't that what you are experiencing?

AGP:
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: ---     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]);
}
     }

--- End code ---

AGP:
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: ---     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");
      }

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version