Panda3D
 All Classes Functions Variables Enumerations
fltToEgg.cxx
1 // Filename: fltToEgg.cxx
2 // Created by: drose (17Apr01)
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 "fltToEgg.h"
16 
17 #include "fltToEggConverter.h"
18 #include "config_flt.h"
19 #include "pystub.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltToEgg::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltToEgg::
27 FltToEgg() :
28  SomethingToEgg("MultiGen", ".flt")
29 {
30  add_path_replace_options();
31  add_path_store_options();
32  add_units_options();
33  add_normals_options();
34  add_transform_options();
35  add_merge_externals_options();
36 
37  set_program_brief("convert a MultiGen .flt file to .egg");
38  set_program_description
39  ("This program converts MultiGen OpenFlight (.flt) files to egg. Most "
40  "features of MultiGen that are also recognized by egg are supported.");
41 
42  redescribe_option
43  ("cs",
44  "Specify the coordinate system of the input " + _format_name +
45  " file. Normally, this is z-up.");
46 
47  // Does anyone really care about this option? It's mainly useful
48  // for debugging the flt2egg logic.
49  /*
50  add_option
51  ("C", "", 0,
52  "Compose node transforms into a single matrix before writing them to "
53  "the egg file, instead of writing them as individual scale, rotate, and "
54  "translate operations.",
55  &FltToEgg::dispatch_none, &_compose_transforms);
56  */
57  _compose_transforms = false;
58 
59  _coordinate_system = CS_zup_right;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: FltToEgg::run
64 // Access: Public
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 void FltToEgg::
68 run() {
69  _data->set_coordinate_system(_coordinate_system);
70 
71  FltToEggConverter converter;
72  converter.set_merge_externals(_merge_externals);
73  converter.set_egg_data(_data);
74  converter._compose_transforms = _compose_transforms;
75  converter._allow_errors = _allow_errors;
76 
77  apply_parameters(converter);
78 
79 
80  PT(FltHeader) header = new FltHeader(_path_replace);
81 
82  nout << "Reading " << _input_filename << "\n";
83  FltError result = header->read_flt(_input_filename);
84  if (result != FE_ok) {
85  nout << "Unable to read: " << result << "\n";
86  exit(1);
87  }
88 
89  header->check_version();
90 
91 
92  if (!converter.convert_flt(header)) {
93  nout << "Errors in conversion.\n";
94  exit(1);
95  }
96 
97  if (_input_units == DU_invalid) {
98  _input_units = converter.get_input_units();
99  }
100 
101  write_egg_file();
102  nout << "\n";
103 }
104 
105 
106 int main(int argc, char *argv[]) {
107  // A call to pystub() to force libpystub.so to be linked in.
108  pystub();
109 
110  init_libflt();
111  FltToEgg prog;
112  prog.parse_command_line(argc, argv);
113  prog.run();
114  return 0;
115 }
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_...
This class supervises the construction of an EggData structure from the data represented by the FltHe...
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
virtual DistanceUnit get_input_units()
This may be called after convert_file() has been called and returned true, indicating a successful co...
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
bool convert_flt(const FltHeader *flt_header)
Fills up the egg_data structure according to the indicated lwo structure.
A program to read a flt file and generate an egg file.
Definition: fltToEgg.h:30
void set_merge_externals(bool merge_externals)
Sets the merge_externals flag.
This is the general base class for a file-converter program that reads some model file format and gen...