AnimControl additional method

Hi there





Because of a project I'm planning, I have studied some of the sourcecode of the animation system in jme3.

I found out, that AnimControl has got all the information about animation in it.



My problem is that I need to get direct access to this information.

So I just made a little hack for it:


package com.jme3.animation;

import com.jme3.scene.Mesh;
import com.jme3.scene.Node;

/**
 * A hacked class to get more control over the used animations.
 *
 */
public class AnimControlHacked
extends AnimControl
{
   /**
    * Does exactly the same as the original constructor.
    *
    * @param model
    * @param meshes
    * @param skeleton
    */
   public AnimControlHacked(Node model, Mesh[] meshes, Skeleton skeleton)
   {
      super(model, meshes, skeleton);
   }
   
   /**
    * "Casts" the AnimControl control to a AnimControlHacked.
    *
    * @param model
    * @param control
    */
   public AnimControlHacked(Node model, AnimControl control)
   {
      super(model, control.getTargets(), control.getSkeleton());
      this.animationMap = control.animationMap;
      this.channels = control.channels;
   }
   
   /**
    * Adds a new animation to the animationMap.
    * @param key
    * @param value
    */
   public void addAnimation(String key, BoneAnimation value)
   {
      if(animationMap.get(key) == null)
         animationMap.put(key, value);
      else
         throw new RuntimeException("key for new entry in animationMap already exists.");
   }
   
   /**
    * Deletes a animation out of animationMap.
    * @param key
    */
   public void removeAnimation(String key)
   {
      animationMap.remove(key);
   }

}



The reason is that I need to make a new animation for my model in runtime, so it's necessary that I can add and remove a new temporary animation.

But it would also be possible to just add these functions in the original file, wouldn't it? ;)
Or did I get something completely wrong? :P


Greetings
kolibri7

thanks a lot :wink:

but wouldn't it be better if we could use for "public void removeAnim(BoneAnimation anim)" a String as parameter instead of a BoneAnimation?

this way, we don't have to save the animation we added anywhere…

and i think it would be useful if addAnim(…) threw an exception if the name already exists in the HashMap, that would help to prevent some failures…



greetings

I guess its fine to add it. Reason it wasn't there was because I thought people might try to take animations from other models and try to add them to other controls only to realize it doesn't work. However making your own animations pro grammatically is definitely a good reason so I guess I'll add it.

With the latest SVN revision these methods are now available.

Yeah I suppose it is a bit misleading to just replace the existing-named animation. I will add the changes soon then.