Tuesday 12 November 2013

Compiling PhyreEngine’s Collada Plugin for Maya 2014

In the previous post we went over PhyreEngine’s setup process, the previous post was more of a tutorial and with this post I’m going to take a different approach and try to walk you through my thought process. If you are not interested in my thought process and just want to see how to compile the plugin for Maya 2014, scroll down to the TLDR at the bottom of this post.*space*
The asset pipeline in PhyreEngine at a very high level is as follows:

   I.    Create asset in Maya or 3DS Max  
  II.     Export asset in Collada (.dae) file format 
 III.  Convert asset data to platform specific runtime asset
    This is a heavily simplified version of Phyre’s asset pipeline, in a future blog post I will get down and dirty with Phyre’s asset pipeline and go into a lot more detail about it.

    When we installed PhyreEngine, there was an option to install exporters for Maya. So that means Phyre installed the Collada plug-in for us…right?

    So I went into Maya 2014 and of course, the exporter wasn’t there. First thing I did was try looking for the exporter in the Phyre directory.

    Image 1. Versions of Maya PhyreEngine 3.4 installs the exporter for
     It turns out PhyreEngine 3.4 installs the exporter for every version of Maya…except the version we’re using, Maya 2014.

    Collada files have the .dae file extension. I noticed that Maya has a .dae exporter so I figured it wouldn’t hurt to give it a shot. Long story short, it didn’t work. The engine would complain and wants us to export models using their exporter.

    So at this point, the way I see things, I have two options:
    1.    Use Maya 2013
    2.    Solve the problem

    Spoilers: I solved the problem.

    Jumping to Maya 2013 would be taking the easy way out and was considered the last resort. Now I am going to go through my process of solving this problem. The first thing that came to mind when I saw all these different versions of the same plugin for the different versions of Maya was “has the creators of Collada written a version for Maya 2014?” so I went to the Google and searched for “Collada”, of course I went straight to Wikipedia. To my dismay I saw that the latest version of Collada was created in August 2008, 5 years ago. So I immediately started to wonder: “how could it be that a plugin that was written in 2008 is able to work with a program created in 2014?”

    My first thought was: maybe all of the Collada plugin files are the same and Phyre’s install just simply copies the plugin into the appropriate Maya directory (defined by an environment variable), but since Maya 2014 wasn’t released when this version of PhyreEngine (3.4) was built, Phyre doesn’t know the name of the Maya 2014 environment variable and therefore cannot put the plugin in the appropriate folder. So I tried simply copying the Maya 2013 plugin into the Maya 2014 plugin directory.

    Maya’s plugin manager was able to find the plugin. However enabling the plugin resulted in several errors, so obviously this means each version of the Collada plugin for Maya is in some way different. Let’s try and figure out how.

    Fortunately PhyreEngine gives us the source for the Collada plugin for Maya. I opened the source and I had no idea where to start. So I tried to just build the project, and it failed. Never in my life have I been so thankful for a project to fail compiling.

    Image 2. Errors when attempting to compile Maya exporter

    The compiler is very clearly telling us that it cannot find a file. Also we see that the directory it is looking for is using angled brackets, rather than quotes. This means that the directory that the project is looking for was added to the “Additional Include Directories” project property.

    Navigating to the Additional Include Directories property (Under C/C++) and inspecting the values we see:

    Image 3. Include directories for Maya 2013 plug-in. Note the "2013" in the file path.
    In the image above we see that the project is looking for the Maya 2013 environment variable which defines Maya 2013’s directory. Very, very interesting. Let’s look at Maya 2012’s property pages.

    Image 4. Include directories for Maya 2013 plug-in. Note the "2012" in the file path.
    We see the exact same thing. This means my first thought wasn’t that far off. Each of these Phyre build configurations were manually made by the PhyreEngine team to specify the install directory of a specific Maya Version. Since Maya 2014 wasn’t out when this version of Phyre was released, they could not make a configuration for it.

    So how do we fix this? I created a new build configuration for Maya 2014 in the configuration manager. I also chose to copy the settings from the Maya 2013 build configuration.

    Image 5. Visual Studio Configuration Manager. I am creating a new config named Maya 2014.

    Now lets set the correct include directory for the newly created configuration. The error says it was looking for MBoundingBox.h, well where the heck is MBoundingBox.h? There is this very useful program called “Everything” which very quickly searches every file on your computer so I simply entered “MBoundingBox.h” into Everything and sure enough, it found it in the Maya 2014 directory. 

    Image 6. I used the handy program "Everything" to locate the location of the file on my computer. Observe that the file path is the exact same as the paths for the Maya 2013 and 2012 versions with the only difference being "2014"
    Now that we know where the file is located, lets simply add its directory to the VC property page. Let’s try rebuilding the project, and of course it fails.

    Image 7. Now the compiler is telling us it cannot find a library file.

    Can’t find a library file…well is there a lib folder in the Maya directory? Why yes there is. Let’s go ahead and add that.

    Now the solution builds successfully. Going back to the exporter directory, we see our newly built Maya 2014 plugin. 
    Image 8. Observe that a 2014 version of the exporter has been built.
    Now the question is, will it work?

    We install the plugin by putting the generted .mll file in the Maya plugin directory:
    %MAYA_INSTALL_DIR%/bin\plug-ins

    And putting the associated scripts in the scripts folder:

    C:\Users\%USERNAME%\Maya2014\bin\plug-ins\My Documents\ maya\2014-64x\scripts

    We can now go back into Maya and successfully load the Collada plugin and export without error.

    Now that we finally have a model exported in a format Phyre likes, let’s import it and render it in engine…actually lets save that for another day.

    TLDR;

    PhyreEngine 3.4 does not install the Collada plugin for Maya 2014, I am not sure if PhyreEngine 3.5 does or not, but if it doesn't I am confident that these same steps will apply.

    Steps to build PhyreEngine's exporter for Maya 2014:
    1. Build a new configuration in the configuration manager, copying settings from Maya 2013. (Image 5)
        *space*
    2. Update the Visual Studio Project include property (C/C++ > Additional Include Directories) to the include folder in Maya 2014's path (%MAYA_INSTALL_DIR%\include)
       *space*
    3. Update the Visual Studio Project Library directory (VC++ Directories > Library Directories) to include the lib folder in Maya 2014's path (%MAYA_INSTALL_DIR%\lib)
       *space*
    4. Copy the generated .mll (located at %SCE_PHYRE\Tools\Exporters\ColladaMaya\*YOUR CONFIG NAME*) file
      to: %MAYA_INSTALL_DIR%/bin\plug-ins
       
      *space*
    5. Copy the mel scripts associated with the exporter (located at %SCE_PHYRE%\Tools\Exporters\ColladaMaya\Scripts)
      to: C:\Users\%USERNAME%\Maya2014\bin\plug-ins\My Documents\ maya\2014-64x\scripts
       
      *space*
    6. Enable the Plug-in in Maya's plugin manager.

    Note: %MAYA_INSTALL_DIR% is the path where you installed Maya, you may not have a environment variable with this name. Fore example, my install directory for Maya is: C:\Program Files\Autodesk\Maya2014

    IMO It's always fun to list the steps after you solve a problem like this, comparing how simple the solution is to all the things you tried. It's kinda funny, you can spend a few hours trying to figure out something that only takes a minute to to.  As usual, if you have any questions tweet me at @MikeGameDev and I'll try my best to help you out.

    No comments:

    Post a Comment