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

Method LoadBuffers

IO/Geometry/vtkGLTFDocumentLoaderInternals.cxx:64–111  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

62
63//------------------------------------------------------------------------------
64bool vtkGLTFDocumentLoaderInternals::LoadBuffers(bool firstBufferIsGLB)
65{
66 try
67 {
68 nlohmann::json bufferRoot =
69 nlohmann::json::parse(this->Self->GetInternalModel()->BufferMetaData);
70 // Load buffers from disk
71 unsigned int bufferIndex = 0;
72 for (const auto& glTFBuffer : bufferRoot)
73 {
74 std::vector<char> buffer;
75 if (this->LoadBuffer(glTFBuffer, buffer))
76 {
77 if (buffer.empty() && this->Self->GetInternalModel()->Buffers.empty() && !firstBufferIsGLB)
78 {
79 vtkErrorWithObjectMacro(this->Self,
80 "Invalid first buffer value for glb file. No buffer was loaded from the file.");
81 return false;
82 }
83 if (firstBufferIsGLB && bufferIndex == 0 && !buffer.empty())
84 {
85 vtkErrorWithObjectMacro(
86 this->Self, "Invalid first buffer value for glb file. buffer.uri should be undefined");
87 return false;
88 }
89
90 // skip if buffer has already been loaded from the GLB BIN chunk
91 if (!firstBufferIsGLB || bufferIndex > 0)
92 {
93 this->Self->GetInternalModel()->Buffers.emplace_back(std::move(buffer));
94 }
95 }
96 else
97 {
98 vtkErrorWithObjectMacro(this->Self, "Could not load Buffer from JSON.");
99 return false;
100 }
101 bufferIndex++;
102 }
103 }
104 catch (nlohmann::json::parse_error& e)
105 {
106 vtkErrorWithObjectMacro(this->Self, "Could not parse JSON: " << e.what());
107 return false;
108 }
109
110 return true;
111}
112
113//------------------------------------------------------------------------------
114bool vtkGLTFDocumentLoaderInternals::LoadFileMetaData(nlohmann::json& gltfRoot)

Callers 1

LoadModelDataMethod · 0.80

Calls 6

LoadBufferMethod · 0.95
GetInternalModelMethod · 0.80
parseFunction · 0.50
emptyMethod · 0.45
emplace_backMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected