Skip to content

Commit bdba4ab

Browse files
author
nbogdan
committed
Added correct working while found id OBST
1 parent 80834cc commit bdba4ab

File tree

1 file changed

+77
-4
lines changed

1 file changed

+77
-4
lines changed

src/api/rvmparser.cpp

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <algorithm>
3131
#include <array>
3232
#include <stdint.h>
33+
#include <memory>
3334

3435
#include "rvmreader.h"
3536

@@ -106,6 +107,16 @@ struct Identifier
106107
return std::string(chrs, chrs + 4);
107108
}
108109

110+
inline Identifier(char source[5])
111+
: chrs { source[0], source[1], source[2], source[3] }
112+
{
113+
}
114+
115+
inline Identifier()
116+
: chrs { '0', '0', '0', '0' }
117+
{
118+
}
119+
109120
char chrs[4];
110121
};
111122

@@ -175,6 +186,24 @@ inline Identifier& read_<Identifier>(std::istream& in, Identifier& res)
175186
return res;
176187
}
177188

189+
size_t readUntil(std::istream& in, const Identifier& identifier)
190+
{
191+
size_t counter = 0;
192+
char charPtr[16]{};
193+
194+
do
195+
{
196+
++counter;
197+
memcpy(charPtr + 0, charPtr + 1, 15);
198+
charPtr[15] = in.get();
199+
} while (charPtr[3] != identifier.chrs[0] ||
200+
charPtr[7] != identifier.chrs[1] ||
201+
charPtr[11] != identifier.chrs[2] ||
202+
charPtr[15] != identifier.chrs[3]);
203+
204+
return counter;
205+
}
206+
178207
template<>
179208
string& read_<string>(istream& is, string& str)
180209
{
@@ -437,8 +466,8 @@ namespace {
437466
}
438467

439468
static void scaleMatrix(std::array<float, 12>& matrix, float factor) {
440-
for (int i = 0; i < 4; i++) {
441-
for (int j = 0; j < 3; j++) {
469+
for (size_t i = 0; i < 4; i++) {
470+
for (size_t j = 0; j < 3; j++) {
442471
matrix[i*3+j] *= factor;
443472
}
444473
}
@@ -738,7 +767,7 @@ bool RVMParser::readGroup(std::istream& is, std::istream* attributeStream)
738767
m_reader.updateProgress(read_<unsigned int>(is));
739768

740769
skip_<1>(is); // Garbage ?
741-
//const unsigned int version =
770+
const unsigned int version =
742771
read_<unsigned int>(is);
743772

744773
string name;
@@ -750,6 +779,12 @@ bool RVMParser::readGroup(std::istream& is, std::istream* attributeStream)
750779

751780
const unsigned int materialId = read_<unsigned int>(is);
752781

782+
783+
if (version == 3)
784+
{
785+
const unsigned int last = read_<unsigned int>(is);
786+
}
787+
753788
if (m_objectName.empty() || m_objectFound || name == m_objectName) {
754789
m_objectFound++;
755790
}
@@ -772,8 +807,46 @@ bool RVMParser::readGroup(std::istream& is, std::istream* attributeStream)
772807
if (!readPrimitive(is)) {
773808
return false;
774809
}
810+
} else if (id == "OBST") {
811+
unsigned int offset = read_<unsigned int>(is, offset);
812+
unsigned int skiped = read_<unsigned int>(is); // Garbage ?
813+
unsigned int version = read_<unsigned int>(is);
814+
815+
readUntil(is, "CNTE");
816+
break;
775817
} else {
776-
m_lastError = "Unknown or invalid identifier found.";
818+
std::stringstream stream;
819+
820+
stream << "Unknown or invalid identifier {";
821+
stream << " 1: " << ((unsigned int)((unsigned char)id.chrs[0]));
822+
if (id.chrs[0] != 0)
823+
{
824+
stream << " / '" << id.chrs[0] << "'";
825+
}
826+
stream << ", ";
827+
stream << " 2: " << ((unsigned int)((unsigned char)id.chrs[1]));
828+
if (id.chrs[1] != 0)
829+
{
830+
stream << " / '" << id.chrs[1] << "'";
831+
}
832+
stream << ", ";
833+
stream << " 3: " << ((unsigned int)((unsigned char)id.chrs[2]));
834+
if (id.chrs[2] != 0)
835+
{
836+
stream << " / '" << id.chrs[2] << "'";
837+
}
838+
stream << ", ";
839+
stream << " 4: " << ((unsigned int)((unsigned char)id.chrs[3]));
840+
if (id.chrs[3] != 0)
841+
{
842+
stream << " / '" << id.chrs[3] << "'";
843+
}
844+
stream << " } found. { 1 }, position of stream is { ";
845+
stream << "10: " << is.tellg() << ", ";
846+
stream << "16 (Hex): " << std::hex << is.tellg();
847+
stream << " }";
848+
849+
m_lastError = stream.str();
777850
return false;
778851
}
779852
}

0 commit comments

Comments
 (0)