At first I didn't have the intention on writing this chapter, and
I still think, that there's no need to write it. This part is surprisingly
well document in Maya's help and on the Net. I'm therefore rather summarizing
the techniques, than explaining every detail. Feel free to look for more
information on the web, or even to complement this chapter (it's open-doc,
isn't it;).
In order to write an exporter one needs to interface in some way with
Maya. The more obvious one is of course by writing a plugin, and
implementing Maya's "interfaces". Another interesting approach consists in
writing a stand-alone application, that just uses Maya's libraries. I
recommend keeping the exporter general enough, so it can be used as both.
If the exporter should be accessible from within Maya, the exporter needs
to derive from
MPxFileTranslator. Furthermore some methods must be
implemented:
haveReadMethod: most of the time returns
false.
haveWriteMethod: most of the time returns
true.
reader: most of the time returns an error.
writer: exports the scene. The method, that
does all the work.
identifyFile: recognizes the plugin's files
(or not;).
defaultExtension: obvious.
Note however, that
gpExport already does all this work for
you. By reusing the framework only two methods need to be implemented:
Export: more or less equivalent to writer
getExtension: more or less equivalent to
defaultExtension
Writing an executable is even easier (as long as one knows what libraries
are needed, and how to link them to your executable). One just needs to
initialize the MLibrary, which can be conveniently done using
gpExport's MayaLibrary-class. In the latter case one just needs
instantiate this class, as shown in executable.cpp:
54: MayaLibrary library((char*)exporterName.c_str());
55:
56: loadScene(inFile);
57:
58: MFileObject outMFile;
59: outMFile.setFullName(outFile.c_str());
60: ExporterConfig config(outMFile, "", false);
61:
62: exporter.Export(config);
|
I might say: this file is an excellent example of a
Maya-executable;). Compiling the cpp-file is then easy. What's way more
difficult is the linking. I heavily advise to reuse gpExport's
Makefile. It could save you a lot of time...