Kemena3D
Loading...
Searching...
No Matches
kbone.h
Go to the documentation of this file.
1
5
6#ifndef KBONE_H
7#define KBONE_H
8
9#include <string>
10#include <stdexcept>
11#include <iostream>
12
13#include "kdatatype.h"
14
15// Forward-declared so this header stays Assimp-free; the bone constructor
16// takes an aiNodeAnim* only as an importer detail and the type is fully
17// defined inside kbone.cpp where Assimp is included. Slim runtime builds
18// (KEMENA_NO_ASSIMP) drop this entry point — animations in that build are
19// populated by the tinygltf importer.
20#ifndef KEMENA_NO_ASSIMP
21struct aiNodeAnim;
22#endif
23
24namespace kemena
25{
34 class kBone
35 {
36 public:
37#ifndef KEMENA_NO_ASSIMP
44 kBone(const kString &boneName, int boneID, aiNodeAnim *channel);
45#endif
46
53 kBone(const kString &boneName, int boneID,
54 std::vector<kKeyPosition> positions,
55 std::vector<kKeyRotation> rotations,
56 std::vector<kKeyScale> scales);
57
62 void update(float animationTime);
63
68 const kMat4 getLocalTransform() const;
69
74 const kString getName() const;
75
80 const int getID() const;
81
87 int getPositionIndex(float animationTime);
88
94 int getRotationIndex(float animationTime);
95
101 int getScaleIndex(float animationTime);
102
103 protected:
104 private:
105 std::vector<kKeyPosition> positions;
106 std::vector<kKeyRotation> rotations;
107 std::vector<kKeyScale> scales;
108
109 int positionCount;
110 int rotationCount;
111 int scaleCount;
112
113 kMat4 localTransform = kMat4(1.0f);
114 kString name;
115 int id;
116
125 float getScaleFactor(float lastTimeStamp, float nextTimeStamp, float animationTime, float duration);
126
132 kMat4 interpolatePosition(float animationTime);
133
139 kMat4 interpolateRotation(float animationTime);
140
146 kMat4 interpolateScale(float animationTime);
147 };
148}
149
150#endif // KBONE_H
int getRotationIndex(float animationTime)
Finds the index of the rotation keyframe just before animationTime.
const int getID() const
Returns the bone palette index.
int getScaleIndex(float animationTime)
Finds the index of the scale keyframe just before animationTime.
const kMat4 getLocalTransform() const
Returns the interpolated local transform for the current time.
int getPositionIndex(float animationTime)
Finds the index of the position keyframe just before animationTime.
kBone(const kString &boneName, int boneID, std::vector< kKeyPosition > positions, std::vector< kKeyRotation > rotations, std::vector< kKeyScale > scales)
Constructs a bone from already-decoded keyframe arrays.
void update(float animationTime)
Interpolates all channels and updates the local transform.
const kString getName() const
Returns the bone name.
kBone(const kString &boneName, int boneID, aiNodeAnim *channel)
Constructs a bone from an Assimp animation channel.
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
std::string kString
Standard string alias.
Definition kdatatype.h:42
glm::mat4 kMat4
4x4 float matrix.
Definition kdatatype.h:39