Search in sources :

Example 61 with Control

use of com.jme3.scene.control.Control 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 62 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestOgreAnim method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));
    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);
    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();
    control = model.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    for (String anim : control.getAnimationNames()) System.out.println(anim);
    channel.setAnim("stand");
    geom = (Geometry) ((Node) model).getChild(0);
    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
    Box b = new Box(.25f, 3f, .25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skeletonControl.getAttachmentsNode("hand.right");
    n.attachChild(item);
    rootNode.attachChild(model);
    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
Also used : Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box)

Example 63 with Control

use of com.jme3.scene.control.Control in project jmonkeyengine by jMonkeyEngine.

the class TestSkeletonControlRefresh method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.White);
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(3.8664846f, 6.2704787f, 9.664585f));
    cam.setRotation(new Quaternion(-0.054774776f, 0.94064945f, -0.27974048f, -0.18418397f));
    makeHudText();
    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);
    Material m = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey k = new TextureKey("Models/Oto/Oto.jpg", false);
    m.setTexture("ColorMap", assetManager.loadTexture(k));
    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
            //setting a different material
            model.setMaterial(m.clone());
            model.setLocalScale(0.1f);
            model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
            control = model.getControl(AnimControl.class);
            channel = control.createChannel();
            channel.setAnim(animNames[(i + j) % 4]);
            channel.setLoopMode(LoopMode.DontLoop);
            SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
            //This is a workaround the issue. this call will make the SkeletonControl gather the targets again.
            //skeletonControl.setSpatial(model);
            skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
            skControls.add(skeletonControl);
            rootNode.attachChild(model);
        }
    }
    rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    setupFloor();
    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
    //        DirectionalLightShadowRenderer pssm = new DirectionalLightShadowRenderer(assetManager, 1024, 2);
    //        pssm.setLight(dl);
    //        viewPort.addProcessor(pssm);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    DirectionalLightShadowFilter sf = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    sf.setLight(dl);
    fpp.addFilter(sf);
    fpp.addFilter(new SSAOFilter());
    viewPort.addProcessor(fpp);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TextureKey(com.jme3.asset.TextureKey) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Example 64 with Control

use of com.jme3.scene.control.Control 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 65 with Control

use of com.jme3.scene.control.Control 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

Vector3f (com.jme3.math.Vector3f)51 DirectionalLight (com.jme3.light.DirectionalLight)24 Material (com.jme3.material.Material)23 Quaternion (com.jme3.math.Quaternion)21 Node (com.jme3.scene.Node)19 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)18 Texture (com.jme3.texture.Texture)16 AnimControl (com.jme3.animation.AnimControl)15 ColorRGBA (com.jme3.math.ColorRGBA)15 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)15 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)14 Geometry (com.jme3.scene.Geometry)14 Spatial (com.jme3.scene.Spatial)13 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)13 BulletAppState (com.jme3.bullet.BulletAppState)12 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)11 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)11 ArrayList (java.util.ArrayList)10 Box (com.jme3.scene.shape.Box)7 Animation (com.jme3.animation.Animation)5