- fix display of compound shapes

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10351 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 9037d7bbee
commit 63ee4d8bbe
  1. 30
      engine/src/bullet-common/com/jme3/bullet/debug/BulletCharacterDebugControl.java
  2. 71
      engine/src/bullet-common/com/jme3/bullet/debug/BulletDebugAppState.java
  3. 32
      engine/src/bullet-common/com/jme3/bullet/debug/BulletGhostObjectDebugControl.java
  4. 34
      engine/src/bullet-common/com/jme3/bullet/debug/BulletRigidBodyDebugControl.java

@ -31,13 +31,16 @@
*/
package com.jme3.bullet.debug;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CylinderCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.objects.PhysicsCharacter;
import com.jme3.bullet.util.DebugShapeFactory;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
@ -48,14 +51,16 @@ import com.jme3.scene.Spatial;
public class BulletCharacterDebugControl extends AbstractPhysicsDebugControl {
protected final PhysicsCharacter body;
protected final Geometry geom;
protected final Vector3f location = new Vector3f();
protected final Quaternion rotation = new Quaternion();
protected CollisionShape myShape;
protected Spatial geom;
public BulletCharacterDebugControl(BulletDebugAppState debugAppState, PhysicsCharacter body) {
super(debugAppState);
this.body = body;
this.geom = new Geometry(body.toString());
myShape = body.getCollisionShape();
this.geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
geom.setMaterial(debugAppState.DEBUG_PINK);
}
@ -73,19 +78,18 @@ public class BulletCharacterDebugControl extends AbstractPhysicsDebugControl {
@Override
protected void controlUpdate(float tpf) {
Mesh mesh = debugAppState.getShapeBuffer().getShapeMesh(body.getCollisionShape());
if (mesh != null) {
if (geom.getMesh() != mesh) {
geom.setMesh(mesh);
}
} else {
if (geom.getMesh() != BulletDebugAppState.CollisionShapeBuffer.NO_MESH) {
geom.setMesh(BulletDebugAppState.CollisionShapeBuffer.NO_MESH);
}
if(myShape != body.getCollisionShape()){
Node node = (Node) this.spatial;
node.detachChild(geom);
geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
node.attachChild(geom);
}
applyPhysicsTransform(body.getPhysicsLocation(location), Quaternion.IDENTITY);
//no scaling for sphere, capsule, cylinder
if (!(body.getCollisionShape() instanceof CylinderCollisionShape) && !(body.getCollisionShape() instanceof CapsuleCollisionShape) || !(body.getCollisionShape() instanceof SphereCollisionShape)) {
geom.setLocalScale(body.getCollisionShape().getScale());
}
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {

@ -36,28 +36,21 @@ import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.joints.PhysicsJoint;
import com.jme3.bullet.objects.PhysicsCharacter;
import com.jme3.bullet.objects.PhysicsGhostObject;
import com.jme3.bullet.objects.PhysicsRigidBody;
import com.jme3.bullet.objects.PhysicsVehicle;
import com.jme3.bullet.util.DebugShapeFactory;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.debug.Arrow;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -69,8 +62,6 @@ public class BulletDebugAppState extends AbstractAppState {
protected static final Logger logger = Logger.getLogger(BulletDebugAppState.class.getName());
protected final PhysicsSpace space;
protected final CollisionShapeBuffer shapeBuffer = new CollisionShapeBuffer();
protected final ArrowBuffer arrowBuffer = new ArrowBuffer();
protected final Node physicsDebugRootNode = new Node("Physics Debug Root Node");
protected ViewPort viewPort;
protected RenderManager rm;
@ -119,10 +110,6 @@ public class BulletDebugAppState extends AbstractAppState {
//update our debug root node
physicsDebugRootNode.updateLogicalState(tpf);
physicsDebugRootNode.updateGeometricState();
//reset shapes -> this removes all meshes for shapes that were not used this update cycle
shapeBuffer.resetShapes();
//reset arrows -> this makes arrow meshes available for the next update cycle
arrowBuffer.resetArrows();
}
@Override
@ -300,62 +287,4 @@ public class BulletDebugAppState extends AbstractAppState {
}
}
public ArrowBuffer getArrowBuffer() {
return arrowBuffer;
}
public CollisionShapeBuffer getShapeBuffer() {
return shapeBuffer;
}
public static class CollisionShapeBuffer {
public static final Mesh NO_MESH = new Arrow(new Vector3f(0, 0, 0));
private HashMap<CollisionShape, Mesh> shapes = new HashMap<CollisionShape, Mesh>();
private HashMap<CollisionShape, Mesh> usedShapes = new HashMap<CollisionShape, Mesh>();
public void resetShapes() {
shapes = usedShapes;
usedShapes = new HashMap<CollisionShape, Mesh>();
}
public Mesh getShapeMesh(CollisionShape shape) {
if (shape == null) {
return null;
}
Mesh mesh = shapes.get(shape);
if (mesh == null) {
logger.log(Level.FINE, "Create new debug MESH");
mesh = DebugShapeFactory.getDebugMesh(shape);
shapes.put(shape, mesh);
}
usedShapes.put(shape, mesh);
return mesh;
}
}
public static class ArrowBuffer {
private final Queue<Arrow> arrows = new ConcurrentLinkedQueue<Arrow>();
private final Queue<Arrow> usedArrows = new ConcurrentLinkedQueue<Arrow>();
public void resetArrows() {
arrows.addAll(usedArrows);
}
public Arrow getArrow() {
return getArrow(Vector3f.UNIT_Y);
}
public Arrow getArrow(Vector3f extent) {
Arrow arrow = arrows.poll();
if (arrow == null) {
arrow = new Arrow(extent);
} else {
arrow.setArrowExtent(extent);
}
usedArrows.add(arrow);
return arrow;
}
}
}

@ -31,13 +31,16 @@
*/
package com.jme3.bullet.debug;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CylinderCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.objects.PhysicsGhostObject;
import com.jme3.bullet.util.DebugShapeFactory;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
@ -47,14 +50,18 @@ import com.jme3.scene.Spatial;
*/
public class BulletGhostObjectDebugControl extends AbstractPhysicsDebugControl{
protected final PhysicsGhostObject body;
protected final Geometry geom;
protected final Vector3f location = new Vector3f();
protected final Quaternion rotation = new Quaternion();
protected CollisionShape myShape;
protected Spatial geom;
public BulletGhostObjectDebugControl(BulletDebugAppState debugAppState, PhysicsGhostObject body) {
super(debugAppState);
this.body = body;
this.geom = new Geometry(body.toString());
myShape = body.getCollisionShape();
this.geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
this.geom.setName(body.toString());
this.geom.setName(body.toString());
geom.setMaterial(debugAppState.DEBUG_YELLOW);
}
@ -72,19 +79,18 @@ public class BulletGhostObjectDebugControl extends AbstractPhysicsDebugControl{
@Override
protected void controlUpdate(float tpf) {
Mesh mesh = debugAppState.getShapeBuffer().getShapeMesh(body.getCollisionShape());
if (mesh != null) {
if (geom.getMesh() != mesh) {
geom.setMesh(mesh);
}
} else {
if (geom.getMesh() != BulletDebugAppState.CollisionShapeBuffer.NO_MESH) {
geom.setMesh(BulletDebugAppState.CollisionShapeBuffer.NO_MESH);
}
if(myShape != body.getCollisionShape()){
Node node = (Node) this.spatial;
node.detachChild(geom);
geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
node.attachChild(geom);
}
applyPhysicsTransform(body.getPhysicsLocation(location), Quaternion.IDENTITY);
//no scaling for sphere, capsule, cylinder
if (!(body.getCollisionShape() instanceof CylinderCollisionShape) && !(body.getCollisionShape() instanceof CapsuleCollisionShape) || !(body.getCollisionShape() instanceof SphereCollisionShape)) {
geom.setLocalScale(body.getCollisionShape().getScale());
}
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {

@ -31,17 +31,18 @@
*/
package com.jme3.bullet.debug;
import com.jme3.bullet.debug.BulletDebugAppState.CollisionShapeBuffer;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.CylinderCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.objects.PhysicsRigidBody;
import com.jme3.bullet.util.DebugShapeFactory;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import java.util.logging.Logger;
/**
*
@ -49,16 +50,18 @@ import java.util.logging.Logger;
*/
public class BulletRigidBodyDebugControl extends AbstractPhysicsDebugControl {
private static final Logger logger = Logger.getLogger(BulletRigidBodyDebugControl.class.getName());
protected final PhysicsRigidBody body;
protected final Geometry geom;
protected final Vector3f location = new Vector3f();
protected final Quaternion rotation = new Quaternion();
protected CollisionShape myShape;
protected Spatial geom;
public BulletRigidBodyDebugControl(BulletDebugAppState debugAppState, PhysicsRigidBody body) {
super(debugAppState);
this.body = body;
this.geom = new Geometry(body.toString());
myShape = body.getCollisionShape();
this.geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
this.geom.setName(body.toString());
geom.setMaterial(debugAppState.DEBUG_BLUE);
}
@ -76,19 +79,18 @@ public class BulletRigidBodyDebugControl extends AbstractPhysicsDebugControl {
@Override
protected void controlUpdate(float tpf) {
Mesh mesh = debugAppState.getShapeBuffer().getShapeMesh(body.getCollisionShape());
if (mesh != null) {
if (geom.getMesh() != mesh) {
geom.setMesh(mesh);
}
} else {
if (geom.getMesh() != CollisionShapeBuffer.NO_MESH) {
geom.setMesh(CollisionShapeBuffer.NO_MESH);
}
if(myShape != body.getCollisionShape()){
Node node = (Node) this.spatial;
node.detachChild(geom);
geom = DebugShapeFactory.getDebugShape(body.getCollisionShape());
node.attachChild(geom);
}
applyPhysicsTransform(body.getPhysicsLocation(location), body.getPhysicsRotation(rotation));
//no scaling for sphere, capsule, cylinder
if (!(body.getCollisionShape() instanceof CylinderCollisionShape) && !(body.getCollisionShape() instanceof CapsuleCollisionShape) || !(body.getCollisionShape() instanceof SphereCollisionShape)) {
geom.setLocalScale(body.getCollisionShape().getScale());
}
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {

Loading…
Cancel
Save