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