Panda3D
eggTrans.cxx
1 // Filename: eggTrans.cxx
2 // Created by: drose (14Feb00)
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 "eggTrans.h"
16 #include "eggGroupUniquifier.h"
17 #include "pystub.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: EggTrans::Constructor
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 EggTrans::
25 EggTrans() {
26  add_path_replace_options();
27  add_path_store_options();
32 
33  set_program_brief("apply transformations and optimizations to an .egg file");
34  set_program_description
35  ("egg-trans reads an egg file and writes an essentially equivalent "
36  "egg file to the standard output, or to the file specified with -o. "
37  "Some simple operations on the egg file are supported.");
38 
39  add_option
40  ("F", "", 0,
41  "Flatten out transforms.",
42  &EggTrans::dispatch_none, &_flatten_transforms);
43 
44  add_option
45  ("t", "", 0,
46  "Apply texture matrices to UV's.",
47  &EggTrans::dispatch_none, &_apply_texmats);
48 
49  add_option
50  ("T", "", 0,
51  "Collapse equivalent texture references.",
52  &EggTrans::dispatch_none, &_collapse_equivalent_textures);
53 
54  add_option
55  ("c", "", 0,
56  "Clean out degenerate polygons and unused vertices.",
57  &EggTrans::dispatch_none, &_remove_invalid_primitives);
58 
59  add_option
60  ("C", "", 0,
61  "Clean out higher-order polygons by subdividing into triangles.",
62  &EggTrans::dispatch_none, &_triangulate_polygons);
63 
64  add_option
65  ("mesh", "", 0,
66  "Mesh triangles into triangle strips. This is mainly useful as a "
67  "tool to visualize the work that the mesher will do, since triangles "
68  "are automatically meshed whenever an egg file is loaded. Note that, "
69  "unlike the automatic meshing at load time, you are must ensure that "
70  "you do not start out with multiple triangles with different attributes "
71  "(e.g. texture) together in the same group.",
72  &EggTrans::dispatch_none, &_mesh_triangles);
73 
74  add_option
75  ("N", "", 0,
76  "Standardize and uniquify group names.",
77  &EggTrans::dispatch_none, &_standardize_names);
78 
79 }
80 
81 ////////////////////////////////////////////////////////////////////
82 // Function: EggTrans::run
83 // Access: Public
84 // Description:
85 ////////////////////////////////////////////////////////////////////
86 void EggTrans::
87 run() {
88  if (_remove_invalid_primitives) {
89  nout << "Removing invalid primitives.\n";
90  int num_removed = _data->remove_invalid_primitives(true);
91  nout << " (" << num_removed << " removed.)\n";
92  _data->remove_unused_vertices(true);
93  }
94 
95  if (_triangulate_polygons) {
96  nout << "Triangulating polygons.\n";
97  int num_produced = _data->triangulate_polygons(~0);
98  nout << " (" << num_produced << " triangles produced.)\n";
99  }
100 
101  if (_mesh_triangles) {
102  nout << "Meshing triangles.\n";
103  _data->mesh_triangles(~0);
104  }
105 
106  if (_apply_texmats) {
107  nout << "Applying texture matrices.\n";
108  _data->apply_texmats();
109  _data->remove_unused_vertices(true);
110  }
111 
112  if (_collapse_equivalent_textures) {
113  nout << "Collapsing equivalent textures.\n";
114  int num_removed = _data->collapse_equivalent_textures();
115  nout << " (" << num_removed << " removed.)\n";
116  }
117 
118  if (_flatten_transforms) {
119  nout << "Flattening transforms.\n";
120  _data->flatten_transforms();
121  _data->remove_unused_vertices(true);
122  }
123 
124  if (_standardize_names) {
125  nout << "Standardizing group names.\n";
126  EggGroupUniquifier uniquifier;
127  uniquifier.uniquify(_data);
128  }
129 
130  if (!do_reader_options()) {
131  exit(1);
132  }
133 
134  write_egg_file();
135 }
136 
137 
138 int main(int argc, char *argv[]) {
139  // A call to pystub() to force libpystub.so to be linked in.
140  pystub();
141 
142  EggTrans prog;
143  prog.parse_command_line(argc, argv);
144  prog.run();
145  return 0;
146 }
void add_delod_options(double default_delod=-1.0)
Adds -delod as a valid option for this program.
Definition: eggReader.cxx:114
A program to read an egg file and write an equivalent egg file, possibly performing some minor operat...
Definition: eggTrans.h:28
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_texture_options()
Adds -td, -te, etc.
Definition: eggReader.cxx:77
This is a specialization of EggNameUniquifier to generate unique names for EggGroup nodes...
void add_normals_options()
Adds -no, -np, etc.
Definition: eggBase.cxx:63
void uniquify(EggNode *node)
Begins the traversal from the indicated node.
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