00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mayaToEgg.h"
00020 #include "mayaToEggConverter.h"
00021 #include "config_mayaegg.h"
00022 #include "config_maya.h"
00023
00024
00025
00026
00027
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
00077
00078
00079
00080 void MayaToEgg::
00081 run() {
00082
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
00095
00096
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
00109 converter._polygon_output = _polygon_output;
00110 converter._polygon_tolerance = _polygon_tolerance;
00111 converter._transform_type = _transform_type;
00112
00113
00114 apply_parameters(converter);
00115
00116
00117 if (!_got_coordinate_system) {
00118 _coordinate_system = converter._maya->get_coordinate_system();
00119 }
00120 _data.set_coordinate_system(_coordinate_system);
00121
00122
00123
00124
00125
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
00144
00145
00146
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 }