Jump to content
  • Advertisement
Sign in to follow this  
Smigss

Handling Multiple Objects

This topic is 2902 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

Recently I've got my program working on loading in info from a modified obj file with a header so i could read the size at the top of the file. I created the index and vertex array's as dynamic before filling them and binding the information to the mesh.

My question is what is a good starting point for handling multiple objects now.
I'm using 3dsMax as my creator. Should i just be exporting an entire scene i create as a single file, then parsing it in my program and grabbing the data for all objects and storing them in a custom class. That way i can just point to the data when creating the dynamic array for transfer to the d3dxmesh object.

[Edited by - Smigss on July 7, 2010 12:39:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think it depends on your rendering technique.

Because, for example, I've looked at Racedriver GRID's models and I saw that they shipped the entire level including many buildings, entities, stands and grandstands etc. in a single model file. But in Crysis, they use seperate files for their models (like buildings, trees etc).

Share this post


Link to post
Share on other sites
I'm a big fan of the separate model files because you only have to load what you need. If you have it all in one file you either wind up loading unused resources, or you have to parse through the file to pull out the model you want from it. Both seem pretty wasteful.

Separate files you can load smaller chunks on the fly as they appear or as a user might add them to the game world. Also updating one model doesn't require updating a big file that contains all models. Just seems easier.

Share this post


Link to post
Share on other sites
If i do go with seperate files, then what would be a good way to store and retrieve the list of models i would need?

Share this post


Link to post
Share on other sites
I'm still a bit confused on how i would want to arrange this. This is my flow of data for the main message loop of the application window.

Process Window Messages-->Update User Input-->ClearRenderTarget()-->DrawGame()-->SwapBuffers()

Before the loop i call InitGame() for the creation of the mesh object from a single file.

DrawGame() just calls the function to draw the current mesh.

Now it seems this way it's organized i would have to load all the information at once and my draw call in the loop would just be drawing everything at once.

Instead what would the alternative be?

I can't imagine creating a bunch of ID3DX10Mesh Objects for each model i need in the scene. And i know that within the scene information that i will have to create a way of choosing what to draw.

Share this post


Link to post
Share on other sites
Bah after much learning i think i understand now that i have to create a Scene class and create a derived class of that for mesh data that i will keep and use inheritance and polymorphism.

Share this post


Link to post
Share on other sites
Hmmm, sounds like we're using different approaches somewhat. It sounds like you have one big mesh object for everything??

I use instancing to draw several static objects of the same type in one call. I have a mesh manager that holds a ID3D10Buffer object for each static mesh in the game. I then have model objects that hold a pointer to the mesh that that model uses. So multiple models (game objects) might use the same mesh but there's only every one copy of it in memory.

For dynamic objects it's different. The mesh manager holds unique buffers for each object that's going to be transformed through skeletal animation. No way I could find to instance this. Well, kind of, but I'm still playing with that. Anyways when it's time to render that it gets copied into a vertex buffer cache if and the cache gets drawn.

But the mesh manager is what handles the loading of objects that it needs. Basically you put a request into it to load the file and create the mesh/buffer/whatever objects. If it's already loaded it just returns the already loaded data and moves on. If it's not loaded it loads it right then. Using this approach you could have it handle both ways really. You pass it a big obj file of everything and it'll either load it all or load only the things out of it it doesn't have yet. Or you could pass in individual models as well.

In the end though you could get access to the mesh data by something like the lines below, regardless of if it was loaded from a single large obj or a separate file.

meshManager->LoadMesh("e:\models\fubu.obj");
Mesh* pMesh = meshManager->GetMeshByName("fubu");

Dunno if this really works for everyone but so far it's been pretty good for my work.

Share this post


Link to post
Share on other sites
If you're asking me then yeah. But right now it's a little messy since I load the mesh, skeleton, and animations in different files and mash them together. Doing this so users can select them all separately. But whoo boy I'm trying to figure out a cleaner way to relate them to one another.

Share this post


Link to post
Share on other sites
Just to be clear about how this works. I could create a class called MeshManager and in it contain all the functions for loading information from a file to my self created Mesh structure. And then taking all that information and loading it into a ID3DX10Mesh Object and commiting it do the device and drawing it out?

If it's in a heirarchy like that it would create a new ID3DX10Mesh object for each static object i had and commit each one to the device and then i would just call MeshManager->DrawModelObject for each one during the frame pass. But they have to be commited before the frame loop occurs otherwise it would stack up the same ones in the memory until it crapped out the program correct?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!