www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on June 14, 2018, 09:39:34 pm

Title: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: AGP on June 14, 2018, 09:39:34 pm
...of keyframes? You should put that in the docs.

For now, I'm going to assume that it is. ; )
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: AGP on June 15, 2018, 05:12:24 am
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?
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: EgonOlsen on June 15, 2018, 09:11:41 am
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?
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: AGP on June 15, 2018, 06:54:22 pm
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]);
}
     }
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: AGP on June 15, 2018, 08:41:55 pm
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");
      }
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: EgonOlsen on June 17, 2018, 12:23:24 pm
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?
Title: Re: Is Animation.getKeyFrames().length always the exact size of the total number...
Post by: AGP on June 17, 2018, 08:18:12 pm
 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.