Spatial Transformer

hello again,

  Im working on animating my models using spatial transformer, just a quick straight forward q, im having a starters of problem with

      …setObject(spatial, 0 , 1);

i keep getting a problem with the above, it keeps on giving me this error, what are the ints for? What would i have to do if i want to just use my walk animation


at com.jme.animation.SpatialTransformer.setObject(Unknown Source)

at Game.Chase.botanimation(

at Game.Chase.updateCycle(

at Game.Chase.rotateBot(

My first guess would be You use the default constructor for SpatialTransformer without parameters which doesn't create the toChange array

so setObject() simply can't access the array ?

edit: same goes for pivots and parentIndexes

this is what i used in my code, it just a starting of bit of code, i tried to follow the tutorial at this link

where am i going wrong? should i use toChange to reference one model?

your help would be much appreciated

 public void botanimation()
       sc = new SpatialTransformer(1);
       if(hit== true)
          //do animation
          sc.setNewAnimationTimes(1.0f, 28.0f);

Rereading Your first post i'm not sure We interpret the purpose of SpatialTransformer the same.

From the javadoc of SpatialTransformer:

 * This class animates spatials by interpolating between various
 * transformations. The user defines objects to be transformed and what
 * rotation/translation/scale to give each object at various points in time. The
 * user must call interpolateMissing() before using the controller in order to
 * interpolate unspecified translation/rotation/scale.

I think it's for animating a spatial along a curve and making it rotate and scale along it's way and not for playback of (walk) animations.

So what would be the best class for animating a node in my game, i tried keyframecontroller, but that is for a trimesh and will not work with my node.

thanks for your help

That really depends on what You want to do.

If You want to animate the node by moving it around on a fixed path like in the Tutorial You mentioned perhaps rotating and scaling like eg. a space station orbiting a planet in a steady manner then SpatialController or com.jme.curve.CurveController are Your bet (imho).

(or implement another type of controller by subclassing abstract com.jme.scene.Controller)

If You want to animate an actor model like a bot to walk, jump, … then You should take a closer look at the jmetest.renderer.loader package

as this is most of the time done by animating a model in an 3D modeller package and then exporting it to a supportet format then loading

it into jme. But that is a whole other story and You should search the forums, the wiki and other sources to get a basic understanding on character animation.

I have an ms3d model, i have loaded it in and converted it to jme format, i have edited the model to walk using the milksahpe 3d application, there are 200 keyframes that define different movements of the bot, this will be like an AI, for example if the bot is hit by a bullet it will move back a bit to give the idea it has been hit and if it is hit more then 5 times it will fly back onto the ground and respawn at another coordinate, keyframe 28 - 50 is for being hit and key frame 1-28 is for walking, right now my bot loads in but goes throught the whole keyframe 1-200, what i want to do is to get the bot to do only certain things, first i thought spatialtransformer, but it will not work giving me the above error.

  i hope this explains what im trying to do

To do what You intend You have to get the JointController from Your ms3d File (I hope it's only one) and set

the start and end frame to use.

For jmetest.renerer.loader.TestMilkJmeWrite (An animated ms3d) an example would be:

        JointController jc = (JointController)i.getController(0);
        jc.setTimes(1, 10);      

( add to the end of simpleInitGame() )
where i is the loaded Node containing the model and it's controllers

whith JointController.setTimes(int start, int end) You can set start and end frame of the animation with first frame being 1 !

if You don't get a JointController with above code then You might inspect Your model to see if and where it contains controllers.

sorry about bringing this up again, just do you know anywhere which could help me use jointController, i have implemented a simple one for the model to walk which is shown below, but it doesnt do anything, i really need a bit of help coz im running out of time to get this done

                JointController jc = (JointController)fighter.getController(0);
                jc.setTimes(1, 30);

sorry about bringing this up again problem, that just shows i didn't make my post clear enough.

The controller has to be already in the model as You imported it to be set up and of any use, You just have to get it from the model.


  sorry bou this, but could you explain what you mean in a bit more detail, could you provide me with a code snippet to help me understand it.

  your help is really appreciated

How can i get the controller from the model? do i export the model or just just save it?

Ok, i did a bit of messing around with my code, and i found out that when im within 50 of my bot it moves in my direction because i use spatial.lookAt(), but it does not do the animation i want it to do until after i have moved more then 50 away from my the bot stops following me and does the specified animations ie. walking, so i think that it has something to do with spatial.lookAt(), then i decided to use the .setRotation method in the JointController class, but the bot follows me but it moves about a lot, here are my questions;

1.  would the spatial.lookAt() prevent the models animation ie. walking, running etc. from taking place?

2. to rotate the bot in my direction would it be better to use spatial.lookAt() or .setRotation?

i have given the could below so yas have an idea what im trying to do

any help would be much appreciated

private void chasePrey(){
        if(predpos.x > nextWayPoint.x)
        else if(predpos.x < nextWayPoint.x)
        if(predpos.z > nextWayPoint.z)
        else if(predpos.z < nextWayPoint.z)
        float xLoc = predpos.x;
        float zLoc = predpos.z;
        float time = timer.getTimeInSeconds();
        predator.setLocalTranslation(new Vector3f(xLoc, terrainPage.getHeight(xLoc, zLoc), zLoc));
        predator.lookAt( nextWayPoint, new Vector3f( 0, 1, 0 ) );//i either comment out lookAt() oor setRotation
      Quaternion additionalRotation = new Quaternion().fromAngleAxis( FastMath.DEG_TO_RAD*90, new Vector3f( 0, 1, 0 ) );
      additionalRotation.mult( predator.getLocalRotation(), predator.getLocalRotation() );
      ((JointController)predator.getController(0)).setRotation(8, time, additionalRotation);

Glad You got the animation part to work in general.

1.  would the spatial.lookAt() prevent the models animation ie. walking, running etc. from taking place?

I don't think it should

2. to rotate the bot in my direction would it be better to use spatial.lookAt() or .setRotation?

Both should work in my opinion, You should use profiling, if You want to get a better understanding of performance, but in general i'd prefer setting rotations and translations on the models top node and not down the hierarchy somewhere.

From a glance at the code i'd say You shouldn't do:


each update-cycle as that would reset the animation everytime making it look like not animated maybe jittering a bit.
But i can't say if You do that from the code.