llpolymorph.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. * @file llpolymorph.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_LLPOLYMORPH_H
  33. #define LL_LLPOLYMORPH_H
  34. #include <string>
  35. #include <vector>
  36. #include "llfile.h"
  37. #include "llviewervisualparam.h"
  38. class LLAvatarJointCollisionVolume;
  39. class LLPolyMeshSharedData;
  40. class LLVector2;
  41. class LLWearable;
  42. class alignas(16) LLPolyMorphData
  43. {
  44. protected:
  45. LOG_CLASS(LLPolyMorphData);
  46. public:
  47. LL_ALIGNED16_NEW_DELETE
  48. LLPolyMorphData(const char* morph_name);
  49. ~LLPolyMorphData();
  50. LLPolyMorphData(const LLPolyMorphData& rhs);
  51. LL_INLINE bool isSuccesfullyAllocated() { return mSuccessfullyAllocated; }
  52. bool loadBinary(LLFILE* fp, LLPolyMeshSharedData* mesh);
  53. LL_INLINE const std::string& getName() { return mName; }
  54. private:
  55. void freeData();
  56. public:
  57. // Average vertex distortion, to infer directionality of the morph
  58. LLVector4a mAvgDistortion;
  59. // Morphology
  60. LLVector4a* mCoords;
  61. LLVector4a* mNormals;
  62. LLVector4a* mBinormals;
  63. LLVector2* mTexCoords;
  64. U32* mVertexIndices;
  65. U32 mNumIndices;
  66. U32 mCurrentIndex;
  67. LLPolyMeshSharedData* mMesh;
  68. // Vertex distortion summed over entire morph
  69. F32 mTotalDistortion;
  70. // Maximum single vertex distortion in a given morph
  71. F32 mMaxDistortion;
  72. std::string mName;
  73. private:
  74. bool mSuccessfullyAllocated;
  75. };
  76. class LLPolyVertexMask
  77. {
  78. public:
  79. LLPolyVertexMask(LLPolyMorphData* morph_data);
  80. LLPolyVertexMask(const LLPolyVertexMask& other);
  81. ~LLPolyVertexMask();
  82. void generateMask(U8* mask_data, S32 width, S32 height, S32 num_components,
  83. bool invert, LLVector4a* clothing_weights);
  84. F32* getMorphMaskWeights();
  85. protected:
  86. F32* mWeights;
  87. LLPolyMorphData* mMorphData;
  88. bool mWeightsGenerated;
  89. };
  90. struct LLPolyVolumeMorphInfo
  91. {
  92. LLPolyVolumeMorphInfo(const std::string& name, const LLVector3& scale,
  93. const LLVector3& pos)
  94. : mName(name),
  95. mScale(scale),
  96. mPos(pos)
  97. {
  98. }
  99. std::string mName;
  100. LLVector3 mScale;
  101. LLVector3 mPos;
  102. };
  103. struct LLPolyVolumeMorph
  104. {
  105. LLPolyVolumeMorph(LLAvatarJointCollisionVolume* volume,
  106. const LLVector3& scale, const LLVector3& pos)
  107. : mVolume(volume),
  108. mScale(scale),
  109. mPos(pos)
  110. {
  111. }
  112. LLAvatarJointCollisionVolume* mVolume;
  113. LLVector3 mScale;
  114. LLVector3 mPos;
  115. };
  116. // Shared information for LLPolyMorphTargets
  117. class LLPolyMorphTargetInfo : public LLViewerVisualParamInfo
  118. {
  119. friend class LLPolyMorphTarget;
  120. protected:
  121. LOG_CLASS(LLPolyMorphTargetInfo);
  122. public:
  123. LLPolyMorphTargetInfo();
  124. bool parseXml(LLXmlTreeNode* node) override;
  125. protected:
  126. std::string mMorphName;
  127. bool mIsClothingMorph;
  128. typedef std::vector<LLPolyVolumeMorphInfo> volume_info_list_t;
  129. volume_info_list_t mVolumeInfoList;
  130. };
  131. // A set of vertex data associated with morph target. These morph targets must
  132. // be topologically consistent with a given Polymesh (share face sets)
  133. class alignas(16) LLPolyMorphTarget : public LLViewerVisualParam
  134. {
  135. protected:
  136. LOG_CLASS(LLPolyMorphTarget);
  137. LLPolyMorphTarget(const LLPolyMorphTarget& other);
  138. public:
  139. LLPolyMorphTarget(LLPolyMesh* poly_mesh);
  140. ~LLPolyMorphTarget();
  141. LL_INLINE LLPolyMorphTarget* asPolyMorphTarget() override
  142. {
  143. return this;
  144. }
  145. // Special: These functions are overridden by child classes
  146. LL_INLINE LLPolyMorphTargetInfo* getInfo() const { return (LLPolyMorphTargetInfo*)mInfo; }
  147. // Sets mInfo and calls initialization functions
  148. bool setInfo(LLPolyMorphTargetInfo* info);
  149. LLViewerVisualParam* cloneParam(LLWearable* wearable) const override;
  150. // LLVisualParam Virtual function
  151. void apply(ESex sex) override;
  152. #if 0 // Unused methods
  153. // LLViewerVisualParam Virtual functions
  154. F32 getTotalDistortion() override;
  155. const LLVector4a& getAvgDistortion() override;
  156. F32 getMaxDistortion() override;
  157. LLVector4a getVertexDistortion(S32 index, LLPolyMesh* mesh) override;
  158. const LLVector4a* getFirstDistortion(U32* idx, LLPolyMesh** mesh) override;
  159. const LLVector4a* getNextDistortion(U32* idx, LLPolyMesh** mesh) override;
  160. #endif
  161. void applyMask(U8* mask_data, S32 width, S32 height, S32 num_components,
  162. bool invert);
  163. LL_INLINE void addPendingMorphMask() { ++mNumMorphMasksPending; }
  164. // Also used by LLVOAvatar::resetSkeleton()
  165. void applyVolumeChanges(F32 delta_weight);
  166. protected:
  167. LLPolyMorphData* mMorphData;
  168. LLPolyMesh* mMesh;
  169. LLPolyVertexMask* mVertMask;
  170. ESex mLastSex;
  171. // Number of morph masks that haven't been generated, must be 0 before
  172. // this morph is applied
  173. S32 mNumMorphMasksPending;
  174. typedef std::vector<LLPolyVolumeMorph> volume_list_t;
  175. volume_list_t mVolumeMorphs;
  176. };
  177. #endif // LL_LLPOLYMORPH_H