PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llvoavatardefines.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 262 lines | 184 code | 31 blank | 47 comment | 13 complexity | e6aa6b99ad52e2b85caa9fc060b0ae3b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvoavatar.cpp
  3. * @brief Implementation of LLVOAvatar class which is a derivation fo LLViewerObject
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llvoavatardefines.h"
  28. #include "llviewercontrol.h" // gSavedSettings
  29. const S32 LLVOAvatarDefines::SCRATCH_TEX_WIDTH = 512;
  30. const S32 LLVOAvatarDefines::SCRATCH_TEX_HEIGHT = 512;
  31. const S32 LLVOAvatarDefines::IMPOSTOR_PERIOD = 2;
  32. using namespace LLVOAvatarDefines;
  33. /*********************************************************************************
  34. * Edit this function to add/remove/change textures and mesh definitions for avatars.
  35. */
  36. LLVOAvatarDictionary::Textures::Textures()
  37. {
  38. addEntry(TEX_HEAD_BODYPAINT, new TextureEntry("head_bodypaint", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_SKIN));
  39. addEntry(TEX_UPPER_SHIRT, new TextureEntry("upper_shirt", TRUE, BAKED_NUM_INDICES, "UIImgDefaultShirtUUID", LLWearableType::WT_SHIRT));
  40. addEntry(TEX_LOWER_PANTS, new TextureEntry("lower_pants", TRUE, BAKED_NUM_INDICES, "UIImgDefaultPantsUUID", LLWearableType::WT_PANTS));
  41. addEntry(TEX_EYES_IRIS, new TextureEntry("eyes_iris", TRUE, BAKED_NUM_INDICES, "UIImgDefaultEyesUUID", LLWearableType::WT_EYES));
  42. addEntry(TEX_HAIR, new TextureEntry("hair_grain", TRUE, BAKED_NUM_INDICES, "UIImgDefaultHairUUID", LLWearableType::WT_HAIR));
  43. addEntry(TEX_UPPER_BODYPAINT, new TextureEntry("upper_bodypaint", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_SKIN));
  44. addEntry(TEX_LOWER_BODYPAINT, new TextureEntry("lower_bodypaint", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_SKIN));
  45. addEntry(TEX_LOWER_SHOES, new TextureEntry("lower_shoes", TRUE, BAKED_NUM_INDICES, "UIImgDefaultShoesUUID", LLWearableType::WT_SHOES));
  46. addEntry(TEX_LOWER_SOCKS, new TextureEntry("lower_socks", TRUE, BAKED_NUM_INDICES, "UIImgDefaultSocksUUID", LLWearableType::WT_SOCKS));
  47. addEntry(TEX_UPPER_JACKET, new TextureEntry("upper_jacket", TRUE, BAKED_NUM_INDICES, "UIImgDefaultJacketUUID", LLWearableType::WT_JACKET));
  48. addEntry(TEX_LOWER_JACKET, new TextureEntry("lower_jacket", TRUE, BAKED_NUM_INDICES, "UIImgDefaultJacketUUID", LLWearableType::WT_JACKET));
  49. addEntry(TEX_UPPER_GLOVES, new TextureEntry("upper_gloves", TRUE, BAKED_NUM_INDICES, "UIImgDefaultGlovesUUID", LLWearableType::WT_GLOVES));
  50. addEntry(TEX_UPPER_UNDERSHIRT, new TextureEntry("upper_undershirt", TRUE, BAKED_NUM_INDICES, "UIImgDefaultUnderwearUUID", LLWearableType::WT_UNDERSHIRT));
  51. addEntry(TEX_LOWER_UNDERPANTS, new TextureEntry("lower_underpants", TRUE, BAKED_NUM_INDICES, "UIImgDefaultUnderwearUUID", LLWearableType::WT_UNDERPANTS));
  52. addEntry(TEX_SKIRT, new TextureEntry("skirt", TRUE, BAKED_NUM_INDICES, "UIImgDefaultSkirtUUID", LLWearableType::WT_SKIRT));
  53. addEntry(TEX_LOWER_ALPHA, new TextureEntry("lower_alpha", TRUE, BAKED_NUM_INDICES, "UIImgDefaultAlphaUUID", LLWearableType::WT_ALPHA));
  54. addEntry(TEX_UPPER_ALPHA, new TextureEntry("upper_alpha", TRUE, BAKED_NUM_INDICES, "UIImgDefaultAlphaUUID", LLWearableType::WT_ALPHA));
  55. addEntry(TEX_HEAD_ALPHA, new TextureEntry("head_alpha", TRUE, BAKED_NUM_INDICES, "UIImgDefaultAlphaUUID", LLWearableType::WT_ALPHA));
  56. addEntry(TEX_EYES_ALPHA, new TextureEntry("eyes_alpha", TRUE, BAKED_NUM_INDICES, "UIImgDefaultAlphaUUID", LLWearableType::WT_ALPHA));
  57. addEntry(TEX_HAIR_ALPHA, new TextureEntry("hair_alpha", TRUE, BAKED_NUM_INDICES, "UIImgDefaultAlphaUUID", LLWearableType::WT_ALPHA));
  58. addEntry(TEX_HEAD_TATTOO, new TextureEntry("head_tattoo", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_TATTOO));
  59. addEntry(TEX_UPPER_TATTOO, new TextureEntry("upper_tattoo", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_TATTOO));
  60. addEntry(TEX_LOWER_TATTOO, new TextureEntry("lower_tattoo", TRUE, BAKED_NUM_INDICES, "", LLWearableType::WT_TATTOO));
  61. addEntry(TEX_HEAD_BAKED, new TextureEntry("head-baked", FALSE, BAKED_HEAD));
  62. addEntry(TEX_UPPER_BAKED, new TextureEntry("upper-baked", FALSE, BAKED_UPPER));
  63. addEntry(TEX_LOWER_BAKED, new TextureEntry("lower-baked", FALSE, BAKED_LOWER));
  64. addEntry(TEX_EYES_BAKED, new TextureEntry("eyes-baked", FALSE, BAKED_EYES));
  65. addEntry(TEX_HAIR_BAKED, new TextureEntry("hair-baked", FALSE, BAKED_HAIR));
  66. addEntry(TEX_SKIRT_BAKED, new TextureEntry("skirt-baked", FALSE, BAKED_SKIRT));
  67. }
  68. LLVOAvatarDictionary::BakedTextures::BakedTextures()
  69. {
  70. // Baked textures
  71. addEntry(BAKED_HEAD, new BakedEntry(TEX_HEAD_BAKED,
  72. "head", "a4b9dc38-e13b-4df9-b284-751efb0566ff",
  73. 3, TEX_HEAD_BODYPAINT, TEX_HEAD_TATTOO, TEX_HEAD_ALPHA,
  74. 5, LLWearableType::WT_SHAPE, LLWearableType::WT_SKIN, LLWearableType::WT_HAIR, LLWearableType::WT_TATTOO, LLWearableType::WT_ALPHA));
  75. addEntry(BAKED_UPPER, new BakedEntry(TEX_UPPER_BAKED,
  76. "upper_body", "5943ff64-d26c-4a90-a8c0-d61f56bd98d4",
  77. 7, TEX_UPPER_SHIRT,TEX_UPPER_BODYPAINT, TEX_UPPER_JACKET,
  78. TEX_UPPER_GLOVES, TEX_UPPER_UNDERSHIRT, TEX_UPPER_TATTOO, TEX_UPPER_ALPHA,
  79. 8, LLWearableType::WT_SHAPE, LLWearableType::WT_SKIN, LLWearableType::WT_SHIRT, LLWearableType::WT_JACKET, LLWearableType::WT_GLOVES, LLWearableType::WT_UNDERSHIRT, LLWearableType::WT_TATTOO, LLWearableType::WT_ALPHA));
  80. addEntry(BAKED_LOWER, new BakedEntry(TEX_LOWER_BAKED,
  81. "lower_body", "2944ee70-90a7-425d-a5fb-d749c782ed7d",
  82. 8, TEX_LOWER_PANTS,TEX_LOWER_BODYPAINT,TEX_LOWER_SHOES, TEX_LOWER_SOCKS,
  83. TEX_LOWER_JACKET, TEX_LOWER_UNDERPANTS, TEX_LOWER_TATTOO, TEX_LOWER_ALPHA,
  84. 9, LLWearableType::WT_SHAPE, LLWearableType::WT_SKIN, LLWearableType::WT_PANTS, LLWearableType::WT_SHOES, LLWearableType::WT_SOCKS, LLWearableType::WT_JACKET, LLWearableType::WT_UNDERPANTS, LLWearableType::WT_TATTOO, LLWearableType::WT_ALPHA));
  85. addEntry(BAKED_EYES, new BakedEntry(TEX_EYES_BAKED,
  86. "eyes", "27b1bc0f-979f-4b13-95fe-b981c2ba9788",
  87. 2, TEX_EYES_IRIS, TEX_EYES_ALPHA,
  88. 2, LLWearableType::WT_EYES, LLWearableType::WT_ALPHA));
  89. addEntry(BAKED_SKIRT, new BakedEntry(TEX_SKIRT_BAKED,
  90. "skirt", "03e7e8cb-1368-483b-b6f3-74850838ba63",
  91. 1, TEX_SKIRT,
  92. 1, LLWearableType::WT_SKIRT));
  93. addEntry(BAKED_HAIR, new BakedEntry(TEX_HAIR_BAKED,
  94. "hair", "a60e85a9-74e8-48d8-8a2d-8129f28d9b61",
  95. 2, TEX_HAIR, TEX_HAIR_ALPHA,
  96. 2, LLWearableType::WT_HAIR, LLWearableType::WT_ALPHA));
  97. }
  98. LLVOAvatarDictionary::Meshes::Meshes()
  99. {
  100. // Meshes
  101. addEntry(MESH_ID_HAIR, new MeshEntry(BAKED_HAIR, "hairMesh", 6, LLViewerJoint::PN_4));
  102. addEntry(MESH_ID_HEAD, new MeshEntry(BAKED_HEAD, "headMesh", 5, LLViewerJoint::PN_5));
  103. addEntry(MESH_ID_EYELASH, new MeshEntry(BAKED_HEAD, "eyelashMesh", 1, LLViewerJoint::PN_0)); // no baked mesh associated currently
  104. addEntry(MESH_ID_UPPER_BODY, new MeshEntry(BAKED_UPPER, "upperBodyMesh", 5, LLViewerJoint::PN_1));
  105. addEntry(MESH_ID_LOWER_BODY, new MeshEntry(BAKED_LOWER, "lowerBodyMesh", 5, LLViewerJoint::PN_2));
  106. addEntry(MESH_ID_EYEBALL_LEFT, new MeshEntry(BAKED_EYES, "eyeBallLeftMesh", 2, LLViewerJoint::PN_3));
  107. addEntry(MESH_ID_EYEBALL_RIGHT, new MeshEntry(BAKED_EYES, "eyeBallRightMesh", 2, LLViewerJoint::PN_3));
  108. addEntry(MESH_ID_SKIRT, new MeshEntry(BAKED_SKIRT, "skirtMesh", 5, LLViewerJoint::PN_5));
  109. }
  110. /*
  111. *
  112. *********************************************************************************/
  113. LLVOAvatarDictionary::LLVOAvatarDictionary()
  114. {
  115. createAssociations();
  116. }
  117. //virtual
  118. LLVOAvatarDictionary::~LLVOAvatarDictionary()
  119. {
  120. }
  121. // Baked textures are composites of textures; for each such composited texture,
  122. // map it to the baked texture.
  123. void LLVOAvatarDictionary::createAssociations()
  124. {
  125. for (BakedTextures::const_iterator iter = mBakedTextures.begin(); iter != mBakedTextures.end(); iter++)
  126. {
  127. const EBakedTextureIndex baked_index = (iter->first);
  128. const BakedEntry *dict = (iter->second);
  129. // For each texture that this baked texture index affects, associate those textures
  130. // with this baked texture index.
  131. for (texture_vec_t::const_iterator local_texture_iter = dict->mLocalTextures.begin();
  132. local_texture_iter != dict->mLocalTextures.end();
  133. local_texture_iter++)
  134. {
  135. const ETextureIndex local_texture_index = (ETextureIndex) *local_texture_iter;
  136. mTextures[local_texture_index]->mIsUsedByBakedTexture = true;
  137. mTextures[local_texture_index]->mBakedTextureIndex = baked_index;
  138. }
  139. }
  140. }
  141. LLVOAvatarDictionary::TextureEntry::TextureEntry(const std::string &name,
  142. bool is_local_texture,
  143. EBakedTextureIndex baked_texture_index,
  144. const std::string &default_image_name,
  145. LLWearableType::EType wearable_type) :
  146. LLDictionaryEntry(name),
  147. mIsLocalTexture(is_local_texture),
  148. mIsBakedTexture(!is_local_texture),
  149. mIsUsedByBakedTexture(baked_texture_index != BAKED_NUM_INDICES),
  150. mBakedTextureIndex(baked_texture_index),
  151. mDefaultImageName(default_image_name),
  152. mWearableType(wearable_type)
  153. {
  154. }
  155. LLVOAvatarDictionary::MeshEntry::MeshEntry(EBakedTextureIndex baked_index,
  156. const std::string &name,
  157. U8 level,
  158. LLViewerJoint::PickName pick) :
  159. LLDictionaryEntry(name),
  160. mBakedID(baked_index),
  161. mLOD(level),
  162. mPickName(pick)
  163. {
  164. }
  165. LLVOAvatarDictionary::BakedEntry::BakedEntry(ETextureIndex tex_index,
  166. const std::string &name,
  167. const std::string &hash_name,
  168. U32 num_local_textures,
  169. ... ) :
  170. LLDictionaryEntry(name),
  171. mWearablesHashID(LLUUID(hash_name)),
  172. mTextureIndex(tex_index)
  173. {
  174. va_list argp;
  175. va_start(argp, num_local_textures);
  176. // Read in local textures
  177. for (U8 i=0; i < num_local_textures; i++)
  178. {
  179. ETextureIndex t = (ETextureIndex)va_arg(argp,int);
  180. mLocalTextures.push_back(t);
  181. }
  182. // Read in number of wearables
  183. const U32 num_wearables = (U32)va_arg(argp,int);
  184. // Read in wearables
  185. for (U8 i=0; i < num_wearables; i++)
  186. {
  187. LLWearableType::EType t = (LLWearableType::EType)va_arg(argp,int);
  188. mWearables.push_back(t);
  189. }
  190. }
  191. // static
  192. ETextureIndex LLVOAvatarDictionary::bakedToLocalTextureIndex(EBakedTextureIndex index)
  193. {
  194. return LLVOAvatarDictionary::getInstance()->getBakedTexture(index)->mTextureIndex;
  195. }
  196. //static
  197. EBakedTextureIndex LLVOAvatarDictionary::findBakedByRegionName(std::string name)
  198. {
  199. U8 index = 0;
  200. while (index < BAKED_NUM_INDICES)
  201. {
  202. const BakedEntry *be = LLVOAvatarDictionary::getInstance()->getBakedTexture((EBakedTextureIndex) index);
  203. if (be && be->mName.compare(name) == 0)
  204. {
  205. // baked texture found
  206. return (EBakedTextureIndex) index;
  207. }
  208. index++;
  209. }
  210. // baked texture could not be found
  211. return BAKED_NUM_INDICES;
  212. }
  213. //static
  214. const LLUUID LLVOAvatarDictionary::getDefaultTextureImageID(ETextureIndex index)
  215. {
  216. const TextureEntry *texture_dict = getInstance()->getTexture(index);
  217. const std::string &default_image_name = texture_dict->mDefaultImageName;
  218. if (default_image_name == "")
  219. {
  220. return IMG_DEFAULT_AVATAR;
  221. }
  222. else
  223. {
  224. return LLUUID(gSavedSettings.getString(default_image_name));
  225. }
  226. }
  227. // static
  228. LLWearableType::EType LLVOAvatarDictionary::getTEWearableType(ETextureIndex index )
  229. {
  230. return getInstance()->getTexture(index)->mWearableType;
  231. }