# Geometry management

This topic is 2482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, everyone, still plugging away at my game here and today I havea low level data management question

I've got mesh loading working, and my loader can handle loads of 3D formats because I included the assimp library to save time. Now I have identified four main components of a mesh in-game

1. Mesh, containing a vertex buffer, index buffer, and a list of subsets
2. Materials, containing references to a diffuse map, normal map, and a Vector4 for a diffuse color multiplier (really simple atm, may be added to later)
3. Skeleton, containing a bone hierarchy
4. Animation, which is combined with a specific skeleton and provides the transformation for each bone each frame.

My problem is that I want each instance of the same animated model to have its own copy of the Skeleton and Material components, but I want them to share Mesh and Animation components. At the moment I have just one class responsible for loading data from model files, and it is set up like this: (pseudocode)

 class ModelLoader { map<string, Mesh> Meshes; map<string, Skeleton> Skeletons; map<string, MaterialList> MaterialList; map<string, AnimationTable> Animations; Mesh* GetMesh(string filename); Skeleton* GetSkeletonCopy(string filename); MaterialList* GetMaterialListCopy(string filename); AnimationTable* GetAnimation(string filename); ModelInstance* CreateInstance(string filename) { return new ModelInstance(GetMesh(filename), GetSkeletonCopy(filename), GetMaterialListCopy(filename), GetAnimation(filename)); } }; 

Then the constructor/destructor of ModelInstance look like this

 class ModelInstance { Mesh* mesh; Skeleton* skeleton; Animation* animation; MaterialList* materials; ModelInstance(Mesh* m, Skeleton* s, Animation* a, MaterialList* ml) { mesh = m; skeleton = s; animation = a; materials = ml; } ~ModelInstance() { delete materials; delete skeleton; } }; 

ModelInstance has weak references to Mesh and Animation, but strong references to Material and Skeleton, but I can see this causing problems in the future. How do people in general handle this?

##### Share on other sites
In my head, i have a hard time understanding what you are trying to do.

but this is what i think you would like to do.
a class that hold all the animation data and key frames, and then make a class for the instance that will be animated, then you only do something like :

myMesh->updateAnimation(myAnimation,XnumberofDeltaTime);

then again, it´s impossible to realy help you with out any serius code or explanation.
Any how! i hope this helpd a bit!

##### Share on other sites

ModelInstance has weak references to Mesh and Animation, but strong references to Material and Skeleton, but I can see this causing problems in the future. How do people in general handle this?

Why/how do you see this causing problems in the future? ModelInstance itself is a coupling of smaller, ideally well-isolated modules, so it itself can be flexible in how it uses resources.

##### Share on other sites

ModelInstance has weak references to Mesh and Animation, but strong references to Material and Skeleton, but I can see this causing problems in the future. How do people in general handle this?
All I see are pointers. Consider using annotated types, such as those provided by boost. In line of concept, if a thing is different from another it should look different.
How do I do this? I do reference-counting for some resources and a simplified garbage collection for others. To be honest, I am not sure what's your problem.

##### Share on other sites
In general I don't see a problem with this, about the only thing I would say is that the objects which are shared should probably be reference counted so that you know when you can free them up safely and the ones which are per-instance are owned by that instance so having control over the life time makes some sense.

A quick implimentation would involve shared_ptr and unique_ptr for the above lifetime management but it might not be a final solution.

The only other way I can see doing it is to complicate the create/release where instead of the object freeing resources on destruction like that instead the object is queued for destruction and dealt with in a central location and instead of the object itself holding the reference directly the reference is held by another cache object which is told "I'm done with this" and does the standard ref-count decrease/release on zero step.

##### Share on other sites
I'm not to keen on importing the entire boost library just to use some smart pointers, so I might roll my own reference counting

##### Share on other sites
What a coincidence. I'm currently working on a mesh class for my library and am currently working out a similar structure. I'm also using assimp to initially import the scene/mesh hierarchy. It's dog slow in debug mode, isn't it? I don't intend the format I'm creating (.3ds) to be the actual library model format. Because assimp is so slow, I'm reading them in, processing them and them streaming them out in my new format. I've written a little CMD tool to do this.

Anyway you no longer need boost for smart pointers. std:: contains shared_ptr, weak_ptr, etc. (in VS 2010). Using them for lifetime management is really a no-brainer for me.

##### Share on other sites
Also, regarding the boost library there is a tool provided for only extracting the portion of the library that you need for any given set of types.
http://kuniganotas.w...for-my-project/

Though, I don't use boost anymore myself given that the STL implementation in VS2010 tends to be easier to use, and also faster in many cases from my tests.

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×