Spatial.clone() question

Is it ideal to load a model once and make it static then just clone() it when needed OR just load the model (assetManager.loadModel()) again and again when needed.

I have a racing game which is capable of having four players. Before the race starts, they’ll choose their racers. After the race, the game will detach the racers and let them set another race which they will choose another set or the same set of racers. I was wondering if making the racer models static and cloning it would be ideal than loading the models again and again after each race. I have 10 racer models to choose from.

Thank you :slight_smile:

If you use clone() you will get a model with a shared mesh, you cannot perform separate animations on those. Getting it from the assetManager gives you a deepClone() version (if the model was loaded before) which has a separate mesh.

No when you get it from asset manager you get a normal clone(). Note that clone() will share the meshes if they are not animated, and duplicate them if they are animated.

Just calling loadModel() every time is fine, there’s no need usually to manually use any of the clone() methods.


if I understand it correctly then I can use clone on any spatial where I definitely know that I will not change the mesh. For my application where I visualize molecules, all atomes could share the same mesh but each spatial will have its own local trans,rot and scale values?





Just a question about clone().

if I move or rotate cloned node/spatial? will its mesh/geometry be cloned or duplicated?


You get a complete copy of the Geometry, the mesh is shared if it can be shared (e.g. it has no animation).

Sorry for my annoying, but I have some questions.

How can I know is my mesh cloned or duplicated (as said Momoko-fan above)? This is very important when a scene has 1000 clones, for example, and some clones have Transforms(translation/rotation,scale).

Is there another proper way to make instances of a mesh/geometry/material?

Thank you.

It is shared if it can be shared, that is if no animation control is existent on the geometry.

As far as I understand “Animation Control” is Bones skinning?

And geom.setLocalTranslation(1,0,0) is not “Animation Control”?

How is putting a geometry somewhere in the world an animation control? O_o

Going back to the original question - is there any performance advantage in choosing to either clone or keep creating each item from scratch? The answers don’t seem to be clear on this point (or I’m being dense).

I’m dealing in tens of thousands of shapes, but these are made up of only a handful of types so would it be faster to create one instance of each type and just clone it? They are static once added, no change in location and no animation. Currently load times as I move around can be 15 to 25 seconds each zone, with each zone containing up to 1000 objects. With the huge number of repetitions any speed gain will quickly add up.


Fastest of all would be to batch them into fewer meshes.

Edit: what kind of shapes are they? Is this a “box world”?