| 174 | } |
| 175 | |
| 176 | void Sampler::Load(Json::Value& node) |
| 177 | { |
| 178 | if (node["mode"].isString()) |
| 179 | { |
| 180 | std::string mode = node["mode"].asString(); |
| 181 | if (mode == "step") |
| 182 | SetInterpolationMode(InterpolationMode::Step); |
| 183 | else if (mode == "linear") |
| 184 | SetInterpolationMode(InterpolationMode::Linear); |
| 185 | if (mode == "spline") |
| 186 | SetInterpolationMode(InterpolationMode::CatmullRomSpline); |
| 187 | } |
| 188 | |
| 189 | bool warningPrinted = false; |
| 190 | Json::Value& valuesNode = node["values"]; |
| 191 | if (valuesNode.isArray()) |
| 192 | { |
| 193 | for (Json::Value& valueNode : valuesNode) |
| 194 | { |
| 195 | Keyframe keyframe; |
| 196 | keyframe.time = valueNode["time"].asFloat(); |
| 197 | if (valueNode.isNumeric()) |
| 198 | { |
| 199 | keyframe.value.x = valueNode.asFloat(); |
| 200 | } |
| 201 | else if (valueNode.isArray()) |
| 202 | { |
| 203 | if (valueNode.size() >= 1) keyframe.value.x = valueNode[0].asFloat(); // NOLINT(readability-container-size-empty) |
| 204 | if (valueNode.size() >= 2) keyframe.value.y = valueNode[1].asFloat(); |
| 205 | if (valueNode.size() >= 3) keyframe.value.z = valueNode[2].asFloat(); |
| 206 | if (valueNode.size() >= 4) keyframe.value.w = valueNode[3].asFloat(); |
| 207 | } |
| 208 | else if ((valueNode.isObject() || valueNode.isString()) && !warningPrinted) |
| 209 | { |
| 210 | log::warning("Objects and strings are not supported as animation keyframe values."); |
| 211 | warningPrinted = true; |
| 212 | continue; |
| 213 | } |
| 214 | |
| 215 | AddKeyframe(keyframe); |
| 216 | } |
| 217 | |
| 218 | std::sort(m_Keyframes.begin(), m_Keyframes.end(), |
| 219 | [](const Keyframe& a, const Keyframe& b) { return a.time < b.time; }); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | std::optional<dm::float4> Sequence::Evaluate(const std::string& name, float time, bool extrapolateLastValues) |
| 224 | { |