Panda3D
|
00001 // Filename: eggCharacterFilter.cxx 00002 // Created by: drose (23Feb01) 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 "eggCharacterFilter.h" 00016 #include "eggCharacterCollection.h" 00017 #include "eggCharacterData.h" 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: EggCharacterFilter::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 EggCharacterFilter:: 00026 EggCharacterFilter() : EggMultiFilter(false) { 00027 _collection = (EggCharacterCollection *)NULL; 00028 00029 _force_initial_rest_frame = false; 00030 } 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: EggCharacterFilter::Destructor 00034 // Access: Public, Virtual 00035 // Description: 00036 //////////////////////////////////////////////////////////////////// 00037 EggCharacterFilter:: 00038 ~EggCharacterFilter() { 00039 if (_collection != (EggCharacterCollection *)NULL) { 00040 delete _collection; 00041 } 00042 } 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Function: EggCharacterFilter::add_fixrest_option 00046 // Access: Public 00047 // Description: 00048 //////////////////////////////////////////////////////////////////// 00049 void EggCharacterFilter:: 00050 add_fixrest_option() { 00051 add_option 00052 ("fixrest", "", 30, 00053 "Specify this to force all the initial rest frames of the various " 00054 "model files to the same value as the first model specified. This " 00055 "is a fairly drastic way to repair models whose initial rest frame " 00056 "values are completely bogus, but should not be performed when the " 00057 "input models are correct.", 00058 &EggCharacterFilter::dispatch_none, &_force_initial_rest_frame); 00059 } 00060 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: EggCharacterFilter::post_command_line 00064 // Access: Protected, Virtual 00065 // Description: 00066 //////////////////////////////////////////////////////////////////// 00067 bool EggCharacterFilter:: 00068 post_command_line() { 00069 if (_collection == (EggCharacterCollection *)NULL) { 00070 _collection = make_collection(); 00071 } 00072 00073 if (!EggMultiFilter::post_command_line()) { 00074 return false; 00075 } 00076 00077 Eggs::iterator ei; 00078 for (ei = _eggs.begin(); ei != _eggs.end(); ++ei) { 00079 EggData *data = (*ei); 00080 00081 if (_collection->add_egg(data) < 0) { 00082 nout << data->get_egg_filename().get_basename() 00083 << " does not contain a character model or animation channel.\n"; 00084 return false; 00085 } 00086 } 00087 00088 _collection->check_errors(nout, _force_initial_rest_frame); 00089 00090 return true; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: EggCharacterFilter::write_eggs 00095 // Access: Protected, Virtual 00096 // Description: Writes out all of the egg files in the _eggs vector, 00097 // to the output directory if one is specified, or over 00098 // the input files if -inplace was specified. 00099 //////////////////////////////////////////////////////////////////// 00100 void EggCharacterFilter:: 00101 write_eggs() { 00102 // Optimize (that is, collapse redudant nodes) in all of the 00103 // characters' joint tables before writing them out. 00104 int num_characters = _collection->get_num_characters(); 00105 for (int i = 0; i < num_characters; i++) { 00106 EggCharacterData *char_data = _collection->get_character(i); 00107 char_data->get_root_joint()->optimize(); 00108 } 00109 00110 EggMultiFilter::write_eggs(); 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: EggCharacterFilter::make_collection 00115 // Access: Protected, Virtual 00116 // Description: Allocates and returns a new EggCharacterCollection 00117 // structure. This is primarily intended as a hook so 00118 // derived classes can customize the type of 00119 // EggCharacterCollection object used to represent the 00120 // character information. 00121 //////////////////////////////////////////////////////////////////// 00122 EggCharacterCollection *EggCharacterFilter:: 00123 make_collection() { 00124 return new EggCharacterCollection; 00125 }