The main objective of this assignment is to create a binary version of our human readable mesh file. The reason we are doing this because this reduces the file size and significantly improves the runtime loading.
We have to make a couple of changes to the Mesh file . We basically have to move the code which reads the Lua file and migrate it from the Graphics project to the MeshBuilder. The reason we do this is so that the builder can covert the lua mesh file to the binary file.
The above image shows the binary file in a hex reader. The structure is the same as we discussed in the lecture. The first 4 bytes have the number of vertices. The next 4 bytes have the vertices. The next 12 bytes are the vertex struct and after that is the indices array.
The size of the binary is only 80 bytes which is significantly lower than the file of the mesh file which is 346 bytes .
The important thing to note and take care of is that the number of vertices needs to come before the vertices or in the other words the number of elements in an array must come before the array. The is because we need to know the number of elements to read before we actually start reading the elements. This is done so that there is clarity in the type of data that we are reading and also the number of elements that we are reading.
The following image shows the way I extract the information from the Binary File :-
The 3 advantages of the binary file format are:
1) Like I mentioned in the start , the reason we are converting the lua to binary file to reduce the file size which improves the runtime loading since no parsing is needed after loading the data from the file.
2)The file size of the binary is significantly lower than the lua file which is only 80 bytes as compared to 356 bytes of the lua file.
3) Another advantage is that we only need to order the data correctly in the corresponding memory blocks and read them in the read them in that correct order.
The binary have significant advantages as discussed above but they are hard to decipher and the lua mesh file are undoubtedly the better human readable formats. So it is better to keep them especially during debugging situations.
The next part of the assignment was to encapsulate the shader’s into the GraphicEffects class like we did for the case of Mesh in order to make it platform independent. I made the structure similar to the Mesh file structure.
Overall the assignment took me around 10 hours to complete . I learnt a lot about binary files and their purpose while working on this assignment. It was fun to finally understand and decipher the binary files which were a complete mystery to me before. I also read the email regarding the project dependencies and I have made changes to the project dependencies.
You can download the Zip File of Assignment_05 from the following link to get the square output.
After downloading the link run Game.exe.