Sign in to follow this  
MohammadAhmed

Scene graph

Recommended Posts

Hello game developers , I have in my game every thing , but all what I need right now is a fast way to create 100 model for example ( zombie )   can you post some code showing the data structures ... etc , say what you know about this smile.png , I have for each model modelAnimatorManager and physicsManager  , so if I want to create 100 zombie model I must create 100 modelAnimaorManager and 100 physicsManager !!!! that's too much right ?!?! 

I used List<model> zombie = new list<model>(); 

and iterate over the model 100 times !!!!!!!!!!!!!! bla bla bla the same goes for physicsManager and modelAnimatorMnager , I know this is not good strategy !!

Sorry game developers if my topic was not related , I have not enough information about these issues , but I think my problem is about mange the scene or whatever is the definition .

Edited by mrmohadnan

Share this post


Link to post
Share on other sites

That entirly depends ...

 

What does modelAnimatorManager and physicsManager do? do you NEED 1 for each zombie?

 

if you have 100 items in the list, and you need to iterate over it, there is no way to get around doing it 100 times. you could look into Multi-threading, but that could cause more problems than it solves.

 

without any details, i would say Do each of the items NEED a physics manager? Why not 1 physics manager that can handle the updating of everything?

 

I currently use a physics engine and have over 1000 objects updating each frame, and the framework does this for me in ~20ms.

Share this post


Link to post
Share on other sites

thanks Andy474 , modelAnimator just load the animation for the model and set the world matrix which will be drawn later on the screen , not physics manager but it's like the controller for the model , i.e updating the bounding box for the model ......etc .

 I was talking with my friend belfegor , he advice me to create one class that contain the model and the modelAnimator and the chrachter controller and just make list of it instead of making 100 list from each one of model , modelAnimator , chrachter controller for each class !!!

for you Andy , what is your advice , tell me about the data structure you used and tell me your opinion in general smile.png and how did you manage all your stuff 1000 model or whatever 

Edited by mrmohadnan

Share this post


Link to post
Share on other sites

Ok , Andy do you face problem like this :

you have 10 models using the same effect , if you use XNA or Directx (the same applied ) I got this error :

Code used to make 10 copies of ModelManagerSupprt which will contain the model and the effect and will holds chrachter controller (BEPU Phsics Engine) :
 

            
            foreach (ModelManagerSupport dwarfModel in dwarfModels)
            {
                //dwarfModel.model = Content.Load<Model>("Models//dwarf//dwarfmodel");
                //dwarfModel.effect = Content.Load<Effect>("Models//dwarf//skinFX");
                //dwarfModel.setEffect(camera , game);
                //dwarfModel.setModelAnimationStatus(game);
                //dwarfModel.intializeChrachterController(new Vector3(0, 0, 0), 20, 10, 2000, 2000, 80, 40);

                //space.Add(dwarfModel.chrachterController);

                //dwarfModels.Add(dwarfModel);
            }

 

 


iatq84t8ca58z3x6g.jpg

Edited by mrmohadnan

Share this post


Link to post
Share on other sites
Asking for code is typically a bad approach. People don't want to write your software for you, and besides that ruins all the fun of it :). What you want to do is "instanced drawing". You load the model once into a Vertex Buffer, and then draw the same object over and over using different shader parameters. Edited by metsfan

Share this post


Link to post
Share on other sites

If your models have a lot of detail and your game starts to stall, you can try to implement Instancing, so instead of having separate draw call for identical zombies (for instance say 100 draw calls). You have one shader, which can draw desired number of models at once.

You can read about animated model instancing here:

 

http://developer.download.nvidia.com/SDK/10/direct3d/Source/SkinnedInstancing/doc/SkinnedInstancingWhitePaper.pdf

 

It might get tricky so first thing is to ask yourself if you really need such optimisation.

Edited by Tasaq

Share this post


Link to post
Share on other sites

OK , Thaaaaaanks so much , but for now I will not do Instancing , all I need is to figure out the bug in my game .

If I load 2 models ( the same model zombie ) and give them the same effect I got the following errore :

 

   for(int i =0 ; i<2 ; i++)
        {
            dwarfModel[i].model = Content.Load<Model>("Models//dwarf//dwarfmodel");
            dwarfModel[i].effect = Content.Load<Effect>("Models//dwarf//skinFX");
            dwarfModel[i].setEffect(camera , game);
            dwarfModel[i].setModelAnimationStatus(game);
            dwarfModel[i].intializeChrachterController(new Vector3(0, 0, 0), 20, 10, 2000, 2000, 80, 40);

            space.Add(dwarfModel[i].chrachterController);

            dwarfModels.Add(dwarfModel);
        }

 

 


iatq84t8ca58z3x6g.jpg

Edited by mrmohadnan

Share this post


Link to post
Share on other sites

that has nothing to do with loading 1, 10, 100 or 1 million objects.

That's just a problem trying to upcast and Effect into something that is not (a BasicEffect), just as the error message is complaining about.

 

The rest of the thread doesn't make a lot of sense either... unless you want to draw 1 million zombies in the same pose, you'll need to draw them separately.

Having the animation data shared for all the zombies or one for every zombie is a memory problem.. are you having problems with memory? If you have, I bet there are MANY other places eating up your memory.. but seriously, considering the fact that you can't understand a simple error message like that means you don't have problems with memory solvable by sharing animation data.. so my suggestion is.. keep coding and forget about all this.

Share this post


Link to post
Share on other sites

well.. sorry to be blunt, but if you dont understand why a cast is failing at runtime you should go back to basics and study C#, inheritance and all that before moving on.

 

Let's have a base class Effect, and then BasicEffect and CustomEffect derived from that. You cannot cast an Effect into a BasicEffect if that is pointing to a CustomEffect... .NET is gentle enough to point that out for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this