159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/*
259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2012 jMonkeyEngine
359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved.
459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without
659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are
759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met:
859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright
1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer.
1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright
1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   notice, this list of conditions and the following disclaimer in the
1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   documentation and/or other materials provided with the distribution.
1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   may be used to endorse or promote products derived from this software
1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *   without specific prior written permission.
1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta *
2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.bullet.collision;
3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.AssetManager;
3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.CollisionShape;
3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.util.DebugShapeFactory;
3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.*;
3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.material.Material;
3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.ColorRGBA;
4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f;
4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Geometry;
4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Node;
4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Spatial;
4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.debug.Arrow;
4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.io.IOException;
4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.Iterator;
4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.List;
4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/**
5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Base class for collision objects (PhysicsRigidBody, PhysicsGhostObject)
5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen
5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */
5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic abstract class PhysicsCollisionObject implements Savable {
5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Spatial debugShape;
5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Arrow debugArrow;
5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Geometry debugArrowGeom;
5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Material debugMaterialBlue;
5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Material debugMaterialRed;
6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Material debugMaterialGreen;
6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Material debugMaterialYellow;
6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected CollisionShape collisionShape;
6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_NONE = 0x00000000;
6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_01 = 0x00000001;
6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_02 = 0x00000002;
6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_03 = 0x00000004;
6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_04 = 0x00000008;
6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_05 = 0x00000010;
6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_06 = 0x00000020;
7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_07 = 0x00000040;
7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_08 = 0x00000080;
7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_09 = 0x00000100;
7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_10 = 0x00000200;
7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_11 = 0x00000400;
7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_12 = 0x00000800;
7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_13 = 0x00001000;
7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_14 = 0x00002000;
7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_15 = 0x00004000;
7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public static final int COLLISION_GROUP_16 = 0x00008000;
8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected int collisionGroup = 0x00000001;
8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected int collisionGroupsMask = 0x00000001;
8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    private Object userObject;
8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Sets a CollisionShape to this physics object, note that the object should
8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * not be in the physics space when adding a new collision shape as it is rebuilt
8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * on the physics side.
8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param collisionShape the CollisionShape to set
8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void setCollisionShape(CollisionShape collisionShape) {
9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.collisionShape = collisionShape;
9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        updateDebugShape();
9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @return the CollisionShape of this PhysicsNode, to be able to reuse it with
9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * other physics nodes (increases performance)
9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public CollisionShape getCollisionShape() {
10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return collisionShape;
10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Returns the collision group for this collision shape
10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @return
10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public int getCollisionGroup() {
10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return collisionGroup;
10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Sets the collision group number for this physics object. <br>
11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * The groups are integer bit masks and some pre-made variables are available in CollisionObject.
11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * All physics objects are by default in COLLISION_GROUP_01.<br>
11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Two object will collide when <b>one</b> of the partys has the
11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * collisionGroup of the other in its collideWithGroups set.
11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param collisionGroup the collisionGroup to set
11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void setCollisionGroup(int collisionGroup) {
12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.collisionGroup = collisionGroup;
12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Add a group that this object will collide with.<br>
12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Two object will collide when <b>one</b> of the partys has the
12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * collisionGroup of the other in its collideWithGroups set.<br>
12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param collisionGroup
12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void addCollideWithGroup(int collisionGroup) {
13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.collisionGroupsMask = this.collisionGroupsMask | collisionGroup;
13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Remove a group from the list this object collides with.
13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param collisionGroup
13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void removeCollideWithGroup(int collisionGroup) {
13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.collisionGroupsMask = this.collisionGroupsMask & ~collisionGroup;
13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Directly set the bitmask for collision groups that this object collides with.
14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param collisionGroups
14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void setCollideWithGroups(int collisionGroups) {
14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.collisionGroupsMask = collisionGroups;
14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Gets the bitmask of collision groups that this object collides with.
15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @return
15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public int getCollideWithGroups() {
15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return collisionGroupsMask;
15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Creates a visual debug shape of the current collision shape of this physics object<br/>
15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param manager AssetManager to load the default wireframe material for the debug shape
16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Spatial attachDebugShape(AssetManager manager) {
16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialGreen.setColor("Color", ColorRGBA.Green);
16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialRed.getAdditionalRenderState().setWireframe(true);
17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialRed.setColor("Color", ColorRGBA.Red);
17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrow = new Arrow(Vector3f.UNIT_XYZ);
17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrowGeom = new Geometry("DebugArrow", debugArrow);
17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrowGeom.setMaterial(debugMaterialGreen);
17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return attachDebugShape();
17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * creates a debug shape for this CollisionObject
18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param manager
18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @return
18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public Spatial createDebugShape(AssetManager manager){
18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return attachDebugShape(manager);
18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Spatial attachDebugShape(Material material) {
19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialBlue = material;
19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialGreen = material;
19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialRed = material;
19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugMaterialYellow = material;
19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrow = new Arrow(Vector3f.UNIT_XYZ);
19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrowGeom = new Geometry("DebugArrow", debugArrow);
19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugArrowGeom.setMaterial(debugMaterialGreen);
19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return attachDebugShape();
19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public Spatial debugShape() {
20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return debugShape;
20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Creates a visual debug shape of the current collision shape of this physics object<br/>
20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param material Material to use for the debug shape
20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Spatial attachDebugShape() {
21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (debugShape != null) {
21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            detachDebugShape();
21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Spatial spatial = getDebugShape();
21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.debugShape = spatial;
21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return debugShape;
21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected void updateDebugShape() {
22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (debugShape != null) {
22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            detachDebugShape();
22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            attachDebugShape();
22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    protected Spatial getDebugShape() {
22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        Spatial spatial = DebugShapeFactory.getDebugShape(collisionShape);
22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (spatial == null) {
22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            return new Node("nullnode");
23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
23159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        if (spatial instanceof Node) {
23259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            List<Spatial> children = ((Node) spatial).getChildren();
23359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            for (Iterator<Spatial> it1 = children.iterator(); it1.hasNext();) {
23459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                Spatial spatial1 = it1.next();
23559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                Geometry geom = ((Geometry) spatial1);
23659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                geom.setMaterial(debugMaterialBlue);
23759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta                geom.setCullHint(Spatial.CullHint.Never);
23859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            }
23959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        } else {
24059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            Geometry geom = ((Geometry) spatial);
24159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            geom.setMaterial(debugMaterialBlue);
24259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta            geom.setCullHint(Spatial.CullHint.Never);
24359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        }
24459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        spatial.setCullHint(Spatial.CullHint.Never);
24559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return spatial;
24659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
24759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
24859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
24959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * Removes the debug shape
25059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
25159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void detachDebugShape() {
25259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugShape = null;
25359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
25459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
25559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
25659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @return the userObject
25759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
25859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public Object getUserObject() {
25959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        return userObject;
26059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
26159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
26259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    /**
26359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     * @param userObject the userObject to set
26459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta     */
26559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void setUserObject(Object userObject) {
26659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        this.userObject = userObject;
26759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
26859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
26959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
27059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void write(JmeExporter e) throws IOException {
27159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        OutputCapsule capsule = e.getCapsule(this);
27259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        capsule.write(collisionGroup, "collisionGroup", 0x00000001);
27359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        capsule.write(collisionGroupsMask, "collisionGroupsMask", 0x00000001);
27459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        capsule.write(debugShape, "debugShape", null);
27559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        capsule.write(collisionShape, "collisionShape", null);
27659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
27759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta
27859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    @Override
27959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    public void read(JmeImporter e) throws IOException {
28059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        InputCapsule capsule = e.getCapsule(this);
28159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        collisionGroup = capsule.readInt("collisionGroup", 0x00000001);
28259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        collisionGroupsMask = capsule.readInt("collisionGroupsMask", 0x00000001);
28359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        debugShape = (Spatial) capsule.readSavable("debugShape", null);
28459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        CollisionShape shape = (CollisionShape) capsule.readSavable("collisionShape", null);
28559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta        collisionShape = shape;
28659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta    }
28759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta}
288