PageRenderTime 476ms CodeModel.GetById 201ms app.highlight 19ms RepoModel.GetById 253ms app.codeStats 0ms

/indra/newview/llfloateravatartextures.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 201 lines | 156 code | 17 blank | 28 comment | 26 complexity | 7f37b7f48b795beb69285ac64cdc632d MD5 | raw file
  1/** 
  2 * @file llfloateravatartextures.cpp
  3 * @brief Debugging view showing underlying avatar textures and baked textures.
  4 *
  5 * $LicenseInfo:firstyear=2006&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 "llfloateravatartextures.h"
 29
 30// library headers
 31#include "llavatarnamecache.h"
 32
 33#include "llagent.h"
 34#include "llagentwearables.h"
 35#include "lltexturectrl.h"
 36#include "lluictrlfactory.h"
 37#include "llviewerobjectlist.h"
 38#include "llvoavatarself.h"
 39
 40using namespace LLVOAvatarDefines;
 41
 42LLFloaterAvatarTextures::LLFloaterAvatarTextures(const LLSD& id)
 43  : LLFloater(id),
 44	mID(id.asUUID())
 45{
 46}
 47
 48LLFloaterAvatarTextures::~LLFloaterAvatarTextures()
 49{
 50}
 51
 52BOOL LLFloaterAvatarTextures::postBuild()
 53{
 54	for (U32 i=0; i < TEX_NUM_INDICES; i++)
 55	{
 56		const std::string tex_name = LLVOAvatarDictionary::getInstance()->getTexture(ETextureIndex(i))->mName;
 57		mTextures[i] = getChild<LLTextureCtrl>(tex_name);
 58	}
 59	mTitle = getTitle();
 60
 61	childSetAction("Dump", onClickDump, this);
 62
 63	refresh();
 64	return TRUE;
 65}
 66
 67void LLFloaterAvatarTextures::draw()
 68{
 69	refresh();
 70	LLFloater::draw();
 71}
 72
 73static void update_texture_ctrl(LLVOAvatar* avatarp,
 74								 LLTextureCtrl* ctrl,
 75								 ETextureIndex te)
 76{
 77	LLUUID id = IMG_DEFAULT_AVATAR;
 78	const LLVOAvatarDictionary::TextureEntry* tex_entry = LLVOAvatarDictionary::getInstance()->getTexture(te);
 79	if (tex_entry->mIsLocalTexture)
 80	{
 81		if (avatarp->isSelf())
 82		{
 83			const LLWearableType::EType wearable_type = tex_entry->mWearableType;
 84			LLWearable *wearable = gAgentWearables.getWearable(wearable_type, 0);
 85			if (wearable)
 86			{
 87				LLLocalTextureObject *lto = wearable->getLocalTextureObject(te);
 88				if (lto)
 89				{
 90					id = lto->getID();
 91				}
 92			}
 93		}
 94	}
 95	else
 96	{
 97		id = avatarp->getTE(te)->getID();
 98	}
 99	//id = avatarp->getTE(te)->getID();
100	if (id == IMG_DEFAULT_AVATAR)
101	{
102		ctrl->setImageAssetID(LLUUID::null);
103		ctrl->setToolTip(tex_entry->mName + " : " + std::string("IMG_DEFAULT_AVATAR"));
104	}
105	else
106	{
107		ctrl->setImageAssetID(id);
108		ctrl->setToolTip(tex_entry->mName + " : " + id.asString());
109	}
110}
111
112static LLVOAvatar* find_avatar(const LLUUID& id)
113{
114	LLViewerObject *obj = gObjectList.findObject(id);
115	while (obj && obj->isAttachment())
116	{
117		obj = (LLViewerObject *)obj->getParent();
118	}
119
120	if (obj && obj->isAvatar())
121	{
122		return (LLVOAvatar*)obj;
123	}
124	else
125	{
126		return NULL;
127	}
128}
129
130void LLFloaterAvatarTextures::refresh()
131{
132	if (gAgent.isGodlike())
133	{
134		LLVOAvatar *avatarp = find_avatar(mID);
135		if (avatarp)
136		{
137			LLAvatarName av_name;
138			if (LLAvatarNameCache::get(avatarp->getID(), &av_name))
139			{
140				setTitle(mTitle + ": " + av_name.getCompleteName());
141			}
142			for (U32 i=0; i < TEX_NUM_INDICES; i++)
143			{
144				update_texture_ctrl(avatarp, mTextures[i], ETextureIndex(i));
145			}
146		}
147		else
148		{
149			setTitle(mTitle + ": " + getString("InvalidAvatar") + " (" + mID.asString() + ")");
150		}
151	}
152}
153
154// static
155void LLFloaterAvatarTextures::onClickDump(void* data)
156{
157	if (gAgent.isGodlike())
158	{
159		const LLVOAvatarSelf* avatarp = gAgentAvatarp;
160		if (!avatarp) return;
161		for (S32 i = 0; i < avatarp->getNumTEs(); i++)
162		{
163			const LLTextureEntry* te = avatarp->getTE(i);
164			if (!te) continue;
165
166			const LLVOAvatarDictionary::TextureEntry* tex_entry = LLVOAvatarDictionary::getInstance()->getTexture((ETextureIndex)(i));
167			if (!tex_entry)
168				continue;
169
170			if (LLVOAvatar::isIndexLocalTexture((ETextureIndex)i))
171			{
172				LLUUID id = IMG_DEFAULT_AVATAR;
173				LLWearableType::EType wearable_type = LLVOAvatarDictionary::getInstance()->getTEWearableType((ETextureIndex)i);
174				if (avatarp->isSelf())
175				{
176					LLWearable *wearable = gAgentWearables.getWearable(wearable_type, 0);
177					if (wearable)
178					{
179						LLLocalTextureObject *lto = wearable->getLocalTextureObject(i);
180						if (lto)
181						{
182							id = lto->getID();
183						}
184					}
185				}
186				if (id != IMG_DEFAULT_AVATAR)
187				{
188					llinfos << "TE " << i << " name:" << tex_entry->mName << " id:" << id << llendl;
189				}
190				else
191				{
192					llinfos << "TE " << i << " name:" << tex_entry->mName << " id:" << "<DEFAULT>" << llendl;
193				}
194			}
195			else
196			{
197				llinfos << "TE " << i << " name:" << tex_entry->mName << " id:" << te->getID() << llendl;
198			}
199		}
200	}
201}