PageRenderTime 669ms CodeModel.GetById 433ms app.highlight 119ms RepoModel.GetById 112ms app.codeStats 1ms

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