00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "somethingToEgg.h"
00020 #include "somethingToEggConverter.h"
00021
00022 #include "config_util.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 SomethingToEgg::
00033 SomethingToEgg(const string &format_name,
00034 const string &preferred_extension,
00035 bool allow_last_param, bool allow_stdout) :
00036 EggConverter(format_name, preferred_extension, allow_last_param, allow_stdout)
00037 {
00038 clear_runlines();
00039 if (_allow_last_param) {
00040 add_runline("[opts] input" + _preferred_extension + " output.egg");
00041 }
00042 add_runline("[opts] -o output.egg input" + _preferred_extension);
00043 if (_allow_stdout) {
00044 add_runline("[opts] input" + _preferred_extension + " >output.egg");
00045 }
00046
00047
00048 remove_option("f");
00049
00050 redescribe_option
00051 ("cs",
00052 "Specify the coordinate system of the input " + _format_name +
00053 " file. Normally, this can inferred from the file itself.");
00054
00055 add_option
00056 ("ignore", "", 0,
00057 "Ignore non-fatal errors and generate an egg file anyway.",
00058 &SomethingToEgg::dispatch_none, &_allow_errors);
00059
00060 _input_units = DU_invalid;
00061 _output_units = DU_invalid;
00062 _animation_convert = AC_none;
00063 _got_start_frame = false;
00064 _got_end_frame = false;
00065 _got_frame_inc = false;
00066 _got_neutral_frame = false;
00067 _got_input_frame_rate = false;
00068 _got_output_frame_rate = false;
00069 _merge_externals = false;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void SomethingToEgg::
00082 add_units_options() {
00083 add_option
00084 ("ui", "units", 40,
00085 "Specify the units of the input " + _format_name +
00086 " file. Normally, this can be inferred from the file itself.",
00087 &SomethingToEgg::dispatch_units, NULL, &_input_units);
00088
00089 add_option
00090 ("uo", "units", 40,
00091 "Specify the units of the resulting egg file. If this is "
00092 "specified, the vertices in the egg file will be scaled as "
00093 "necessary to make the appropriate units conversion; otherwise, "
00094 "the vertices will be left as they are.",
00095 &SomethingToEgg::dispatch_units, NULL, &_output_units);
00096 }
00097
00098
00099
00100
00101
00102
00103 void SomethingToEgg::
00104 add_animation_options() {
00105 add_option
00106 ("a", "animation-mode", 40,
00107 "Specifies how animation from the " + _format_name + " file is "
00108 "converted to egg, if at all. At present, the following keywords "
00109 "are supported: none, pose, flip, model, chan, or both. The default "
00110 "is none, which means not to convert animation.",
00111 &SomethingToEgg::dispatch_animation_convert, NULL, &_animation_convert);
00112
00113 add_option
00114 ("cn", "name", 40,
00115 "Specifies the name of the animation character. This should match "
00116 "between all of the model files and all of the channel files for a "
00117 "particular model and its associated channels.",
00118 &SomethingToEgg::dispatch_string, NULL, &_character_name);
00119
00120 add_option
00121 ("sf", "start-frame", 40,
00122 "Specifies the starting frame of animation to extract. If omitted, "
00123 "the first frame of the time slider will be used. For -a pose, this "
00124 "is the one frame of animation to extract.",
00125 &SomethingToEgg::dispatch_double, &_got_start_frame, &_start_frame);
00126
00127 add_option
00128 ("ef", "end-frame", 40,
00129 "Specifies the ending frame of animation to extract. If omitted, "
00130 "the last frame of the time slider will be used.",
00131 &SomethingToEgg::dispatch_double, &_got_end_frame, &_end_frame);
00132
00133 add_option
00134 ("if", "frame-inc", 40,
00135 "Specifies the increment between successive frames. If omitted, "
00136 "this is taken from the time slider settings, or 1.0 if the time "
00137 "slider does not specify.",
00138 &SomethingToEgg::dispatch_double, &_got_frame_inc, &_frame_inc);
00139
00140 add_option
00141 ("nf", "neutral-frame", 40,
00142 "Specifies the frame number to use for the neutral pose. The model "
00143 "will be set to this frame before extracting out the neutral character. "
00144 "If omitted, the current frame of the model is used. This is only "
00145 "relevant for -a model or -a both.",
00146 &SomethingToEgg::dispatch_double, &_got_neutral_frame, &_neutral_frame);
00147
00148 add_option
00149 ("fri", "fps", 40,
00150 "Specify the frame rate (frames per second) of the input " + _format_name +
00151 " file. Normally, this can be inferred from the file itself.",
00152 &SomethingToEgg::dispatch_double, &_got_input_frame_rate, &_input_frame_rate);
00153
00154 add_option
00155 ("fro", "fps", 40,
00156 "Specify the frame rate (frames per second) of the generated animation. "
00157 "If this is specified, the animation speed is scaled by the appropriate "
00158 "factor based on the frame rate of the input file (see -ri).",
00159 &SomethingToEgg::dispatch_double, &_got_output_frame_rate, &_output_frame_rate);
00160 }
00161
00162
00163
00164
00165
00166
00167 void SomethingToEgg::
00168 add_merge_externals_options() {
00169 add_option
00170 ("f", "", 40,
00171 "Follow and convert all external references in the source file.",
00172 &SomethingToEgg::dispatch_none, &_merge_externals);
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182 void SomethingToEgg::
00183 apply_units_scale(EggData &data) {
00184 if (_output_units != DU_invalid && _input_units != DU_invalid &&
00185 _input_units != _output_units) {
00186 nout << "Converting from " << format_long_unit(_input_units)
00187 << " to " << format_long_unit(_output_units) << "\n";
00188 double scale = convert_units(_input_units, _output_units);
00189 data.transform(LMatrix4d::scale_mat(scale));
00190 }
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 void SomethingToEgg::
00202 apply_parameters(SomethingToEggConverter &converter) {
00203 converter.set_path_replace(_path_replace);
00204
00205 converter.set_animation_convert(_animation_convert);
00206 converter.set_character_name(_character_name);
00207 if (_got_start_frame) {
00208 converter.set_start_frame(_start_frame);
00209 }
00210 if (_got_end_frame) {
00211 converter.set_end_frame(_end_frame);
00212 }
00213 if (_got_frame_inc) {
00214 converter.set_frame_inc(_frame_inc);
00215 }
00216 if (_got_neutral_frame) {
00217 converter.set_neutral_frame(_neutral_frame);
00218 }
00219 if (_got_input_frame_rate) {
00220 converter.set_input_frame_rate(_input_frame_rate);
00221 }
00222 if (_got_output_frame_rate) {
00223 converter.set_output_frame_rate(_output_frame_rate);
00224 }
00225 }
00226
00227
00228
00229
00230
00231
00232 bool SomethingToEgg::
00233 handle_args(Args &args) {
00234 if (_allow_last_param && !_got_output_filename && args.size() > 1) {
00235 _got_output_filename = true;
00236 _output_filename = Filename::from_os_specific(args.back());
00237 args.pop_back();
00238
00239 if (!(_output_filename.get_extension() == "egg")) {
00240 nout << "Output filename " << _output_filename
00241 << " does not end in .egg. If this is really what you intended, "
00242 "use the -o output_file syntax.\n";
00243 return false;
00244 }
00245
00246 if (!verify_output_file_safe()) {
00247 return false;
00248 }
00249 }
00250
00251 if (args.empty()) {
00252 nout << "You must specify the " << _format_name
00253 << " file to read on the command line.\n";
00254 return false;
00255 }
00256
00257 if (args.size() != 1) {
00258 nout << "You may only specify one " << _format_name
00259 << " file to read on the command line. "
00260 << "You specified: ";
00261 Args::const_iterator ai;
00262 for (ai = args.begin(); ai != args.end(); ++ai) {
00263 nout << (*ai) << " ";
00264 }
00265 nout << "\n";
00266 return false;
00267 }
00268
00269 _input_filename = Filename::from_os_specific(args[0]);
00270
00271 if (!_input_filename.exists()) {
00272 nout << "Cannot find input file " << _input_filename << "\n";
00273 return false;
00274 }
00275
00276 return true;
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 bool SomethingToEgg::
00290 post_command_line() {
00291
00292 DSearchPath &model_path = get_model_path();
00293 Filename directory = _input_filename.get_dirname();
00294 if (directory.empty()) {
00295 directory = ".";
00296 }
00297 model_path.prepend_directory(directory);
00298
00299 return EggConverter::post_command_line();
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 void SomethingToEgg::
00315 post_process_egg_file() {
00316 apply_units_scale(_data);
00317 EggConverter::post_process_egg_file();
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327 bool SomethingToEgg::
00328 dispatch_animation_convert(const string &opt, const string &arg, void *var) {
00329 AnimationConvert *ip = (AnimationConvert *)var;
00330 (*ip) = string_animation_convert(arg);
00331 if ((*ip) == AC_invalid) {
00332 nout << "Invalid keyword for -" << opt << ": " << arg << "\n";
00333 return false;
00334 }
00335
00336 return true;
00337 }