| 155 | } |
| 156 | |
| 157 | void AssetLoader::LoadAnimationCurvesToPlayer(AnimationPlayer* pPlayer, const std::string& packPath, const std::string& filePath) |
| 158 | { |
| 159 | std::string pachDir = packPath.back() != '/' ? packPath + '/' : packPath; |
| 160 | const std::string fullPath = pachDir + filePath; |
| 161 | std::ifstream animationFile(fullPath); |
| 162 | if (!animationFile.is_open()) |
| 163 | { |
| 164 | LOG_ERROR("Failed to load animation curves: %s", fullPath.c_str()); |
| 165 | return; |
| 166 | } |
| 167 | nlohmann::json animationDesc = nlohmann::json::parse(animationFile); |
| 168 | |
| 169 | std::vector<KeyFrame<float>> floatKeyFrames; |
| 170 | std::vector<KeyFrame<simd::float3>> float3KeyFrames; |
| 171 | std::vector<KeyFrame<simd::float4>> float4KeyFrames; |
| 172 | for (const auto& curveDesc : animationDesc) |
| 173 | { |
| 174 | const std::string& target = curveDesc["target"].get<std::string>(); |
| 175 | const std::string& type = curveDesc["type"].get<std::string>(); |
| 176 | const nlohmann::json& keyFrames = curveDesc["keyframes"]; |
| 177 | const nlohmann::json& times = keyFrames["times"]; |
| 178 | const nlohmann::json& values = keyFrames["values"]; |
| 179 | const nlohmann::json& inTangents = keyFrames["inTangents"]; |
| 180 | const nlohmann::json& outTangents = keyFrames["outTangents"]; |
| 181 | uint32_t numFrames = (uint32_t)times.size(); |
| 182 | if (type == "local_rotation") |
| 183 | { |
| 184 | AnimationCurve<simd::float4> float4Curve; |
| 185 | float4Curve.SetTarget(target); |
| 186 | float4Curve.SetAttributeType(AttributeType::Rotation); |
| 187 | |
| 188 | float4KeyFrames.resize(numFrames); |
| 189 | for (uint32_t i = 0; i < numFrames; ++i) |
| 190 | { |
| 191 | float4KeyFrames[i].time = times[i].get<float>(); |
| 192 | float4KeyFrames[i].value = TryParseFloat4(values[i]); |
| 193 | float4KeyFrames[i].inTangent = TryParseFloat4(inTangents[i]); |
| 194 | float4KeyFrames[i].outTangent = TryParseFloat4(outTangents[i]); |
| 195 | } |
| 196 | |
| 197 | float4Curve.SetKeyFrames(float4KeyFrames); |
| 198 | pPlayer->AddAnimationCurve(std::move(float4Curve)); |
| 199 | } |
| 200 | else if (type == "local_position") |
| 201 | { |
| 202 | AnimationCurve<simd::float3> float3Curve; |
| 203 | float3Curve.SetTarget(target); |
| 204 | float3Curve.SetAttributeType(AttributeType::Position); |
| 205 | |
| 206 | float3KeyFrames.resize(numFrames); |
| 207 | for (uint32_t i = 0; i < numFrames; ++i) |
| 208 | { |
| 209 | float3KeyFrames[i].time = times[i].get<float>(); |
| 210 | float3KeyFrames[i].value = TryParseFloat3(values[i]); |
| 211 | float3KeyFrames[i].inTangent = TryParseFloat3(inTangents[i]); |
| 212 | float3KeyFrames[i].outTangent = TryParseFloat3(outTangents[i]); |
| 213 | } |
| 214 |
nothing calls this directly
no test coverage detected