use of com.jme3.animation.AnimationFactory 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();
}
use of com.jme3.animation.AnimationFactory in project jmonkeyengine by jMonkeyEngine.
the class TestJaime method setupCinematic.
public void setupCinematic(final Node jaime) {
cinematic = new Cinematic(rootNode, 60);
stateManager.attach(cinematic);
jaime.move(0, 0, -3);
AnimationFactory af = new AnimationFactory(0.7f, "JumpForward");
af.addTimeTranslation(0, new Vector3f(0, 0, -3));
af.addTimeTranslation(0.35f, new Vector3f(0, 1, -1.5f));
af.addTimeTranslation(0.7f, new Vector3f(0, 0, 0));
jaime.getControl(AnimControl.class).addAnim(af.buildAnimation());
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 3, LoopMode.DontLoop));
float jumpStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpStart", LoopMode.DontLoop));
cinematic.addCinematicEvent(jumpStart + 0.2f, new AnimationEvent(jaime, "JumpForward", LoopMode.DontLoop, 1));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "JumpEnd", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Punches", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "SideKick", LoopMode.DontLoop));
float camStart = cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Taunt", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", 1, LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Wave", LoopMode.DontLoop));
cinematic.enqueueCinematicEvent(new AnimationEvent(jaime, "Idle", LoopMode.DontLoop));
CameraNode camNode = cinematic.bindCamera("cam", cam);
camNode.setLocalTranslation(new Vector3f(1.1f, 1.2f, 2.9f));
camNode.lookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
MotionPath path = new MotionPath();
path.addWayPoint(new Vector3f(1.1f, 1.2f, 2.9f));
path.addWayPoint(new Vector3f(0f, 1.2f, 3.0f));
path.addWayPoint(new Vector3f(-1.1f, 1.2f, 2.9f));
path.enableDebugShape(assetManager, rootNode);
path.setCurveTension(0.8f);
MotionEvent camMotion = new MotionEvent(camNode, path, 6);
camMotion.setDirectionType(MotionEvent.Direction.LookAt);
camMotion.setLookAt(new Vector3f(0, 0.5f, 0), Vector3f.UNIT_Y);
cinematic.addCinematicEvent(camStart, camMotion);
cinematic.activateCamera(0, "cam");
cinematic.fitDuration();
cinematic.setSpeed(1.2f);
cinematic.setLoopMode(LoopMode.Loop);
cinematic.play();
}
use of com.jme3.animation.AnimationFactory 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");
}
Aggregations