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