Panda3D
lwoToEgg.cxx
1 // Filename: lwoToEgg.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 "lwoToEgg.h"
16 
17 #include "lwoToEggConverter.h"
18 #include "lwoHeader.h"
19 #include "lwoInputFile.h"
20 #include "config_lwo.h"
21 #include "pystub.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: LwoToEgg::Constructor
25 // Access: Public
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 LwoToEgg::
29 LwoToEgg() :
30  SomethingToEgg("Lightwave", ".lwo")
31 {
32  add_path_replace_options();
33  add_path_store_options();
34  add_units_options();
35  add_normals_options();
36  add_transform_options();
37 
38  set_program_brief("convert a Lightwave Object file to .egg");
39  set_program_description
40  ("This program converts Lightwave Object (.lwo) files to egg. Many "
41  "rendering characteristics of Lightwave (like layered shaders, etc.) "
42  "are not supported, but fundamental things like polygons and texture "
43  "maps are. This program is primarily designed to support files written "
44  "by Lightwave version 6.x (LWO2 files), but it also has some limited "
45  "support for version 5.x files (LWOB files).");
46 
47  redescribe_option
48  ("cs",
49  "Specify the coordinate system of the input " + _format_name +
50  " file. Normally, this is y-up-left.");
51 
52  redescribe_option
53  ("ui",
54  "Specify the units of the input Lightwave file. By convention, "
55  "this is assumed to be meters if it is unspecified.");
56 
57  _coordinate_system = CS_yup_left;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: LwoToEgg::run
62 // Access: Public
63 // Description:
64 ////////////////////////////////////////////////////////////////////
65 void LwoToEgg::
66 run() {
67  _data->set_coordinate_system(_coordinate_system);
68 
69  if (_input_units == DU_invalid) {
70  _input_units = DU_meters;
71  }
72 
73  LwoToEggConverter converter;
74  converter.set_egg_data(_data);
75  apply_parameters(converter);
76 
77  if (!converter.convert_file(_input_filename)) {
78  nout << "Errors in conversion.\n";
79  exit(1);
80  }
81 
82  write_egg_file();
83  nout << "\n";
84 }
85 
86 
87 int main(int argc, char *argv[]) {
88  // A call to pystub() to force libpystub.so to be linked in.
89  pystub();
90 
91  init_liblwo();
92  LwoToEgg prog;
93  prog.parse_command_line(argc, argv);
94  prog.run();
95  return 0;
96 }
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 set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
This class supervises the construction of an EggData structure from the data represented by the LwoHe...
This is the general base class for a file-converter program that reads some model file format and gen...
A program to read a Lightwave file and generate an egg file.
Definition: lwoToEgg.h:30
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.