Panda3D
xFileToEgg.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file xFileToEgg.cxx
10  * @author drose
11  * @date 2001-06-21
12  */
13 
14 #include "xFileToEgg.h"
15 #include "xFileToEggConverter.h"
16 #include "config_xfile.h"
17 
18 /**
19  *
20  */
21 XFileToEgg::
22 XFileToEgg() :
23  SomethingToEgg("DirectX", ".x")
24 {
25  add_path_replace_options();
26  add_path_store_options();
30 
31  set_program_brief("convert a DirectX .x file to an .egg file");
32  set_program_description
33  ("This program converts DirectX retained-mode (.x) files to egg. "
34  "Polygon meshes, materials, and textures, as well as skeleton "
35  "animation and skinning data, are supported. All animations "
36  "found in the source .x file are written together into the same "
37  "egg file.");
38 
39  add_option
40  ("a", "name", 0,
41  "Specify the name of the animated character to generate. This option "
42  "forces the model to be converted as an animatable character, even "
43  "if animation channels are not found in the file. Without this "
44  "option, the model is converted as a static model (which "
45  "is usually more efficient to load within Panda), unless animation "
46  "channels are present in the .x file.",
47  &XFileToEgg::dispatch_string, &_make_char, &_char_name);
48 
49  add_option
50  ("fr", "fps", 0,
51  "Specify the frame rate of the resulting animation. If this is "
52  "omitted or 0, the frame rate is inferred from the file itself; but "
53  "note that the file must contain evenly-spaced keyframes.",
54  &XFileToEgg::dispatch_double, nullptr, &_frame_rate);
55 
56  add_option
57  ("anim", "", 0,
58  "Generate animation data only (all geometry will be discarded).",
59  &XFileToEgg::dispatch_none, &_keep_animation);
60 
61  add_option
62  ("model", "", 0,
63  "Generate model data only (all animation data will be discarded).",
64  &XFileToEgg::dispatch_none, &_keep_model);
65 
66  redescribe_option
67  ("ui",
68  "Specify the units of the input " + _format_name + " file.");
69 
70  redescribe_option
71  ("uo",
72  "Specify the units of the resulting egg file. If both this and -ui are "
73  "specified, the vertices in the egg file will be scaled as "
74  "necessary to make the appropriate units conversion; otherwise, "
75  "the vertices will be left as they are.");
76 
77  redescribe_option
78  ("cs",
79  "Specify the coordinate system of the input " + _format_name +
80  " file. Normally, this is y-up-left.");
81 
82  _frame_rate = 0.0;
83  _coordinate_system = CS_yup_left;
84 }
85 
86 /**
87  *
88  */
89 void XFileToEgg::
90 run() {
91  _data->set_coordinate_system(_coordinate_system);
92 
93  XFileToEggConverter converter;
94  converter.set_egg_data(_data);
95 
96  converter._frame_rate = _frame_rate;
97  converter._make_char = _make_char;
98  converter._char_name = _char_name;
99  converter._keep_model = _keep_model;
100  converter._keep_animation = _keep_animation;
101 
102  // Copy in the path and animation parameters.
103  apply_parameters(converter);
104 
105  if (!converter.convert_file(_input_filename)) {
106  nout << "Unable to read " << _input_filename << "\n";
107  exit(1);
108  }
109 
110  write_egg_file();
111  nout << "\n";
112 }
113 
114 
115 int main(int argc, char *argv[]) {
116  init_libxfile();
117  XFileToEgg prog;
118  prog.parse_command_line(argc, argv);
119  prog.run();
120  return 0;
121 }
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_normals_options()
Adds -no, -np, etc.
Definition: eggBase.cxx:59
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
void write_egg_file()
Writes out the egg file as the normal result of the program.
Definition: eggWriter.cxx:177
void init_libxfile()
Initializes the library.
void add_transform_options()
Adds -TS, -TT, etc.
Definition: eggBase.cxx:126
This is the general base class for a file-converter program that reads some model file format and gen...
A program to read a DirectX "x" file and generate an egg file.
Definition: xFileToEgg.h:26
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void add_units_options()
Adds -ui and -uo as valid options for this program.