00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "xFileToEgg.h"
00016 #include "xFileToEggConverter.h"
00017 #include "config_xfile.h"
00018 #include "pystub.h"
00019
00020
00021
00022
00023
00024
00025 XFileToEgg::
00026 XFileToEgg() :
00027 SomethingToEgg("DirectX", ".x")
00028 {
00029 add_path_replace_options();
00030 add_path_store_options();
00031 add_units_options();
00032 add_normals_options();
00033 add_transform_options();
00034
00035 set_program_description
00036 ("This program converts DirectX retained-mode (.x) files to egg. "
00037 "Polygon meshes, materials, and textures, as well as skeleton "
00038 "animation and skinning data, are supported. All animations "
00039 "found in the source .x file are written together into the same "
00040 "egg file.");
00041
00042 add_option
00043 ("a", "name", 0,
00044 "Specify the name of the animated character to generate. This option "
00045 "forces the model to be converted as an animatable character, even "
00046 "if animation channels are not found in the file. Without this "
00047 "option, the model is converted as a static model (which "
00048 "is usually more efficient to load within Panda), unless animation "
00049 "channels are present in the .x file.",
00050 &XFileToEgg::dispatch_string, &_make_char, &_char_name);
00051
00052 add_option
00053 ("fr", "fps", 0,
00054 "Specify the frame rate of the resulting animation. If this is "
00055 "omitted or 0, the frame rate is inferred from the file itself; but "
00056 "note that the file must contain evenly-spaced keyframes.",
00057 &XFileToEgg::dispatch_double, NULL, &_frame_rate);
00058
00059 add_option
00060 ("anim", "", 0,
00061 "Generate animation data only (all geometry will be discarded).",
00062 &XFileToEgg::dispatch_none, &_keep_animation);
00063
00064 add_option
00065 ("model", "", 0,
00066 "Generate model data only (all animation data will be discarded).",
00067 &XFileToEgg::dispatch_none, &_keep_model);
00068
00069 redescribe_option
00070 ("ui",
00071 "Specify the units of the input " + _format_name + " file.");
00072
00073 redescribe_option
00074 ("uo",
00075 "Specify the units of the resulting egg file. If both this and -ui are "
00076 "specified, the vertices in the egg file will be scaled as "
00077 "necessary to make the appropriate units conversion; otherwise, "
00078 "the vertices will be left as they are.");
00079
00080 redescribe_option
00081 ("cs",
00082 "Specify the coordinate system of the input " + _format_name +
00083 " file. Normally, this is y-up-left.");
00084
00085 _frame_rate = 0.0;
00086 _coordinate_system = CS_yup_left;
00087 }
00088
00089
00090
00091
00092
00093
00094 void XFileToEgg::
00095 run() {
00096 _data->set_coordinate_system(_coordinate_system);
00097
00098 XFileToEggConverter converter;
00099 converter.set_egg_data(_data);
00100
00101 converter._frame_rate = _frame_rate;
00102 converter._make_char = _make_char;
00103 converter._char_name = _char_name;
00104 converter._keep_model = _keep_model;
00105 converter._keep_animation = _keep_animation;
00106
00107
00108 apply_parameters(converter);
00109
00110 if (!converter.convert_file(_input_filename)) {
00111 nout << "Unable to read " << _input_filename << "\n";
00112 exit(1);
00113 }
00114
00115 write_egg_file();
00116 nout << "\n";
00117 }
00118
00119
00120 int main(int argc, char *argv[]) {
00121
00122 pystub();
00123
00124 init_libxfile();
00125 XFileToEgg prog;
00126 prog.parse_command_line(argc, argv);
00127 prog.run();
00128 return 0;
00129 }