00001
00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024
00025
00026 #include "std_afx.h"
00027 #include "object_viewer.h"
00028 #include "animation_set_dlg.h"
00029 #include <nel/misc/file.h>
00030
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #undef THIS_FILE
00034 static char THIS_FILE[] = __FILE__;
00035 #endif
00036
00037 using namespace NLMISC;
00038 using namespace NL3D;
00039
00041
00042
00043
00044 CAnimationSetDlg::CAnimationSetDlg(CObjectViewer* objView, CWnd* pParent )
00045 : CDialog(CAnimationSetDlg::IDD, pParent)
00046 {
00047
00048
00049
00050
00051 _ObjView=objView;
00052 }
00053
00054
00055 void CAnimationSetDlg::DoDataExchange(CDataExchange* pDX)
00056 {
00057 CDialog::DoDataExchange(pDX);
00058
00059 DDX_Control(pDX, IDC_TREE2, SkelTree);
00060 DDX_Control(pDX, IDC_TREE, Tree);
00061
00062 }
00063
00064
00065 BEGIN_MESSAGE_MAP(CAnimationSetDlg, CDialog)
00066
00067 ON_BN_CLICKED(IDC_ADD_ANIMATION, OnAddAnimation)
00068 ON_BN_CLICKED(IDC_RESET, OnReset)
00069 ON_BN_CLICKED(IDC_ADD_SKEL_WT, OnAddSkelWt)
00070 ON_WM_DESTROY()
00071
00072 END_MESSAGE_MAP()
00073
00075
00076
00077
00078
00079 void CAnimationSetDlg::OnAddAnimation ()
00080 {
00081
00082 static char BASED_CODE szFilter[] = "NeL Animation Files (*.anim)|*.anim|All Files (*.*)|*.*||";
00083 CFileDialog fileDlg( TRUE, ".anim", "*.anim", OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
00084 if (fileDlg.DoModal()==IDOK)
00085 {
00086
00087 try
00088 {
00089
00090 POSITION pos=fileDlg.GetStartPosition( );
00091 while (pos)
00092 {
00093
00094 CString filename=fileDlg.GetNextPathName(pos);
00095
00096
00097 loadAnimation (filename);
00098
00099
00100 _ObjView->reinitChannels ();
00101 }
00102 }
00103 catch (Exception& e)
00104 {
00105 MessageBox (e.what(), "NeL object viewer", MB_OK|MB_ICONEXCLAMATION);
00106 }
00107 }
00108 }
00109
00110
00111
00112 void CAnimationSetDlg::OnAddSkelWt()
00113 {
00114
00115 static char BASED_CODE szFilter[] = "NeL Skeleton Weight Template Files (*.swt)|*.swt|All Files (*.*)|*.*||";
00116 CFileDialog fileDlg( TRUE, ".swt", "*.swt", OFN_ALLOWMULTISELECT|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
00117 if (fileDlg.DoModal()==IDOK)
00118 {
00119
00120 try
00121 {
00122
00123 POSITION pos=fileDlg.GetStartPosition( );
00124 while (pos)
00125 {
00126
00127 CString filename=fileDlg.GetNextPathName(pos);
00128
00129
00130 loadSkeleton (filename);
00131
00132
00133 _ObjView->reinitChannels ();
00134 }
00135 }
00136 catch (Exception& e)
00137 {
00138 MessageBox (e.what(), "NeL object viewer", MB_OK|MB_ICONEXCLAMATION);
00139 }
00140 }
00141 }
00142
00143
00144
00145 void CAnimationSetDlg::OnReset ()
00146 {
00147
00148 _ObjView->resetSlots ();
00149
00150
00151 _ListAnimation.clear();
00152 _ListSkeleton.clear();
00153
00154
00155 Tree.DeleteAllItems ();
00156
00157
00158 SkelTree.DeleteAllItems ();
00159 }
00160
00161
00162
00163 void CAnimationSetDlg::loadAnimation (const char* fileName)
00164 {
00165
00166 CIFile file;
00167 if (file.open (fileName))
00168 {
00169
00170 char name[256];
00171 _splitpath (fileName, NULL, NULL, name, NULL);
00172
00173
00174 CAnimation *anim=new CAnimation;
00175
00176
00177 anim->serial (file);
00178
00179
00180 addAnimation (anim, name);
00181
00182
00183 _ListAnimation.push_back (fileName);
00184 }
00185 else
00186 {
00187
00188 char msg[512];
00189 _snprintf (msg, 512, "Can't open the file %s for reading.", fileName);
00190 MessageBox (msg, "NeL object viewer", MB_OK|MB_ICONEXCLAMATION);
00191 }
00192
00193 }
00194
00195
00196
00197 void CAnimationSetDlg::addAnimation (NL3D::CAnimation* anim, const char* name)
00198 {
00199
00200 _ObjView->_AnimationSet.addAnimation (name, anim);
00201
00202
00203 _ObjView->_AnimationSet.build ();
00204
00205
00206 HTREEITEM item=Tree.InsertItem (name);
00207 nlassert (item!=NULL);
00208
00209
00210 std::set<std::string> setString;
00211 anim->getTrackNames (setString);
00212 std::set<std::string>::iterator ite=setString.begin();
00213 while (ite!=setString.end())
00214 {
00215
00216 Tree.InsertItem (ite->c_str(), item);
00217
00218 ite++;
00219 }
00220 }
00221
00222
00223
00224 void CAnimationSetDlg::loadSkeleton (const char* fileName)
00225 {
00226
00227 CIFile file;
00228 if (file.open (fileName))
00229 {
00230
00231 char name[256];
00232 _splitpath (fileName, NULL, NULL, name, NULL);
00233
00234
00235 CAnimation *anim=new CAnimation;
00236
00237
00238 uint id=_ObjView->_AnimationSet.addSkeletonWeight (name);
00239
00240
00241 CSkeletonWeight* skel=_ObjView->_AnimationSet.getSkeletonWeight (id);
00242
00243
00244 skel->serial (file);
00245
00246
00247 _ListSkeleton.push_back (fileName);
00248
00249
00250 HTREEITEM item=SkelTree.InsertItem (name);
00251 nlassert (item!=NULL);
00252
00253
00254 uint numNode=skel->getNumNode ();
00255
00256
00257 for (uint n=0; n<numNode; n++)
00258 {
00259 char percent[512];
00260 sprintf (percent, "%s (%f%%)", skel->getNodeName (n).c_str(), skel->getNodeWeight(n));
00261
00262 SkelTree.InsertItem (percent, item);
00263 }
00264 }
00265 else
00266 {
00267
00268 char msg[512];
00269 _snprintf (msg, 512, "Can't open the file %s for reading.", fileName);
00270 MessageBox (msg, "NeL object viewer", MB_OK|MB_ICONEXCLAMATION);
00271 }
00272
00273 }
00274
00275 void CAnimationSetDlg::OnDestroy()
00276 {
00277 setRegisterWindowState (this, REGKEY_OBJ_VIEW_ANIMATION_SET_DLG);
00278
00279 CDialog::OnDestroy();
00280
00281
00282 }