| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "imodule.h" |
| 4 |
|
| 5 |
#include <vector> |
| 6 |
#include "math/Vector3.h" |
| 7 |
#include "math/Quaternion.h" |
| 8 |
|
| 9 |
namespace md5 |
| 10 |
{ |
| 11 |
|
| 12 |
struct Joint |
| 13 |
{ |
| 14 |
// The ID of this joint |
| 15 |
int id; |
| 16 |
|
| 17 |
// the name of this bone |
| 18 |
std::string name; |
| 19 |
|
| 20 |
// ID of parent bone (-1 == no parent) |
| 21 |
int parentId; |
| 22 |
|
| 23 |
// The 6 possible components that might be modified by a key |
| 24 |
enum AnimComponent |
| 25 |
{ |
| 26 |
X = 1 << 0, |
| 27 |
Y = 1 << 1, |
| 28 |
Z = 1 << 2, |
| 29 |
YAW = 1 << 3, |
| 30 |
PITCH = 1 << 4, |
| 31 |
ROLL = 1 << 5, |
| 32 |
INVALID_COMPONENT = 1 << 6 |
| 33 |
}; |
| 34 |
|
| 35 |
// A bit mask explaining which components we're animating |
| 36 |
std::size_t animComponents; |
| 37 |
|
| 38 |
std::size_t firstKey; |
| 39 |
|
| 40 |
// The child joint IDs |
| 41 |
std::vector<int> children; |
| 42 |
}; |
| 43 |
|
| 44 |
/** |
| 45 |
* Base class for an MD5 animation as used in Doom 3. |
| 46 |
*/ |
| 47 |
class IMD5Anim |
| 48 |
{ |
| 49 |
public: |
| 50 |
// Information used by the base frame |
| 51 |
struct Key |
| 52 |
{ |
| 53 |
Vector3 origin; |
| 54 |
Quaternion orientation; |
| 55 |
}; |
| 56 |
|
| 57 |
// Each frame has a series of float values, applied to one or more animated components (x, y, z, yaw, pitch, roll) |
| 58 |
typedef std::vector<float> FrameKeys; |
| 59 |
|
| 60 |
/** |
| 61 |
* Get the number of joints in this animation. |
| 62 |
*/ |
| 63 |
virtual std::size_t getNumJoints() const = 0; |
| 64 |
|
| 65 |
/** |
| 66 |
* Retrieve a certain joint by index, bounds are [0..getNumJoints()) |
| 67 |
*/ |
| 68 |
virtual const Joint& getJoint(std::size_t index) const = 0; |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns the baseframe info for the given joint number. |
| 72 |
*/ |
| 73 |
virtual const Key& getBaseFrameKey(std::size_t jointNum) const = 0; |
| 74 |
|
| 75 |
/** |
| 76 |
* Returns the frame rate this anim should be played. |
| 77 |
*/ |
| 78 |
virtual int getFrameRate() const = 0; |
| 79 |
|
| 80 |
/** |
| 81 |
* Returns the number of frames in this animation. |
| 82 |
*/ |
| 83 |
virtual std::size_t getNumFrames() const = 0; |
| 84 |
|
| 85 |
/** |
| 86 |
* Returns the float values of the given frame index. |
| 87 |
*/ |
| 88 |
virtual const FrameKeys& getFrameKeys(std::size_t index) const = 0; |
| 89 |
}; |
| 90 |
typedef std::shared_ptr<IMD5Anim> IMD5AnimPtr; |
| 91 |
|
| 92 |
class IAnimationCache : |
| 93 |
public RegisterableModule |
| 94 |
{ |
| 95 |
public: |
| 96 |
/** |
| 97 |
* Returns the MD5 animation for the given VFS path, or NULL if |
| 98 |
* the file does not exist or the anim was found to be invalid. |
| 99 |
*/ |
| 100 |
virtual IMD5AnimPtr getAnim(const std::string& vfsPath) = 0; |
| 101 |
}; |
| 102 |
|
| 103 |
const char* const MODULE_ANIMATIONCACHE("MD5AnimationCache"); |
| 104 |
|
| 105 |
} // namespace |
| 106 |
|
| 107 |
inline md5::IAnimationCache& GlobalAnimationCache() |
| 108 |
{ |
| 109 |
static module::InstanceReference<md5::IAnimationCache> _reference(md5::MODULE_ANIMATIONCACHE); |
| 110 |
return _reference; |
| 111 |
} |