------------------------------------------------------------------------------
| 1412 | |
| 1413 | //------------------------------------------------------------------------------ |
| 1414 | void vtkGLTFDocumentLoader::Animation::Sampler::GetInterpolatedData(float timeValue, |
| 1415 | size_t numberOfComponents, std::vector<float>* output, bool forceStep, bool isRotation) const |
| 1416 | { |
| 1417 | // Find the previous and following keyframes |
| 1418 | vtkIdType prevKeyFrameId = 0; |
| 1419 | |
| 1420 | vtkIdType nextKeyFrameId = |
| 1421 | std::upper_bound(this->InputData->Begin(), this->InputData->End(), timeValue) - |
| 1422 | this->InputData->Begin(); |
| 1423 | |
| 1424 | // If we didn't find the next keyframe, that means t is over the animation's duration. |
| 1425 | vtkIdType numberOfKeyFrames = this->InputData->GetNumberOfTuples(); |
| 1426 | if (nextKeyFrameId == numberOfKeyFrames) |
| 1427 | { |
| 1428 | nextKeyFrameId = numberOfKeyFrames - 1; |
| 1429 | prevKeyFrameId = nextKeyFrameId; |
| 1430 | timeValue = this->InputData->GetValue(nextKeyFrameId); |
| 1431 | } |
| 1432 | |
| 1433 | // Animation hasn't started yet. |
| 1434 | else if (nextKeyFrameId == 0) |
| 1435 | { |
| 1436 | prevKeyFrameId = 0; |
| 1437 | timeValue = this->InputData->GetValue(prevKeyFrameId); |
| 1438 | } |
| 1439 | else |
| 1440 | { |
| 1441 | prevKeyFrameId = nextKeyFrameId - 1; |
| 1442 | } |
| 1443 | |
| 1444 | // Check if we are on an exact time stamp |
| 1445 | const bool exact = this->InputData->GetValue(prevKeyFrameId) == timeValue; |
| 1446 | // linear or spline interpolation |
| 1447 | if (this->Interpolation != Animation::Sampler::InterpolationMode::STEP && !exact && !forceStep) |
| 1448 | { |
| 1449 | // Normalize t. Set to zero when at the first keyframe, and set to one when at the last keyframe |
| 1450 | float tNorm = 0; |
| 1451 | float tDelta = 0; |
| 1452 | if (prevKeyFrameId == 0 && nextKeyFrameId == 0) |
| 1453 | { |
| 1454 | tNorm = 0; |
| 1455 | } |
| 1456 | else if (prevKeyFrameId == numberOfKeyFrames - 1 && nextKeyFrameId == numberOfKeyFrames - 1) |
| 1457 | { |
| 1458 | tNorm = 1; |
| 1459 | } |
| 1460 | else |
| 1461 | { |
| 1462 | const float prevTime = this->InputData->GetValue(prevKeyFrameId); |
| 1463 | const float nextTime = this->InputData->GetValue(nextKeyFrameId); |
| 1464 | tDelta = nextTime - prevTime; |
| 1465 | tNorm = (timeValue - prevTime) / tDelta; |
| 1466 | } |
| 1467 | |
| 1468 | if (this->Interpolation == Animation::Sampler::InterpolationMode::LINEAR) |
| 1469 | { |
| 1470 | std::vector<float> prevTuple(numberOfComponents); |
| 1471 | std::vector<float> nextTuple(numberOfComponents); |
no test coverage detected