Browse Source

Some review findings.

Kim Kulling 7 years ago
parent
commit
339cc2e951
4 changed files with 22 additions and 17 deletions
  1. 6 1
      code/XFileImporter.cpp
  2. 8 2
      code/XFileParser.cpp
  3. 7 12
      tools/assimp_view/Display.cpp
  4. 1 2
      tools/assimp_view/assimp_view.cpp

+ 6 - 1
code/XFileImporter.cpp

@@ -332,6 +332,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
                 // collect vertex data for indices of this face
                 for( unsigned int d = 0; d < df.mNumIndices; ++d ) {
                     df.mIndices[d] = newIndex;
+                    const unsigned int newIdx( pf.mIndices[ d ] );
+                    if ( newIdx > sourceMesh->mPositions.size() ) {
+                        continue;
+                    }
+
                     orgPoints[newIndex] = pf.mIndices[d];
 
                     // Position
@@ -459,7 +464,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
             nbone->mNodeName.Set( bone->mBoneName);
             nanim->mChannels[b] = nbone;
 
-            // keyframes are given as combined transformation matrix keys
+            // key-frames are given as combined transformation matrix keys
             if( !bone->mTrafoKeys.empty() )
             {
                 nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size();

+ 8 - 2
code/XFileParser.cpp

@@ -471,7 +471,10 @@ void XFileParser::ParseDataObjectMesh( Mesh* pMesh)
         unsigned int numIndices = ReadInt();
         Face& face = pMesh->mPosFaces[a];
         for (unsigned int b = 0; b < numIndices; ++b) {
-            face.mIndices.push_back( ReadInt() );
+            const int idx( ReadInt() );
+            if ( idx <= numVertices ) {
+                face.mIndices.push_back( idx );
+            }
         }
         TestForSeparator();
     }
@@ -1293,7 +1296,8 @@ unsigned int XFileParser::ReadBinDWord() {
 // ------------------------------------------------------------------------------------------------
 unsigned int XFileParser::ReadInt()
 {
-    if( mIsBinaryFormat)
+:
+cd if( mIsBinaryFormat)
     {
         if( mBinaryNumCount == 0 && mEnd - mP >= 2)
         {
@@ -1305,6 +1309,7 @@ unsigned int XFileParser::ReadInt()
         }
 
         --mBinaryNumCount;
+        const size_t len( mEnd - mP );
         if ( mEnd - mP >= 4) {
             return ReadBinDWord();
         } else {
@@ -1340,6 +1345,7 @@ unsigned int XFileParser::ReadInt()
         }
 
         CheckForSeparator();
+
         return isNegative ? ((unsigned int) -int( number)) : number;
     }
 }

+ 7 - 12
tools/assimp_view/Display.cpp

@@ -362,9 +362,7 @@ int CDisplay::ReplaceCurrentTexture(const char* szPath)
             *tex = piTexture;
             m_pcCurrentTexture->piTexture = tex;
 
-            //if (!pcMesh->bSharedFX){
-                pcMesh->piEffect->SetTexture(tex_string,piTexture);
-            //}
+            pcMesh->piEffect->SetTexture(tex_string,piTexture);
         }
     }
 
@@ -562,7 +560,6 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot,
     tvi.iImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
     tvi.iSelectedImage = m_aiImageList[AI_VIEW_IMGLIST_MATERIAL];
     tvi.lParam = (LPARAM)10;
-    //tvi.state = TVIS_EXPANDED | TVIS_EXPANDEDONCE ;
 
     sNew.itemex = tvi;
     sNew.hInsertAfter = TVI_LAST;
@@ -629,7 +626,7 @@ int CDisplay::AddMaterialToDisplayList(HTREEITEM hRoot,
     return 1;
 }
 //-------------------------------------------------------------------------------
-// Expand all elements in the treeview
+// Expand all elements in the tree-view
 int CDisplay::ExpandTree()
 {
     // expand all materials
@@ -779,7 +776,7 @@ int CDisplay::OnRender()
     // Now render the log display in the upper right corner of the window
     CLogDisplay::Instance().OnRender();
 
-    // present the backbuffer
+    // present the back-buffer
     g_piDevice->EndScene();
     g_piDevice->Present(NULL,NULL,NULL,NULL);
 
@@ -1593,7 +1590,7 @@ int CDisplay::HandleInput()
     return 1;
 }
 //-------------------------------------------------------------------------------
-// Process input for an empty scen view to allow for skybox rotations
+// Process input for an empty scene view to allow for sky-box rotations
 int CDisplay::HandleInputEmptyScene()
 {
     if(CBackgroundPainter::TEXTURE_CUBE == CBackgroundPainter::Instance().GetMode())
@@ -2035,7 +2032,7 @@ int CDisplay::RenderNode (aiNode* piNode,const aiMatrix4x4& piMatrix,
             g_piDevice->SetVertexDeclaration( gDefaultVertexDecl);
 
             if (g_sOptions.bNoAlphaBlending) {
-                // manually disable alphablending
+                // manually disable alpha-blending
                 g_piDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
             }
 
@@ -2199,9 +2196,6 @@ int CDisplay::RenderTextureView()
     // it might be that there is no texture ...
     if (!m_pcCurrentTexture->piTexture)
     {
-        // FIX: no such log message. it would be repeated to often
-        //CLogDisplay::Instance().AddEntry("Unable to display texture. Image is unreachable.",
-        //  D3DCOLOR_ARGB(0xFF,0xFF,0,0));
         return 0;
     }
 
@@ -2296,5 +2290,6 @@ int CDisplay::RenderTextureView()
     // do we need to draw UV coordinates?
     return 1;
 }
-};
+
+}
 

+ 1 - 2
tools/assimp_view/assimp_view.cpp

@@ -178,7 +178,6 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
     // get the end time of zje operation, calculate delta t
     double fEnd = (double)timeGetTime();
     g_fLoadTime = (float)((fEnd - fCur) / 1000);
-//	char szTemp[128];
     g_bLoadingFinished = true;
 
     // check whether the loading process has failed ...
@@ -202,7 +201,7 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
 //-------------------------------------------------------------------------------
 int LoadAsset(void)
 {
-    // set the world and world rotation matrices to the identuty
+    // set the world and world rotation matrices to the identity
     g_mWorldRotate = aiMatrix4x4();
     g_mWorld = aiMatrix4x4();