From de02fb212962cae39966e92466d17145773166fa Mon Sep 17 00:00:00 2001 From: kimkulling Date: Wed, 30 Jan 2019 16:07:40 +0100 Subject: [PATCH] Fix review findings. --- tools/assimp_view/AnimEvaluator.cpp | 81 ++-- tools/assimp_view/AnimEvaluator.h | 32 +- tools/assimp_view/Background.cpp | 2 +- tools/assimp_view/Display.cpp | 2 +- tools/assimp_view/HelpDialog.cpp | 49 +- tools/assimp_view/Input.cpp | 2 +- tools/assimp_view/LogDisplay.cpp | 74 ++- tools/assimp_view/LogWindow.cpp | 61 +-- tools/assimp_view/Material.cpp | 3 +- tools/assimp_view/MeshRenderer.cpp | 8 +- tools/assimp_view/MessageProc.cpp | 685 ++++++++++------------------ tools/assimp_view/Normals.cpp | 60 +-- tools/assimp_view/SceneAnimator.cpp | 102 ++--- tools/assimp_view/SceneAnimator.h | 32 +- tools/assimp_view/Shaders.cpp | 2 +- 15 files changed, 464 insertions(+), 731 deletions(-) diff --git a/tools/assimp_view/AnimEvaluator.cpp b/tools/assimp_view/AnimEvaluator.cpp index 23e3c0e7d..9d9481a77 100644 --- a/tools/assimp_view/AnimEvaluator.cpp +++ b/tools/assimp_view/AnimEvaluator.cpp @@ -47,17 +47,21 @@ using namespace AssimpView; // ------------------------------------------------------------------------------------------------ // Constructor on a given animation. -AnimEvaluator::AnimEvaluator( const aiAnimation* pAnim) -{ - mAnim = pAnim; - mLastTime = 0.0; +AnimEvaluator::AnimEvaluator( const aiAnimation *pAnim ) +: mAnim(pAnim) +, mLastTime(0.0) { mLastPositions.resize( pAnim->mNumChannels, std::make_tuple( 0, 0, 0)); } +// ------------------------------------------------------------------------------------------------ +// Destructor. +AnimEvaluator::~AnimEvaluator() { + // empty +} + // ------------------------------------------------------------------------------------------------ // Evaluates the animation tracks for a given time stamp. -void AnimEvaluator::Evaluate( double pTime) -{ +void AnimEvaluator::Evaluate( double pTime ) { // extract ticks per second. Assume default value if not given double ticksPerSecond = mAnim->mTicksPerSecond != 0.0 ? mAnim->mTicksPerSecond : 25.0; // every following time calculation happens in ticks @@ -65,29 +69,29 @@ void AnimEvaluator::Evaluate( double pTime) // map into anim's duration double time = 0.0f; - if( mAnim->mDuration > 0.0) - time = fmod( pTime, mAnim->mDuration); + if (mAnim->mDuration > 0.0) { + time = fmod(pTime, mAnim->mDuration); + } - if( mTransforms.size() != mAnim->mNumChannels) - mTransforms.resize( mAnim->mNumChannels); + if (mTransforms.size() != mAnim->mNumChannels) { + mTransforms.resize(mAnim->mNumChannels); + } // calculate the transformations for each animation channel - for( unsigned int a = 0; a < mAnim->mNumChannels; a++) - { + for( unsigned int a = 0; a < mAnim->mNumChannels; ++a ) { const aiNodeAnim* channel = mAnim->mChannels[a]; // ******** Position ***** aiVector3D presentPosition( 0, 0, 0); - if( channel->mNumPositionKeys > 0) - { + if( channel->mNumPositionKeys > 0) { // Look for present frame number. Search from last position if time is after the last time, else from beginning // Should be much quicker than always looking from start for the average use case. unsigned int frame = (time >= mLastTime) ? std::get<0>(mLastPositions[a]) : 0; - while( frame < channel->mNumPositionKeys - 1) - { - if( time < channel->mPositionKeys[frame+1].mTime) + while( frame < channel->mNumPositionKeys - 1) { + if (time < channel->mPositionKeys[frame + 1].mTime) { break; - frame++; + } + ++frame; } // interpolate between this frame's value and next frame's value @@ -95,14 +99,13 @@ void AnimEvaluator::Evaluate( double pTime) const aiVectorKey& key = channel->mPositionKeys[frame]; const aiVectorKey& nextKey = channel->mPositionKeys[nextFrame]; double diffTime = nextKey.mTime - key.mTime; - if( diffTime < 0.0) + if (diffTime < 0.0) { diffTime += mAnim->mDuration; - if( diffTime > 0) - { + } + if( diffTime > 0) { float factor = float( (time - key.mTime) / diffTime); presentPosition = key.mValue + (nextKey.mValue - key.mValue) * factor; - } else - { + } else { presentPosition = key.mValue; } @@ -111,14 +114,13 @@ void AnimEvaluator::Evaluate( double pTime) // ******** Rotation ********* aiQuaternion presentRotation( 1, 0, 0, 0); - if( channel->mNumRotationKeys > 0) - { + if( channel->mNumRotationKeys > 0) { unsigned int frame = (time >= mLastTime) ? std::get<1>(mLastPositions[a]) : 0; - while( frame < channel->mNumRotationKeys - 1) - { - if( time < channel->mRotationKeys[frame+1].mTime) + while( frame < channel->mNumRotationKeys - 1) { + if (time < channel->mRotationKeys[frame + 1].mTime) { break; - frame++; + } + ++frame; } // interpolate between this frame's value and next frame's value @@ -126,14 +128,13 @@ void AnimEvaluator::Evaluate( double pTime) const aiQuatKey& key = channel->mRotationKeys[frame]; const aiQuatKey& nextKey = channel->mRotationKeys[nextFrame]; double diffTime = nextKey.mTime - key.mTime; - if( diffTime < 0.0) + if (diffTime < 0.0) { diffTime += mAnim->mDuration; - if( diffTime > 0) - { + } + if( diffTime > 0) { float factor = float( (time - key.mTime) / diffTime); aiQuaternion::Interpolate( presentRotation, key.mValue, nextKey.mValue, factor); - } else - { + } else { presentRotation = key.mValue; } @@ -142,14 +143,13 @@ void AnimEvaluator::Evaluate( double pTime) // ******** Scaling ********** aiVector3D presentScaling( 1, 1, 1); - if( channel->mNumScalingKeys > 0) - { + if( channel->mNumScalingKeys > 0) { unsigned int frame = (time >= mLastTime) ? std::get<2>(mLastPositions[a]) : 0; - while( frame < channel->mNumScalingKeys - 1) - { - if( time < channel->mScalingKeys[frame+1].mTime) + while( frame < channel->mNumScalingKeys - 1) { + if (time < channel->mScalingKeys[frame + 1].mTime) { break; - frame++; + } + ++frame; } // TODO: (thom) interpolation maybe? This time maybe even logarithmic, not linear @@ -164,7 +164,6 @@ void AnimEvaluator::Evaluate( double pTime) mat.a2 *= presentScaling.y; mat.b2 *= presentScaling.y; mat.c2 *= presentScaling.y; mat.a3 *= presentScaling.z; mat.b3 *= presentScaling.z; mat.c3 *= presentScaling.z; mat.a4 = presentPosition.x; mat.b4 = presentPosition.y; mat.c4 = presentPosition.z; - //mat.Transpose(); } mLastTime = time; diff --git a/tools/assimp_view/AnimEvaluator.h b/tools/assimp_view/AnimEvaluator.h index 417a02935..1b4d54186 100644 --- a/tools/assimp_view/AnimEvaluator.h +++ b/tools/assimp_view/AnimEvaluator.h @@ -4,7 +4,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2012, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -46,22 +46,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -namespace AssimpView -{ +namespace AssimpView { -/** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful, - * better use the AnimPlayer class. +/** + * @brief Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful, + * better use the AnimPlayer class. */ -class AnimEvaluator -{ +class AnimEvaluator { public: - /** Constructor on a given animation. The animation is fixed throughout the lifetime of - * the object. - * @param pAnim The animation to calculate poses for. Ownership of the animation object stays - * at the caller, the evaluator just keeps a reference to it as long as it persists. - */ + /// @brief Constructor on a given animation. The animation is fixed throughout the lifetime of + /// the object. + /// @param pAnim The animation to calculate poses for. Ownership of the animation object stays + /// at the caller, the evaluator just keeps a reference to it as long as it persists. AnimEvaluator( const aiAnimation* pAnim); + /// @brief The class destructor. + ~AnimEvaluator(); + /** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a * array of transformation matrices afterwards by calling GetTransformations(). * @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so @@ -74,16 +75,9 @@ public: const std::vector& GetTransformations() const { return mTransforms; } protected: - /** The animation we're working on */ const aiAnimation* mAnim; - - /** At which frame the last evaluation happened for each channel. - * Useful to quickly find the corresponding frame for slightly increased time stamps - */ double mLastTime; std::vector > mLastPositions; - - /** The array to store the transformations results of the evaluation */ std::vector mTransforms; }; diff --git a/tools/assimp_view/Background.cpp b/tools/assimp_view/Background.cpp index 14bf5b90d..b356a245b 100644 --- a/tools/assimp_view/Background.cpp +++ b/tools/assimp_view/Background.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. diff --git a/tools/assimp_view/Display.cpp b/tools/assimp_view/Display.cpp index 041ab34c5..196e8a2ac 100644 --- a/tools/assimp_view/Display.cpp +++ b/tools/assimp_view/Display.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. diff --git a/tools/assimp_view/HelpDialog.cpp b/tools/assimp_view/HelpDialog.cpp index 7b2ebf7b6..1a9f08f5f 100644 --- a/tools/assimp_view/HelpDialog.cpp +++ b/tools/assimp_view/HelpDialog.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -48,14 +48,10 @@ namespace AssimpView { //------------------------------------------------------------------------------- // Message procedure for the help dialog //------------------------------------------------------------------------------- -INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg, - WPARAM wParam,LPARAM lParam) - { - (void)lParam; - switch (uMsg) - { +INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM ) { + switch (uMsg) { case WM_INITDIALOG: - { + { // load the help file ... HRSRC res = FindResource(NULL,MAKEINTRESOURCE(IDR_TEXT1),"TEXT"); HGLOBAL hg = LoadResource(NULL,res); @@ -70,39 +66,38 @@ INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg, FreeResource(hg); return TRUE; - } + } case WM_CLOSE: EndDialog(hwndDlg,0); return TRUE; case WM_COMMAND: - - if (IDOK == LOWORD(wParam)) - { + if (IDOK == LOWORD(wParam)) { EndDialog(hwndDlg,0); return TRUE; - } + } case WM_PAINT: { - PAINTSTRUCT sPaint; - HDC hdc = BeginPaint(hwndDlg,&sPaint); + PAINTSTRUCT sPaint; + HDC hdc = BeginPaint(hwndDlg,&sPaint); - HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF)); + HBRUSH hBrush = CreateSolidBrush(RGB(0xFF,0xFF,0xFF)); - RECT sRect; - sRect.left = 0; - sRect.top = 26; - sRect.right = 1000; - sRect.bottom = 507; - FillRect(hdc, &sRect, hBrush); + RECT sRect; + sRect.left = 0; + sRect.top = 26; + sRect.right = 1000; + sRect.bottom = 507; + FillRect(hdc, &sRect, hBrush); - EndPaint(hwndDlg,&sPaint); - return TRUE; + EndPaint(hwndDlg,&sPaint); + return TRUE; } - }; - return FALSE; } -}; \ No newline at end of file + return FALSE; +} + +} diff --git a/tools/assimp_view/Input.cpp b/tools/assimp_view/Input.cpp index 7a9582fb2..56007bdf1 100644 --- a/tools/assimp_view/Input.cpp +++ b/tools/assimp_view/Input.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. diff --git a/tools/assimp_view/LogDisplay.cpp b/tools/assimp_view/LogDisplay.cpp index bf0c190b6..d24b9bf20 100644 --- a/tools/assimp_view/LogDisplay.cpp +++ b/tools/assimp_view/LogDisplay.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -46,32 +46,26 @@ namespace AssimpView { CLogDisplay CLogDisplay::s_cInstance; //------------------------------------------------------------------------------- -void CLogDisplay::AddEntry(const std::string& szText, - const D3DCOLOR clrColor) - { +void CLogDisplay::AddEntry(const std::string& szText, const D3DCOLOR clrColor) { SEntry sNew; sNew.clrColor = clrColor; sNew.szText = szText; sNew.dwStartTicks = (DWORD)GetTickCount(); this->asEntries.push_back(sNew); - } +} //------------------------------------------------------------------------------- -void CLogDisplay::ReleaseNativeResource() - { - if (this->piFont) - { +void CLogDisplay::ReleaseNativeResource() { + if (this->piFont) { this->piFont->Release(); - this->piFont = NULL; - } + this->piFont = nullptr; } +} //------------------------------------------------------------------------------- -void CLogDisplay::RecreateNativeResource() - { - if (!this->piFont) - { +void CLogDisplay::RecreateNativeResource() { + if (!this->piFont) { if (FAILED(D3DXCreateFont(g_piDevice, 16, //Font height 0, //Font width @@ -84,20 +78,17 @@ void CLogDisplay::RecreateNativeResource() 5, //Quality DEFAULT_PITCH|FF_DONTCARE, //PitchAndFamily "Verdana", //pFacename, - &this->piFont))) - { + &this->piFont))) { CLogDisplay::Instance().AddEntry("Unable to load font",D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - this->piFont = NULL; + this->piFont = nullptr; return; - } } - return; } +} //------------------------------------------------------------------------------- -void CLogDisplay::OnRender() - { +void CLogDisplay::OnRender() { DWORD dwTick = (DWORD) GetTickCount(); DWORD dwLimit = dwTick - 8000; DWORD dwLimit2 = dwLimit + 3000; @@ -117,9 +108,8 @@ void CLogDisplay::OnRender() sRect.bottom = sWndRect.bottom; // if no asset is loaded draw a "no asset loaded" text in the center - if (!g_pcAsset) - { - const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset"; + if (!g_pcAsset) { + const char* szText = "Nothing to display ... \r\nTry [Viewer | Open asset] to load an asset"; // shadow RECT sCopy; @@ -151,38 +141,34 @@ void CLogDisplay::OnRender() // text this->piFont->DrawText(NULL,szText , -1,&sWndRect,DT_CENTER | DT_VCENTER,D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF)); - } + } // update all elements in the queue and render them for (std::list::iterator - i = this->asEntries.begin(); - i != this->asEntries.end();++i,++iCnt) - { - if ((*i).dwStartTicks < dwLimit) - { + i = this->asEntries.begin(); + i != this->asEntries.end();++i,++iCnt) { + if ((*i).dwStartTicks < dwLimit) { i = this->asEntries.erase(i); - if(i == this->asEntries.end())break; + if (i == this->asEntries.end()) { + break; } - else if (NULL != this->piFont) - { + } else if (nullptr != this->piFont) { float fAlpha = 1.0f; - if ((*i).dwStartTicks <= dwLimit2) - { + if ((*i).dwStartTicks <= dwLimit2) { // linearly interpolate to create the fade out effect fAlpha = 1.0f - (float)(dwLimit2 - (*i).dwStartTicks) / 3000.0f; - } + } D3DCOLOR& clrColor = (*i).clrColor; clrColor &= ~(0xFFu << 24); clrColor |= (((unsigned char)(fAlpha * 255.0f)) & 0xFFu) << 24; const char* szText = (*i).szText.c_str(); - if (sRect.top + 30 > sWndRect.bottom) - { + if (sRect.top + 30 > sWndRect.bottom) { // end of window. send a special message szText = "... too many errors"; clrColor = D3DCOLOR_ARGB(0xFF,0xFF,100,0x0); - } + } // draw the black shadow RECT sCopy; @@ -225,9 +211,11 @@ void CLogDisplay::OnRender() sRect.top += iPX; sRect.bottom += iPX; - if (szText != (*i).szText.c_str())break; + if (szText != (*i).szText.c_str()) { + break; } } - return; } -}; \ No newline at end of file +} + +} diff --git a/tools/assimp_view/LogWindow.cpp b/tools/assimp_view/LogWindow.cpp index dba70ee71..ca9b88f95 100644 --- a/tools/assimp_view/LogWindow.cpp +++ b/tools/assimp_view/LogWindow.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -101,13 +101,11 @@ INT_PTR CALLBACK LogDialogProc(HWND hwndDlg,UINT uMsg, } //------------------------------------------------------------------------------- -void CLogWindow::Init () -{ +void CLogWindow::Init () { this->hwnd = ::CreateDialog(g_hInstance,MAKEINTRESOURCE(IDD_LOGVIEW), NULL,&LogDialogProc); - if (!this->hwnd) - { + if (!this->hwnd) { CLogDisplay::Instance().AddEntry("[ERROR] Unable to create logger window", D3DCOLOR_ARGB(0xFF,0,0xFF,0)); } @@ -116,11 +114,10 @@ void CLogWindow::Init () this->szText = AI_VIEW_RTF_LOG_HEADER;; this->szPlainText = ""; } + //------------------------------------------------------------------------------- -void CLogWindow::Show() -{ - if (this->hwnd) - { +void CLogWindow::Show() { + if (this->hwnd) { ShowWindow(this->hwnd,SW_SHOW); this->bIsVisible = true; @@ -128,24 +125,23 @@ void CLogWindow::Show() this->Update(); } } + //------------------------------------------------------------------------------- -void CMyLogStream::write(const char* message) -{ +void CMyLogStream::write(const char* message) { CLogWindow::Instance().WriteLine(message); } + //------------------------------------------------------------------------------- -void CLogWindow::Clear() -{ +void CLogWindow::Clear() { this->szText = AI_VIEW_RTF_LOG_HEADER;; this->szPlainText = ""; this->Update(); } + //------------------------------------------------------------------------------- -void CLogWindow::Update() -{ - if (this->bIsVisible) - { +void CLogWindow::Update() { + if (this->bIsVisible) { SETTEXTEX sInfo; sInfo.flags = ST_DEFAULT; sInfo.codepage = CP_ACP; @@ -154,20 +150,16 @@ void CLogWindow::Update() EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str()); } } + //------------------------------------------------------------------------------- -void CLogWindow::Save() -{ +void CLogWindow::Save() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL, - (BYTE*)szFileName,&dwTemp)) - { + if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LogDestination",NULL,NULL,(BYTE*)szFileName,&dwTemp)) { // Key was not found. Use C: strcpy(szFileName,""); - } - else - { + } else { // need to remove the file name char* sz = strrchr(szFileName,'\\'); if (!sz) @@ -196,14 +188,13 @@ void CLogWindow::Save() CLogDisplay::Instance().AddEntry("[INFO] The log file has been saved", D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0)); } + //------------------------------------------------------------------------------- -void CLogWindow::WriteLine(const char* message) -{ +void CLogWindow::WriteLine(const char* message) { this->szPlainText.append(message); this->szPlainText.append("\r\n"); - if (0 != this->szText.length()) - { + if (0 != this->szText.length()) { this->szText.resize(this->szText.length()-1); } @@ -231,12 +222,10 @@ void CLogWindow::WriteLine(const char* message) } std::string _message = message; - for (unsigned int i = 0; i < _message.length();++i) - { + for (unsigned int i = 0; i < _message.length();++i) { if ('\\' == _message[i] || '}' == _message[i] || - '{' == _message[i]) - { + '{' == _message[i]) { _message.insert(i++,"\\"); } } @@ -244,8 +233,7 @@ void CLogWindow::WriteLine(const char* message) this->szText.append(_message); this->szText.append("\\par}}"); - if (this->bIsVisible && this->bUpdate) - { + if (this->bIsVisible && this->bUpdate) { SETTEXTEX sInfo; sInfo.flags = ST_DEFAULT; sInfo.codepage = CP_ACP; @@ -253,7 +241,6 @@ void CLogWindow::WriteLine(const char* message) SendDlgItemMessage(this->hwnd,IDC_EDIT1, EM_SETTEXTEX,(WPARAM)&sInfo,( LPARAM)this->szText.c_str()); } - return; } -}; //! AssimpView \ No newline at end of file +} //! AssimpView diff --git a/tools/assimp_view/Material.cpp b/tools/assimp_view/Material.cpp index 1fb13f5a8..2c5316d81 100644 --- a/tools/assimp_view/Material.cpp +++ b/tools/assimp_view/Material.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -136,7 +136,6 @@ extern float g_smoothAngle /*= 80.f*/; extern unsigned int ppsteps, ppstepsdefault; extern bool nopointslines; - CMaterialManager CMaterialManager::s_cInstance; //------------------------------------------------------------------------------- diff --git a/tools/assimp_view/MeshRenderer.cpp b/tools/assimp_view/MeshRenderer.cpp index 834c5a9e2..dfa249735 100644 --- a/tools/assimp_view/MeshRenderer.cpp +++ b/tools/assimp_view/MeshRenderer.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -49,8 +49,7 @@ namespace AssimpView { CMeshRenderer CMeshRenderer::s_cInstance; //------------------------------------------------------------------------------- -int CMeshRenderer::DrawUnsorted(unsigned int iIndex) -{ +int CMeshRenderer::DrawUnsorted(unsigned int iIndex) { ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes); // set vertex and index buffer @@ -77,8 +76,7 @@ int CMeshRenderer::DrawUnsorted(unsigned int iIndex) return 1; } //------------------------------------------------------------------------------- -int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld) -{ +int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld) { ai_assert(iIndex < g_pcAsset->pcScene->mNumMeshes); AssetHelper::MeshHelper* pcHelper = g_pcAsset->apcMeshes[iIndex]; diff --git a/tools/assimp_view/MessageProc.cpp b/tools/assimp_view/MessageProc.cpp index 5a9cfd0ed..f9bcf2e9d 100644 --- a/tools/assimp_view/MessageProc.cpp +++ b/tools/assimp_view/MessageProc.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -47,9 +47,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #ifdef __MINGW32__ -#include +# include #else -#include +# include #endif namespace AssimpView { @@ -92,31 +92,29 @@ void MakeFileAssociations() { GetModuleFileName(NULL,szTemp2,MAX_PATH); sprintf(szTemp,"%s %%1",szTemp2); - HKEY g_hRegistry; + HKEY hRegistry = NULL; aiString list, tmp; aiGetExtensionList(&list); tmp = list; const char* sz = strtok(list.data,";"); - do - { + do { char buf[256]; ai_assert(sz[0] == '*'); sprintf(buf,"Software\\Classes\\%s",sz+1); - RegCreateKeyEx(HKEY_CURRENT_USER,buf,0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL); - RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1); - RegCloseKey(g_hRegistry); - } - while ((sz = strtok(NULL,";"))); + RegCreateKeyEx(HKEY_CURRENT_USER,buf,0,NULL,0,KEY_ALL_ACCESS, NULL, &hRegistry,NULL); + RegSetValueEx(hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1); + RegCloseKey(hRegistry); + } while ((sz = strtok(NULL,";"))); - RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL); - RegCloseKey(g_hRegistry); + RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS",0,NULL,0,KEY_ALL_ACCESS, NULL, &hRegistry,NULL); + RegCloseKey(hRegistry); - RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS\\shell\\open\\command",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL); - RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)szTemp,(DWORD)strlen(szTemp)+1); - RegCloseKey(g_hRegistry); + RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS\\shell\\open\\command",0,NULL,0,KEY_ALL_ACCESS, NULL, &hRegistry,NULL); + RegSetValueEx(hRegistry,"",0,REG_SZ,(const BYTE*)szTemp,(DWORD)strlen(szTemp)+1); + RegCloseKey(hRegistry); CLogDisplay::Instance().AddEntry("[OK] File assocations have been registered", D3DCOLOR_ARGB(0xFF,0,0xFF,0)); @@ -124,19 +122,19 @@ void MakeFileAssociations() { CLogDisplay::Instance().AddEntry(tmp.data,D3DCOLOR_ARGB(0xFF,0,0xFF,0)); } - //------------------------------------------------------------------------------- // Handle command line parameters // // The function loads an asset specified on the command line as first argument // Other command line parameters are not handled //------------------------------------------------------------------------------- -void HandleCommandLine(char* p_szCommand) -{ +void HandleCommandLine(char* p_szCommand) { char* sz = p_szCommand; //bool bQuak = false; - if (strlen(sz) < 2)return; + if (strlen(sz) < 2) { + return; + } if (*sz == '\"') { char* sz2 = strrchr(sz,'\"'); @@ -157,8 +155,7 @@ void HandleCommandLine(char* p_szCommand) //------------------------------------------------------------------------------- // Load the light colors from the registry //------------------------------------------------------------------------------- -void LoadLightColors() -{ +void LoadLightColors() { DWORD dwTemp = 4; RegQueryValueEx(g_hRegistry,"LightColor0",NULL,NULL, (BYTE*)&g_avLightColors[0],&dwTemp); RegQueryValueEx(g_hRegistry,"LightColor1",NULL,NULL, (BYTE*)&g_avLightColors[1],&dwTemp); @@ -168,8 +165,7 @@ void LoadLightColors() //------------------------------------------------------------------------------- // Save the light colors to the registry //------------------------------------------------------------------------------- -void SaveLightColors() -{ +void SaveLightColors() { RegSetValueExA(g_hRegistry,"LightColor0",0,REG_DWORD,(const BYTE*)&g_avLightColors[0],4); RegSetValueExA(g_hRegistry,"LightColor1",0,REG_DWORD,(const BYTE*)&g_avLightColors[1],4); RegSetValueExA(g_hRegistry,"LightColor2",0,REG_DWORD,(const BYTE*)&g_avLightColors[2],4); @@ -178,8 +174,7 @@ void SaveLightColors() //------------------------------------------------------------------------------- // Save the checker pattern colors to the registry //------------------------------------------------------------------------------- -void SaveCheckerPatternColors() -{ +void SaveCheckerPatternColors() { // we have it as float4. save it as binary value --. RegSetValueExA(g_hRegistry,"CheckerPattern0",0,REG_BINARY, (const BYTE*)CDisplay::Instance().GetFirstCheckerColor(), @@ -193,8 +188,7 @@ void SaveCheckerPatternColors() //------------------------------------------------------------------------------- // Load the checker pattern colors from the registry //------------------------------------------------------------------------------- -void LoadCheckerPatternColors() -{ +void LoadCheckerPatternColors() { DWORD dwTemp = sizeof(D3DXVECTOR3); RegQueryValueEx(g_hRegistry,"CheckerPattern0",NULL,NULL, (BYTE*) /* jep, this is evil */ CDisplay::Instance().GetFirstCheckerColor(),&dwTemp); @@ -206,8 +200,7 @@ void LoadCheckerPatternColors() //------------------------------------------------------------------------------- // Changed pp setup //------------------------------------------------------------------------------- -void UpdatePPSettings() -{ +void UpdatePPSettings() { DWORD dwValue = ppsteps; RegSetValueExA(g_hRegistry,"PostProcessing",0,REG_DWORD,(const BYTE*)&dwValue,4); UpdateWindow(g_hDlg); @@ -216,8 +209,7 @@ void UpdatePPSettings() //------------------------------------------------------------------------------- // Toggle the "Display Normals" state //------------------------------------------------------------------------------- -void ToggleNormals() -{ +void ToggleNormals() { g_sOptions.bRenderNormals = !g_sOptions.bRenderNormals; // store this in the registry, too @@ -226,97 +218,72 @@ void ToggleNormals() RegSetValueExA(g_hRegistry,"RenderNormals",0,REG_DWORD,(const BYTE*)&dwValue,4); } +static void storeRegKey(bool option, LPCSTR name) { + // store this in the registry, too + DWORD dwValue = 0; + if (option) { + dwValue = 1; + } + RegSetValueExA(g_hRegistry, name, 0, REG_DWORD, (const BYTE*)&dwValue, 4); + +} //------------------------------------------------------------------------------- // Toggle the "AutoRotate" state //------------------------------------------------------------------------------- -void ToggleAutoRotate() -{ +void ToggleAutoRotate() { g_sOptions.bRotate = !g_sOptions.bRotate; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bRotate)dwValue = 1; - RegSetValueExA(g_hRegistry,"AutoRotate",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bRotate, "AutoRotate"); UpdateWindow(g_hDlg); } //------------------------------------------------------------------------------- // Toggle the "FPS" state //------------------------------------------------------------------------------- -void ToggleFPSView() -{ +void ToggleFPSView() { g_bFPSView = !g_bFPSView; SetupFPSView(); - - // store this in the registry, too - DWORD dwValue = 0; - if (g_bFPSView)dwValue = 1; - RegSetValueExA(g_hRegistry,"FPSView",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_bFPSView, "FPSView"); } //------------------------------------------------------------------------------- // Toggle the "2 Light sources" state //------------------------------------------------------------------------------- -void ToggleMultipleLights() -{ +void ToggleMultipleLights() { g_sOptions.b3Lights = !g_sOptions.b3Lights; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.b3Lights)dwValue = 1; - RegSetValueExA(g_hRegistry,"MultipleLights",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.b3Lights, "MultipleLights"); } //------------------------------------------------------------------------------- // Toggle the "LightRotate" state //------------------------------------------------------------------------------- -void ToggleLightRotate() -{ +void ToggleLightRotate() { g_sOptions.bLightRotate = !g_sOptions.bLightRotate; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bLightRotate)dwValue = 1; - RegSetValueExA(g_hRegistry,"LightRotate",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bLightRotate, "LightRotate"); } //------------------------------------------------------------------------------- // Toggle the "NoTransparency" state //------------------------------------------------------------------------------- -void ToggleTransparency() -{ +void ToggleTransparency() { g_sOptions.bNoAlphaBlending = !g_sOptions.bNoAlphaBlending; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bNoAlphaBlending)dwValue = 1; - RegSetValueExA(g_hRegistry,"NoTransparency",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bNoAlphaBlending, "NoTransparency"); } //------------------------------------------------------------------------------- // Toggle the "LowQuality" state //------------------------------------------------------------------------------- -void ToggleLowQuality() -{ +void ToggleLowQuality() { g_sOptions.bLowQuality = !g_sOptions.bLowQuality; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bLowQuality)dwValue = 1; - RegSetValueExA(g_hRegistry,"LowQuality",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bLowQuality, "LowQuality"); } //------------------------------------------------------------------------------- // Toggle the "Specular" state //------------------------------------------------------------------------------- -void ToggleSpecular() -{ +void ToggleSpecular() { g_sOptions.bNoSpecular = !g_sOptions.bNoSpecular; - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bNoSpecular)dwValue = 1; - RegSetValueExA(g_hRegistry,"NoSpecular",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bNoSpecular, "NoSpecular"); // update all specular materials CMaterialManager::Instance().UpdateSpecularMaterials(); @@ -325,14 +292,10 @@ void ToggleSpecular() //------------------------------------------------------------------------------- // Toggle the "RenderMats" state //------------------------------------------------------------------------------- -void ToggleMats() -{ +void ToggleMats() { g_sOptions.bRenderMats = !g_sOptions.bRenderMats; - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bRenderMats)dwValue = 1; - RegSetValueExA(g_hRegistry,"RenderMats",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bRenderMats, "RenderMats"); // update all specular materials CMaterialManager::Instance().UpdateSpecularMaterials(); @@ -341,45 +304,32 @@ void ToggleMats() //------------------------------------------------------------------------------- // Toggle the "Culling" state //------------------------------------------------------------------------------- -void ToggleCulling() -{ +void ToggleCulling() { g_sOptions.bCulling = !g_sOptions.bCulling; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bCulling)dwValue = 1; - RegSetValueExA(g_hRegistry,"Culling",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bCulling, "Culling"); } //------------------------------------------------------------------------------- // Toggle the "Skeleton" state //------------------------------------------------------------------------------- -void ToggleSkeleton() -{ +void ToggleSkeleton() { g_sOptions.bSkeleton = !g_sOptions.bSkeleton; - - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bCulling)dwValue = 1; - RegSetValueExA(g_hRegistry,"Skeleton",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bSkeleton, "Skeleton"); } //------------------------------------------------------------------------------- // Toggle the "WireFrame" state //------------------------------------------------------------------------------- -void ToggleWireFrame() -{ - if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME) +void ToggleWireFrame() { + if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME) { g_sOptions.eDrawMode = RenderOptions::NORMAL; - else g_sOptions.eDrawMode = RenderOptions::WIREFRAME; + } else { + g_sOptions.eDrawMode = RenderOptions::WIREFRAME; + } - // store this in the registry, too - DWORD dwValue = 0; - if (RenderOptions::WIREFRAME == g_sOptions.eDrawMode)dwValue = 1; - RegSetValueExA(g_hRegistry,"Wireframe",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(RenderOptions::WIREFRAME == g_sOptions.eDrawMode, "Wireframe"); } - //------------------------------------------------------------------------------- // Toggle the "MultiSample" state //------------------------------------------------------------------------------- @@ -388,8 +338,7 @@ void ToggleMS() g_sOptions.bMultiSample = !g_sOptions.bMultiSample; DeleteAssetData(); ShutdownDevice(); - if (0 == CreateDevice()) - { + if (0 == CreateDevice()) { CLogDisplay::Instance().AddEntry( "[ERROR] Failed to toggle MultiSampling mode"); g_sOptions.bMultiSample = !g_sOptions.bMultiSample; @@ -397,28 +346,21 @@ void ToggleMS() } CreateAssetData(); - if (g_sOptions.bMultiSample) - { + if (g_sOptions.bMultiSample) { CLogDisplay::Instance().AddEntry( "[OK] Changed MultiSampling mode to the maximum value for this device"); - } - else - { + } else { CLogDisplay::Instance().AddEntry( "[OK] MultiSampling has been disabled"); } - // store this in the registry, too - DWORD dwValue = 0; - if (g_sOptions.bMultiSample)dwValue = 1; - RegSetValueExA(g_hRegistry,"MultiSampling",0,REG_DWORD,(const BYTE*)&dwValue,4); + storeRegKey(g_sOptions.bMultiSample, "MultiSampling"); } //------------------------------------------------------------------------------- // Expand or collapse the UI //------------------------------------------------------------------------------- -void ToggleUIState() -{ +void ToggleUIState() { // adjust the size RECT sRect; GetWindowRect(g_hDlg,&sRect); @@ -430,46 +372,33 @@ void ToggleUIState() sRect2.left -= sRect.left; sRect2.top -= sRect.top; - DWORD dwValue; - if (BST_UNCHECKED == IsDlgButtonChecked(g_hDlg,IDC_BLUBB)) - { + if (BST_UNCHECKED == IsDlgButtonChecked(g_hDlg,IDC_BLUBB)) { SetWindowPos(g_hDlg,NULL,0,0,sRect.right-214,sRect.bottom, SWP_NOMOVE | SWP_NOZORDER); - dwValue = 0; SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>"); - RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4); - } - else - { + storeRegKey(false, "MultiSampling"); + } else { SetWindowPos(g_hDlg,NULL,0,0,sRect.right+214,sRect.bottom, SWP_NOMOVE | SWP_NOZORDER); - dwValue = 1; + storeRegKey(true, "LastUIState"); SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),"<<"); - RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4); } UpdateWindow(g_hDlg); - return; } - //------------------------------------------------------------------------------- // Load the background texture for the cviewer //------------------------------------------------------------------------------- -void LoadBGTexture() -{ +void LoadBGTexture() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"TextureSrc",NULL,NULL, - (BYTE*)szFileName,&dwTemp)) - { + if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"TextureSrc",NULL,NULL, (BYTE*)szFileName,&dwTemp)) { // Key was not found. Use C: strcpy(szFileName,""); - } - else - { + } else { // need to remove the file name char* sz = strrchr(szFileName,'\\'); if (!sz) @@ -495,14 +424,12 @@ void LoadBGTexture() RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH); CBackgroundPainter::Instance().SetTextureBG(szFileName); - return; } //------------------------------------------------------------------------------- // Reset the background color to a smart and nice grey //------------------------------------------------------------------------------- -void ClearBG() -{ +void ClearBG() { D3DCOLOR clrColor = D3DCOLOR_ARGB(0xFF,100,100,100); CBackgroundPainter::Instance().SetColor(clrColor); @@ -510,14 +437,12 @@ void ClearBG() RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH); RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4); - return; } //------------------------------------------------------------------------------- // Let the user choose a color in a windows standard color dialog //------------------------------------------------------------------------------- -void DisplayColorDialog(D3DCOLOR* pclrResult) -{ +void DisplayColorDialog(D3DCOLOR* pclrResult) { CHOOSECOLOR clr; clr.lStructSize = sizeof(CHOOSECOLOR); clr.hwndOwner = g_hDlg; @@ -534,15 +459,12 @@ void DisplayColorDialog(D3DCOLOR* pclrResult) GetRValue(clr.rgbResult), GetGValue(clr.rgbResult), GetBValue(clr.rgbResult)); - return; } - //------------------------------------------------------------------------------- // Let the user choose a color in a windows standard color dialog //------------------------------------------------------------------------------- -void DisplayColorDialog(D3DXVECTOR4* pclrResult) -{ +void DisplayColorDialog(D3DXVECTOR4* pclrResult) { CHOOSECOLOR clr; clr.lStructSize = sizeof(CHOOSECOLOR); clr.hwndOwner = g_hDlg; @@ -560,14 +482,12 @@ void DisplayColorDialog(D3DXVECTOR4* pclrResult) pclrResult->x = GetRValue(clr.rgbResult) / 255.0f; pclrResult->y = GetGValue(clr.rgbResult) / 255.0f; pclrResult->z = GetBValue(clr.rgbResult) / 255.0f; - return; } //------------------------------------------------------------------------------- -// Let the user choose the baclground color for the viewer +// Let the user choose the background color for the viewer //------------------------------------------------------------------------------- -void ChooseBGColor() -{ +void ChooseBGColor() { RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH); RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH); @@ -576,14 +496,12 @@ void ChooseBGColor() CBackgroundPainter::Instance().SetColor(clrColor); RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4); - return; } //------------------------------------------------------------------------------- // Display the OpenFile dialog and let the user choose a new slybox as bg //------------------------------------------------------------------------------- -void LoadSkybox() -{ +void LoadSkybox() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; @@ -622,23 +540,26 @@ void LoadSkybox() return; } +template +inline +void SaveRelease(T **iface ) { + if (nullptr != iface) { + (*iface)->Release(); + *iface = nullptr; + } +} //------------------------------------------------------------------------------- -// Sace a screenshot to an user-defined file +// Save a screenshot to an user-defined file //------------------------------------------------------------------------------- -void SaveScreenshot() -{ +void SaveScreenshot() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"ScreenShot",NULL,NULL, - (BYTE*)szFileName,&dwTemp)) - { + if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"ScreenShot",NULL,NULL, (BYTE*)szFileName,&dwTemp)) { // Key was not found. Use C: strcpy(szFileName,""); - } - else - { + } else { // need to remove the file name char* sz = strrchr(szFileName,'\\'); if (!sz) @@ -662,49 +583,42 @@ void SaveScreenshot() IDirect3DSurface9* pi = NULL; g_piDevice->GetRenderTarget(0,&pi); - if(!pi || FAILED(D3DXSaveSurfaceToFile(szFileName,D3DXIFF_PNG,pi,NULL,NULL))) - { + if(!pi || FAILED(D3DXSaveSurfaceToFile(szFileName,D3DXIFF_PNG,pi,NULL,NULL))) { CLogDisplay::Instance().AddEntry("[ERROR] Unable to save screenshot", D3DCOLOR_ARGB(0xFF,0xFF,0,0)); - } - else - { + } else { CLogDisplay::Instance().AddEntry("[INFO] The screenshot has been saved", D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0)); } - if(pi)pi->Release(); - return; + SaveRelease(&pi); } //------------------------------------------------------------------------------- // Get the amount of memory required for textures //------------------------------------------------------------------------------- -void AddTextureMem(IDirect3DTexture9* pcTex, unsigned int& out) -{ - if (!pcTex)return; +void AddTextureMem(IDirect3DTexture9* pcTex, unsigned int& out) { + if (!pcTex) { + return; + } D3DSURFACE_DESC sDesc; pcTex->GetLevelDesc(0,&sDesc); out += (sDesc.Width * sDesc.Height) << 2; - return; } //------------------------------------------------------------------------------- // Display memory statistics //------------------------------------------------------------------------------- -void DisplayMemoryConsumption() -{ +void DisplayMemoryConsumption() { // first get the memory consumption for the aiScene - if (! g_pcAsset ||!g_pcAsset->pcScene) - { + if (! g_pcAsset ||!g_pcAsset->pcScene) { MessageBox(g_hDlg,"No asset is loaded. Can you guess how much memory I need to store nothing?", "Memory consumption",MB_OK); return; } unsigned int iScene = sizeof(aiScene); - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) { iScene += sizeof(aiMesh); if (g_pcAsset->pcScene->mMeshes[i]->HasPositions()) iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices; @@ -715,22 +629,20 @@ void DisplayMemoryConsumption() if (g_pcAsset->pcScene->mMeshes[i]->HasTangentsAndBitangents()) iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices * 2; - for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) - { - if (g_pcAsset->pcScene->mMeshes[i]->HasVertexColors(a)) + for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) { + if (g_pcAsset->pcScene->mMeshes[i]->HasVertexColors(a)) { iScene += sizeof(aiColor4D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices; - else break; + } else { + break; + } } - for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) - { + for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) { if (g_pcAsset->pcScene->mMeshes[i]->HasTextureCoords(a)) iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices; else break; } - if (g_pcAsset->pcScene->mMeshes[i]->HasBones()) - { - for (unsigned int p = 0; p < g_pcAsset->pcScene->mMeshes[i]->mNumBones;++p) - { + if (g_pcAsset->pcScene->mMeshes[i]->HasBones()) { + for (unsigned int p = 0; p < g_pcAsset->pcScene->mMeshes[i]->mNumBones;++p) { iScene += sizeof(aiBone); iScene += g_pcAsset->pcScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight); } @@ -738,22 +650,20 @@ void DisplayMemoryConsumption() iScene += (sizeof(aiFace) + 3 * sizeof(unsigned int))*g_pcAsset->pcScene->mMeshes[i]->mNumFaces; } // add all embedded textures - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumTextures;++i) - { + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumTextures;++i) { const aiTexture* pc = g_pcAsset->pcScene->mTextures[i]; - if (0 != pc->mHeight) - { + if (0 != pc->mHeight) { iScene += 4 * pc->mHeight * pc->mWidth; + } else { + iScene += pc->mWidth; } - else iScene += pc->mWidth; } // add 30k for each material ... a string has 4k for example iScene += g_pcAsset->pcScene->mNumMaterials * 30 * 1024; // now get the memory consumption required by D3D, first all textures unsigned int iTexture = 0; - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) { AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i]; AddTextureMem(pc->piDiffuseTexture,iTexture); @@ -767,15 +677,13 @@ void DisplayMemoryConsumption() unsigned int iVRAM = iTexture; // now get the memory consumption of all vertex/index buffers - unsigned int iVB = 0; - unsigned int iIB = 0; - for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) - { + unsigned int iVB( 0 ), iIB(0); + for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i) { AssetHelper:: MeshHelper* pc = g_pcAsset->apcMeshes[i]; union{ - D3DVERTEXBUFFER_DESC sDesc; - D3DINDEXBUFFER_DESC sDesc2; + D3DVERTEXBUFFER_DESC sDesc; + D3DINDEXBUFFER_DESC sDesc2; }; if (pc->piVB) @@ -814,36 +722,30 @@ void DisplayMemoryConsumption() iScene / 1024,iTexture / 1024,iVB / 1024,iIB / 1024,iVRAM / 1024, (iScene + iTexture + iVB + iIB + iVRAM) / 1024); MessageBox(g_hDlg,szOut,"Memory consumption",MB_OK); - return; } //------------------------------------------------------------------------------- // Save the list of recent files to the registry //------------------------------------------------------------------------------- -void SaveHistory() -{ - for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i) - { +void SaveHistory() { + for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i) { char szName[66]; sprintf(szName,"Recent%i",i+1); RegSetValueEx(g_hRegistry,szName,0,REG_SZ, (const BYTE*)g_aPreviousFiles[i].c_str(),(DWORD)g_aPreviousFiles[i].length()); } - return; } //------------------------------------------------------------------------------- // Recover the file history //------------------------------------------------------------------------------- -void LoadHistory() -{ +void LoadHistory() { g_aPreviousFiles.resize(AI_VIEW_NUM_RECENT_FILES); char szFileName[MAX_PATH]; - for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i) - { + for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i) { char szName[66]; sprintf(szName,"Recent%i",i+1); @@ -851,20 +753,17 @@ void LoadHistory() szFileName[0] ='\0'; if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,szName,NULL,NULL, - (BYTE*)szFileName,&dwTemp)) - { + (BYTE*)szFileName,&dwTemp)) { g_aPreviousFiles[i] = std::string(szFileName); } } // add sub items for all recent files g_hHistoryMenu = CreateMenu(); - for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) - { + for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) { const char* szText = g_aPreviousFiles[i].c_str(); UINT iFlags = 0; - if ('\0' == *szText) - { + if ('\0' == *szText) { szText = ""; iFlags = MF_GRAYED | MF_DISABLED; } @@ -873,19 +772,17 @@ void LoadHistory() ModifyMenu(GetMenu(g_hDlg),ID_VIEWER_RECENTFILES,MF_BYCOMMAND | MF_POPUP, (UINT_PTR)g_hHistoryMenu,"Recent files"); - return; } //------------------------------------------------------------------------------- // Clear the file history //------------------------------------------------------------------------------- -void ClearHistory() -{ - for(unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i) +void ClearHistory() { + for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES; ++i) { g_aPreviousFiles[i] = std::string(""); + } - for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) - { + for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) { ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i), MF_STRING | MF_BYCOMMAND | MF_GRAYED | MF_DISABLED,AI_VIEW_RECENT_FILE_ID(i),""); } @@ -896,50 +793,44 @@ void ClearHistory() //------------------------------------------------------------------------------- // Update the file history //------------------------------------------------------------------------------- -void UpdateHistory() -{ - if(!g_hHistoryMenu)return; +void UpdateHistory() { + if (!g_hHistoryMenu) { + return; + } std::string sz = std::string(g_szFileName); - if (g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] == sz)return; + if (g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES - 1] == sz) { + return; + } // add the new asset to the list of recent files - for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES-1;++i) - { + for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES-1;++i) { g_aPreviousFiles[i] = g_aPreviousFiles[i+1]; } g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] = sz; - for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) - { + for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i) { const char* szText = g_aPreviousFiles[i].c_str(); UINT iFlags = 0; - if ('\0' == *szText) - { + if ('\0' == *szText) { szText = ""; iFlags = MF_GRAYED | MF_DISABLED; } ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i), MF_STRING | MF_BYCOMMAND | iFlags,AI_VIEW_RECENT_FILE_ID(i),szText); } - return; } //------------------------------------------------------------------------------- // Open a new asset //------------------------------------------------------------------------------- -void OpenAsset() -{ +void OpenAsset() { char szFileName[MAX_PATH]; DWORD dwTemp = MAX_PATH; - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"CurrentApp",NULL,NULL, - (BYTE*)szFileName,&dwTemp)) - { + if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"CurrentApp",NULL,NULL, (BYTE*)szFileName,&dwTemp)) { // Key was not found. Use C: strcpy(szFileName,""); - } - else - { + } else { // need to remove the file name char* sz = strrchr(szFileName,'\\'); if (!sz) @@ -970,13 +861,14 @@ void OpenAsset() OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR, 0, 1, ".x", 0, NULL, NULL }; - if(GetOpenFileName(&sFilename1) == 0) return; + if (GetOpenFileName(&sFilename1) == 0) { + return; + } // Now store the file in the registry RegSetValueExA(g_hRegistry,"CurrentApp",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH); - if (0 != strcmp(g_szFileName,szFileName)) - { + if (0 != strcmp(g_szFileName,szFileName)) { strcpy(g_szFileName, szFileName); DeleteAssetData(); DeleteAsset(); @@ -988,13 +880,10 @@ void OpenAsset() // Save the list of previous files to the registry SaveHistory(); } - return; } //------------------------------------------------------------------------------- -void SetupPPUIState() -{ - +void SetupPPUIState() { // that's ugly. anyone willing to rewrite me from scratch? HMENU hMenu = GetMenu(g_hDlg); CheckMenuItem(hMenu,ID_VIEWER_PP_JIV,ppsteps & aiProcess_JoinIdenticalVertices ? MF_CHECKED : MF_UNCHECKED); @@ -1018,13 +907,11 @@ void SetupPPUIState() //------------------------------------------------------------------------------- // Fill the 'export' top level menu with a list of all supported export formats //------------------------------------------------------------------------------- -void PopulateExportMenu() -{ +void PopulateExportMenu() { // add sub items for all recent files Exporter exp; HMENU hm = ::CreateMenu(); - for(size_t i = 0; i < exp.GetExportFormatCount(); ++i) - { + for(size_t i = 0; i < exp.GetExportFormatCount(); ++i) { const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i); char tmp[256]; sprintf(tmp,"%s (%s)",e->description,e->id); @@ -1038,8 +925,7 @@ void PopulateExportMenu() //------------------------------------------------------------------------------- //------------------------------------------------------------------------------- -void DoExport(size_t formatId) -{ +void DoExport(size_t formatId) { if (!g_szFileName[0]) { MessageBox(g_hDlg, "No model loaded", "Export", MB_ICONERROR); return; @@ -1122,8 +1008,7 @@ void DoExport(size_t formatId) //------------------------------------------------------------------------------- // Initialize the user interface //------------------------------------------------------------------------------- -void InitUI() -{ +void InitUI() { SetDlgItemText(g_hDlg,IDC_EVERT,"0"); SetDlgItemText(g_hDlg,IDC_EFACE,"0"); SetDlgItemText(g_hDlg,IDC_EMAT,"0"); @@ -1147,13 +1032,10 @@ void InitUI() RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\ASSIMP\\Viewer", 0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL); - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LastUIState",NULL,NULL, - (BYTE*)&dwValue,&dwTemp)) - { + if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LastUIState",NULL,NULL, (BYTE*)&dwValue,&dwTemp)) { dwValue = 1; } - if (0 == dwValue) - { + if (0 == dwValue) { // collapse the viewer // adjust the size RECT sRect; @@ -1169,22 +1051,17 @@ void InitUI() SetWindowPos(g_hDlg,NULL,0,0,sRect.right-214,sRect.bottom, SWP_NOMOVE | SWP_NOZORDER); SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>"); - } - else - { + } else { CheckDlgButton(g_hDlg,IDC_BLUBB,BST_CHECKED); } // AutoRotate if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"AutoRotate",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.bRotate = false; CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bRotate = true; CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_CHECKED); } @@ -1192,13 +1069,10 @@ void InitUI() // MultipleLights if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"MultipleLights",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.b3Lights = false; CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_UNCHECKED); - } - else - { + } else { g_sOptions.b3Lights = true; CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_CHECKED); } @@ -1206,27 +1080,22 @@ void InitUI() // Light rotate if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LightRotate",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.bLightRotate = false; CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bLightRotate = true; CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_CHECKED); } // NoSpecular - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoSpecular",NULL,NULL, - (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (ERROR_SUCCESS != RegQueryValueEx(g_hRegistry, "NoSpecular", NULL, NULL, (BYTE*)&dwValue, &dwTemp)) { + dwValue = 0; + } + if (0 == dwValue) { g_sOptions.bNoSpecular = false; CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bNoSpecular = true; CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_CHECKED); } @@ -1234,13 +1103,10 @@ void InitUI() // LowQuality if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LowQuality",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.bLowQuality = false; CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bLowQuality = true; CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_CHECKED); } @@ -1248,13 +1114,10 @@ void InitUI() // LowQuality if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoTransparency",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.bNoAlphaBlending = false; CheckDlgButton(g_hDlg,IDC_NOAB,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bNoAlphaBlending = true; CheckDlgButton(g_hDlg,IDC_NOAB,BST_CHECKED); } @@ -1262,27 +1125,23 @@ void InitUI() // DisplayNormals if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderNormals",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_sOptions.bRenderNormals = false; CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bRenderNormals = true; CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_CHECKED); } // NoMaterials - if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderMats",NULL,NULL, - (BYTE*)&dwValue,&dwTemp))dwValue = 1; - if (0 == dwValue) - { + if (ERROR_SUCCESS != RegQueryValueEx(g_hRegistry, "RenderMats", NULL, NULL, + (BYTE*)&dwValue, &dwTemp)) { + dwValue = 1; + } + if (0 == dwValue) { g_sOptions.bRenderMats = false; CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_CHECKED); - } - else - { + } else { g_sOptions.bRenderMats = true; CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_UNCHECKED); } @@ -1294,9 +1153,7 @@ void InitUI() { g_sOptions.bMultiSample = false; CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_UNCHECKED); - } - else - { + } else { g_sOptions.bMultiSample = true; CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_CHECKED); } @@ -1304,13 +1161,10 @@ void InitUI() // FPS Mode if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"FPSView",NULL,NULL, (BYTE*)&dwValue,&dwTemp))dwValue = 0; - if (0 == dwValue) - { + if (0 == dwValue) { g_bFPSView = false; CheckDlgButton(g_hDlg,IDC_ZOOM,BST_CHECKED); - } - else - { + } else { g_bFPSView = true; CheckDlgButton(g_hDlg,IDC_ZOOM,BST_UNCHECKED); } @@ -1338,22 +1192,20 @@ void InitUI() SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMIN,TRUE,0); SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMAX,TRUE,10000); - return; } //------------------------------------------------------------------------------- -// Message prcoedure for the smooth normals dialog +// Message procedure for the smooth normals dialog //------------------------------------------------------------------------------- -INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg, - WPARAM wParam,LPARAM lParam) -{ +INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); - switch (uMsg) - { + switch (uMsg) { case WM_INITDIALOG: - char s[30]; - ::sprintf(s,"%.2f",g_smoothAngle); - SetDlgItemText(hwndDlg,IDC_EDITSM,s); + { + char s[30]; + ::sprintf(s, "%.2f", g_smoothAngle); + SetDlgItemText(hwndDlg, IDC_EDITSM, s); + } return TRUE; case WM_CLOSE: @@ -1361,16 +1213,16 @@ INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg, return TRUE; case WM_COMMAND: + { + if (IDOK == LOWORD(wParam)) { + char s[30]; + GetDlgItemText(hwndDlg, IDC_EDITSM, s, 30); + g_smoothAngle = (float)atof(s); - if (IDOK == LOWORD(wParam)) { - char s[30]; - GetDlgItemText(hwndDlg,IDC_EDITSM,s,30); - g_smoothAngle = (float)atof(s); - - EndDialog(hwndDlg,0); - } - else if (IDCANCEL == LOWORD(wParam)) { - EndDialog(hwndDlg,1); + EndDialog(hwndDlg, 0); + } else if (IDCANCEL == LOWORD(wParam)) { + EndDialog(hwndDlg, 1); + } } return TRUE; } @@ -1385,9 +1237,7 @@ INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg, // NOTE: Due to the impossibility to process WM_CHAR messages in dialogs // properly the code for all hotkeys has been moved to the WndMain //------------------------------------------------------------------------------- -INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, - WPARAM wParam,LPARAM lParam) - { +INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); UNREFERENCED_PARAMETER(wParam); @@ -1830,13 +1680,10 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, case WM_COMMAND: HMENU hMenu = GetMenu(g_hDlg); - if (ID_VIEWER_QUIT == LOWORD(wParam)) - { + if (ID_VIEWER_QUIT == LOWORD(wParam)) { PostQuitMessage(0); DestroyWindow(hwndDlg); - } - else if (IDC_COMBO1 == LOWORD(wParam)) - { + } else if (IDC_COMBO1 == LOWORD(wParam)) { if(HIWORD(wParam) == CBN_SELCHANGE) { const size_t sel = static_cast(ComboBox_GetCurSel(GetDlgItem(hwndDlg,IDC_COMBO1))); if(g_pcAsset) { @@ -1844,9 +1691,7 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, SendDlgItemMessage(hwndDlg,IDC_SLIDERANIM,TBM_SETPOS,TRUE,0); } } - } - else if (ID_VIEWER_RESETVIEW == LOWORD(wParam)) - { + } else if (ID_VIEWER_RESETVIEW == LOWORD(wParam)) { g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f); g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f); g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f); @@ -1856,63 +1701,35 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, // don't forget to reset the st CBackgroundPainter::Instance().ResetSB(); - } - else if (ID__HELP == LOWORD(wParam)) - { + } else if (ID__HELP == LOWORD(wParam)) { DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_AVHELP), hwndDlg,&HelpDialogProc); - } - else if (ID__ABOUT == LOWORD(wParam)) - { + } else if (ID__ABOUT == LOWORD(wParam)) { DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_ABOUTBOX), hwndDlg,&AboutMessageProc); - } - else if (ID_TOOLS_LOGWINDOW == LOWORD(wParam)) - { - CLogWindow::Instance().Show(); - } - else if (ID__WEBSITE == LOWORD(wParam)) - { - ShellExecute(NULL,"open","http://assimp.sourceforge.net","","",SW_SHOW); - } - else if (ID__WEBSITESF == LOWORD(wParam)) - { - ShellExecute(NULL,"open","https://sourceforge.net/projects/assimp","","",SW_SHOW); - } - else if (ID_REPORTBUG == LOWORD(wParam)) - { - ShellExecute(NULL,"open","https://sourceforge.net/tracker/?func=add&group_id=226462&atid=1067632","","",SW_SHOW); - } - else if (ID_FR == LOWORD(wParam)) - { - ShellExecute(NULL,"open","https://sourceforge.net/forum/forum.php?forum_id=817653","","",SW_SHOW); - } - else if (ID_TOOLS_CLEARLOG == LOWORD(wParam)) - { - CLogWindow::Instance().Clear(); - } - else if (ID_TOOLS_SAVELOGTOFILE == LOWORD(wParam)) - { - CLogWindow::Instance().Save(); - } - else if (ID_VIEWER_MEMORYCONSUMATION == LOWORD(wParam)) - { - DisplayMemoryConsumption(); - } - else if (ID_VIEWER_H == LOWORD(wParam)) - { + } else if (ID_TOOLS_LOGWINDOW == LOWORD(wParam)) { + CLogWindow::Instance().Show(); + } else if (ID__WEBSITE == LOWORD(wParam)) { + ShellExecute(NULL,"open","http://assimp.sourceforge.net","","",SW_SHOW); + } else if (ID__WEBSITESF == LOWORD(wParam)) { + ShellExecute(NULL,"open","https://sourceforge.net/projects/assimp","","",SW_SHOW); + } else if (ID_REPORTBUG == LOWORD(wParam)) { + ShellExecute(NULL,"open","https://sourceforge.net/tracker/?func=add&group_id=226462&atid=1067632","","",SW_SHOW); + } else if (ID_FR == LOWORD(wParam)) { + ShellExecute(NULL,"open","https://sourceforge.net/forum/forum.php?forum_id=817653","","",SW_SHOW); + } else if (ID_TOOLS_CLEARLOG == LOWORD(wParam)) { + CLogWindow::Instance().Clear(); + } else if (ID_TOOLS_SAVELOGTOFILE == LOWORD(wParam)) { + CLogWindow::Instance().Save(); + } else if (ID_VIEWER_MEMORYCONSUMATION == LOWORD(wParam)) { + DisplayMemoryConsumption(); + } else if (ID_VIEWER_H == LOWORD(wParam)) { MakeFileAssociations(); - } - else if (ID_BACKGROUND_CLEAR == LOWORD(wParam)) - { + } else if (ID_BACKGROUND_CLEAR == LOWORD(wParam)) { ClearBG(); - } - else if (ID_BACKGROUND_SETCOLOR == LOWORD(wParam)) - { + } else if (ID_BACKGROUND_SETCOLOR == LOWORD(wParam)) { ChooseBGColor(); - } - else if (ID_BACKGROUND_LOADTEXTURE == LOWORD(wParam)) - { + } else if (ID_BACKGROUND_LOADTEXTURE == LOWORD(wParam)) { LoadBGTexture(); } else if (ID_BACKGROUND_LOADSKYBOX == LOWORD(wParam)) @@ -2071,34 +1888,25 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg, { g_sOptions.bStereoView =! g_sOptions.bStereoView; - HMENU hMenu = GetMenu(g_hDlg); - if (g_sOptions.bStereoView) - { - ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW, + HMENU menu = ::GetMenu(g_hDlg); + if (g_sOptions.bStereoView) { + ::ModifyMenu(menu,ID_TOOLS_STEREOVIEW, MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view"); CLogDisplay::Instance().AddEntry("[INFO] Switched to stereo mode", D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0)); - } - else - { - ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW, + } else { + ModifyMenu(menu,ID_TOOLS_STEREOVIEW, MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view"); CLogDisplay::Instance().AddEntry("[INFO] Switched to mono mode", D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0)); } - } - else if (ID_TOOLS_SETANGLELIMIT == LOWORD(wParam)) - { + } else if (ID_TOOLS_SETANGLELIMIT == LOWORD(wParam)) { DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_DIALOGSMOOTH),g_hDlg,&SMMessageProc); - } - else if (ID_VIEWER_CLEARHISTORY == LOWORD(wParam)) - { + } else if (ID_VIEWER_CLEARHISTORY == LOWORD(wParam)) { ClearHistory(); - } - else if (ID_VIEWER_CLOSEASSET == LOWORD(wParam)) - { + } else if (ID_VIEWER_CLOSEASSET == LOWORD(wParam)) { DeleteAssetData(); DeleteAsset(); } @@ -2420,36 +2228,34 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, SetFocus(g_hDlg); // recover background skyboxes/textures from the last session - HKEY g_hRegistry; - union - { + HKEY hRegistry; + union { char szFileName[MAX_PATH]; D3DCOLOR clrColor; - }; + }; DWORD dwTemp = MAX_PATH; RegCreateKeyEx(HKEY_CURRENT_USER, - "Software\\ASSIMP\\Viewer",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL); - if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastSkyBoxSrc",NULL,NULL, + "Software\\ASSIMP\\Viewer",0,NULL,0,KEY_ALL_ACCESS, NULL, &hRegistry,NULL); + if(ERROR_SUCCESS == RegQueryValueEx(hRegistry,"LastSkyBoxSrc",NULL,NULL, (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0]) { CBackgroundPainter::Instance().SetCubeMapBG(szFileName); } - else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastTextureSrc",NULL,NULL, + else if(ERROR_SUCCESS == RegQueryValueEx(hRegistry,"LastTextureSrc",NULL,NULL, (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0]) { CBackgroundPainter::Instance().SetTextureBG(szFileName); } - else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"Color",NULL,NULL, + else if(ERROR_SUCCESS == RegQueryValueEx(hRegistry,"Color",NULL,NULL, (BYTE*)&clrColor,&dwTemp)) { CBackgroundPainter::Instance().SetColor(clrColor); } - RegCloseKey(g_hRegistry); + RegCloseKey(hRegistry); // now handle command line arguments HandleCommandLine(lpCmdLine); - double adLast[30]; for (int i = 0; i < 30;++i)adLast[i] = 0.0f; int iCurrent = 0; @@ -2608,7 +2414,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, // render the scene CDisplay::Instance().OnRender(); - // measure FPS, average it out g_dCurTime = timeGetTime(); g_fElpasedTime = (float)((g_dCurTime - g_dLastTime) * 0.001); @@ -2617,26 +2422,26 @@ int APIENTRY _tWinMain(HINSTANCE hInstance, adLast[iCurrent++] = 1.0f / g_fElpasedTime; double dFPS = 0.0; - for (int i = 0;i < 30;++i) - dFPS += adLast[i]; + for (int i = 0; i < 30; ++i) { + dFPS += adLast[ i ]; + } dFPS /= 30.0; - if (30 == iCurrent) - { + if (30 == iCurrent) { iCurrent = 0; - if (dFPS != g_fFPS) - { + if (dFPS != g_fFPS) { g_fFPS = dFPS; char szOut[256]; sprintf(szOut,"%i",(int)floorf((float)dFPS+0.5f)); SetDlgItemText(g_hDlg,IDC_EFPS,szOut); - } } } + } DeleteAsset(); Assimp::DefaultLogger::kill(); ShutdownDevice(); ShutdownD3D(); + return 0; - } \ No newline at end of file +} diff --git a/tools/assimp_view/Normals.cpp b/tools/assimp_view/Normals.cpp index 240825905..4ce706c6a 100644 --- a/tools/assimp_view/Normals.cpp +++ b/tools/assimp_view/Normals.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -39,11 +39,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ - #include "assimp_view.h" -// note: these are no longer part of the public API, but they are -// exported on Windows to keep AssimpView alive. #include "GenFaceNormalsProcess.h" #include "GenVertexNormalsProcess.h" #include "JoinVerticesProcess.h" @@ -60,15 +57,14 @@ float g_smoothAngle = 80.f; //------------------------------------------------------------------------------- // Flip all normal vectors //------------------------------------------------------------------------------- -void AssetHelper::FlipNormalsInt() -{ +void AssetHelper::FlipNormalsInt() { // invert all normal vectors - for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i) - { + for (unsigned int i = 0; i < this->pcScene->mNumMeshes;++i) { aiMesh* pcMesh = this->pcScene->mMeshes[i]; - if (!pcMesh->mNormals) + if (!pcMesh->mNormals) { continue; + } for (unsigned int a = 0; a < pcMesh->mNumVertices;++a){ pcMesh->mNormals[a] *= -1.0f; @@ -77,8 +73,7 @@ void AssetHelper::FlipNormalsInt() } //------------------------------------------------------------------------------- -void AssetHelper::FlipNormals() -{ +void AssetHelper::FlipNormals() { FlipNormalsInt(); // recreate native data @@ -90,53 +85,42 @@ void AssetHelper::FlipNormals() //------------------------------------------------------------------------------- // Set the normal set of the scene //------------------------------------------------------------------------------- -void AssetHelper::SetNormalSet(unsigned int iSet) -{ +void AssetHelper::SetNormalSet(unsigned int iSet) { // we need to build an unique set of vertices for this ... { MakeVerboseFormatProcess* pcProcess = new MakeVerboseFormatProcess(); pcProcess->Execute(pcScene); delete pcProcess; - for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) - { - if (!apcMeshes[i]->pvOriginalNormals) - { + for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) { + if (!apcMeshes[i]->pvOriginalNormals) { apcMeshes[i]->pvOriginalNormals = new aiVector3D[pcScene->mMeshes[i]->mNumVertices]; memcpy( apcMeshes[i]->pvOriginalNormals,pcScene->mMeshes[i]->mNormals, pcScene->mMeshes[i]->mNumVertices * sizeof(aiVector3D)); } delete[] pcScene->mMeshes[i]->mNormals; - pcScene->mMeshes[i]->mNormals = NULL; + pcScene->mMeshes[i]->mNormals = nullptr; } } - // now we can start to calculate a new set of normals - if (HARD == iSet) - { + if (HARD == iSet) { GenFaceNormalsProcess* pcProcess = new GenFaceNormalsProcess(); pcProcess->Execute(pcScene); FlipNormalsInt(); delete pcProcess; - } - else if (SMOOTH == iSet) - { + } else if (SMOOTH == iSet) { GenVertexNormalsProcess* pcProcess = new GenVertexNormalsProcess(); pcProcess->SetMaxSmoothAngle((float)AI_DEG_TO_RAD(g_smoothAngle)); pcProcess->Execute(pcScene); FlipNormalsInt(); delete pcProcess; - } - else if (ORIGINAL == iSet) - { - for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) - { - if (apcMeshes[i]->pvOriginalNormals) - { + } else if (ORIGINAL == iSet) { + for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) { + if (apcMeshes[i]->pvOriginalNormals) { delete[] pcScene->mMeshes[i]->mNormals; pcScene->mMeshes[i]->mNormals = apcMeshes[i]->pvOriginalNormals; - apcMeshes[i]->pvOriginalNormals = NULL; + apcMeshes[i]->pvOriginalNormals = nullptr; } } } @@ -153,14 +137,11 @@ void AssetHelper::SetNormalSet(unsigned int iSet) iNormalSet = iSet; - if (g_bWasFlipped) - { + if (g_bWasFlipped) { // invert all normal vectors - for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) - { + for (unsigned int i = 0; i < pcScene->mNumMeshes;++i) { aiMesh* pcMesh = pcScene->mMeshes[i]; - for (unsigned int a = 0; a < pcMesh->mNumVertices;++a) - { + for (unsigned int a = 0; a < pcMesh->mNumVertices;++a) { pcMesh->mNormals[a] *= -1.0f; } } @@ -169,7 +150,6 @@ void AssetHelper::SetNormalSet(unsigned int iSet) // recreate native data DeleteAssetData(true); CreateAssetData(); - return; } -}; \ No newline at end of file +} diff --git a/tools/assimp_view/SceneAnimator.cpp b/tools/assimp_view/SceneAnimator.cpp index 6e507cb41..c2ebeacb3 100644 --- a/tools/assimp_view/SceneAnimator.cpp +++ b/tools/assimp_view/SceneAnimator.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -47,21 +47,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace AssimpView; +const aiMatrix4x4 IdentityMatrix; + // ------------------------------------------------------------------------------------------------ // Constructor for a given scene. SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex) -{ - mScene = pScene; - mCurrentAnimIndex = -1; - mAnimEvaluator = NULL; - mRootNode = NULL; - +: mScene( pScene ) +, mCurrentAnimIndex( -1 ) +, mAnimEvaluator( nullptr ) +, mRootNode( nullptr ) { // build the nodes-for-bones table - for (unsigned int i = 0; i < pScene->mNumMeshes;++i) - { + for (unsigned int i = 0; i < pScene->mNumMeshes;++i) { const aiMesh* mesh = pScene->mMeshes[i]; - for (unsigned int n = 0; n < mesh->mNumBones;++n) - { + for (unsigned int n = 0; n < mesh->mNumBones;++n) { const aiBone* bone = mesh->mBones[n]; mBoneNodesByName[bone->mName.data] = pScene->mRootNode->FindNode(bone->mName); @@ -74,34 +72,34 @@ SceneAnimator::SceneAnimator( const aiScene* pScene, size_t pAnimIndex) // ------------------------------------------------------------------------------------------------ // Destructor -SceneAnimator::~SceneAnimator() -{ +SceneAnimator::~SceneAnimator() { delete mRootNode; delete mAnimEvaluator; } // ------------------------------------------------------------------------------------------------ // Sets the animation to use for playback. -void SceneAnimator::SetAnimIndex( size_t pAnimIndex) -{ +void SceneAnimator::SetAnimIndex( size_t pAnimIndex) { // no change - if( pAnimIndex == mCurrentAnimIndex) + if (pAnimIndex == static_cast( mCurrentAnimIndex ) ) { return; + } // kill data of the previous anim - delete mRootNode; mRootNode = NULL; - delete mAnimEvaluator; mAnimEvaluator = NULL; + delete mRootNode; mRootNode = nullptr; + delete mAnimEvaluator; mAnimEvaluator = nullptr; mNodesByName.clear(); mCurrentAnimIndex = pAnimIndex; // create the internal node tree. Do this even in case of invalid animation index // so that the transformation matrices are properly set up to mimic the current scene - mRootNode = CreateNodeTree( mScene->mRootNode, NULL); + mRootNode = CreateNodeTree( mScene->mRootNode, nullptr); // invalid anim index - if( mCurrentAnimIndex >= mScene->mNumAnimations) + if (static_cast( mCurrentAnimIndex )>= mScene->mNumAnimations) { return; + } // create an evaluator for this animation mAnimEvaluator = new AnimEvaluator( mScene->mAnimations[mCurrentAnimIndex]); @@ -109,11 +107,11 @@ void SceneAnimator::SetAnimIndex( size_t pAnimIndex) // ------------------------------------------------------------------------------------------------ // Calculates the node transformations for the scene. -void SceneAnimator::Calculate( double pTime) -{ +void SceneAnimator::Calculate( double pTime) { // invalid anim - if( !mAnimEvaluator) + if (!mAnimEvaluator) { return; + } // calculate current local transformations mAnimEvaluator->Evaluate( pTime); @@ -124,36 +122,35 @@ void SceneAnimator::Calculate( double pTime) // ------------------------------------------------------------------------------------------------ // Retrieves the most recent local transformation matrix for the given node. -const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const -{ +const aiMatrix4x4& SceneAnimator::GetLocalTransform( const aiNode* node) const { NodeMap::const_iterator it = mNodesByName.find( node); - if( it == mNodesByName.end()) - return mIdentityMatrix; + if (it == mNodesByName.end()) { + return IdentityMatrix; + } return it->second->mLocalTransform; } // ------------------------------------------------------------------------------------------------ // Retrieves the most recent global transformation matrix for the given node. -const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const -{ +const aiMatrix4x4& SceneAnimator::GetGlobalTransform( const aiNode* node) const { NodeMap::const_iterator it = mNodesByName.find( node); - if( it == mNodesByName.end()) - return mIdentityMatrix; + if (it == mNodesByName.end()) { + return IdentityMatrix; + } return it->second->mGlobalTransform; } // ------------------------------------------------------------------------------------------------ // Calculates the bone matrices for the given mesh. -const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */) -{ +const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex /* = 0 */) { ai_assert( pMeshIndex < pNode->mNumMeshes); size_t meshIndex = pNode->mMeshes[pMeshIndex]; ai_assert( meshIndex < mScene->mNumMeshes); const aiMesh* mesh = mScene->mMeshes[meshIndex]; - // resize array and initialise it with identity matrices + // resize array and initialize it with identity matrices mTransforms.resize( mesh->mNumBones, aiMatrix4x4()); // calculate the mesh's inverse global transform @@ -162,8 +159,7 @@ const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pN // Bone matrices transform from mesh coordinates in bind pose to mesh coordinates in skinned pose // Therefore the formula is offsetMatrix * currentGlobalTransform * inverseCurrentMeshTransform - for( size_t a = 0; a < mesh->mNumBones; ++a) - { + for( size_t a = 0; a < mesh->mNumBones; ++a) { const aiBone* bone = mesh->mBones[a]; const aiMatrix4x4& currentGlobalTransform = GetGlobalTransform( mBoneNodesByName[ bone->mName.data ]); mTransforms[a] = globalInverseMeshTransform * currentGlobalTransform * bone->mOffsetMatrix; @@ -175,8 +171,7 @@ const std::vector& SceneAnimator::GetBoneMatrices( const aiNode* pN // ------------------------------------------------------------------------------------------------ // Recursively creates an internal node structure matching the current scene and animation. -SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent) -{ +SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pParent) { // create a node SceneAnimNode* internalNode = new SceneAnimNode( pNode->mName.data); internalNode->mParent = pParent; @@ -187,14 +182,11 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar CalculateGlobalTransform( internalNode); // find the index of the animation track affecting this node, if any - if( mCurrentAnimIndex < mScene->mNumAnimations) - { + if(static_cast( mCurrentAnimIndex ) < mScene->mNumAnimations) { internalNode->mChannelIndex = -1; const aiAnimation* currentAnim = mScene->mAnimations[mCurrentAnimIndex]; - for( unsigned int a = 0; a < currentAnim->mNumChannels; a++) - { - if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName) - { + for( unsigned int a = 0; a < currentAnim->mNumChannels; a++) { + if( currentAnim->mChannels[a]->mNodeName.data == internalNode->mName) { internalNode->mChannelIndex = a; break; } @@ -202,8 +194,7 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar } // continue for all child nodes and assign the created internal nodes as our children - for( unsigned int a = 0; a < pNode->mNumChildren; a++) - { + for( unsigned int a = 0; a < pNode->mNumChildren; ++a ) { SceneAnimNode* childNode = CreateNodeTree( pNode->mChildren[a], internalNode); internalNode->mChildren.push_back( childNode); } @@ -213,12 +204,10 @@ SceneAnimNode* SceneAnimator::CreateNodeTree( aiNode* pNode, SceneAnimNode* pPar // ------------------------------------------------------------------------------------------------ // Recursively updates the internal node transformations from the given matrix array -void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector& pTransforms) -{ +void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector& pTransforms) { // update node local transform - if( pNode->mChannelIndex != -1) - { - ai_assert( pNode->mChannelIndex < pTransforms.size()); + if( pNode->mChannelIndex != -1) { + ai_assert(static_cast( pNode->mChannelIndex ) < pTransforms.size()); pNode->mLocalTransform = pTransforms[pNode->mChannelIndex]; } @@ -226,19 +215,18 @@ void SceneAnimator::UpdateTransforms( SceneAnimNode* pNode, const std::vector::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it) - UpdateTransforms( *it, pTransforms); + for (std::vector::iterator it = pNode->mChildren.begin(); it != pNode->mChildren.end(); ++it) { + UpdateTransforms(*it, pTransforms); + } } // ------------------------------------------------------------------------------------------------ // Calculates the global transformation matrix for the given internal node -void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode) -{ +void SceneAnimator::CalculateGlobalTransform( SceneAnimNode* pInternalNode) { // concatenate all parent transforms to get the global transform for this node pInternalNode->mGlobalTransform = pInternalNode->mLocalTransform; SceneAnimNode* node = pInternalNode->mParent; - while( node) - { + while( node) { pInternalNode->mGlobalTransform = node->mLocalTransform * pInternalNode->mGlobalTransform; node = node->mParent; } diff --git a/tools/assimp_view/SceneAnimator.h b/tools/assimp_view/SceneAnimator.h index afcbac925..00d9832b6 100644 --- a/tools/assimp_view/SceneAnimator.h +++ b/tools/assimp_view/SceneAnimator.h @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2012, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved. @@ -49,15 +49,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -namespace AssimpView { +namespace AssimpView { // --------------------------------------------------------------------------------- /** A little tree structure to match the scene's node structure, but holding * additional data. Needs to be public to allow using it in templates at * certain compilers. */ -struct SceneAnimNode -{ +struct SceneAnimNode { std::string mName; SceneAnimNode* mParent; std::vector mChildren; @@ -69,12 +68,15 @@ struct SceneAnimNode aiMatrix4x4 mGlobalTransform; //! index in the current animation's channel array. -1 if not animated. - size_t mChannelIndex; + int mChannelIndex; //! Default construction SceneAnimNode() : mName() - , mParent(NULL) + , mParent(nullptr) + , mChildren() + , mLocalTransform() + , mGlobalTransform() , mChannelIndex(-1) { // empty } @@ -82,8 +84,11 @@ struct SceneAnimNode //! Construction from a given name SceneAnimNode( const std::string& pName) : mName( pName) - , mParent(NULL) - , mChannelIndex( -1 ) { + , mParent(nullptr) + , mChildren() + , mLocalTransform() + , mGlobalTransform() + , mChannelIndex(-1) { // empty } @@ -105,8 +110,7 @@ struct SceneAnimNode * GetGlobalTransform(). A full set of bone matrices can be retrieved by * GetBoneMatrices() for a given mesh. */ -class SceneAnimator -{ +class SceneAnimator { public: // ---------------------------------------------------------------------------- @@ -186,7 +190,6 @@ public: const std::vector& GetBoneMatrices( const aiNode* pNode, size_t pMeshIndex = 0); - // ---------------------------------------------------------------------------- /** @brief Get the current animation index */ @@ -198,7 +201,7 @@ public: /** @brief Get the current animation or NULL */ aiAnimation* CurrentAnim() const { - return mCurrentAnimIndex < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL; + return static_cast( mCurrentAnimIndex ) < mScene->mNumAnimations ? mScene->mAnimations[ mCurrentAnimIndex ] : NULL; } protected: @@ -221,7 +224,7 @@ protected: const aiScene* mScene; /** Current animation index */ - size_t mCurrentAnimIndex; + int mCurrentAnimIndex; /** The AnimEvaluator we use to calculate the current pose for the current animation */ AnimEvaluator* mAnimEvaluator; @@ -239,9 +242,6 @@ protected: /** Array to return transformations results inside. */ std::vector mTransforms; - - /** Identity matrix to return a reference to in case of error */ - aiMatrix4x4 mIdentityMatrix; }; } // end of namespace AssimpView diff --git a/tools/assimp_view/Shaders.cpp b/tools/assimp_view/Shaders.cpp index 1b6f3dc88..49ec5320d 100644 --- a/tools/assimp_view/Shaders.cpp +++ b/tools/assimp_view/Shaders.cpp @@ -3,7 +3,7 @@ Open Asset Import Library (assimp) --------------------------------------------------------------------------- -Copyright (c) 2006-2015, assimp team +Copyright (c) 2006-2019, assimp team All rights reserved.