Panda3D
|
00001 // Filename: eggMultiBase.cxx 00002 // Created by: drose (02Nov00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 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 // Function: EggMultiBase::Constructor 00024 // Access: Public 00025 // Description: 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 // Function: EggMultiBase::post_process_egg_files 00046 // Access: Public 00047 // Description: Performs any processing of the egg file(s) that is 00048 // appropriate before writing them out. This includes any 00049 // normal adjustments the user requested via -np, etc. 00050 // 00051 // Normally, you should not need to call this function 00052 // directly; write_egg_files() calls it for you. You 00053 // should call this only if you do not use 00054 // write_egg_files() to write out the resulting egg 00055 // files. 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 switch (_normals_mode) { 00079 case NM_strip: 00080 nout << "Stripping normals.\n"; 00081 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) { 00082 (*ei)->strip_normals(); 00083 (*ei)->remove_unused_vertices(true); 00084 } 00085 break; 00086 00087 case NM_polygon: 00088 nout << "Recomputing polygon normals.\n"; 00089 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) { 00090 (*ei)->recompute_polygon_normals(); 00091 (*ei)->remove_unused_vertices(true); 00092 } 00093 break; 00094 00095 case NM_vertex: 00096 nout << "Recomputing vertex normals.\n"; 00097 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) { 00098 (*ei)->recompute_vertex_normals(_normals_threshold); 00099 (*ei)->remove_unused_vertices(true); 00100 } 00101 break; 00102 00103 case NM_preserve: 00104 // Do nothing. 00105 break; 00106 } 00107 } 00108 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: EggMultiBase::read_egg 00112 // Access: Protected, Virtual 00113 // Description: Allocates and returns a new EggData structure that 00114 // represents the indicated egg file. If the egg file 00115 // cannot be read for some reason, returns NULL. 00116 // 00117 // This can be overridden by derived classes to control 00118 // how the egg files are read, or to extend the 00119 // information stored with each egg structure, by 00120 // deriving from EggData. 00121 //////////////////////////////////////////////////////////////////// 00122 PT(EggData) EggMultiBase:: 00123 read_egg(const Filename &filename) { 00124 PT(EggData) data = new EggData; 00125 00126 if (!data->read(filename)) { 00127 // Failure reading. 00128 return (EggData *)NULL; 00129 } 00130 00131 if (_noabs && data->original_had_absolute_pathnames()) { 00132 nout << filename.get_basename() 00133 << " includes absolute pathnames!\n"; 00134 return (EggData *)NULL; 00135 } 00136 00137 DSearchPath file_path; 00138 file_path.append_directory(filename.get_dirname()); 00139 00140 // We always resolve filenames first based on the source egg 00141 // filename, since egg files almost always store relative paths. 00142 // This is a temporary kludge around integrating the path_replace 00143 // system with the EggData better. 00144 // 00145 // Update: I believe this kludge is obsolete. Commenting out. - Josh. 00146 // data->resolve_filenames(file_path); 00147 00148 if (_force_complete) { 00149 if (!data->load_externals()) { 00150 return (EggData *)NULL; 00151 } 00152 } 00153 00154 // Now resolve the filenames again according to the user's 00155 // specified _path_replace. 00156 EggBase::convert_paths(data, _path_replace, file_path); 00157 00158 if (_got_coordinate_system) { 00159 data->set_coordinate_system(_coordinate_system); 00160 } else { 00161 _coordinate_system = data->get_coordinate_system(); 00162 _got_coordinate_system = true; 00163 } 00164 00165 return data; 00166 }