00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "std3d.h"
00027
00028 #include "3d/animation_set.h"
00029 #include "nel/misc/stream.h"
00030 #include "nel/misc/path.h"
00031 #include "nel/misc/file.h"
00032
00033
00034 #include <memory>
00035
00036
00037
00038 namespace NL3D
00039 {
00040
00041
00042
00043 CAnimationSet::~CAnimationSet ()
00044 {
00045
00046 for (uint a=0; a<_Animation.size(); a++)
00047 delete _Animation[a];
00048 for (uint s=0; s<_SkeletonWeight.size(); s++)
00049 delete _SkeletonWeight[s];
00050 }
00051
00052
00053
00054 uint CAnimationSet::getNumChannelId () const
00055 {
00056 return _ChannelIdByName.size ();
00057 }
00058
00059
00060
00061 uint CAnimationSet::addAnimation (const char* name, CAnimation* animation)
00062 {
00063
00064 _Animation.push_back (animation);
00065 _AnimationName.push_back (name);
00066
00067
00068 _AnimationIdByName.insert (std::map <std::string, uint32>::value_type (name, _Animation.size()-1));
00069
00070
00071 return _Animation.size()-1;
00072 }
00073
00074
00075
00076 uint CAnimationSet::addSkeletonWeight (const char* name, CSkeletonWeight* skeletonWeight)
00077 {
00078
00079 _SkeletonWeight.push_back (skeletonWeight);
00080 _SkeletonWeightName.push_back (name);
00081
00082
00083 _SkeletonWeightIdByName.insert (std::map <std::string, uint32>::value_type (name, _SkeletonWeight.size()-1));
00084
00085
00086 return _SkeletonWeight.size()-1;
00087 }
00088
00089
00090
00091 void CAnimationSet::reset ()
00092 {
00093 _Animation.clear();
00094 _SkeletonWeight.clear();
00095 _AnimationName.clear();
00096 _SkeletonWeightName.clear();
00097 _ChannelIdByName.clear();
00098 _AnimationIdByName.clear();
00099 _SkeletonWeightIdByName.clear();
00100 }
00101
00102
00103
00104 void CAnimationSet::build ()
00105 {
00106
00107 _ChannelIdByName.clear ();
00108
00109
00110 std::set<std::string> channelNames;
00111
00112
00113 for (uint a=0; a<_Animation.size(); a++)
00114 {
00115
00116 getAnimation (a)->getTrackNames (channelNames);
00117 }
00118
00119
00120 uint id=0;
00121 std::set<std::string>::iterator ite=channelNames.begin ();
00122 while (ite!=channelNames.end ())
00123 {
00124
00125 _ChannelIdByName.insert (std::map <std::string, uint32>::value_type (*ite, id++));
00126
00127
00128 ite++;
00129 }
00130 }
00131
00132
00133
00134 void CAnimationSet::serial (NLMISC::IStream& f)
00135 {
00136
00137 f.serialCheck ((uint32)'_LEN');
00138 f.serialCheck ((uint32)'MINA');
00139 f.serialCheck ((uint32)'TES_');
00140
00141
00142 (void)f.serialVersion (0);
00143
00144
00145 f.serialContPtr (_Animation);
00146 f.serialContPtr (_SkeletonWeight);
00147 f.serialCont (_AnimationName);
00148 f.serialCont (_SkeletonWeightName);
00149 f.serialCont(_ChannelIdByName);
00150 f.serialCont(_AnimationIdByName);
00151 f.serialCont(_SkeletonWeightIdByName);
00152 }
00153
00154
00155 bool CAnimationSet::loadFromFiles(const std::string &path, bool recurse , const char *ext , bool wantWarningMessage )
00156 {
00157 bool everythingOk = true;
00158 std::vector<std::string> anims;
00159 NLMISC::CPath::getPathContent(path, recurse, false, true, anims);
00160 for (uint k = 0; k < anims.size(); ++k)
00161 {
00162 std::string fileExt = NLMISC::CFile::getExtension(anims[k]);
00163 if (fileExt == ext)
00164 {
00165 try
00166 {
00167 NLMISC::CIFile iFile;
00168 iFile.open(anims[k]);
00169 std::auto_ptr<CAnimation> anim(new CAnimation);
00170 anim->serial(iFile);
00171 addAnimation(NLMISC::CFile::getFilenameWithoutExtension(anims[k]).c_str(), anim.release());
00172 iFile.close();
00173
00174 }
00175 catch (NLMISC::EStream &e)
00176 {
00177 if (wantWarningMessage)
00178 {
00179 nlinfo("Unable to load an automatic animation : %s", e.what());
00180 }
00181 everythingOk = false;
00182 }
00183 }
00184 }
00185 build();
00186 return everythingOk;
00187 }
00188
00189
00190 }