Merge pull request #749 from andrewparlane/master

ObjImporter: Added better progress reporting during file import.
pull/756/head
Kim Kulling 2016-01-11 20:39:09 +01:00
commit 48eed0d2c6
3 changed files with 44 additions and 4 deletions

View File

@ -145,6 +145,13 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
modelName = pFile;
}
// This next stage takes ~ 1/3th of the total readFile task
// so should amount for 1/3th of the progress
// only update every 100KB or it'll be too slow
unsigned int progress = 0;
unsigned int progressCounter = 0;
const unsigned int updateProgressEveryBytes = 100 * 1024;
const unsigned int progressTotal = (3*m_Buffer.size()/updateProgressEveryBytes);
// process all '\'
std::vector<char> ::iterator iter = m_Buffer.begin();
while (iter != m_Buffer.end())
@ -159,10 +166,19 @@ void ObjFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene,
}
else
++iter;
if (++progressCounter >= updateProgressEveryBytes)
{
m_progress->UpdateFileRead(++progress, progressTotal);
progressCounter = 0;
}
}
// 1/3rd progress
m_progress->UpdateFileRead(1, 3);
// parse the file into a temporary representation
ObjFileParser parser(m_Buffer, modelName, pIOHandler);
ObjFileParser parser(m_Buffer, modelName, pIOHandler, m_progress);
// And create the proper return structures out of it
CreateDataFromImport(parser.GetModel(), pScene);

View File

@ -61,12 +61,13 @@ const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME;
// -------------------------------------------------------------------
// Constructor with loaded data and directories.
ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io ) :
ObjFileParser::ObjFileParser(std::vector<char> &data,const std::string &modelName, IOSystem *io, ProgressHandler* progress ) :
m_DataIt(data.begin()),
m_DataItEnd(data.end()),
m_pModel(NULL),
m_uiLine(0),
m_pIO( io )
m_pIO( io ),
m_progress(progress)
{
std::fill_n(m_buffer,Buffersize,0);
@ -106,8 +107,28 @@ void ObjFileParser::parseFile()
if (m_DataIt == m_DataItEnd)
return;
// only update every 100KB or it'll be too slow
const unsigned int updateProgressEveryBytes = 100 * 1024;
unsigned int progressCounter = 0;
const unsigned int bytesToProcess = std::distance(m_DataIt, m_DataItEnd);
const unsigned int progressTotal = 3 * bytesToProcess;
const unsigned int progressOffset = bytesToProcess;
unsigned int processed = 0;
DataArrayIt lastDataIt = m_DataIt;
while (m_DataIt != m_DataItEnd)
{
// Handle progress reporting
processed += std::distance(lastDataIt, m_DataIt);
lastDataIt = m_DataIt;
if (processed > (progressCounter * updateProgressEveryBytes))
{
progressCounter++;
m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal);
}
// parse line
switch (*m_DataIt)
{
case 'v': // Parse a vertex texture coordinate

View File

@ -59,6 +59,7 @@ namespace ObjFile {
class ObjFileImporter;
class IOSystem;
class ProgressHandler;
/// \class ObjFileParser
/// \brief Parser for a obj waveform file
@ -71,7 +72,7 @@ public:
public:
/// \brief Constructor with data array.
ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io, ProgressHandler* progress);
/// \brief Destructor
~ObjFileParser();
/// \brief Model getter.
@ -139,6 +140,8 @@ private:
char m_buffer[Buffersize];
/// Pointer to IO system instance.
IOSystem *m_pIO;
//! Pointer to progress handler
ProgressHandler* m_progress;
/// Path to the current model
};