00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "eggTrans.h"
00020 #include "eggGroupUniquifier.h"
00021
00022
00023
00024
00025
00026
00027 EggTrans::
00028 EggTrans() {
00029 add_path_replace_options();
00030 add_path_store_options();
00031 add_normals_options();
00032 add_transform_options();
00033 add_texture_options();
00034 add_delod_options();
00035
00036 set_program_description
00037 ("egg-trans reads an egg file and writes an essentially equivalent "
00038 "egg file to the standard output, or to the file specified with -o. "
00039 "Some simple operations on the egg file are supported.");
00040
00041 add_option
00042 ("F", "", 0,
00043 "Flatten out transforms.",
00044 &EggTrans::dispatch_none, &_flatten_transforms);
00045
00046 add_option
00047 ("t", "", 0,
00048 "Apply texture matrices to UV's.",
00049 &EggTrans::dispatch_none, &_apply_texmats);
00050
00051 add_option
00052 ("T", "", 0,
00053 "Collapse equivalent texture references.",
00054 &EggTrans::dispatch_none, &_collapse_equivalent_textures);
00055
00056 add_option
00057 ("c", "", 0,
00058 "Clean out degenerate polygons and unused vertices.",
00059 &EggTrans::dispatch_none, &_remove_invalid_primitives);
00060
00061 add_option
00062 ("C", "", 0,
00063 "Clean out higher-order polygons by subdividing into triangles.",
00064 &EggTrans::dispatch_none, &_triangulate_polygons);
00065
00066 add_option
00067 ("N", "", 0,
00068 "Standardize and uniquify group names.",
00069 &EggTrans::dispatch_none, &_standardize_names);
00070
00071 }
00072
00073
00074
00075
00076
00077
00078 void EggTrans::
00079 run() {
00080 if (_remove_invalid_primitives) {
00081 nout << "Removing invalid primitives.\n";
00082 int num_removed = _data.remove_invalid_primitives();
00083 nout << " (" << num_removed << " removed.)\n";
00084 _data.remove_unused_vertices();
00085 }
00086
00087 if (_triangulate_polygons) {
00088 nout << "Triangulating polygons.\n";
00089 int num_produced = _data.triangulate_polygons(true);
00090 nout << " (" << num_produced << " triangles produced.)\n";
00091 }
00092
00093 if (_apply_texmats) {
00094 nout << "Applying texture matrices.\n";
00095 _data.apply_texmats();
00096 _data.remove_unused_vertices();
00097 }
00098
00099 if (_collapse_equivalent_textures) {
00100 nout << "Collapsing equivalent textures.\n";
00101 int num_removed = _data.collapse_equivalent_textures();
00102 nout << " (" << num_removed << " removed.)\n";
00103 }
00104
00105 if (_flatten_transforms) {
00106 nout << "Flattening transforms.\n";
00107 _data.flatten_transforms();
00108 _data.remove_unused_vertices();
00109 }
00110
00111 if (_standardize_names) {
00112 nout << "Standardizing group names.\n";
00113 EggGroupUniquifier uniquifier;
00114 uniquifier.uniquify(&_data);
00115 }
00116
00117 if (!do_reader_options()) {
00118 exit(1);
00119 }
00120
00121 write_egg_file();
00122 }
00123
00124
00125 int main(int argc, char *argv[]) {
00126 EggTrans prog;
00127 prog.parse_command_line(argc, argv);
00128 prog.run();
00129 return 0;
00130 }