Search in sources :

Example 1 with Animation

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

the class KinematicRagdollControl method kinematicUpdate.

protected void kinematicUpdate(float tpf) {
    //the ragdoll does not have the controll, so the keyframed animation updates the physic position of the physic bonces
    TempVars vars = TempVars.get();
    Quaternion tmpRot1 = vars.quat1;
    Quaternion tmpRot2 = vars.quat2;
    Vector3f position = vars.vect1;
    for (PhysicsBoneLink link : boneLinks.values()) {
        //but to allow smooth transition, we blend this transformation with the saved position of the ragdoll
        if (blendedControl) {
            Vector3f position2 = vars.vect2;
            //initializing tmp vars with the start position/rotation of the ragdoll
            position.set(link.startBlendingPos);
            tmpRot1.set(link.startBlendingRot);
            //interpolating between ragdoll position/rotation and keyframed position/rotation
            tmpRot2.set(tmpRot1).nlerp(link.bone.getModelSpaceRotation(), blendStart / blendTime);
            position2.set(position).interpolateLocal(link.bone.getModelSpacePosition(), blendStart / blendTime);
            tmpRot1.set(tmpRot2);
            position.set(position2);
            //updating bones transforms
            if (boneList.isEmpty()) {
                //we ensure we have the control to update the bone
                link.bone.setUserControl(true);
                link.bone.setUserTransformsInModelSpace(position, tmpRot1);
                //we give control back to the key framed animation.
                link.bone.setUserControl(false);
            } else {
                RagdollUtils.setTransform(link.bone, position, tmpRot1, true, boneList);
            }
        }
        //setting skeleton transforms to the ragdoll
        matchPhysicObjectToBone(link, position, tmpRot1);
        modelPosition.set(targetModel.getLocalTranslation());
    }
    //time control for blending
    if (blendedControl) {
        blendStart += tpf;
        if (blendStart > blendTime) {
            blendedControl = false;
        }
    }
    vars.release();
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 2 with Animation

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

the class KinematicRagdollControl method blendToKinematicMode.

/**
     * Smoothly blend from Ragdoll mode to Kinematic mode This is useful to
     * blend ragdoll actual position to a keyframe animation for example
     *
     * @param blendTime the blending time between ragdoll to anim.
     */
public void blendToKinematicMode(float blendTime) {
    if (mode == Mode.Kinematic) {
        return;
    }
    blendedControl = true;
    this.blendTime = blendTime;
    mode = Mode.Kinematic;
    AnimControl animControl = targetModel.getControl(AnimControl.class);
    animControl.setEnabled(true);
    TempVars vars = TempVars.get();
    for (PhysicsBoneLink link : boneLinks.values()) {
        Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
        Vector3f position = vars.vect1;
        targetModel.getWorldTransform().transformInverseVector(p, position);
        Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
        Quaternion q2 = vars.quat1;
        Quaternion q3 = vars.quat2;
        q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
        q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
        q2.normalizeLocal();
        link.startBlendingPos.set(position);
        link.startBlendingRot.set(q2);
        link.rigidBody.setKinematic(true);
    }
    vars.release();
    for (Bone bone : skeleton.getRoots()) {
        RagdollUtils.setUserControl(bone, false);
    }
    blendStart = 0;
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars) Bone(com.jme3.animation.Bone) AnimControl(com.jme3.animation.AnimControl)

Example 3 with Animation

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

the class HelloEffects method simpleInitApp.

@Override
public void simpleInitApp() {
    ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
    Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    fire.setMaterial(mat_red);
    fire.setImagesX(2);
    // 2x2 texture animation
    fire.setImagesY(2);
    // red
    fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
    // yellow
    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
    fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
    fire.setStartSize(1.5f);
    fire.setEndSize(0.1f);
    fire.setGravity(0, 0, 0);
    fire.setLowLife(1f);
    fire.setHighLife(3f);
    fire.getParticleInfluencer().setVelocityVariation(0.3f);
    rootNode.attachChild(fire);
    ParticleEmitter debris = new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10);
    Material debris_mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    debris_mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png"));
    debris.setMaterial(debris_mat);
    debris.setImagesX(3);
    // 3x3 texture animation
    debris.setImagesY(3);
    debris.setSelectRandomImage(true);
    debris.setRotateSpeed(4);
    debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 4, 0));
    debris.setStartColor(ColorRGBA.White);
    debris.setGravity(0, 6, 0);
    debris.getParticleInfluencer().setVelocityVariation(.60f);
    rootNode.attachChild(debris);
    debris.emitAllParticles();
//    ParticleEmitter water = 
//            new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 20);
//    Material mat_blue = new Material(assetManager, 
//            "Common/MatDefs/Misc/Particle.j3md");
//    mat_blue.setTexture("Texture", assetManager.loadTexture(
//            "Effects/Explosion/flame.png"));
//    water.setMaterial(mat_blue);
//    water.setImagesX(2); 
//    water.setImagesY(2); // 2x2 texture animation
//    water.setStartColor( ColorRGBA.Blue); 
//    water.setEndColor( ColorRGBA.Cyan); 
//    water.getParticleInfluencer().setInitialVelocity(new Vector3f(0, -4, 0));
//    water.setStartSize(1f);
//    water.setEndSize(1.5f);
//    water.setGravity(0,1,0);
//    water.setLowLife(1f);
//    water.setHighLife(1f);
//    water.getParticleInfluencer().setVelocityVariation(0.1f);
//    water.setLocalTranslation(0, 6, 0);
//    rootNode.attachChild(water);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material)

Example 4 with Animation

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

the class TestSoftParticles method createParticles.

private void createParticles() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    material.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    // 
    material.setFloat("Softness", 3f);
    //Fire
    ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30);
    fire.setMaterial(material);
    fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f));
    fire.setImagesX(2);
    // 2x2 texture animation
    fire.setImagesY(2);
    // red
    fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
    // yellow
    fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
    fire.setStartSize(0.6f);
    fire.setEndSize(0.01f);
    fire.setGravity(0, -0.3f, 0);
    fire.setLowLife(0.5f);
    fire.setHighLife(3f);
    fire.setLocalTranslation(0, 0.2f, 0);
    particleNode.attachChild(fire);
    ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30);
    smoke.setMaterial(material);
    smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5));
    smoke.setImagesX(1);
    // 2x2 texture animation
    smoke.setImagesY(1);
    // dark gray
    smoke.setStartColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f));
    // gray      
    smoke.setEndColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.3f));
    smoke.setStartSize(3f);
    smoke.setEndSize(5f);
    smoke.setGravity(0, -0.001f, 0);
    smoke.setLowLife(100f);
    smoke.setHighLife(100f);
    smoke.setLocalTranslation(0, 0.1f, 0);
    smoke.emitAllParticles();
    particleNode.attachChild(smoke);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) ColorRGBA(com.jme3.math.ColorRGBA) EmitterSphereShape(com.jme3.effect.shapes.EmitterSphereShape) Material(com.jme3.material.Material)

Example 5 with Animation

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

the class HelloAnimation method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.LightGray);
    initKeys();
    /** Add a light source so we can see the model */
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -1f, -1).normalizeLocal());
    rootNode.addLight(dl);
    /** Load a model that contains animation */
    player = (Node) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    player.setLocalScale(0.5f);
    rootNode.attachChild(player);
    /** Create a controller and channels. */
    control = player.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim("stand");
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) AnimControl(com.jme3.animation.AnimControl)

Aggregations

Vector3f (com.jme3.math.Vector3f)18 Animation (com.jme3.animation.Animation)12 Quaternion (com.jme3.math.Quaternion)12 AnimControl (com.jme3.animation.AnimControl)11 BoneTrack (com.jme3.animation.BoneTrack)10 HashMap (java.util.HashMap)9 Bone (com.jme3.animation.Bone)8 SpatialTrack (com.jme3.animation.SpatialTrack)7 TempVars (com.jme3.util.TempVars)6 Material (com.jme3.material.Material)5 Track (com.jme3.animation.Track)4 ParticleEmitter (com.jme3.effect.ParticleEmitter)4 DirectionalLight (com.jme3.light.DirectionalLight)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 ArrayList (java.util.ArrayList)4 AmbientLight (com.jme3.light.AmbientLight)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Transform (com.jme3.math.Transform)3 Spatial (com.jme3.scene.Spatial)3