I did the coding and the results are below. Please, take a look if it's correct. However, it seems I'd need to do that on each animation transition (ie. create animation with last frame of animation that ended and first frame of new animation) to provide smooth transition, right? Is there really no easier way?
public static ModelAnimation createSubAnimation(ModelAnimation originalAnimation, String animationName, Collection<Integer> frameNumbers, float fps) {
int frameCount = frameNumbers.size();
//create controllers for each model subshape with set of selected frames
List<KeyFrameController> controllers = new ArrayList<KeyFrameController>();
for (KeyFrameController originalController : originalAnimation.getControllers()) {
MeshDeformationKeyFrameController meshDeformationController = (MeshDeformationKeyFrameController) originalController;
MeshDeformationKeyFrame[] controllerFrames = new MeshDeformationKeyFrame[frameCount];
int newFrameNo = 0;
for (int origFrameNo : frameNumbers) {
controllerFrames[newFrameNo] = meshDeformationController.getFrame(origFrameNo);
newFrameNo++;
}
controllers.add(new MeshDeformationKeyFrameController(controllerFrames, meshDeformationController.getTarget()));
}
ModelAnimation customAnimation = new ModelAnimation(animationName, frameCount, fps, controllers.toArray(new KeyFrameController[controllers.size()]));
{ //create mount transforms with set of selected frames
int mountCount = originalAnimation.getMountTransformFrame(0).length;
Matrix4f[][] customMountTransformFrames = new Matrix4f[frameCount][mountCount];
int newFrameNo = 0;
for (int origFrameNo : frameNumbers) {
for (int mountNo = 0; mountNo != mountCount; mountNo++) {
customMountTransformFrames[newFrameNo][mountNo] = originalAnimation.getMountTransformFrame(origFrameNo)[mountNo];
}
newFrameNo++;
}
customAnimation.setMountTransformFrames(customMountTransformFrames);
}
return customAnimation;
}