------------------------------------------------------------------------------
| 338 | |
| 339 | //------------------------------------------------------------------------------ |
| 340 | bool vtkGLTFDocumentLoaderInternals::LoadAnimation( |
| 341 | const nlohmann::json& root, vtkGLTFDocumentLoader::Animation& animation) |
| 342 | { |
| 343 | if (root.empty() || !root.is_object()) |
| 344 | { |
| 345 | vtkErrorWithObjectMacro(this->Self, "Invalid animation value"); |
| 346 | return false; |
| 347 | } |
| 348 | |
| 349 | animation.Name = ""; |
| 350 | vtkGLTFUtils::GetStringValue(root, "name", animation.Name); |
| 351 | auto rootChannelsIt = root.find("channels"); |
| 352 | auto rootSamplersIt = root.find("samplers"); |
| 353 | if ((rootChannelsIt != root.end() && !rootChannelsIt.value().is_array()) || |
| 354 | (rootSamplersIt != root.end() && !rootSamplersIt.value().is_array())) |
| 355 | { |
| 356 | vtkErrorWithObjectMacro(this->Self, |
| 357 | "Invalid animation.channels and animation.samplers for animation " << animation.Name); |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | // Load channel metadata |
| 362 | for (const auto& channelRoot : rootChannelsIt.value()) |
| 363 | { |
| 364 | vtkGLTFDocumentLoader::Animation::Channel channel; |
| 365 | if (!vtkGLTFUtils::GetIntValue(channelRoot, "sampler", channel.Sampler)) |
| 366 | { |
| 367 | vtkErrorWithObjectMacro( |
| 368 | this->Self, "Invalid animation.channel.sampler value for animation " << animation.Name); |
| 369 | return false; |
| 370 | } |
| 371 | channel.TargetNode = -1; |
| 372 | const auto& target = channelRoot.value("target", nlohmann::json::object()); |
| 373 | vtkGLTFUtils::GetIntValue(target, "node", channel.TargetNode); |
| 374 | |
| 375 | std::string targetPathString; |
| 376 | if (!vtkGLTFUtils::GetStringValue(target, "path", targetPathString)) |
| 377 | { |
| 378 | vtkErrorWithObjectMacro( |
| 379 | this->Self, "Invalid animation.channel.target.path value for animation " << animation.Name); |
| 380 | return false; |
| 381 | } |
| 382 | if (targetPathString == "translation") |
| 383 | { |
| 384 | channel.TargetPath = vtkGLTFDocumentLoader::Animation::Channel::PathType::TRANSLATION; |
| 385 | } |
| 386 | else if (targetPathString == "rotation") |
| 387 | { |
| 388 | channel.TargetPath = vtkGLTFDocumentLoader::Animation::Channel::PathType::ROTATION; |
| 389 | } |
| 390 | else if (targetPathString == "scale") |
| 391 | { |
| 392 | channel.TargetPath = vtkGLTFDocumentLoader::Animation::Channel::PathType::SCALE; |
| 393 | } |
| 394 | else if (targetPathString == "weights") |
| 395 | { |
| 396 | channel.TargetPath = vtkGLTFDocumentLoader::Animation::Channel::PathType::WEIGHTS; |
| 397 | } |
no test coverage detected