Jump to content
  • Advertisement
Sign in to follow this  
hupsilardee

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!