Now that we’ve moved to the third dimension and we are rendering meshes on the screen, we need to be able to edit the mesh data easily. Until now the mesh data is hard coded in the code and editing the data requires some knowledge about how the code works. In this assignment, the aim is to start work towards solving this problem. I define a lua based human readable file format that will define a mesh. This is the first step towards loading an asset straight out of maya.
The point of human readable asset files is to make them easy to edit and debug. The format should be such that a person with no or little technical knowledge should be able to edit it easily, and at the same time a person with technical knowledge should be able to debug errors in the file. To achieve this format I use lua, there is no specific reason to choose lua you could use json, xml or any other format, I chose lua out of convenience. A thing to note here is that a human readable file is not necessarily easy to parse, the main objective of the file is to be human readable. I will work towards making the files easy to parse in the future but for now, that is not my main concern.
In this new format the plane that you saw in the last assignment looks like this.
The file is made up of two main structures: vertices and indices. Each vertex has a vertex position and color which is understandable to both artists and programmers. The indices are defined in the right hand winding order and the order of the vertices does not matter as long as their index is correct in the index array. While defining the vertex array I could have taken another approach and had two arrays: one for the vertex position and another for the vertex color. Though this would have been easier to parse, it would be bit more difficult to edit and quite difficult to debug when the number of vertices becomes large. By keeping the vertex position and color together in pairs, it becomes easy to correlate these values to what is being rendered on screen. I chose to clearly label the individual components in order to make clear what they represent and remove ambiguity.
The most challenging (and stressful) part of this assignment for me was writing the code to parse the asset file. Because lua parsing is not straightforward, I had to constantly keep in mind where I am in the lua stack, when I need to pop and when I need to test. Luckily there were some handy tips that our professor JP had given to us that helped me modularize the actions on lua stack to keep from not getting lost in it.
Once all the changes were done, the final test was to check if the mesh is loaded and rendered properly. This is what the final output looks like.
I am very excited to take this further and be at a point where I can export data straight from maya, load it into the game and display it.