Walk the scene and find the transformgroup that is the parent
of the primitive in question. Or walk upwards from the primitive in
question and try find a transform group above it. Otherwise manufacture a
transform group above it. Walking the scene is pretty easy. I hope
this is the right take on your question... I do find it difficult to
discover the 'type' of a primitive... for some reason instanceof failed for me
when I tried this last. You may not have a transformgroup above some
leaf nodes... or the transformgroup may collect some other stuff you don't want
to rotate.
Here is a chunk of (uncleaned) code for doing
this:
void find_node_recurse(Object node) { if( node instanceof TransformGroup ) { for( Enumeration i = ((Group)node).getAllChildren(); i.hasMoreElements(); ) { find_node_recurse( i.nextElement() ); } } else if( node instanceof Switch ) { // do nothing } else if( node instanceof Group ) { for( Enumeration i = ((Group)node).getAllChildren(); i.hasMoreElements(); ) { find_node_recurse( i.nextElement() ); } } else if( node instanceof javax.media.j3d.Locale ) { for( Enumeration i = ((javax.media.j3d.Locale)node).getAllBranchGraphs(); i.hasMoreElements(); ) { find_node_recurse( i.nextElement() ); } } else if( node instanceof VirtualUniverse ) { for( Enumeration i = ((VirtualUniverse)node).getAllLocales(); i.hasMoreElements(); ) { find_node_recurse( i.nextElement() ); } } else if( node instanceof Appearance ) { ((Appearance)node).setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE); PolygonAttributes poly_attrib = new PolygonAttributes(); poly_attrib.setPolygonMode(PolygonAttributes.POLYGON_FILL); poly_attrib.setCullFace(PolygonAttributes.CULL_BACK); ((Appearance)node).setPolygonAttributes(poly_attrib); } else if( node instanceof Shape3D ) { ((Shape3D)node).setCapability( Shape3D.ALLOW_APPEARANCE_WRITE ); find_node_recurse( ((Shape3D)node).getAppearance() ); } }
|
- [JAVA3D] Selecting a 3D primitive JoeB
- Anselm Hook