| 387 | } |
| 388 | |
| 389 | void Scene::LoadAnimations(const Json::Value& nodeList) |
| 390 | { |
| 391 | std::shared_ptr<SceneGraphNode> animationContainer; |
| 392 | |
| 393 | for (const auto& animationNode : nodeList) |
| 394 | { |
| 395 | const auto& animation = std::make_shared<SceneGraphAnimation>(); |
| 396 | |
| 397 | const auto& sceneAnimationNode = std::make_shared<SceneGraphNode>(); |
| 398 | sceneAnimationNode->SetLeaf(animation); |
| 399 | |
| 400 | const auto& nameNode = animationNode["name"]; |
| 401 | if (nameNode.isString()) |
| 402 | { |
| 403 | animation->SetName(nameNode.asString()); |
| 404 | } |
| 405 | |
| 406 | const auto& channelsNode = animationNode["channels"]; |
| 407 | if (channelsNode.isArray()) |
| 408 | { |
| 409 | int channelIndex = -1; |
| 410 | for (const auto& channelSrc : channelsNode) |
| 411 | { |
| 412 | // Increment the index in the beginning because there are 'continue' statements below |
| 413 | ++channelIndex; |
| 414 | |
| 415 | const auto& sampler = std::make_shared<animation::Sampler>(); |
| 416 | |
| 417 | const auto& modeNode = channelSrc["mode"]; |
| 418 | if (modeNode.isString()) |
| 419 | { |
| 420 | if (modeNode.asString() == "step") |
| 421 | sampler->SetInterpolationMode(animation::InterpolationMode::Step); |
| 422 | else if (modeNode.asString() == "linear") |
| 423 | sampler->SetInterpolationMode(animation::InterpolationMode::Linear); |
| 424 | else if (modeNode.asString() == "slerp") |
| 425 | sampler->SetInterpolationMode(animation::InterpolationMode::Slerp); |
| 426 | else if (modeNode.asString() == "hermite") |
| 427 | sampler->SetInterpolationMode(animation::InterpolationMode::HermiteSpline); |
| 428 | else if (modeNode.asString() == "catmull-rom") |
| 429 | sampler->SetInterpolationMode(animation::InterpolationMode::CatmullRomSpline); |
| 430 | else |
| 431 | log::warning("Unknown interpolation mode '%s' specified for animation '%s' channel %d. " |
| 432 | "Valid interpolation modes are: step, linear, hermite, catmull-rom.", |
| 433 | modeNode.asCString(), animation->GetName().c_str(), channelIndex); |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | sampler->SetInterpolationMode(animation::InterpolationMode::Step); |
| 438 | log::warning("Interpolation mode is not specified for animation '%s' channel %d, using step.", |
| 439 | animation->GetName().c_str(), channelIndex); |
| 440 | } |
| 441 | |
| 442 | const auto& attributeNode = channelSrc["attribute"]; |
| 443 | AnimationAttribute attribute = AnimationAttribute::Undefined; |
| 444 | if (attributeNode.isString() && !attributeNode.asString().empty()) |
| 445 | { |
| 446 | if (attributeNode.asString() == "translation") |
nothing calls this directly
no test coverage detected