Jump to content
  • Advertisement
Sign in to follow this  
Synthesizer

Octrees & models

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

I'm trying to optimize (once again) my XNA game project.
I've been using an octree for a long time ONLY to check collisions but not to draw, & now I'd like to use it to draw as well.
Nowadays in order to draw I'm looping through all the objects & drawing them if they are in the view frustum.

I'm currently building my models by myself (in 3Ds Max), & a Model usually contains many parts (Meshes). It may be a telephone (with buttons, wire, etc), or a train station (with stairs, lamp posts, rails, house, bridge, etc, etc, etc). Because of this, in order to check for collisions, I store the Meshes in each octree leaf (not the models).
It works good because I can identify if I'm standing over a stairstep or if i collided onto a solid wall or so.

The main issue is that the "draw" method is in my Model & not in my Mesh (& I cannot build a draw method per mesh because the model applies the corresponding transformations to its meshes when drawing them, inside "draw" method).
I thought of storing a reference to the model on each mesh, so when looping through the meshes in the octree, I call the draw method of the mesh owner's model. But the problem is that I will find several meshes which belong to the same model...

It's a mess...
I hope you can help me!

Thanks a lot for reading & helping!
Synth

Share this post


Link to post
Share on other sites
Advertisement

I'm trying to optimize (once again) my XNA game project.
I've been using an octree for a long time ONLY to check collisions but not to draw, & now I'd like to use it to draw as well.
Nowadays in order to draw I'm looping through all the objects & drawing them if they are in the view frustum.

I'm currently building my models by myself (in 3Ds Max), & a Model usually contains many parts (Meshes). It may be a telephone (with buttons, wire, etc), or a train station (with stairs, lamp posts, rails, house, bridge, etc, etc, etc). Because of this, in order to check for collisions, I store the Meshes in each octree leaf (not the models).
It works good because I can identify if I'm standing over a stairstep or if i collided onto a solid wall or so.

The main issue is that the "draw" method is in my Model & not in my Mesh (& I cannot build a draw method per mesh because the model applies the corresponding transformations to its meshes when drawing them, inside "draw" method).
I thought of storing a reference to the model on each mesh, so when looping through the meshes in the octree, I call the draw method of the mesh owner's model. But the problem is that I will find several meshes which belong to the same model...

It's a mess...
I hope you can help me!

Thanks a lot for reading & helping!
Synth



The storage of the reference sounds like a good idea but instead of drawing that whole model how about you get the information from the model that is nessecary to draw the mesh and submit that drawcall. In my own code I introduced a layer between model and mesh which is a meshgroup. This mesh group stores the material that mesh is using and it's object transform and is then contained in a list in the model. This way the mesh group knows all the data it needs, except for the global world transform but having a reference to the model will solve that, to be rendered.

You could even write your code in such a way that your visibility determination flags meshes to be visible, once you come to render the actual model you actually only render the meshes that are visible.

Share this post


Link to post
Share on other sites
I'm familiar with XNA's way of drawing things so I'm a bit confused by the "draw" method that is the Model class.

In XNA 4.0 (and I believe also 3.1) the Model class as defined by XNA doesn't have a Draw method. It's the Mesh objects in them that do, and usually you loop through the list of Meshes in a Model and call Mesh.Draw(). What XNA version are you using? Are you referring to a custom Draw method that you made for the models?

The way I draw culled meshes is that I have a class called CustomModel which stores the XNA Model itself, the list of visible meshes, and other metadata about the model. Usually what I do is cull the individual Meshes for each Model and store the visible ones in the list, which could change every frame. I clear the lists every frame right before culling. So this problem doesn't seem like it's at all related to octrees, actually, but in the way that you are grouping your culled meshes.

To draw them, I first loop through the CustomModels, and if its visible Mesh list isn't empty, apply the transformations, which will get passed to the meshes anyways because of how the effect parameters are set. I then loop through the list of visible Meshes and set my more mesh-specific parameters, and call the Draw function of each mesh.

Share this post


Link to post
Share on other sites
Hi guys,
thank you very much for your answers. I think you helped me in finding the path!
I managed to use my octree to draw static models :)

I'm using XNA 3.1 and yes, you are right JustChris: ModelMesh contains a Draw method, but I was using a custom "draw" method in my own "ExtendedModel" class (same as your CustomModel I guess).
Now I created a custom "draw" in my "ExtendedModelMesh" class which (now) contains a reference to the ExtendedModel (as well as materials; something like NightCreature83 said I think).

I loop through the ExtendedModelMeshes in the octree: when I have to draw it, (by using a delegate) I trigger a method that calls ExtendedModelMesh's draw method, & as it has a reference to the ExtendedModel, I can access its transforms :)

I also noticed that I was calculating the models' transforms at each frame (& I guess it's wastefull as they are static models & they won't move, rotate nor scale :D) So now I'm calculating it at startup & store the model transforms in a matrix.

It's 5am so I'm completely burned up, hehe, but I think everything is working fine! (otherwise I'll post again :P)

So thank you very much for your help, you opened my eyes!!!
Synth

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!