Deep Copy of Models

Hi, how do I make a deep copy (not just a reference) of a loaded model (i.e. a creature)?
When I want to show 2 creatures of the same kind, one jumping and one walking, I need to have 2 copies of the original model.
Pls, tell me how, or if there r better ways in solving my problem.
Thx, cu

Not quite sure what you mean by this.

Anyway, the easiest way is to write a ‘copy’ function that creates a new object and fills in all the data from the original.

But, when you talk about ‘model’, are you referring to 3D graphics models? Are they skinned (multi-bone meshes)? If so, you need a copy of the matrices but not the geometry etc.

Perhaps this needs to go in a different forum ( 3D? )depending on what you are actually talking about (sorry, but your question is a bit vague)

Either:

  1. If you own the model code, look up the Cloneable interface and implement it to do a deep copy.

  2. If you don’t have direct control over the model classes, check the docs to see if clone is implemented and see if it does a deep copy.

3a. Check to see if there is a copy constructor instead of clone.
3b. See if there is a constructor that takes all the data and that you have access to the data.

  1. If none of those, then you may be stuck loading a copy of the model for each copy that you need.

Well, perhaps this alternate solution will work for use.

Rather than making an actual copy of the data, which wastes memory, just keep track of the state of each creature (either jumping, running, idle, etc.), and render the proper model based on the current state. This way you only need 1 copy of each animation in memory.

The model and animation data itself never changes - it’s static - it’s the state the changes. There’s no reason to have X copies of identical data in memory. Just give out a reference to that data to the objects that need it.

If you’re worried about another programmer changing the data, then notify the programmer about this in your code (javadoc) documentation. Put the responsibility onto the implementor (this is not an uncommon practice). Otherwise you’re going to have a memory hog of a program for no good reason.

hi and thx for all :slight_smile:

@kul_th_las:
this is a good idea, but so I need control of each frame within the animations. I don’t know much about animation, but I wanted to use the AseFile from Xith. I saw a commnd like ‘setAnimation(“name”);’. I thougt, this way, I would just start the animation. And the animation controlls the single frames to be shown.