Panda3D

eggToMaya.cxx

00001 // Filename: eggToMaya.cxx
00002 // Created by:  drose (11Aug05)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "eggToMaya.h"
00016 #include "mayaEggLoader.h"
00017 #include "mayaApi.h"
00018 #ifdef _WIN32
00019   #include "pystub.h"
00020 #endif
00021 
00022 // We must define this to prevent Maya from doubly-declaring its
00023 // MApiVersion string in this file as well as in libmayaegg.
00024 #define _MApiVersion
00025 
00026 #include "pre_maya_include.h"
00027 #include <maya/MString.h>
00028 #include <maya/MFileIO.h>
00029 #include "post_maya_include.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: EggToMaya::Constructor
00033 //       Access: Public
00034 //  Description: 
00035 ////////////////////////////////////////////////////////////////////
00036 EggToMaya::
00037 EggToMaya() :
00038   EggToSomething("Maya", ".mb", true, false)
00039 {
00040   add_units_options();
00041 
00042   set_binary_output(true);
00043   set_program_description
00044     ("egg2maya converts files from egg format to Maya .mb or .ma "
00045      "format.  It contains support for basic geometry (polygons with textures)."
00046      "It also supports animation for joints.");
00047 
00048   add_option
00049     ("a", "", 0,
00050      "Convert animation tables.",
00051      &EggToMaya::dispatch_none, &_convert_anim);
00052 
00053   add_option
00054     ("m", "", 0,
00055      "Convert polygon models.  You may specify both -a and -m at the same "
00056      "time.  If you specify neither, the default is -m.",
00057      &EggToMaya::dispatch_none, &_convert_model);
00058 
00059   add_option
00060     ("nv", "", 0,
00061      "respect vertex and polygon normals.",
00062      &EggToMaya::dispatch_none, &_respect_normals);
00063 
00064   // Maya files always store centimeters.
00065   _output_units = DU_centimeters;
00066 }
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: EggToMaya::run
00070 //       Access: Public
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 void EggToMaya::
00074 run() {
00075   if (!_convert_anim && !_convert_model) {
00076     _convert_model = true;
00077   }
00078 
00079   // Let's convert the output file to a full path before we initialize
00080   // Maya, since Maya now has a nasty habit of changing the current
00081   // directory.
00082   _output_filename.make_absolute();
00083 
00084   nout << "Initializing Maya.\n";
00085   PT(MayaApi) maya = MayaApi::open_api(_program_name);
00086   if (!maya->is_valid()) {
00087     nout << "Unable to initialize Maya.\n";
00088     exit(1);
00089   }
00090 
00091   MStatus status;
00092   status = MFileIO::newFile(true);
00093   if (!status) {
00094     status.perror("Could not initialize file");
00095     exit(1);
00096   }
00097 
00098   // [gjeon] since maya's internal unit is fixed to cm
00099   // and when we can't change UI unit without affecting data
00100   // all distance data is converted to cm
00101   // we need to convert them back to proper output unit user provided here
00102   // along with UI unit
00103   maya->set_units(_output_units);
00104 
00105   if (_output_units != DU_centimeters && _output_units != DU_invalid) {
00106     nout << "Converting from centimeters"
00107          << " to " << format_long_unit(_output_units) << "\n";
00108   }
00109 
00110   // Now convert the data.
00111   if (!MayaLoadEggData(_data, true, _convert_model, _convert_anim, _respect_normals)) {
00112     nout << "Unable to convert egg file.\n";
00113     exit(1);
00114   }
00115 
00116   if (!maya->write(_output_filename)) {
00117     status.perror("Could not save file");
00118     exit(1);
00119   }
00120     
00121   /*
00122   // And write out the resulting Maya file.
00123   string os_specific = _output_filename.to_os_generic();
00124   const char *file_type = NULL;
00125   if (_output_filename.get_extension() == "mb") {
00126     file_type = "mayaBinary";
00127   }
00128   status = MFileIO::saveAs(os_specific.c_str(), file_type);
00129   if (!status) {
00130     status.perror("Could not save file");
00131     exit(1);
00132   }
00133   */
00134 }
00135 
00136 int main(int argc, char *argv[]) {
00137   // We don't want pystub on linux, since it gives problems with Maya's python.
00138 #ifdef _WIN32
00139   // A call to pystub() to force libpystub.so to be linked in.
00140   pystub();
00141 #endif
00142 
00143   EggToMaya prog;
00144   prog.parse_command_line(argc, argv);
00145   prog.run();
00146   return 0;
00147 }
00148 
 All Classes Functions Variables Enumerations