|
@@ -31,20 +31,9 @@
|
|
*/
|
|
*/
|
|
package com.jme3.bullet.collision;
|
|
package com.jme3.bullet.collision;
|
|
|
|
|
|
-import com.jme3.asset.AssetManager;
|
|
|
|
import com.jme3.bullet.collision.shapes.CollisionShape;
|
|
import com.jme3.bullet.collision.shapes.CollisionShape;
|
|
-import com.jme3.bullet.util.DebugShapeFactory;
|
|
|
|
import com.jme3.export.*;
|
|
import com.jme3.export.*;
|
|
-import com.jme3.material.Material;
|
|
|
|
-import com.jme3.math.ColorRGBA;
|
|
|
|
-import com.jme3.math.Vector3f;
|
|
|
|
-import com.jme3.scene.Geometry;
|
|
|
|
-import com.jme3.scene.Node;
|
|
|
|
-import com.jme3.scene.Spatial;
|
|
|
|
-import com.jme3.scene.debug.Arrow;
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.Iterator;
|
|
|
|
-import java.util.List;
|
|
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -55,13 +44,6 @@ import java.util.logging.Logger;
|
|
public abstract class PhysicsCollisionObject implements Savable {
|
|
public abstract class PhysicsCollisionObject implements Savable {
|
|
|
|
|
|
protected long objectId = 0;
|
|
protected long objectId = 0;
|
|
- protected Spatial debugShape;
|
|
|
|
- protected Arrow debugArrow;
|
|
|
|
- protected Geometry debugArrowGeom;
|
|
|
|
- protected Material debugMaterialBlue;
|
|
|
|
- protected Material debugMaterialRed;
|
|
|
|
- protected Material debugMaterialGreen;
|
|
|
|
- protected Material debugMaterialYellow;
|
|
|
|
protected CollisionShape collisionShape;
|
|
protected CollisionShape collisionShape;
|
|
public static final int COLLISION_GROUP_NONE = 0x00000000;
|
|
public static final int COLLISION_GROUP_NONE = 0x00000000;
|
|
public static final int COLLISION_GROUP_01 = 0x00000001;
|
|
public static final int COLLISION_GROUP_01 = 0x00000001;
|
|
@@ -92,7 +74,6 @@ public abstract class PhysicsCollisionObject implements Savable {
|
|
*/
|
|
*/
|
|
public void setCollisionShape(CollisionShape collisionShape) {
|
|
public void setCollisionShape(CollisionShape collisionShape) {
|
|
this.collisionShape = collisionShape;
|
|
this.collisionShape = collisionShape;
|
|
- updateDebugShape();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -174,103 +155,6 @@ public abstract class PhysicsCollisionObject implements Savable {
|
|
initUserPointer(objectId, collisionGroup, collisionGroupsMask);
|
|
initUserPointer(objectId, collisionGroup, collisionGroupsMask);
|
|
}
|
|
}
|
|
native void initUserPointer(long objectId, int group, int groups);
|
|
native void initUserPointer(long objectId, int group, int groups);
|
|
- /**
|
|
|
|
- * Creates a visual debug shape of the current collision shape of this physics object<br/>
|
|
|
|
- * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
|
|
|
|
- * @param manager AssetManager to load the default wireframe material for the debug shape
|
|
|
|
- */
|
|
|
|
- protected Spatial attachDebugShape(AssetManager manager) {
|
|
|
|
- debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
|
- debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
|
|
|
|
- debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
|
|
|
|
- debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
|
- debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
|
|
|
|
- debugMaterialGreen.setColor("Color", ColorRGBA.Green);
|
|
|
|
- debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
|
- debugMaterialRed.getAdditionalRenderState().setWireframe(true);
|
|
|
|
- debugMaterialRed.setColor("Color", ColorRGBA.Red);
|
|
|
|
- debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
|
- debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
|
|
|
|
- debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
|
|
|
|
- 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 The created debug shape
|
|
|
|
- */
|
|
|
|
- public Spatial createDebugShape(AssetManager manager){
|
|
|
|
- return attachDebugShape(manager);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected Spatial attachDebugShape(Material material) {
|
|
|
|
- debugMaterialBlue = material;
|
|
|
|
- debugMaterialGreen = material;
|
|
|
|
- debugMaterialRed = material;
|
|
|
|
- debugMaterialYellow = material;
|
|
|
|
- debugArrow = new Arrow(Vector3f.UNIT_XYZ);
|
|
|
|
- debugArrowGeom = new Geometry("DebugArrow", debugArrow);
|
|
|
|
- debugArrowGeom.setMaterial(debugMaterialGreen);
|
|
|
|
- return attachDebugShape();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Spatial debugShape() {
|
|
|
|
- return debugShape;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Creates a visual debug shape of the current collision shape of this physics object<br/>
|
|
|
|
- * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
|
|
|
|
- * @param material Material to use for the debug shape
|
|
|
|
- */
|
|
|
|
- protected Spatial attachDebugShape() {
|
|
|
|
- if (debugShape != null) {
|
|
|
|
- detachDebugShape();
|
|
|
|
- }
|
|
|
|
- Spatial spatial = getDebugShape();
|
|
|
|
- this.debugShape = spatial;
|
|
|
|
- return debugShape;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected void updateDebugShape() {
|
|
|
|
- if (debugShape != null) {
|
|
|
|
- detachDebugShape();
|
|
|
|
- attachDebugShape();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected Spatial getDebugShape() {
|
|
|
|
- Spatial spatial = DebugShapeFactory.getDebugShape(collisionShape);
|
|
|
|
- if (spatial == null) {
|
|
|
|
- return new Node("nullnode");
|
|
|
|
- }
|
|
|
|
- if (spatial instanceof Node) {
|
|
|
|
- List<Spatial> children = ((Node) spatial).getChildren();
|
|
|
|
- for (Iterator<Spatial> it1 = children.iterator(); it1.hasNext();) {
|
|
|
|
- Spatial spatial1 = it1.next();
|
|
|
|
- Geometry geom = ((Geometry) spatial1);
|
|
|
|
- geom.setMaterial(debugMaterialBlue);
|
|
|
|
- geom.setCullHint(Spatial.CullHint.Never);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- Geometry geom = ((Geometry) spatial);
|
|
|
|
- geom.setMaterial(debugMaterialBlue);
|
|
|
|
- geom.setCullHint(Spatial.CullHint.Never);
|
|
|
|
- }
|
|
|
|
- spatial.setCullHint(Spatial.CullHint.Never);
|
|
|
|
- return spatial;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Removes the debug shape
|
|
|
|
- */
|
|
|
|
- public void detachDebugShape() {
|
|
|
|
- debugShape = null;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @return the userObject
|
|
* @return the userObject
|
|
@@ -299,7 +183,6 @@ public abstract class PhysicsCollisionObject implements Savable {
|
|
OutputCapsule capsule = e.getCapsule(this);
|
|
OutputCapsule capsule = e.getCapsule(this);
|
|
capsule.write(collisionGroup, "collisionGroup", 0x00000001);
|
|
capsule.write(collisionGroup, "collisionGroup", 0x00000001);
|
|
capsule.write(collisionGroupsMask, "collisionGroupsMask", 0x00000001);
|
|
capsule.write(collisionGroupsMask, "collisionGroupsMask", 0x00000001);
|
|
- capsule.write(debugShape, "debugShape", null);
|
|
|
|
capsule.write(collisionShape, "collisionShape", null);
|
|
capsule.write(collisionShape, "collisionShape", null);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -308,7 +191,6 @@ public abstract class PhysicsCollisionObject implements Savable {
|
|
InputCapsule capsule = e.getCapsule(this);
|
|
InputCapsule capsule = e.getCapsule(this);
|
|
collisionGroup = capsule.readInt("collisionGroup", 0x00000001);
|
|
collisionGroup = capsule.readInt("collisionGroup", 0x00000001);
|
|
collisionGroupsMask = capsule.readInt("collisionGroupsMask", 0x00000001);
|
|
collisionGroupsMask = capsule.readInt("collisionGroupsMask", 0x00000001);
|
|
- debugShape = (Spatial) capsule.readSavable("debugShape", null);
|
|
|
|
CollisionShape shape = (CollisionShape) capsule.readSavable("collisionShape", null);
|
|
CollisionShape shape = (CollisionShape) capsule.readSavable("collisionShape", null);
|
|
collisionShape = shape;
|
|
collisionShape = shape;
|
|
}
|
|
}
|