I am sorry for the time it has taken to get back to you. Java3d has built in methods that seem to have been buried in to the darkest of all knowledge. I found a method of collision detection that is crude, but works.
Here is a simple snip it for a method that can be called upon to give collision.
import java.util.Enumeration;
import javax.media.j3d.Behavior;
import javax.media.j3d.Bounds;
import javax.media.j3d.Node;
import javax.media.j3d.Shape3D;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupOnCollisionEntry;
import javax.media.j3d.WakeupOnCollisionExit;
import javax.media.j3d.WakeupOnCollisionMovement;
import javax.media.j3d.WakeupOr;
/**
*
* @author sawyera.2016
*/
public class Coll extends Behavior {
/** The separate criteria used to wake up this beahvior. */
protected WakeupCriterion[] theCriteria;
/** The OR of the separate criteria. */
protected WakeupOr oredCriteria;
/** The shape that is watched for collision. */
protected Shape3D collidingShape;
/**
* @param theShape
* Shape3D that is to be watched for collisions.
* @param theBounds
* Bounds that define the active region for this behaviour
*/
public Coll(Shape3D theShape, Bounds theBounds) {
collidingShape = theShape;
setSchedulingBounds(theBounds);
}
/**
* This creates an entry, exit and movement collision criteria. These are
* then OR'ed together, and the wake up condition set to the result.
*/
public void initialize() {
theCriteria = new WakeupCriterion[3];
theCriteria[0] = new WakeupOnCollisionEntry(collidingShape);
theCriteria[1] = new WakeupOnCollisionExit(collidingShape);
theCriteria[2] = new WakeupOnCollisionMovement(collidingShape);
oredCriteria = new WakeupOr(theCriteria);
wakeupOn(oredCriteria);
}
/**
* Where the work is done in this class. A message is printed out using the
* userData of the object collided with. The wake up condition is then set
* to the OR'ed criterion again.
*/
public void processStimulus(Enumeration criteria) {
WakeupCriterion theCriterion = (WakeupCriterion) criteria.nextElement();
if (theCriterion instanceof WakeupOnCollisionEntry) {
Node theLeaf = ((WakeupOnCollisionEntry) theCriterion)
.getTriggeringPath().getObject();
System.out.println("Collided with " + theLeaf.getUserData());
} else if (theCriterion instanceof WakeupOnCollisionExit) {
Node theLeaf = ((WakeupOnCollisionExit) theCriterion)
.getTriggeringPath().getObject();
System.out.println("Stopped colliding with "
+ theLeaf.getUserData());
} else {
Node theLeaf = ((WakeupOnCollisionMovement) theCriterion)
.getTriggeringPath().getObject();
System.out.println("Moved whilst colliding with "
+ theLeaf.getUserData());
}
wakeupOn(oredCriteria);
}
}
I cannot take full credit for this, i did get some information about it from the web however i made this version from a 1.2 version of java3d.