Meshes

Assignment 04

This assignment was one of the first tests of our mesh structure from the previous assignments. We had to load the mesh data from a file instead of hard coding the data. This allows us to dynamically modify the mesh data such as vertex positions, colors and even amount of vertices or indices. This task should have been easy if the mesh structure was designed for scaling. Thankfully I had designed the mesh to be a class with all the related code encapsulated inside. For more details on this, see the previous assignment description here. The output can be seen to be the same as previous as I had copied the same vertex and index data as the previous assignment. Special care was to be taken for loading indices for Direct3D, as we had a single winding order.

Shaders

One more requirement for this assignment was to combine the .glsl and .hlsl shaders into one platform independent file. I used the extension of .shader just so I can distinguish the file as my own file extension and not a third party standard. And it has too many letters for shorthand notation of .shdr and might be confusing. That was the whole goal of the assignment that we should design files and extension which can be easy to read and understand. One weird thing I notices about the shaders, especially in OpenGL, is that it is very sensitive to spaces. I had a space after defined in #if defined (...) and it didn’t compile the shader. After a few hours of debugging and a Kdiff comparison later I found the space which was causing the trouble. Direct3D worked fine with the space and displayed the square correctly. Wasting so much time in this debugging, I chose not to make any changes to the shader code apart from which fulfilled the basic requirements and focus on the other part of the assignment . Some potential changes I could see were making the last few lines of code that are same out of the #if defined block.

Loading Meshes

We also had to design a mesh file with lua syntax to read the mesh data and pass it to the mesh object in the code. The mesh file is a Lua table with two elements, vertices and indices. Vertices is an array of individual vertex data, which is again a dictionary with two elements, position and color. Each of the elements are an array with 2 and 4 values respectively. Some of the design choices made were to keep the key as position instead of pos. Also I chose not to write keys inside the position and color tables. This would have made the file more cluttered and confusing. The indices is an array of index values. I could have put them in individual arrays but I decided against it in order to not over-complicate things.

The winding order for the indices is right handed, because Maya uses the right handed orientation. Any order could be acceptable but it should be platform independent. One thing which we should be mindful about is changing the order while loading for the other platform. The color requires 4 values but the alpha value is always 1. All the choices while deciding between various alternatives, is that it should be easy to read and not overcomplicate any loading which is required. The extension used for this file is .msh, as the shorthand notation is not that difficult to read. That is why I decided to use that file extension.

return
{
	vertices = 
	{
		{
			position = { 0, 0 },
			color = { 1, 0, 0, 1}
		},
		{
			position = { 1, 0 },
			color = { 0, 1, 0, 1}
		},
		{
			position = { 1, 1 },
			color = { 0, 0.5, 1, 1}
		},
		{
			position = { 0, 1 },
			color = { 0.5, 0, 1, 1}
		},
	},
	indices = 
	{
		0, 1, 2,
		0, 2, 3,
	}
}
							

Human Readable formats:

Making files which are similar to the mesh files should be human readable. These files are going to be edited by the artists for the most part. Even if tools are generating files, making them easy to read will be useful for debugging any errors later. Making easy to read files might cause more efforts to be required at the time of reading, but the extra effort is worth it in the long run.

Time Estimate

Reading: 1 hours
Coding: 4 hours
Testing and Fixes: 3 hour
Writeup: 1 hour