浏览代码

Merge pull request #326 from Gargaj/newprogresshandler

More elaborate progress handler
Kim Kulling 11 年之前
父节点
当前提交
9f795c64d5
共有 2 个文件被更改,包括 42 次插入7 次删除
  1. 13 4
      code/Importer.cpp
  2. 29 3
      include/assimp/ProgressHandler.hpp

+ 13 - 4
code/Importer.cpp

@@ -640,16 +640,25 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
 			}
 		}
 
+		// Get file size for progress handler
+		IOStream * fileIO = pimpl->mIOHandler->Open( pFile );
+		uint32_t fileSize = 0;
+		if (fileIO)
+		{
+			fileSize = fileIO->FileSize();
+			pimpl->mIOHandler->Close( fileIO );
+		}
+
 		// Dispatch the reading to the worker class for this format
 		DefaultLogger::get()->info("Found a matching importer for this file format");
-		pimpl->mProgressHandler->Update();
+		pimpl->mProgressHandler->UpdateFileRead( 0, fileSize );
 
 		if (profiler) {
 			profiler->BeginRegion("import");
 		}
 
 		pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler);
-		pimpl->mProgressHandler->Update();
+		pimpl->mProgressHandler->UpdateFileRead( fileSize, fileSize );
 
 		if (profiler) {
 			profiler->EndRegion("import");
@@ -678,7 +687,6 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
 			ScenePreprocessor pre(pimpl->mScene);
 			pre.ProcessScene();
 
-			pimpl->mProgressHandler->Update();
 			if (profiler) {
 				profiler->EndRegion("preprocess");
 			}
@@ -768,6 +776,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
 	for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++)	{
 
 		BaseProcess* process = pimpl->mPostProcessingSteps[a];
+		pimpl->mProgressHandler->UpdatePostProcess( a, pimpl->mPostProcessingSteps.size() );
 		if( process->IsActive( pFlags))	{
 
 			if (profiler) {
@@ -775,7 +784,6 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
 			}
 
 			process->ExecuteOnScene	( this );
-			pimpl->mProgressHandler->Update();
 
 			if (profiler) {
 				profiler->EndRegion("postprocess");
@@ -803,6 +811,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
 		}
 #endif // ! DEBUG
 	}
+	pimpl->mProgressHandler->UpdatePostProcess( pimpl->mPostProcessingSteps.size(), pimpl->mPostProcessingSteps.size() );
 
 	// update private scene flags
   if( pimpl->mScene )

+ 29 - 3
include/assimp/ProgressHandler.hpp

@@ -81,13 +81,39 @@ public:
 	 *   all needed cleanup tasks prior to returning control to the
 	 *   caller). If the loading is aborted, #Importer::ReadFile()
 	 *   returns always NULL.
-	 *
-	 *  @note Currently, percentage is always -1.f because there is 
-	 *   no reliable way to compute it.
 	 *   */
 	virtual bool Update(float percentage = -1.f) = 0;
 
+	// -------------------------------------------------------------------
+	/** @brief Progress callback for file loading steps
+	 *  @param numberOfSteps The number of total post-processing
+	 *   steps
+	 *  @param currentStep The index of the current post-processing
+	 *   step that will run, or equal to numberOfSteps if all of
+	 *   them has finished. This number is always strictly monotone
+	 *   increasing, although not necessarily linearly.
+	 *
+	 *  @note This is currently only used at the start and the end
+	 *   of the file parsing.
+	 *   */
+	virtual void UpdateFileRead(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
+		float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
+		Update( f * 0.5f );
+	};
 
+	// -------------------------------------------------------------------
+	/** @brief Progress callback for post-processing steps
+	 *  @param numberOfSteps The number of total post-processing
+	 *   steps
+	 *  @param currentStep The index of the current post-processing
+	 *   step that will run, or equal to numberOfSteps if all of
+	 *   them has finished. This number is always strictly monotone
+	 *   increasing, although not necessarily linearly.
+	 *   */
+	virtual void UpdatePostProcess(int currentStep /*= 0*/, int numberOfSteps /*= 0*/) {
+		float f = numberOfSteps ? currentStep / (float)numberOfSteps : 1.0f;
+		Update( f * 0.5f + 0.5f );
+	};
 
 }; // !class ProgressHandler 
 // ------------------------------------------------------------------------------------