From bb6a8c80629f71a81ef9fecce115a423d5d25e29 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Wed, 27 Apr 2011 18:49:55 +0000 Subject: [PATCH] Ragdoll - setSpatial(null) supported - fixed debug shape git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7336 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../collision/PhysicsCollisionObject.java | 14 ++++++++----- .../jme3/bullet/control/RagdollControl.java | 21 +++++++++++++++---- .../test/jme3test/bullet/TestBoneRagdoll.java | 5 ++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/engine/src/jbullet/com/jme3/bullet/collision/PhysicsCollisionObject.java b/engine/src/jbullet/com/jme3/bullet/collision/PhysicsCollisionObject.java index a59678267..82c0846d2 100644 --- a/engine/src/jbullet/com/jme3/bullet/collision/PhysicsCollisionObject.java +++ b/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; diff --git a/engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java b/engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java index 4ec4ba250..8fc00fa66 100644 --- a/engine/src/jbullet/com/jme3/bullet/control/RagdollControl.java +++ b/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 it = boneLinks.values().iterator(); it.hasNext();) { PhysicsBoneLink physicsBoneLink = it.next(); if (physicsBoneLink.rigidBody != null) { space.add(physicsBoneLink.rigidBody); + added=true; } } for (Iterator 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 it = boneLinks.values().iterator(); it.hasNext();) { PhysicsBoneLink physicsBoneLink = it.next(); - physicsBoneLink.rigidBody.attachDebugShape(manager); + physicsBoneLink.rigidBody.createDebugShape(manager); } debug = true; } diff --git a/engine/src/test/jme3test/bullet/TestBoneRagdoll.java b/engine/src/test/jme3test/bullet/TestBoneRagdoll.java index 189194557..fd0254251 100644 --- a/engine/src/test/jme3test/bullet/TestBoneRagdoll.java +++ b/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{