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();
}
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);
}
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");
}
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");
}
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);
}
Aggregations