llavatarappearance.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * @file llavatarappearance.h
  3. * @brief Declaration of LLAvatarAppearance 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_AVATAR_APPEARANCE_H
  33. #define LL_AVATAR_APPEARANCE_H
  34. #include <vector>
  35. #include "llavatarappearancedefines.h"
  36. #include "llavatarjointmesh.h"
  37. #include "llcharacter.h"
  38. #include "lldriverparam.h"
  39. #include "hbfastmap.h"
  40. #include "llstring.h"
  41. #include "lltexlayer.h"
  42. #include "llviewervisualparam.h"
  43. #include "llxmltree.h"
  44. class LLAvatarBoneInfo;
  45. class LLAvatarSkeletonInfo;
  46. class LLTexGlobalColor;
  47. class LLTexGlobalColorInfo;
  48. class LLTexLayerSet;
  49. class LLWearableData;
  50. class LLAvatarAppearance : public LLCharacter
  51. {
  52. protected:
  53. LOG_CLASS(LLAvatarAppearance);
  54. public:
  55. //-------------------------------------------------------------------------
  56. // INITIALIZATION
  57. LLAvatarAppearance() = delete; // No default constructor allowed
  58. LLAvatarAppearance(LLWearableData* wearable_data);
  59. ~LLAvatarAppearance() override;
  60. // Initializes static members
  61. static void initClass(const std::string& lad_file = LLStringUtil::null,
  62. const std::string& skel_file = LLStringUtil::null);
  63. // Cleanup data that is only initialised once per class.
  64. static void cleanupClass();
  65. // Called after construction to initialize the instance:
  66. virtual void initInstance();
  67. virtual bool loadSkeletonNode();
  68. bool loadMeshNodes();
  69. bool loadLayersets();
  70. //-------------------------------------------------------------------------
  71. // INHERITED (LLCharacter interface and related)
  72. public:
  73. LLJoint* getCharacterJoint(U32 num) override;
  74. LL_INLINE const char* getAnimationPrefix() override
  75. {
  76. return "avatar";
  77. }
  78. LLVector3 getVolumePos(S32 joint_index, LLVector3& volume_offset) override;
  79. LLJoint* findCollisionVolume(S32 volume_id) override;
  80. S32 getCollisionVolumeID(std::string& name) override;
  81. LLPolyMesh* getHeadMesh() override;
  82. LLPolyMesh* getUpperBodyMesh() override;
  83. LLPolyMesh* getMesh(S32 which) override;
  84. //-------------------------------------------------------------------------
  85. // STATE
  86. public:
  87. // True if this avatar is for this viewer's agent
  88. LL_INLINE virtual bool isSelf() const { return false; }
  89. // True if this avatar is for this viewer's agent and it is valid
  90. LL_INLINE virtual bool isValid() const { return false; }
  91. virtual bool isUsingServerBakes() const = 0;
  92. virtual bool isUsingLocalAppearance() const = 0;
  93. virtual bool isEditingAppearance() const = 0;
  94. LL_INLINE bool isBuilt() const { return mIsBuilt; }
  95. //-------------------------------------------------------------------------
  96. // SKELETON
  97. protected:
  98. virtual LLAvatarJoint* createAvatarJoint() = 0;
  99. virtual LLAvatarJointMesh* createAvatarJointMesh() = 0;
  100. void makeJointAliases(LLAvatarBoneInfo* bone_info);
  101. public:
  102. LL_INLINE F32 getPelvisToFoot() const { return mPelvisToFoot; }
  103. LL_INLINE LLJoint* getRootJoint() override { return mRoot; }
  104. virtual void computeBodySize(bool force = false);
  105. typedef std::vector<LLAvatarJoint*> avatar_joint_list_t;
  106. LL_INLINE const avatar_joint_list_t& getSkeleton() { return mSkeleton; }
  107. const joint_alias_map_t& getJointAliases();
  108. LLJoint* getSkeletonJoint(S32 joint_num);
  109. protected:
  110. static bool parseSkeletonFile(const std::string& filename,
  111. LLXmlTree& skel_xml_tree);
  112. virtual void buildCharacter();
  113. virtual bool loadAvatar();
  114. virtual void bodySizeChanged() = 0;
  115. bool setupBone(const LLAvatarBoneInfo* info, LLJoint* parent,
  116. S32& current_volume_num, S32& current_joint_num);
  117. bool allocateCharacterJoints(U32 num);
  118. bool buildSkeleton(const LLAvatarSkeletonInfo* info);
  119. void clearSkeleton();
  120. // Pelvis height adjustment members.
  121. public:
  122. void addPelvisFixup(F32 fixup, const LLUUID& mesh_id);
  123. void removePelvisFixup(const LLUUID& mesh_id);
  124. bool hasPelvisFixup(F32& fixup, LLUUID& mesh_id) const;
  125. bool hasPelvisFixup(F32& fixup) const;
  126. public:
  127. LLVector3 mHeadOffset; // current head position
  128. LLAvatarJoint* mRoot;
  129. typedef flat_hmap<U32, LLJoint*> joint_map_t;
  130. joint_map_t mJointMap;
  131. LLVector3 mBodySize;
  132. LLVector3 mAvatarOffset;
  133. protected:
  134. // State of deferred character building
  135. bool mIsBuilt;
  136. F32 mPelvisToFoot;
  137. avatar_joint_list_t mSkeleton;
  138. joint_alias_map_t mJointAliasMap;
  139. LLVector3OverrideMap mPelvisFixups;
  140. // Cached pointers to well known joints
  141. public:
  142. LLJoint* mPelvisp;
  143. LLJoint* mTorsop;
  144. LLJoint* mChestp;
  145. LLJoint* mNeckp;
  146. LLJoint* mHeadp;
  147. LLJoint* mSkullp;
  148. LLJoint* mEyeLeftp;
  149. LLJoint* mEyeRightp;
  150. LLJoint* mHipLeftp;
  151. LLJoint* mHipRightp;
  152. LLJoint* mKneeLeftp;
  153. LLJoint* mKneeRightp;
  154. LLJoint* mAnkleLeftp;
  155. LLJoint* mAnkleRightp;
  156. LLJoint* mFootLeftp;
  157. LLJoint* mFootRightp;
  158. LLJoint* mWristLeftp;
  159. LLJoint* mWristRightp;
  160. // XML parse tree
  161. protected:
  162. static LLAvatarSkeletonInfo* sAvatarSkeletonInfo;
  163. struct LLAvatarXmlInfo;
  164. static LLAvatarXmlInfo* sAvatarXmlInfo;
  165. //-------------------------------------------------------------------------
  166. // RENDERING
  167. public:
  168. // true when for special views and animated objects puppet avatars, which
  169. // are both local to the viewer.
  170. bool mIsDummy;
  171. // Morph masks
  172. public:
  173. virtual void applyMorphMask(U8* tex_data, S32 width, S32 height,
  174. S32 num_components,
  175. LLAvatarAppearanceDefines::EBakedTextureIndex index =
  176. LLAvatarAppearanceDefines::BAKED_NUM_INDICES) = 0;
  177. private:
  178. void addMaskedMorph(LLAvatarAppearanceDefines::EBakedTextureIndex index,
  179. LLVisualParam* morph_target, bool invert,
  180. const std::string& layer);
  181. // Composites
  182. public:
  183. virtual void invalidateComposite(LLTexLayerSet* layerset,
  184. bool upload_result) = 0;
  185. //-------------------------------------------------------------------------
  186. // MESHES
  187. public:
  188. virtual void updateMeshTextures() = 0;
  189. virtual void dirtyMesh() = 0; // Dirty the avatar mesh
  190. LL_INLINE avatar_joint_list_t getMeshLOD() { return mMeshLOD; }
  191. protected:
  192. // Dirty the avatar mesh, with priority
  193. virtual void dirtyMesh(S32 priority) = 0;
  194. protected:
  195. typedef std::multimap<std::string, LLPolyMesh*> polymesh_map_t;
  196. polymesh_map_t mPolyMeshes;
  197. avatar_joint_list_t mMeshLOD;
  198. //-------------------------------------------------------------------------
  199. // APPEARANCE
  200. // Clothing colors (convenience functions to access visual parameters)
  201. public:
  202. void setClothesColor(LLAvatarAppearanceDefines::ETextureIndex te,
  203. const LLColor4& new_color, bool upload_bake);
  204. LLColor4 getClothesColor(LLAvatarAppearanceDefines::ETextureIndex te);
  205. static bool teToColorParams(LLAvatarAppearanceDefines::ETextureIndex te,
  206. U32* param_name);
  207. // Global colors
  208. public:
  209. LLColor4 getGlobalColor(const std::string& color_name) const;
  210. virtual void onGlobalColorChanged(const LLTexGlobalColor* global_color,
  211. bool upload_bake) = 0;
  212. protected:
  213. LLTexGlobalColor* mTexSkinColor;
  214. LLTexGlobalColor* mTexHairColor;
  215. LLTexGlobalColor* mTexEyeColor;
  216. // Visibility
  217. public:
  218. static LLColor4 getDummyColor();
  219. //-------------------------------------------------------------------------
  220. // WEARABLES
  221. public:
  222. LL_INLINE LLWearableData* getWearableData() { return mWearableData; }
  223. LL_INLINE const LLWearableData* getWearableData() const
  224. {
  225. return mWearableData;
  226. }
  227. virtual bool isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex te,
  228. U32 index = 0) const = 0;
  229. virtual bool isWearingWearableType(LLWearableType::EType type) const;
  230. private:
  231. LLWearableData* mWearableData;
  232. //-------------------------------------------------------------------------
  233. // BAKED TEXTURES
  234. public:
  235. LLTexLayerSet* getAvatarLayerSet(LLAvatarAppearanceDefines::EBakedTextureIndex baked_index) const;
  236. protected:
  237. virtual LLTexLayerSet* createTexLayerSet() = 0;
  238. protected:
  239. class LLMaskedMorph;
  240. typedef std::deque<LLMaskedMorph*> morph_list_t;
  241. struct BakedTextureData
  242. {
  243. avatar_joint_mesh_list_t mJointMeshes;
  244. morph_list_t mMaskedMorphs;
  245. LLUUID mLastTextureID;
  246. // Only exists for self
  247. LLTexLayerSet* mTexLayerSet;
  248. LLAvatarAppearanceDefines::ETextureIndex mTextureIndex;
  249. U32 mMaskTexName;
  250. // Stores pointers to the joint meshes that this baked texture deals with
  251. bool mIsLoaded;
  252. bool mIsUsed;
  253. };
  254. typedef std::vector<BakedTextureData> bakedtexturedata_vec_t;
  255. bakedtexturedata_vec_t mBakedTextureDatas;
  256. //-------------------------------------------------------------------------
  257. // PHYSICS
  258. // Collision volumes
  259. protected:
  260. void clearCollisionVolumes();
  261. bool allocateCollisionVolumes(U32 num);
  262. public:
  263. S32 mNumBones;
  264. typedef std::vector<LLAvatarJointCollisionVolume*> collision_volumes_list_t;
  265. collision_volumes_list_t mCollisionVolumes;
  266. //-------------------------------------------------------------------------
  267. // SUPPORT CLASSES
  268. protected:
  269. struct LLAvatarXmlInfo
  270. {
  271. LLAvatarXmlInfo();
  272. ~LLAvatarXmlInfo();
  273. bool parseXmlSkeletonNode(LLXmlTreeNode* root);
  274. bool parseXmlMeshNodes(LLXmlTreeNode* root);
  275. bool parseXmlColorNodes(LLXmlTreeNode* root);
  276. bool parseXmlLayerNodes(LLXmlTreeNode* root);
  277. bool parseXmlDriverNodes(LLXmlTreeNode* root);
  278. bool parseXmlMorphNodes(LLXmlTreeNode* root);
  279. struct LLAvatarMeshInfo
  280. {
  281. // LLPolyMorphTargetInfo stored here:
  282. typedef std::pair<LLViewerVisualParamInfo*, bool> morph_info_pair_t;
  283. typedef std::vector<morph_info_pair_t> morph_info_list_t;
  284. LLAvatarMeshInfo()
  285. : mLOD(0),
  286. mMinPixelArea(.1f)
  287. {
  288. }
  289. ~LLAvatarMeshInfo()
  290. {
  291. for (morph_info_list_t::iterator
  292. iter = mPolyMorphTargetInfoList.begin(),
  293. end = mPolyMorphTargetInfoList.end();
  294. iter != end; ++iter)
  295. {
  296. delete iter->first;
  297. }
  298. mPolyMorphTargetInfoList.clear();
  299. }
  300. std::string mType;
  301. S32 mLOD;
  302. std::string mMeshFileName;
  303. std::string mReferenceMeshName;
  304. F32 mMinPixelArea;
  305. morph_info_list_t mPolyMorphTargetInfoList;
  306. };
  307. typedef std::vector<LLAvatarMeshInfo*> mesh_info_list_t;
  308. mesh_info_list_t mMeshInfoList;
  309. // LLPolySkeletalDistortionInfo stored here:
  310. typedef std::vector<LLViewerVisualParamInfo*> skeletal_distortion_info_list_t;
  311. skeletal_distortion_info_list_t mSkeletalDistortionInfoList;
  312. struct LLAvatarAttachmentInfo
  313. {
  314. LLAvatarAttachmentInfo()
  315. : mGroup(-1),
  316. mAttachmentID(-1),
  317. mPieMenuSlice(-1),
  318. mVisibleFirstPerson(false),
  319. mIsHUDAttachment(false),
  320. mHasPosition(false),
  321. mHasRotation(false)
  322. {
  323. }
  324. std::string mName;
  325. std::string mJointName;
  326. U32 mJointKey;
  327. LLVector3 mPosition;
  328. LLVector3 mRotationEuler;
  329. S32 mGroup;
  330. S32 mAttachmentID;
  331. S32 mPieMenuSlice;
  332. bool mVisibleFirstPerson;
  333. bool mIsHUDAttachment;
  334. bool mHasPosition;
  335. bool mHasRotation;
  336. };
  337. typedef std::vector<LLAvatarAttachmentInfo*> attachment_info_list_t;
  338. attachment_info_list_t mAttachmentInfoList;
  339. LLTexGlobalColorInfo* mTexSkinColorInfo;
  340. LLTexGlobalColorInfo* mTexHairColorInfo;
  341. LLTexGlobalColorInfo* mTexEyeColorInfo;
  342. typedef std::vector<LLTexLayerSetInfo*> layer_info_list_t;
  343. layer_info_list_t mLayerInfoList;
  344. typedef std::vector<LLDriverParamInfo*> driver_info_list_t;
  345. driver_info_list_t mDriverInfoList;
  346. struct LLAvatarMorphInfo
  347. {
  348. LLAvatarMorphInfo()
  349. : mInvert(false)
  350. {
  351. }
  352. std::string mName;
  353. std::string mRegion;
  354. std::string mLayer;
  355. bool mInvert;
  356. };
  357. typedef std::vector<LLAvatarMorphInfo*> morph_info_list_t;
  358. morph_info_list_t mMorphMaskInfoList;
  359. };
  360. class LLMaskedMorph
  361. {
  362. public:
  363. LLMaskedMorph(LLVisualParam* morph_target, bool invert,
  364. const std::string& layer);
  365. public:
  366. LLVisualParam* mMorphTarget;
  367. std::string mLayer;
  368. bool mInvert;
  369. };
  370. };
  371. #endif // LL_AVATAR_APPEARANCE_H