Panda3D
eggToObj.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 eggToObj.cxx
10  * @author drose
11  * @date 2012-02-28
12  */
13 
14 #include "eggToObj.h"
15 #include "eggPolygon.h"
16 #include "eggGroupNode.h"
17 #include "dcast.h"
18 #include "string_utils.h"
19 
20 /**
21  *
22  */
23 EggToObj::
24 EggToObj() :
25  EggToSomething("Obj", ".obj", true, false)
26 {
27  set_program_brief("convert .egg files to .obj");
28  set_program_description
29  ("This program converts egg files to obj. It "
30  "only converts polygon data, with no fancy tricks. "
31  "Very bare-bones at the moment; not even texture maps are supported.");
32 
33  redescribe_option
34  ("cs",
35  "Specify the coordinate system of the resulting " + _format_name +
36  " file. Normally, this is z-up.");
37 
38  add_option
39  ("C", "", 0,
40  "Clean out higher-order polygons by subdividing into triangles.",
41  &EggToObj::dispatch_none, &_triangulate_polygons);
42 
43  _coordinate_system = CS_zup_right;
44  _got_coordinate_system = true;
45 }
46 
47 /**
48  *
49  */
50 void EggToObj::
51 run() {
52  if (_triangulate_polygons) {
53  nout << "Triangulating polygons.\n";
54  int num_produced = _data->triangulate_polygons(~0);
55  nout << " (" << num_produced << " triangles produced.)\n";
56  }
57 
58  EggToObjConverter saver;
59  saver.set_egg_data(_data);
60 
61  if (!saver.write_file(get_output_filename())) {
62  nout << "An error occurred while writing.\n";
63  exit(1);
64  }
65 }
66 
67 /**
68  * Does something with the additional arguments on the command line (after all
69  * the -options have been parsed). Returns true if the arguments are good,
70  * false otherwise.
71  */
72 bool EggToObj::
73 handle_args(ProgramBase::Args &args) {
74  return EggToSomething::handle_args(args);
75 }
76 
77 int main(int argc, char *argv[]) {
78  EggToObj prog;
79  prog.parse_command_line(argc, argv);
80  prog.run();
81  return 0;
82 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Filename get_output_filename() const
If has_output_filename() returns true, this is the filename that the user specified.
void set_egg_data(EggData *egg_data)
Sets the egg data that will be filled in when convert_file() is called.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.