llvoavatardefines.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:12k
源码类别:

游戏引擎

开发平台:

C++ Builder

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