Panda3D
eggToObj.cxx
1 // Filename: eggToObj.cxx
2 // Created by: drose (28Feb12)
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 "eggToObj.h"
16 #include "pystub.h"
17 #include "eggPolygon.h"
18 #include "eggGroupNode.h"
19 #include "dcast.h"
20 #include "string_utils.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Function: EggToObj::Constructor
24 // Access: Public
25 // Description:
26 ////////////////////////////////////////////////////////////////////
27 EggToObj::
28 EggToObj() :
29  EggToSomething("Obj", ".obj", true, false)
30 {
31  set_program_brief("convert .egg files to .obj");
32  set_program_description
33  ("This program converts egg files to obj. It "
34  "only converts polygon data, with no fancy tricks. "
35  "Very bare-bones at the moment; not even texture maps are supported.");
36 
37  redescribe_option
38  ("cs",
39  "Specify the coordinate system of the resulting " + _format_name +
40  " file. Normally, this is z-up.");
41 
42  add_option
43  ("C", "", 0,
44  "Clean out higher-order polygons by subdividing into triangles.",
45  &EggToObj::dispatch_none, &_triangulate_polygons);
46 
47  _coordinate_system = CS_zup_right;
48  _got_coordinate_system = true;
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: EggToObj::run
53 // Access: Public
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 void EggToObj::
57 run() {
58  if (_triangulate_polygons) {
59  nout << "Triangulating polygons.\n";
60  int num_produced = _data->triangulate_polygons(~0);
61  nout << " (" << num_produced << " triangles produced.)\n";
62  }
63 
64  EggToObjConverter saver;
65  saver.set_egg_data(_data);
66 
67  if (!saver.write_file(get_output_filename())) {
68  nout << "An error occurred while writing.\n";
69  exit(1);
70  }
71 }
72 
73 ////////////////////////////////////////////////////////////////////
74 // Function: EggToObj::handle_args
75 // Access: Protected, Virtual
76 // Description: Does something with the additional arguments on the
77 // command line (after all the -options have been
78 // parsed). Returns true if the arguments are good,
79 // false otherwise.
80 ////////////////////////////////////////////////////////////////////
81 bool EggToObj::
82 handle_args(ProgramBase::Args &args) {
83  return EggToSomething::handle_args(args);
84 }
85 
86 int main(int argc, char *argv[]) {
87  // A call to pystub() to force libpystub.so to be linked in.
88  pystub();
89 
90  EggToObj prog;
91  prog.parse_command_line(argc, argv);
92  prog.run();
93  return 0;
94 }
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_...
virtual bool write_file(const Filename &filename)
Handles the conversion of the internal EggData to the target file format, written to the specified fi...
void set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
This is the general base class for a file-converter program that reads some model file format and gen...
Convert an obj file to egg data.