MCPcopy Create free account
hub / github.com/Kitware/VTK / LoadStreamBuffer

Method LoadStreamBuffer

IO/Geometry/vtkGLTFDocumentLoader.cxx:1568–1623  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1566
1567//------------------------------------------------------------------------------
1568bool vtkGLTFDocumentLoader::LoadStreamBuffer(
1569 vtkResourceStream* stream, std::vector<char>& glbBuffer)
1570{
1571 stream->Seek(this->GLBStart, vtkResourceStream::SeekDirection::Begin);
1572
1573 // Get base information
1574 std::array<char, 4> magic;
1575 if (stream->Read(magic.data(), magic.size()) != magic.size())
1576 {
1577 return false;
1578 }
1579
1580 if (std::strncmp(magic.data(), "glTF", 4) != 0)
1581 {
1582 return false;
1583 }
1584
1585 std::uint32_t version;
1586 std::uint32_t fileLength;
1587 std::vector<vtkGLTFUtils::ChunkInfoType> chunkInfo;
1588 if (!vtkGLTFUtils::ExtractGLBFileInformation(
1589 stream, version, fileLength, this->GLBStart, chunkInfo))
1590 {
1591 vtkErrorMacro("Invalid .glb file");
1592 return false;
1593 }
1594
1595 // Look for BIN chunk while updating fstream position
1596 stream->Seek(this->GLBStart + vtkGLTFUtils::GLBHeaderSize + vtkGLTFUtils::GLBChunkHeaderSize,
1597 vtkResourceStream::SeekDirection::Begin);
1598 for (auto& chunk : chunkInfo)
1599 {
1600 if (std::memcmp(chunk.first.data(), "BIN\0", 4) == 0)
1601 {
1602 // Read chunk data into output vector
1603 std::vector<char> binData;
1604 binData.resize(chunk.second);
1605 if (stream->Read(binData.data(), chunk.second) != chunk.second)
1606 {
1607 vtkErrorMacro("Failed to read BIN chunk from .glb file");
1608 return false;
1609 }
1610
1611 glbBuffer.insert(glbBuffer.end(), binData.begin(), binData.begin() + chunk.second);
1612
1613 return true;
1614 }
1615
1616 // Jump to next chunk
1617 stream->Seek(
1618 chunk.second + vtkGLTFUtils::GLBChunkHeaderSize, vtkResourceStream::SeekDirection::Current);
1619 }
1620
1621 vtkErrorMacro("Could not find any valid BIN chunks in file");
1622 return false;
1623}
1624
1625//------------------------------------------------------------------------------

Callers 3

LoadFileBufferMethod · 0.95
RequestDataMethod · 0.80
ImportBeginMethod · 0.80

Calls 9

SeekMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected