Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 251 vs 253 for /trunk/Source Code/Geometry/Animations/AnimationController.cpp

Diff revisions: vs.
  @@ -1,10 +1,12 @@
1 1 #include "Headers/AnimationController.h"
2 2 #include "Hardware/Video/Headers/GFXDevice.h"
3 3 #include "Headers/AnimationUtils.h"
4 +
5 + #include <assimp/scene.h>
6 +
4 7 using namespace boost;
5 8
6 9 void SceneAnimator::Release(){// this should clean everything up
7 - _currentAnimIndex = -1;
8 10 FOR_EACH(pointCollection::value_type& it, _pointsA){
9 11 FOR_EACH(pointMap::value_type& it2, it.second){
10 12 it2.second.clear();
  @@ -35,8 +37,8 @@
35 37 SAFE_DELETE(_skeleton);
36 38 }
37 39
38 - void SceneAnimator::Init(const aiScene* pScene, U8 meshPointer){// this will build the skeleton based on the scene passed to it and CLEAR EVERYTHING
39 - if(!pScene->HasAnimations()) return;
40 + bool SceneAnimator::Init(const aiScene* pScene, U8 meshPointer){// this will build the skeleton based on the scene passed to it and CLEAR EVERYTHING
41 + if(!pScene->HasAnimations()) return false;
40 42 Release();
41 43
42 44 _skeleton = CreateBoneTree( pScene->mRootNode, nullptr);
  @@ -70,11 +72,10 @@
70 72 mat4<F32> rotationmat;
71 73 vectorImpl<mat4<F32> > vec;
72 74 for(size_t i(0); i< _animations.size(); i++){// pre calculate the animations
73 - SetAnimIndex((I32)i);
74 75 D32 dt = 0;
75 76 for(D32 ticks = 0; ticks < _animations[i]._duration; ticks += _animations[i]._ticksPerSecond/ANIMATION_TICKS_PER_SECOND){
76 77 dt +=timestep;
77 - Calculate(dt);
78 + Calculate((I32)i, dt);
78 79 _animations[i]._transforms.push_back(vec);
79 80 vectorImpl<mat4<F32> >& trans = _animations[i]._transforms.back();
80 81 if(GFX_DEVICE.getApi() == Direct3D){
  @@ -92,6 +93,7 @@
92 93 }
93 94
94 95 D_PRINT_FN(Locale::get("LOAD_ANIMATIONS_END"), _bones.size());
96 + return !_transforms.empty();
95 97 }
96 98
97 99 void SceneAnimator::ExtractAnimations(const aiScene* pScene){
  @@ -106,35 +108,13 @@
106 108 FOR_EACH(AnimEvaluator& animation, _animations){
107 109 _animationNameToId.insert(Unordered_map<std::string, U32>::value_type(animation._name, i++));
108 110 }
109 - _currentAnimIndex=0;
110 - SetAnimation("Idle");
111 - }
112 -
113 - bool SceneAnimator::SetAnimation(const std::string& name){
114 - Unordered_map<std::string, U32>::iterator itr = _animationNameToId.find(name);
115 - I32 oldindex = _currentAnimIndex;
116 - if(itr !=_animationNameToId.end()) _currentAnimIndex = itr->second;
117 - return oldindex != _currentAnimIndex;
118 - }
119 -
120 - bool SceneAnimator::SetAnimIndex( I32 pAnimIndex){
121 - if(pAnimIndex >= (I32)_animations.size()) return false;// no change, or the animations data is out of bounds
122 - I32 oldindex = _currentAnimIndex;
123 - _currentAnimIndex = pAnimIndex;// only set this after the checks for good data and the object was actually inserted
124 - return oldindex != _currentAnimIndex;
125 - }
126 -
127 - bool SceneAnimator::SetNextAnimation() {
128 - I32 oldindex = _currentAnimIndex;
129 - _currentAnimIndex = ++_currentAnimIndex % _animations.size();
130 - return oldindex != _currentAnimIndex;
131 111 }
132 112
133 113 // ------------------------------------------------------------------------------------------------
134 114 // Calculates the node transformations for the scene.
135 - void SceneAnimator::Calculate(const D32 pTime){
136 - if( (_currentAnimIndex < 0) || (_currentAnimIndex >= (I32)_animations.size()) ) return;// invalid animation
137 - _animations[_currentAnimIndex].Evaluate( pTime, _bonesByName);
115 + void SceneAnimator::Calculate(I32 animationIndex, const D32 pTime){
116 + if ((animationIndex < 0) || (animationIndex >= (I32)_animations.size())) return;// invalid animation
117 + _animations[animationIndex].Evaluate(pTime, _bonesByName);
138 118 UpdateTransforms(_skeleton);
139 119 }
140 120
  @@ -206,35 +186,35 @@
206 186 }
207 187
208 188 ///Renders the current skeleton pose at time index dt
209 - I32 SceneAnimator::RenderSkeleton(const D32 dt){
210 - U32 frameIndex = _animations[_currentAnimIndex].GetFrameIndexAt(dt);
189 + I32 SceneAnimator::RenderSkeleton(I32 animationIndex, const D32 dt){
190 + U32 frameIndex = _animations[animationIndex].GetFrameIndexAt(dt);
211 191
212 - if(_pointsA.find(_currentAnimIndex) == _pointsA.end()){
192 + if (_pointsA.find(animationIndex) == _pointsA.end()){
213 193 pointMap pointsA;
214 194 pointMap pointsB;
215 195 colorMap colors;
216 - _pointsA.insert(std::make_pair(_currentAnimIndex, pointsA));
217 - _pointsB.insert(std::make_pair(_currentAnimIndex, pointsB));
218 - _colors.insert(std::make_pair(_currentAnimIndex, colors));
196 + _pointsA.insert(std::make_pair(animationIndex, pointsA));
197 + _pointsB.insert(std::make_pair(animationIndex, pointsB));
198 + _colors.insert(std::make_pair(animationIndex, colors));
219 199 }
220 200
221 - if(_pointsA[_currentAnimIndex][frameIndex].empty()){
201 + if (_pointsA[animationIndex][frameIndex].empty()){
222 202 // create all the needed points
223 - vectorImpl<vec3<F32> >& pA = _pointsA[_currentAnimIndex][frameIndex];
224 - vectorImpl<vec3<F32> >& pB = _pointsB[_currentAnimIndex][frameIndex];
225 - vectorImpl<vec4<U8> >& cl = _colors[_currentAnimIndex][frameIndex];
203 + vectorImpl<vec3<F32> >& pA = _pointsA[animationIndex][frameIndex];
204 + vectorImpl<vec3<F32> >& pB = _pointsB[animationIndex][frameIndex];
205 + vectorImpl<vec4<U8> >& cl = _colors[animationIndex][frameIndex];
226 206 pA.reserve(_bones.size());
227 207 pB.reserve(_bones.size());
228 208 cl.reserve(_bones.size());
229 209 // Construct skeleton
230 - Calculate(dt);
210 + Calculate(animationIndex, dt);
231 211 // Prepare global transform
232 212 aiMatrix4x4 rootTransform;
233 213 AnimUtils::TransformMatrix(rootTransform,_rootTransformRender);
234 214 CreateSkeleton(_skeleton, rootTransform, pA, pB, cl);
235 215 }
236 216 // Submit skeleton to gpu
237 - return SubmitSkeletonToGPU(frameIndex);
217 + return SubmitSkeletonToGPU(animationIndex, frameIndex);
238 218 }
239 219
240 220 /// Create animation skeleton
  @@ -260,10 +240,10 @@
260 240 return 1;
261 241 }
262 242
263 - I32 SceneAnimator::SubmitSkeletonToGPU(U32 frameIndex){
264 - GFX_DEVICE.drawLines(_pointsA[_currentAnimIndex][frameIndex],
265 - _pointsB[_currentAnimIndex][frameIndex],
266 - _colors[_currentAnimIndex][frameIndex],
243 + I32 SceneAnimator::SubmitSkeletonToGPU(I32 animationIndex, U32 frameIndex){
244 + GFX_DEVICE.drawLines(_pointsA[animationIndex][frameIndex],
245 + _pointsB[animationIndex][frameIndex],
246 + _colors[animationIndex][frameIndex],
267 247 _rootTransformRender,
268 248 false,
269 249 true);