Browse Source

Ragdoll
- setSpatial(null) supported
- fixed debug shape

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7336 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

rem..om 14 years ago
parent
commit
bb6a8c8062

+ 9 - 5
engine/src/jbullet/com/jme3/bullet/collision/PhysicsCollisionObject.java

@@ -32,7 +32,6 @@
 package com.jme3.bullet.collision;
 
 import com.jme3.asset.AssetManager;
-import com.jme3.bullet.collision.shapes.BoxCollisionShape;
 import com.jme3.bullet.collision.shapes.CollisionShape;
 import com.jme3.bullet.util.DebugShapeFactory;
 import com.jme3.export.InputCapsule;
@@ -167,21 +166,26 @@ public abstract class PhysicsCollisionObject implements Savable {
     protected Spatial attachDebugShape(AssetManager manager) {
         debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
         debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
-   //     debugMaterialBlue.getAdditionalRenderState().setDepthTest(false);
         debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
         debugMaterialGreen.setColor("Color", ColorRGBA.Green);
-//        debugMaterialGreen.getAdditionalRenderState().setDepthTest(false);
         debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
         debugMaterialRed.setColor("Color", ColorRGBA.Red);
-  //      debugMaterialRed.getAdditionalRenderState().setDepthTest(false);
         debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/WireColor.j3md");
         debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
-   //     debugMaterialYellow.getAdditionalRenderState().setDepthTest(false);
         debugArrow = new Arrow(Vector3f.UNIT_XYZ);
         debugArrowGeom = new Geometry("DebugArrow", debugArrow);
         debugArrowGeom.setMaterial(debugMaterialGreen);
         return attachDebugShape();
     }
+    
+    /**
+     * creates a debug shape for this CollisionObject
+     * @param manager
+     * @return 
+     */
+    public Spatial createDebugShape(AssetManager manager){
+        return attachDebugShape(manager);
+    }
 
     protected Spatial attachDebugShape(Material material) {
         debugMaterialBlue = material;

+ 17 - 4
engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java

@@ -103,7 +103,8 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     protected Vector3f modelPosition = new Vector3f();
     protected Quaternion modelRotation = new Quaternion();
     protected float rootMass = 15;
-    private float totalMass = 0;
+    protected float totalMass = 0;
+    protected boolean added=false;
 
     public RagdollControl() {
     }
@@ -142,9 +143,9 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
 
                 Quaternion q = link.rigidBody.getMotionState().getWorldRotationQuat();
 
-                q2.set(q).multLocal(link.initalWorldRotation).normalize();
+                q2.set(q).multLocal(link.initalWorldRotation).normalizeLocal();
                 q3.set(targetModel.getWorldRotation()).inverseLocal().mult(q2, q2);
-                q2.normalize();
+                q2.normalizeLocal();
                 if (link.bone.getParent() == null) {
                     modelPosition.set(p).subtractLocal(link.bone.getInitialPos());
                     modelRotation.set(q).multLocal(link.bone.getInitialRot().inverse());
@@ -244,6 +245,11 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     }
 
     public void setSpatial(Spatial model) {
+        if (model == null) {
+            removeFromPhysicsSpace();
+            clearData();
+            return;
+        }
         targetModel = model;
         Node parent = model.getParent();
 
@@ -399,21 +405,26 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     }
 
     private void addToPhysicsSpace() {
+        
         if (baseRigidBody != null) {
             space.add(baseRigidBody);
+            added=true;
         }
         for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
             PhysicsBoneLink physicsBoneLink = it.next();
             if (physicsBoneLink.rigidBody != null) {
                 space.add(physicsBoneLink.rigidBody);
+                added=true;
             }
         }
         for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
             PhysicsBoneLink physicsBoneLink = it.next();
             if (physicsBoneLink.joint != null) {
                 space.add(physicsBoneLink.joint);
+                added=true;
             }
         }
+        
     }
 
     private HullCollisionShape makeShape(PhysicsBoneLink link, Spatial model) {
@@ -506,6 +517,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     }
 
     private void removeFromPhysicsSpace() {
+        
         if (baseRigidBody != null) {
             space.remove(baseRigidBody);
         }
@@ -521,6 +533,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
                 space.remove(physicsBoneLink.rigidBody);
             }
         }
+        added=false;
     }
 
     public void setEnabled(boolean enabled) {
@@ -542,7 +555,7 @@ public class RagdollControl implements PhysicsControl, PhysicsCollisionListener
     public void attachDebugShape(AssetManager manager) {
         for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) {
             PhysicsBoneLink physicsBoneLink = it.next();
-            physicsBoneLink.rigidBody.attachDebugShape(manager);
+            physicsBoneLink.rigidBody.createDebugShape(manager);
         }
         debug = true;
     }

+ 2 - 3
engine/src/test/jme3test/bullet/TestBoneRagdoll.java

@@ -97,7 +97,7 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi
         bulletAppState = new BulletAppState();
         bulletAppState.setEnabled(true);
         stateManager.attach(bulletAppState);
-//        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
         PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
         setupLight();
 
@@ -154,8 +154,7 @@ public class TestBoneRagdoll extends SimpleApplication implements RagdollCollisi
                     model.getLocalRotation().toAngles(angles);
                     q.fromAngleAxis(angles[1],  Vector3f.UNIT_Y);
                     //q.lookAt(model.getLocalRotation().toRotationMatrix().getColumn(2), Vector3f.UNIT_Y);
-                    model.setLocalRotation(q);
-                    System.out.println(angles[0]+ " "+angles[2]);
+                    model.setLocalRotation(q);              
                     if(angles[0]<0){
                         ragdoll.blendControlToAnim("StandUpBack",animChannel);
                     }else{