3030#include < algorithm>
3131#include < array>
3232#include < stdint.h>
33+ #include < string.h>
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+
178207template <>
179208string& 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,13 @@ 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 =
786+ read_<unsigned int >(is);
787+ }
788+
753789 if (m_objectName.empty () || m_objectFound || name == m_objectName) {
754790 m_objectFound++;
755791 }
@@ -772,8 +808,49 @@ bool RVMParser::readGroup(std::istream& is, std::istream* attributeStream)
772808 if (!readPrimitive (is)) {
773809 return false ;
774810 }
811+ } else if (id == " OBST" ) {
812+ // unsigned int offset =
813+ read_<unsigned int >(is, offset);
814+ // unsigned int skiped =
815+ read_<unsigned int >(is); // Garbage ?
816+ // unsigned int version =
817+ read_<unsigned int >(is);
818+
819+ readUntil (is, " CNTE" );
820+ break ;
775821 } else {
776- m_lastError = " Unknown or invalid identifier found." ;
822+ std::stringstream stream;
823+
824+ stream << " Unknown or invalid identifier {" ;
825+ stream << " 1: " << ((unsigned int )((unsigned char )id.chrs [0 ]));
826+ if (id.chrs [0 ] != 0 )
827+ {
828+ stream << " / '" << id.chrs [0 ] << " '" ;
829+ }
830+ stream << " , " ;
831+ stream << " 2: " << ((unsigned int )((unsigned char )id.chrs [1 ]));
832+ if (id.chrs [1 ] != 0 )
833+ {
834+ stream << " / '" << id.chrs [1 ] << " '" ;
835+ }
836+ stream << " , " ;
837+ stream << " 3: " << ((unsigned int )((unsigned char )id.chrs [2 ]));
838+ if (id.chrs [2 ] != 0 )
839+ {
840+ stream << " / '" << id.chrs [2 ] << " '" ;
841+ }
842+ stream << " , " ;
843+ stream << " 4: " << ((unsigned int )((unsigned char )id.chrs [3 ]));
844+ if (id.chrs [3 ] != 0 )
845+ {
846+ stream << " / '" << id.chrs [3 ] << " '" ;
847+ }
848+ stream << " } found. { 1 }, position of stream is { " ;
849+ stream << " 10: " << is.tellg () << " , " ;
850+ stream << " 16 (Hex): " << std::hex << is.tellg ();
851+ stream << " }" ;
852+
853+ m_lastError = stream.str ();
777854 return false ;
778855 }
779856 }
0 commit comments