* the skeleton of the node
* @param animationNames
* the names of the skeleton animations
*/
public void applyAnimations(Node node, Skeleton skeleton, List<String> animationNames) {
node.addControl(new SkeletonControl(skeleton));
blenderContext.setNodeForSkeleton(skeleton, node);
if (animationNames != null && animationNames.size() > 0) {
List<Animation> animations = new ArrayList<Animation>();
for (String animationName : animationNames) {
BlenderAction action = actions.get(animationName);
if (action != null) {
BoneTrack[] tracks = action.toTracks(skeleton);
if (tracks != null && tracks.length > 0) {
Animation boneAnimation = new Animation(animationName, action.getAnimationTime());
boneAnimation.setTracks(tracks);
animations.add(boneAnimation);
Long animatedNodeOMA = ((Number)blenderContext.getMarkerValue(ObjectHelper.OMA_MARKER, node)).longValue();
blenderContext.addAnimation(animatedNodeOMA, boneAnimation);
}
} else {
LOGGER.log(Level.WARNING, "Cannot find animation named: {0}.", animationName);
}
}
if (animations.size() > 0) {
AnimControl control = new AnimControl(skeleton);
HashMap<String, Animation> anims = new HashMap<String, Animation>(animations.size());
for (int i = 0; i < animations.size(); ++i) {
Animation animation = animations.get(i);
anims.put(animation.getName(), animation);
}
control.setAnimations(anims);
node.addControl(control);
//make sure that SkeletonControl is added AFTER the AnimControl
SkeletonControl skeletonControl = node.getControl(SkeletonControl.class);
if(skeletonControl != null) {
node.removeControl(SkeletonControl.class);
node.addControl(skeletonControl);
}
}