vtk object building and animation operations **/ ------------------------------------------------------------------------------
| 1057 | /** vtk object building and animation operations **/ |
| 1058 | //------------------------------------------------------------------------------ |
| 1059 | bool vtkGLTFDocumentLoader::ApplyAnimation(float t, int animationId, bool forceStep) |
| 1060 | { |
| 1061 | const Animation& animation = this->InternalModel->Animations[animationId]; |
| 1062 | for (const Animation::Channel& channel : animation.Channels) |
| 1063 | { |
| 1064 | if (channel.TargetNode >= static_cast<int>(this->InternalModel->Nodes.size())) |
| 1065 | { |
| 1066 | vtkErrorMacro("Invalid target node"); |
| 1067 | return false; |
| 1068 | } |
| 1069 | |
| 1070 | Node& node = this->InternalModel->Nodes[channel.TargetNode]; |
| 1071 | const Animation::Sampler& sampler = animation.Samplers[channel.Sampler]; |
| 1072 | |
| 1073 | std::vector<float>* target; |
| 1074 | |
| 1075 | size_t numberOfComponents = 0; |
| 1076 | switch (channel.TargetPath) |
| 1077 | { |
| 1078 | case Animation::Channel::PathType::ROTATION: |
| 1079 | numberOfComponents = |
| 1080 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType(AccessorType::VEC4); |
| 1081 | target = &(node.Rotation); |
| 1082 | break; |
| 1083 | case Animation::Channel::PathType::TRANSLATION: |
| 1084 | numberOfComponents = |
| 1085 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType(AccessorType::VEC3); |
| 1086 | target = &(node.Translation); |
| 1087 | break; |
| 1088 | case Animation::Channel::PathType::SCALE: |
| 1089 | numberOfComponents = |
| 1090 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType(AccessorType::VEC3); |
| 1091 | target = &(node.Scale); |
| 1092 | break; |
| 1093 | case Animation::Channel::PathType::WEIGHTS: |
| 1094 | numberOfComponents = node.InitialWeights.size(); |
| 1095 | if (numberOfComponents == 0) |
| 1096 | { |
| 1097 | int nbMeshes = static_cast<int>(this->InternalModel->Meshes.size()); |
| 1098 | if (node.Mesh < 0 || node.Mesh > nbMeshes) |
| 1099 | { |
| 1100 | vtkErrorMacro("Invalid node.mesh value."); |
| 1101 | return false; |
| 1102 | } |
| 1103 | numberOfComponents = this->InternalModel->Meshes[node.Mesh].Weights.size(); |
| 1104 | } |
| 1105 | target = &(node.Weights); |
| 1106 | break; |
| 1107 | default: |
| 1108 | vtkErrorMacro( |
| 1109 | "Invalid animation.channel.target.path value for animation " << animation.Name); |
| 1110 | return false; |
| 1111 | } |
| 1112 | target->clear(); |
| 1113 | target->reserve(numberOfComponents); |
| 1114 | sampler.GetInterpolatedData(t, numberOfComponents, target, forceStep, |
| 1115 | channel.TargetPath == Animation::Channel::PathType::ROTATION); |
| 1116 | node.UpdateTransform(); |
no test coverage detected