00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "mayaToEgg.h"
00043 #include "mayaToEggConverter.h"
00044 #include "config_mayaegg.h"
00045 #include "config_maya.h"
00046 #include "globPattern.h"
00047 #ifdef _WIN32
00048 #include "pystub.h"
00049 #endif
00050
00051
00052
00053
00054
00055
00056 MayaToEgg::
00057 MayaToEgg() :
00058 SomethingToEgg("Maya", ".mb")
00059 {
00060 add_path_replace_options();
00061 add_path_store_options();
00062 add_animation_options();
00063 add_units_options();
00064 add_normals_options();
00065 add_transform_options();
00066
00067 set_program_description
00068 ("This program converts Maya model files to egg. Static and animatable "
00069 "models can be converted, with polygon or NURBS output. Animation tables "
00070 "can also be generated to apply to an animatable model.");
00071
00072 add_option
00073 ("p", "", 0,
00074 "Generate polygon output only. Tesselate all NURBS surfaces to "
00075 "polygons via the built-in Maya tesselator. The tesselation will "
00076 "be based on the tolerance factor given by -ptol.",
00077 &MayaToEgg::dispatch_none, &_polygon_output);
00078
00079 add_option
00080 ("ptol", "tolerance", 0,
00081 "Specify the fit tolerance for Maya polygon tesselation. The smaller "
00082 "the number, the more polygons will be generated. The default is "
00083 "0.01.",
00084 &MayaToEgg::dispatch_double, NULL, &_polygon_tolerance);
00085
00086 add_option
00087 ("bface", "", 0,
00088 "Respect the Maya \"double sided\" rendering flag to indicate whether "
00089 "polygons should be double-sided or single-sided. Since this flag "
00090 "is set to double-sided by default in Maya, it is often better to "
00091 "ignore this flag (unless your modelers are diligent in turning it "
00092 "off where it is not desired). If this flag is not specified, the "
00093 "default is to treat all polygons as single-sided, unless an "
00094 "egg object type of \"double-sided\" is set.",
00095 &MayaToEgg::dispatch_none, &_respect_maya_double_sided);
00096
00097 add_option
00098 ("suppress-vcolor", "", 0,
00099 "Ignore vertex color for geometry that has a texture applied. "
00100 "(This is the way Maya normally renders internally.) The egg flag "
00101 "'vertex-color' may be applied to a particular model to override "
00102 "this setting locally.",
00103 &MayaToEgg::dispatch_none, &_suppress_vertex_color);
00104
00105 add_option
00106 ("keep-uvs", "", 0,
00107 "Convert all UV sets on all vertices, even those that do not appear "
00108 "to be referenced by any textures.",
00109 &MayaToEgg::dispatch_none, &_keep_all_uvsets);
00110
00111 add_option
00112 ("round-uvs", "", 0,
00113 "round up uv coordinates to the nearest 1/100th. i.e. -0.001 becomes"
00114 "0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.",
00115 &MayaToEgg::dispatch_none, &_round_uvs);
00116
00117 add_option
00118 ("copytex", "dir", 41,
00119 "Legacy option. Same as -pc.",
00120 &MayaToEgg::dispatch_filename, &_legacy_copytex, &_legacy_copytex_dir);
00121
00122 add_option
00123 ("trans", "type", 0,
00124 "Specifies which transforms in the Maya file should be converted to "
00125 "transforms in the egg file. The option may be one of all, model, "
00126 "dcs, or none. The default is model, which means only transforms on "
00127 "nodes that have the model flag or the dcs flag are preserved.",
00128 &MayaToEgg::dispatch_transform_type, NULL, &_transform_type);
00129
00130 add_option
00131 ("subroot", "name", 0,
00132 "Specifies that only a subroot of the geometry in the Maya file should "
00133 "be converted; specifically, the geometry under the node or nodes whose "
00134 "name matches the parameter (which may include globbing characters "
00135 "like * or ?). This parameter may be repeated multiple times to name "
00136 "multiple roots. If it is omitted altogether, the entire file is "
00137 "converted.",
00138 &MayaToEgg::dispatch_vector_string, NULL, &_subroots);
00139
00140 add_option
00141 ("subset", "name", 0,
00142 "Specifies that only a subset of the geometry in the Maya file should "
00143 "be converted; specifically, the geometry under the node or nodes whose "
00144 "name matches the parameter (which may include globbing characters "
00145 "like * or ?). This parameter may be repeated multiple times to name "
00146 "multiple roots. If it is omitted altogether, the entire file is "
00147 "converted.",
00148 &MayaToEgg::dispatch_vector_string, NULL, &_subsets);
00149
00150 add_option
00151 ("exclude", "name", 0,
00152 "Specifies that a subset of the geometry in the Maya file should "
00153 "not be converted; specifically, the geometry under the node or nodes whose "
00154 "name matches the parameter (which may include globbing characters "
00155 "like * or ?). This parameter may be repeated multiple times to name "
00156 "multiple roots.",
00157 &MayaToEgg::dispatch_vector_string, NULL, &_excludes);
00158
00159 add_option
00160 ("ignore-slider", "name", 0,
00161 "Specifies the name of a slider (blend shape deformer) that maya2egg "
00162 "should not process. The slider will not be touched during conversion "
00163 "and it will not become a part of the animation. This "
00164 "parameter may including globbing characters, and it may be repeated "
00165 "as needed.",
00166 &MayaToEgg::dispatch_vector_string, NULL, &_ignore_sliders);
00167
00168 add_option
00169 ("force-joint", "name", 0,
00170 "Specifies the name of a DAG node that maya2egg "
00171 "should treat as a joint, even if it does not appear to be a Maya joint "
00172 "and does not appear to be animated.",
00173 &MayaToEgg::dispatch_vector_string, NULL, &_force_joints);
00174
00175 add_option
00176 ("v", "", 0,
00177 "Increase verbosity. More v's means more verbose.",
00178 &MayaToEgg::dispatch_count, NULL, &_verbose);
00179
00180 add_option
00181 ("legacy-shaders", "", 0,
00182 "Use this flag to turn off modern (Phong) shader generation"
00183 "and treat all shaders as if they were Lamberts (legacy).",
00184 &MayaToEgg::dispatch_none, &_legacy_shader);
00185
00186
00187
00188
00189
00190 remove_option("noabs");
00191
00192 _verbose = 0;
00193 _polygon_tolerance = 0.01;
00194 _transform_type = MayaToEggConverter::TT_model;
00195 _got_tbnauto = true;
00196 }
00197
00198
00199
00200
00201
00202
00203 void MayaToEgg::
00204 run() {
00205
00206 if (_verbose >= 3) {
00207 maya_cat->set_severity(NS_spam);
00208 mayaegg_cat->set_severity(NS_spam);
00209 } else if (_verbose >= 2) {
00210 maya_cat->set_severity(NS_debug);
00211 mayaegg_cat->set_severity(NS_debug);
00212 } else if (_verbose >= 1) {
00213 maya_cat->set_severity(NS_info);
00214 mayaegg_cat->set_severity(NS_info);
00215 }
00216
00217 if (_legacy_copytex && !_path_replace->_copy_files) {
00218 _path_replace->_copy_files = true;
00219 _path_replace->_copy_into_directory = _legacy_copytex_dir;
00220 }
00221
00222
00223
00224
00225 if (_got_output_filename) {
00226 _output_filename.make_absolute();
00227 _path_replace->_path_directory.make_absolute();
00228 }
00229
00230 nout << "Initializing Maya.\n";
00231 MayaToEggConverter converter(_program_name);
00232
00233
00234 if (!converter.open_api(false)) {
00235 nout << "Unable to initialize Maya.\n";
00236 exit(1);
00237 }
00238
00239
00240 converter._polygon_output = _polygon_output;
00241 converter._polygon_tolerance = _polygon_tolerance;
00242 converter._respect_maya_double_sided = _respect_maya_double_sided;
00243 converter._always_show_vertex_color = !_suppress_vertex_color;
00244 converter._keep_all_uvsets = _keep_all_uvsets;
00245 converter._round_uvs = _round_uvs;
00246 converter._transform_type = _transform_type;
00247 converter._legacy_shader = _legacy_shader;
00248
00249 vector_string::const_iterator si;
00250 if (!_subroots.empty()) {
00251 converter.clear_subroots();
00252 for (si = _subroots.begin(); si != _subroots.end(); ++si) {
00253 converter.add_subroot(GlobPattern(*si));
00254 }
00255 }
00256
00257 if (!_subsets.empty()) {
00258 converter.clear_subsets();
00259 for (si = _subsets.begin(); si != _subsets.end(); ++si) {
00260 converter.add_subset(GlobPattern(*si));
00261 }
00262 }
00263
00264 if (!_excludes.empty()) {
00265 converter.clear_excludes();
00266 for (si = _excludes.begin(); si != _excludes.end(); ++si) {
00267 converter.add_exclude(GlobPattern(*si));
00268 }
00269 }
00270
00271 if (!_ignore_sliders.empty()) {
00272 converter.clear_ignore_sliders();
00273 for (si = _ignore_sliders.begin(); si != _ignore_sliders.end(); ++si) {
00274 converter.add_ignore_slider(GlobPattern(*si));
00275 }
00276 }
00277
00278 if (!_force_joints.empty()) {
00279 converter.clear_force_joints();
00280 for (si = _force_joints.begin(); si != _force_joints.end(); ++si) {
00281 converter.add_force_joint(GlobPattern(*si));
00282 }
00283 }
00284
00285
00286 apply_parameters(converter);
00287
00288
00289 if (!_got_coordinate_system) {
00290 _coordinate_system = converter._maya->get_coordinate_system();
00291 }
00292 _data->set_coordinate_system(_coordinate_system);
00293
00294 converter.set_egg_data(_data);
00295
00296 if (!converter.convert_file(_input_filename)) {
00297 nout << "Errors in conversion.\n";
00298 exit(1);
00299 }
00300
00301
00302
00303
00304
00305 if (_input_units == DU_invalid) {
00306 _input_units = converter.get_input_units();
00307 }
00308
00309 write_egg_file();
00310 nout << "\n";
00311 }
00312
00313
00314
00315
00316
00317
00318
00319 bool MayaToEgg::
00320 dispatch_transform_type(const string &opt, const string &arg, void *var) {
00321 MayaToEggConverter::TransformType *ip = (MayaToEggConverter::TransformType *)var;
00322 (*ip) = MayaToEggConverter::string_transform_type(arg);
00323
00324 if ((*ip) == MayaToEggConverter::TT_invalid) {
00325 nout << "Invalid type for -" << opt << ": " << arg << "\n"
00326 << "Valid types are all, model, dcs, and none.\n";
00327 return false;
00328 }
00329
00330 return true;
00331 }
00332
00333 int main(int argc, char *argv[]) {
00334
00335 #ifdef _WIN32
00336
00337 pystub();
00338 #endif
00339
00340 MayaToEgg prog;
00341 prog.parse_command_line(argc, argv);
00342 prog.run();
00343 return 0;
00344 }
00345