AMFP Enhanced
C++ reference: the code this unofficial fork added
Loading...
Searching...
No Matches
FbxAnimTimes.h
Go to the documentation of this file.
1/*
2 * AMFP-2026: FBX animation key times as the original Autodesk FBX SDK loader saw them.
3 * The SDK loader read every key time as whole milliseconds (KTime::GetMilliSeconds truncates),
4 * merged the translation / rotation / scale keys of a bone into one sorted set and sampled
5 * the bone at each of those times. The ufbx loader (MeshLoaderFBX.cpp) does the same so its
6 * output matches the .anm files the original loader cached. Pure, unit tested in
7 * tests/cpp/test_fbx_anim_times.cpp.
8 */
9#ifndef HPL_FBX_ANIM_TIMES_H
10#define HPL_FBX_ANIM_TIMES_H
11
12#include <cmath>
13#include <set>
14
15namespace hpl {
16
17/** Seconds -> whole milliseconds, truncated like KTime::GetMilliSeconds. A tiny tolerance keeps
18 * times stored as 0.99999999 s on 999 ms's right side (1000). */
19inline long long FbxTimeToMs(double afSeconds)
20{
21 return (long long)std::floor(afSeconds * 1000.0 + 1e-6);
22}
23
24/** The time the SDK loader stored for a key: its whole milliseconds, in seconds. */
25inline float FbxKeyTime(double afSeconds)
26{
27 return (float)FbxTimeToMs(afSeconds) / 1000.0f;
28}
29
30/** Adds key times (seconds) to the bone's sorted set of sample times. */
31template<class tIt>
32inline void FbxAddKeyTimes(std::set<float>& aTimes, tIt aBegin, tIt aEnd)
33{
34 for(tIt it = aBegin; it != aEnd; ++it) aTimes.insert(FbxKeyTime(*it));
35}
36
37/** Length the SDK loader gave an animation: the take's end in whole milliseconds, in seconds. */
38inline float FbxAnimLength(double afEndSeconds)
39{
40 return (float)FbxTimeToMs(afEndSeconds) / 1000.0f;
41}
42
43/** The SDK loader used the first take whose span is at least one millisecond. */
44inline bool FbxTakeHasLength(double afBeginSeconds, double afEndSeconds)
45{
46 return FbxTimeToMs(afEndSeconds) - FbxTimeToMs(afBeginSeconds) > 0;
47}
48
49}
50
51#endif
void FbxAddKeyTimes(std::set< float > &aTimes, tIt aBegin, tIt aEnd)
Adds key times (seconds) to the bone's sorted set of sample times.
long long FbxTimeToMs(double afSeconds)
Seconds -> whole milliseconds, truncated like KTime::GetMilliSeconds.
bool FbxTakeHasLength(double afBeginSeconds, double afEndSeconds)
The SDK loader used the first take whose span is at least one millisecond.
float FbxKeyTime(double afSeconds)
The time the SDK loader stored for a key: its whole milliseconds, in seconds.
float FbxAnimLength(double afEndSeconds)
Length the SDK loader gave an animation: the take's end in whole milliseconds, in seconds.