I screwed around with your code for a while, and I think I know what's going
on. It's not that the Shape3D's are taking so long to create. It's how the
Materials are kept internally.
I un-commented your "m_Appearance.setMaterial(m_Material)" line and ran the
program. Every time
I hit quit (on my Unix box I set it to control-backslash), I got a stack trace
(which is a handy trick to know just in general, not just for this. Anywho,
when the program started slow down, and I hit quit, the program was nearly
always showed the following:
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.remove(Compiled Code)
at javax.media.j3d.NodeComponentRetained.removeUser(Compiled Code)
at javax.media.j3d.AppearanceRetained.setMaterial(Compiled Code)
at javax.media.j3d.Appearance.setMaterial(Compiled Code)
at CVoxel.<init>(Compiled Code)
at CVoxel.main(Compiled Code)
Or, at least something that it was in the process of doing in conjunction with
the setMaterial call. It could just be that the ArrayList is not set to
anything beyond the default value, and is constantly in the process of growing
it's value by one.
One way around this is to preallocate all your common Appearances (which I
assume would be less than 4000), and pass those of when you create the Shape3D
objects. I allocated one appearance and used that for all 4000 objects that
were created, and it ran just as fast as the version of your program with all
the comments in place.
I'd be interested if someone at Sun can comment as to whether this analysis was
correct or not. :-)
Steve
Daniel Selman wrote:
> Has anyone else had problems with creating scenegraphs with lots of objects.
> I'm trying to create a scenegraph with approx. 25,000 Shape3D objects
> (controlled with a Switch node). The objects themselves are very simple,
> just a single point in a PointArray, but I've seen that creating up to 1,000
> objects is fine, but after that point creating each object takes longer and
> longer (exponentially so).
>
> I'm interested to know if anyone else is using scengraphs with comparable
> numbers of objects, or if I'm on a hiding to nowhere here and should try
> something different (like immediate mode). Anyone have any suggestions for
> me, to get reasonable performance?
>
> A fuller description of my woes with Shape3D creation (as posted a couple of
> days ago), is available here:
> http://www.tornadolabs.com/java/java3ddocs.html
>
> Any help is appreciated, and I'd love to hear from the Sun engineers who
> have access to the Shape3D constructor source code, and might be able to
> tell me what code is being called that appears to be N squared in the number
> of Shape3D objects that have been created with non-default materials.
>
> Regards to all,
>
> Daniel Selman
>
> Tornado Labs Ltd.
>
> Email: [EMAIL PROTECTED]
> Web: www.tornadolabs.com
> Phone: +44 (0131) 343 2513
> Fax: +44 07070 800 483
>
> =====================================================================
> To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
> Java 3D Home Page: http://java.sun.com/products/java-media/3D/
--
Steve Pietrowicz - [EMAIL PROTECTED] Project Manager - NCSA Java 3D Group
NCSA Portfolio: http://havefun.ncsa.uiuc.edu/Java3D/portfolio/
New Beta 2a release! New Loaders, record and replay of your
Java 3D apps and more! Freely available for non-commercial use!
You Build It VR: http://havefun.ncsa.uiuc.edu/Java3D/YouBuildItVR/
Build your own multi-user virtual worlds with no programming experience!
The Java3D FAQ: http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html
Java News Network: http://tintoy.ncsa.uiuc.edu/~srp/java/javanews.html
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/