I had some inconsistencies with Links and shared groups as well, and even stopped using them when I couldn't figure out what I was doing wrong (memory use extreme, visual glitches, no perceived benefit to using them...) Will try to find my notes.
Scott ----- Original Message ----- From: "Joerg 'Herkules' Plewe" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 05, 2002 6:48 AM Subject: Re: [JAVA3D] Trouble with Link/SharedGroup - is it a Java3D bug?? > Subject: Re: [JAVA3D] Trouble with Link/SharedGroup - is it a Java3D bug?? > > > > We also use shared groups to put in trees, boulders, etc, but we haven't > > put all that many into a scene yet. I've not noticed any specific > > memory issues (Java 3D is a memory hog but we all know that). > > Sigh, ok, nobody seems to believe me.... > > Here is a small code snippet that demonstrates the effect (e.g. in a > HelloUniverse environment). > I turns out that the memory consumption depends on the complexity/depth of > the subtree that > is used below the SharedGroup. I create an arbitrary tree with some > ColorCubes and TGs and > either Link/SharedGroup or cloneTree() it. The bigger the subtree, the > better the Link-solution > should be. In cases where the subtree in question only consists of one or > two groups, it should > not make any difference at all anyway. > > The samples creates only 10 clones/links. While cloning keeps the memory > consumption well > below 40megs, Link gives an OutOfMemoryException even with -Xmx256mb. > > A smaller test (createDeepSubGraph(6)) works marginally with 256MB and > produces > 2.021.371 instances of javax.media.j3d.BranchGroupRetained. > > I'd really appreciate if someone could confirm my observation. > > > ================================================================ > > /** > * Create a subgraph with 10 objects by either Linking or cloning an > object. > */ > Node create10Objects( boolean clone ) > { > Group grp = new Group(); > > // Create a non-trivial subgraph > Node object = createDeepSubGraph( 7 ); > System.out.println( numNodesCreated ); > > // Setup sharedgroup > SharedGroup shared = null; > if ( ! clone ) > { > shared = new SharedGroup(); > shared.addChild( object ); > } > > // Add the objects > for ( int i = 0; i < 10; i++ ) > { > TransformGroup tg = new TransformGroup(); > Transform3D t3d = new Transform3D(); > t3d.setTranslation( new Vector3f( i * 2.0f, 0.0f, i * 2.0f ) ); > tg.setTransform( t3d ); > > // either link or clone the object > if ( clone ) > tg.addChild( object.cloneTree() ); > else > tg.addChild( new Link( shared ) ); > > grp.addChild( tg ); > } > return grp; > } > > > /** > * Create subgraph of a certain depth. > */ > static int numNodesCreated = 0; > Node createDeepSubGraph( int depth ) > { > BranchGroup g = new BranchGroup(); > > // One new cube... > g.addChild( new ColorCube( 0.1 ) ); > numNodesCreated++; > > // ...and maybe two subgraphs > if ( depth > 0 ) > { > Transform3D t3d = new Transform3D(); > Transform3D t3d2 = new Transform3D(); > TransformGroup tg; > > t3d.setScale( 0.2 * (double)depth ); > t3d2.setTranslation( new Vector3f( 0.2f, -0.2f, 0.0f ) ); > t3d.mul( t3d2 ); > tg = new TransformGroup(); > tg.setTransform( t3d ); > tg.addChild( createDeepSubGraph( depth - 1 ) ); > g.addChild( tg ); > > t3d.setScale( 0.2 * (double)depth ); > t3d2.setTranslation( new Vector3f( -0.2f, -0.2f, 0.0f ) ); > t3d.mul( t3d2 ); > tg = new TransformGroup(); > tg.setTransform( t3d ); > tg.addChild( createDeepSubGraph( depth - 1 ) ); > g.addChild( tg ); > } > return g; > } > > =========================================================================== > 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". =========================================================================== 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".