Changeset 453
- Timestamp:
- 01/07/12 14:44:14 (5 months ago)
- Location:
- cafu/trunk/Libs
- Files:
-
- 1 added
- 5 modified
-
MaterialSystem/MaterialManagerImpl.hpp (modified) (1 diff)
-
Models/AnimExpr.cpp (modified) (4 diffs)
-
Models/AnimExpr.hpp (modified) (7 diffs)
-
Models/AnimPose.cpp (modified) (5 diffs)
-
Models/AnimPose.hpp (modified) (6 diffs)
-
Templates/Pointer.hpp (added)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/Libs/MaterialSystem/MaterialManagerImpl.hpp
r439 r453 53 53 54 54 /// Returns whether the material with the given name is registered with the material manager, 55 /// i.e. if a call to <code>GetMaterial(MaterialName)</code> will return successfully.55 /// i.e.\ if a call to <code>GetMaterial(MaterialName)</code> will return successfully. 56 56 /// Use this to avoid warning messages to the console if the material is not registered. 57 57 bool HasMaterial(const std::string& MaterialName) const; -
cafu/trunk/Libs/Models/AnimExpr.cpp
r452 r453 24 24 25 25 26 AnimExpressionT::AnimExpressionT(const CafuModelT& Model) 27 : m_Model(Model), 28 m_RefCount(0), 29 m_ChangeNum(0) 30 { 31 UpdateChangeNum(); 32 } 33 34 35 void AnimExpressionT::UpdateChangeNum() 36 { 37 static unsigned int s_ChangeCount=0; 38 39 m_ChangeNum = ++s_ChangeCount; 40 } 41 42 26 43 /*************************/ 27 44 /*** AnimExprStandardT ***/ … … 31 48 : AnimExpressionT(Model), 32 49 m_SequNr(SequNr), 33 m_FrameNr(FrameNr), 34 m_ChangeCount(1) // The user code inits its own count with 0. 50 m_FrameNr(FrameNr) 35 51 { 36 52 NormalizeInput(); … … 144 160 NormalizeInput(); 145 161 146 m_ChangeCount++;162 UpdateChangeNum(); 147 163 } 148 164 … … 155 171 NormalizeInput(); 156 172 157 m_ChangeCount++; 158 } 173 UpdateChangeNum(); 174 } 175 176 177 /***********************/ 178 /*** AnimExprFilterT ***/ 179 /***********************/ 180 181 namespace 182 { 183 unsigned int FindChannelByName(const CafuModelT& Model, const std::string& ChannelName) 184 { 185 unsigned int ChannelNr; 186 187 for (ChannelNr=0; ChannelNr<Model.GetChannels().Size(); ChannelNr++) 188 if (ChannelName == Model.GetChannels()[ChannelNr].Name) 189 return ChannelNr; 190 191 return ChannelNr; 192 } 193 } 194 195 196 AnimExprFilterT::AnimExprFilterT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr) 197 : AnimExpressionT(Model), 198 m_SubExpr(SubExpr), 199 m_ChannelNr(ChannelNr) 200 { 201 } 202 203 204 AnimExprFilterT::AnimExprFilterT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> SubExpr, const std::string& ChannelName) 205 : AnimExpressionT(Model), 206 m_SubExpr(SubExpr), 207 m_ChannelNr(FindChannelByName(Model, ChannelName)) 208 { 209 } 210 211 212 void AnimExprFilterT::ReInit(IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr) 213 { 214 if (m_SubExpr==SubExpr && m_ChannelNr==ChannelNr) return; 215 216 m_SubExpr =SubExpr; 217 m_ChannelNr=ChannelNr; 218 219 UpdateChangeNum(); 220 } 221 222 223 unsigned int AnimExprFilterT::GetChangeNum() const 224 { 225 return std::max(GetChangeNum(), m_SubExpr->GetChangeNum()); 226 } 227 228 229 void AnimExprFilterT::GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const 230 { 231 Weight=0.0f; 232 233 if (m_ChannelNr >= GetModel().GetChannels().Size() || GetModel().GetChannels()[m_ChannelNr].IsMember(JointNr)) 234 { 235 m_SubExpr->GetData(JointNr, Weight, Pos, Quat, Scale); 236 } 237 } 238 239 240 /************************/ 241 /*** AnimExprCombineT ***/ 242 /************************/ 243 244 AnimExprCombineT::AnimExprCombineT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B) 245 : AnimExpressionT(Model), 246 m_A(A), 247 m_B(B) 248 { 249 } 250 251 252 void AnimExprCombineT::ReInit(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B) 253 { 254 if (m_A==A && m_B==B) return; 255 256 m_A=A; 257 m_B=B; 258 259 UpdateChangeNum(); 260 } 261 262 263 unsigned int AnimExprCombineT::GetChangeNum() const 264 { 265 return std::max(GetChangeNum(), 266 std::max(m_A->GetChangeNum(), m_B->GetChangeNum())); 267 } 268 269 270 void AnimExprCombineT::GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const 271 { 272 m_A->GetData(JointNr, Weight, Pos, Quat, Scale); 273 274 float WeightB; 275 Vector3fT PosB; 276 cf::math::QuaternionfT QuatB; 277 Vector3fT ScaleB; 278 279 // Pick the expression with the largest weight. 280 m_B->GetData(JointNr, WeightB, PosB, QuatB, ScaleB); 281 282 if (WeightB > Weight) 283 { 284 Weight = WeightB; 285 Pos = PosB; 286 Quat = QuatB; 287 Scale = ScaleB; 288 } 289 } 290 291 292 void AnimExprCombineT::AdvanceTime(float Time, bool ForceLoop) 293 { 294 m_A->AdvanceTime(Time, ForceLoop); 295 m_B->AdvanceTime(Time, ForceLoop); 296 } 297 298 299 /**********************/ 300 /*** AnimExprBlendT ***/ 301 /**********************/ 302 303 AnimExprBlendT::AnimExprBlendT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration) 304 : AnimExpressionT(Model), 305 m_A(A), 306 m_B(B), 307 m_Duration(Duration), 308 m_Frac(0.0f) 309 { 310 } 311 312 313 void AnimExprBlendT::ReInit(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration) 314 { 315 m_A=A; 316 m_B=B; 317 m_Duration=Duration; 318 m_Frac=0.0f; 319 320 UpdateChangeNum(); 321 } 322 323 324 unsigned int AnimExprBlendT::GetChangeNum() const 325 { 326 return std::max(GetChangeNum(), 327 std::max(m_A->GetChangeNum(), m_B->GetChangeNum())); 328 } 329 330 331 void AnimExprBlendT::GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const 332 { 333 float w[2]; 334 Vector3fT p[2]; 335 cf::math::QuaternionfT q[2]; 336 Vector3fT s[2]; 337 338 if (m_Frac <= 0.0f) 339 { 340 m_A->GetData(JointNr, Weight, Pos, Quat, Scale); 341 return; 342 } 343 344 if (m_Frac >= 1.0f) 345 { 346 m_B->GetData(JointNr, Weight, Pos, Quat, Scale); 347 return; 348 } 349 350 m_A->GetData(JointNr, w[0], p[0], q[0], s[0]); 351 m_B->GetData(JointNr, w[1], p[1], q[1], s[1]); 352 353 const float f0 = 1.0f - m_Frac; 354 const float f1 = m_Frac; 355 356 Weight = w[0]*f0 + w[1]*f1; 357 Pos = p[0]*f0 + p[1]*f1; 358 Quat = slerp(q[0], q[1], f0); // slerp() is why we cannot have generic "add" and "mul" AnimExpressionT's. 359 Scale = s[0]*f0 + s[1]*f1; 360 } 361 362 363 void AnimExprBlendT::AdvanceTime(float Time, bool ForceLoop) 364 { 365 // Advance the blend fraction. 366 if (m_Duration < 0.001f) 367 { 368 m_Frac = 1.0f; 369 } 370 else 371 { 372 m_Frac += Time/m_Duration; 373 } 374 375 m_Frac = std::min(m_Frac, 1.0f); 376 377 378 // Advance the sub-expressions. 379 if (m_Frac < 1.0f) 380 { 381 m_A->AdvanceTime(Time, ForceLoop); 382 } 383 else 384 { 385 m_A=NULL; // m_A is unused now that m_Frac >= 1.0. 386 } 387 388 m_B->AdvanceTime(Time, ForceLoop); 389 390 391 UpdateChangeNum(); 392 } 393 394 395 /*********************/ 396 /*** AnimExprPoolT ***/ 397 /*********************/ 398 399 void AnimExprPoolT::FlattenUnused() 400 { 401 for (unsigned int AENr=0; AENr<m_Filter.Size(); AENr++) 402 if (m_Filter[AENr]->GetRefCount()==1) 403 m_Filter[AENr]->ReInit(NULL, 0); 404 405 for (unsigned int AENr=0; AENr<m_Combine.Size(); AENr++) 406 if (m_Combine[AENr]->GetRefCount()==1) 407 m_Combine[AENr]->ReInit(NULL, NULL); 408 409 for (unsigned int AENr=0; AENr<m_Blend.Size(); AENr++) 410 if (m_Blend[AENr]->GetRefCount()==1) 411 m_Blend[AENr]->ReInit(NULL, NULL, 0.0f); 412 } 413 414 415 IntrusivePtrT<AnimExprStandardT> AnimExprPoolT::GetStandard(int SequNr, float FrameNr) 416 { 417 FlattenUnused(); 418 419 for (unsigned int AENr=0; AENr<m_Standard.Size(); AENr++) 420 { 421 if (m_Standard[AENr]->GetRefCount()==1) 422 { 423 m_Standard[AENr]->SetSequNr(SequNr); 424 m_Standard[AENr]->SetFrameNr(FrameNr); 425 426 return m_Standard[AENr]; 427 } 428 } 429 430 IntrusivePtrT<AnimExprStandardT> NewAE(new AnimExprStandardT(m_Model, SequNr, FrameNr)); 431 m_Standard.PushBack(NewAE); 432 433 return NewAE; 434 } 435 436 437 IntrusivePtrT<AnimExprFilterT> AnimExprPoolT::GetFilter(IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr) 438 { 439 FlattenUnused(); 440 441 for (unsigned int AENr=0; AENr<m_Filter.Size(); AENr++) 442 { 443 if (m_Filter[AENr]->GetRefCount()==1) 444 { 445 m_Filter[AENr]->ReInit(SubExpr, ChannelNr); 446 447 return m_Filter[AENr]; 448 } 449 } 450 451 IntrusivePtrT<AnimExprFilterT> NewAE(new AnimExprFilterT(m_Model, SubExpr, ChannelNr)); 452 m_Filter.PushBack(NewAE); 453 454 return NewAE; 455 } 456 457 458 IntrusivePtrT<AnimExprFilterT> AnimExprPoolT::GetFilter(IntrusivePtrT<AnimExpressionT> SubExpr, const std::string& ChannelName) 459 { 460 return GetFilter(SubExpr, FindChannelByName(m_Model, ChannelName)); 461 } 462 463 464 IntrusivePtrT<AnimExprCombineT> AnimExprPoolT::GetCombine(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B) 465 { 466 FlattenUnused(); 467 468 for (unsigned int AENr=0; AENr<m_Combine.Size(); AENr++) 469 { 470 if (m_Combine[AENr]->GetRefCount()==1) 471 { 472 m_Combine[AENr]->ReInit(A, B); 473 474 return m_Combine[AENr]; 475 } 476 } 477 478 IntrusivePtrT<AnimExprCombineT> NewAE(new AnimExprCombineT(m_Model, A, B)); 479 m_Combine.PushBack(NewAE); 480 481 return NewAE; 482 } 483 484 485 IntrusivePtrT<AnimExprBlendT> AnimExprPoolT::GetBlend(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration) 486 { 487 FlattenUnused(); 488 489 for (unsigned int AENr=0; AENr<m_Blend.Size(); AENr++) 490 { 491 if (m_Blend[AENr]->GetRefCount()==1) 492 { 493 m_Blend[AENr]->ReInit(A, B, Duration); 494 495 return m_Blend[AENr]; 496 } 497 } 498 499 IntrusivePtrT<AnimExprBlendT> NewAE(new AnimExprBlendT(m_Model, A, B, Duration)); 500 m_Blend.PushBack(NewAE); 501 502 return NewAE; 503 } -
cafu/trunk/Libs/Models/AnimExpr.hpp
r452 r453 24 24 25 25 #include "Math3D/Quaternion.hpp" 26 #include "Templates/Array.hpp" 27 #include "Templates/Pointer.hpp" 26 28 27 29 … … 29 31 30 32 33 /// Animation expressions describe the "skeleton pose" of a model. 34 /// 35 /// They are used as an input to AnimPoseT instances, which use the "skeleton pose" expressed by an anim 36 /// expression in order to derive the "full pose", including meshes and other features such as collision 37 /// detection. 38 /// In other words, AnimPoseT's refer to an AnimExpressionT for the "configuration" of its pose. 39 /// 40 /// AnimExpressionT's can be hierarchically composed, just like mathematical expressions, 41 /// which is in fact their strongest and most important feature. 42 /// They are also very easy and care-free to use and have very good performance, because when obtained 43 /// from an AnimExprPoolT, the pool minimizes both the number of instances as well as the penalties from 44 /// memory allocations and deletes. 31 45 class AnimExpressionT 32 46 { 33 47 public: 34 48 35 /// The constructor. TODO: Make protected, so that only derived classes can use it? 36 AnimExpressionT(const CafuModelT& Model) : m_Model(Model) { } 49 /// The constructor. 50 /// (It's ok to have this in "public" instead of "protected": we have pure virtual methods as well.) 51 AnimExpressionT(const CafuModelT& Model); 37 52 38 53 /// The (virtual) destructor. … … 41 56 /// Returns the model that this is an anim expression for. 42 57 const CafuModelT& GetModel() const { return m_Model; } 58 59 /// Returns the number of IntrusivePtrT<>'s that currently refer to this anim expression. 60 /// This is especially useful for the implementation of "pools" of AnimExpressionT's, 61 /// so that the pool implementation can learn if this instance is available for being re-used. 62 unsigned int GetRefCount() const { return m_RefCount; } 43 63 44 64 /// Returns a number that changes whenever this expression changes, … … 46 66 /// This is the case for example after every call to AdvanceTime() with a nonzero Time, 47 67 /// or when a sub-expression has been modified (e.g. got a new sequence number assigned). 48 /// The caller can use this number in order to control refreshes of its mesh caches.49 virtual unsigned int GetChange Count() const=0;68 /// The caller can use this number in order to control updates of its mesh caches. 69 virtual unsigned int GetChangeNum() const { return m_ChangeNum; } 50 70 51 71 /// For the joint with the given JointNr, this function returns … … 58 78 59 79 60 private: 80 protected: 81 82 void UpdateChangeNum(); 83 84 85 private: 86 87 template<class T> friend class IntrusivePtrT; 61 88 62 89 AnimExpressionT(const AnimExpressionT&); ///< Use of the Copy Constructor is not allowed. 63 90 void operator = (const AnimExpressionT&); ///< Use of the Assignment Operator is not allowed. 64 91 65 const CafuModelT& m_Model; ///< The related model that this is an anim expression for. 92 const CafuModelT& m_Model; ///< The related model that this is an anim expression for. 93 unsigned int m_RefCount; ///< How many IntrusivePtrT<>'s currently refer to this anim expression? 94 unsigned int m_ChangeNum; ///< Changes whenever the data returned by GetData() changes. 66 95 }; 67 96 … … 74 103 75 104 // Implementations and overrides for base class methods. 76 virtual unsigned int GetChangeCount() const { return m_ChangeCount; }77 105 virtual void GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const; 78 106 virtual void AdvanceTime(float Time, bool ForceLoop=false); … … 97 125 void NormalizeInput(); 98 126 99 int m_SequNr; ///< The animation sequence number. 100 float m_FrameNr; ///< The frame number in the sequence. 101 unsigned int m_ChangeCount; ///< Changes whenever the data returned by GetData() might have changed. 127 int m_SequNr; ///< The animation sequence number. 128 float m_FrameNr; ///< The frame number in the sequence. 129 }; 130 131 132 /// Filters the result of another expression by a "channel". 133 class AnimExprFilterT : public AnimExpressionT 134 { 135 public: 136 137 AnimExprFilterT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr); 138 AnimExprFilterT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> SubExpr, const std::string& ChannelName); 139 140 /// Re-initializes this anim expression, so that it can be re-used with different parameters (on the same model). 141 void ReInit(IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr); 142 143 // Implementations and overrides for base class methods. 144 virtual unsigned int GetChangeNum() const; 145 virtual void GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const; 146 virtual void AdvanceTime(float Time, bool ForceLoop=false) { m_SubExpr->AdvanceTime(Time, ForceLoop); } 147 148 149 private: 150 151 IntrusivePtrT<AnimExpressionT> m_SubExpr; 152 unsigned int m_ChannelNr; 153 }; 154 155 156 class AnimExprCombineT : public AnimExpressionT 157 { 158 public: 159 160 AnimExprCombineT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B); 161 162 /// Re-initializes this anim expression, so that it can be re-used with different parameters (on the same model). 163 void ReInit(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B); 164 165 // Implementations and overrides for base class methods. 166 virtual unsigned int GetChangeNum() const; 167 virtual void GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const; 168 virtual void AdvanceTime(float Time, bool ForceLoop=false); 169 170 171 private: 172 173 IntrusivePtrT<AnimExpressionT> m_A; 174 IntrusivePtrT<AnimExpressionT> m_B; 175 }; 176 177 178 class AnimExprBlendT : public AnimExpressionT 179 { 180 public: 181 182 AnimExprBlendT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration); 183 184 /// Re-initializes this anim expression, so that it can be re-used with different parameters (on the same model). 185 /// Note that resetting \c A, \c B or \c Duration individually is not possible, because the implementation 186 /// may prune and drop \c A when the blend is complete. 187 void ReInit(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration); 188 189 // Implementations and overrides for base class methods. 190 virtual unsigned int GetChangeNum() const; 191 virtual void GetData(unsigned int JointNr, float& Weight, Vector3fT& Pos, cf::math::QuaternionfT& Quat, Vector3fT& Scale) const; 192 virtual void AdvanceTime(float Time, bool ForceLoop=false); 193 194 195 private: 196 197 IntrusivePtrT<AnimExpressionT> m_A; 198 IntrusivePtrT<AnimExpressionT> m_B; 199 float m_Duration; 200 float m_Frac; 201 }; 202 203 204 class AnimExprPoolT 205 { 206 public: 207 208 AnimExprPoolT(const CafuModelT& Model) : m_Model(Model) { } 209 210 // These methods mimic the ctors of the anim expression classes. 211 IntrusivePtrT<AnimExprStandardT> GetStandard(int SequNr, float FrameNr); 212 IntrusivePtrT<AnimExprFilterT> GetFilter(IntrusivePtrT<AnimExpressionT> SubExpr, unsigned int ChannelNr); 213 IntrusivePtrT<AnimExprFilterT> GetFilter(IntrusivePtrT<AnimExpressionT> SubExpr, const std::string& ChannelName); 214 IntrusivePtrT<AnimExprCombineT> GetCombine(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B); 215 IntrusivePtrT<AnimExprBlendT> GetBlend(IntrusivePtrT<AnimExpressionT> A, IntrusivePtrT<AnimExpressionT> B, float Duration); 216 217 218 private: 219 220 /// This function makes sure that anim expressions that are unused don't keep pointers 221 /// to subexpressions, such that the subexpressions are available as unused as well. 222 void FlattenUnused(); 223 224 const CafuModelT& m_Model; ///< The related model that this is an anim expression pool for. 225 ArrayT< IntrusivePtrT<AnimExprStandardT> > m_Standard; 226 ArrayT< IntrusivePtrT<AnimExprFilterT> > m_Filter; 227 ArrayT< IntrusivePtrT<AnimExprCombineT> > m_Combine; 228 ArrayT< IntrusivePtrT<AnimExprBlendT> > m_Blend; 102 229 }; 103 230 -
cafu/trunk/Libs/Models/AnimPose.cpp
r452 r453 30 30 31 31 32 AnimPoseT::AnimPoseT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> AnimExpr) 33 : m_Model(Model), 34 m_AnimExpr(AnimExpr), 35 m_SuperPose(NULL), 36 m_DlodPose(NULL), 37 m_RecacheCount(0), 38 m_BoundingBox() 39 { 40 if (m_Model.GetDlodModel()) 41 { 42 // Recursively create the chain of dlod poses matching the chain of dlod models. 43 // Note that all dlod poses share the *SAME* AnimExpr as the top-most pose! 44 m_DlodPose = new AnimPoseT(*m_Model.GetDlodModel(), m_AnimExpr); 45 } 46 } 47 48 32 49 AnimPoseT::AnimPoseT(const CafuModelT& Model, int SequNr, float FrameNr) 33 50 : m_Model(Model), 34 m_AnimExpr( NULL),51 m_AnimExpr(new AnimExprStandardT(m_Model, SequNr, FrameNr)), 35 52 m_SuperPose(NULL), 36 m_DlodPose(m_Model.GetDlodModel() ? new AnimPoseT(*m_Model.GetDlodModel(), SequNr, FrameNr) : NULL), // Recursively create the chain of dlod poses matching the chain of dlod models.53 m_DlodPose(m_Model.GetDlodModel() ? new AnimPoseT(*m_Model.GetDlodModel(), m_AnimExpr) : NULL), // Recursively create the chain of dlod poses matching the chain of dlod models. 37 54 m_RecacheCount(0), 38 55 m_BoundingBox() 39 56 { 40 m_AnimExpr=new AnimExprStandardT(m_Model, SequNr, FrameNr);41 57 } 42 58 … … 45 61 { 46 62 delete m_DlodPose; 47 delete m_AnimExpr; 63 } 64 65 66 void AnimPoseT::SetAnimExpr(IntrusivePtrT<AnimExpressionT> AnimExpr) 67 { 68 for (AnimPoseT* Pose=this; Pose; Pose=Pose->m_DlodPose) 69 { 70 Pose->m_AnimExpr = AnimExpr; 71 } 48 72 } 49 73 … … 399 423 void AnimPoseT::Recache() const 400 424 { 401 if (!m_SuperPose && m_RecacheCount==m_AnimExpr->GetChange Count()) return;425 if (!m_SuperPose && m_RecacheCount==m_AnimExpr->GetChangeNum()) return; 402 426 403 427 SyncDimensions(); … … 414 438 // y(); 415 439 416 m_RecacheCount=m_AnimExpr->GetChangeCount(); 417 } 418 419 420 int AnimPoseT::GetSequNr() const { return dynamic_cast<AnimExprStandardT*>(m_AnimExpr)->GetSequNr(); } 421 float AnimPoseT::GetFrameNr() const { return dynamic_cast<AnimExprStandardT*>(m_AnimExpr)->GetFrameNr(); } 440 m_RecacheCount=m_AnimExpr->GetChangeNum(); 441 } 442 443 444 int AnimPoseT::GetSequNr() const 445 { 446 return dynamic_cast<const AnimExprStandardT*>(&*m_AnimExpr)->GetSequNr(); 447 } 448 449 450 float AnimPoseT::GetFrameNr() const 451 { 452 return dynamic_cast<const AnimExprStandardT*>(&*m_AnimExpr)->GetFrameNr(); 453 } 422 454 423 455 424 456 void AnimPoseT::SetSequNr(int SequNr) 425 457 { 426 dynamic_cast<AnimExprStandardT*>( m_AnimExpr)->SetSequNr(SequNr);458 dynamic_cast<AnimExprStandardT*>(&*m_AnimExpr)->SetSequNr(SequNr); 427 459 428 460 // Recursively update the chain of dlod poses. … … 433 465 void AnimPoseT::SetFrameNr(float FrameNr) 434 466 { 435 dynamic_cast<AnimExprStandardT*>( m_AnimExpr)->SetFrameNr(FrameNr);467 dynamic_cast<AnimExprStandardT*>(&*m_AnimExpr)->SetFrameNr(FrameNr); 436 468 437 469 // Recursively update the chain of dlod poses. -
cafu/trunk/Libs/Models/AnimPose.hpp
r452 r453 23 23 #define _CAFU_MODEL_ANIM_POSE_HPP_ 24 24 25 #include " Templates/Array.hpp"25 #include "AnimExpr.hpp" 26 26 #include "MaterialSystem/Mesh.hpp" 27 27 #include "Math3D/BoundingBox.hpp" … … 29 29 30 30 31 class AnimExpressionT;32 31 class CafuModelT; 33 32 class MaterialT; … … 36 35 /// This class describes a specific pose of an associated model. 37 36 /// 38 /// A pose is defined by a set of animation sequences at given frame numbers for given channels,39 /// whose combinedapplication to the model yields all data that is relevant for further actions37 /// A pose is defined (or "configured") by an AnimExpressionT instance 38 /// whose application to the model yields all data that is relevant for further actions 40 39 /// on the model in that pose, such as rendering, tracing rays, collision detection, etc. 41 40 /// 42 /// The data that is derived from the set of input tuples (sequence, frame number, channel)43 /// is cached within the pose instance.It comprises:41 /// The data that is derived from the anim expression is cached within the pose instance. 42 /// It comprises: 44 43 /// - the transformation matrices for each joint in the skeleton, 45 44 /// - the MatSys render meshes for each mesh, … … 48 47 /// the representation of a model (the \c CafuModelT instance). 49 48 /// As a consequence, AnimPoseT instances should be shared whenever there are multiple users 50 /// (such as "static detail model" entity instances) that all show the same model in the same 51 /// pose. 49 /// (such as "static detail model" entity instances) that all show the same model in the same pose. 52 50 class AnimPoseT 53 51 { … … 89 87 90 88 /// The constructor. 89 AnimPoseT(const CafuModelT& Model, IntrusivePtrT<AnimExpressionT> AnimExpr); 90 91 /// The constructor. 91 92 AnimPoseT(const CafuModelT& Model, int SequNr=-1, float FrameNr=0.0f); 92 93 93 94 /// The destructor. 94 95 ~AnimPoseT(); 96 97 /// Sets a new anim expression to use for this pose. 98 /// 99 /// \param AnimExpr The new anim expression to use for this pose. 100 void SetAnimExpr(IntrusivePtrT<AnimExpressionT> AnimExpr); 95 101 96 102 int GetSequNr() const; … … 172 178 void Recache() const; 173 179 174 const CafuModelT& m_Model; ///< The related model that this is a pose for. 175 AnimExpressionT* m_AnimExpr; ///< The expression that describes the animation state of the joints for which we have computed the cache data. 176 const AnimPoseT* m_SuperPose; 177 AnimPoseT* m_DlodPose; ///< The next pose in the chain of dlod poses matching the chain of dlod models. 178 // ArrayT<...> m_Def; ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples. 179 // bool m_DoCache; ///< Cache the computed data? (Set to true by the user if he want to re-use this instance.) 180 const CafuModelT& m_Model; ///< The related model that this is a pose for. 181 IntrusivePtrT<AnimExpressionT> m_AnimExpr; ///< The expression that describes the skeleton pose for which we have computed the cache data. 182 const AnimPoseT* m_SuperPose; 183 AnimPoseT* m_DlodPose; ///< The next pose in the chain of dlod poses matching the chain of dlod models. 180 184 181 mutable unsigned int m_RecacheCount;///< Used to detect if the m_AnimExpr has changed, so that our matrices, meshes etc. can be recached.182 mutable ArrayT<MatrixT> m_JointMatrices;///< The transformation matrices that represent the pose of the skeleton at the given animation sequence and frame number.183 mutable ArrayT<MeshInfoT> m_MeshInfos;///< Additional data for each mesh in m_Model.184 mutable ArrayT<MatSys::MeshT> m_Draw_Meshes;///< The draw meshes resulting from the m_JointMatrices.185 mutable BoundingBox3fT m_BoundingBox;///< The bounding-box for the model in this pose.185 mutable unsigned int m_RecacheCount; ///< Used to detect if the m_AnimExpr has changed, so that our matrices, meshes etc. can be recached. 186 mutable ArrayT<MatrixT> m_JointMatrices; ///< The transformation matrices that represent the pose of the skeleton at the given animation sequence and frame number. 187 mutable ArrayT<MeshInfoT> m_MeshInfos; ///< Additional data for each mesh in m_Model. 188 mutable ArrayT<MatSys::MeshT> m_Draw_Meshes; ///< The draw meshes resulting from the m_JointMatrices. 189 mutable BoundingBox3fT m_BoundingBox; ///< The bounding-box for the model in this pose. 186 190 }; 187 191
