*/
@Override
public void findPick(Ray ray, PickResults results) {
- if (getWorldBound() == null || !isCollidable) {
+ if (getWorldBound() == null || !isCollidable()) {
return;
}
if (getWorldBound().intersects(ray)) {
@Override
public void findCollisions(Spatial scene, CollisionResults results) {
- if (getWorldBound() != null && isCollidable && scene.isCollidable()) {
+ if (getWorldBound() != null && isCollidable() && scene.isCollidable()) {
if (getWorldBound().intersects(scene.getWorldBound())) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
@Override
public boolean hasCollision(Spatial scene, boolean checkTriangles) {
if (this == scene) return false; // No Collision with "self"
- if (getWorldBound() != null && isCollidable && scene.isCollidable()) {
+ if (getWorldBound() != null && isCollidable() && scene.isCollidable()) {
if (getWorldBound().intersects(scene.getWorldBound())) {
if(children == null && !checkTriangles) {
return true;
if(children == null) {
return;
}
- if (getWorldBound() != null && isCollidable) {
+ if (getWorldBound() != null && isCollidable()) {
if (getWorldBound().intersects(toTest)) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
* Defines if this spatial will be used in intersection operations or not.
* Default is true
*/
- protected boolean isCollidable = true;
+ protected int collisionBits = 1;
public transient float queueDistance = Float.NEGATIVE_INFINITY;
public void write(JMEExporter ex) throws IOException {
OutputCapsule capsule = ex.getCapsule(this);
capsule.write(name, "name", null);
- capsule.write(isCollidable, "isCollidable", true);
+ capsule.write(collisionBits, "collisionBits", 1);
capsule.write(cullHint, "cullMode", CullHint.Inherit);
capsule.write(renderQueueMode, "renderQueueMode",
* for compatibility, this should be dropped.
*/
if (name == null) name = "";
- isCollidable = capsule.readBoolean("isCollidable", true);
+ boolean collisionBoolean = capsule.readBoolean("isCollidable", true);
+ collisionBits = capsule.readInt("collisionBits", 1);
+
+ // Handle legacy model files that have stored 'isCollidable' instead of
+ // 'collisionBits'.
+ if (!collisionBoolean && collisionBits == 1) collisionBits = 0;
+ /* Our exporter routines do not allow us to always detect whether
+ * 'isCollidable' was actually persisted.
+ * However, if 'isCollidable' has a non-default val and 'collisionBits'
+ * has default val, we know that legacy value was stored. */
+
cullHint = capsule.readEnum("cullMode", CullHint.class,
CullHint.Inherit);
/**
* Sets if this Spatial is to be used in intersection (collision and
* picking) calculations. By default this is true.
+ *
+ * Turns on or off the first (least significant) bit in the collision bit
+ * set.
*
* @param isCollidable
* true if this Spatial is to be used in intersection
* calculations, false otherwise.
*/
public void setIsCollidable(boolean isCollidable) {
- this.isCollidable = isCollidable;
+ collisionBits = isCollidable ? (collisionBits | 1)
+ : (collisionBits & (~1));
}
/**
* false otherwise.
*/
public boolean isCollidable() {
- return this.isCollidable;
+ return (collisionBits & 1) != 0;
}
/**
*/
@Override
public void findCollisions(Spatial scene, CollisionResults results) {
- if (this == scene || !isCollidable || !scene.isCollidable()) {
+ if (this == scene || !isCollidable() || !scene.isCollidable()) {
return;
}
*/
@Override
public boolean hasCollision(Spatial scene, boolean checkTriangles) {
- if (this == scene || !isCollidable || !scene.isCollidable()) {
+ if (this == scene || !isCollidable() || !scene.isCollidable()) {
return false;
}
activeChild = capsule.readInt("activeChild", 0);
activeChildData = (Spatial)capsule.readSavable("activeChildData", null);
}
-}
\ No newline at end of file
+}
* if it has true is returned, otherwise false is returned.
*/
public boolean hasCollision(Spatial scene, boolean checkTriangles) {
- if (this == scene || !isCollidable || !scene.isCollidable()) {
+ if (this == scene || !isCollidable() || !scene.isCollidable()) {
return false;
}
if (getWorldBound().intersects(scene.getWorldBound())) {
* hit.
*/
public void findCollisions(Spatial scene, CollisionResults results) {
- if (this == scene || !isCollidable || !scene.isCollidable()) {
+ if (this == scene || !isCollidable() || !scene.isCollidable()) {
return;
}
CollisionTree checkCT = CollisionTreeManager.getInstance()
.getCollisionTree(toCheck);
- if (thisCT == null || checkCT == null || !isCollidable
+ if (thisCT == null || checkCT == null || !isCollidable()
|| !toCheck.isCollidable()) {
return false;
}
* the indices to the triangles.
*/
public void findTrianglePick(Ray toTest, ArrayList<Integer> results) {
- if (worldBound == null || !isCollidable) {
+ if (worldBound == null || !isCollidable()) {
return;
}
recalcTriangleQuantity();
mode = (Mode) capsule.readEnum("mode", Mode.class, Mode.Triangles);
}
-}
\ No newline at end of file
+}