llpose.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * @file llpose.h
  3. * @brief Implementation of LLPose class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLPOSE_H
  33. #define LL_LLPOSE_H
  34. #include <map>
  35. #include <string>
  36. #include "lljointstate.h"
  37. class LLPose
  38. {
  39. friend class LLPoseBlender;
  40. public:
  41. LLPose();
  42. // Adds a joint state in this pose
  43. bool addJointState(const LLPointer<LLJointState>& jstate);
  44. // Removes a joint state from this pose
  45. bool removeJointState(const LLPointer<LLJointState>& jstate);
  46. // Removes all joint states from this pose
  47. bool removeAllJointStates();
  48. // Sets weight for all joint states in this pose
  49. void setWeight(F32 weight);
  50. // Gets weight for this pose
  51. LL_INLINE F32 getWeight() const { return mWeight; }
  52. // Returns number of joint states stored in this pose
  53. LL_INLINE S32 getNumJointStates() const { return mJointMap.size(); }
  54. // Iterate through joint states
  55. LLJointState* getFirstJointState();
  56. LLJointState* getNextJointState();
  57. LLJointState* findJointState(LLJoint* joint);
  58. LLJointState* findJointState(U32 key);
  59. protected:
  60. F32 mWeight;
  61. typedef std::map<U32, LLPointer<LLJointState> > joint_map;
  62. joint_map mJointMap;
  63. typedef joint_map::iterator joint_map_iterator;
  64. joint_map_iterator mListIter;
  65. };
  66. constexpr S32 JSB_NUM_JOINT_STATES = 6;
  67. class LLJointStateBlender
  68. {
  69. public:
  70. LLJointStateBlender();
  71. void blendJointStates(bool apply_now = true);
  72. bool addJointState(const LLPointer<LLJointState>& joint_state,
  73. S32 priority, bool additive_blend);
  74. void interpolate(F32 u);
  75. void clear();
  76. void resetCachedJoint();
  77. public:
  78. LLJoint mJointCache;
  79. protected:
  80. LLPointer<LLJointState> mJointStates[JSB_NUM_JOINT_STATES];
  81. S32 mPriorities[JSB_NUM_JOINT_STATES];
  82. bool mAdditiveBlends[JSB_NUM_JOINT_STATES];
  83. };
  84. class LLMotion;
  85. class LLPoseBlender
  86. {
  87. public:
  88. LLPoseBlender();
  89. ~LLPoseBlender();
  90. // Requests motion joint states to be added to pose blender joint state
  91. // records
  92. bool addMotion(LLMotion* motion);
  93. // blends all joint states and apply to skeleton
  94. void blendAndApply();
  95. // removes all joint state blenders from last time
  96. void clearBlenders();
  97. // blends all joint states and cache results
  98. void blendAndCache(bool reset_cached_joints);
  99. // interpolates all joints towards cached values
  100. void interpolate(F32 u);
  101. LL_INLINE LLPose* getBlendedPose() { return &mBlendedPose; }
  102. protected:
  103. S32 mNextPoseSlot;
  104. LLPose mBlendedPose;
  105. typedef std::map<LLJoint*, LLJointStateBlender*> blender_map_t;
  106. blender_map_t mJointStateBlenderPool;
  107. typedef std::list<LLJointStateBlender*> blender_list_t;
  108. blender_list_t mActiveBlenders;
  109. };
  110. #endif // LL_LLPOSE_H