llvoavatarself.cpp 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616
  1. /**
  2. * @file llvoavatarself.cpp
  3. * @brief Implementation of LLVOAvatarSelf class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-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 "llvoavatarself.h"
  34. #include "imageids.h"
  35. #include "llcallbacklist.h"
  36. #include "llcorehttputil.h"
  37. #include "lleconomy.h"
  38. #include "lltrans.h"
  39. #include "llagent.h"
  40. #include "llagentwearables.h"
  41. #include "llapp.h"
  42. #include "llappearancemgr.h"
  43. #include "llappviewer.h" // For gFrameTimeSeconds
  44. #include "lldrawpoolalpha.h"
  45. #include "lleconomy.h"
  46. #include "llfasttimer.h"
  47. #include "llhudeffectspiral.h"
  48. #include "llhudmanager.h"
  49. #include "llinventorybridge.h"
  50. #include "llmeshrepository.h"
  51. #include "hbobjectbackup.h" // For HBObjectBackup::validateAssetPerms()
  52. #include "llpipeline.h"
  53. //MK
  54. #include "mkrlinterface.h"
  55. //mk
  56. #include "llselectmgr.h"
  57. #include "lltoolgrab.h" // For needsRenderBeam
  58. #include "lltoolmgr.h" // For needsRenderBeam
  59. #include "llviewercamera.h"
  60. #include "llviewercontrol.h"
  61. #include "llviewermenu.h"
  62. #include "llviewerobjectlist.h"
  63. #include "llviewerparcelmgr.h"
  64. #include "llviewerstats.h"
  65. #include "llviewerregion.h"
  66. #include "llviewertexlayer.h"
  67. #include "llviewerwearable.h"
  68. #include "llvisualparamhint.h"
  69. #include "llvoavatar.h"
  70. #include "llvovolume.h"
  71. constexpr F32 Z_OFFSET_THROTTLE_DELAY = 1.f; // In seconds
  72. // Globals
  73. LLPointer<LLVOAvatarSelf> gAgentAvatarp = NULL;
  74. LLFrameTimer gAttachmentsTimer;
  75. bool gAttachmentsListDirty = true;
  76. LLPieMenu* gAttachBodyPartPieMenusp[8];
  77. LLPieMenu* gDetachBodyPartPieMenusp[8];
  78. U32 gMaxSelfAttachments = 0;
  79. using namespace LLAvatarAppearanceDefines;
  80. ///////////////////////////////////////////////////////////////////////////////
  81. // Support classes
  82. ///////////////////////////////////////////////////////////////////////////////
  83. struct LocalTextureData
  84. {
  85. LocalTextureData()
  86. : mIsBakedReady(false),
  87. mDiscard(MAX_DISCARD_LEVEL + 1),
  88. mImage(NULL),
  89. mWearableID(IMG_DEFAULT_AVATAR),
  90. mTexEntry(NULL)
  91. {
  92. }
  93. LLPointer<LLViewerFetchedTexture> mImage;
  94. bool mIsBakedReady;
  95. S32 mDiscard;
  96. // UUID of the wearable that this texture belongs to, not of the image
  97. // itself
  98. LLUUID mWearableID;
  99. LLTextureEntry* mTexEntry;
  100. };
  101. ///////////////////////////////////////////////////////////////////////////////
  102. // LLVOAvatarSelf class
  103. ///////////////////////////////////////////////////////////////////////////////
  104. LLVOAvatarSelf::LLVOAvatarSelf(const LLUUID& id, LLViewerRegion* regionp)
  105. : LLVOAvatar(id, regionp),
  106. mInitialBakesLoaded(false),
  107. mScreenp(NULL),
  108. mLastRegionHandle(0),
  109. mRegionCrossingCount(0),
  110. // Value outside legal range, so will always be a mismatch the first time
  111. // through.
  112. mLastHoverOffsetSent(LLVector3(0.f, 0.f, -999.f)),
  113. mAttachmentUpdateEnabled(true),
  114. mAttachmentUpdateExpiry(0.f)
  115. {
  116. LL_DEBUGS("Avatar") << "Marking avatar as self " << id << LL_ENDL;
  117. gAgent.setAvatarObject(this);
  118. gAgentWearables.setAvatarObject(this);
  119. gAttachmentsTimer.reset();
  120. #if 0
  121. mMotionController.mIsSelf = true;
  122. #endif
  123. mOffsetUpdateDelay.stop();
  124. gMaxSelfAttachments =
  125. (U32)llmax(MAX_AGENT_ATTACHMENTS,
  126. LLEconomy::getInstance()->getAttachmentLimit());
  127. mAttachedObjectsVector.reserve(gMaxSelfAttachments);
  128. llinfos << "Maximum number of attachments set to: " << gMaxSelfAttachments
  129. << llendl;
  130. setAttachmentUpdatePeriod(DEFAULT_ATTACHMENT_UPDATE_PERIOD);
  131. }
  132. void LLVOAvatarSelf::initInstance()
  133. {
  134. bool status = true;
  135. // Creates hud joint(mScreen) among other things:
  136. status &= loadAvatarSelf();
  137. // Adds attachment points to mScreen among other things:
  138. LLVOAvatar::initInstance();
  139. for (U32 i = 0; i < BAKED_NUM_INDICES; ++i)
  140. {
  141. mInitialBakeIDs[i].setNull();
  142. }
  143. status &= buildMenus();
  144. if (!status)
  145. {
  146. llerrs << "Unable to load user's avatar" << llendl;
  147. }
  148. mTeleportFinishedSlot =
  149. gViewerParcelMgr.setTPFinishedCallback(boost::bind(&LLVOAvatarSelf::handleTeleportFinished,
  150. this));
  151. scheduleHoverUpdate();
  152. }
  153. //static
  154. bool LLVOAvatarSelf::useAvatarHoverHeight()
  155. {
  156. LLViewerRegion* region = NULL;
  157. if (isAgentAvatarValid())
  158. {
  159. region = gAgentAvatarp->getRegion();
  160. }
  161. return region && region->avatarHoverHeightEnabled();
  162. }
  163. void LLVOAvatarSelf::scheduleHoverUpdate()
  164. {
  165. mOffsetUpdateDelay.start();
  166. mOffsetUpdateDelay.setTimerExpirySec(Z_OFFSET_THROTTLE_DELAY);
  167. }
  168. void LLVOAvatarSelf::setHoverIfRegionEnabled()
  169. {
  170. LLViewerRegion* region = getRegion();
  171. if (!region || region != gAgent.getRegion())
  172. {
  173. mLastHoverOffsetSent = LLVector3(0.f, 0.f, -999.f);
  174. scheduleHoverUpdate(); // retry later...
  175. return;
  176. }
  177. if (region->getFeaturesReceived())
  178. {
  179. if (useAvatarHoverHeight())
  180. {
  181. // Transform avatar Z size offset into altitude (Z) offset
  182. F32 ptf = getPelvisToFoot();
  183. F32 ahh_dividor = ptf > 0.f ? mBodySize.mV[VZ] / ptf : 1.f;
  184. F32 hover =
  185. llclamp(gSavedSettings.getF32("AvatarOffsetZ") / ahh_dividor,
  186. MIN_HOVER_Z, MAX_HOVER_Z);
  187. setHoverOffset(LLVector3(0.f, 0.f, hover));
  188. llinfos << "Set hover height for self from debug setting: "
  189. << hover << "m" << llendl;
  190. }
  191. else
  192. {
  193. setHoverOffset(LLVector3::zero);
  194. if (canUseServerBaking())
  195. {
  196. llwarns_once << "Cannot set Z offset by lack of capability"
  197. << llendl;
  198. }
  199. else
  200. {
  201. llinfos_once << "Avatar Hover Offset disabled or not supported. Falling back to legacy method."
  202. << llendl;
  203. gAgent.sendAgentSetAppearance();
  204. }
  205. }
  206. return;
  207. }
  208. llinfos << "Region or simulator features not yet known, delaying change to hover for self"
  209. << llendl;
  210. if (region)
  211. {
  212. region->setFeaturesReceivedCB(boost::bind(&LLVOAvatarSelf::onSimulatorFeaturesReceived,
  213. this, _1));
  214. }
  215. }
  216. //virtual
  217. void LLVOAvatarSelf::markDead()
  218. {
  219. mBeam = NULL;
  220. LLVOAvatar::markDead();
  221. }
  222. //virtual
  223. bool LLVOAvatarSelf::loadAvatar()
  224. {
  225. bool success = LLVOAvatar::loadAvatar();
  226. // Set all parameters stored directly in the avatar to have the isSelfParam
  227. // to be true: this is used to prevent them from being animated or trigger
  228. // accidental rebakes when we copy params from the wearable to the base
  229. // avatar.
  230. for (LLViewerVisualParam* param =
  231. (LLViewerVisualParam*)getFirstVisualParam();
  232. param; param = (LLViewerVisualParam*)getNextVisualParam())
  233. {
  234. if (param->getWearableType() != LLWearableType::WT_INVALID)
  235. {
  236. param->setIsDummy(true);
  237. }
  238. }
  239. return success;
  240. }
  241. bool LLVOAvatarSelf::loadAvatarSelf()
  242. {
  243. // avatar_skeleton.xml
  244. if (!buildSkeletonSelf(sAvatarSkeletonInfo))
  245. {
  246. llwarns << "Avatar file: buildSkeleton() failed" << llendl;
  247. return false;
  248. }
  249. return true;
  250. }
  251. bool LLVOAvatarSelf::buildSkeletonSelf(const LLAvatarSkeletonInfo* info)
  252. {
  253. // Add special-purpose "screen" joint
  254. mScreenp = new LLViewerJoint("mScreen", NULL);
  255. // For now, put screen at origin, as it is only used during special HUD
  256. // rendering mode
  257. F32 aspect = gViewerCamera.getAspect();
  258. LLVector3 scale(1.f, aspect, 1.f);
  259. mScreenp->setScale(scale);
  260. mScreenp->setWorldPosition(LLVector3::zero);
  261. return true;
  262. }
  263. bool LLVOAvatarSelf::buildMenus()
  264. {
  265. //-------------------------------------------------------------------------
  266. // Build the attach and detach menus
  267. //-------------------------------------------------------------------------
  268. // *TODO: Translate
  269. gAttachBodyPartPieMenusp[0] = new LLPieMenu("More limbs>");
  270. gAttachBodyPartPieMenusp[1] = new LLPieMenu("Right Arm >");
  271. gAttachBodyPartPieMenusp[2] = new LLPieMenu("Head >");
  272. gAttachBodyPartPieMenusp[3] = new LLPieMenu("Left Arm >");
  273. gAttachBodyPartPieMenusp[4] = new LLPieMenu("Head extras>");
  274. gAttachBodyPartPieMenusp[5] = new LLPieMenu("Left Leg >");
  275. gAttachBodyPartPieMenusp[6] = new LLPieMenu("Torso >");
  276. gAttachBodyPartPieMenusp[7] = new LLPieMenu("Right Leg >");
  277. gDetachBodyPartPieMenusp[0] = new LLPieMenu("More limbs>");
  278. gDetachBodyPartPieMenusp[1] = new LLPieMenu("Right Arm >");
  279. gDetachBodyPartPieMenusp[2] = new LLPieMenu("Head >");
  280. gDetachBodyPartPieMenusp[3] = new LLPieMenu("Left Arm >");
  281. gDetachBodyPartPieMenusp[4] = new LLPieMenu("Head extras>");
  282. gDetachBodyPartPieMenusp[5] = new LLPieMenu("Left Leg >");
  283. gDetachBodyPartPieMenusp[6] = new LLPieMenu("Torso >");
  284. gDetachBodyPartPieMenusp[7] = new LLPieMenu("Right Leg >");
  285. LLMenuItemCallGL* item;
  286. for (S32 i = 0; i < 8; ++i)
  287. {
  288. if (gAttachBodyPartPieMenusp[i])
  289. {
  290. gAttachPieMenup->appendPieMenu(gAttachBodyPartPieMenusp[i]);
  291. }
  292. else
  293. {
  294. bool attachment_found = false;
  295. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  296. iter != mAttachmentPoints.end(); )
  297. {
  298. attachment_map_t::iterator curiter = iter++;
  299. LLViewerJointAttachment* attachment = curiter->second;
  300. if (attachment && attachment->getGroup() == i)
  301. {
  302. item = new LLMenuItemCallGL(LLTrans::getString(attachment->getName()),
  303. NULL,
  304. object_selected_and_point_valid);
  305. item->addListener(gMenuHolderp->getListenerByName("Object.AttachToAvatar"),
  306. "on_click", curiter->first);
  307. gAttachPieMenup->append(item);
  308. attachment_found = true;
  309. break;
  310. }
  311. }
  312. if (!attachment_found)
  313. {
  314. gAttachPieMenup->appendSeparator();
  315. }
  316. }
  317. if (gDetachBodyPartPieMenusp[i])
  318. {
  319. gDetachPieMenup->appendPieMenu(gDetachBodyPartPieMenusp[i]);
  320. }
  321. else
  322. {
  323. bool attachment_found = false;
  324. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  325. iter != mAttachmentPoints.end(); )
  326. {
  327. attachment_map_t::iterator curiter = iter++;
  328. LLViewerJointAttachment* attachment = curiter->second;
  329. if (attachment && attachment->getGroup() == i)
  330. {
  331. item = new LLMenuItemCallGL(LLTrans::getString(attachment->getName()),
  332. &handle_detach_from_avatar,
  333. object_attached,
  334. attachment);
  335. gDetachPieMenup->append(item);
  336. attachment_found = true;
  337. break;
  338. }
  339. }
  340. if (!attachment_found)
  341. {
  342. gDetachPieMenup->appendSeparator();
  343. }
  344. }
  345. }
  346. // Add screen attachments
  347. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  348. iter != mAttachmentPoints.end(); )
  349. {
  350. attachment_map_t::iterator curiter = iter++;
  351. LLViewerJointAttachment* attachment = curiter->second;
  352. if (attachment && attachment->getGroup() == 8)
  353. {
  354. std::string pt_name = LLTrans::getString(attachment->getName());
  355. item = new LLMenuItemCallGL(pt_name, NULL,
  356. object_selected_and_point_valid);
  357. item->addListener(gMenuHolderp->getListenerByName("Object.AttachToAvatar"),
  358. "on_click", curiter->first);
  359. gAttachScreenPieMenup->append(item);
  360. item = new LLMenuItemCallGL(pt_name, &handle_detach_from_avatar,
  361. object_attached, attachment);
  362. gDetachScreenPieMenup->append(item);
  363. }
  364. }
  365. for (S32 pass = 0; pass < 2; ++pass)
  366. {
  367. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  368. iter != mAttachmentPoints.end(); )
  369. {
  370. attachment_map_t::iterator curiter = iter++;
  371. LLViewerJointAttachment* attachment = curiter->second;
  372. if (attachment && attachment->getIsHUDAttachment() != (pass == 1))
  373. {
  374. continue;
  375. }
  376. std::string pt_name = LLTrans::getString(attachment->getName());
  377. item = new LLMenuItemCallGL(pt_name,
  378. &handle_detach_from_avatar,
  379. object_attached, &detach_label,
  380. attachment);
  381. gDetachSubMenup->append(item);
  382. }
  383. if (pass == 0)
  384. {
  385. // Insert a separator between non-HUD and HUD attachments
  386. gDetachSubMenup->appendSeparator();
  387. }
  388. }
  389. for (S32 group = 0; group < 8; ++group)
  390. {
  391. // skip over groups that don't have sub menus
  392. if (!gAttachBodyPartPieMenusp[group] ||
  393. !gDetachBodyPartPieMenusp[group])
  394. {
  395. continue;
  396. }
  397. std::multimap<S32, S32> attachment_pie_menu_map;
  398. // Gather up all attachment points assigned to this group, and throw
  399. // into map sorted by pie slice number
  400. for (attachment_map_t::iterator iter = mAttachmentPoints.begin();
  401. iter != mAttachmentPoints.end(); )
  402. {
  403. attachment_map_t::iterator curiter = iter++;
  404. LLViewerJointAttachment* attachment = curiter->second;
  405. if (attachment && attachment->getGroup() == group)
  406. {
  407. // Use multimap to provide a partial order off of the pie slice
  408. // key
  409. S32 pie_index = attachment->getPieSlice();
  410. attachment_pie_menu_map.emplace(pie_index, curiter->first);
  411. }
  412. }
  413. // Add in requested order to pie menu, inserting separators as
  414. // necessary
  415. S32 cur_pie_slice = 0;
  416. for (std::multimap<S32, S32>::iterator attach_it =
  417. attachment_pie_menu_map.begin();
  418. attach_it != attachment_pie_menu_map.end(); ++attach_it)
  419. {
  420. S32 requested_pie_slice = attach_it->first;
  421. S32 attach_index = attach_it->second;
  422. while (cur_pie_slice < requested_pie_slice)
  423. {
  424. gAttachBodyPartPieMenusp[group]->appendSeparator();
  425. gDetachBodyPartPieMenusp[group]->appendSeparator();
  426. ++cur_pie_slice;
  427. }
  428. LLViewerJointAttachment* attachp =
  429. get_ptr_in_map(mAttachmentPoints, attach_index);
  430. if (attachp)
  431. {
  432. std::string pt_name = LLTrans::getString(attachp->getName());
  433. item = new LLMenuItemCallGL(pt_name, NULL,
  434. object_selected_and_point_valid);
  435. gAttachBodyPartPieMenusp[group]->append(item);
  436. item->addListener(gMenuHolderp->getListenerByName("Object.AttachToAvatar"),
  437. "on_click", attach_index);
  438. item = new LLMenuItemCallGL(pt_name,
  439. &handle_detach_from_avatar,
  440. object_attached, attachp);
  441. gDetachBodyPartPieMenusp[group]->append(item);
  442. ++cur_pie_slice;
  443. }
  444. }
  445. }
  446. return true;
  447. }
  448. LLVOAvatarSelf::~LLVOAvatarSelf()
  449. {
  450. markDead();
  451. delete mScreenp;
  452. mScreenp = NULL;
  453. mRegionp = NULL;
  454. }
  455. //virtual
  456. bool LLVOAvatarSelf::updateCharacter()
  457. {
  458. // Update screen joint size
  459. if (mScreenp)
  460. {
  461. F32 aspect = gViewerCamera.getAspect();
  462. LLVector3 scale(1.f, aspect, 1.f);
  463. mScreenp->setScale(scale);
  464. mScreenp->updateWorldMatrixChildren();
  465. resetHUDAttachments();
  466. }
  467. return LLVOAvatar::updateCharacter();
  468. }
  469. //virtual
  470. bool LLVOAvatarSelf::isValid() const
  471. {
  472. return isAgentAvatarValid();
  473. }
  474. //virtual
  475. void LLVOAvatarSelf::idleUpdate(F64 time)
  476. {
  477. if (isAgentAvatarValid())
  478. {
  479. LLVOAvatar::idleUpdate(time);
  480. {
  481. LL_FAST_TIMER(FTM_AVATAR_UPDATE);
  482. idleUpdateTractorBeam();
  483. gAppearanceMgr.checkOutfit();
  484. if (mOffsetUpdateDelay.getStarted() &&
  485. mOffsetUpdateDelay.hasExpired())
  486. {
  487. mOffsetUpdateDelay.stop();
  488. setHoverIfRegionEnabled();
  489. }
  490. }
  491. }
  492. }
  493. //virtual
  494. LLJoint* LLVOAvatarSelf::getJoint(U32 key)
  495. {
  496. LLJoint* jointp = LLVOAvatar::getJoint(key);
  497. if (!jointp && mScreenp)
  498. {
  499. jointp = mScreenp->findJoint(key);
  500. if (jointp)
  501. {
  502. mJointMap[key] = jointp;
  503. }
  504. }
  505. return jointp;
  506. }
  507. //virtual
  508. bool LLVOAvatarSelf::setVisualParamWeight(const LLVisualParam* which_param,
  509. F32 weight, bool upload_bake)
  510. {
  511. if (!which_param)
  512. {
  513. return false;
  514. }
  515. LLViewerVisualParam* param =
  516. (LLViewerVisualParam*)LLCharacter::getVisualParam(which_param->getID());
  517. return setParamWeight(param, weight, upload_bake);
  518. }
  519. //virtual
  520. bool LLVOAvatarSelf::setVisualParamWeight(const char* param_name, F32 weight,
  521. bool upload_bake)
  522. {
  523. if (!param_name)
  524. {
  525. return false;
  526. }
  527. LLViewerVisualParam* param =
  528. (LLViewerVisualParam*)LLCharacter::getVisualParam(param_name);
  529. return setParamWeight(param, weight, upload_bake);
  530. }
  531. //virtual
  532. bool LLVOAvatarSelf::setVisualParamWeight(S32 index, F32 weight,
  533. bool upload_bake)
  534. {
  535. LLViewerVisualParam* param =
  536. (LLViewerVisualParam*)LLCharacter::getVisualParam(index);
  537. return setParamWeight(param, weight, upload_bake);
  538. }
  539. bool LLVOAvatarSelf::setParamWeight(const LLViewerVisualParam* param,
  540. F32 weight, bool upload_bake)
  541. {
  542. if (!param)
  543. {
  544. return false;
  545. }
  546. #if 0
  547. // *FIXME: kludgy way to avoid overwriting avatar state from wearables.
  548. if (isUsingServerBakes() && !isUsingLocalAppearance())
  549. {
  550. return false;
  551. }
  552. #endif
  553. if (param->getCrossWearable())
  554. {
  555. LLWearableType::EType type =
  556. (LLWearableType::EType)param->getWearableType();
  557. U32 size = gAgentWearables.getWearableCount(type);
  558. for (U32 count = 0; count < size; ++count)
  559. {
  560. LLViewerWearable* wearable =
  561. gAgentWearables.getViewerWearable(type, count);
  562. if (wearable)
  563. {
  564. wearable->setVisualParamWeight(param->getID(), weight,
  565. upload_bake);
  566. }
  567. }
  568. }
  569. return LLCharacter::setVisualParamWeight(param, weight, upload_bake);
  570. }
  571. void LLVOAvatarSelf::writeWearablesToAvatar()
  572. {
  573. for (U32 type = 0; type < LLWearableType::WT_COUNT; ++type)
  574. {
  575. LLWearable* wearable =
  576. gAgentWearables.getTopWearable((LLWearableType::EType)type);
  577. if (wearable)
  578. {
  579. wearable->writeToAvatar(this);
  580. }
  581. }
  582. }
  583. //virtual
  584. void LLVOAvatarSelf::idleUpdateAppearanceAnimation()
  585. {
  586. // Animate all top-level wearable visual parameters
  587. gAgentWearables.animateAllWearableParams(calcMorphAmount(), false);
  588. // Apply wearable visual params to avatar
  589. writeWearablesToAvatar();
  590. // Allow avatar to process updates
  591. LLVOAvatar::idleUpdateAppearanceAnimation();
  592. }
  593. //virtual
  594. void LLVOAvatarSelf::requestStopMotion(LLMotion* motion)
  595. {
  596. // Only agent avatars should handle the stop motion notifications.
  597. // Notify agent that motion has stopped
  598. gAgent.requestStopMotion(motion);
  599. }
  600. //virtual
  601. bool LLVOAvatarSelf::hasMotionFromSource(const LLUUID& source_id)
  602. {
  603. return mAnimationSources.find(source_id) != mAnimationSources.end();
  604. }
  605. //virtual
  606. void LLVOAvatarSelf::stopMotionFromSource(const LLUUID& source_id)
  607. {
  608. anim_src_map_it_t it = mAnimationSources.find(source_id);
  609. while (it != mAnimationSources.end())
  610. {
  611. gAgent.sendAnimationRequest(it->second, ANIM_REQUEST_STOP);
  612. mAnimationSources.erase(it);
  613. // We must find() after each erase() to deal with potential
  614. // iterator invalidation; this also ensures that we do not go past the
  615. // end of this source's animations into those of another source.
  616. it = mAnimationSources.find(source_id);
  617. }
  618. LLViewerObject* object = gObjectList.findObject(source_id);
  619. if (object)
  620. {
  621. object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, false);
  622. }
  623. }
  624. //virtual
  625. U32 LLVOAvatarSelf::processUpdateMessage(LLMessageSystem* mesgsys,
  626. void** user_data, U32 block_num,
  627. EObjectUpdateType update_type,
  628. LLDataPacker* dp)
  629. {
  630. U32 retval = LLVOAvatar::processUpdateMessage(mesgsys, user_data,
  631. block_num, update_type, dp);
  632. #if 1 // It is not clear this does anything useful. If we wait until an
  633. // appearance message has been received, we already have the texture
  634. // IDs. If we do not wait, we do not yet know where to look for baked
  635. // textures, because we have not received the appearance version data
  636. // from the appearance message. This looks like an old optimization
  637. // that is incompatible with server-side texture baking.
  638. // *FIXME: skipping in the case of !mFirstAppearanceMessageReceived
  639. // prevents us from trying to load textures before we know where they come
  640. // from (ie, from baking service or not); unknown impact on performance.
  641. if (!mInitialBakesLoaded && retval == 0x0 &&
  642. mFirstAppearanceMessageReceived)
  643. {
  644. // Call update textures to force the images to be created
  645. updateMeshTextures();
  646. // Unpack the texture UUIDs to the texture slots
  647. if (mesgsys)
  648. {
  649. retval = unpackTEMessage(mesgsys, _PREHASH_ObjectData,
  650. (S32)block_num);
  651. }
  652. else
  653. {
  654. retval = false;
  655. }
  656. // Need to trigger a few operations to get the avatar to use the new
  657. // bakes
  658. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  659. {
  660. const ETextureIndex te = mBakedTextureDatas[i].mTextureIndex;
  661. LLUUID texture_id = getTEImage(te)->getID();
  662. setNewBakedTexture(te, texture_id);
  663. mInitialBakeIDs[i] = texture_id;
  664. }
  665. onFirstTEMessageReceived();
  666. mInitialBakesLoaded = true;
  667. }
  668. #endif
  669. return retval;
  670. }
  671. void LLVOAvatarSelf::setLocalTextureTE(U8 te, LLViewerTexture* texp, U32 index)
  672. {
  673. if (te >= TEX_NUM_INDICES)
  674. {
  675. llassert(false);
  676. return;
  677. }
  678. LLViewerTexture* te_texp = getTEImage(te);
  679. if (!te_texp || te_texp->getID() == texp->getID())
  680. {
  681. return;
  682. }
  683. if (isIndexBakedTexture((ETextureIndex)te))
  684. {
  685. llassert(false);
  686. return;
  687. }
  688. setTEImage(te, texp);
  689. }
  690. //virtual
  691. void LLVOAvatarSelf::removeMissingBakedTextures()
  692. {
  693. bool removed = false;
  694. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  695. {
  696. const S32 te = mBakedTextureDatas[i].mTextureIndex;
  697. const LLViewerTexture* tex = getTEImage(te);
  698. // Replace with default if we cannot find the asset, assuming the
  699. // default is actually valid (which it should be unless something is
  700. // seriously wrong).
  701. if (!tex || tex->isMissingAsset())
  702. {
  703. LLViewerTexture* imagep =
  704. LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
  705. if (imagep && imagep != tex)
  706. {
  707. setTEImage(te, imagep);
  708. removed = true;
  709. }
  710. }
  711. }
  712. if (removed)
  713. {
  714. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  715. {
  716. LLViewerTexLayerSet* layerset = getTexLayerSet(i);
  717. if (layerset)
  718. {
  719. layerset->setUpdatesEnabled(true);
  720. invalidateComposite(layerset, false);
  721. }
  722. }
  723. updateMeshTextures(); // may call back into this function
  724. requestLayerSetUploads();
  725. }
  726. }
  727. void LLVOAvatarSelf::onSimulatorFeaturesReceived(const LLUUID&)
  728. {
  729. llinfos << "Simulator features received, setting hover based on region props"
  730. << llendl;
  731. scheduleHoverUpdate();
  732. }
  733. //virtual
  734. void LLVOAvatarSelf::updateRegion(LLViewerRegion* regionp)
  735. {
  736. // Save the global position
  737. LLVector3d global_pos_from_old_region = getPositionGlobal();
  738. // Change the region
  739. setRegion(regionp);
  740. if (regionp)
  741. {
  742. // Set correct region-relative position from global coordinates
  743. setPositionGlobal(global_pos_from_old_region);
  744. // Update hover height
  745. scheduleHoverUpdate();
  746. }
  747. if (!regionp || regionp->getHandle() != mLastRegionHandle)
  748. {
  749. if (mLastRegionHandle != 0)
  750. {
  751. F64 delta = (F64)mRegionCrossingTimer.getElapsedTimeF32();
  752. F64 avg = 0.0;
  753. F64 max = 0.0;
  754. if (++mRegionCrossingCount > 1)
  755. {
  756. avg = gViewerStats.getStat(LLViewerStats::ST_CROSSING_AVG);
  757. max = gViewerStats.getStat(LLViewerStats::ST_CROSSING_MAX);
  758. }
  759. F64 delta_avg = (delta + avg * (mRegionCrossingCount - 1)) /
  760. mRegionCrossingCount;
  761. gViewerStats.setStat(LLViewerStats::ST_CROSSING_AVG, delta_avg);
  762. max = llmax(delta, max);
  763. gViewerStats.setStat(LLViewerStats::ST_CROSSING_MAX, max);
  764. // Diagnostics
  765. llinfos << "Region crossing took " << (F32)delta * 1000.0f
  766. << " ms " << llendl;
  767. }
  768. if (regionp)
  769. {
  770. mLastRegionHandle = regionp->getHandle();
  771. }
  772. }
  773. mRegionCrossingTimer.reset();
  774. #if 0 // No operation
  775. LLViewerObject::updateRegion(regionp);
  776. #endif
  777. }
  778. //--------------------------------------------------------------------
  779. // Draws the tractor beam when editing objects
  780. //--------------------------------------------------------------------
  781. //virtual
  782. void LLVOAvatarSelf::idleUpdateTractorBeam()
  783. {
  784. // This is only done for yourself (maybe it should be moved to LLAgent ?)
  785. if (!needsRenderBeam() || !isBuilt())
  786. {
  787. mBeam = NULL;
  788. return;
  789. }
  790. if (mBeam.isNull() || mBeam->isDead())
  791. {
  792. // VEFFECT: Tractor Beam
  793. mBeam =
  794. (LLHUDEffectSpiral*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_BEAM);
  795. mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
  796. mBeam->setSourceObject(this);
  797. mBeamTimer.reset();
  798. }
  799. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  800. if (gAgent.mPointAt.notNull())
  801. {
  802. // Get point from pointat effect
  803. mBeam->setPositionGlobal(gAgent.mPointAt->getPointAtPosGlobal());
  804. mBeam->triggerLocal();
  805. }
  806. else if (selection->getFirstRootObject() &&
  807. selection->getSelectType() != SELECT_TYPE_HUD)
  808. {
  809. LLViewerObject* objectp = selection->getFirstRootObject();
  810. mBeam->setTargetObject(objectp);
  811. }
  812. else
  813. {
  814. mBeam->setTargetObject(NULL);
  815. LLTool* toolp = gToolMgr.getCurrentTool();
  816. if (toolp && toolp->isEditing())
  817. {
  818. if (toolp->getEditingObject())
  819. {
  820. mBeam->setTargetObject(toolp->getEditingObject());
  821. }
  822. else
  823. {
  824. mBeam->setPositionGlobal(toolp->getEditingPointGlobal());
  825. }
  826. }
  827. else
  828. {
  829. const LLPickInfo& pick = gViewerWindowp->getLastPick();
  830. mBeam->setPositionGlobal(pick.mPosGlobal);
  831. }
  832. }
  833. if (mBeamTimer.getElapsedTimeF32() > 0.25f)
  834. {
  835. mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
  836. mBeam->setNeedsSendToSim(true);
  837. mBeamTimer.reset();
  838. }
  839. }
  840. //virtual
  841. void LLVOAvatarSelf::restoreMeshData()
  842. {
  843. mMeshValid = true;
  844. updateJointLODs();
  845. updateAttachmentVisibility(gAgent.getCameraMode());
  846. // Force mesh update as LOD might not have changed to trigger this
  847. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
  848. }
  849. void LLVOAvatarSelf::updateAttachmentVisibility(U32 camera_mode)
  850. {
  851. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  852. end = mAttachmentPoints.end();
  853. iter != end; ++iter)
  854. {
  855. LLViewerJointAttachment* attachment = iter->second;
  856. if (!attachment) continue; // Paranoia
  857. if (camera_mode != CAMERA_MODE_MOUSELOOK ||
  858. attachment->getIsHUDAttachment())
  859. {
  860. attachment->setAttachmentVisibility(true);
  861. }
  862. else if ((LLVOAvatar::sVisibleInFirstPerson &&
  863. attachment->getVisibleInFirstPerson()) ||
  864. gPipeline.mHeroProbeManager.isMirrorPass())
  865. {
  866. attachment->setAttachmentVisibility(true);
  867. }
  868. else
  869. {
  870. attachment->setAttachmentVisibility(false);
  871. }
  872. }
  873. }
  874. // Forces an update to any baked textures relevant to type. Will force an
  875. // upload of the resulting bake if the second parameter is true.
  876. void LLVOAvatarSelf::wearableUpdated(LLWearableType::EType type,
  877. bool upload_result)
  878. {
  879. for (LLAvatarAppearanceDictionary::BakedTextures::const_iterator
  880. baked_iter = gAvatarAppDictp->getBakedTextures().begin(),
  881. end = gAvatarAppDictp->getBakedTextures().end();
  882. baked_iter != end; ++baked_iter)
  883. {
  884. const LLAvatarAppearanceDictionary::BakedEntry* baked_dictp =
  885. baked_iter->second;
  886. if (!baked_dictp)
  887. {
  888. continue;
  889. }
  890. const EBakedTextureIndex index = baked_iter->first;
  891. for (wearables_vec_t::const_iterator
  892. type_iter = baked_dictp->mWearables.begin(),
  893. type_end = baked_dictp->mWearables.end();
  894. type_iter != type_end; ++type_iter)
  895. {
  896. const LLWearableType::EType comp_type = *type_iter;
  897. if (comp_type == type)
  898. {
  899. LLViewerTexLayerSet* layersetp = getLayerSet(index);
  900. if (layersetp)
  901. {
  902. layersetp->setUpdatesEnabled(true);
  903. invalidateComposite(layersetp, upload_result);
  904. }
  905. break;
  906. }
  907. }
  908. }
  909. // Physics type has no associated baked textures, but change of params
  910. // needs to be sent to other avatars.
  911. if (type == LLWearableType::WT_PHYSICS)
  912. {
  913. gAgent.sendAgentSetAppearance();
  914. }
  915. }
  916. bool LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
  917. {
  918. const LLUUID& base_inv_id = gInventory.getLinkedItemID(inv_item_id);
  919. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(),
  920. end = mAttachmentPoints.end();
  921. iter != end; ++iter)
  922. {
  923. const LLViewerJointAttachment* attachp = iter->second;
  924. if (attachp && attachp->getAttachedObject(base_inv_id))
  925. {
  926. return true;
  927. }
  928. }
  929. return false;
  930. }
  931. LLViewerObject* LLVOAvatarSelf::getWornAttachment(const LLUUID& inv_item_id)
  932. {
  933. const LLUUID& base_inv_id = gInventory.getLinkedItemID(inv_item_id);
  934. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  935. end = mAttachmentPoints.end();
  936. iter != end; ++iter)
  937. {
  938. LLViewerJointAttachment* attachp = iter->second;
  939. if (!attachp) continue; // Paranoia
  940. LLViewerObject* objectp = attachp->getAttachedObject(base_inv_id);
  941. if (objectp)
  942. {
  943. return objectp;
  944. }
  945. }
  946. return NULL;
  947. }
  948. const std::string LLVOAvatarSelf::getAttachedPointName(const LLUUID& inv_item_id,
  949. bool translate) const
  950. {
  951. if (inv_item_id.notNull())
  952. {
  953. const LLUUID& base_inv_id = gInventory.getLinkedItemID(inv_item_id);
  954. if (base_inv_id.notNull())
  955. {
  956. for (attachment_map_t::const_iterator
  957. iter = mAttachmentPoints.begin(),
  958. end = mAttachmentPoints.end();
  959. iter != end; ++iter)
  960. {
  961. const LLViewerJointAttachment* attachp = iter->second;
  962. if (attachp && attachp->getAttachedObject(base_inv_id))
  963. {
  964. const std::string name = attachp->getName();
  965. if (translate)
  966. {
  967. return LLTrans::getString(name);
  968. }
  969. if (name == "Avatar Center")
  970. {
  971. return "Root";
  972. }
  973. return name;
  974. }
  975. }
  976. }
  977. }
  978. return LLStringUtil::null;
  979. }
  980. //virtual
  981. S32 LLVOAvatarSelf::getMaxAnimatedObjectAttachments() const
  982. {
  983. S32 limit = LLEconomy::getInstance()->getAnimatedObjectLimit();
  984. return limit >= 0 ? limit : LLVOAvatar::getMaxAnimatedObjectAttachments();
  985. }
  986. //virtual
  987. const LLViewerJointAttachment* LLVOAvatarSelf::attachObject(LLViewerObject* objp)
  988. {
  989. const LLViewerJointAttachment* attachp = LLVOAvatar::attachObject(objp);
  990. if (!attachp)
  991. {
  992. return NULL;
  993. }
  994. //MK
  995. if (gRLenabled)
  996. {
  997. // If the corresponding inventory item is under #RLV and does not
  998. // contain any attachment info in its name, rename it (or its parent
  999. // category) for later use by RestrainedLove.
  1000. gRLInterface.addAttachmentPointName(objp);
  1001. }
  1002. //mk
  1003. updateAttachmentVisibility(gAgent.getCameraMode());
  1004. // Then make sure the inventory is in sync with the avatar.
  1005. gInventory.addChangedMask(LLInventoryObserver::LABEL,
  1006. objp->getAttachmentItemID());
  1007. gInventory.notifyObservers();
  1008. updateLODRiggedAttachments();
  1009. return attachp;
  1010. }
  1011. //virtual
  1012. bool LLVOAvatarSelf::detachObject(LLViewerObject* objp)
  1013. {
  1014. const LLUUID attachment_id = objp->getAttachmentItemID();
  1015. if (LLVOAvatar::detachObject(objp))
  1016. {
  1017. // The simulator should automatically handle permission revocation
  1018. stopMotionFromSource(attachment_id);
  1019. LLFollowCamMgr::setCameraActive(objp->getID(), false);
  1020. LLViewerObject::const_child_list_t& child_list = objp->getChildren();
  1021. for (LLViewerObject::child_list_t::const_iterator
  1022. iter = child_list.begin(), end = child_list.end();
  1023. iter != end; ++iter)
  1024. {
  1025. LLViewerObject* childp = *iter;
  1026. if (childp) // Paranoia
  1027. {
  1028. // The simulator should automatically handle permissions
  1029. // revocation
  1030. stopMotionFromSource(childp->getID());
  1031. LLFollowCamMgr::setCameraActive(childp->getID(), false);
  1032. }
  1033. }
  1034. // Make sure the inventory is in sync with the avatar.
  1035. gInventory.addChangedMask(LLInventoryObserver::LABEL, attachment_id);
  1036. gInventory.notifyObservers();
  1037. return true;
  1038. }
  1039. return false;
  1040. }
  1041. //static
  1042. bool LLVOAvatarSelf::detachAttachmentIntoInventory(const LLUUID& item_id)
  1043. {
  1044. LLInventoryItem* itemp =
  1045. gInventory.getItem(gInventory.getLinkedItemID(item_id));
  1046. if (!itemp || !gAgent.getRegion())
  1047. {
  1048. return false;
  1049. }
  1050. LLMessageSystem* msg = gMessageSystemp;
  1051. msg->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
  1052. msg->nextBlockFast(_PREHASH_ObjectData);
  1053. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  1054. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  1055. msg->sendReliable(gAgent.getRegionHost());
  1056. // This object might have been selected, so let the selection manager know
  1057. // it is gone now.
  1058. LLViewerObject* objp = gObjectList.findObject(item_id);
  1059. if (objp)
  1060. {
  1061. gSelectMgr.remove(objp);
  1062. }
  1063. return true;
  1064. }
  1065. U32 LLVOAvatarSelf::getNumWearables(ETextureIndex i) const
  1066. {
  1067. LLWearableType::EType type = gAvatarAppDictp->getTEWearableType(i);
  1068. return gAgentWearables.getWearableCount(type);
  1069. }
  1070. //virtual
  1071. void LLVOAvatarSelf::localTextureLoaded(bool success,
  1072. LLViewerFetchedTexture* texp,
  1073. LLImageRaw* src_raw,
  1074. LLImageRaw* aux_src,
  1075. S32 discard_level,
  1076. bool is_final, void* userdata)
  1077. {
  1078. LLAvatarTexData* datap = (LLAvatarTexData*)userdata;
  1079. ETextureIndex index = datap->mIndex;
  1080. if (!isIndexLocalTexture(index))
  1081. {
  1082. return;
  1083. }
  1084. LLLocalTextureObject* ltop = getLocalTextureObject(index, 0);
  1085. // Fix for EXT-268. Preventing using of NULL pointer
  1086. if (!ltop)
  1087. {
  1088. llwarns << "There is no local texture object with index: " << index
  1089. << " - is_final: " << is_final << llendl;
  1090. return;
  1091. }
  1092. const LLUUID& src_id = texp->getID();
  1093. if (success)
  1094. {
  1095. if (!ltop->getBakedReady() && ltop->getImage() &&
  1096. ltop->getID() == src_id && discard_level < ltop->getDiscard())
  1097. {
  1098. ltop->setDiscard(discard_level);
  1099. requestLayerSetUpdate(index);
  1100. if (isEditingAppearance())
  1101. {
  1102. LLVisualParamHint::requestHintUpdates();
  1103. }
  1104. updateMeshTextures();
  1105. }
  1106. }
  1107. // Failed: asset is missing
  1108. else if (is_final && !ltop->getBakedReady() && ltop->getImage() &&
  1109. ltop->getImage()->getID() == src_id)
  1110. {
  1111. ltop->setDiscard(0);
  1112. requestLayerSetUpdate(index);
  1113. updateMeshTextures();
  1114. }
  1115. }
  1116. LLViewerFetchedTexture* LLVOAvatarSelf::getLocalTextureGL(ETextureIndex type,
  1117. U32 index) const
  1118. {
  1119. if (!isIndexLocalTexture(type))
  1120. {
  1121. return NULL;
  1122. }
  1123. const LLLocalTextureObject* ltop = getLocalTextureObject(type, index);
  1124. if (!ltop)
  1125. {
  1126. return NULL;
  1127. }
  1128. if (ltop->getID() == IMG_DEFAULT_AVATAR)
  1129. {
  1130. return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
  1131. }
  1132. LLGLTexture* gltexp = ltop->getImage();
  1133. return gltexp ? gltexp->asFetched() : NULL;
  1134. }
  1135. const LLUUID& LLVOAvatarSelf::getLocalTextureID(ETextureIndex type,
  1136. U32 index) const
  1137. {
  1138. if (!isIndexLocalTexture(type)) return IMG_DEFAULT_AVATAR;
  1139. const LLLocalTextureObject* ltop = getLocalTextureObject(type, index);
  1140. if (ltop && ltop->getImage())
  1141. {
  1142. return ltop->getImage()->getID();
  1143. }
  1144. return IMG_DEFAULT_AVATAR;
  1145. }
  1146. // Returns true if at least the lowest quality discard level exists for every
  1147. // texture in the layerset.
  1148. bool LLVOAvatarSelf::isLocalTextureDataAvailable(LLViewerTexLayerSet* layersetp)
  1149. {
  1150. for (LLAvatarAppearanceDictionary::BakedTextures::const_iterator
  1151. it = gAvatarAppDictp->getBakedTextures().begin(),
  1152. end = gAvatarAppDictp->getBakedTextures().end();
  1153. it != end; ++it)
  1154. {
  1155. EBakedTextureIndex baked_index = it->first;
  1156. if (layersetp == mBakedTextureDatas[baked_index].mTexLayerSet)
  1157. {
  1158. LLAvatarAppearanceDictionary::BakedEntry* baked_dictp =
  1159. it->second;
  1160. texture_vec_t& textures = baked_dictp->mLocalTextures;
  1161. for (U32 i = 0, count = textures.size(); i < count; ++i)
  1162. {
  1163. ETextureIndex tex_index = textures[i];
  1164. LLWearableType::EType wearable_type =
  1165. LLAvatarAppearanceDictionary::getTEWearableType(tex_index);
  1166. U32 wcount = gAgentWearables.getWearableCount(wearable_type);
  1167. for (U32 w = 0; w < wcount; ++w)
  1168. {
  1169. if (getLocalDiscardLevel(tex_index, w) < 0)
  1170. {
  1171. return false;
  1172. }
  1173. }
  1174. }
  1175. return true;
  1176. }
  1177. }
  1178. llassert(false);
  1179. return false;
  1180. }
  1181. // Returns true if the highest quality discard level exists for every texture
  1182. // in the layerset.
  1183. bool LLVOAvatarSelf::isLocalTextureDataFinal(LLViewerTexLayerSet* layersetp)
  1184. {
  1185. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1186. {
  1187. if (layersetp == mBakedTextureDatas[i].mTexLayerSet)
  1188. {
  1189. const LLAvatarAppearanceDictionary::BakedEntry* baked_dictp =
  1190. gAvatarAppDictp->getBakedTexture((EBakedTextureIndex)i);
  1191. const texture_vec_t& textures = baked_dictp->mLocalTextures;
  1192. for (U32 j = 0, count2 = textures.size(); j < count2; ++j)
  1193. {
  1194. ETextureIndex tex_index = textures[j];
  1195. LLWearableType::EType wearable_type =
  1196. LLAvatarAppearanceDictionary::getTEWearableType(tex_index);
  1197. U32 wcount = gAgentWearables.getWearableCount(wearable_type);
  1198. for (U32 w = 0; w < wcount; ++w)
  1199. {
  1200. if (getLocalDiscardLevel(tex_index, w) != 0)
  1201. {
  1202. return false;
  1203. }
  1204. }
  1205. }
  1206. return true;
  1207. }
  1208. }
  1209. llassert(false);
  1210. return false;
  1211. }
  1212. bool LLVOAvatarSelf::isBakedTextureFinal(EBakedTextureIndex index)
  1213. {
  1214. LLViewerTexLayerSet* layersetp = getLayerSet(index);
  1215. if (!layersetp) return false;
  1216. LLViewerTexLayerSetBuffer* bufferp = layersetp->getViewerComposite();
  1217. return bufferp && !bufferp->uploadNeeded();
  1218. }
  1219. bool LLVOAvatarSelf::isTextureDefined(ETextureIndex type, U32 index) const
  1220. {
  1221. LLUUID id;
  1222. bool is_defined = true;
  1223. if (isIndexLocalTexture(type))
  1224. {
  1225. const LLWearableType::EType wearable_type =
  1226. LLAvatarAppearanceDictionary::getTEWearableType(type);
  1227. U32 count = gAgentWearables.getWearableCount(wearable_type);
  1228. if (index >= count)
  1229. {
  1230. // Invalid index passed in. check all textures of a given type
  1231. for (U32 i = 0; i < count; ++i)
  1232. {
  1233. id = getLocalTextureID(type, i);
  1234. is_defined &= id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT;
  1235. }
  1236. }
  1237. else
  1238. {
  1239. id = getLocalTextureID(type, index);
  1240. is_defined &= id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT;
  1241. }
  1242. }
  1243. else
  1244. {
  1245. id = getTEImage(type)->getID();
  1246. is_defined &= id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT;
  1247. }
  1248. return is_defined;
  1249. }
  1250. //virtual
  1251. bool LLVOAvatarSelf::isTextureVisible(ETextureIndex type, U32 index) const
  1252. {
  1253. if (isIndexBakedTexture(type))
  1254. {
  1255. return LLVOAvatar::isTextureVisible(type, 0U);
  1256. }
  1257. return LLDrawPoolAlpha::sShowDebugAlpha ||
  1258. getLocalTextureID(type, index) != IMG_INVISIBLE;
  1259. }
  1260. //virtual
  1261. bool LLVOAvatarSelf::isTextureVisible(ETextureIndex type,
  1262. LLViewerWearable* wearablep) const
  1263. {
  1264. if (isIndexBakedTexture(type))
  1265. {
  1266. return LLVOAvatar::isTextureVisible(type);
  1267. }
  1268. U32 index;
  1269. if (gAgentWearables.getWearableIndex(wearablep, index))
  1270. {
  1271. return isTextureVisible(type, index);
  1272. }
  1273. LL_DEBUGS("Avatar") << "Wearable not found on avatar" << LL_ENDL;
  1274. return false;
  1275. }
  1276. void LLVOAvatarSelf::requestLayerSetUploads()
  1277. {
  1278. if (!canUseServerBaking())
  1279. {
  1280. gAppearanceMgr.setRebaking();
  1281. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1282. {
  1283. requestLayerSetUpload((EBakedTextureIndex)i);
  1284. }
  1285. }
  1286. }
  1287. void LLVOAvatarSelf::requestLayerSetUpload(EBakedTextureIndex i)
  1288. {
  1289. ETextureIndex tex_idx = mBakedTextureDatas[i].mTextureIndex;
  1290. if (!isTextureDefined(tex_idx, gAgentWearables.getWearableCount(tex_idx)))
  1291. {
  1292. LLViewerTexLayerSet* layerset = getLayerSet(i);
  1293. if (layerset)
  1294. {
  1295. layerset->requestUpload();
  1296. }
  1297. }
  1298. }
  1299. bool LLVOAvatarSelf::areTexturesCurrent()
  1300. {
  1301. return !hasPendingBakedUploads() && gAgentWearables.areWearablesLoaded();
  1302. }
  1303. bool LLVOAvatarSelf::hasPendingBakedUploads()
  1304. {
  1305. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1306. {
  1307. LLViewerTexLayerSet* layerset = getTexLayerSet(i);
  1308. if (layerset && layerset->getViewerComposite() &&
  1309. layerset->getViewerComposite()->uploadPending())
  1310. {
  1311. gAppearanceMgr.setRebaking();
  1312. return true;
  1313. }
  1314. }
  1315. gAppearanceMgr.setRebaking(false);
  1316. return false;
  1317. }
  1318. //virtual
  1319. void LLVOAvatarSelf::invalidateComposite(LLTexLayerSet* texlayersetp,
  1320. bool upload_result)
  1321. {
  1322. if (!texlayersetp) return;
  1323. LLViewerTexLayerSet* vtexlayersetp = texlayersetp->asViewerTexLayerSet();
  1324. if (!vtexlayersetp || !vtexlayersetp->getUpdatesEnabled())
  1325. {
  1326. return;
  1327. }
  1328. vtexlayersetp->requestUpdate();
  1329. vtexlayersetp->invalidateMorphMasks();
  1330. if (upload_result && !canUseServerBaking())
  1331. {
  1332. ETextureIndex baked_te = getBakedTE(vtexlayersetp);
  1333. setTEImage(baked_te,
  1334. LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR));
  1335. vtexlayersetp->requestUpload();
  1336. updateMeshTextures();
  1337. }
  1338. }
  1339. //virtual
  1340. void LLVOAvatarSelf::invalidateAll()
  1341. {
  1342. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1343. {
  1344. LLViewerTexLayerSet* layersetp = getTexLayerSet(i);
  1345. invalidateComposite(layersetp, true);
  1346. }
  1347. }
  1348. //virtual
  1349. void LLVOAvatarSelf::setCompositeUpdatesEnabled(bool b)
  1350. {
  1351. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1352. {
  1353. setCompositeUpdatesEnabled(i, b);
  1354. }
  1355. }
  1356. //virtual
  1357. void LLVOAvatarSelf::setCompositeUpdatesEnabled(U32 index, bool b)
  1358. {
  1359. LLViewerTexLayerSet* layersetp = getTexLayerSet(index);
  1360. if (layersetp)
  1361. {
  1362. layersetp->setUpdatesEnabled(b);
  1363. }
  1364. }
  1365. //virtual
  1366. bool LLVOAvatarSelf::isCompositeUpdateEnabled(U32 index)
  1367. {
  1368. LLViewerTexLayerSet* layersetp = getTexLayerSet(index);
  1369. return layersetp ? layersetp->getUpdatesEnabled() : false;
  1370. }
  1371. void LLVOAvatarSelf::setupComposites()
  1372. {
  1373. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1374. {
  1375. LLViewerTexLayerSet* layersetp = getTexLayerSet(i);
  1376. if (layersetp)
  1377. {
  1378. ETextureIndex idx = mBakedTextureDatas[i].mTextureIndex;
  1379. bool layer_baked =
  1380. isTextureDefined(idx, gAgentWearables.getWearableCount(idx));
  1381. layersetp->setUpdatesEnabled(!layer_baked);
  1382. }
  1383. }
  1384. }
  1385. void LLVOAvatarSelf::updateComposites()
  1386. {
  1387. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  1388. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1389. {
  1390. if (i != BAKED_SKIRT || wearing_skirt)
  1391. {
  1392. LLViewerTexLayerSet* layersetp = getTexLayerSet(i);
  1393. if (layersetp)
  1394. {
  1395. layersetp->updateComposite();
  1396. }
  1397. }
  1398. }
  1399. }
  1400. S32 LLVOAvatarSelf::getLocalDiscardLevel(ETextureIndex type, U32 wearable_idx)
  1401. {
  1402. if (type < 0 || !isIndexLocalTexture(type)) return 0;
  1403. LLLocalTextureObject* ltop = getLocalTextureObject(type, wearable_idx);
  1404. if (ltop)
  1405. {
  1406. LLGLTexture* gltexp = ltop->getImage();
  1407. if (gltexp)
  1408. {
  1409. LLViewerFetchedTexture* texp = gltexp->asFetched();
  1410. if (texp && !texp->isMissingAsset() &&
  1411. ltop->getID() != IMG_DEFAULT_AVATAR)
  1412. {
  1413. return texp->getDiscardLevel();
  1414. }
  1415. }
  1416. }
  1417. // We do not care about this (no image associated with the layer) treat as
  1418. // fully loaded.
  1419. return 0;
  1420. }
  1421. // Counts the memory footprint of local textures.
  1422. void LLVOAvatarSelf::getLocalTextureByteCount(S32* gl_bytes)
  1423. {
  1424. *gl_bytes = 0;
  1425. for (S32 type = 0; type < TEX_NUM_INDICES; ++type)
  1426. {
  1427. if (!isIndexLocalTexture((ETextureIndex)type))
  1428. {
  1429. continue;
  1430. }
  1431. U32 max_tex = getNumWearables((ETextureIndex)type);
  1432. for (U32 num = 0; num < max_tex; ++num)
  1433. {
  1434. LLLocalTextureObject* ltop =
  1435. getLocalTextureObject((ETextureIndex)type, num);
  1436. if (!ltop) continue;
  1437. LLGLTexture* gltexp = ltop->getImage();
  1438. if (!gltexp) continue;
  1439. LLViewerFetchedTexture* texp = gltexp->asFetched();
  1440. if (texp && texp->hasGLTexture())
  1441. {
  1442. *gl_bytes += texp->getWidth() * texp->getHeight() *
  1443. texp->getComponents();
  1444. }
  1445. }
  1446. }
  1447. }
  1448. //virtual
  1449. void LLVOAvatarSelf::setLocalTexture(ETextureIndex type,
  1450. LLViewerTexture* src_texp,
  1451. bool baked_version_ready, U32 index)
  1452. {
  1453. if (type >= TEX_NUM_INDICES || !isIndexLocalTexture(type)) return;
  1454. LLViewerFetchedTexture* texp = LLViewerTextureManager::staticCast(src_texp,
  1455. true);
  1456. if (!texp)
  1457. {
  1458. return;
  1459. }
  1460. LLLocalTextureObject* ltop = getLocalTextureObject(type, index);
  1461. if (!ltop)
  1462. {
  1463. LLWearableType::EType wearable_type =
  1464. gAvatarAppDictp->getTEWearableType(type);
  1465. ltop = gAgentWearables.addLocalTextureObject(wearable_type, type,
  1466. index);
  1467. if (!ltop)
  1468. {
  1469. // Wearable not loaded, could not set the texture.
  1470. return;
  1471. }
  1472. LLViewerTexLayerSet* layersetp = getLayerSet(type);
  1473. if (layersetp)
  1474. {
  1475. layersetp->cloneTemplates(ltop, type,
  1476. gAgentWearables.getViewerWearable(wearable_type,
  1477. index));
  1478. }
  1479. }
  1480. if (!baked_version_ready)
  1481. {
  1482. if (texp != ltop->getImage() || ltop->getBakedReady())
  1483. {
  1484. ltop->setDiscard(MAX_DISCARD_LEVEL + 1);
  1485. }
  1486. if (texp->getID() != IMG_DEFAULT_AVATAR)
  1487. {
  1488. if (ltop->getDiscard() > 0)
  1489. {
  1490. S32 tex_discard = texp->getDiscardLevel();
  1491. if (tex_discard == 0)
  1492. {
  1493. ltop->setDiscard(tex_discard);
  1494. if (isSelf())
  1495. {
  1496. requestLayerSetUpdate(type);
  1497. if (isEditingAppearance())
  1498. {
  1499. LLVisualParamHint::requestHintUpdates();
  1500. }
  1501. }
  1502. }
  1503. else
  1504. {
  1505. texp->setLoadedCallback(onLocalTextureLoaded, 0, true,
  1506. false,
  1507. new LLAvatarTexData(getID(), type),
  1508. NULL);
  1509. }
  1510. }
  1511. texp->setMinDiscardLevel(0);
  1512. }
  1513. }
  1514. ltop->setImage(texp);
  1515. ltop->setID(texp->getID());
  1516. setBakedReady(type, baked_version_ready, index);
  1517. }
  1518. //virtual
  1519. void LLVOAvatarSelf::setBakedReady(ETextureIndex type, bool has_baked,
  1520. U32 index)
  1521. {
  1522. if (!isIndexLocalTexture(type))
  1523. {
  1524. return;
  1525. }
  1526. LLLocalTextureObject* ltop = getLocalTextureObject(type, index);
  1527. if (ltop)
  1528. {
  1529. ltop->setBakedReady(has_baked);
  1530. }
  1531. }
  1532. void LLVOAvatarSelf::dumpLocalTextures()
  1533. {
  1534. llinfos << "Local textures:" << llendl;
  1535. bool is_god = gAgent.isGodlikeWithoutAdminMenuFakery();
  1536. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  1537. iter = gAvatarAppDictp->getTextures().begin(),
  1538. end = gAvatarAppDictp->getTextures().end();
  1539. iter != end; ++iter)
  1540. {
  1541. LLAvatarAppearanceDictionary::TextureEntry* t_dict = iter->second;
  1542. if (!t_dict->mIsLocalTexture || !t_dict->mIsUsedByBakedTexture)
  1543. {
  1544. continue;
  1545. }
  1546. EBakedTextureIndex baked_index = t_dict->mBakedTextureIndex;
  1547. ETextureIndex baked_equiv =
  1548. gAvatarAppDictp->getBakedTexture(baked_index)->mTextureIndex;
  1549. const std::string& name = t_dict->mName;
  1550. // Index is baked texture - index is not relevant. putting in 0 as
  1551. // placeholder
  1552. if (isTextureDefined(baked_equiv, 0))
  1553. {
  1554. llinfos << "LocTex " << name << ": baked";
  1555. if (is_god)
  1556. {
  1557. llcont << " - Id: " << getTEImage(baked_equiv)->getID();
  1558. }
  1559. llcont << llendl;
  1560. continue;
  1561. }
  1562. LLViewerFetchedTexture* texp = NULL;
  1563. LLLocalTextureObject* ltop = getLocalTextureObject(iter->first, 0);
  1564. if (ltop && ltop->getImage())
  1565. {
  1566. texp = ltop->getImage()->asFetched();
  1567. }
  1568. if (!texp)
  1569. {
  1570. llinfos << "LocTex " << name << ": no LLViewerTexture" << llendl;
  1571. continue;
  1572. }
  1573. if (ltop->getImage()->getID() == IMG_DEFAULT_AVATAR)
  1574. {
  1575. llinfos << "LocTex " << name << ": none" << llendl;
  1576. continue;
  1577. }
  1578. llinfos << "LocTex " << name;
  1579. if (is_god)
  1580. {
  1581. llcont << " - Id: " << texp->getID();
  1582. }
  1583. llcont << " - Size: " << texp->getWidth() << "x" << texp->getHeight()
  1584. << " - Discard level: " << texp->getDiscardLevel()
  1585. << " - Priority: " << texp->getDecodePriority() << llendl;
  1586. }
  1587. }
  1588. //static
  1589. void LLVOAvatarSelf::onLocalTextureLoaded(bool success,
  1590. LLViewerFetchedTexture* texp,
  1591. LLImageRaw* src_raw_imagep,
  1592. LLImageRaw* src_aux_imagep,
  1593. S32 discard_level,
  1594. bool is_final,
  1595. void* userdata)
  1596. {
  1597. LLAvatarTexData* datap = (LLAvatarTexData*)userdata;
  1598. LLVOAvatarSelf* self =
  1599. (LLVOAvatarSelf*)gObjectList.findAvatar(datap->mAvatarID);
  1600. if (self)
  1601. {
  1602. self->localTextureLoaded(success, texp, src_raw_imagep, src_aux_imagep,
  1603. discard_level, is_final, userdata);
  1604. }
  1605. // Ensure data is cleaned up
  1606. if (is_final || !success)
  1607. {
  1608. delete datap;
  1609. }
  1610. }
  1611. //virtual
  1612. void LLVOAvatarSelf::setImage(U8 te, LLViewerTexture* imagep, U32 index)
  1613. {
  1614. if (isIndexLocalTexture((ETextureIndex)te))
  1615. {
  1616. setLocalTexture((ETextureIndex)te, imagep, false, index);
  1617. }
  1618. else
  1619. {
  1620. setTEImage(te, imagep);
  1621. }
  1622. }
  1623. //virtual
  1624. LLViewerTexture* LLVOAvatarSelf::getImage(U8 te, U32 index) const
  1625. {
  1626. if (isIndexLocalTexture((ETextureIndex)te))
  1627. {
  1628. return getLocalTextureGL((ETextureIndex)te, index);
  1629. }
  1630. return getTEImage(te);
  1631. }
  1632. //static
  1633. void LLVOAvatarSelf::dumpTotalLocalTextureByteCount()
  1634. {
  1635. S32 gl_bytes = 0;
  1636. gAgentAvatarp->getLocalTextureByteCount(&gl_bytes);
  1637. llinfos << "Total Avatar LocTex GL:" << gl_bytes / 1024 << "KB" << llendl;
  1638. }
  1639. bool LLVOAvatarSelf::getIsCloud()
  1640. {
  1641. // Do we have our body parts ?
  1642. if (gAgentWearables.getWearableCount(LLWearableType::WT_SHAPE) == 0 ||
  1643. gAgentWearables.getWearableCount(LLWearableType::WT_HAIR) == 0 ||
  1644. gAgentWearables.getWearableCount(LLWearableType::WT_EYES) == 0 ||
  1645. gAgentWearables.getWearableCount(LLWearableType::WT_SKIN) == 0)
  1646. {
  1647. LL_DEBUGS("Avatar") << "Missing body part" << LL_ENDL;
  1648. return true;
  1649. }
  1650. if (!isTextureDefined(TEX_HAIR, 0))
  1651. {
  1652. LL_DEBUGS("Avatar") << "No hair texture" << LL_ENDL;
  1653. return true;
  1654. }
  1655. if (!mPreviousFullyLoaded)
  1656. {
  1657. if (!isLocalTextureDataAvailable(getLayerSet(BAKED_LOWER)) &&
  1658. !isTextureDefined(TEX_LOWER_BAKED, 0))
  1659. {
  1660. LL_DEBUGS("Avatar") << "Lower textures not baked" << LL_ENDL;
  1661. return true;
  1662. }
  1663. if (!isLocalTextureDataAvailable(getLayerSet(BAKED_UPPER)) &&
  1664. !isTextureDefined(TEX_UPPER_BAKED, 0))
  1665. {
  1666. LL_DEBUGS("Avatar") << "Upper textures not baked" << LL_ENDL;
  1667. return true;
  1668. }
  1669. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  1670. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1671. {
  1672. if (i == BAKED_SKIRT && !wearing_skirt)
  1673. {
  1674. continue;
  1675. }
  1676. const BakedTextureData& texture_data = mBakedTextureDatas[i];
  1677. if (!isTextureDefined(texture_data.mTextureIndex, 0))
  1678. {
  1679. continue;
  1680. }
  1681. // Check for the case that texture is defined but not sufficiently
  1682. // loaded to display anything.
  1683. const LLViewerTexture* baked_img =
  1684. getImage(texture_data.mTextureIndex, 0);
  1685. if (!baked_img || !baked_img->hasGLTexture())
  1686. {
  1687. LL_DEBUGS("Avatar") << "Texture at index " << i
  1688. << " (texture index is "
  1689. << texture_data.mTextureIndex
  1690. << ") is not loaded" << LL_ENDL;
  1691. return true;
  1692. }
  1693. }
  1694. LL_DEBUGS("Avatar") << "Avatar de-clouded" << LL_ENDL;
  1695. }
  1696. return false;
  1697. }
  1698. const LLUUID& LLVOAvatarSelf::grabBakedTexture(EBakedTextureIndex baked_index) const
  1699. {
  1700. if (!canGrabBakedTexture(baked_index))
  1701. {
  1702. return LLUUID::null;
  1703. }
  1704. ETextureIndex tex_index =
  1705. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex(baked_index);
  1706. if (tex_index == TEX_NUM_INDICES)
  1707. {
  1708. return LLUUID::null;
  1709. }
  1710. return getTEImage(tex_index)->getID();
  1711. }
  1712. bool LLVOAvatarSelf::canGrabBakedTexture(EBakedTextureIndex baked_index) const
  1713. {
  1714. ETextureIndex tex_index =
  1715. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex(baked_index);
  1716. if (tex_index == TEX_NUM_INDICES)
  1717. {
  1718. return false;
  1719. }
  1720. // Check if the texture has not been baked yet.
  1721. if (!isTextureDefined(tex_index, 0))
  1722. {
  1723. LL_DEBUGS("Avatar") << "getTEImage( " << (U32) tex_index
  1724. << " )->getID() == IMG_DEFAULT_AVATAR" << LL_ENDL;
  1725. return false;
  1726. }
  1727. if (gAgent.isGodlikeWithoutAdminMenuFakery())
  1728. {
  1729. return true;
  1730. }
  1731. // Check permissions of textures that show up in the baked texture. We
  1732. // do not want people copying people's work via baked textures.
  1733. const LLAvatarAppearanceDictionary::BakedEntry* baked_dict =
  1734. gAvatarAppDictp->getBakedTexture(baked_index);
  1735. const texture_vec_t& textures = baked_dict->mLocalTextures;
  1736. for (U32 t = 0, tcount = textures.size(); t < tcount; ++t)
  1737. {
  1738. const ETextureIndex t_index = textures[t];
  1739. LLWearableType::EType wearable_type =
  1740. LLAvatarAppearanceDictionary::getTEWearableType(t_index);
  1741. U32 wcount = gAgentWearables.getWearableCount(wearable_type);
  1742. LL_DEBUGS("Avatar") << "Checking index " << (U32)t_index << " count: "
  1743. << wcount << LL_ENDL;
  1744. for (U32 w = 0; w < wcount; ++w)
  1745. {
  1746. LLViewerWearable* wearablep =
  1747. gAgentWearables.getViewerWearable(wearable_type, w);
  1748. if (!wearablep) continue;
  1749. const LLLocalTextureObject* ltop =
  1750. wearablep->getLocalTextureObject((S32)t_index);
  1751. const LLUUID& texture_id = ltop->getID();
  1752. if (texture_id != IMG_DEFAULT_AVATAR &&
  1753. texture_id != IMG_INVISIBLE &&
  1754. !HBObjectBackup::validateAssetPerms(texture_id, true))
  1755. {
  1756. return false;
  1757. }
  1758. }
  1759. }
  1760. return true;
  1761. }
  1762. void LLVOAvatarSelf::addLocalTextureStats(ETextureIndex type,
  1763. LLViewerFetchedTexture* imagep,
  1764. F32 texel_area_ratio,
  1765. bool render_avatar,
  1766. bool covered_by_baked)
  1767. {
  1768. if (covered_by_baked || !imagep || !isIndexLocalTexture(type))
  1769. {
  1770. return;
  1771. }
  1772. if (imagep->getID() != IMG_DEFAULT_AVATAR)
  1773. {
  1774. if (imagep->getDiscardLevel() != 0)
  1775. {
  1776. // Note: used to be 512x512, but increased to take into account
  1777. // larger (1024x1024) new bakes. HB
  1778. constexpr F32 MAX_AREA = 1024.f * 1024.f;
  1779. F32 desired_pixels = llmin(mPixelArea, MAX_AREA);
  1780. imagep->setBoostLevel(LLGLTexture::BOOST_AVATAR_SELF);
  1781. #if !LL_IMPLICIT_SETNODELETE
  1782. imagep->setNoDelete();
  1783. #endif
  1784. imagep->setAdditionalDecodePriority(SELF_ADDITIONAL_PRI);
  1785. imagep->resetTextureStats();
  1786. imagep->setMaxVirtualSizeResetInterval(S32_MAX);
  1787. imagep->addTextureStats(desired_pixels / texel_area_ratio);
  1788. imagep->forceUpdateBindStats();
  1789. if (imagep->getDiscardLevel() < 0)
  1790. {
  1791. mHasGrey = true; // For statistics gathering
  1792. }
  1793. }
  1794. }
  1795. else
  1796. {
  1797. // Texture asset is missing
  1798. mHasGrey = true; // For statistics gathering
  1799. }
  1800. }
  1801. LLLocalTextureObject* LLVOAvatarSelf::getLocalTextureObject(ETextureIndex i,
  1802. U32 wearable_index) const
  1803. {
  1804. LLWearableType::EType type = gAvatarAppDictp->getTEWearableType(i);
  1805. LLViewerWearable* wearable =
  1806. gAgentWearables.getViewerWearable(type, wearable_index);
  1807. return wearable ? wearable->getLocalTextureObject(i) : NULL;
  1808. }
  1809. // Used by the LayerSet (layer sets do not in general know what textures depend
  1810. // on them).
  1811. ETextureIndex LLVOAvatarSelf::getBakedTE(const LLViewerTexLayerSet* layerset) const
  1812. {
  1813. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1814. {
  1815. if (layerset == mBakedTextureDatas[i].mTexLayerSet)
  1816. {
  1817. return mBakedTextureDatas[i].mTextureIndex;
  1818. }
  1819. }
  1820. llassert(false);
  1821. return TEX_HEAD_BAKED;
  1822. }
  1823. // A new baked texture has been successfully uploaded and we can start using it
  1824. // now.
  1825. void LLVOAvatarSelf::setNewBakedTexture(EBakedTextureIndex i, const LLUUID& id)
  1826. {
  1827. ETextureIndex index =
  1828. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex(i);
  1829. setNewBakedTexture(index, id);
  1830. }
  1831. // A new baked texture has been successfully uploaded and we can start using it
  1832. // now.
  1833. void LLVOAvatarSelf::setNewBakedTexture(ETextureIndex te, const LLUUID& uuid)
  1834. {
  1835. // Baked textures live on other sims.
  1836. LLHost target_host = getObjectHost();
  1837. setTEImage(te,
  1838. LLViewerTextureManager::getFetchedTextureFromHost(uuid,
  1839. FTT_HOST_BAKE,
  1840. target_host));
  1841. updateMeshTextures();
  1842. dirtyMesh();
  1843. refreshAttachmentBakes();
  1844. setAvatarCullingDirty();
  1845. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  1846. gAvatarAppDictp->getTexture(te);
  1847. if (t_dict && t_dict->mIsBakedTexture)
  1848. {
  1849. llinfos << "New baked texture: " << t_dict->mName << " UUID: "
  1850. << uuid <<llendl;
  1851. }
  1852. else
  1853. {
  1854. llwarns << "New baked texture: unknown te " << te << llendl;
  1855. }
  1856. // RN: throttle uploads
  1857. if (!hasPendingBakedUploads())
  1858. {
  1859. gAgent.sendAgentSetAppearance();
  1860. }
  1861. }
  1862. // A baked texture Id was received from a cache query, make it active
  1863. void LLVOAvatarSelf::setCachedBakedTexture(ETextureIndex te,
  1864. const LLUUID& uuid)
  1865. {
  1866. setTETexture(te, uuid);
  1867. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1868. {
  1869. LLViewerTexLayerSet* layerset = getTexLayerSet(i);
  1870. if (layerset && mBakedTextureDatas[i].mTextureIndex == te)
  1871. {
  1872. if (mInitialBakeIDs[i].notNull())
  1873. {
  1874. if (mInitialBakeIDs[i] == uuid)
  1875. {
  1876. llinfos << "baked texture #" << i
  1877. << " correctly loaded at login: " << llendl;
  1878. }
  1879. else
  1880. {
  1881. llwarns << "baked texture #" << i
  1882. << " does not match id loaded at login" << llendl;
  1883. }
  1884. mInitialBakeIDs[i].setNull();
  1885. }
  1886. layerset->cancelUpload();
  1887. }
  1888. }
  1889. }
  1890. //static
  1891. void LLVOAvatarSelf::processRebakeAvatarTextures(LLMessageSystem* msg, void**)
  1892. {
  1893. LLUUID texture_id;
  1894. msg->getUUID("TextureData", "TextureID", texture_id);
  1895. if (!isAgentAvatarValid()) return;
  1896. // If this is a texture corresponding to one of our baked entries, just
  1897. // rebake that layer set.
  1898. bool found = false;
  1899. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  1900. iter = gAvatarAppDictp->getTextures().begin(),
  1901. end = gAvatarAppDictp->getTextures().end();
  1902. iter != end; ++iter)
  1903. {
  1904. const ETextureIndex index = iter->first;
  1905. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  1906. iter->second;
  1907. if (t_dict->mIsBakedTexture &&
  1908. texture_id == gAgentAvatarp->getTEImage(index)->getID())
  1909. {
  1910. LLViewerTexLayerSet* layer_set = gAgentAvatarp->getLayerSet(index);
  1911. if (layer_set)
  1912. {
  1913. llinfos << "TAT: rebake - matched entry " << (S32)index
  1914. << llendl;
  1915. gAgentAvatarp->invalidateComposite(layer_set, true);
  1916. found = true;
  1917. gViewerStats.incStat(LLViewerStats::ST_TEX_REBAKES);
  1918. }
  1919. break;
  1920. }
  1921. }
  1922. if (found)
  1923. {
  1924. // Not sure if this is necessary, but forceBakeAllTextures() does it.
  1925. gAgentAvatarp->updateMeshTextures();
  1926. }
  1927. else
  1928. {
  1929. // If texture not found, rebake all entries.
  1930. gAgentAvatarp->forceBakeAllTextures();
  1931. }
  1932. }
  1933. void LLVOAvatarSelf::forceBakeAllTextures(bool slam_for_debug)
  1934. {
  1935. llinfos << "TAT: forced full rebake. " << llendl;
  1936. if (mIsEditingAppearance)
  1937. {
  1938. slam_for_debug = false;
  1939. }
  1940. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  1941. {
  1942. ETextureIndex baked_index = mBakedTextureDatas[i].mTextureIndex;
  1943. LLViewerTexLayerSet* layer_set = getLayerSet(baked_index);
  1944. if (layer_set)
  1945. {
  1946. if (slam_for_debug)
  1947. {
  1948. layer_set->setUpdatesEnabled(true);
  1949. layer_set->cancelUpload();
  1950. }
  1951. invalidateComposite(layer_set, true);
  1952. gViewerStats.incStat(LLViewerStats::ST_TEX_REBAKES);
  1953. }
  1954. else
  1955. {
  1956. llwarns << "TAT: NO LAYER SET FOR " << (S32)baked_index << llendl;
  1957. }
  1958. }
  1959. // Is this needed really ?
  1960. updateMeshTextures();
  1961. static LLCachedControl<bool> aggressive_rebake(gSavedSettings,
  1962. "AvatarAggressiveRebake");
  1963. if (slam_for_debug && aggressive_rebake)
  1964. {
  1965. // This is equivalent to entering and exiting the Edit Appearance mode
  1966. // and should slam all baked textures for good, ensuring they all get
  1967. // rebaked at next frame.
  1968. gAgentQueryManager.resetPendingQueries();
  1969. mIsEditingAppearance = true;
  1970. mUseLocalAppearance = true;
  1971. updateTextures();
  1972. invalidateAll();
  1973. updateMeshTextures();
  1974. gAgent.sendAgentSetAppearance();
  1975. mUseLocalAppearance = false;
  1976. mIsEditingAppearance = false;
  1977. }
  1978. }
  1979. void LLVOAvatarSelf::requestLayerSetUpdate(ETextureIndex index)
  1980. {
  1981. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  1982. gAvatarAppDictp->getTexture(index);
  1983. if (!t_dict || !t_dict->mIsLocalTexture || !t_dict->mIsUsedByBakedTexture)
  1984. {
  1985. return;
  1986. }
  1987. EBakedTextureIndex baked_index = t_dict->mBakedTextureIndex;
  1988. if (mBakedTextureDatas[baked_index].mTexLayerSet)
  1989. {
  1990. mBakedTextureDatas[baked_index].mTexLayerSet->requestUpdate();
  1991. }
  1992. }
  1993. LLViewerTexLayerSet* LLVOAvatarSelf::getLayerSet(ETextureIndex index)
  1994. {
  1995. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  1996. gAvatarAppDictp->getTexture(index);
  1997. if (!t_dict || !t_dict->mIsUsedByBakedTexture)
  1998. {
  1999. return NULL;
  2000. }
  2001. EBakedTextureIndex baked_index = t_dict->mBakedTextureIndex;
  2002. return getLayerSet(baked_index);
  2003. }
  2004. LLViewerTexLayerSet* LLVOAvatarSelf::getLayerSet(EBakedTextureIndex baked_index)
  2005. {
  2006. if (baked_index < 0 || baked_index >= BAKED_NUM_INDICES)
  2007. {
  2008. return NULL;
  2009. }
  2010. return getTexLayerSet(baked_index);
  2011. }
  2012. //virtual
  2013. void LLVOAvatarSelf::updateMotions(e_update_t update_type)
  2014. {
  2015. LLCharacter::updateMotions(update_type);
  2016. static LLCachedControl<bool> send_data(gSavedSettings,
  2017. "PuppetrySendAttachmentsData");
  2018. if (!send_data)
  2019. {
  2020. return;
  2021. }
  2022. // Post motion update
  2023. if (!mAttachmentUpdateEnabled ||
  2024. gFrameTimeSeconds < mAttachmentUpdateExpiry)
  2025. {
  2026. return;
  2027. }
  2028. mAttachmentUpdateExpiry = gFrameTimeSeconds + mAttachmentUpdatePeriod;
  2029. LLViewerRegion* regionp = gAgent.getRegion();
  2030. if (!regionp ||
  2031. !regionp->getRegionFlag(REGION_FLAGS_ENABLE_ANIMATION_TRACKING))
  2032. {
  2033. return;
  2034. }
  2035. LLVector3 pos;
  2036. LLQuaternion rot;
  2037. const LLVector3& agent_pos = getPositionRegion();
  2038. LLQuaternion agent_inv_rot(~getWorldRotation());
  2039. LLMessageSystem* msg = gMessageSystemp;
  2040. bool start_new_message = true;
  2041. for (attachment_map_t::iterator it = mAttachmentPoints.begin(),
  2042. end = mAttachmentPoints.end();
  2043. it != end; ++it)
  2044. {
  2045. LLViewerJointAttachment* attachp = it->second;
  2046. if (!attachp || attachp->getIsHUDAttachment()) continue;
  2047. pos = attachp->getWorldPosition() - agent_pos;
  2048. rot = attachp->getWorldRotation() * agent_inv_rot;
  2049. if (!attachp->hasChanged(pos, rot))
  2050. {
  2051. continue;
  2052. }
  2053. attachp->setLastTracked(pos, rot);
  2054. if (start_new_message)
  2055. {
  2056. start_new_message = false;
  2057. msg->newMessageFast(_PREHASH_AgentAnimationTracking);
  2058. msg->nextBlockFast(_PREHASH_AgentData);
  2059. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2060. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2061. }
  2062. msg->nextBlockFast(_PREHASH_AttachmentPointUpdate);
  2063. msg->addU8Fast(_PREHASH_AttachmentPoint, (U8)it->first);
  2064. msg->addVector3Fast(_PREHASH_Position, pos);
  2065. msg->addQuatFast(_PREHASH_Rotation, rot);
  2066. msg->addF32Fast(_PREHASH_Radius, 0.f);
  2067. if (msg->isSendFull())
  2068. {
  2069. gAgent.sendMessage();
  2070. start_new_message = true;
  2071. }
  2072. }
  2073. if (!start_new_message)
  2074. {
  2075. gAgent.sendMessage();
  2076. }
  2077. }
  2078. void LLVOAvatarSelf::setAttachmentUpdatePeriod(F32 period_sec)
  2079. {
  2080. constexpr F32 MIN_PERIOD = 0.01f;
  2081. constexpr F32 MAX_PERIOD = 2.f;
  2082. mAttachmentUpdatePeriod = llclamp(period_sec, MIN_PERIOD, MAX_PERIOD);
  2083. }
  2084. //static
  2085. bool LLVOAvatarSelf::canUseServerBaking()
  2086. {
  2087. return isAgentAvatarValid() && gAgentAvatarp->getRegion() &&
  2088. gAgentAvatarp->getRegion()->getCentralBakeVersion();
  2089. }
  2090. //static
  2091. void LLVOAvatarSelf::onCustomizeStart()
  2092. {
  2093. if (isAgentAvatarValid())
  2094. {
  2095. gAgentAvatarp->mIsEditingAppearance = true;
  2096. gAgentAvatarp->mUseLocalAppearance = true;
  2097. gAgentAvatarp->invalidateAll();
  2098. gAgentAvatarp->updateMeshTextures();
  2099. gAgentAvatarp->updateTextures();
  2100. }
  2101. }
  2102. //static
  2103. void LLVOAvatarSelf::onCustomizeEnd()
  2104. {
  2105. if (isAgentAvatarValid())
  2106. {
  2107. gAgentAvatarp->mIsEditingAppearance = false;
  2108. if (!canUseServerBaking())
  2109. {
  2110. // *FIXME: move to sendAgentSetAppearance, make conditional on
  2111. // upload complete.
  2112. gAgentAvatarp->mUseLocalAppearance = false;
  2113. }
  2114. else
  2115. {
  2116. gAppearanceMgr.incrementCofVersion();
  2117. }
  2118. gAgentAvatarp->invalidateAll();
  2119. }
  2120. }
  2121. #if 0 // Removed from LL's viewer, at some point... Prevented some small mesh
  2122. // avatars from getting leveled with the ground using the shape Hover
  2123. // visual parameter.
  2124. //virtual
  2125. void LLVOAvatarSelf::computeBodySize(bool force)
  2126. {
  2127. LLAvatarAppearance::computeBodySize();
  2128. // Certain configurations of avatars can force the overall height (with
  2129. // offset) to go negative. Enforce a constraint to make sure we don't go
  2130. // below 1.1 meters (server-enforced limit). Camera positioning and other
  2131. // things start to break down when your avatar is "walking" while being
  2132. // fully underground
  2133. if (getWearableData() && !LLApp::isExiting() &&
  2134. // Do not force a hover parameter change while we have pending
  2135. // attachments, which may be mesh-based with joint offsets.
  2136. mPendingAttachment.size() == 0)
  2137. {
  2138. LLViewerWearable* shape =
  2139. (LLViewerWearable*)getWearableData()->getWearable(LLWearableType::WT_SHAPE,
  2140. 0);
  2141. bool loaded = true;
  2142. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  2143. {
  2144. const LLViewerObject* object = mAttachedObjectsVector[i].first;
  2145. if (object)
  2146. {
  2147. loaded &= !object->isDrawableState(LLDrawable::REBUILD_ALL);
  2148. if (!loaded && shape && !shape->getVolatile())
  2149. {
  2150. llwarns << "Caught unloaded attachment at point: "
  2151. << mAttachedObjectsVector[i].second->getName()
  2152. << " - Object: "
  2153. << object->getAttachmentItemID()
  2154. << ". Skipping enforcement." << llendl;
  2155. break;
  2156. }
  2157. LL_DEBUGS("Avatar") << "Attachment at point: "
  2158. << mAttachedObjectsVector[i].second->getName()
  2159. << " object: "
  2160. << object->getAttachmentItemID()
  2161. << LL_ENDL;
  2162. }
  2163. }
  2164. if ((loaded || force) && shape && !shape->getVolatile())
  2165. {
  2166. F32 hover_value = shape->getVisualParamWeight(AVATAR_HOVER);
  2167. if (hover_value < 0.0f && mBodySize.mV[VZ] + hover_value < 1.1f)
  2168. {
  2169. // Avoid floating point rounding making the above check
  2170. // continue to fail.
  2171. hover_value = -mBodySize.mV[VZ] + 1.1f;
  2172. llassert(mBodySize.mV[VZ] + hover_value >= 1.1f);
  2173. // Do not force the hover value to be greater than 0.
  2174. hover_value = llmin(hover_value, 0.f);
  2175. LL_DEBUGS("Avatar") << "Changed hover value to: "
  2176. << hover_value << " from: "
  2177. << mAvatarOffset.mV[VZ] << LL_ENDL;
  2178. mAvatarOffset.mV[VZ] = hover_value;
  2179. shape->setVisualParamWeight(AVATAR_HOVER, hover_value, false);
  2180. if (canUseServerBaking() && !useAvatarHoverHeight())
  2181. {
  2182. F32 offset = gSavedSettings.getF32("AvatarOffsetZ");
  2183. #if 1
  2184. F32 factor = gSavedSettings.getF32("HoverToZOffsetFactor");
  2185. if (factor > 1.f)
  2186. {
  2187. // Hover is wrongly accounted twice in LL's viewer...
  2188. hover_value *= factor;
  2189. }
  2190. #endif
  2191. if (hover_value != offset)
  2192. {
  2193. gSavedSettings.setF32("AvatarOffsetZ", hover_value);
  2194. }
  2195. }
  2196. }
  2197. }
  2198. }
  2199. }
  2200. #endif
  2201. //virtual
  2202. bool LLVOAvatarSelf::shouldRenderRigged() const
  2203. {
  2204. return gAgent.needsRenderAvatar();
  2205. }
  2206. // HACK: this will null out the avatar's local texture IDs before the TE message
  2207. // is sent to ensure local texture IDs are not sent to other clients in
  2208. // the area. This is a short-term solution. The long term solution will be
  2209. // to not set the texture IDs in the avatar object, and keep them only in
  2210. // the wearable. This will involve further refactoring that is too risky
  2211. // for the initial release of 2.0.
  2212. void LLVOAvatarSelf::sendAppearanceMessage(LLMessageSystem* mesgsys) const
  2213. {
  2214. LLUUID texture_id[TEX_NUM_INDICES];
  2215. // Pack away current TEs to make sure we don't send them out
  2216. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  2217. iter = gAvatarAppDictp->getTextures().begin(),
  2218. end = gAvatarAppDictp->getTextures().end();
  2219. iter != end; ++iter)
  2220. {
  2221. const ETextureIndex index = iter->first;
  2222. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  2223. iter->second;
  2224. if (t_dict && !t_dict->mIsBakedTexture)
  2225. {
  2226. LLTextureEntry* entry = getTE((U8)index);
  2227. if (entry)
  2228. {
  2229. texture_id[index] = entry->getID();
  2230. entry->setID(IMG_DEFAULT_AVATAR);
  2231. }
  2232. }
  2233. }
  2234. packTEMessage(mesgsys);
  2235. // Unpack TEs to make sure we don't re-trigger a bake
  2236. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  2237. iter = gAvatarAppDictp->getTextures().begin(),
  2238. end = gAvatarAppDictp->getTextures().end();
  2239. iter != end; ++iter)
  2240. {
  2241. const ETextureIndex index = iter->first;
  2242. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  2243. iter->second;
  2244. if (t_dict && !t_dict->mIsBakedTexture)
  2245. {
  2246. LLTextureEntry* entry = getTE((U8)index);
  2247. if (entry)
  2248. {
  2249. entry->setID(texture_id[index]);
  2250. }
  2251. }
  2252. }
  2253. }
  2254. void LLVOAvatarSelf::sendHoverHeight() const
  2255. {
  2256. const std::string& url = gAgent.getRegionCapability("AgentPreferences");
  2257. if (url.empty())
  2258. {
  2259. return;
  2260. }
  2261. LLSD update = LLSD::emptyMap();
  2262. const LLVector3& hover_offset = getHoverOffset();
  2263. update["hover_height"] = hover_offset.mV[VZ];
  2264. mLastHoverOffsetSent = hover_offset;
  2265. LL_DEBUGS("Avatar") << "Sending hover height value for self: "
  2266. << hover_offset.mV[VZ] << "m" << LL_ENDL;
  2267. LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, update,
  2268. "Hover height sent to sim",
  2269. "Failed to send hover height to sim");
  2270. }
  2271. void LLVOAvatarSelf::setHoverOffset(const LLVector3& hover_offset,
  2272. bool send_update)
  2273. {
  2274. if (getHoverOffset() != hover_offset)
  2275. {
  2276. llinfos << "Setting hover value for self due to change: "
  2277. << hover_offset[2] << llendl;
  2278. LLVOAvatar::setHoverOffset(hover_offset, send_update);
  2279. }
  2280. if (send_update && hover_offset != mLastHoverOffsetSent)
  2281. {
  2282. llinfos << "Sending hover value for self due to change: "
  2283. << hover_offset[2] << LL_ENDL;
  2284. sendHoverHeight();
  2285. }
  2286. }
  2287. bool LLVOAvatarSelf::needsRenderBeam()
  2288. {
  2289. // No beam for selected far objects when PrivateLookAt is true
  2290. static LLCachedControl<bool> private_point_at(gSavedSettings,
  2291. "PrivatePointAt");
  2292. static LLCachedControl<U32> point_at_limit(gSavedSettings,
  2293. "PrivatePointAtLimit");
  2294. LLObjectSelectionHandle selection;
  2295. selection = gSelectMgr.getSelection();
  2296. LLViewerObject* objp = selection->getFirstObject();
  2297. LLVector3d agent_pos = gAgent.getPositionGlobal();
  2298. if (objp && private_point_at &&
  2299. (objp->getPositionGlobal() - agent_pos).length() > point_at_limit)
  2300. {
  2301. return false;
  2302. }
  2303. bool is_touching_or_grabbing = gToolMgr.isCurrentTool(&gToolGrab) &&
  2304. gToolGrab.isEditing();
  2305. if (is_touching_or_grabbing)
  2306. {
  2307. objp = gToolGrab.getEditingObject();
  2308. if (objp && !objp->isAttachment() &&
  2309. (objp->getPositionGlobal() - agent_pos).length() <= point_at_limit)
  2310. {
  2311. return true;
  2312. }
  2313. // Do not render selection beam on hud objects, or on far objects when
  2314. // PrivateLookAt is true
  2315. is_touching_or_grabbing = false;
  2316. }
  2317. return is_touching_or_grabbing ||
  2318. ((mAttachmentState & AGENT_STATE_EDITING) != 0 &&
  2319. gSelectMgr.shouldShowSelection());
  2320. }
  2321. void LLVOAvatarSelf::resetHUDAttachments()
  2322. {
  2323. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  2324. {
  2325. const LLViewerObject* object = mAttachedObjectsVector[i].first;
  2326. if (object && object->isHUDAttachment() && object->mDrawable.notNull())
  2327. {
  2328. gPipeline.markMoved(object->mDrawable);
  2329. }
  2330. }
  2331. }
  2332. void LLVOAvatarSelf::refreshAttachments()
  2333. {
  2334. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  2335. {
  2336. const LLViewerObject* object = mAttachedObjectsVector[i].first;
  2337. if (object && object->isAttachment())
  2338. {
  2339. if (object->mDrawable.notNull())
  2340. {
  2341. gPipeline.markMoved(object->mDrawable);
  2342. }
  2343. object->dirtySpatialGroup();
  2344. }
  2345. }
  2346. }
  2347. void LLVOAvatarSelf::handleTeleportFinished()
  2348. {
  2349. doAfterInterval(boost::bind(&LLVOAvatarSelf::refreshAttachments, this), 2);
  2350. }