|
|
|
@ -6,6 +6,10 @@ import com.jme3.animation.Skeleton; |
|
|
|
|
import com.jme3.animation.SkeletonControl; |
|
|
|
|
import com.jme3.asset.AssetManager; |
|
|
|
|
import com.jme3.bullet.PhysicsSpace; |
|
|
|
|
import com.jme3.bullet.collision.PhysicsCollisionEvent; |
|
|
|
|
import com.jme3.bullet.collision.PhysicsCollisionGroupListener; |
|
|
|
|
import com.jme3.bullet.collision.PhysicsCollisionListener; |
|
|
|
|
import com.jme3.bullet.collision.PhysicsCollisionObject; |
|
|
|
|
import com.jme3.bullet.collision.shapes.BoxCollisionShape; |
|
|
|
|
import com.jme3.bullet.collision.shapes.HullCollisionShape; |
|
|
|
|
import com.jme3.bullet.joints.ConeJoint; |
|
|
|
@ -36,7 +40,7 @@ import java.util.List; |
|
|
|
|
import java.util.logging.Level; |
|
|
|
|
import java.util.logging.Logger; |
|
|
|
|
|
|
|
|
|
public class RagdollControl implements PhysicsControl { |
|
|
|
|
public class RagdollControl implements PhysicsControl, PhysicsCollisionListener { |
|
|
|
|
|
|
|
|
|
protected static final Logger logger = Logger.getLogger(RagdollControl.class.getName()); |
|
|
|
|
protected List<PhysicsBoneLink> boneLinks = new LinkedList<PhysicsBoneLink>(); |
|
|
|
@ -51,6 +55,7 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
protected Vector3f initPosition; |
|
|
|
|
protected Quaternion initRotation; |
|
|
|
|
protected Vector3f initScale; |
|
|
|
|
protected boolean control = false; |
|
|
|
|
|
|
|
|
|
//Normen: Think you have the system you want, with movement
|
|
|
|
|
//Normen: but the rootBone movement and translation is also accessible like getRootBoneLocation()
|
|
|
|
@ -73,9 +78,10 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
if (!enabled) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
|
assert vars.lock(); |
|
|
|
|
if (control) { |
|
|
|
|
|
|
|
|
|
Quaternion q2 = vars.quat1; |
|
|
|
|
// skeleton.reset();
|
|
|
|
|
for (PhysicsBoneLink link : boneLinks) { |
|
|
|
@ -94,10 +100,23 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
link.bone.setUserTransformsWorld(p, q2); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
for (PhysicsBoneLink link : boneLinks) { |
|
|
|
|
|
|
|
|
|
Vector3f position = vars.vect1; |
|
|
|
|
Quaternion rotation = vars.quat1; |
|
|
|
|
Vector3f scale= vars.vect2; |
|
|
|
|
|
|
|
|
|
position.set(link.bone.getModelSpacePosition()); |
|
|
|
|
rotation.set(link.bone.getModelSpaceRotation()).multLocal(link.bone.getWorldBindInverseRotation()); |
|
|
|
|
scale.set(link.bone.getModelSpaceScale()); |
|
|
|
|
link.rigidBody.setPhysicsLocation(position); |
|
|
|
|
link.rigidBody.setPhysicsRotation(rotation); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert vars.unlock(); |
|
|
|
|
|
|
|
|
|
assert vars.unlock(); |
|
|
|
|
//baseRigidBody.getMotionState().applyTransform(targetModel);
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -168,11 +187,12 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
|
|
|
|
|
//get world space position of the bone
|
|
|
|
|
Vector3f pos = bone.getModelSpacePosition().add(model.getLocalTranslation()); |
|
|
|
|
Quaternion rot= bone.getModelSpaceRotation().mult(initRotation); |
|
|
|
|
Quaternion rot = bone.getModelSpaceRotation().mult(initRotation); |
|
|
|
|
|
|
|
|
|
//creating the collision shape from the bone's associated vertices
|
|
|
|
|
PhysicsRigidBody shapeNode = new PhysicsRigidBody(makeShape(bone, model), 10.0f / (float) reccount); |
|
|
|
|
shapeNode.setPhysicsLocation(pos); |
|
|
|
|
|
|
|
|
|
// shapeNode.setPhysicsRotation(rot);
|
|
|
|
|
|
|
|
|
|
PhysicsBoneLink link = new PhysicsBoneLink(); |
|
|
|
@ -369,6 +389,7 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
this.space = space; |
|
|
|
|
addToPhysicsSpace(); |
|
|
|
|
} |
|
|
|
|
this.space.addCollisionListener(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public PhysicsSpace getPhysicsSpace() { |
|
|
|
@ -383,6 +404,62 @@ public class RagdollControl implements PhysicsControl { |
|
|
|
|
throw new UnsupportedOperationException("Not supported yet."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void collision(PhysicsCollisionEvent event) { |
|
|
|
|
PhysicsCollisionObject objA = event.getObjectA(); |
|
|
|
|
PhysicsCollisionObject objB = event.getObjectB(); |
|
|
|
|
// System.out.println("----------------------------");
|
|
|
|
|
// System.out.println("NodeA "+event.getNodeA());
|
|
|
|
|
// System.out.println("NodeB "+event.getNodeB());
|
|
|
|
|
if (event == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (event.getNodeA() != null && "Floor".equals(event.getNodeA().getName())) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (event.getNodeB() != null && "Floor".equals(event.getNodeB().getName())) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// if(event.getNodeB() == null && event.getNodeA() ==null){
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
if (event.getAppliedImpulse() < 3.0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean hit = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (objA instanceof PhysicsRigidBody) { |
|
|
|
|
PhysicsRigidBody prb = (PhysicsRigidBody) objA; |
|
|
|
|
for (PhysicsBoneLink physicsBoneLink : boneLinks) { |
|
|
|
|
if (physicsBoneLink.rigidBody == prb) { |
|
|
|
|
hit = true; |
|
|
|
|
// System.out.println("objA " + physicsBoneLink.bone.getName() + " " + event.getAppliedImpulse() + " " + event.getAppliedImpulseLateral1() + " " + event.getAppliedImpulseLateral2());
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (objB instanceof PhysicsRigidBody) { |
|
|
|
|
PhysicsRigidBody prb = (PhysicsRigidBody) objB; |
|
|
|
|
for (PhysicsBoneLink physicsBoneLink : boneLinks) { |
|
|
|
|
if (physicsBoneLink.rigidBody == prb) { |
|
|
|
|
hit = false; |
|
|
|
|
// System.out.println("objB " + physicsBoneLink.bone.getName() + " " + event.getAppliedImpulse() + " " + event.getAppliedImpulseLateral1() + " " + event.getAppliedImpulseLateral2());
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (hit && event.getAppliedImpulse() > 10.0) { |
|
|
|
|
control = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// System.out.println("----------------------------");
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean collide(PhysicsCollisionObject nodeA, PhysicsCollisionObject nodeB) { |
|
|
|
|
throw new UnsupportedOperationException("Not supported yet."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected static class PhysicsBoneLink { |
|
|
|
|
|
|
|
|
|
Bone bone; |
|
|
|
|