From 63ee4d8bbec94e5e909347f296fa15a33daf7b11 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 6 Feb 2013 02:58:37 +0000 Subject: [PATCH] - fix display of compound shapes git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10351 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../debug/BulletCharacterDebugControl.java | 32 +++++---- .../bullet/debug/BulletDebugAppState.java | 71 ------------------- .../debug/BulletGhostObjectDebugControl.java | 34 +++++---- .../debug/BulletRigidBodyDebugControl.java | 36 +++++----- 4 files changed, 57 insertions(+), 116 deletions(-) diff --git a/engine/src/bullet-common/com/jme3/bullet/debug/BulletCharacterDebugControl.java b/engine/src/bullet-common/com/jme3/bullet/debug/BulletCharacterDebugControl.java index 9a5750fa4..288f44368 100644 --- a/engine/src/bullet-common/com/jme3/bullet/debug/BulletCharacterDebugControl.java +++ b/engine/src/bullet-common/com/jme3/bullet/debug/BulletCharacterDebugControl.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,18 +78,17 @@ 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); - geom.setLocalScale(body.getCollisionShape().getScale()); + //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 diff --git a/engine/src/bullet-common/com/jme3/bullet/debug/BulletDebugAppState.java b/engine/src/bullet-common/com/jme3/bullet/debug/BulletDebugAppState.java index 5294d7b9e..8147d40ae 100644 --- a/engine/src/bullet-common/com/jme3/bullet/debug/BulletDebugAppState.java +++ b/engine/src/bullet-common/com/jme3/bullet/debug/BulletDebugAppState.java @@ -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 shapes = new HashMap(); - private HashMap usedShapes = new HashMap(); - - public void resetShapes() { - shapes = usedShapes; - usedShapes = new HashMap(); - } - - 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 arrows = new ConcurrentLinkedQueue(); - private final Queue usedArrows = new ConcurrentLinkedQueue(); - - 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; - } - } } diff --git a/engine/src/bullet-common/com/jme3/bullet/debug/BulletGhostObjectDebugControl.java b/engine/src/bullet-common/com/jme3/bullet/debug/BulletGhostObjectDebugControl.java index d10f20f4a..8318d96b6 100644 --- a/engine/src/bullet-common/com/jme3/bullet/debug/BulletGhostObjectDebugControl.java +++ b/engine/src/bullet-common/com/jme3/bullet/debug/BulletGhostObjectDebugControl.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.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,18 +79,17 @@ 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); - geom.setLocalScale(body.getCollisionShape().getScale()); + //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 diff --git a/engine/src/bullet-common/com/jme3/bullet/debug/BulletRigidBodyDebugControl.java b/engine/src/bullet-common/com/jme3/bullet/debug/BulletRigidBodyDebugControl.java index 3cc231504..f78a03497 100644 --- a/engine/src/bullet-common/com/jme3/bullet/debug/BulletRigidBodyDebugControl.java +++ b/engine/src/bullet-common/com/jme3/bullet/debug/BulletRigidBodyDebugControl.java @@ -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,18 +79,17 @@ 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)); - geom.setLocalScale(body.getCollisionShape().getScale()); + //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