llvisualparam.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * @file llvisualparam.h
  3. * @brief Implementation of LLPolyMesh 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_LLVisualParam_H
  33. #define LL_LLVisualParam_H
  34. #include "llmemory.h"
  35. #include "llstring.h"
  36. #include "llxmltree.h"
  37. #include "llvector3.h"
  38. #include "boost/function.hpp"
  39. class LLDriverParam;
  40. class LLPolyMesh;
  41. class LLPolyMorphTarget;
  42. class LLPolySkeletalDistortion;
  43. class LLPolySkeletalDistortionInfo;
  44. class LLViewerVisualParam;
  45. class LLXmlTreeNode;
  46. enum ESex
  47. {
  48. SEX_FEMALE = 0x01,
  49. SEX_MALE = 0x02,
  50. SEX_BOTH = 0x03 // values chosen to allow use as a bit field.
  51. };
  52. enum EVisualParamGroup
  53. {
  54. VISUAL_PARAM_GROUP_TWEAKABLE,
  55. VISUAL_PARAM_GROUP_ANIMATABLE,
  56. VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT,
  57. NUM_VISUAL_PARAM_GROUPS
  58. };
  59. enum EParamLocation
  60. {
  61. LOC_UNKNOWN,
  62. LOC_AV_SELF,
  63. LOC_AV_OTHER,
  64. LOC_WEARABLE
  65. };
  66. constexpr S32 MAX_TRANSMITTED_VISUAL_PARAMS = 255;
  67. //-----------------------------------------------------------------------------
  68. // LLVisualParamInfo
  69. // Contains shared data for VisualParams
  70. //-----------------------------------------------------------------------------
  71. class LLVisualParamInfo
  72. {
  73. friend class LLVisualParam;
  74. protected:
  75. LOG_CLASS(LLVisualParamInfo);
  76. public:
  77. LLVisualParamInfo();
  78. virtual ~LLVisualParamInfo() = default;
  79. LL_INLINE virtual LLPolySkeletalDistortionInfo* asPolySkeletalDistortionInfo()
  80. {
  81. return NULL;
  82. }
  83. virtual bool parseXml(LLXmlTreeNode* node);
  84. LL_INLINE S32 getID() const { return mID; }
  85. protected:
  86. std::string mName; // name (for internal purposes)
  87. std::string mDisplayName; // name displayed to the user
  88. std::string mMinName; // name associated with minimum value
  89. std::string mMaxName; // name associated with maximum value
  90. S32 mID; // ID associated with VisualParam
  91. EVisualParamGroup mGroup; // morph group for use in the pie menu
  92. F32 mMinWeight; // minimum weight for this morph target
  93. F32 mMaxWeight; // maximum weight for this morph target
  94. F32 mDefaultWeight;
  95. ESex mSex; // Which gender(s) this param applies to.
  96. };
  97. //-----------------------------------------------------------------------------
  98. // LLVisualParam
  99. // VIRTUAL CLASS
  100. // An interface class for a generalized parametric modification of the avatar
  101. // mesh. Contains data that is specific to each Avatar.
  102. //
  103. // IMPORTANT NOTE: several derived classes use 16-bytes aligned structures so
  104. // that the latter can be used with SSE2 maths. new() and delete() are
  105. // therefore redefined here (so that all derived classes will inherit and use
  106. // those as well, ensuring consistency for all constructors and destructors),
  107. // and all derived classes shall therefore be 16-bytes aligned (do use the
  108. // alignas(16) for all of them !). HB
  109. //-----------------------------------------------------------------------------
  110. class alignas(16) LLVisualParam
  111. {
  112. protected:
  113. LOG_CLASS(LLVisualParam);
  114. LLVisualParam(const LLVisualParam& other);
  115. public:
  116. LL_ALIGNED16_NEW_DELETE
  117. typedef boost::function<LLVisualParam*(S32)> visual_param_mapper;
  118. LLVisualParam();
  119. virtual ~LLVisualParam();
  120. LL_INLINE virtual LLDriverParam* asDriverParam() { return NULL; }
  121. LL_INLINE virtual LLPolyMorphTarget* asPolyMorphTarget()
  122. {
  123. return NULL;
  124. }
  125. LL_INLINE virtual LLViewerVisualParam* asViewerVisualParam()
  126. {
  127. return NULL;
  128. }
  129. LL_INLINE virtual LLPolySkeletalDistortion* asPolySkeletalDistortion()
  130. {
  131. return NULL;
  132. }
  133. // Special: These functions are overridden by child classes
  134. // (They can not be virtual because they use specific derived Info classes)
  135. LL_INLINE LLVisualParamInfo* getInfo() const { return mInfo; }
  136. // This sets mInfo and calls initialization functions
  137. bool setInfo(LLVisualParamInfo* info);
  138. // Virtual functions
  139. // Pure virtual
  140. virtual void apply(ESex avatar_sex) = 0;
  141. // Default functions
  142. virtual void setWeight(F32 weight, bool upload_bake);
  143. virtual void setAnimationTarget(F32 target_value, bool upload_bake);
  144. virtual void animate(F32 delta, bool upload_bake);
  145. virtual void stopAnimating(bool upload_bake);
  146. LL_INLINE virtual bool linkDrivenParams(visual_param_mapper mapper,
  147. bool only_cross_params)
  148. {
  149. return true;
  150. }
  151. LL_INLINE virtual void resetDrivenParams() {}
  152. // Interface methods
  153. LL_INLINE S32 getID() const { return mID; }
  154. LL_INLINE void setID(S32 id) { llassert(!mInfo); mID = id; }
  155. LL_INLINE const std::string& getName() const { return mInfo->mName; }
  156. LL_INLINE const std::string& getDisplayName() const { return mInfo->mDisplayName; }
  157. LL_INLINE const std::string& getMaxDisplayName() const { return mInfo->mMaxName; }
  158. LL_INLINE const std::string& getMinDisplayName() const { return mInfo->mMinName; }
  159. LL_INLINE void setDisplayName(const std::string& s) { mInfo->mDisplayName = s; }
  160. LL_INLINE void setMaxDisplayName(const std::string& s) { mInfo->mMaxName = s; }
  161. LL_INLINE void setMinDisplayName(const std::string& s) { mInfo->mMinName = s; }
  162. LL_INLINE EVisualParamGroup getGroup() const { return mInfo->mGroup; }
  163. LL_INLINE F32 getMinWeight() const { return mInfo->mMinWeight; }
  164. LL_INLINE F32 getMaxWeight() const { return mInfo->mMaxWeight; }
  165. LL_INLINE F32 getDefaultWeight() const { return mInfo->mDefaultWeight; }
  166. LL_INLINE ESex getSex() const { return mInfo->mSex; }
  167. LL_INLINE F32 getWeight() const { return mIsAnimating ? mTargetWeight : mCurWeight; }
  168. LL_INLINE F32 getCurrentWeight() const { return mCurWeight; }
  169. LL_INLINE F32 getLastWeight() const { return mLastWeight; }
  170. LL_INLINE void setLastWeight(F32 val) { mLastWeight = val; }
  171. LL_INLINE bool isAnimating() const { return mIsAnimating; }
  172. LL_INLINE bool isTweakable() const
  173. {
  174. return mInfo->mGroup == VISUAL_PARAM_GROUP_TWEAKABLE ||
  175. mInfo->mGroup == VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT;
  176. }
  177. LL_INLINE LLVisualParam* getNextParam() { return mNext; }
  178. void setNextParam(LLVisualParam* next);
  179. LL_INLINE void clearNextParam() { mNext = NULL; }
  180. LL_INLINE virtual void setAnimating(bool b) { mIsAnimating = b && !mIsDummy; }
  181. LL_INLINE bool getAnimating() const { return mIsAnimating; }
  182. LL_INLINE void setIsDummy(bool is_dummy) { mIsDummy = is_dummy; }
  183. void setParamLocation(EParamLocation loc);
  184. LL_INLINE EParamLocation getParamLocation() const { return mParamLocation; }
  185. protected:
  186. LLVisualParam* mNext; // Next param in a shared chain
  187. LLVisualParamInfo* mInfo;
  188. F32 mCurWeight; // Current weight
  189. F32 mLastWeight; // Last weight
  190. F32 mTargetWeight; // Interpolation target
  191. // Id for storing weight/morphtarget compares compactly
  192. S32 mID;
  193. // Where does this visual param live ?
  194. EParamLocation mParamLocation;
  195. // This value has been given an interpolation target
  196. bool mIsAnimating;
  197. // used to prevent dummy visual params from animating
  198. bool mIsDummy;
  199. };
  200. #endif // LL_LLVisualParam_H