Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/mayaprogs/mayaToEgg.cxx

Go to the documentation of this file.
00001 // Filename: mayaToEgg.cxx
00002 // Created by:  drose (15Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "mayaToEgg.h"
00020 #include "mayaToEggConverter.h"
00021 #include "config_mayaegg.h"
00022 #include "config_maya.h"  // for maya_cat
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: MayaToEgg::Constructor
00026 //       Access: Public
00027 //  Description:
00028 ////////////////////////////////////////////////////////////////////
00029 MayaToEgg::
00030 MayaToEgg() :
00031   SomethingToEgg("Maya", ".mb")
00032 {
00033   add_path_replace_options();
00034   add_path_store_options();
00035   add_animation_options();
00036   add_units_options();
00037   add_normals_options();
00038   add_transform_options();
00039 
00040   set_program_description
00041     ("This program converts Maya model files to egg.  Nothing fancy yet.");
00042 
00043   add_option
00044     ("p", "", 0,
00045      "Generate polygon output only.  Tesselate all NURBS surfaces to "
00046      "polygons via the built-in Maya tesselator.  The tesselation will "
00047      "be based on the tolerance factor given by -ptol.",
00048      &MayaToEgg::dispatch_none, &_polygon_output);
00049 
00050   add_option
00051     ("ptol", "tolerance", 0,
00052      "Specify the fit tolerance for Maya polygon tesselation.  The smaller "
00053      "the number, the more polygons will be generated.  The default is "
00054      "0.01.",
00055      &MayaToEgg::dispatch_double, NULL, &_polygon_tolerance);
00056 
00057   add_option
00058     ("trans", "type", 0,
00059      "Specifies which transforms in the Maya file should be converted to "
00060      "transforms in the egg file.  The option may be one of all, model, "
00061      "dcs, or none.  The default is model, which means only transforms on "
00062      "nodes that have the model flag or the dcs flag are preserved.",
00063      &MayaToEgg::dispatch_transform_type, NULL, &_transform_type);
00064 
00065   add_option
00066     ("v", "", 0,
00067      "Increase verbosity.  More v's means more verbose.",
00068      &MayaToEgg::dispatch_count, NULL, &_verbose);
00069 
00070   _verbose = 0;
00071   _polygon_tolerance = 0.01;
00072   _transform_type = MayaToEggConverter::TT_model;
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: MayaToEgg::run
00077 //       Access: Public
00078 //  Description:
00079 ////////////////////////////////////////////////////////////////////
00080 void MayaToEgg::
00081 run() {
00082   // Set the verbose level by using Notify.
00083   if (_verbose >= 3) {
00084     maya_cat->set_severity(NS_spam);
00085     mayaegg_cat->set_severity(NS_spam);
00086   } else if (_verbose >= 2) {
00087     maya_cat->set_severity(NS_debug);
00088     mayaegg_cat->set_severity(NS_debug);
00089   } else if (_verbose >= 1) {
00090     maya_cat->set_severity(NS_info);
00091     mayaegg_cat->set_severity(NS_info);
00092   }
00093 
00094   // Let's convert the output file to a full path before we initialize
00095   // Maya, since Maya now has a nasty habit of changing the current
00096   // directory.
00097   if (_got_output_filename) {
00098     _output_filename.make_absolute();
00099   }
00100 
00101   nout << "Initializing Maya.\n";
00102   MayaToEggConverter converter(_program_name);
00103   if (!converter.open_api()) {
00104     nout << "Unable to initialize Maya.\n";
00105     exit(1);
00106   }
00107 
00108   // Copy in the command-line parameters.
00109   converter._polygon_output = _polygon_output;
00110   converter._polygon_tolerance = _polygon_tolerance;
00111   converter._transform_type = _transform_type;
00112 
00113   // Copy in the path and animation parameters.
00114   apply_parameters(converter);
00115 
00116   // Set the coordinate system to match Maya's.
00117   if (!_got_coordinate_system) {
00118     _coordinate_system = converter._maya->get_coordinate_system();
00119   }
00120   _data.set_coordinate_system(_coordinate_system);
00121 
00122   // Use the standard Maya units, if the user didn't specify
00123   // otherwise.  This always returns centimeters, which is the way all
00124   // Maya files are stored internally (and is the units returned by
00125   // all of the API functions called here).
00126   if (_input_units == DU_invalid) {
00127     _input_units = converter._maya->get_units();
00128   }
00129 
00130   converter.set_egg_data(&_data, false);
00131   apply_parameters(converter);
00132 
00133   if (!converter.convert_file(_input_filename)) {
00134     nout << "Errors in conversion.\n";
00135     exit(1);
00136   }
00137 
00138   write_egg_file();
00139   nout << "\n";
00140 }
00141 
00142 ////////////////////////////////////////////////////////////////////
00143 //     Function: MayaToEgg::dispatch_transform_type
00144 //       Access: Protected, Static
00145 //  Description: Dispatches a parameter that expects a
00146 //               MayaToEggConverter::TransformType option.
00147 ////////////////////////////////////////////////////////////////////
00148 bool MayaToEgg::
00149 dispatch_transform_type(const string &opt, const string &arg, void *var) {
00150   MayaToEggConverter::TransformType *ip = (MayaToEggConverter::TransformType *)var;
00151   (*ip) = MayaToEggConverter::string_transform_type(arg);
00152 
00153   if ((*ip) == MayaToEggConverter::TT_invalid) {
00154     nout << "Invalid type for -" << opt << ": " << arg << "\n"
00155          << "Valid types are all, model, dcs, and none.\n";
00156     return false;
00157   }
00158 
00159   return true;
00160 }
00161 
00162 int main(int argc, char *argv[]) {
00163   MayaToEgg prog;
00164   prog.parse_command_line(argc, argv);
00165   prog.run();
00166   return 0;
00167 }

Generated on Fri May 2 03:21:27 2003 for Panda-Tool by doxygen1.3