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.