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