99
1010namespace BIN {
1111
12- struct AnimInfo {
13- bool mLoop { 0 };
14- bool mPlaying { false };
15- bool mLoaded { false };
16- float mCurrentFrame { 0 .0f }; // float so that we can change speed more easily
17- float mPlaybackSpeed { 0 .5f };
18- uint32_t mFrameCount { 0 };
19- };
20-
2112 #pragma pack(push, 1)
2213 struct Header {
2314 uint8_t Version { 0x02 };
@@ -192,12 +183,13 @@ namespace BIN {
192183 void InitShaders ();
193184 void DestroyShaders ();
194185
186+ class Animation ;
187+
195188 class Model
196189 {
197190 public:
198191 Header mHeader ;
199192
200- AnimInfo mAnim ;
201193
202194 std::map<uint16_t , TextureHeader> mTextureHeaders ;
203195
@@ -206,22 +198,18 @@ namespace BIN {
206198
207199 std::map<uint16_t , Material> mMaterials ;
208200 std::map<uint16_t , SceneGraphNode> mGraphNodes ;
209- std::map<uint16_t , GraphNodeTrack> mAnimationTracks ;
210201
211202 std::vector<glm::vec3> mPositions ;
212203 std::vector<glm::vec3> mNormals ;
213204 std::vector<glm::vec2> mTexCoords ;
214205 std::vector<glm::vec4> mColors ;
215206
216207 void ReadSceneGraphNode (bStream::CStream* stream, uint32_t index);
217- void DrawScenegraphNode (uint32_t idx, glm::mat4 transform);
208+ void DrawScenegraphNode (uint32_t idx, glm::mat4 transform, Animation* animation );
218209
219210 glm::vec3 bbMax {0 , 0 , 0 }, bbMin {0 , 0 , 0 };
220211
221- void LoadAnimation (bStream::CStream* stream);
222- void ClearAnimation ();
223-
224- void Draw (glm::mat4* transform, int32_t id, bool selected);
212+ void Draw (glm::mat4* transform, int32_t id, bool selected, Animation* animation = nullptr );
225213
226214 void Load (bStream::CStream* stream);
227215 void Write (bStream::CStream* stream);
@@ -233,4 +221,29 @@ namespace BIN {
233221 ~Model ();
234222 };
235223
224+ class Animation
225+ {
226+ bool mLoop { 0 };
227+ bool mPlaying { false };
228+ bool mLoaded { false };
229+ float mTime { 0 .0f }; // float so that we can change speed more easily
230+ uint32_t mFrameCount { 0 };
231+
232+ std::map<uint16_t , GraphNodeTrack> mAnimationTracks ;
233+
234+ public:
235+ bool Playing () { return mPlaying ; }
236+ void ResetTracks ();
237+ void Play ();
238+ void Stop ();
239+
240+ glm::mat4 GetNodeFrame (uint16_t node);
241+ void Step (float dt) { mTime += dt * 10 ; if (mTime >= mFrameCount && mLoop ) { mTime = 0 .0f ; ResetTracks (); } else if (mTime >= mFrameCount ) { mPlaying = false ; } }
242+
243+ void Load (Model* model, bStream::CStream* stream);
244+
245+ Animation (){}
246+ ~Animation (){}
247+ };
248+
236249}
0 commit comments