Reusing data

Is there any way to reuse model data in jME? What I mean is to have the model data itself (vertices, skeleton) in memory only once, and then there is a node that uses a reference to the model data to draw itself. I need to know, because this may be a big downfall in jME. If you want to use a model 32 times, will it have to be in memory 32 times?



Dr. Freak is 411 KB without textures.



411KB * 32 = ~12.8 MB



Now in its current state, textures must be loaded with the model too. so:



37.3KB * 32 = ~1.1 MB + 12.8 MB = 13.9MB



Now, you have to consider the fact that this is the size of the compressed format on the harddrive. MD2 uses char’s to store vertex positions. When loaded they use floats. I really think this needs to be fixed, somehow.

We have CloneNode and it’s child Clone, which gives you some such functionality, but in a limited way. You would run into problems using it with animated geometry though since you’d likely want each model tracked seperately (in regards to its animation state.)

I tried to address this shortcoming with my MilkLoader. Models can be cloned (fetchCopy()), with the actual Geometry buffers and render state memory inside jME shared, along with the animating controller’s information. The only thing that isn’t shared is Vertex and Normal memory which must be made new for each model because each model has it’s own Vertex and Normal depending upon the stage of the animation.



The loader I’m writting now will have copy features. Of course a ‘copy’ depends on its use. Will each copy only have to have diffrent Vertex data? Or will textures be diffrent for each copy? Will one copies alpha value be diffrent than another’s? For ‘optimal’ performance you could just go inside all of Dr. Freak’s information and where a copy needs to be made (like for example Dr. Freak’s VertexBuffer), copy information and where a refrence to a shared thing is ok (like his texture, or TextureBuffer), just refrence buffers, states, ect.



Look inside MilkFile.spawnCopy() and MilkshapeGroup.getGeo() for an example of how I do that. You’ll notice I call setVerticies when I want to build new FloatBuffers for a model and just call setTextureBuffer when the buffers would be the same (bypassing the creation of a new buffer)