00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "eggMultiBase.h"
00016 #include "eggBase.h"
00017 #include "eggData.h"
00018 #include "eggComment.h"
00019 #include "filename.h"
00020 #include "dSearchPath.h"
00021
00022
00023
00024
00025
00026
00027 EggMultiBase::
00028 EggMultiBase() {
00029 add_option
00030 ("f", "", 80,
00031 "Force complete loading: load up the egg file along with all of its "
00032 "external references.",
00033 &EggMultiBase::dispatch_none, &_force_complete);
00034
00035 add_option
00036 ("noabs", "", 0,
00037 "Don't allow any of the named egg files to have absolute pathnames. "
00038 "If any do, abort with an error. This option is designed to help "
00039 "detect errors when populating or building a standalone model tree, "
00040 "which should be self-contained and include only relative pathnames.",
00041 &EggMultiBase::dispatch_none, &_noabs);
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void EggMultiBase::
00058 post_process_egg_files() {
00059 if (_eggs.empty()) {
00060 return;
00061 }
00062
00063 Eggs::iterator ei;
00064 if (_got_transform) {
00065 nout << "Applying transform matrix:\n";
00066 _transform.write(nout, 2);
00067 LVecBase3d scale, hpr, translate;
00068 if (decompose_matrix(_transform, scale, hpr, translate,
00069 _eggs[0]->get_coordinate_system())) {
00070 nout << "(scale " << scale << ", hpr " << hpr << ", translate "
00071 << translate << ")\n";
00072 }
00073 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
00074 (*ei)->transform(_transform);
00075 }
00076 }
00077
00078 if (_make_points) {
00079 nout << "Making points\n";
00080 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
00081 (*ei)->make_point_primitives();
00082 }
00083 }
00084
00085 switch (_normals_mode) {
00086 case NM_strip:
00087 nout << "Stripping normals.\n";
00088 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
00089 (*ei)->strip_normals();
00090 (*ei)->remove_unused_vertices(true);
00091 }
00092 break;
00093
00094 case NM_polygon:
00095 nout << "Recomputing polygon normals.\n";
00096 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
00097 (*ei)->recompute_polygon_normals();
00098 (*ei)->remove_unused_vertices(true);
00099 }
00100 break;
00101
00102 case NM_vertex:
00103 nout << "Recomputing vertex normals.\n";
00104 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) {
00105 (*ei)->recompute_vertex_normals(_normals_threshold);
00106 (*ei)->remove_unused_vertices(true);
00107 }
00108 break;
00109
00110 case NM_preserve:
00111
00112 break;
00113 }
00114 }
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 PT(EggData) EggMultiBase::
00130 read_egg(const Filename &filename) {
00131 PT(EggData) data = new EggData;
00132
00133 if (!data->read(filename)) {
00134
00135 return (EggData *)NULL;
00136 }
00137
00138 if (_noabs && data->original_had_absolute_pathnames()) {
00139 nout << filename.get_basename()
00140 << " includes absolute pathnames!\n";
00141 return (EggData *)NULL;
00142 }
00143
00144 DSearchPath file_path;
00145 file_path.append_directory(filename.get_dirname());
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 if (_force_complete) {
00156 if (!data->load_externals()) {
00157 return (EggData *)NULL;
00158 }
00159 }
00160
00161
00162
00163 EggBase::convert_paths(data, _path_replace, file_path);
00164
00165 if (_got_coordinate_system) {
00166 data->set_coordinate_system(_coordinate_system);
00167 } else {
00168 _coordinate_system = data->get_coordinate_system();
00169 _got_coordinate_system = true;
00170 }
00171
00172 return data;
00173 }