package jme3test.model.anim;

import com.jme3.animation.AnimControl;
import com.jme3.animation.Animation;
import com.jme3.animation.SpatialTrack;
import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import java.util.HashMap;

public class TestSpatialAnim extends SimpleApplication {

    public static void main(String[] args) {
    	TestSpatialAnim app = new TestSpatialAnim();
        app.start();
    }

    @Override
    public void simpleInitApp() {

        AmbientLight al = new AmbientLight();
        rootNode.addLight(al);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(Vector3f.UNIT_XYZ.negate());
        rootNode.addLight(dl);

        // Create model
        Box box = new Box(1, 1, 1);
        Geometry geom = new Geometry("box", box);
        geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
        Node model = new Node("model");
        model.attachChild(geom);

        Box child = new Box(0.5f, 0.5f, 0.5f);
        Geometry childGeom = new Geometry("box", child);
        childGeom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
        Node childModel = new Node("childmodel");
        childModel.setLocalTranslation(2, 2, 2);
        childModel.attachChild(childGeom);
        model.attachChild(childModel);
        
        //animation parameters
        float animTime = 5;
        int fps = 25;
        float totalXLength = 10;
        
        //calculating frames
        int totalFrames = (int) (fps * animTime);
        float dT = animTime / totalFrames, t = 0;
        float dX = totalXLength / totalFrames, x = 0;
        float[] times = new float[totalFrames];
        Vector3f[] translations = new Vector3f[totalFrames];
        Quaternion[] rotations = new Quaternion[totalFrames];
        Vector3f[] scales = new Vector3f[totalFrames];
		for (int i = 0; i < totalFrames; ++i) {
        	times[i] = t;
        	t += dT;
        	translations[i] = new Vector3f(x, 0, 0);
        	x += dX;
        	rotations[i] = Quaternion.IDENTITY;
        	scales[i] = Vector3f.UNIT_XYZ;
        }
        SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales);
        
        //creating the animation
        Animation spatialAnimation = new Animation("anim", animTime);
        spatialAnimation.setTracks(new SpatialTrack[] { spatialTrack });
        
        //create spatial animation control
        AnimControl control = new AnimControl();
        HashMap<String, Animation> animations = new HashMap<String, Animation>();
        animations.put("anim", spatialAnimation);
        control.setAnimations(animations);
        model.addControl(control);

        rootNode.attachChild(model);
        
        //run animation
        control.createChannel().setAnim("anim");
    }
}

@@ -49,25 +49,17 @@
 anim
-ation
 .AnimC
-ontrol
+lip
 ;%0D%0Ai
@@ -81,23 +81,21 @@
 anim
-ation.Animation
+.AnimComposer
 ;%0D%0Ai
@@ -117,21 +117,51 @@
 anim
-ation.Spatial
+.AnimTrack;%0D%0Aimport com.jme3.anim.Transform
 Trac
@@ -447,35 +447,8 @@
 ox;%0D
-%0Aimport java.util.HashMap;%0D
 %0A%0D%0Ap
@@ -2413,103 +2413,222 @@
     
-SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales);%0D%0A        
+TransformTrack transformTrack = new TransformTrack(geom, times, translations, rotations, scales);%0D%0A        TransformTrack transformTrackChild = new TransformTrack(childGeom, times, translations, rotations, scales);
 %0D%0A  
@@ -2631,24 +2631,25 @@
 %0D%0A        //
+ 
 creating the
@@ -2676,30 +2676,21 @@
 Anim
-ation spatialAnimation
+Clip animClip
  = n
@@ -2700,30 +2700,19 @@
 Anim
-ation
+Clip
 (%22anim%22
-, animTime
 );%0D%0A
@@ -2719,32 +2719,24 @@
         
-spatialAnimation
+animClip
 .setTrac
@@ -2742,23 +2742,20 @@
 cks(new 
-Spatial
+Anim
 Track%5B%5D 
@@ -2760,34 +2760,49 @@
 %5D %7B 
-spatialTrack %7D);%0D%0A        
+transformTrack, transformTrackChild %7D);%0D%0A
 %0D%0A  
@@ -2809,16 +2809,17 @@
       //
+ 
 create s
@@ -2862,220 +2862,96 @@
 imCo
-ntrol control = new AnimControl();%0D%0A        HashMap%3CString, Animation%3E animations = new HashMap%3CString, Animation%3E();%0D%0A        animations.put(%22anim%22, spatialAnimation);%0D%0A        control.setAnimations(animations);
+mposer animComposer = new AnimComposer();%0D%0A        animComposer.addAnimClip(animClip);%0D%0A
 %0D%0A  
@@ -2977,19 +2977,22 @@
 rol(
-control);%0D%0A
+animComposer);
 %0D%0A  
@@ -3023,32 +3023,24 @@
 ld(model);%0D%0A
-        
 %0D%0A        //
@@ -3039,16 +3039,17 @@
       //
+ 
 run anim
@@ -3067,39 +3067,61 @@
     
-control.createChannel().setAnim
+model.getControl(AnimComposer.class).setCurrentAction
 (%22an

Migrate TestSpatialAnim to the new Anim class