------------------------------------------------------------------------------
| 16 | |
| 17 | //------------------------------------------------------------------------------ |
| 18 | VTK_ABI_NAMESPACE_BEGIN |
| 19 | bool vtkGLTFDocumentLoaderInternals::LoadBuffer( |
| 20 | const nlohmann::json& root, std::vector<char>& buffer) |
| 21 | { |
| 22 | if (root.empty() || !root.is_object()) |
| 23 | { |
| 24 | vtkErrorWithObjectMacro(this->Self, "Invalid buffer value"); |
| 25 | return false; |
| 26 | } |
| 27 | |
| 28 | auto rootUriIt = root.find("uri"); |
| 29 | if (rootUriIt == root.end()) |
| 30 | { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | if (!this->Self->GetInternalModel()->URILoader) |
| 35 | { |
| 36 | vtkErrorWithObjectMacro(this->Self, "Trying to load data using URI without an URI loader"); |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | int byteLength = 0; |
| 41 | if (!vtkGLTFUtils::GetIntValue(root, "byteLength", byteLength)) |
| 42 | { |
| 43 | std::string name; |
| 44 | vtkGLTFUtils::GetStringValue(root, "name", name); |
| 45 | vtkErrorWithObjectMacro(this->Self, "Invalid buffer.byteLength value for buffer " << name); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // Load buffer data |
| 50 | std::string uri = rootUriIt.value(); |
| 51 | if (!vtkGLTFUtils::GetBinaryBufferFromUri( |
| 52 | uri, this->Self->GetInternalModel()->URILoader, buffer, byteLength)) |
| 53 | { |
| 54 | std::string name; |
| 55 | vtkGLTFUtils::GetStringValue(root, "name", name); |
| 56 | vtkErrorWithObjectMacro(this->Self, "Invalid buffer.uri value for buffer " << name); |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | //------------------------------------------------------------------------------ |
| 64 | bool vtkGLTFDocumentLoaderInternals::LoadBuffers(bool firstBufferIsGLB) |
no test coverage detected