Game Engineering 2 Assignment 9

Objective:

1. Create a Maya plug-in that can export geometry in a customized mesh format.

2. Add user-defined events to organize the information that PIX shows.

3. Add a setting file that user can specify settings for my game.

Create a Maya Plug-in

Maya plug-ins can be made with C++ and Python. Here I used C++ because I’m not familiar with Python.

Before I start writing the plug-in, there are some set up need to be done in the Visual Studio:

  •  Create a dynamic libaray (.dll) project and set the Target Extension to .mll
  • C++ -> General -> Additional Include Directories: (Maya Install Path)\include\
  • C++ -> Preprocessor: add NT_PLUGIN; REQUIRE_IOSTREAM;
  • Linker->Additional Library Directories: (Maya Install Path)\lib\
  • Linker->Input->Additional Dependencies: add Foundation.lib; OpenMaya.lib;

Autodesk has a file translator example at here. In my case I only need to implement 3 methods:

  • bool haveWriteMethod() const;
  • MString defaultExtension() const;
  • MStatus writer( const MFileObject& i_file, const MString& i_options, FileAccessMode i_mode );

I had a helper function WriteMeshToFile() called from writer() method. This function uses std::ofstream to write vertex and index information to a file. The only thing needs to be noticed is Maya uses right-hand system and Direct3D9 uses left-hand system and this leads to:

  • For position, normal and tangent: z value in Maya needs to be -z in D3D;
  • For bitangent: x and y in Maya needs to be -x, -y in D3D;
  • For texture coordinate: v in Maya needs to be 1 – v in D3D;
  • For index: index for a triangle A, B, C needs to be A, C, B in D3D

Improved AssetBuilder

I improved my AssetBuilder and it now supports multiple image formats. This is what my AssetsToBuild.lua looks like:

assetlist

Now you can use .bmp, .jpg, .tga, .dds as textures instead of using just .png.

Manage Game Scene

I feel like I need a file to organize my scene so I came up with this scene file:

Scene1

It lists all the entities in my scene (Cameras and GameObjects for now). Each game object has 4 parameters: position, rotation, mesh and material.

pyramid.mesh in my Assets folder is a mesh I exported from Maya.

Here is a screenshot of my program:

sc9

 

Orgnize PIX Information

In D3D9 users can group their code with D3DPERF_BeginEvent(0, eventName) and D3DPERF_EndEvent().

I grouped my setting material code and drawing mesh code. Here is a PIX capture showing the events in my program:

PIX_organize

User Settings File

I added a settings file where users can change window width, height and whether the program should run in full screen mode.

The basic idea is treat the setting file as a Lua table and read entities from the table.

Time Estimates

  • Reading – 2 hours
  • Coding – 6 hours
  • Write up – 3 hours
  • Total – 11 hours

Download Executable

Leave a Reply