llfloateravatartextures.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /**
  2. * @file llfloateravatartextures.cpp
  3. * @brief Debugging view showing underlying avatar textures and baked textures.
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewergpl$
  6. *
  7. * Copyright (c) 2006-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. #include "llviewerprecompiledheaders.h"
  33. #include "llfloateravatartextures.h"
  34. #include "imageids.h"
  35. #include "llcachename.h"
  36. #include "llspinctrl.h"
  37. #include "lltexturectrl.h"
  38. #include "lluictrlfactory.h"
  39. #include "llagent.h"
  40. #include "llagentwearables.h"
  41. #include "llappviewer.h" // For gFrameTimeSeconds
  42. //MK
  43. #include "mkrlinterface.h"
  44. //mk
  45. #include "llviewermenu.h"
  46. #include "llviewerobjectlist.h"
  47. #include "llvoavatarself.h"
  48. using namespace LLAvatarAppearanceDefines;
  49. LLFloaterAvatarTextures::instances_map_t LLFloaterAvatarTextures::sInstances;
  50. //static
  51. LLFloaterAvatarTextures* LLFloaterAvatarTextures::show(const LLUUID& id)
  52. {
  53. LLFloaterAvatarTextures* self;
  54. if (sInstances.count(id))
  55. {
  56. self = sInstances[id];
  57. self->open();
  58. }
  59. else
  60. {
  61. self = new LLFloaterAvatarTextures(id);
  62. }
  63. return self;
  64. }
  65. LLFloaterAvatarTextures::LLFloaterAvatarTextures(const LLUUID& id)
  66. : mID(id),
  67. mLastRefresh(0.f),
  68. mShallClose(false)
  69. {
  70. sInstances[id] = this;
  71. LLUICtrlFactory::getInstance()->buildFloater(this,
  72. "floater_avatar_textures.xml");
  73. }
  74. LLFloaterAvatarTextures::~LLFloaterAvatarTextures()
  75. {
  76. sInstances.erase(mID);
  77. }
  78. bool LLFloaterAvatarTextures::postBuild()
  79. {
  80. mTitle = getTitle();
  81. for (U32 i = 0; i < TEX_NUM_INDICES; ++i)
  82. {
  83. const LLAvatarAppearanceDictionary::TextureEntry* te =
  84. gAvatarAppDictp->getTexture(ETextureIndex(i));
  85. if (te)
  86. {
  87. LLTextureCtrl* ctrl = getChild<LLTextureCtrl>(te->mName.c_str());
  88. if (ctrl)
  89. {
  90. ctrl->setCaptionAlwaysEnabled();
  91. }
  92. mTextures[i] = ctrl;
  93. }
  94. else
  95. {
  96. mTextures[i] = NULL;
  97. }
  98. }
  99. childSetAction("Dump", onClickDump, this);
  100. childSetAction("Rebake", onClickRebake, this);
  101. mSpinLayer = getChild<LLSpinCtrl>("layer");
  102. if (mID == gAgentID)
  103. {
  104. mSpinLayer->setCommitCallback(onCommitLayer);
  105. mSpinLayer->setCallbackUserData(this);
  106. }
  107. else
  108. {
  109. mSpinLayer->setEnabled(false);
  110. }
  111. center();
  112. gFloaterViewp->adjustToFitScreen(this);
  113. refresh();
  114. return true;
  115. }
  116. void LLFloaterAvatarTextures::draw()
  117. {
  118. if (gFrameTimeSeconds - mLastRefresh > 1.f)
  119. {
  120. refresh();
  121. }
  122. if (mShallClose)
  123. {
  124. close();
  125. }
  126. else
  127. {
  128. LLFloater::draw();
  129. }
  130. }
  131. //static
  132. S32 LLFloaterAvatarTextures::getTextureIds(LLVOAvatar* avatarp,
  133. ETextureIndex te,
  134. std::string& name, uuid_vec_t& ids)
  135. {
  136. ids.clear();
  137. LLWearableType::EType wtype = LLWearableType::WT_NONE;
  138. const LLAvatarAppearanceDictionary::TextureEntry* tex_entry =
  139. gAvatarAppDictp->getTexture(te);
  140. if (tex_entry)
  141. {
  142. wtype = tex_entry->mWearableType;
  143. if (tex_entry->mIsLocalTexture && avatarp->isSelf())
  144. {
  145. U32 count = gAgentWearables.getWearableCount(wtype);
  146. for (U32 layer = 0; layer < count; ++layer)
  147. {
  148. LLViewerWearable* wearable =
  149. gAgentWearables.getViewerWearable(wtype, layer);
  150. if (wearable)
  151. {
  152. LLLocalTextureObject* lto =
  153. wearable->getLocalTextureObject(te);
  154. if (lto)
  155. {
  156. ids.push_back(lto->getID());
  157. }
  158. }
  159. }
  160. }
  161. else
  162. {
  163. ids.push_back(avatarp->getTE(te)->getID());
  164. }
  165. name = tex_entry->mName;
  166. }
  167. else
  168. {
  169. name.clear();
  170. }
  171. while (ids.size() < 5)
  172. {
  173. ids.push_back(IMG_DEFAULT_AVATAR);
  174. }
  175. if (wtype == LLWearableType::WT_INVALID)
  176. {
  177. // Easier to test (since negative and thus <= WT_EYES) for refresh()
  178. wtype = LLWearableType::WT_NONE;
  179. }
  180. return (S32)wtype;
  181. }
  182. void LLFloaterAvatarTextures::refresh()
  183. {
  184. bool can_view = gAgent.isGodlikeWithoutAdminMenuFakery() ||
  185. (mID == gAgentID && enable_avatar_textures(NULL));
  186. LLVOAvatar* avatarp = gObjectList.findAvatar(mID);
  187. if (!can_view || !avatarp)
  188. {
  189. mShallClose = true;
  190. return;
  191. }
  192. std::string title = mTitle;
  193. //MK
  194. if (mID == gAgentID || !gRLenabled ||
  195. !(gRLInterface.mContainsShownames ||
  196. gRLInterface.mContainsShownametags))
  197. //mk
  198. {
  199. std::string fullname;
  200. if (gCacheNamep &&
  201. gCacheNamep->getFullName(avatarp->getID(), fullname))
  202. {
  203. title += ": " + fullname;
  204. }
  205. else
  206. {
  207. title += ": " + mID.asString();
  208. }
  209. }
  210. setTitle(title);
  211. std::string te_name;
  212. uuid_vec_t ids;
  213. U32 layer = llmin((U32)mSpinLayer->get(), 4U);
  214. for (U32 i = 0; i < TEX_NUM_INDICES; ++i)
  215. {
  216. LLTextureCtrl* ctrl = mTextures[i];
  217. if (!ctrl) continue;
  218. S32 type = getTextureIds(avatarp, ETextureIndex(i), te_name, ids);
  219. const LLUUID& id =
  220. // There is only one layer for baked textures and body parts...
  221. type <= (S32)LLWearableType::WT_EYES ? ids[0] : ids[layer];
  222. if (id == IMG_DEFAULT_AVATAR)
  223. {
  224. ctrl->setImageAssetID(LLUUID::null);
  225. ctrl->setToolTip("");
  226. }
  227. else
  228. {
  229. ctrl->setImageAssetID(id);
  230. ctrl->setToolTip(te_name + ": " + id.asString());
  231. }
  232. ctrl->setEnabled(false);
  233. }
  234. mLastRefresh = gFrameTimeSeconds;
  235. }
  236. //static
  237. void LLFloaterAvatarTextures::onClickDump(void* data)
  238. {
  239. LLFloaterAvatarTextures* self = (LLFloaterAvatarTextures*)data;
  240. if (!self) return;
  241. LLVOAvatar* avatarp = gObjectList.findAvatar(self->mID);
  242. bool can_view = gAgent.isGodlikeWithoutAdminMenuFakery() ||
  243. (self->mID == gAgentID && enable_avatar_textures(NULL));
  244. if (can_view && avatarp)
  245. {
  246. std::string te_name;
  247. uuid_vec_t ids;
  248. for (S32 i = 0, count = avatarp->getNumTEs(); i < count; ++i)
  249. {
  250. getTextureIds(avatarp, ETextureIndex(i), te_name, ids);
  251. for (U32 layer = 0; layer < 5; ++layer)
  252. {
  253. const LLUUID& id = ids[layer];
  254. if (id != IMG_DEFAULT_AVATAR)
  255. {
  256. llinfos << "Avatar texture " << te_name << ", layer "
  257. << layer << ". Id: " << id << llendl;
  258. }
  259. }
  260. }
  261. }
  262. }
  263. //static
  264. void LLFloaterAvatarTextures::onClickRebake(void* data)
  265. {
  266. LLFloaterAvatarTextures* self = (LLFloaterAvatarTextures*)data;
  267. LLVOAvatar* avatarp = gObjectList.findAvatar(self->mID);
  268. if (self && avatarp)
  269. {
  270. if (avatarp == gAgentAvatarp)
  271. {
  272. handle_rebake_textures(NULL);
  273. }
  274. else
  275. {
  276. handle_refresh_avatar(avatarp, false);
  277. }
  278. }
  279. }
  280. void LLFloaterAvatarTextures::onCommitLayer(LLUICtrl*, void* userdata)
  281. {
  282. LLFloaterAvatarTextures* self = (LLFloaterAvatarTextures*)userdata;
  283. if (self)
  284. {
  285. self->refresh();
  286. }
  287. }