------------------------------------------------------------------------------
| 1177 | |
| 1178 | //------------------------------------------------------------------------------ |
| 1179 | bool vtkGLTFDocumentLoaderInternals::LoadSparse( |
| 1180 | const nlohmann::json& root, vtkGLTFDocumentLoader::Accessor::Sparse& sparse) |
| 1181 | { |
| 1182 | if (root.empty() || !root.is_object()) |
| 1183 | { |
| 1184 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse object"); |
| 1185 | return false; |
| 1186 | } |
| 1187 | if (!vtkGLTFUtils::GetIntValue(root, "count", sparse.Count)) |
| 1188 | { |
| 1189 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.count value"); |
| 1190 | return false; |
| 1191 | } |
| 1192 | const nlohmann::json& indices = root.value("indices", nlohmann::json::object()); |
| 1193 | const nlohmann::json& values = root.value("values", nlohmann::json::object()); |
| 1194 | if (indices.empty() || values.empty() || !indices.is_object() || !values.is_object()) |
| 1195 | { |
| 1196 | vtkErrorWithObjectMacro( |
| 1197 | this->Self, "Invalid accessor.sparse.indices or accessor.sparse.values value"); |
| 1198 | return false; |
| 1199 | } |
| 1200 | if (!vtkGLTFUtils::GetIntValue(indices, "bufferView", sparse.IndicesBufferView)) |
| 1201 | { |
| 1202 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.indices.bufferView value"); |
| 1203 | return false; |
| 1204 | } |
| 1205 | if (!vtkGLTFUtils::GetIntValue(indices, "byteOffset", sparse.IndicesByteOffset)) |
| 1206 | { |
| 1207 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.indices.byteOffset value"); |
| 1208 | return false; |
| 1209 | } |
| 1210 | int intIndicesComponentTypes = 0; |
| 1211 | if (!vtkGLTFUtils::GetIntValue(indices, "componentType", intIndicesComponentTypes)) |
| 1212 | { |
| 1213 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.indices.componentType value"); |
| 1214 | return false; |
| 1215 | } |
| 1216 | if (intIndicesComponentTypes < static_cast<int>(vtkGLTFDocumentLoader::ComponentType::BYTE) || |
| 1217 | intIndicesComponentTypes > static_cast<int>(vtkGLTFDocumentLoader::ComponentType::FLOAT)) |
| 1218 | { |
| 1219 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.componentType value"); |
| 1220 | return false; |
| 1221 | } |
| 1222 | sparse.IndicesComponentType = |
| 1223 | static_cast<vtkGLTFDocumentLoader::ComponentType>(intIndicesComponentTypes); |
| 1224 | if (!vtkGLTFUtils::GetIntValue(values, "bufferView", sparse.ValuesBufferView)) |
| 1225 | { |
| 1226 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.values.bufferView value"); |
| 1227 | return false; |
| 1228 | } |
| 1229 | if (!vtkGLTFUtils::GetIntValue(values, "byteOffset", sparse.ValuesByteOffset)) |
| 1230 | { |
| 1231 | vtkErrorWithObjectMacro(this->Self, "Invalid accessor.sparse.values.byteOffset value"); |
| 1232 | return false; |
| 1233 | } |
| 1234 | return true; |
| 1235 | } |
| 1236 |
no test coverage detected