VRML and Capability bits

So I’m using XJ3D to load my vrmls into my project. Allegedly the VRML97Loader can mass set capability bits, but any actual confirmation to this is dodgy at best., using loader.setCapabilityRequiredMap(Map, Map). Even tracking down an example of this was futile. The code I used to initialize the loader is

 VRML97Loader loader = new VRML97Loader();
Map<Integer,Integer> capabilityBits = new LinkedHashMap<Integer,Integer>();
capabilityBits.put(BranchGroup.ALLOW_CHILDREN_READ,BranchGroup.ALLOW_CHILDREN_READ);
Map<Integer,Integer> freqBits = new LinkedHashMap<Integer,Integer>();
freqBits.put(BranchGroup.ALLOW_CHILDREN_READ,BranchGroup.ALLOW_CHILDREN_READ);
loader.setCapabilityRequiredMap(capabilityBits, freqBits);

My problem is thus, I’m trying to add an object to a light’s scope list to essentially highlight the object. The Light.addScope(Group) function only takes adds the Group and not its children. So I wrote a little hack to traverse the sub-graph and add all of the group nodes.

private void Scope(Light light, Group group)
{
light.addScope(group);//group.getCapability(BranchGroup.ALLOW_CHILDREN_READ)
Enumeration children = group.getAllChildren();
while(children.hasMoreElements())
{
Object o = (Object)children.nextElement();
if(o instanceof Group)
{
Scope(light, (Group)o);
}
}

}

Then I ran into my capability bit problem. It seems that while I can set the BranchGroup containing the loaded VRML model’s bits, the loader’s setCapabilityRequiredMap function, does not work as anticipated. I get the following expection:

javax.media.j3d.CapabilityNotSetException: Group: no capability to read children

I tried to manually traverse the sub-graph of the loaded VRML with a similar hack as above

private void setCapability(Group group)
{
group.setCapability(Group.ALLOW_CHILDREN_READ);
Enumeration e = group.getAllChildren();
System.out.println(this.id);
while(e.hasMoreElements())
{
Object o = (Object)e.nextElement();
if(o instanceof Group)
{
setCapability((Group)o);
}
}
}

Not to keep you all in suspense, but it didn’t work. So I’m curious if anyone has any suggestions as to what i have done wrong, or even a different approach to solving my problem. Any help would be greatly appreciate, thanks in advance.

Well… I have a suggestion but you may not like it…

Basically what a lot of people do is write recursive code they run after the loader laods the scene but before they make it live to traverse the tree and set the bits they need.

I know that Paul Byrne in the J3D group attempted to write a generic tree traverser to do things like this, but I dont know if its public and/or if it is where it lives.

I can ask him on Tuesday…

A generic tree traverser would be a godsend. I’m a little curious why this sort of functionality doesn’t exist in the form of a helper class or even on the loader itself. I’m running into similar capability bits (which I can only assume were devised to make life that much more irritating) with picking. It very well could be my complete misunderstanding of the nature of capability bits.

We try to be pretty good about setting the right capability bits, but sometimes this just don’t work out right. For example, if you set a Group node as the key to the map with ALLOW_CHILDREN_WRITE, and we’re using a TransformGroup as the internal implementation, then we won’t pick that up: our code uses TransformGroup.class as the key to the map. There’s a lot of places where this comes into play due to all the derived classes that are part of the Java3D design.

If you have specific instances that are not being set correctly, please post a bug report at http://bugzilla.xj3d.org for us to look through. Sometimes these are just trivial errors in our handling and can be fixed in a minute or too. Doing a generic audit is something we currently don’t have time to do, but if we know of specific cases, that makes our lives much, much easier and we can take the hour or two out of our schedule to go fix it.