Ply importer with correction from last general trunk merge

pull/1293/head
arkeon 2017-06-02 22:19:41 +02:00
parent f84851e893
commit 44a9f80e40
3 changed files with 54 additions and 13 deletions

View File

@ -100,6 +100,11 @@ public:
/// @return true if successful.
bool getNextDataLine( std::vector<T> &buffer, T continuationToken );
/// @brief Will read the next line ascii or binary end line char.
/// @param buffer The buffer for the next line.
/// @return true if successful.
bool getNextLine(std::vector<T> &buffer);
/// @brief Will read the next block.
/// @param buffer The buffer for the next block.
/// @return true if successful.
@ -279,6 +284,41 @@ bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationT
return true;
}
template<class T>
inline
bool IOStreamBuffer<T>::getNextLine(std::vector<T> &buffer) {
buffer.resize(m_cacheSize);
if (m_cachePos == m_cacheSize || 0 == m_filePos) {
if (!readNextBlock()) {
return false;
}
}
if (IsLineEnd(m_cache[m_cachePos])) {
// skip line end
while (m_cache[m_cachePos] != '\n') {
++m_cachePos;
}
++m_cachePos;
}
size_t i = 0;
while (!IsLineEnd(m_cache[m_cachePos])) {
buffer[i] = m_cache[m_cachePos];
m_cachePos++;
i++;
if (m_cachePos >= m_cacheSize) {
if (!readNextBlock()) {
return false;
}
}
}
buffer[i] = '\n';
m_cachePos++;
return true;
}
template<class T>
inline
bool IOStreamBuffer<T>::getNextBlock( std::vector<T> &buffer) {

View File

@ -165,7 +165,7 @@ void PLYImporter::InternReadFile(const std::string& pFile,
// the beginning of the file must be PLY - magic, magic
std::vector<char> headerCheck;
streamedBuffer.getNextDataLine(headerCheck, '\\');
streamedBuffer.getNextLine(headerCheck);
if ((headerCheck.size() >= 3) && (headerCheck[0] != 'P' && headerCheck[0] != 'p') ||
(headerCheck[1] != 'L' && headerCheck[1] != 'l') ||
@ -176,7 +176,7 @@ void PLYImporter::InternReadFile(const std::string& pFile,
}
std::vector<char> mBuffer2;
streamedBuffer.getNextDataLine(mBuffer2, '\\');
streamedBuffer.getNextLine(mBuffer2);
mBuffer = (unsigned char*)&mBuffer2[0];
char* szMe = (char*)&this->mBuffer[0];
@ -1019,12 +1019,13 @@ void PLYImporter::LoadMaterial(std::vector<aiMaterial*>* pvOut, std::string &def
int iMode = (int)aiShadingMode_Gouraud;
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
//generate white material most 3D engine just multiply ambient / diffuse color with actual ambient / light color
aiColor3D clr;
clr.b = clr.g = clr.r = 0.6f;
clr.b = clr.g = clr.r = 1.0f;
pcHelper->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
pcHelper->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_SPECULAR);
clr.b = clr.g = clr.r = 0.05f;
clr.b = clr.g = clr.r = 1.0f;
pcHelper->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_AMBIENT);
// The face order is absolutely undefined for PLY, so we have to

View File

@ -200,11 +200,11 @@ PLY::ESemantic PLY::Property::ParseSemantic(std::vector<char> &buffer) {
}
// NOTE: Blender3D exports texture coordinates as s,t tuples
else if (PLY::DOM::TokenMatch(buffer, "u", 1) || PLY::DOM::TokenMatch(buffer, "s", 1) || PLY::DOM::TokenMatch(buffer, "tx", 2))
else if (PLY::DOM::TokenMatch(buffer, "u", 1) || PLY::DOM::TokenMatch(buffer, "s", 1) || PLY::DOM::TokenMatch(buffer, "tx", 2) || PLY::DOM::TokenMatch(buffer, "texture_u", 9))
{
eOut = PLY::EST_UTextureCoord;
}
else if (PLY::DOM::TokenMatch(buffer, "v", 1) || PLY::DOM::TokenMatch(buffer, "t", 1) || PLY::DOM::TokenMatch(buffer, "ty", 2))
else if (PLY::DOM::TokenMatch(buffer, "v", 1) || PLY::DOM::TokenMatch(buffer, "t", 1) || PLY::DOM::TokenMatch(buffer, "ty", 2) || PLY::DOM::TokenMatch(buffer, "texture_v", 9))
{
eOut = PLY::EST_VTextureCoord;
}
@ -393,7 +393,7 @@ bool PLY::Element::ParseElement(IOStreamBuffer<char> &streamBuffer, std::vector<
// now parse all properties of the element
while (true)
{
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
pCur = (char*)&buffer[0];
// skip all comments
@ -530,7 +530,7 @@ bool PLY::DOM::ParseHeader(IOStreamBuffer<char> &streamBuffer, std::vector<char>
else
{
// ignore unknown header elements
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
}
}
@ -607,7 +607,7 @@ bool PLY::DOM::ParseInstanceBinary(IOStreamBuffer<char> &streamBuffer, DOM* p_pc
ai_assert(NULL != loader);
std::vector<char> buffer;
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin");
@ -636,7 +636,7 @@ bool PLY::DOM::ParseInstance(IOStreamBuffer<char> &streamBuffer, DOM* p_pcOut, P
ai_assert(NULL != loader);
std::vector<char> buffer;
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() begin");
@ -647,7 +647,7 @@ bool PLY::DOM::ParseInstance(IOStreamBuffer<char> &streamBuffer, DOM* p_pcOut, P
}
//get next line after header
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
if (!p_pcOut->ParseElementInstanceLists(streamBuffer, buffer, loader))
{
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() failure");
@ -677,7 +677,7 @@ bool PLY::ElementInstanceList::ParseInstanceList(
{
PLY::DOM::SkipComments(buffer);
PLY::DOM::SkipLine(buffer);
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
pCur = (buffer.empty()) ? NULL : (const char*)&buffer[0];
}
}
@ -711,7 +711,7 @@ bool PLY::ElementInstanceList::ParseInstanceList(
}
}
streamBuffer.getNextDataLine(buffer, '\\');
streamBuffer.getNextLine(buffer);
pCur = (buffer.empty()) ? NULL : (const char*)&buffer[0];
}
}