Friday, 21 September 2012

Loading FBX Model and caching data

With the first steps taken we can start working in chunks and get a better understanding of what is going on while we load and use our imported model. These next steps will make a few changes to our Model class and create a new class, ModelCache, which will handle some information such as vertex and normal information. This will fix how we store our normals for the geometry and aid in the render process. The code is based on the View Scene Sample and have removed some elements that aren't needed for now. Here we have added a new method to begin caching some information take we will obtain from the model during the loading process with StorModelInformaiton being the entry point for that. The following methods are used to traverse the loaded scene node and also methods for unloaded the stored data when finished with the model. Our entry point for storing the data is after we set the scene to be imported and before the importer is destroyed. Here we use the StoreModelInformation as the entry point to start the recursion process in the scene. The traversal process is simple, we look at the node, check if it is a mesh type, grab our mesh data from that node and process it. We'll process it by creating a VBOMesh object which we will create later, this will store and handle the rendering of the mesh data for us.
Finally at the end of processing the node, check if it has any child nodes. If it does proceed with the same process with those. When finishing with our model we'll make sure to remove the data that we created in the form of our VBOMesh objects. Calling UnloadCachedData begins the unloading process. Here we have our modified drawing method. You'll notice that we now check to see if we have any objects stored as a VBOMesh object in our node before drawing. This gives us the opportunity to grab that and render the mesh with the stored data instead of how we processed it before, which we have as a fall back. Next we have our VBOMesh object that we use for storing our data. The main methods you'll note from earlier are the Initialise, which will handle storing the passed mesh data. BeginDraw which will set up our vertex buffer object for drawing, EndDraw which will end the meshes drawing process and finally Draw which pass our VBO for drawing. The VBOMesh for now will focus on storing vertex data and normal data. Last time we didn't use the normals that were supplied by the model, whereas this time we will store them like the vertex data and pass them when rendering. The initialise method is quite lengthy and you'll want to ensure that the data your storing is correct, otherwise you'll run into rendering upsets later. End result will be that our vertex buffer objects will be generated with normal data.

No comments:

Post a Comment