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

Method LoadAnimation

IO/Geometry/vtkGLTFDocumentLoaderInternals.cxx:340–467  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

338
339//------------------------------------------------------------------------------
340bool 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 }

Callers 1

LoadModelMetaDataMethod · 0.95

Calls 12

objectClass · 0.85
arrayClass · 0.85
GetInternalModelMethod · 0.80
GetStringValueFunction · 0.70
GetIntValueFunction · 0.70
GetUIntValueFunction · 0.70
emptyMethod · 0.45
findMethod · 0.45
endMethod · 0.45
valueMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected