Search in sources :

Example 6 with AnimationHelper

use of com.jme3.scene.plugins.blender.animations.AnimationHelper in project jmonkeyengine by jMonkeyEngine.

the class TestAnimationFactory method simpleInitApp.

@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);
    TangentBinormalGenerator.generate(model);
    //creating quite complex animation witht the AnimationHelper
    // animation of 6 seconds named "anim" and with 25 frames per second
    AnimationFactory animationFactory = new AnimationFactory(6, "anim", 25);
    //creating a translation keyFrame at time = 3 with a translation on the x axis of 5 WU        
    animationFactory.addTimeTranslation(3, new Vector3f(5, 0, 0));
    //reseting the translation to the start position at time = 6
    animationFactory.addTimeTranslation(6, new Vector3f(0, 0, 0));
    //Creating a scale keyFrame at time = 2 with the unit scale.
    animationFactory.addTimeScale(2, new Vector3f(1, 1, 1));
    //Creating a scale keyFrame at time = 4 scaling to 1.5
    animationFactory.addTimeScale(4, new Vector3f(1.5f, 1.5f, 1.5f));
    //reseting the scale to the start value at time = 5
    animationFactory.addTimeScale(5, new Vector3f(1, 1, 1));
    //Creating a rotation keyFrame at time = 0.5 of quarter PI around the Z axis
    animationFactory.addTimeRotation(0.5f, new Quaternion().fromAngleAxis(FastMath.QUARTER_PI, Vector3f.UNIT_Z));
    //rotating back to initial rotation value at time = 1
    animationFactory.addTimeRotation(1, Quaternion.IDENTITY);
    //Creating a rotation keyFrame at time = 2. Note that i used the Euler angle version because the angle is higher than PI
    //this should result in a complete revolution of the spatial around the x axis in 1 second (from 1 to 2)
    animationFactory.addTimeRotationAngles(2, FastMath.TWO_PI, 0, 0);
    AnimControl control = new AnimControl();
    control.addAnim(animationFactory.buildAnimation());
    model.addControl(control);
    rootNode.attachChild(model);
    //run animation
    control.createChannel().setAnim("anim");
}
Also used : Geometry(com.jme3.scene.Geometry) AnimationFactory(com.jme3.animation.AnimationFactory) Quaternion(com.jme3.math.Quaternion) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) AnimControl(com.jme3.animation.AnimControl) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

AnimationHelper (com.jme3.scene.plugins.blender.animations.AnimationHelper)5 Node (com.jme3.scene.Node)3 ConstraintHelper (com.jme3.scene.plugins.blender.constraints.ConstraintHelper)3 Structure (com.jme3.scene.plugins.blender.file.Structure)3 MeshHelper (com.jme3.scene.plugins.blender.meshes.MeshHelper)3 ArrayList (java.util.ArrayList)3 BlenderKey (com.jme3.asset.BlenderKey)2 Light (com.jme3.light.Light)2 CameraNode (com.jme3.scene.CameraNode)2 Geometry (com.jme3.scene.Geometry)2 LightNode (com.jme3.scene.LightNode)2 CameraHelper (com.jme3.scene.plugins.blender.cameras.CameraHelper)2 CurvesHelper (com.jme3.scene.plugins.blender.curves.CurvesHelper)2 FileBlockHeader (com.jme3.scene.plugins.blender.file.FileBlockHeader)2 Pointer (com.jme3.scene.plugins.blender.file.Pointer)2 LandscapeHelper (com.jme3.scene.plugins.blender.landscape.LandscapeHelper)2 LightHelper (com.jme3.scene.plugins.blender.lights.LightHelper)2 MaterialHelper (com.jme3.scene.plugins.blender.materials.MaterialHelper)2 TemporalMesh (com.jme3.scene.plugins.blender.meshes.TemporalMesh)2 ModifierHelper (com.jme3.scene.plugins.blender.modifiers.ModifierHelper)2