------------------------------------------------------------------------------
| 224 | |
| 225 | //------------------------------------------------------------------------------ |
| 226 | bool ExtractGLBFileInformation(vtkResourceStream* stream, uint32_t& version, uint32_t& fileLength, |
| 227 | uint32_t glbStart, std::vector<vtkGLTFUtils::ChunkInfoType>& chunkInfo) |
| 228 | { |
| 229 | // Read version |
| 230 | if (stream->Read(&version, GLBWordSize) != GLBWordSize) |
| 231 | { |
| 232 | vtkErrorWithObjectMacro(nullptr, "Truncated glb file"); |
| 233 | return false; |
| 234 | } |
| 235 | |
| 236 | // Read file length |
| 237 | if (stream->Read(&fileLength, GLBWordSize) != GLBWordSize) |
| 238 | { |
| 239 | vtkErrorWithObjectMacro(nullptr, "Truncated glb file"); |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | // Read chunks until end of file |
| 244 | while (stream->Tell() - glbStart != fileLength) |
| 245 | { |
| 246 | // Read chunk length |
| 247 | std::uint32_t chunkDataSize; |
| 248 | if (stream->Read(&chunkDataSize, GLBWordSize) != GLBWordSize) |
| 249 | { |
| 250 | vtkErrorWithObjectMacro(nullptr, "Truncated glb file"); |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | // Read chunk type |
| 255 | std::string chunkType; |
| 256 | chunkType.resize(GLBWordSize); |
| 257 | if (stream->Read(chunkType.data(), chunkType.size()) != chunkType.size()) |
| 258 | { |
| 259 | vtkErrorWithObjectMacro(nullptr, "Truncated glb file"); |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | chunkInfo.emplace_back(chunkType, chunkDataSize); |
| 264 | |
| 265 | // Jump to next chunk |
| 266 | stream->Seek(chunkDataSize, vtkResourceStream::SeekDirection::Current); |
| 267 | } |
| 268 | |
| 269 | return true; |
| 270 | } |
| 271 | |
| 272 | //------------------------------------------------------------------------------ |
| 273 | bool ValidateGLBFile(const std::string& magic, uint32_t version, uint32_t fileLength, |