26 const std::string &preferred_extension,
27 bool allow_last_param,
bool allow_stdout) :
28 EggConverter(format_name, preferred_extension, allow_last_param, allow_stdout)
31 if (_allow_last_param) {
32 add_runline(
"[opts] input" + _preferred_extension +
" output.egg");
34 add_runline(
"[opts] -o output.egg input" + _preferred_extension);
36 add_runline(
"[opts] input" + _preferred_extension +
" >output.egg");
44 "Specify the coordinate system of the input " + _format_name +
45 " file. Normally, this can inferred from the file itself.");
49 "Don't allow the input " + _format_name +
" file to have absolute pathnames. " 50 "If it does, abort with an error. This option is designed to help " 51 "detect errors when populating or building a standalone model tree, " 52 "which should be self-contained and include only relative pathnames.",
53 &SomethingToEgg::dispatch_none, &_noabs);
57 "Don't treat it as an error if the input file references pathnames " 58 "(e.g. textures) that don't exist. Normally, this will be flagged as " 59 "an error and the command aborted; with this option, an egg file will " 60 "be generated anyway, referencing pathnames that do not exist.",
61 &SomethingToEgg::dispatch_none, &_noexist);
65 "Ignore non-fatal errors and generate an egg file anyway.",
66 &SomethingToEgg::dispatch_none, &_allow_errors);
68 _input_units = DU_invalid;
69 _output_units = DU_invalid;
70 _animation_convert = AC_none;
71 _got_start_frame =
false;
72 _got_end_frame =
false;
73 _got_frame_inc =
false;
74 _got_neutral_frame =
false;
75 _got_input_frame_rate =
false;
76 _got_output_frame_rate =
false;
77 _merge_externals =
false;
90 "Specify the units of the input " + _format_name +
91 " file. Normally, this can be inferred from the file itself.",
92 &SomethingToEgg::dispatch_units,
nullptr, &_input_units);
96 "Specify the units of the resulting egg file. If this is " 97 "specified, the vertices in the egg file will be scaled as " 98 "necessary to make the appropriate units conversion; otherwise, " 99 "the vertices will be left as they are.",
100 &SomethingToEgg::dispatch_units,
nullptr, &_output_units);
109 (
"a",
"animation-mode", 40,
110 "Specifies how animation from the " + _format_name +
" file is " 111 "converted to egg, if at all. At present, the following keywords " 112 "are supported: none, pose, flip, strobe, model, chan, or both. " 113 "The default is none, which means not to convert animation.",
114 &SomethingToEgg::dispatch_animation_convert,
nullptr, &_animation_convert);
118 "Specifies the name of the animation character. This should match " 119 "between all of the model files and all of the channel files for a " 120 "particular model and its associated channels.",
121 &SomethingToEgg::dispatch_string,
nullptr, &_character_name);
124 (
"sf",
"start-frame", 40,
125 "Specifies the starting frame of animation to extract. If omitted, " 126 "the first frame of the time slider will be used. For -a pose, this " 127 "is the one frame of animation to extract.",
128 &SomethingToEgg::dispatch_double, &_got_start_frame, &_start_frame);
131 (
"ef",
"end-frame", 40,
132 "Specifies the ending frame of animation to extract. If omitted, " 133 "the last frame of the time slider will be used.",
134 &SomethingToEgg::dispatch_double, &_got_end_frame, &_end_frame);
137 (
"if",
"frame-inc", 40,
138 "Specifies the increment between successive frames. If omitted, " 139 "this is taken from the time slider settings, or 1.0 if the time " 140 "slider does not specify.",
141 &SomethingToEgg::dispatch_double, &_got_frame_inc, &_frame_inc);
144 (
"nf",
"neutral-frame", 40,
145 "Specifies the frame number to use for the neutral pose. The model " 146 "will be set to this frame before extracting out the neutral character. " 147 "If omitted, the current frame of the model is used. This is only " 148 "relevant for -a model or -a both.",
149 &SomethingToEgg::dispatch_double, &_got_neutral_frame, &_neutral_frame);
153 "Specify the frame rate (frames per second) of the input " + _format_name +
154 " file. Normally, this can be inferred from the file itself.",
155 &SomethingToEgg::dispatch_double, &_got_input_frame_rate, &_input_frame_rate);
159 "Specify the frame rate (frames per second) of the generated animation. " 160 "If this is specified, the animation speed is scaled by the appropriate " 161 "factor based on the frame rate of the input file (see -fri).",
162 &SomethingToEgg::dispatch_double, &_got_output_frame_rate, &_output_frame_rate);
172 "Follow and convert all external references in the source file.",
173 &SomethingToEgg::dispatch_none, &_merge_externals);
181 void SomethingToEgg::
182 apply_units_scale(
EggData *data) {
183 if (_output_units != DU_invalid && _input_units != DU_invalid &&
184 _input_units != _output_units) {
188 data->transform(LMatrix4d::scale_mat(scale));
197 void SomethingToEgg::
199 _path_replace->_noabs = _noabs;
200 _path_replace->_exists = !_noexist;
205 if (_got_start_frame) {
208 if (_got_end_frame) {
211 if (_got_frame_inc) {
214 if (_got_neutral_frame) {
217 if (_got_input_frame_rate) {
220 if (_got_output_frame_rate) {
228 bool SomethingToEgg::
229 handle_args(Args &args) {
230 if (_allow_last_param && !_got_output_filename && args.size() > 1) {
231 _got_output_filename =
true;
235 if (!(_output_filename.get_extension() ==
"egg")) {
236 nout <<
"Output filename " << _output_filename
237 <<
" does not end in .egg. If this is really what you intended, " 238 "use the -o output_file syntax.\n";
242 if (!verify_output_file_safe()) {
248 nout <<
"You must specify the " << _format_name
249 <<
" file to read on the command line.\n";
253 if (args.size() != 1) {
254 nout <<
"You may only specify one " << _format_name
255 <<
" file to read on the command line. " 256 <<
"You specified: ";
257 Args::const_iterator ai;
258 for (ai = args.begin(); ai != args.end(); ++ai) {
259 nout << (*ai) <<
" ";
267 if (!_input_filename.
exists()) {
268 nout <<
"Cannot find input file " << _input_filename <<
"\n";
272 if (!_got_path_directory && _got_output_filename) {
274 _path_replace->_path_directory = _output_filename.
get_dirname();
286 bool SomethingToEgg::
287 post_command_line() {
291 if (directory.empty()) {
296 return EggConverter::post_command_line();
308 void SomethingToEgg::
309 post_process_egg_file() {
310 apply_units_scale(_data);
318 bool SomethingToEgg::
319 dispatch_animation_convert(
const std::string &opt,
const std::string &arg,
void *var) {
322 if ((*ip) == AC_invalid) {
323 nout <<
"Invalid keyword for -" << opt <<
": " << arg <<
"\n";
std::string get_dirname() const
Returns the directory part of the filename.
This is similar to a ConfigVariableList, but it returns its list as a DSearchPath,...
void set_character_name(const std::string &character_name)
Specifies the name of the character generated.
AnimationConvert
This enumerated type lists the methods by which animation from an animation package might be represen...
string format_long_unit(DistanceUnit unit)
Returns the string representing the full name (plural) for the given unit.
void set_frame_inc(double frame_inc)
Specifies the increment between frames to extract.
void add_animation_options()
Adds options appropriate to animation packages.
double convert_units(DistanceUnit from, DistanceUnit to)
Returns the scaling factor that must be applied to convert from units of "from" to "to".
void set_neutral_frame(double neutral_frame)
Specifies the frame of animation to represent the neutral pose of the model.
This is the primary interface into all the egg data, and the root of the egg file structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a general base class for programs that convert between egg files and some other format.
void set_start_frame(double start_frame)
Specifies the starting frame of the animation to convert, in the units specified by set_input_frame_r...
void set_end_frame(double end_frame)
Specifies the ending frame of the animation to convert, in the units specified by set_input_frame_rat...
The name of a file, such as a texture file or an Egg file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_path_replace(PathReplace *path_replace)
Replaces the PathReplace object (which specifies how to mangle paths from the source to the destinati...
void set_animation_convert(AnimationConvert animation_convert)
Specifies how source animation will be converted into egg structures.
virtual void post_process_egg_file()
Performs any processing of the egg file that is appropriate before writing it out.
AnimationConvert string_animation_convert(const std::string &str)
Converts from a string, as might be input by the user, to one of the known AnimationConvert types.
void add_merge_externals_options()
Adds -f.
void set_output_frame_rate(double output_frame_rate)
Specifies the number of frames per second that the resulting animation should be played at.
void set_input_frame_rate(double input_frame_rate)
Specifies the number of frames per second that is represented by the "frame" unit in the animation pa...
This is a base class for a family of converter classes that manage a conversion from some file type t...
void prepend_directory(const Filename &directory)
Adds a new directory to the front of the search list.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
SomethingToEgg(const std::string &format_name, const std::string &preferred_extension=std::string(), bool allow_last_param=true, bool allow_stdout=true)
The first parameter to the constructor should be the one-word name of the file format that is to be r...
void add_units_options()
Adds -ui and -uo as valid options for this program.