Search in sources :

Example 16 with AnimControl

use of com.jme3.animation.AnimControl in project jmonkeyengine by jMonkeyEngine.

the class TestCinematic method simpleInitApp.

@Override
public void simpleInitApp() {
    //just some text
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(getAssetManager(), getInputManager(), getAudioRenderer(), getGuiViewPort());
    Nifty nifty;
    nifty = niftyDisplay.getNifty();
    nifty.fromXmlWithoutStartScreen("Interface/Nifty/CinematicTest.xml");
    getGuiViewPort().addProcessor(niftyDisplay);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText text = new BitmapText(guiFont, false);
    text.setSize(guiFont.getCharSet().getRenderedSize());
    text.setText("Press enter to play/pause cinematic");
    text.setLocalTranslation((cam.getWidth() - text.getLineWidth()) / 2, cam.getHeight(), 0);
    guiNode.attachChild(text);
    createScene();
    cinematic = new Cinematic(rootNode, 20);
    stateManager.attach(cinematic);
    createCameraMotion();
    //creating spatial animation for the teapot
    AnimationFactory factory = new AnimationFactory(20, "teapotAnim");
    factory.addTimeTranslation(0, new Vector3f(10, 0, 10));
    factory.addTimeTranslation(20, new Vector3f(10, 0, -10));
    factory.addTimeScale(10, new Vector3f(4, 4, 4));
    factory.addTimeScale(20, new Vector3f(1, 1, 1));
    factory.addTimeRotationAngles(20, 0, 4 * FastMath.TWO_PI, 0);
    AnimControl control = new AnimControl();
    control.addAnim(factory.buildAnimation());
    teapot.addControl(control);
    //fade in
    cinematic.addCinematicEvent(0, new FadeEvent(true));
    // cinematic.activateCamera(0, "aroundCam");
    cinematic.addCinematicEvent(0, new AnimationEvent(teapot, "teapotAnim", LoopMode.DontLoop));
    cinematic.addCinematicEvent(0, cameraMotionEvent);
    cinematic.addCinematicEvent(0, new SoundEvent("Sound/Environment/Nature.ogg", LoopMode.Loop));
    cinematic.addCinematicEvent(3f, new SoundEvent("Sound/Effects/kick.wav"));
    cinematic.addCinematicEvent(3, new SubtitleTrack(nifty, "start", 3, "jMonkey engine really kicks A..."));
    cinematic.addCinematicEvent(5.1f, new SoundEvent("Sound/Effects/Beep.ogg", 1));
    cinematic.addCinematicEvent(2, new AnimationEvent(model, "Walk", LoopMode.Loop));
    cinematic.activateCamera(0, "topView");
    //  cinematic.activateCamera(10, "aroundCam");
    //fade out
    cinematic.addCinematicEvent(19, new FadeEvent(false));
    //        cinematic.addCinematicEvent(19, new AbstractCinematicEvent() {
    //
    //            @Override
    //            public void onPlay() {
    //                fade.setDuration(1f / cinematic.getSpeed());
    //                fade.fadeOut();
    //
    //            }
    //
    //            @Override
    //            public void onUpdate(float tpf) {
    //            }
    //
    //            @Override
    //            public void onStop() {
    //            }
    //
    //            @Override
    //            public void onPause() {
    //            }
    //        });
    cinematic.addListener(new CinematicEventListener() {

        public void onPlay(CinematicEvent cinematic) {
            chaseCam.setEnabled(false);
            System.out.println("play");
        }

        public void onPause(CinematicEvent cinematic) {
            System.out.println("pause");
        }

        public void onStop(CinematicEvent cinematic) {
            chaseCam.setEnabled(true);
            fade.setValue(1);
            System.out.println("stop");
        }
    });
    //cinematic.setSpeed(2);
    flyCam.setEnabled(false);
    chaseCam = new ChaseCamera(cam, model, inputManager);
    initInputs();
}
Also used : NiftyJmeDisplay(com.jme3.niftygui.NiftyJmeDisplay) Cinematic(com.jme3.cinematic.Cinematic) ChaseCamera(com.jme3.input.ChaseCamera) Nifty(de.lessvoid.nifty.Nifty) AnimControl(com.jme3.animation.AnimControl) BitmapText(com.jme3.font.BitmapText) AnimationFactory(com.jme3.animation.AnimationFactory) Vector3f(com.jme3.math.Vector3f)

Example 17 with AnimControl

use of com.jme3.animation.AnimControl in project jmonkeyengine by jMonkeyEngine.

the class TestModelExportingCloning method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(10f, 3f, 40f));
    cam.lookAtDirection(Vector3f.UNIT_Z.negate(), Vector3f.UNIT_Y);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
    AnimControl control;
    AnimChannel channel;
    Spatial originalModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    control = originalModel.getControl(AnimControl.class);
    channel = control.createChannel();
    channel.setAnim("Walk");
    rootNode.attachChild(originalModel);
    Spatial clonedModel = originalModel.clone();
    clonedModel.move(10, 0, 0);
    control = clonedModel.getControl(AnimControl.class);
    channel = control.createChannel();
    channel.setAnim("push");
    rootNode.attachChild(clonedModel);
    Spatial exportedModel = BinaryExporter.saveAndLoad(assetManager, originalModel);
    exportedModel.move(20, 0, 0);
    control = exportedModel.getControl(AnimControl.class);
    channel = control.createChannel();
    channel.setAnim("pull");
    rootNode.attachChild(exportedModel);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) AnimChannel(com.jme3.animation.AnimChannel) AnimControl(com.jme3.animation.AnimControl)

Example 18 with AnimControl

use of com.jme3.animation.AnimControl in project jmonkeyengine by jMonkeyEngine.

the class TestSpatialAnim 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);
    //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");
}
Also used : Quaternion(com.jme3.math.Quaternion) HashMap(java.util.HashMap) Node(com.jme3.scene.Node) Box(com.jme3.scene.shape.Box) AnimControl(com.jme3.animation.AnimControl) Geometry(com.jme3.scene.Geometry) SpatialTrack(com.jme3.animation.SpatialTrack) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) Animation(com.jme3.animation.Animation) AmbientLight(com.jme3.light.AmbientLight)

Example 19 with AnimControl

use of com.jme3.animation.AnimControl 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)

Example 20 with AnimControl

use of com.jme3.animation.AnimControl in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method applySkinning.

private void applySkinning() {
    for (FbxBindPose pose : bindMap.values()) pose.fillBindTransforms();
    if (limbMap == null)
        return;
    List<Bone> bones = new ArrayList<>();
    for (FbxNode limb : limbMap.values()) {
        if (limb.bone != null) {
            bones.add(limb.bone);
            limb.buildBindPoseBoneTransform();
        }
    }
    skeleton = new Skeleton(bones.toArray(new Bone[bones.size()]));
    skeleton.setBindingPose();
    for (FbxNode limb : limbMap.values()) limb.setSkeleton(skeleton);
    for (FbxSkin skin : skinMap.values()) skin.generateSkinning();
    // Attach controls
    animControl = new AnimControl(skeleton);
    sceneNode.addControl(animControl);
    SkeletonControl control = new SkeletonControl(skeleton);
    sceneNode.addControl(control);
}
Also used : FbxNode(com.jme3.scene.plugins.fbx.objects.FbxNode) FbxBindPose(com.jme3.scene.plugins.fbx.objects.FbxBindPose) ArrayList(java.util.ArrayList) FbxSkin(com.jme3.scene.plugins.fbx.objects.FbxSkin) SkeletonControl(com.jme3.animation.SkeletonControl) Skeleton(com.jme3.animation.Skeleton) Bone(com.jme3.animation.Bone) AnimControl(com.jme3.animation.AnimControl)

Aggregations

AnimControl (com.jme3.animation.AnimControl)17 Vector3f (com.jme3.math.Vector3f)13 Quaternion (com.jme3.math.Quaternion)8 Animation (com.jme3.animation.Animation)7 Bone (com.jme3.animation.Bone)6 Node (com.jme3.scene.Node)6 HashMap (java.util.HashMap)6 DirectionalLight (com.jme3.light.DirectionalLight)5 Spatial (com.jme3.scene.Spatial)5 SkeletonControl (com.jme3.animation.SkeletonControl)4 AnimChannel (com.jme3.animation.AnimChannel)3 BoneTrack (com.jme3.animation.BoneTrack)3 SpatialTrack (com.jme3.animation.SpatialTrack)3 Material (com.jme3.material.Material)3 Geometry (com.jme3.scene.Geometry)3 SkeletonDebugger (com.jme3.scene.debug.SkeletonDebugger)3 TempVars (com.jme3.util.TempVars)3 AnimationFactory (com.jme3.animation.AnimationFactory)2 Skeleton (com.jme3.animation.Skeleton)2 BulletAppState (com.jme3.bullet.BulletAppState)2