In this blog, we will discuss creating a mesh exporter plugin for Maya and how it helps us in using external content inside our engine.
In the previous blog, we created our own custom human-readable mesh format to represent meshes and used it to load meshes inside our engine. Now it is easy for us to change content without going into any code. But it is still not a convenient way for content creators to work on meshes. Let's take the gear mesh in the above image as an example, how difficult would it be to write a human-readable mesh file in our custom format for the gear mesh? It is very difficult and it becomes more difficult as the complexity of the mesh increases. So, what is the solution? One solution is to make a custom editor for the content creators that is simple. The editor then exports the mesh created inside it as our human-readable format and we can use it inside our engine. But for this project we are not going to create an editor instead, we will use the existing tools like Maya and create an exporter that Maya can use to export the mesh created inside Maya to our format.
The way we create an exporter for Maya is we create a plugin as a dll(Dynamic Link Library) that Maya can use to export the mesh. We need to install Maya and the devkit for Maya to create the plugin. After setting up Maya and the required environment variables we add the MayaExporterProject to our solution. The exporter is not dependent on any other project in our solution so no reference is needed and there are no other projects in our solution that depend on the exporter.
One other thing to keep in mind is Maya provides more information to us about the mesh than we need in our custom format ( for example information like normals, color, etc). So we have to decide either to export all the data and then use only the information required in the engine or we can only export the data that is needed. I choose to export only the data that is required in my format and the reason is to keep my format and the code handling the mesh loading to be simple. It might also be a little difficult to debug large mesh files with the unneeded data if we go with the first method. Exporting only the required information keeps our human-readable mesh file small and is simple to debug. The only disadvantage with this method is if we update our mesh format then we have to update the plugin as well. I am okay with this as the mesh format will not be changed frequently.
We can also debug our plugin code once we have loaded it inside Maya. Using visual studio we can attach a debugger to maya.exe and setup breakpoints inside our exporter project.
Following is a screenshot that illustrates debugging the exporter project
We talked a little about large mesh files above and one other important thing to keep in mind is our engine has a hard limit on the number of vertices a mesh can have. I think we need to have some kind of limit on how many vertices a mesh can have as we don't have infinite memory. Currently, we assert if the vertex count exceeds the limit in Debug configuration but in Release configuration the size gets truncated to the vertex limit and this might result in undefined behavior so I added few safety checks which returns a failure in mesh initialization when the vertex count is exceeded.
I updated the human-readable mesh format from the last blog. I added new Color information which stores the color value for each vertex. I updated the shaders as well as the mesh initialization methods to use this Color data. You can see that the plane has colors now and the reason for the gradient look is the color values are interpolated between the vertices.
Controls:
ESC – exit.
Up/Down/Left/Right - Move Gear Object
W/A/S/D/Q/E - Move Camera Forward/Left/Baclward/Right/Down/Up
ENTER - Changes the mesh to square and effect to the animating color of the object.
Space - Toggle between main and secondary camera. Note: the secondary camera does not support the movement.
Comments