Hello all,
I have two JPanels, and for each one a scenegraph gets created and a Canvas3D is
added. When the first JPanel is created, it loads in a number of vrml files and sets
picking capabilities for them, (I'm using the vrml97.jar code). After it is finished,
the second JPanel gets created and also loads in many of the same vrml files and also
sets the picking capabilities for them, but when one of the vrml files is loaded, an
exception occurs when setting the picking capability. It is strange because I don't
get any errors for any of the other vrml files, only one in particular.
Here is the line of code that it occurs on:
PickTool.setCapabilities( (javax.media.j3d.Node) sg, PickTool.INTERSECT_FULL );
Here is the exception:
[java] javax.media.j3d.RestrictedAccessException: Cannot modify capability bits on a
live or compiled object
[java] at javax.media.j3d.SceneGraphObject.setCapability(SceneGraphObject.java:101)
[java] at com.sun.j3d.utils.picking.PickTool.setCapabilities(PickTool.java:283)
[java] at com.sun.j3d.utils.picking.PickTool.setCapabilities(PickTool.java:270)
[java] at
javalab.electrophoresis.ElectrophoresisVrmlFileFinder.recursiveSetUserData(Unknown
Source)
...
I tried adding the following line, but I still get the same error.
if(sg.isLive() == false && sg.isCompiled() == false)
{
Here are the methods that load the vrml file and set the capabilities taken from
Selman's book:
public void recursiveSetUserData(Object value, Object key) {
if( value instanceof SceneGraphObject != false ) {
SceneGraphObject sg = (SceneGraphObject) value;
// recursively process group
if( sg instanceof Group ) {
Group g = (Group) sg;
// recurse on child nodes
java.util.Enumeration enumKids = g.getAllChildren( );
while( enumKids.hasMoreElements( ) != false )
recursiveSetUserData( enumKids.nextElement( ), key );
}
else if ( sg instanceof Shape3D || sg instanceof Morph ) {
if(sg.isLive() == false && sg.isCompiled() == false)
{
try
{
PickTool.setCapabilities( (javax.media.j3d.Node) sg, PickTool.INTERSECT_FULL );
}
catch(Exception e)
{ }
}
}
}
public BranchGroup loadVrml(String filename) {
BranchGroup sceneGroup = null;
Scene scene = null;
VrmlLoader loader = new VrmlLoader( );
try {
try {
scene = loader.load(filename);
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
}
catch ( Exception e ) {
System.out.println( "Exception loading file from path:" + e );
e.printStackTrace( );
}
if (scene != null) {
sceneGroup = scene.getSceneGroup( );
sceneGroup.setCapability( BranchGroup.ALLOW_BOUNDS_READ );
sceneGroup.setCapability( BranchGroup.ALLOW_CHILDREN_READ );
sceneGroup.setCapability( BranchGroup.ALLOW_DETACH );
Hashtable namedObjects = scene.getNamedObjects( );
// recursively set the user data here
// so we can find our objects when they are picked
java.util.Enumeration enumValues = namedObjects.elements( );
java.util.Enumeration enumKeys = namedObjects.keys( );
if( enumValues != null ) {
if( enumValues.hasMoreElements( ) != false ) {
Object value = enumValues.nextElement( );
Object key = enumKeys.nextElement( );
recursiveSetUserData( value, key );
}
while( enumValues.hasMoreElements( ) != false ) {
Object value = enumValues.nextElement( );
Object key = enumKeys.nextElement( );
recursiveSetUserData( value, key );
}
}
}
return sceneGroup;
}
Thanks for any help,
Jason
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".