------------------------------------------------------------------------------
| 62 | |
| 63 | //------------------------------------------------------------------------------ |
| 64 | bool 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 | //------------------------------------------------------------------------------ |
| 114 | bool vtkGLTFDocumentLoaderInternals::LoadFileMetaData(nlohmann::json& gltfRoot) |
no test coverage detected