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