llvoavatar.cpp 245 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473
  1. /**
  2. * @file llvoavatar.cpp
  3. * @brief Implementation of LLVOAvatar class which is a derivation of
  4. * LLViewerObject
  5. *
  6. * $LicenseInfo:firstyear=2001&license=viewergpl$
  7. *
  8. * Copyright (c) 2001-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include <stdio.h>
  35. #include <ctype.h>
  36. #include "llvoavatar.h"
  37. #include "imageids.h"
  38. #include "llanimationstates.h"
  39. #include "llapp.h"
  40. #include "llaudioengine.h"
  41. #include "llavatarnamecache.h"
  42. #include "lleditingmotion.h"
  43. #include "llevents.h" // For gEventPumps
  44. #include "llfasttimer.h"
  45. #include "llheadrotmotion.h"
  46. #include "llkeyframefallmotion.h"
  47. #include "llkeyframestandmotion.h"
  48. #include "llkeyframewalkmotion.h"
  49. #include "llnoise.h"
  50. #include "llnotifications.h"
  51. #include "llphysshapebuilderutil.h" // For COLLISION_TOLERANCE
  52. #include "llpolyskeletaldistortion.h"
  53. #include "llraytrace.h"
  54. #include "llrenderutils.h" // For gSphere
  55. #include "llscriptpermissions.h"
  56. #include "llsdserialize.h"
  57. #include "lltargetingmotion.h"
  58. #include "lltrans.h"
  59. #include "sound_ids.h"
  60. #include "llagent.h" // Get state values from here
  61. #include "llagentpilot.h"
  62. #include "llagentwearables.h"
  63. #include "llappearancemgr.h"
  64. #include "llappviewer.h" // For gFrameCount
  65. #include "llavatartracker.h" // For LLAvatarTracker::isAgentFriend()
  66. #include "lldrawpoolalpha.h"
  67. #include "lldrawpoolavatar.h"
  68. #include "llemote.h"
  69. #include "llfirstuse.h"
  70. #include "llgesturemgr.h" // Needed to trigger the voice gestures
  71. #include "llgridmanager.h" // For gIsInSecondLife
  72. #include "llhudeffectspiral.h"
  73. #include "llhudmanager.h"
  74. #include "llhudtext.h"
  75. #include "llinventorybridge.h"
  76. #include "llmanipscale.h"
  77. #include "llmeshrepository.h"
  78. #include "hbobjectbackup.h" // HBObjectBackup::validateAssetPerms()
  79. #include "llphysicsmotion.h"
  80. #include "llpipeline.h"
  81. #include "llpuppetmodule.h"
  82. #include "llpuppetmotion.h"
  83. //MK
  84. #include "mkrlinterface.h"
  85. //mk
  86. #include "llselectmgr.h"
  87. #include "llskinningutil.h"
  88. #include "llviewercamera.h"
  89. #include "llviewercontrol.h"
  90. #include "llviewerinventory.h"
  91. #include "llviewermedia.h"
  92. #include "llviewermessage.h" // For send_generic_message()
  93. #include "llviewerobjectlist.h"
  94. #include "llviewerparcelmgr.h"
  95. #include "llviewershadermgr.h"
  96. #include "llviewerstats.h"
  97. #include "llviewertexlayer.h"
  98. #include "llviewertexturelist.h"
  99. #include "llviewerwearable.h"
  100. #include "llvisualparamhint.h"
  101. #include "llvoavatarpuppet.h"
  102. #include "llvoavatarself.h"
  103. #include "llvoiceclient.h"
  104. #include "llvoicevisualizer.h"
  105. #include "llvovolume.h"
  106. #include "llworld.h"
  107. constexpr U32 JOINT_COUNT_REQUIRED_FOR_FULLRIG = 1;
  108. constexpr F32 MAX_ATTACHMENT_COMPLEXITY = 1.0e6f;
  109. constexpr F32 COMPLEXITY_UPDATE_INTERVAL = 10.f;
  110. using namespace LLAvatarAppearanceDefines;
  111. //-----------------------------------------------------------------------------
  112. // Constants
  113. //-----------------------------------------------------------------------------
  114. // We clamp measured delta_time to this
  115. constexpr F32 DELTA_TIME_MIN = 0.01f;
  116. // Range to insure stability of computations
  117. constexpr F32 DELTA_TIME_MAX = 0.2f;
  118. // Pelvis follow half life while flying
  119. constexpr F32 PELVIS_LAG_FLYING = 0.22f;
  120. // Pelvis follow half life while walking
  121. constexpr F32 PELVIS_LAG_WALKING = 0.4f;
  122. constexpr F32 PELVIS_LAG_MOUSELOOK = 0.15f;
  123. constexpr F32 MOUSELOOK_PELVIS_FOLLOW_FACTOR = 0.5f;
  124. // Amount of deviation allowed between the pelvis and the view direction
  125. // when moving fast & slow
  126. constexpr F32 PELVIS_ROT_THRESHOLD_SLOW = 60.f;
  127. constexpr F32 PELVIS_ROT_THRESHOLD_FAST = 2.f;
  128. // Amount of deviation from up-axis, in degrees
  129. constexpr F32 TORSO_NOISE_AMOUNT = 1.f;
  130. // Time scale factor on torso noise
  131. constexpr F32 TORSO_NOISE_SPEED = 0.2f;
  132. constexpr F32 BREATHE_ROT_MOTION_STRENGTH = 0.05f;
  133. constexpr S32 MIN_REQUIRED_PIXEL_AREA_BODY_NOISE = 10000;
  134. constexpr S32 MIN_REQUIRED_PIXEL_AREA_BREATHE = 10000;
  135. constexpr S32 MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX = 40;
  136. constexpr F32 HEAD_MOVEMENT_AVG_TIME = 0.9f;
  137. constexpr S32 MORPH_MASK_REQUESTED_DISCARD = 0;
  138. // Discard level at which to switch to baked textures. Should probably be 4 or
  139. // 3, but did not want to change it while change other logic - SJB
  140. constexpr S32 SWITCH_TO_BAKED_DISCARD = 5;
  141. constexpr F32 HOVER_EFFECT_MAX_SPEED = 3.f;
  142. constexpr F32 HOVER_EFFECT_STRENGTH = 0.f;
  143. constexpr F32 UNDERWATER_EFFECT_STRENGTH = 0.1f;
  144. constexpr F32 UNDERWATER_FREQUENCY_DAMP = 0.33f;
  145. constexpr F32 APPEARANCE_MORPH_TIME = 0.65f;
  146. constexpr F32 TIME_BEFORE_MESH_CLEANUP = 5.f; // seconds
  147. // Number of avatar instances before releasing memory:
  148. constexpr S32 AVATAR_RELEASE_THRESHOLD = 10;
  149. constexpr F32 FOOT_GROUND_COLLISION_TOLERANCE = 0.25f;
  150. constexpr F32 AVATAR_LOD_TWEAK_RANGE = 0.7f;
  151. constexpr S32 MAX_BUBBLE_CHAT_LENGTH = DB_CHAT_MSG_STR_LEN;
  152. constexpr S32 MAX_BUBBLE_CHAT_UTTERANCES = 12;
  153. constexpr F32 CHAT_FADE_TIME = 8.0;
  154. constexpr F32 BUBBLE_CHAT_TIME = CHAT_FADE_TIME * 3.f;
  155. constexpr F32 DERUTHING_TIMEOUT_SECONDS = 60.f;
  156. enum ERenderName
  157. {
  158. RENDER_NAME_NEVER,
  159. RENDER_NAME_FADE,
  160. RENDER_NAME_ALWAYS
  161. };
  162. //-----------------------------------------------------------------------------
  163. // Callback data
  164. //-----------------------------------------------------------------------------
  165. struct LLTextureMaskData
  166. {
  167. LLTextureMaskData(const LLUUID& id)
  168. : mAvatarID(id),
  169. mLastDiscardLevel(S32_MAX)
  170. {
  171. }
  172. LLUUID mAvatarID;
  173. S32 mLastDiscardLevel;
  174. };
  175. /*********************************************************************************
  176. ** **
  177. ** Begin private LLVOAvatar Support classes
  178. **
  179. **/
  180. //-----------------------------------------------------------------------------
  181. // class LLBodyNoiseMotion
  182. //-----------------------------------------------------------------------------
  183. class LLBodyNoiseMotion final : public LLMotion
  184. {
  185. public:
  186. LLBodyNoiseMotion(const LLUUID& id)
  187. : LLMotion(id)
  188. {
  189. mName = "body_noise";
  190. mTorsoState = new LLJointState;
  191. }
  192. // Functions to support MotionController and MotionRegistry
  193. // Static constructor. All subclasses must implement such a method and
  194. // register it.
  195. LL_INLINE static LLMotion* create(const LLUUID& id)
  196. {
  197. return new LLBodyNoiseMotion(id);
  198. }
  199. // Animation callbacks to be implemented by subclasses
  200. // Motions must specify whether or not they loop
  201. LL_INLINE bool getLoop() override { return true; }
  202. // Lotions must report their total duration
  203. LL_INLINE F32 getDuration() override { return 0.f; }
  204. // Motions must report their "ease in" duration
  205. LL_INLINE F32 getEaseInDuration() override { return 0.f; }
  206. // Motions must report their "ease out" duration.
  207. LL_INLINE F32 getEaseOutDuration() override { return 0.f; }
  208. // Motions must report their priority
  209. LL_INLINE LLJoint::JointPriority getPriority() override
  210. {
  211. return LLJoint::HIGH_PRIORITY;
  212. }
  213. LL_INLINE LLMotionBlendType getBlendType() override
  214. {
  215. return ADDITIVE_BLEND;
  216. }
  217. // Called to determine when a motion should be activated/deactivated based
  218. // on avatar pixel coverage
  219. LL_INLINE F32 getMinPixelArea() override
  220. {
  221. return MIN_REQUIRED_PIXEL_AREA_BODY_NOISE;
  222. }
  223. // Run-time (post constructor) initialization, called after parameters have
  224. // been set; must return true to indicate success and be available for
  225. // activation.
  226. LLMotionInitStatus onInitialize(LLCharacter* character) override
  227. {
  228. if (!mTorsoState->setJoint(character->getJoint(LL_JOINT_KEY_TORSO)))
  229. {
  230. return STATUS_FAILURE;
  231. }
  232. mTorsoState->setUsage(LLJointState::ROT);
  233. addJointState(mTorsoState);
  234. return STATUS_SUCCESS;
  235. }
  236. // Called when a motion is activated. Must return true to indicate success,
  237. // or else it will be deactivated
  238. LL_INLINE bool onActivate() override { return true; }
  239. // Called per time step. Must return true while it is active, and must
  240. // return false when the motion is completed.
  241. bool onUpdate(F32 time, U8* joint_mask) override
  242. {
  243. F32 nx[2];
  244. nx[0] = time * TORSO_NOISE_SPEED;
  245. nx[1] = 0.f;
  246. F32 ny[2];
  247. ny[0] = 0.f;
  248. ny[1] = time * TORSO_NOISE_SPEED;
  249. F32 noiseX = noise2(nx);
  250. F32 noiseY = noise2(ny);
  251. F32 rx = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseX / 0.42f;
  252. F32 ry = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseY / 0.42f;
  253. LLQuaternion tQn;
  254. tQn.setEulerAngles(rx, ry, 0.f);
  255. mTorsoState->setRotation(tQn);
  256. return true;
  257. }
  258. // Called when a motion is deactivated
  259. LL_INLINE void onDeactivate() override {}
  260. private:
  261. // Joint states to be animated
  262. LLPointer<LLJointState> mTorsoState;
  263. };
  264. //-----------------------------------------------------------------------------
  265. // class LLBreatheMotionRot
  266. //-----------------------------------------------------------------------------
  267. class LLBreatheMotionRot final : public LLMotion
  268. {
  269. public:
  270. LLBreatheMotionRot(const LLUUID& id)
  271. : LLMotion(id),
  272. mBreatheRate(1.f),
  273. mCharacter(NULL)
  274. {
  275. mName = "breathe_rot";
  276. mChestState = new LLJointState;
  277. }
  278. // Methods to support MotionController and MotionRegistry
  279. // Static constructor
  280. // all subclasses must implement such a function and register it
  281. LL_INLINE static LLMotion* create(const LLUUID& id)
  282. {
  283. return new LLBreatheMotionRot(id);
  284. }
  285. // Animation callbacks to be implemented by subclasses
  286. // Motions must specify whether or not they loop
  287. LL_INLINE bool getLoop() override { return true; }
  288. // Motions must report their total duration
  289. LL_INLINE F32 getDuration() override { return 0.f; }
  290. // Motions must report their "ease in" duration
  291. LL_INLINE F32 getEaseInDuration() override { return 0.f; }
  292. // Motions must report their "ease out" duration.
  293. LL_INLINE F32 getEaseOutDuration() override { return 0.f; }
  294. // Motions must report their priority
  295. LL_INLINE LLJoint::JointPriority getPriority() override
  296. {
  297. return LLJoint::MEDIUM_PRIORITY;
  298. }
  299. LL_INLINE LLMotionBlendType getBlendType() override
  300. {
  301. return NORMAL_BLEND;
  302. }
  303. // Called to determine when a motion should be activated/deactivated based
  304. // on avatar pixel coverage
  305. LL_INLINE F32 getMinPixelArea() override
  306. {
  307. return MIN_REQUIRED_PIXEL_AREA_BREATHE;
  308. }
  309. // Run-time (post constructor) initialization, called after parameters have
  310. // been set must return true to indicate success and be available for
  311. // activation
  312. LLMotionInitStatus onInitialize(LLCharacter* character) override
  313. {
  314. mCharacter = character;
  315. bool success = true;
  316. if (!mChestState->setJoint(character->getJoint(LL_JOINT_KEY_CHEST)))
  317. {
  318. success = false;
  319. }
  320. if (success)
  321. {
  322. mChestState->setUsage(LLJointState::ROT);
  323. addJointState(mChestState);
  324. }
  325. if (success)
  326. {
  327. return STATUS_SUCCESS;
  328. }
  329. else
  330. {
  331. return STATUS_FAILURE;
  332. }
  333. }
  334. // Called when a motion is activated, must return true to indicate success,
  335. // or else it will be deactivated.
  336. LL_INLINE bool onActivate() override { return true; }
  337. // Called per time step, must return true while it is active, and must
  338. // return false when the motion is completed.
  339. bool onUpdate(F32 time, U8* joint_mask) override
  340. {
  341. mBreatheRate = 1.f;
  342. F32 breathe_amt = (sinf(mBreatheRate * time) * BREATHE_ROT_MOTION_STRENGTH);
  343. mChestState->setRotation(LLQuaternion(breathe_amt,
  344. LLVector3(0.f, 1.f, 0.f)));
  345. return true;
  346. }
  347. // Called when a motion is deactivated
  348. LL_INLINE void onDeactivate() override {}
  349. private:
  350. //-------------------------------------------------------------------------
  351. // joint states to be animated
  352. //-------------------------------------------------------------------------
  353. LLPointer<LLJointState> mChestState;
  354. F32 mBreatheRate;
  355. LLCharacter* mCharacter;
  356. };
  357. //-----------------------------------------------------------------------------
  358. // class LLPelvisFixMotion
  359. //-----------------------------------------------------------------------------
  360. class LLPelvisFixMotion final : public LLMotion
  361. {
  362. public:
  363. LLPelvisFixMotion(const LLUUID& id)
  364. : LLMotion(id), mCharacter(NULL)
  365. {
  366. mName = "pelvis_fix";
  367. mPelvisState = new LLJointState;
  368. }
  369. // functions to support MotionController and MotionRegistry
  370. // Static constructor
  371. // all subclasses must implement such a function and register it
  372. LL_INLINE static LLMotion* create(const LLUUID& id)
  373. {
  374. return new LLPelvisFixMotion(id);
  375. }
  376. // Animation callbacks to be implemented by subclasses
  377. // Motions must specify whether or not they loop
  378. LL_INLINE bool getLoop() override { return true; }
  379. // Motions must report their total duration
  380. LL_INLINE F32 getDuration() override { return 0.f; }
  381. // Motions must report their "ease in" duration
  382. LL_INLINE F32 getEaseInDuration() override { return 0.5f; }
  383. // Motions must report their "ease out" duration.
  384. LL_INLINE F32 getEaseOutDuration() override { return 0.5f; }
  385. // Motions must report their priority
  386. LL_INLINE LLJoint::JointPriority getPriority() override
  387. {
  388. return LLJoint::LOW_PRIORITY;
  389. }
  390. LL_INLINE LLMotionBlendType getBlendType() override
  391. {
  392. return NORMAL_BLEND;
  393. }
  394. // Called to determine when a motion should be activated/deactivated based
  395. // on avatar pixel coverage.
  396. LL_INLINE F32 getMinPixelArea() override
  397. {
  398. return MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX;
  399. }
  400. // Run-time (post constructor) initialization, called after parameters have
  401. // been set/ must return true to indicate success and be available for
  402. // activation
  403. LLMotionInitStatus onInitialize(LLCharacter* character) override
  404. {
  405. mCharacter = character;
  406. if (!mPelvisState->setJoint(character->getJoint(LL_JOINT_KEY_PELVIS)))
  407. {
  408. return STATUS_FAILURE;
  409. }
  410. mPelvisState->setUsage(LLJointState::POS);
  411. addJointState(mPelvisState);
  412. return STATUS_SUCCESS;
  413. }
  414. // Called when a motion is activated, must return true to indicate success,
  415. // or else it will be deactivated.
  416. LL_INLINE bool onActivate() override { return true; }
  417. // Called per time step, must return true while it is active, and must
  418. // return false when the motion is completed.
  419. bool onUpdate(F32 time, U8* joint_mask) override
  420. {
  421. mPelvisState->setPosition(LLVector3::zero);
  422. return true;
  423. }
  424. // Called when a motion is deactivated
  425. LL_INLINE void onDeactivate() override {}
  426. private:
  427. // joint states to be animated
  428. LLPointer<LLJointState> mPelvisState;
  429. LLCharacter* mCharacter;
  430. };
  431. /**
  432. **
  433. ** End LLVOAvatar Support classes
  434. ** **
  435. *****************************************************************************/
  436. //-----------------------------------------------------------------------------
  437. // Static Data
  438. //-----------------------------------------------------------------------------
  439. const LLUUID LLVOAvatar::sStepSoundOnLand = SND_STEP_ON_LAND;
  440. const LLUUID LLVOAvatar::sStepSounds[LL_MCODE_END] =
  441. {
  442. SND_STONE_RUBBER,
  443. SND_METAL_RUBBER,
  444. SND_GLASS_RUBBER,
  445. SND_WOOD_RUBBER,
  446. SND_FLESH_RUBBER,
  447. SND_RUBBER_PLASTIC,
  448. SND_RUBBER_RUBBER
  449. };
  450. LLAvatarAppearanceDictionary* LLVOAvatar::sAvatarDictionary = NULL;
  451. std::string LLVOAvatar::sAgentAppearanceServiceURL;
  452. F32 LLVOAvatar::sRenderDistance = 256.f;
  453. F32 LLVOAvatar::sLODFactor = 1.f;
  454. F32 LLVOAvatar::sPhysicsLODFactor = 1.f;
  455. S32 LLVOAvatar::sNumVisibleAvatars = 0;
  456. S32 LLVOAvatar::sNumLODChangesThisFrame = 0;
  457. S32 LLVOAvatar::sRenderName = RENDER_NAME_ALWAYS;
  458. S32 LLVOAvatar::sNumVisibleChatBubbles = 0;
  459. U32 LLVOAvatar::sMaxNonImpostors = 50;
  460. U32 LLVOAvatar::sMaxNonImpostorsPuppets = 0;
  461. bool LLVOAvatar::sUseImpostors = false;
  462. bool LLVOAvatar::sUsePuppetImpostors = false;
  463. bool LLVOAvatar::sAvatarCullingDirty = false;
  464. bool LLVOAvatar::sRenderGroupTitles = true;
  465. bool LLVOAvatar::sDebugInvisible = false;
  466. bool LLVOAvatar::sShowAttachmentPoints = false;
  467. bool LLVOAvatar::sShowAnimationDebug = false;
  468. bool LLVOAvatar::sVisibleInFirstPerson = false;
  469. bool LLVOAvatar::sAvatarPhysics = false;
  470. bool LLVOAvatar::sJointDebug = false;
  471. bool LLVOAvatar::sLipSyncEnabled = false;
  472. F32 LLVOAvatar::sUnbakedTime = 0.f;
  473. F32 LLVOAvatar::sUnbakedUpdateTime = 0.f;
  474. F32 LLVOAvatar::sGreyTime = 0.f;
  475. F32 LLVOAvatar::sGreyUpdateTime = 0.f;
  476. LLVOAvatar::colors_map_t LLVOAvatar::sMinimapColorsMap;
  477. //-----------------------------------------------------------------------------
  478. // Forward declarations
  479. //-----------------------------------------------------------------------------
  480. static F32 calc_bouncy_animation(F32 x);
  481. LLVOAvatar::LLVOAvatar(const LLUUID& id, LLViewerRegion* regionp)
  482. : LLAvatarAppearance(&gAgentWearables),
  483. LLViewerObject(id, LL_PCODE_LEGACY_AVATAR, regionp),
  484. mSpecialRenderMode(0),
  485. mAttachmentSurfaceArea(0.f),
  486. mAttachmentGeometryBytes(0),
  487. mTurning(false),
  488. mLastSkeletonSerialNum(0),
  489. mIsSitting(false),
  490. mTimeVisible(),
  491. mTyping(false),
  492. mMeshValid(false),
  493. mVisible(false),
  494. mNeedsImpostorUpdate(true),
  495. mNeedsAnimUpdate(true),
  496. mNeedsExtentUpdate(false),
  497. mNextFrameForExtentUpdate(0),
  498. mDirtyMesh(2), // Dirty geometry, need to regenerate.
  499. mMeshTexturesDirty(false),
  500. mSpeed(0.f),
  501. mSpeedAccum(0.f),
  502. mTimeLast(0.f),
  503. mRippleTimeLast(0.f),
  504. mWindFreq(0.f),
  505. mRipplePhase(0.f),
  506. mBelowWater(false),
  507. mInAir(false),
  508. mStepOnLand(true),
  509. mStepMaterial(0),
  510. mLastAppearanceBlendTime(0.f),
  511. mEnableDefaultMotions(true),
  512. mAppearanceAnimating(false),
  513. mWasOnGroundLeft(false),
  514. mWasOnGroundRight(false),
  515. mNextVoiceVisualizerUpdate(0.f),
  516. mLipSyncActive(false),
  517. mOohMorph(NULL),
  518. mAahMorph(NULL),
  519. mCurrentGesticulationLevel(0),
  520. mNewResident(false),
  521. mNameAway(false),
  522. mNameBusy(false),
  523. mNameTyping(false),
  524. mNameMute(-1),
  525. mNameAppearance(false),
  526. mCachedVisualMuteUpdateTime(0.f),
  527. mCachedVisualMute(false),
  528. //MK
  529. mCachedRLVMute(false),
  530. //mk
  531. mRenderGroupTitles(sRenderGroupTitles),
  532. mFirstTEMessageReceived(false),
  533. mFirstAppearanceMessageReceived(false),
  534. mCulled(false),
  535. mVisibilityRank(0),
  536. mNeedsSkin(false),
  537. mLastSkinTime(0.f),
  538. mUpdatePeriod(1),
  539. mImpostorDistance(0.f),
  540. mImpostorPixelArea(0.f),
  541. mVisualComplexityStale(true),
  542. mComplexityUpdateTime(0.f),
  543. mVisualComplexity(0),
  544. mVisuallyMuteSetting(AV_RENDER_NORMALLY),
  545. mMutedAVColor(LLColor4::white),
  546. mFullyLoaded(false),
  547. mPreviousFullyLoaded(false),
  548. mFullyLoadedInitialized(false),
  549. mLoadedCallbacksPaused(false),
  550. mIsEditingAppearance(false),
  551. mUseLocalAppearance(false),
  552. mUseServerBakes(false),
  553. mLastUpdateRequestCOFVersion(LLViewerInventoryCategory::VERSION_UNKNOWN),
  554. mLastUpdateReceivedCOFVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
  555. {
  556. LL_DEBUGS("Avatar") << "Constructor (0x" << this << ") id:" << mID
  557. << LL_ENDL;
  558. mAttachedObjectsVector.reserve(MAX_AGENT_ATTACHMENTS);
  559. setHoverOffset(LLVector3::zero);
  560. // mVoiceVisualizer is created by the hud effects manager and uses the HUD
  561. // effects pipeline. NOTE: there is no need sending the effect to sim (thus
  562. // the false second parameter).
  563. mVoiceVisualizer =
  564. (LLVoiceVisualizer*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_VOICE_VISUALIZER,
  565. false);
  566. mPelvisp = NULL;
  567. mHeadp = NULL;
  568. // Set up animation variables
  569. setAnimationData("Speed", &mSpeed);
  570. setNumTEs(TEX_NUM_INDICES);
  571. mCanSelect = true;
  572. mSignaledAnimations.clear();
  573. mPlayingAnimations.clear();
  574. // Register our mute list observer, and run it once so to update the
  575. // corresponding cached values.
  576. LLMuteList::addObserver(this);
  577. onChange();
  578. mRuthTimer.reset();
  579. mMinimapColor = getMinimapColor(id);
  580. static const LLColor4 tag_color(gColors.getColor4U("AvatarNameColor"));
  581. mNameTagColor = tag_color;
  582. LL_DEBUGS("Avatar") << "Constructor end" << LL_ENDL;
  583. }
  584. LLVOAvatar::~LLVOAvatar()
  585. {
  586. LL_DEBUGS("Avatar") << "LLVOAvatar Destructor (0x" << this << ") id:"
  587. << mID << LL_ENDL;
  588. LLMuteList::removeObserver(this);
  589. for (attachment_map_t::iterator it = mAttachmentPoints.begin(),
  590. end = mAttachmentPoints.end();
  591. it != end; ++it)
  592. {
  593. delete it->second;
  594. }
  595. mAttachmentPoints.clear();
  596. mDead = true;
  597. mAnimationSources.clear();
  598. LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList);
  599. LL_DEBUGS("Avatar") << "LLVOAvatar Destructor end" << LL_ENDL;
  600. }
  601. void LLVOAvatar::markDead()
  602. {
  603. deleteNameTag();
  604. // The UI gets destroyed when we quit and mVoiceVisualizer is dereferenced
  605. // as a result !
  606. if (!LLApp::isExiting())
  607. {
  608. mVoiceVisualizer->markDead();
  609. }
  610. LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList);
  611. LLViewerObject::markDead();
  612. }
  613. bool LLVOAvatar::isFullyBaked()
  614. {
  615. if (mIsDummy) return true;
  616. if (getNumTEs() == 0) return false;
  617. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  618. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  619. {
  620. if ((i != BAKED_SKIRT || wearing_skirt) &&
  621. i != BAKED_LEFT_ARM && i != BAKED_LEFT_LEG && i != BAKED_AUX1 &&
  622. i != BAKED_AUX2 && i != BAKED_AUX3 &&
  623. !isTextureDefined(mBakedTextureDatas[i].mTextureIndex))
  624. {
  625. return false;
  626. }
  627. }
  628. return true;
  629. }
  630. void LLVOAvatar::deleteLayerSetCaches(bool clearAll)
  631. {
  632. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  633. {
  634. if (mBakedTextureDatas[i].mTexLayerSet)
  635. {
  636. // ! BACKWARDS COMPATIBILITY !
  637. // Can be removed after hair baking is mandatory on the grid
  638. if ((i != BAKED_HAIR || isSelf()) && !clearAll)
  639. {
  640. mBakedTextureDatas[i].mTexLayerSet->deleteCaches();
  641. }
  642. }
  643. if (mBakedTextureDatas[i].mMaskTexName)
  644. {
  645. LLImageGL::deleteTextures(1,
  646. (GLuint*)&(mBakedTextureDatas[i].mMaskTexName));
  647. mBakedTextureDatas[i].mMaskTexName = 0;
  648. }
  649. }
  650. stop_glerror();
  651. }
  652. //static
  653. void LLVOAvatar::dumpBakedStatus()
  654. {
  655. LLVector3d camera_pos_global = gAgent.getCameraPositionGlobal();
  656. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  657. {
  658. LLVOAvatar* inst = (LLVOAvatar*)LLCharacter::sInstances[i];
  659. if (!inst || inst->isDead()) continue;
  660. llinfos << "Avatar ";
  661. LLNameValue* firstname = inst->getNVPair("FirstName");
  662. LLNameValue* lastname = inst->getNVPair("LastName");
  663. if (firstname)
  664. {
  665. llcont << firstname->getString();
  666. }
  667. if (lastname)
  668. {
  669. llcont << " " << lastname->getString();
  670. }
  671. llcont << " " << inst->mID;
  672. if (inst->isDead())
  673. {
  674. llcont << " DEAD (" << inst->getNumRefs() << " refs)";
  675. }
  676. if (inst->isSelf())
  677. {
  678. llcont << " (self)";
  679. }
  680. F64 dist_to_camera = (inst->getPositionGlobal() -
  681. camera_pos_global).length();
  682. llcont << " " << dist_to_camera << "m ";
  683. llcont << " " << inst->mPixelArea << " pixels";
  684. if (inst->isVisible())
  685. {
  686. llcont << " (visible)";
  687. }
  688. else
  689. {
  690. llcont << " (not visible)";
  691. }
  692. if (inst->isFullyBaked())
  693. {
  694. llcont << " Baked";
  695. }
  696. else
  697. {
  698. llcont << " Unbaked (";
  699. for (LLAvatarAppearanceDictionary::BakedTextures::const_iterator
  700. iter = gAvatarAppDictp->getBakedTextures().begin(),
  701. end = gAvatarAppDictp->getBakedTextures().end();
  702. iter != end; ++iter)
  703. {
  704. const LLAvatarAppearanceDictionary::BakedEntry* baked_dict =
  705. iter->second;
  706. const ETextureIndex index = baked_dict->mTextureIndex;
  707. if (inst->isTextureDefined(index)) continue;
  708. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  709. gAvatarAppDictp->getTexture(index);
  710. if (!t_dict) continue;
  711. llcont << " " << t_dict->mName;
  712. }
  713. llcont << ") " << inst->getUnbakedPixelAreaRank();
  714. if (inst->isCulled())
  715. {
  716. llcont << " culled";
  717. }
  718. }
  719. llcont << llendl;
  720. }
  721. }
  722. //static
  723. void LLVOAvatar::restoreGL()
  724. {
  725. if (!isAgentAvatarValid()) return;
  726. gAgentAvatarp->setCompositeUpdatesEnabled(true);
  727. for (U32 i = 0, count = gAgentAvatarp->mBakedTextureDatas.size();
  728. i < count; ++i)
  729. {
  730. gAgentAvatarp->invalidateComposite(gAgentAvatarp->getTexLayerSet(i),
  731. false);
  732. }
  733. gAgentAvatarp->updateMeshTextures();
  734. }
  735. //static
  736. void LLVOAvatar::destroyGL()
  737. {
  738. deleteCachedImages();
  739. resetImpostors();
  740. }
  741. //static
  742. void LLVOAvatar::resetImpostors()
  743. {
  744. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  745. {
  746. LLVOAvatar* avatar = (LLVOAvatar*)LLCharacter::sInstances[i];
  747. if (avatar && !avatar->isDead())
  748. {
  749. avatar->mImpostor.release();
  750. avatar->mNeedsImpostorUpdate = true;
  751. }
  752. }
  753. }
  754. //static
  755. void LLVOAvatar::deleteCachedImages(bool clearAll)
  756. {
  757. if (LLViewerTexLayerSet::sHasCaches)
  758. {
  759. LL_DEBUGS("Avatar") << "Deleting layer set caches" << LL_ENDL;
  760. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  761. {
  762. LLVOAvatar* inst = (LLVOAvatar*)LLCharacter::sInstances[i];
  763. if (inst)
  764. {
  765. inst->deleteLayerSetCaches(clearAll);
  766. }
  767. }
  768. LLViewerTexLayerSet::sHasCaches = false;
  769. }
  770. gTexLayerStaticImageList.deleteCachedImages();
  771. }
  772. //static
  773. void LLVOAvatar::initClass()
  774. {
  775. llinfos << "Initializing settings." << llendl;
  776. sAvatarPhysics = gSavedSettings.getBool("AvatarPhysics");
  777. sLipSyncEnabled = gSavedSettings.getBool("LipSyncEnabled");
  778. updateSettings();
  779. llinfos << "Use avatar physics: " << (sAvatarPhysics ? "yes" : "no")
  780. << " - Use impostors: " << (sUseImpostors ? "yes" : "no")
  781. << " - Max non-impostors: " << sMaxNonImpostors << llendl;
  782. LLVOAvatarPuppet::sRegionChangedSlot =
  783. gAgent.addRegionChangedCB(boost::bind(&LLVOAvatarPuppet::onRegionChanged));
  784. }
  785. void LLVOAvatar::cleanupClass()
  786. {
  787. LLVOAvatarPuppet::sRegionChangedSlot.disconnect();
  788. }
  789. //virtual
  790. void LLVOAvatar::initInstance()
  791. {
  792. // Register motions
  793. if (LLCharacter::sInstances.size() == 1)
  794. {
  795. registerMotion(ANIM_AGENT_BUSY, LLNullMotion::create);
  796. registerMotion(ANIM_AGENT_CROUCH, LLKeyframeStandMotion::create);
  797. registerMotion(ANIM_AGENT_CROUCHWALK, LLKeyframeWalkMotion::create);
  798. registerMotion(ANIM_AGENT_EXPRESS_AFRAID, LLEmote::create);
  799. registerMotion(ANIM_AGENT_EXPRESS_ANGER, LLEmote::create);
  800. registerMotion(ANIM_AGENT_EXPRESS_BORED, LLEmote::create);
  801. registerMotion(ANIM_AGENT_EXPRESS_CRY, LLEmote::create);
  802. registerMotion(ANIM_AGENT_EXPRESS_DISDAIN, LLEmote::create);
  803. registerMotion(ANIM_AGENT_EXPRESS_EMBARRASSED, LLEmote::create);
  804. registerMotion(ANIM_AGENT_EXPRESS_FROWN, LLEmote::create);
  805. registerMotion(ANIM_AGENT_EXPRESS_KISS, LLEmote::create);
  806. registerMotion(ANIM_AGENT_EXPRESS_LAUGH, LLEmote::create);
  807. registerMotion(ANIM_AGENT_EXPRESS_OPEN_MOUTH, LLEmote::create);
  808. registerMotion(ANIM_AGENT_EXPRESS_REPULSED, LLEmote::create);
  809. registerMotion(ANIM_AGENT_EXPRESS_SAD, LLEmote::create);
  810. registerMotion(ANIM_AGENT_EXPRESS_SHRUG, LLEmote::create);
  811. registerMotion(ANIM_AGENT_EXPRESS_SMILE, LLEmote::create);
  812. registerMotion(ANIM_AGENT_EXPRESS_SURPRISE, LLEmote::create);
  813. registerMotion(ANIM_AGENT_EXPRESS_TONGUE_OUT, LLEmote::create);
  814. registerMotion(ANIM_AGENT_EXPRESS_TOOTHSMILE, LLEmote::create);
  815. registerMotion(ANIM_AGENT_EXPRESS_WINK, LLEmote::create);
  816. registerMotion(ANIM_AGENT_EXPRESS_WORRY, LLEmote::create);
  817. registerMotion(ANIM_AGENT_FEMALE_RUN_NEW,
  818. LLKeyframeWalkMotion::create);
  819. registerMotion(ANIM_AGENT_FEMALE_WALK, LLKeyframeWalkMotion::create);
  820. registerMotion(ANIM_AGENT_FEMALE_WALK_NEW,
  821. LLKeyframeWalkMotion::create);
  822. registerMotion(ANIM_AGENT_RUN, LLKeyframeWalkMotion::create);
  823. registerMotion(ANIM_AGENT_RUN_NEW, LLKeyframeWalkMotion::create);
  824. registerMotion(ANIM_AGENT_STAND, LLKeyframeStandMotion::create);
  825. registerMotion(ANIM_AGENT_STAND_1, LLKeyframeStandMotion::create);
  826. registerMotion(ANIM_AGENT_STAND_2, LLKeyframeStandMotion::create);
  827. registerMotion(ANIM_AGENT_STAND_3, LLKeyframeStandMotion::create);
  828. registerMotion(ANIM_AGENT_STAND_4, LLKeyframeStandMotion::create);
  829. registerMotion(ANIM_AGENT_STANDUP, LLKeyframeFallMotion::create);
  830. registerMotion(ANIM_AGENT_TURNLEFT, LLKeyframeWalkMotion::create);
  831. registerMotion(ANIM_AGENT_TURNRIGHT, LLKeyframeWalkMotion::create);
  832. registerMotion(ANIM_AGENT_WALK, LLKeyframeWalkMotion::create);
  833. registerMotion(ANIM_AGENT_WALK_NEW, LLKeyframeWalkMotion::create);
  834. // Motions without a start/stop bit
  835. registerMotion(ANIM_AGENT_BODY_NOISE, LLBodyNoiseMotion::create);
  836. registerMotion(ANIM_AGENT_BREATHE_ROT, LLBreatheMotionRot::create);
  837. registerMotion(ANIM_AGENT_PHYSICS_MOTION,
  838. LLPhysicsMotionController::create);
  839. registerMotion(ANIM_AGENT_EDITING, LLEditingMotion::create);
  840. registerMotion(ANIM_AGENT_EYE, LLEyeMotion::create);
  841. registerMotion(ANIM_AGENT_FLY_ADJUST, LLFlyAdjustMotion::create);
  842. registerMotion(ANIM_AGENT_HAND_MOTION, LLHandMotion::create);
  843. registerMotion(ANIM_AGENT_HEAD_ROT, LLHeadRotMotion::create);
  844. registerMotion(ANIM_AGENT_PELVIS_FIX, LLPelvisFixMotion::create);
  845. registerMotion(ANIM_AGENT_SIT_FEMALE, LLKeyframeMotion::create);
  846. registerMotion(ANIM_AGENT_TARGET, LLTargetingMotion::create);
  847. registerMotion(ANIM_AGENT_WALK_ADJUST, LLWalkAdjustMotion::create);
  848. #if LL_PUPPETRY
  849. registerMotion(ANIM_AGENT_PUPPET_MOTION,
  850. LLPuppetMotion::create);
  851. #endif
  852. }
  853. LLAvatarAppearance::initInstance();
  854. // Preload specific motions here
  855. createMotion(ANIM_AGENT_CUSTOMIZE);
  856. createMotion(ANIM_AGENT_CUSTOMIZE_DONE);
  857. #if LL_PUPPETRY
  858. createMotion(ANIM_AGENT_PUPPET_MOTION);
  859. #endif
  860. mVoiceVisualizer->setVoiceEnabled(gVoiceClient.getVoiceEnabled(mID));
  861. }
  862. #if LL_PUPPETRY
  863. LLPuppetMotion* LLVOAvatar::getPuppetMotion()
  864. {
  865. return (LLPuppetMotion*)findMotion(ANIM_AGENT_PUPPET_MOTION);
  866. }
  867. #endif
  868. //virtual
  869. LLAvatarJoint* LLVOAvatar::createAvatarJoint()
  870. {
  871. return new LLViewerJoint();
  872. }
  873. //virtual
  874. LLAvatarJointMesh* LLVOAvatar::createAvatarJointMesh()
  875. {
  876. return new LLViewerJointMesh();
  877. }
  878. //virtual
  879. LLTexLayerSet* LLVOAvatar::createTexLayerSet()
  880. {
  881. return new LLViewerTexLayerSet(this);
  882. }
  883. const LLVector3 LLVOAvatar::getRenderPosition() const
  884. {
  885. if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
  886. {
  887. return getPositionAgent();
  888. }
  889. if (!isRoot())
  890. {
  891. LLDrawable* parentp = mDrawable->getParent();
  892. if (parentp)
  893. {
  894. return getPosition() * parentp->getRenderMatrix();
  895. }
  896. else
  897. {
  898. return mDrawable->getPositionAgent();
  899. }
  900. }
  901. LLVector3 pos = mDrawable->getPositionAgent();
  902. F32 fixup;
  903. if (hasPelvisFixup(fixup))
  904. {
  905. // Apply a pelvis fixup (as defined by the avatar's skin)
  906. pos[VZ] += fixup;
  907. }
  908. return pos;
  909. }
  910. void LLVOAvatar::updateDrawable(bool force_damped)
  911. {
  912. clearChanged(SHIFTED);
  913. }
  914. void LLVOAvatar::onShift(const LLVector4a& shift_vector)
  915. {
  916. const LLVector3& shift = reinterpret_cast<const LLVector3&>(shift_vector);
  917. mLastAnimExtents[0] += shift;
  918. mLastAnimExtents[1] += shift;
  919. mNeedsImpostorUpdate = true;
  920. mNeedsAnimUpdate = true;
  921. }
  922. void LLVOAvatar::updateSpatialExtents(LLVector4a& new_min, LLVector4a& new_max)
  923. {
  924. if (mDrawable.isNull() || isDead()) return;
  925. if (mNeedsExtentUpdate)
  926. {
  927. calculateSpatialExtents(new_min, new_max);
  928. mLastAnimExtents[0].set(new_min.getF32ptr());
  929. mLastAnimExtents[1].set(new_max.getF32ptr());
  930. if (mPelvisp)
  931. {
  932. mLastAnimBasePos = mPelvisp->getWorldPosition();
  933. }
  934. mNeedsExtentUpdate = false;
  935. }
  936. else if (mPelvisp)
  937. {
  938. LLVector3 new_base_pos = mPelvisp->getWorldPosition();
  939. LLVector3 shift = new_base_pos - mLastAnimBasePos;
  940. mLastAnimExtents[0] += shift;
  941. mLastAnimExtents[1] += shift;
  942. mLastAnimBasePos = new_base_pos;
  943. }
  944. if (isImpostor() && !needsImpostorUpdate())
  945. {
  946. LLVector3 delta =
  947. getRenderPosition() -
  948. ((LLVector3(mDrawable->getPositionGroup().getF32ptr()) -
  949. mImpostorOffset));
  950. new_min.load3((mLastAnimExtents[0] + delta).mV);
  951. new_max.load3((mLastAnimExtents[1] + delta).mV);
  952. }
  953. else
  954. {
  955. new_min.load3(mLastAnimExtents[0].mV);
  956. new_max.load3(mLastAnimExtents[1].mV);
  957. LLVector4a pos_group;
  958. pos_group.setAdd(new_min, new_max);
  959. pos_group.mul(0.5f);
  960. mImpostorOffset = LLVector3(pos_group.getF32ptr()) -
  961. getRenderPosition();
  962. mDrawable->setPositionGroup(pos_group);
  963. }
  964. }
  965. void LLVOAvatar::calculateSpatialExtents(LLVector4a& new_min,
  966. LLVector4a& new_max)
  967. {
  968. static LLVector4a temp1, temp2, temp3;
  969. if (isDead()) return;
  970. // Load position
  971. #if 0 // This causes massive issues for in-sim TPs, since the pelvis world
  972. // position is not updated in real time, unlike getRenderPosition(). HB
  973. LLVector3 pos = mPelvisp->getWorldPosition();
  974. if (pos.isExactlyZero())
  975. {
  976. pos = getRenderPosition();
  977. }
  978. new_min.load3(pos.mV);
  979. #else
  980. new_min.load3(getRenderPosition().mV);
  981. #endif
  982. new_max = new_min;
  983. // Pad bounding box for starting joint, plus polymesh if applicable.
  984. // Subsequent calcs should be accurate enough to not need padding.
  985. static const LLVector4a padding(0.25f);
  986. new_min.sub(padding);
  987. new_max.add(padding);
  988. static LLCachedControl<U32> avbbox_detail(gSavedSettings,
  989. "AvatarBoundingBoxComplexity");
  990. U32 box_detail = avbbox_detail;
  991. if (isPuppetAvatar())
  992. {
  993. // Animated objects do not show an actual avatar but do need to include
  994. // their rigged meshes in their bounding box.
  995. box_detail = 3;
  996. }
  997. // Stretch bounding box by joint positions. No point doing this for puppet
  998. // avatars, where the polymeshes are not maintained or displayed.
  999. else if (box_detail >= 1)
  1000. {
  1001. for (polymesh_map_t::iterator i = mPolyMeshes.begin(),
  1002. end = mPolyMeshes.end();
  1003. i != end; ++i)
  1004. {
  1005. LLPolyMesh* mesh = i->second;
  1006. if (!mesh) continue; // Paranoia
  1007. for (S32 joint_num = 0, count = mesh->mJointRenderData.size();
  1008. joint_num < count; ++joint_num)
  1009. {
  1010. // Load translation:
  1011. temp1.load3(mesh->mJointRenderData[joint_num]->mWorldMatrix->getTranslation().mV);
  1012. update_min_max(new_min, new_max, temp1);
  1013. }
  1014. }
  1015. }
  1016. // Stretch bounding box by static attachments
  1017. if (box_detail >= 2)
  1018. {
  1019. // Max attachment span:
  1020. temp1.splat(LLManipScale::maxPrimScale() * 5.f);
  1021. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  1022. {
  1023. LLViewerObject* object = mAttachedObjectsVector[i].first;
  1024. if (!object || object->isHUDAttachment())
  1025. {
  1026. continue;
  1027. }
  1028. LLVOVolume* vol = object->asVolume();
  1029. if (vol && vol->isAnimatedObject())
  1030. {
  1031. // Animated objects already have a bounding box in their puppet
  1032. // avatar, use that. They could lag by a frame if there is no
  1033. // guarantee on order of processing for avatars.
  1034. LLVOAvatarPuppet* puppet = vol->getPuppetAvatar();
  1035. if (puppet)
  1036. {
  1037. temp2.load3(puppet->mLastAnimExtents[0].mV);
  1038. temp3.load3(puppet->mLastAnimExtents[1].mV);
  1039. update_min_max(new_min, new_max, temp2);
  1040. update_min_max(new_min, new_max, temp3);
  1041. continue;
  1042. }
  1043. }
  1044. LLDrawable* drawable = object->mDrawable;
  1045. if (!drawable || drawable->isState(LLDrawable::RIGGED |
  1046. // Do not extend box to children
  1047. LLDrawable::RIGGED_CHILD))
  1048. {
  1049. continue;
  1050. }
  1051. LLSpatialBridge* bridge = drawable->getSpatialBridge();
  1052. if (bridge)
  1053. {
  1054. // Calculate distance:
  1055. const LLVector4a* ext = bridge->getSpatialExtents();
  1056. temp2.setSub(ext[1], ext[0]);
  1057. // Only add the prim to spatial extents calculations if it is
  1058. // not a megaprim (max attachment span calculated above is
  1059. // currently 5 times our max prim size).
  1060. S32 lt = temp2.lessThan(temp1).getGatheredBits() & 0x7;
  1061. if (lt == 0x7)
  1062. {
  1063. update_min_max(new_min, new_max, ext[0]);
  1064. update_min_max(new_min, new_max, ext[1]);
  1065. }
  1066. }
  1067. }
  1068. }
  1069. // Stretch bounding box by rigged mesh joint boxes
  1070. if (box_detail >= 3 && !isImpostor())
  1071. {
  1072. if (box_detail >= 4 || mJointRiggingInfoTab.needsUpdate())
  1073. {
  1074. updateRiggingInfo();
  1075. mJointRiggingInfoTab.setNeedsUpdate(false);
  1076. }
  1077. static LLMatrix4a mat;
  1078. static LLVector4a new_extents[2];
  1079. for (U32 i = 0, count = mJointRiggingInfoTab.size(); i < count; ++i)
  1080. {
  1081. LLJointRiggingInfo* rig_info = &mJointRiggingInfoTab[i];
  1082. if (!rig_info->isRiggedTo()) continue;
  1083. // Note: joint key 0 = "unnamed", 1 = "mScreen" (so we skip them)
  1084. LLJoint* jointp = getJoint(i + 2);
  1085. if (!jointp) continue;
  1086. mat.loadu(jointp->getWorldMatrix());
  1087. mat.matMulBoundBox(rig_info->getRiggedExtents(), new_extents);
  1088. update_min_max(new_min, new_max, new_extents[0]);
  1089. update_min_max(new_min, new_max, new_extents[1]);
  1090. }
  1091. }
  1092. // Update pixel area. First, calculate center.
  1093. temp1.setAdd(new_min, new_max);
  1094. temp1.mul(0.5f);
  1095. // Calculate size.
  1096. temp2.setSub(new_max, new_min);
  1097. temp2.mul(0.5f);
  1098. mPixelArea = LLPipeline::calcPixelArea(temp1, temp2, gViewerCamera);
  1099. }
  1100. void render_sphere_and_line(const LLVector3& begin_pos,
  1101. const LLVector3& end_pos, F32 sphere_scale,
  1102. const LLVector3& occ_color,
  1103. const LLVector3& visible_color)
  1104. {
  1105. // Unoccluded bone portions
  1106. LLGLDepthTest normal_depth(GL_TRUE);
  1107. // Draw line segment for unoccluded joint
  1108. gGL.diffuseColor3f(visible_color[0], visible_color[1], visible_color[2]);
  1109. gGL.begin(LLRender::LINES);
  1110. gGL.vertex3fv(begin_pos.mV);
  1111. gGL.vertex3fv(end_pos.mV);
  1112. gGL.end();
  1113. // Draw sphere representing joint pos
  1114. gGL.pushMatrix();
  1115. gGL.scalef(sphere_scale, sphere_scale, sphere_scale);
  1116. gSphere.renderGGL();
  1117. gGL.popMatrix();
  1118. LLGLDepthTest depth_under(GL_TRUE, GL_FALSE, GL_GREATER);
  1119. // Occluded bone portions
  1120. gGL.diffuseColor3f(occ_color[0], occ_color[1], occ_color[2]);
  1121. gGL.begin(LLRender::LINES);
  1122. gGL.vertex3fv(begin_pos.mV);
  1123. gGL.vertex3fv(end_pos.mV);
  1124. gGL.end();
  1125. // Draw sphere representing joint pos
  1126. gGL.pushMatrix();
  1127. gGL.scalef(sphere_scale, sphere_scale, sphere_scale);
  1128. gSphere.renderGGL();
  1129. gGL.popMatrix();
  1130. }
  1131. void LLVOAvatar::renderCollisionVolumes()
  1132. {
  1133. constexpr F32 SPHERE_SCALE = 1.f;
  1134. constexpr F32 CENTER_DOT_SCALE = 0.05f;
  1135. static const LLVector3 CV_COLOR_OCCLUDED(0.f, 0.f, 1.f);
  1136. static const LLVector3 CV_COLOR_OCC_PUPPET(0.f, 1.f, 1.f);
  1137. static const LLVector3 CV_COLOR_VISIBLE(0.5f, 0.5f, 1.f);
  1138. static const LLVector3 CV_COLOR_VIS_PUPPET(0.5f, 1.f, 1.f);
  1139. static const LLVector3 DOT_COLOR_OCCLUDED(1.f, 1.f, 1.f);
  1140. static const LLVector3 DOT_COLOR_VISIBLE(1.f, 1.f, 1.f);
  1141. for (S32 i = 0, count = mCollisionVolumes.size(); i < count; ++i)
  1142. {
  1143. LLAvatarJointCollisionVolume& colvol = *mCollisionVolumes[i];
  1144. colvol.updateWorldMatrix();
  1145. gGL.pushMatrix();
  1146. gGL.multMatrix(colvol.getXform()->getWorldMatrix().getF32ptr());
  1147. LLVector3 end_pos(colvol.getEnd());
  1148. if (isPuppetAvatar())
  1149. {
  1150. render_sphere_and_line(LLVector3::zero, end_pos, SPHERE_SCALE,
  1151. CV_COLOR_OCC_PUPPET, CV_COLOR_VIS_PUPPET);
  1152. }
  1153. else
  1154. {
  1155. render_sphere_and_line(LLVector3::zero, end_pos, SPHERE_SCALE,
  1156. CV_COLOR_OCCLUDED, CV_COLOR_VISIBLE);
  1157. }
  1158. render_sphere_and_line(LLVector3::zero, end_pos, CENTER_DOT_SCALE,
  1159. DOT_COLOR_OCCLUDED, DOT_COLOR_VISIBLE);
  1160. gGL.popMatrix();
  1161. }
  1162. if (mNameText.notNull() && !mNameText->isDead())
  1163. {
  1164. LLVector4a unused;
  1165. mNameText->lineSegmentIntersect(unused, unused, unused, true);
  1166. }
  1167. }
  1168. void LLVOAvatar::renderBones(const std::string& selected_joint)
  1169. {
  1170. if (isImpostor()) return;
  1171. static const LLVector3 COLOR_VISIBLE(0.5f, 0.5f, 0.5f);
  1172. // For selected joint
  1173. static const LLVector3 SELECTED_COLOR_OCCLUDED(1.f, 1.f, 0.f);
  1174. // For bones with position overrides defined
  1175. static const LLVector3 OVERRIDE_COLOR_OCCLUDED(1.f, 0.f, 0.f);
  1176. // For bones which are rigged to by at least one attachment
  1177. static const LLVector3 RIGGED_COLOR_OCCLUDED(0.f, 1.f, 1.f);
  1178. #if LL_PUPPETRY
  1179. // For bones with puppetry data
  1180. static const LLVector3 PUPPETRY_COLOR_OCCLUDED(0.f, 0.f, 1.f);
  1181. #endif
  1182. // For bones not otherwise colored
  1183. static const LLVector3 OTHER_COLOR_OCCLUDED(0.f, 1.f, 0.f);
  1184. constexpr F32 SPHERE_SCALEF = 0.001f;
  1185. #if LL_PUPPETRY
  1186. LLPuppetModule* modulep = LLPuppetModule::getInstance();
  1187. #endif
  1188. const LLVector3* occ_color;
  1189. LLVector3 pos;
  1190. LLUUID mesh_id;
  1191. LLGLEnable blend(GL_BLEND);
  1192. for (avatar_joint_list_t::iterator iter = mSkeleton.begin(),
  1193. end = mSkeleton.end();
  1194. iter != end; ++iter)
  1195. {
  1196. LLJoint* jointp = *iter;
  1197. if (!jointp || !jointp->getXform())
  1198. {
  1199. continue;
  1200. }
  1201. jointp->updateWorldMatrix();
  1202. F32 sphere_scale = SPHERE_SCALEF;
  1203. if (jointp->getName() == selected_joint)
  1204. {
  1205. sphere_scale *= 16;
  1206. occ_color = &SELECTED_COLOR_OCCLUDED;
  1207. }
  1208. #if LL_PUPPETRY
  1209. else if (modulep->isActiveJoint(jointp->getName()))
  1210. {
  1211. occ_color = &PUPPETRY_COLOR_OCCLUDED;
  1212. }
  1213. #endif
  1214. else if (jointp->hasAttachmentPosOverride(pos, mesh_id))
  1215. {
  1216. occ_color = &OVERRIDE_COLOR_OCCLUDED;
  1217. }
  1218. else if (jointIsRiggedTo(jointp->getKey()))
  1219. {
  1220. occ_color = &RIGGED_COLOR_OCCLUDED;
  1221. }
  1222. else
  1223. {
  1224. occ_color = &OTHER_COLOR_OCCLUDED;
  1225. }
  1226. gGL.pushMatrix();
  1227. gGL.multMatrix(jointp->getXform()->getWorldMatrix().getF32ptr());
  1228. render_sphere_and_line(LLVector3::zero, jointp->getEnd(), sphere_scale,
  1229. *occ_color, COLOR_VISIBLE);
  1230. gGL.popMatrix();
  1231. }
  1232. }
  1233. void LLVOAvatar::renderJoints()
  1234. {
  1235. if (isImpostor()) return;
  1236. static const LLVector3 v[] =
  1237. {
  1238. LLVector3(0.1f, 0.f, 0.f),
  1239. LLVector3(-0.1f, 0.f, 0.f),
  1240. LLVector3(0.f, 0.1f, 0.f),
  1241. LLVector3(0.f, -0.1f, 0.f),
  1242. LLVector3(0.f, 0.f, -0.1f),
  1243. LLVector3(0.f, 0.f, 0.1f),
  1244. };
  1245. for (joint_map_t::iterator iter = mJointMap.begin(), end = mJointMap.end();
  1246. iter != end; ++iter)
  1247. {
  1248. LLJoint* jointp = iter->second;
  1249. if (!jointp || !jointp->getXform())
  1250. {
  1251. continue;
  1252. }
  1253. jointp->updateWorldMatrix();
  1254. gGL.pushMatrix();
  1255. gGL.multMatrix(jointp->getXform()->getWorldMatrix().getF32ptr());
  1256. gGL.diffuseColor3f(1.f, 0.f, 1.f);
  1257. gGL.begin(LLRender::LINES);
  1258. // sides
  1259. gGL.vertex3fv(v[0].mV);
  1260. gGL.vertex3fv(v[2].mV);
  1261. gGL.vertex3fv(v[0].mV);
  1262. gGL.vertex3fv(v[3].mV);
  1263. gGL.vertex3fv(v[1].mV);
  1264. gGL.vertex3fv(v[2].mV);
  1265. gGL.vertex3fv(v[1].mV);
  1266. gGL.vertex3fv(v[3].mV);
  1267. // top
  1268. gGL.vertex3fv(v[0].mV);
  1269. gGL.vertex3fv(v[4].mV);
  1270. gGL.vertex3fv(v[1].mV);
  1271. gGL.vertex3fv(v[4].mV);
  1272. gGL.vertex3fv(v[2].mV);
  1273. gGL.vertex3fv(v[4].mV);
  1274. gGL.vertex3fv(v[3].mV);
  1275. gGL.vertex3fv(v[4].mV);
  1276. // bottom
  1277. gGL.vertex3fv(v[0].mV);
  1278. gGL.vertex3fv(v[5].mV);
  1279. gGL.vertex3fv(v[1].mV);
  1280. gGL.vertex3fv(v[5].mV);
  1281. gGL.vertex3fv(v[2].mV);
  1282. gGL.vertex3fv(v[5].mV);
  1283. gGL.vertex3fv(v[3].mV);
  1284. gGL.vertex3fv(v[5].mV);
  1285. gGL.end();
  1286. gGL.popMatrix();
  1287. }
  1288. }
  1289. bool LLVOAvatar::lineSegmentIntersect(const LLVector4a& start,
  1290. const LLVector4a& end, S32 face,
  1291. bool pick_transparent, bool pick_rigged,
  1292. S32* face_hit, LLVector4a* intersection,
  1293. LLVector2* tex_coord, LLVector4a* normal,
  1294. LLVector4a* tangent)
  1295. {
  1296. if (isPuppetAvatar() || (isSelf() && !gAgent.needsRenderAvatar()) ||
  1297. !LLPipeline::sPickAvatar)
  1298. {
  1299. return false;
  1300. }
  1301. if (lineSegmentBoundingBox(start, end))
  1302. {
  1303. for (S32 i = 0, count = mCollisionVolumes.size(); i < count; ++i)
  1304. {
  1305. mCollisionVolumes[i]->updateWorldMatrix();
  1306. LLMatrix4a mat(mCollisionVolumes[i]->getXform()->getWorldMatrix());
  1307. LLMatrix4a inverse = mat;
  1308. inverse.invert();
  1309. LLMatrix4a norm_mat = inverse;
  1310. norm_mat.transpose();
  1311. LLVector4a p1, p2;
  1312. // Might need to use perspectiveTransform here.
  1313. inverse.affineTransform(start, p1);
  1314. inverse.affineTransform(end, p2);
  1315. LLVector3 position;
  1316. LLVector3 norm;
  1317. if (linesegment_sphere(LLVector3(p1.getF32ptr()),
  1318. LLVector3(p2.getF32ptr()),
  1319. LLVector3::zero, 1.f, position, norm))
  1320. {
  1321. if (intersection)
  1322. {
  1323. intersection->load3(position.mV);
  1324. mat.affineTransform(*intersection, *intersection);
  1325. }
  1326. if (normal)
  1327. {
  1328. normal->load3(norm.mV);
  1329. normal->normalize3fast();
  1330. norm_mat.perspectiveTransform(*normal, *normal);
  1331. }
  1332. return true;
  1333. }
  1334. }
  1335. if (isSelf())
  1336. {
  1337. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count;
  1338. ++i)
  1339. {
  1340. LLViewerObject* object = mAttachedObjectsVector[i].first;
  1341. if (object && !object->isDead() &&
  1342. mAttachedObjectsVector[i].second->getValid())
  1343. {
  1344. LLDrawable* drawable = object->mDrawable;
  1345. if (drawable && drawable->isState(LLDrawable::RIGGED))
  1346. {
  1347. // Regenerate octree for rigged attachment
  1348. gPipeline.markRebuild(mDrawable,
  1349. LLDrawable::REBUILD_RIGGED);
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. LLVector4a position;
  1356. if (mNameText.notNull() && !mNameText->isDead() &&
  1357. mNameText->lineSegmentIntersect(start, end, position))
  1358. {
  1359. if (intersection)
  1360. {
  1361. *intersection = position;
  1362. }
  1363. return true;
  1364. }
  1365. return false;
  1366. }
  1367. //virtual
  1368. LLViewerObject* LLVOAvatar::lineSegmentIntersectRiggedAttachments(const LLVector4a& start,
  1369. const LLVector4a& end,
  1370. S32 face,
  1371. bool pick_transparent,
  1372. bool pick_rigged,
  1373. S32* face_hit,
  1374. LLVector4a* intersection,
  1375. LLVector2* tex_coord,
  1376. LLVector4a* normal,
  1377. LLVector4a* tangent)
  1378. {
  1379. if (isSelf() && !gAgent.needsRenderAvatar())
  1380. {
  1381. return NULL;
  1382. }
  1383. LLViewerObject* hit = NULL;
  1384. if (lineSegmentBoundingBox(start, end))
  1385. {
  1386. LLVector4a local_end = end;
  1387. LLVector4a local_intersection;
  1388. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  1389. {
  1390. LLViewerObject* object = mAttachedObjectsVector[i].first;
  1391. if (object &&
  1392. object->lineSegmentIntersect(start, local_end, face,
  1393. pick_transparent, pick_rigged,
  1394. face_hit, &local_intersection,
  1395. tex_coord, normal, tangent))
  1396. {
  1397. local_end = local_intersection;
  1398. if (intersection)
  1399. {
  1400. *intersection = local_intersection;
  1401. }
  1402. hit = object;
  1403. }
  1404. }
  1405. }
  1406. return hit;
  1407. }
  1408. void LLVOAvatar::startDefaultMotions()
  1409. {
  1410. if (mEnableDefaultMotions)
  1411. {
  1412. // Start default motions
  1413. startMotion(ANIM_AGENT_HEAD_ROT);
  1414. startMotion(ANIM_AGENT_EYE);
  1415. startMotion(ANIM_AGENT_BODY_NOISE);
  1416. startMotion(ANIM_AGENT_BREATHE_ROT);
  1417. startMotion(ANIM_AGENT_PHYSICS_MOTION);
  1418. startMotion(ANIM_AGENT_HAND_MOTION);
  1419. startMotion(ANIM_AGENT_PELVIS_FIX);
  1420. }
  1421. // Restart any currently active motions
  1422. processAnimationStateChanges();
  1423. }
  1424. // Deferred initialization and rebuild of the avatar.
  1425. //virtual
  1426. void LLVOAvatar::buildCharacter()
  1427. {
  1428. LLAvatarAppearance::buildCharacter();
  1429. // Not done building yet; more to do.
  1430. mIsBuilt = false;
  1431. // Set head offset from pelvis
  1432. updateHeadOffset();
  1433. // Initialize lip sync morph pointers
  1434. mOohMorph = getVisualParam("Lipsync_Ooh");
  1435. mAahMorph = getVisualParam("Lipsync_Aah");
  1436. // If we do not have the Ooh morph, use the Kiss morph
  1437. if (!mOohMorph)
  1438. {
  1439. llwarns << "Missing 'Ooh' morph for lipsync, using fallback."
  1440. << llendl;
  1441. mOohMorph = getVisualParam("Express_Kiss");
  1442. }
  1443. // If we do not have the Aah morph, use the Open Mouth morph
  1444. if (!mAahMorph)
  1445. {
  1446. llwarns << "Missing 'Aah' morph for lipsync, using fallback."
  1447. << llendl;
  1448. mAahMorph = getVisualParam("Express_Open_Mouth");
  1449. }
  1450. if (mEnableDefaultMotions)
  1451. {
  1452. startDefaultMotions();
  1453. }
  1454. // Restart any currently active motions
  1455. processAnimationStateChanges();
  1456. mIsBuilt = true;
  1457. mMeshValid = true;
  1458. }
  1459. void LLVOAvatar::resetVisualParams()
  1460. {
  1461. // Skeletal params
  1462. for (LLAvatarXmlInfo::skeletal_distortion_info_list_t::iterator
  1463. iter = sAvatarXmlInfo->mSkeletalDistortionInfoList.begin(),
  1464. end = sAvatarXmlInfo->mSkeletalDistortionInfoList.end();
  1465. iter != end; ++iter)
  1466. {
  1467. LLPolySkeletalDistortionInfo* info =
  1468. (*iter)->asPolySkeletalDistortionInfo();
  1469. if (!info) continue;
  1470. S32 id = info->getID();
  1471. LLPolySkeletalDistortion* param =
  1472. getVisualParam(id)->asPolySkeletalDistortion();
  1473. if (param)
  1474. {
  1475. *param = LLPolySkeletalDistortion(this);
  1476. if (!param->setInfo(info))
  1477. {
  1478. llwarns << "Failed to set skeletal distortion for: " << id
  1479. << llendl;
  1480. }
  1481. }
  1482. else
  1483. {
  1484. llwarns << "Failed to find skeletal distortion param for: " << id
  1485. << llendl;
  1486. }
  1487. }
  1488. // Driver parameters
  1489. for (LLAvatarXmlInfo::driver_info_list_t::iterator
  1490. iter = sAvatarXmlInfo->mDriverInfoList.begin(),
  1491. end = sAvatarXmlInfo->mDriverInfoList.end();
  1492. iter != end; ++iter)
  1493. {
  1494. LLDriverParamInfo* info = *iter;
  1495. if (!info) continue; // Paranoia
  1496. LLVisualParam* vparam = getVisualParam(info->getID());
  1497. if (!vparam) continue;
  1498. LLDriverParam* param = vparam->asDriverParam();
  1499. if (!param) continue;
  1500. LLDriverParam::entry_list_t driven_list = param->getDrivenList();
  1501. *param = LLDriverParam(this);
  1502. if (param && param->setInfo(info))
  1503. {
  1504. param->setDrivenList(driven_list);
  1505. }
  1506. }
  1507. }
  1508. void LLVOAvatar::resetSkeleton()
  1509. {
  1510. if (!mLastProcessedAppearance && !isPuppetAvatar())
  1511. {
  1512. llwarns << "No appearance message received yet: cannot reset avatar."
  1513. << llendl;
  1514. return;
  1515. }
  1516. // Clear all attachment position and scale overrides
  1517. clearAttachmentOverrides();
  1518. // Reset the joints lookup cache
  1519. mJointMap.clear();
  1520. // Note that we call buildSkeleton twice in this function. The first time
  1521. // is just to get the right scale for the collision volumes, because this
  1522. // will be used in setting the mJointScales for the
  1523. // LLPolySkeletalDistortions of which the collision volumes are children
  1524. if (!buildSkeleton(sAvatarSkeletonInfo))
  1525. {
  1526. llwarns << "Could not rebuild " << getFullname(true) << "'s skeleton !"
  1527. << llendl;
  1528. }
  1529. // Reset some params to default state, without propagating changes
  1530. // downstream
  1531. resetVisualParams();
  1532. // Now we have to reset the skeleton again, because its state got clobbered
  1533. // by the resetVisualParams() calls above
  1534. if (!buildSkeleton(sAvatarSkeletonInfo))
  1535. {
  1536. llwarns << "Could not rebuild " << getFullname(true) << "'s skeleton !"
  1537. << llendl;
  1538. }
  1539. // Reset attachment points (buildSkeleton only does bones and CVs)
  1540. // but we still need to reinit HUDs (for self) since huds can be animated.
  1541. initAttachmentPoints(!isSelf()); // true to ignore HUD joints
  1542. // Fix up collision volumes
  1543. for (LLVisualParam* param = getFirstVisualParam(); param;
  1544. param = getNextVisualParam())
  1545. {
  1546. LLPolyMorphTarget* pmorph = param->asPolyMorphTarget();
  1547. if (pmorph)
  1548. {
  1549. // This is a kludgy way to correct for the fact that the collision
  1550. // volumes have been reset out from under the poly morph sliders.
  1551. F32 delta = pmorph->getLastWeight() - pmorph->getDefaultWeight();
  1552. pmorph->applyVolumeChanges(delta);
  1553. }
  1554. }
  1555. if (mLastProcessedAppearance)
  1556. {
  1557. // Reset/slam tweakable params to preserved state
  1558. applyParsedAppearanceMessage(*mLastProcessedAppearance, true);
  1559. }
  1560. updateVisualParams();
  1561. // Restore attachment pos overrides
  1562. rebuildAttachmentOverrides();
  1563. }
  1564. void LLVOAvatar::releaseMeshData()
  1565. {
  1566. if ((S32)sInstances.size() < AVATAR_RELEASE_THRESHOLD || isUIAvatar())
  1567. {
  1568. return;
  1569. }
  1570. // Cleanup mesh data
  1571. for (avatar_joint_list_t::iterator iter = mMeshLOD.begin(),
  1572. end = mMeshLOD.end();
  1573. iter != end; ++iter)
  1574. {
  1575. LLAvatarJoint* joint = *iter;
  1576. joint->setValid(false, true);
  1577. }
  1578. // Cleanup data
  1579. if (mDrawable.notNull())
  1580. {
  1581. LLFace* facep = mDrawable->getFace(0);
  1582. if (facep)
  1583. {
  1584. facep->setSize(0, 0);
  1585. for (S32 i = mNumInitFaces, count = mDrawable->getNumFaces();
  1586. i < count; ++i)
  1587. {
  1588. facep = mDrawable->getFace(i);
  1589. if (facep)
  1590. {
  1591. facep->setSize(0, 0);
  1592. }
  1593. }
  1594. }
  1595. }
  1596. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  1597. end = mAttachmentPoints.end();
  1598. iter != end; ++iter)
  1599. {
  1600. LLViewerJointAttachment* attachment = iter->second;
  1601. if (attachment && !attachment->getIsHUDAttachment())
  1602. {
  1603. attachment->setAttachmentVisibility(false);
  1604. }
  1605. }
  1606. mMeshValid = false;
  1607. }
  1608. //virtual
  1609. void LLVOAvatar::restoreMeshData()
  1610. {
  1611. llassert(!isSelf());
  1612. if (mDrawable.isNull()) return;
  1613. mMeshValid = true;
  1614. updateJointLODs();
  1615. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  1616. end = mAttachmentPoints.end();
  1617. iter != end; ++iter)
  1618. {
  1619. LLViewerJointAttachment* attachment = iter->second;
  1620. if (attachment && !attachment->getIsHUDAttachment())
  1621. {
  1622. attachment->setAttachmentVisibility(true);
  1623. }
  1624. }
  1625. // Force mesh update as LOD might not have changed to trigger this
  1626. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
  1627. }
  1628. void LLVOAvatar::updateMeshData()
  1629. {
  1630. if (mDrawable.isNull())
  1631. {
  1632. return;
  1633. }
  1634. S32 f_num = 0;
  1635. // Small number of this means each part of an avatar has its own vertex
  1636. // buffer.
  1637. constexpr U32 VERTEX_NUMBER_THRESHOLD = 128;
  1638. const S32 num_parts = mMeshLOD.size();
  1639. // This order is determined by number of LODS; if a mesh earlier in this
  1640. // list changed LODs while a later mesh does not, the later mesh index
  1641. // offset will be inaccurate
  1642. for (S32 part_index = 0; part_index < num_parts; )
  1643. {
  1644. S32 j = part_index;
  1645. U32 num_verts = 0;
  1646. U32 num_indices = 0;
  1647. U32 last_v_num = 0;
  1648. U32 last_i_num = 0;
  1649. while (part_index < num_parts && num_verts < VERTEX_NUMBER_THRESHOLD)
  1650. {
  1651. last_v_num = num_verts;
  1652. last_i_num = num_indices;
  1653. LLViewerJoint* part_mesh = getViewerJoint(part_index++);
  1654. if (part_mesh)
  1655. {
  1656. part_mesh->updateFaceSizes(num_verts, num_indices,
  1657. mAdjustedPixelArea);
  1658. }
  1659. }
  1660. if (num_verts < 1)
  1661. {
  1662. // Skip empty meshes
  1663. continue;
  1664. }
  1665. if (last_v_num > 0)
  1666. {
  1667. // Put the last inserted part into next vertex buffer.
  1668. num_verts = last_v_num;
  1669. num_indices = last_i_num;
  1670. --part_index;
  1671. }
  1672. LLFace* facep;
  1673. if (f_num < mDrawable->getNumFaces())
  1674. {
  1675. facep = mDrawable->getFace(f_num);
  1676. }
  1677. else
  1678. {
  1679. facep = mDrawable->getFace(0);
  1680. if (facep)
  1681. {
  1682. facep = mDrawable->addFace(facep->getPool(),
  1683. facep->getTexture());
  1684. }
  1685. }
  1686. if (!facep)
  1687. {
  1688. continue;
  1689. }
  1690. // Resize immediately
  1691. facep->setSize(num_verts, num_indices);
  1692. bool terse_update = false;
  1693. facep->setGeomIndex(0);
  1694. facep->setIndicesIndex(0);
  1695. LLVertexBuffer* buffp = facep->getVertexBuffer();
  1696. if (buffp && buffp->getNumIndices() == num_indices &&
  1697. buffp->getNumVerts() == num_verts)
  1698. {
  1699. terse_update = true;
  1700. }
  1701. else
  1702. {
  1703. buffp = new LLVertexBuffer(LLDrawPoolAvatar::VERTEX_DATA_MASK);
  1704. #if LL_DEBUG_VB_ALLOC
  1705. buffp->setOwner("LLVOAvatar");
  1706. #endif
  1707. if (!buffp->allocateBuffer(num_verts, num_indices))
  1708. {
  1709. llwarns << "Failure to allocate a vertex buffer with "
  1710. << num_verts << " vertices and " << num_indices
  1711. << " indices" << llendl;
  1712. // Attempt to create a dummy triangle
  1713. facep->setSize(1, 3);
  1714. buffp->allocateBuffer(1, 3);
  1715. if (!buffp) continue;
  1716. buffp->resetVertexData();
  1717. buffp->resetIndexData();
  1718. }
  1719. facep->setVertexBuffer(buffp);
  1720. }
  1721. // *HACK: avatars have their own pool, so we are detecting the case of
  1722. // more than one avatar in the pool (thus > 0 instead of >= 0)
  1723. if (facep->getGeomIndex() > 0)
  1724. {
  1725. llwarns << getFullname(true) << " has non-zero geom index: "
  1726. << facep->getGeomIndex() << llendl;
  1727. llassert(false);
  1728. continue;
  1729. }
  1730. if (buffp->getNumIndices() == num_indices &&
  1731. buffp->getNumVerts() == num_verts)
  1732. {
  1733. for (S32 k = j; k < part_index; ++k)
  1734. {
  1735. bool rigid = false;
  1736. if (k == MESH_ID_EYEBALL_LEFT || k == MESH_ID_EYEBALL_RIGHT)
  1737. {
  1738. // Eyeballs cannot have terse updates since they are never
  1739. // rendered with the hardware skinning shader
  1740. rigid = true;
  1741. }
  1742. LLViewerJoint* mesh = getViewerJoint(k);
  1743. if (mesh)
  1744. {
  1745. mesh->updateFaceData(facep, mAdjustedPixelArea,
  1746. k == MESH_ID_HAIR,
  1747. terse_update && !rigid);
  1748. }
  1749. }
  1750. }
  1751. buffp->unmapBuffer();
  1752. if (!f_num)
  1753. {
  1754. f_num += mNumInitFaces;
  1755. }
  1756. else
  1757. {
  1758. ++f_num;
  1759. }
  1760. }
  1761. }
  1762. U32 LLVOAvatar::processUpdateMessage(LLMessageSystem* msg,
  1763. void** user_data, U32 block_num,
  1764. EObjectUpdateType update_type,
  1765. LLDataPacker* dp)
  1766. {
  1767. // Do base class updates...
  1768. U32 retval = LLViewerObject::processUpdateMessage(msg, user_data,
  1769. block_num, update_type,
  1770. dp);
  1771. if ((retval & LLViewerObject::INVALID_UPDATE) && isSelf())
  1772. {
  1773. // Tell the sim to cancel this update
  1774. gAgent.teleportViaLocation(gAgent.getPositionGlobal());
  1775. }
  1776. return retval;
  1777. }
  1778. LLViewerFetchedTexture* LLVOAvatar::getBakedTextureImage(U8 te,
  1779. const LLUUID& id)
  1780. {
  1781. if (id.isNull() && LLViewerFetchedTexture::sDefaultImagep.notNull())
  1782. {
  1783. return LLViewerFetchedTexture::sDefaultImagep;
  1784. }
  1785. if (id == IMG_DEFAULT_AVATAR || id == IMG_DEFAULT || id == IMG_INVISIBLE)
  1786. {
  1787. // Should already exist, do not need to find it on sim or baked texture
  1788. // host.
  1789. LLViewerFetchedTexture* texp = gTextureList.findImage(id);
  1790. if (texp)
  1791. {
  1792. return texp;
  1793. }
  1794. }
  1795. const std::string url = getImageURL(te, id);
  1796. if (url.empty())
  1797. {
  1798. LL_DEBUGS("Avatar") << getFullname(true) << "Getting texture " << id
  1799. << " from host." << LL_ENDL;
  1800. LLHost host = getObjectHost();
  1801. return LLViewerTextureManager::getFetchedTexture(id, FTT_HOST_BAKE,
  1802. true,
  1803. LLGLTexture::BOOST_NONE,
  1804. LLViewerTexture::LOD_TEXTURE,
  1805. 0, 0, host);
  1806. }
  1807. LL_DEBUGS("Avatar") << getFullname(true) << " - URL for texture "
  1808. << id << ": " << url << LL_ENDL;
  1809. return LLViewerTextureManager::getFetchedTextureFromUrl(url,
  1810. FTT_SERVER_BAKE,
  1811. true,
  1812. LLGLTexture::BOOST_NONE,
  1813. LLViewerTexture::LOD_TEXTURE,
  1814. 0, 0, id);
  1815. }
  1816. LLViewerTexture* LLVOAvatar::getBakedTexture(U8 te)
  1817. {
  1818. if (te < 0 || te >= BAKED_NUM_INDICES)
  1819. {
  1820. return NULL;
  1821. }
  1822. if (!mIsEditingAppearance)
  1823. {
  1824. ETextureIndex i = mBakedTextureDatas[te].mTextureIndex;
  1825. if (!isTextureDefined(i))
  1826. {
  1827. return NULL;
  1828. }
  1829. LLViewerTexture* baked_img = getImage(i, 0);
  1830. if (!baked_img)
  1831. {
  1832. return NULL;
  1833. }
  1834. return LLViewerTextureManager::staticCast(baked_img, true);
  1835. }
  1836. LLViewerTexLayerSet* layerset = getTexLayerSet(te);
  1837. if (!layerset)
  1838. {
  1839. return NULL;
  1840. }
  1841. layerset->createComposite();
  1842. layerset->setUpdatesEnabled(true);
  1843. return layerset->getViewerComposite();
  1844. }
  1845. //virtual
  1846. S32 LLVOAvatar::setTETexture(U8 te, const LLUUID& id)
  1847. {
  1848. if (!isIndexBakedTexture((ETextureIndex)te))
  1849. {
  1850. // Sim still sends some UUIDs for non-baked slots sometimes: ignore.
  1851. return LLViewerObject::setTETexture(te, LLUUID::null);
  1852. }
  1853. return setTETextureCore(te, getBakedTextureImage(te, id));
  1854. }
  1855. void LLVOAvatar::idleUpdate(F64 time)
  1856. {
  1857. LL_FAST_TIMER(FTM_AVATAR_UPDATE);
  1858. if (isDead())
  1859. {
  1860. llwarns << "Idle update on dead avatar" << llendl;
  1861. return;
  1862. }
  1863. U32 type = isPuppetAvatar() ? LLPipeline::RENDER_TYPE_PUPPET
  1864. : LLPipeline::RENDER_TYPE_AVATAR;
  1865. if (!gPipeline.hasRenderType(type))
  1866. {
  1867. return;
  1868. }
  1869. S32 current_frame = LLViewerOctreeEntryData::getCurrentFrame();
  1870. if (!mNeedsExtentUpdate)
  1871. {
  1872. mNeedsExtentUpdate = current_frame >= mNextFrameForExtentUpdate ||
  1873. mLastAnimExtents[0].isExactlyZero() ||
  1874. mLastAnimExtents[1].isExactlyZero();
  1875. }
  1876. // Extent update should be happening max once every 4 frames (and even
  1877. // less often for far impostors - HB).
  1878. if (mNeedsExtentUpdate)
  1879. {
  1880. mNextFrameForExtentUpdate = current_frame + llmax(4, mUpdatePeriod);
  1881. }
  1882. checkTextureLoading();
  1883. // Force immediate pixel area update on avatars using last frames data
  1884. // (before drawable or camera updates)
  1885. setPixelAreaAndAngle();
  1886. // Force asynchronous drawable update
  1887. if (mDrawable.notNull())
  1888. {
  1889. LL_FAST_TIMER(FTM_JOINT_UPDATE);
  1890. if (mIsSitting && getParent())
  1891. {
  1892. LLViewerObject* root_object = (LLViewerObject*)getRoot();
  1893. LLDrawable* drawablep = root_object->mDrawable;
  1894. // If this object has not already been updated by another avatar...
  1895. if (drawablep) // && !drawablep->isState(LLDrawable::EARLY_MOVE))
  1896. {
  1897. if (root_object->isSelected())
  1898. {
  1899. gPipeline.updateMoveNormalAsync(drawablep);
  1900. }
  1901. else
  1902. {
  1903. gPipeline.updateMoveDampedAsync(drawablep);
  1904. }
  1905. }
  1906. }
  1907. else
  1908. {
  1909. gPipeline.updateMoveDampedAsync(mDrawable);
  1910. }
  1911. }
  1912. // Set alpha flag depending on state
  1913. if (isSelf())
  1914. {
  1915. LLViewerObject::idleUpdate(time);
  1916. // trigger fidget anims
  1917. if (isAnyAnimationSignaled(AGENT_STAND_ANIMS, NUM_AGENT_STAND_ANIMS))
  1918. {
  1919. gAgent.fidget();
  1920. }
  1921. }
  1922. else
  1923. {
  1924. // Should override the idleUpdate stuff and leave out the angular
  1925. // update part.
  1926. LLQuaternion rotation = getRotation();
  1927. LLViewerObject::idleUpdate(time);
  1928. setRotation(rotation);
  1929. }
  1930. // attach objects that were waiting for a drawable
  1931. lazyAttach();
  1932. // Animate the character. Store off last frame's root position to be
  1933. // consistent with camera position.
  1934. LLVector3 root_pos_last = mRoot->getWorldPosition();
  1935. bool detailed_update = updateCharacter();
  1936. bool voice_enabled = gVoiceClient.getVoiceEnabled(mID) &&
  1937. gVoiceClient.inProximalChannel();
  1938. idleUpdateVoiceVisualizer(voice_enabled);
  1939. idleUpdateMisc(detailed_update);
  1940. idleUpdateAppearanceAnimation();
  1941. if (detailed_update)
  1942. {
  1943. if (voice_enabled)
  1944. {
  1945. idleUpdateLipSync();
  1946. }
  1947. idleUpdateLoadingEffect();
  1948. idleUpdateBelowWater(); // wind effect uses this
  1949. idleUpdateWindEffect();
  1950. }
  1951. idleUpdateNameTag(root_pos_last);
  1952. idleUpdateRenderComplexity();
  1953. }
  1954. void LLVOAvatar::idleUpdateVoiceVisualizer(bool voice_enabled)
  1955. {
  1956. bool is_self = isSelf();
  1957. // Disable voice visualizer when in mouselook
  1958. mVoiceVisualizer->setVoiceEnabled(voice_enabled &&
  1959. !(is_self && gAgent.cameraMouselook()));
  1960. if (!voice_enabled || gFrameTimeSeconds < mNextVoiceVisualizerUpdate)
  1961. {
  1962. return;
  1963. }
  1964. // No more than 5 updates per second, please... HB
  1965. constexpr F32 MIN_DELAY = 0.2f;
  1966. mNextVoiceVisualizerUpdate = gFrameTimeSeconds + MIN_DELAY;
  1967. // Only do gesture triggering for your own avatar, and only when you are
  1968. // in a proximal channel.
  1969. if (is_self)
  1970. {
  1971. // The following takes the voice signal and uses that to trigger
  1972. // gesticulations.
  1973. S32 last_level = mCurrentGesticulationLevel;
  1974. mCurrentGesticulationLevel =
  1975. mVoiceVisualizer->getCurrentGesticulationLevel();
  1976. // If "current gesticulation level" changes, we catch this, and trigger
  1977. // the new gesture
  1978. if (last_level != mCurrentGesticulationLevel &&
  1979. mCurrentGesticulationLevel != VOICE_GESTICULATION_LEVEL_OFF)
  1980. {
  1981. if (mCurrentGesticulationLevel >= 0 &&
  1982. mCurrentGesticulationLevel <= 2)
  1983. {
  1984. std::string gesture_name =
  1985. llformat("/voicelevel%d", mCurrentGesticulationLevel + 1);
  1986. gGestureManager.triggerAndReviseString(gesture_name);
  1987. }
  1988. else
  1989. {
  1990. llwarns << "CurrentGesticulationLevel can be only 0, 1, or 2"
  1991. << llendl;
  1992. }
  1993. }
  1994. }
  1995. // If the avatar is speaking, then the voice amplitude signal is passed to
  1996. // the voice visualizer. Also, here we trigger voice visualizer start and
  1997. // stop speaking, so it can animate the voice symbol.
  1998. //
  1999. // Notice the calls to "gAgent.clearAFK()". This resets the timer that
  2000. // determines how long the avatar has been "away", so that the avatar
  2001. // does not lapse into away-mode (and slump over) while the user is still
  2002. // talking.
  2003. if (gVoiceClient.getIsSpeaking(mID))
  2004. {
  2005. if (!mVoiceVisualizer->getCurrentlySpeaking())
  2006. {
  2007. mVoiceVisualizer->setStartSpeaking();
  2008. }
  2009. mVoiceVisualizer->setSpeakingAmplitude(gVoiceClient.getCurrentPower(mID));
  2010. if (is_self)
  2011. {
  2012. gAgent.clearAFK();
  2013. }
  2014. }
  2015. else if (mVoiceVisualizer->getCurrentlySpeaking())
  2016. {
  2017. mVoiceVisualizer->setStopSpeaking();
  2018. if (mLipSyncActive)
  2019. {
  2020. if (mOohMorph)
  2021. {
  2022. mOohMorph->setWeight(mOohMorph->getMinWeight(), false);
  2023. }
  2024. if (mAahMorph)
  2025. {
  2026. mAahMorph->setWeight(mAahMorph->getMinWeight(), false);
  2027. }
  2028. mLipSyncActive = false;
  2029. LLCharacter::updateVisualParams();
  2030. dirtyMesh();
  2031. }
  2032. }
  2033. // Here we get the approximate head position and set as sound source for
  2034. // the voice symbol (the following version uses a tweak of "mHeadOffset"
  2035. // which handles sitting vs. standing)
  2036. if (mIsSitting)
  2037. {
  2038. LLVector3 headOffset = LLVector3(0.f, 0.f, mHeadOffset.mV[2]);
  2039. mVoiceVisualizer->setVoiceSourceWorldPosition(mRoot->getWorldPosition() +
  2040. headOffset);
  2041. }
  2042. else
  2043. {
  2044. LLVector3 tagPos = mRoot->getWorldPosition();
  2045. tagPos[VZ] -= mPelvisToFoot;
  2046. tagPos[VZ] += (mBodySize[VZ] + 0.125f);
  2047. mVoiceVisualizer->setVoiceSourceWorldPosition(tagPos);
  2048. }
  2049. }
  2050. static void override_bbox(LLDrawable* drawablep, LLVector4a* extents)
  2051. {
  2052. drawablep->setSpatialExtents(extents[0], extents[1]);
  2053. drawablep->setPositionGroup(LLVector4a::getZero());
  2054. drawablep->movePartition();
  2055. }
  2056. void LLVOAvatar::idleUpdateMisc(bool detailed_update)
  2057. {
  2058. if (sJointDebug)
  2059. {
  2060. llinfos << getFullname(true) << ": joint touches: "
  2061. << LLJoint::sNumTouches << " updates: "
  2062. << LLJoint::sNumUpdates << llendl;
  2063. }
  2064. LLJoint::sNumUpdates = 0;
  2065. LLJoint::sNumTouches = 0;
  2066. bool visible = isVisible() || mNeedsAnimUpdate;
  2067. bool impostor_not_needing_update = isImpostor() && !mNeedsImpostorUpdate;
  2068. // Update attachments positions
  2069. if (detailed_update && !impostor_not_needing_update)
  2070. {
  2071. LL_FAST_TIMER(FTM_ATTACHMENT_UPDATE);
  2072. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  2073. bool selected_attachment = selection->getObjectCount() &&
  2074. selection->isAttachment();
  2075. U32 draw_order = 0;
  2076. LLVector4a extents[2];
  2077. LLDrawable* drawablep;
  2078. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  2079. {
  2080. LLViewerObject* attach_objp = mAttachedObjectsVector[i].first;
  2081. LLViewerJointAttachment* attachment =
  2082. mAttachedObjectsVector[i].second;
  2083. if (!attachment || !attachment->getValid() ||
  2084. !attach_objp || attach_objp->isDead() ||
  2085. !(drawablep = attach_objp->mDrawable))
  2086. {
  2087. continue;
  2088. }
  2089. LLSpatialBridge* bridgep = drawablep->getSpatialBridge();
  2090. bool visible_attachment = visible ||
  2091. !(bridgep && bridgep->getRadius() < 2.f);
  2092. if (!visible_attachment)
  2093. {
  2094. continue;
  2095. }
  2096. constexpr S32 rigged_flags = LLDrawable::RIGGED |
  2097. LLDrawable::RIGGED_CHILD;
  2098. bool rigged_bridge = drawablep->isState(rigged_flags) &&
  2099. bridgep && !bridgep->isDead();
  2100. // Override rigged attachments' octree spatial extents with this
  2101. // avatar's bounding box
  2102. if (rigged_bridge)
  2103. {
  2104. // Transform avatar bounding box into the coordinate frame of
  2105. // the attachment
  2106. bridgep->transformExtents(mDrawable->getSpatialExtents(),
  2107. extents);
  2108. override_bbox(drawablep, extents);
  2109. // The bridge could have died in override_bbox() so we need to
  2110. // update the bridge.
  2111. bridgep = drawablep->getSpatialBridge();
  2112. }
  2113. if (selected_attachment)
  2114. {
  2115. gPipeline.updateMoveNormalAsync(drawablep);
  2116. }
  2117. else
  2118. {
  2119. gPipeline.updateMoveDampedAsync(drawablep);
  2120. }
  2121. if (bridgep && !bridgep->isDead())
  2122. {
  2123. if (rigged_bridge)
  2124. {
  2125. // Specialized updateMoveNormalAsync()-like move just for
  2126. // rigged attachment spatial bridge
  2127. bridgep->setState(LLDrawable::MOVE_UNDAMPED);
  2128. bridgep->updateMove();
  2129. bridgep->setState(LLDrawable::EARLY_MOVE);
  2130. // Set draw order of spatial group, if any.
  2131. LLSpatialGroup* group = drawablep->getSpatialGroup();
  2132. if (group)
  2133. {
  2134. group->mAvatarp = this;
  2135. group->mRenderOrder = draw_order++;
  2136. }
  2137. }
  2138. else
  2139. {
  2140. gPipeline.updateMoveNormalAsync(bridgep);
  2141. }
  2142. }
  2143. attach_objp->updateText();
  2144. }
  2145. }
  2146. mNeedsAnimUpdate = false;
  2147. if (impostor_not_needing_update)
  2148. {
  2149. LLVector4a ext[2];
  2150. F32 distance;
  2151. LLVector3 angle;
  2152. getImpostorValues(ext, angle, distance);
  2153. for (U32 i = 0; i < 3 && !mNeedsImpostorUpdate; ++i)
  2154. {
  2155. F32 cur_angle = angle.mV[i];
  2156. F32 old_angle = mImpostorAngle.mV[i];
  2157. F32 angle_diff = fabsf(cur_angle - old_angle);
  2158. if (angle_diff > F_PI / 512.f * distance * mUpdatePeriod)
  2159. {
  2160. mNeedsImpostorUpdate = mNeedsExtentUpdate = true;
  2161. }
  2162. }
  2163. if (detailed_update && !mNeedsImpostorUpdate)
  2164. {
  2165. // Update impostor if view angle, distance, or bounding box change
  2166. // significantly
  2167. F32 dist_diff = fabsf(distance - mImpostorDistance);
  2168. if (mImpostorDistance != 0.f &&
  2169. dist_diff / mImpostorDistance > 0.1f)
  2170. {
  2171. mNeedsImpostorUpdate = mNeedsExtentUpdate = true;
  2172. }
  2173. else
  2174. {
  2175. #if 0 // Do this only once per frame, in updateSpatialExtents()
  2176. calculateSpatialExtents(ext[0], ext[1]);
  2177. #else
  2178. ext[0].load3(mLastAnimExtents[0].mV);
  2179. ext[1].load3(mLastAnimExtents[1].mV);
  2180. #endif
  2181. LLVector4a diff;
  2182. diff.setSub(ext[1], mImpostorExtents[1]);
  2183. if (diff.getLength3().getF32() > 0.05f)
  2184. {
  2185. mNeedsImpostorUpdate = mNeedsExtentUpdate = true;
  2186. }
  2187. else
  2188. {
  2189. diff.setSub(ext[0], mImpostorExtents[0]);
  2190. if (diff.getLength3().getF32() > 0.05f)
  2191. {
  2192. mNeedsImpostorUpdate = mNeedsExtentUpdate = true;
  2193. }
  2194. }
  2195. }
  2196. }
  2197. }
  2198. if (mDrawable.notNull())
  2199. {
  2200. mDrawable->movePartition();
  2201. // Force a move if sitting on an active object
  2202. LLViewerObject* parent = (LLViewerObject*)getParent();
  2203. if (parent && parent->mDrawable && parent->mDrawable->isActive())
  2204. {
  2205. gPipeline.markMoved(mDrawable, true);
  2206. }
  2207. }
  2208. }
  2209. void LLVOAvatar::idleUpdateAppearanceAnimation()
  2210. {
  2211. // Update morphing params
  2212. if (!mAppearanceAnimating)
  2213. {
  2214. return;
  2215. }
  2216. F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
  2217. if (appearance_anim_time >= APPEARANCE_MORPH_TIME)
  2218. {
  2219. mAppearanceAnimating = false;
  2220. for (LLVisualParam* paramp = getFirstVisualParam(); paramp;
  2221. paramp = getNextVisualParam())
  2222. {
  2223. if (paramp->isTweakable())
  2224. {
  2225. paramp->stopAnimating(false);
  2226. }
  2227. }
  2228. updateVisualParams();
  2229. if (isSelf())
  2230. {
  2231. gAgent.sendAgentSetAppearance();
  2232. }
  2233. }
  2234. else
  2235. {
  2236. if (!isSelf())
  2237. {
  2238. F32 morph_amt = calcMorphAmount();
  2239. // Animate only top level params for non-self avatars
  2240. for (LLVisualParam* paramp = getFirstVisualParam(); paramp;
  2241. paramp = getNextVisualParam())
  2242. {
  2243. if (paramp->isTweakable())
  2244. {
  2245. paramp->animate(morph_amt, false);
  2246. }
  2247. }
  2248. }
  2249. // Apply all params
  2250. ESex avatar_sex = getSex();
  2251. for (LLVisualParam* paramp = getFirstVisualParam(); paramp;
  2252. paramp = getNextVisualParam())
  2253. {
  2254. paramp->apply(avatar_sex);
  2255. }
  2256. mLastAppearanceBlendTime = appearance_anim_time;
  2257. }
  2258. dirtyMesh();
  2259. }
  2260. F32 LLVOAvatar::calcMorphAmount()
  2261. {
  2262. F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
  2263. F32 blend_frac = calc_bouncy_animation(appearance_anim_time /
  2264. APPEARANCE_MORPH_TIME);
  2265. F32 last_blend_frac = calc_bouncy_animation(mLastAppearanceBlendTime /
  2266. APPEARANCE_MORPH_TIME);
  2267. F32 morph_amt;
  2268. if (last_blend_frac == 1.f)
  2269. {
  2270. morph_amt = 1.f;
  2271. }
  2272. else
  2273. {
  2274. morph_amt = (blend_frac - last_blend_frac) / (1.f - last_blend_frac);
  2275. }
  2276. return morph_amt;
  2277. }
  2278. void LLVOAvatar::idleUpdateLipSync()
  2279. {
  2280. // Use the Lipsync_Ooh and Lipsync_Aah morphs for lip sync
  2281. if (sLipSyncEnabled && gVoiceClient.isVoiceWorking() &&
  2282. gVoiceClient.getIsSpeaking(mID))
  2283. {
  2284. F32 ooh_morph_amount = 0.f;
  2285. F32 aah_morph_amount = 0.f;
  2286. mVoiceVisualizer->lipSyncOohAah(ooh_morph_amount, aah_morph_amount);
  2287. if (mOohMorph)
  2288. {
  2289. F32 ooh_weight = mOohMorph->getMinWeight() +
  2290. ooh_morph_amount *
  2291. (mOohMorph->getMaxWeight() -
  2292. mOohMorph->getMinWeight());
  2293. mOohMorph->setWeight(ooh_weight, false);
  2294. }
  2295. if (mAahMorph)
  2296. {
  2297. F32 aah_weight = mAahMorph->getMinWeight() +
  2298. aah_morph_amount *
  2299. (mAahMorph->getMaxWeight() -
  2300. mAahMorph->getMinWeight());
  2301. mAahMorph->setWeight(aah_weight, false);
  2302. }
  2303. mLipSyncActive = true;
  2304. LLCharacter::updateVisualParams();
  2305. dirtyMesh();
  2306. }
  2307. }
  2308. void LLVOAvatar::idleUpdateLoadingEffect()
  2309. {
  2310. // Update visibility when avatar is partially loaded
  2311. if (updateIsFullyLoaded()) // changed ?
  2312. {
  2313. if (isFullyLoaded())
  2314. {
  2315. deleteParticleSource();
  2316. updateLOD();
  2317. }
  2318. else if (!mIsDummy && !isTooComplex())
  2319. {
  2320. // Fancy particle cloud designed by Brent
  2321. LLPartSysData particle_parameters;
  2322. particle_parameters.mPartData.mMaxAge = 4.f;
  2323. particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
  2324. particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
  2325. particle_parameters.mPartData.mStartScale.mV[VY] = 1.f;
  2326. particle_parameters.mPartData.mEndScale.mV[VX] = 0.02f;
  2327. particle_parameters.mPartData.mEndScale.mV[VY] = 0.02f;
  2328. particle_parameters.mPartData.mStartColor =
  2329. LLColor4(1.f, 1.f, 1.f, 0.5f);
  2330. particle_parameters.mPartData.mEndColor =
  2331. LLColor4(1.f, 1.f, 1.f, 0.f);
  2332. particle_parameters.mPartData.mStartScale.mV[VX] = 0.8f;
  2333. particle_parameters.mPartImageID =
  2334. LLViewerTexture::sCloudImagep->getID();
  2335. particle_parameters.mMaxAge = 0.f;
  2336. particle_parameters.mPattern =
  2337. LLPartSysData::LL_PART_SRC_PATTERN_ANGLE_CONE;
  2338. particle_parameters.mInnerAngle = F_PI;
  2339. particle_parameters.mOuterAngle = 0.f;
  2340. particle_parameters.mBurstRate = 0.02f;
  2341. particle_parameters.mBurstRadius = 0.f;
  2342. particle_parameters.mBurstPartCount = 1;
  2343. particle_parameters.mBurstSpeedMin = 0.1f;
  2344. particle_parameters.mBurstSpeedMax = 1.f;
  2345. particle_parameters.mPartData.mFlags =
  2346. LLPartData::LL_PART_INTERP_COLOR_MASK |
  2347. LLPartData::LL_PART_INTERP_SCALE_MASK |
  2348. LLPartData::LL_PART_EMISSIVE_MASK |
  2349. LLPartData::LL_PART_TARGET_POS_MASK;
  2350. setParticleSource(particle_parameters, getID());
  2351. }
  2352. }
  2353. }
  2354. void LLVOAvatar::idleUpdateWindEffect()
  2355. {
  2356. // Update wind effect
  2357. if (gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) >=
  2358. LLDrawPoolAvatar::SHADER_LEVEL_CLOTH)
  2359. {
  2360. F32 hover_strength = 0.f;
  2361. F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
  2362. mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
  2363. LLVector3 velocity = getVelocity();
  2364. F32 speed = velocity.length();
  2365. #if 0 // RN: velocity varies too much frame to frame for this to work
  2366. lerp(mRippleAccel, (velocity - mLastVel) * time_delta,
  2367. LLCriticalDamp::getInterpolant(0.02f));
  2368. #else
  2369. mRippleAccel.clear();
  2370. #endif
  2371. mLastVel = velocity;
  2372. LLVector4 wind;
  2373. wind.set(getRegion()->mWind.getVelocityNoisy(getPositionAgent(), 4.f) -
  2374. velocity);
  2375. if (mInAir)
  2376. {
  2377. hover_strength = HOVER_EFFECT_STRENGTH *
  2378. llmax(0.f, HOVER_EFFECT_MAX_SPEED - speed);
  2379. }
  2380. if (mBelowWater)
  2381. {
  2382. // *TODO: make cloth flow more gracefully when underwater
  2383. hover_strength += UNDERWATER_EFFECT_STRENGTH;
  2384. }
  2385. wind.mV[VZ] += hover_strength;
  2386. wind.normalize();
  2387. wind.mV[VW] = llmin(0.025f + speed * 0.015f + hover_strength, 0.5f);
  2388. F32 interp;
  2389. if (wind.mV[VW] > mWindVec.mV[VW])
  2390. {
  2391. interp = LLCriticalDamp::getInterpolant(0.2f);
  2392. }
  2393. else
  2394. {
  2395. interp = LLCriticalDamp::getInterpolant(0.4f);
  2396. }
  2397. mWindVec = lerp(mWindVec, wind, interp);
  2398. F32 wind_freq = hover_strength +
  2399. llclamp(8.f + speed * 0.7f +
  2400. noise1(mRipplePhase) * 4.f,
  2401. 8.f, 25.f);
  2402. mWindFreq = lerp(mWindFreq, wind_freq, interp);
  2403. if (mBelowWater)
  2404. {
  2405. mWindFreq *= UNDERWATER_FREQUENCY_DAMP;
  2406. }
  2407. mRipplePhase += time_delta * mWindFreq;
  2408. if (mRipplePhase > F_TWO_PI)
  2409. {
  2410. mRipplePhase = fmodf(mRipplePhase, F_TWO_PI);
  2411. }
  2412. }
  2413. }
  2414. void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
  2415. {
  2416. // Update chat bubble (draw text label over character's head)
  2417. if (mChatTimer.getElapsedTimeF32() > BUBBLE_CHAT_TIME)
  2418. {
  2419. mChats.clear();
  2420. }
  2421. static LLCachedControl<F32> name_show_time(gSavedSettings,
  2422. "RenderNameShowTime");
  2423. static LLCachedControl<F32> fade_duration(gSavedSettings,
  2424. "RenderNameFadeDuration");
  2425. static LLCachedControl<bool> show_typing_info(gSavedSettings,
  2426. "ShowTypingInfo");
  2427. static LLCachedControl<bool> use_chat_bubbles(gSavedSettings,
  2428. "UseChatBubbles");
  2429. bool show_typing = show_typing_info && !use_chat_bubbles;
  2430. bool visible_avatar = isVisible() || mNeedsAnimUpdate;
  2431. bool visible_chat = use_chat_bubbles && (mChats.size() || mTyping);
  2432. if (mTyping && show_typing && !visible_chat &&
  2433. sRenderName == RENDER_NAME_FADE)
  2434. {
  2435. mTimeVisible.reset();
  2436. }
  2437. const F32 time_visible = mTimeVisible.getElapsedTimeF32();
  2438. bool render_name = visible_chat ||
  2439. (visible_avatar &&
  2440. (sRenderName == RENDER_NAME_ALWAYS ||
  2441. (sRenderName == RENDER_NAME_FADE &&
  2442. time_visible < name_show_time)));
  2443. // If it is our own avatar, do not draw in mouselook, and do not draw if we
  2444. // are specifically hiding our own name.
  2445. if (render_name && isSelf())
  2446. {
  2447. static LLCachedControl<bool> render_name_hide_self(gSavedSettings,
  2448. "RenderNameHideSelf");
  2449. render_name = !gAgent.cameraMouselook() &&
  2450. (visible_chat || !render_name_hide_self);
  2451. }
  2452. //MK
  2453. // Hide the names above the heads if we are under @shownametags or
  2454. // @shownames or if we are under @camdistdrawmin and the other avatar is
  2455. // farther than the specified distance hide the names above the heads
  2456. if (gRLenabled)
  2457. {
  2458. if (gRLInterface.mContainsShownames ||
  2459. gRLInterface.mContainsShownametags)
  2460. {
  2461. render_name = false;
  2462. }
  2463. else if (gRLInterface.mCamDistDrawMin < EXTREMUM &&
  2464. isAgentAvatarValid() && gAgentAvatarp != this)
  2465. {
  2466. LLVector3 head_pos = gAgentAvatarp->mHeadp->getWorldPosition();
  2467. LLVector3 camera_offset = mHeadp->getWorldPosition() - head_pos;
  2468. F32 camera_distance = (F32)camera_offset.length();
  2469. if (camera_distance > gRLInterface.mCamDistDrawMin)
  2470. {
  2471. render_name = false;
  2472. }
  2473. }
  2474. }
  2475. //mk
  2476. if (!render_name)
  2477. {
  2478. deleteNameTag();
  2479. return;
  2480. }
  2481. bool new_name = false;
  2482. if (visible_chat != mVisibleChat)
  2483. {
  2484. mVisibleChat = visible_chat;
  2485. new_name = true;
  2486. }
  2487. if (sRenderGroupTitles != mRenderGroupTitles)
  2488. {
  2489. mRenderGroupTitles = sRenderGroupTitles;
  2490. new_name = true;
  2491. }
  2492. // First Calculate alpha. If > 0, create mNameText if necessary, otherwise
  2493. // delete it
  2494. F32 alpha = 0.f;
  2495. if (mAppAngle > 5.f)
  2496. {
  2497. const F32 start_fade_time = name_show_time - fade_duration;
  2498. if (!visible_chat && sRenderName == RENDER_NAME_FADE &&
  2499. time_visible > start_fade_time)
  2500. {
  2501. alpha = 1.f - (time_visible - start_fade_time) / fade_duration;
  2502. }
  2503. else
  2504. {
  2505. // ...not fading, full alpha
  2506. alpha = 1.f;
  2507. }
  2508. }
  2509. else if (mAppAngle > 2.f)
  2510. {
  2511. // Far away is faded out also
  2512. alpha = (mAppAngle - 2.f) / 3.f;
  2513. }
  2514. if (alpha <= 0.f)
  2515. {
  2516. deleteNameTag();
  2517. return;
  2518. }
  2519. if (mNameText.isNull() || mNameText->isDead())
  2520. {
  2521. mNameText =
  2522. (LLHUDText*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
  2523. mNameText->setMass(10.f);
  2524. mNameText->setSourceObject(this);
  2525. mNameText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
  2526. mNameText->setVisibleOffScreen(true);
  2527. mNameText->setMaxLines(11);
  2528. mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
  2529. mNameText->setUseBubble(true);
  2530. ++sNumVisibleChatBubbles;
  2531. new_name = true;
  2532. }
  2533. LLColor4 name_color = mNameTagColor;
  2534. name_color.setAlpha(alpha);
  2535. mNameText->setColor(name_color);
  2536. LLQuaternion root_rot = mRoot->getWorldRotation();
  2537. mNameText->setUsePixelSize(true);
  2538. LLVector3 pixel_right_vec;
  2539. LLVector3 pixel_up_vec;
  2540. gViewerCamera.getPixelVectors(root_pos_last, pixel_up_vec,
  2541. pixel_right_vec);
  2542. LLVector3 camera_to_av = root_pos_last - gViewerCamera.getOrigin();
  2543. camera_to_av.normalize();
  2544. LLVector3 local_camera_at = camera_to_av * ~root_rot;
  2545. LLVector3 local_camera_up = camera_to_av % gViewerCamera.getLeftAxis();
  2546. local_camera_up.normalize();
  2547. local_camera_up = local_camera_up * ~root_rot;
  2548. local_camera_up.scaleVec(mBodySize * 0.5f);
  2549. local_camera_at.scaleVec(mBodySize * 0.5f);
  2550. LLVector3 name_position = mRoot->getWorldPosition();
  2551. name_position[VZ] -= mPelvisToFoot;
  2552. name_position[VZ] += (mBodySize[VZ] * 0.55f);
  2553. name_position += local_camera_up * root_rot -
  2554. projected_vec(local_camera_at * root_rot,
  2555. camera_to_av);
  2556. name_position += pixel_up_vec * 15.f;
  2557. mNameText->setPositionAgent(name_position);
  2558. LLNameValue* title = getNVPair("Title");
  2559. LLNameValue* firstname = getNVPair("FirstName");
  2560. LLNameValue* lastname = getNVPair("LastName");
  2561. if (mNameText.notNull() && !mNameText->isDead() && firstname && lastname)
  2562. {
  2563. std::string complete_name = firstname->getString();
  2564. std::string last = lastname->getString();
  2565. if (!LLAvatarName::sOmitResidentAsLastName || last != "Resident")
  2566. {
  2567. if (sRenderGroupTitles)
  2568. {
  2569. complete_name += " ";
  2570. }
  2571. else
  2572. {
  2573. // If all group titles are turned off, stack first name on a
  2574. // line above last name
  2575. complete_name += "\n";
  2576. }
  2577. complete_name += last;
  2578. }
  2579. if (LLAvatarNameCache::useDisplayNames())
  2580. {
  2581. LLAvatarName avatar_name;
  2582. if (LLAvatarNameCache::get(mID, &avatar_name))
  2583. {
  2584. if (LLAvatarNameCache::useDisplayNames() == 2)
  2585. {
  2586. complete_name = avatar_name.mDisplayName;
  2587. }
  2588. else
  2589. {
  2590. complete_name = avatar_name.getNames(true);
  2591. }
  2592. }
  2593. }
  2594. anim_it_t end_signaled_anims = mSignaledAnimations.end();
  2595. bool is_away =
  2596. mSignaledAnimations.find(ANIM_AGENT_AWAY) != end_signaled_anims;
  2597. bool is_busy =
  2598. mSignaledAnimations.find(ANIM_AGENT_BUSY) != end_signaled_anims;
  2599. bool is_appearance =
  2600. mSignaledAnimations.find(ANIM_AGENT_CUSTOMIZE) != end_signaled_anims;
  2601. bool chat_muted = mCachedMuteFlags == 0 ||
  2602. (mCachedMuteFlags != -1 &&
  2603. (mCachedMuteFlags & LLMute::flagTextChat));
  2604. if (mNameString.empty() || new_name ||
  2605. complete_name != mCompleteName ||
  2606. (!title && !mTitle.empty()) ||
  2607. (title && mTitle != title->getString()) ||
  2608. is_away != mNameAway || is_busy != mNameBusy ||
  2609. mCachedMuteFlags != mNameMute || is_appearance != mNameAppearance ||
  2610. (show_typing && !chat_muted && mTyping != mNameTyping))
  2611. {
  2612. std::string line;
  2613. if (sRenderGroupTitles && title && title->getString() &&
  2614. title->getString()[0] != '\0')
  2615. {
  2616. line += title->getString();
  2617. LLStringFn::replace_ascii_controlchars(line, LL_UNKNOWN_CHAR);
  2618. line += "\n";
  2619. line += complete_name;
  2620. }
  2621. else
  2622. {
  2623. line = complete_name;
  2624. }
  2625. bool need_comma = false;
  2626. if (is_away || is_busy || mCachedMuteFlags != -1 ||
  2627. (show_typing && mTyping))
  2628. {
  2629. line += "\n(";
  2630. if (is_away)
  2631. {
  2632. line += "Away";
  2633. need_comma = true;
  2634. }
  2635. if (is_busy)
  2636. {
  2637. if (need_comma)
  2638. {
  2639. line += ", ";
  2640. }
  2641. line += "Busy";
  2642. need_comma = true;
  2643. }
  2644. if (show_typing && mTyping && !chat_muted)
  2645. {
  2646. if (need_comma)
  2647. {
  2648. line += ", ";
  2649. }
  2650. line += "Typing";
  2651. need_comma = true;
  2652. }
  2653. if (mCachedMuteFlags != -1)
  2654. {
  2655. if (need_comma)
  2656. {
  2657. line += ", ";
  2658. }
  2659. line += mCachedMuteDesc;
  2660. }
  2661. line += ")";
  2662. }
  2663. if (is_appearance)
  2664. {
  2665. line += "\n";
  2666. line += "(Editing Appearance)";
  2667. }
  2668. mNameAway = is_away;
  2669. mNameBusy = is_busy;
  2670. mNameTyping = mTyping;
  2671. mNameMute = mCachedMuteFlags;
  2672. mNameAppearance = is_appearance;
  2673. mTitle = title ? title->getString() : "";
  2674. mCompleteName = complete_name;
  2675. mNameString = utf8str_to_wstring(line);
  2676. new_name = true;
  2677. }
  2678. if (visible_chat)
  2679. {
  2680. mNameText->setDropShadow(true);
  2681. mNameText->setFont(LLFontGL::getFontSansSerif());
  2682. mNameText->setTextAlignment(LLHUDText::ALIGN_TEXT_LEFT);
  2683. mNameText->setFadeDistance(CHAT_NORMAL_RADIUS * 2.f, 5.f);
  2684. if (new_name)
  2685. {
  2686. mNameText->setLabel(mNameString);
  2687. }
  2688. std::deque<LLChat>::iterator chat_iter = mChats.begin();
  2689. std::deque<LLChat>::iterator chat_end = mChats.end();
  2690. mNameText->clearString();
  2691. LLColor4 new_chat = mNameTagColor;
  2692. LLColor4 normal_chat = lerp(new_chat,
  2693. LLColor4(0.8f, 0.8f, 0.8f, 1.f),
  2694. 0.7f);
  2695. LLColor4 old_chat = lerp(normal_chat,
  2696. LLColor4(0.6f, 0.6f, 0.6f, 1.f),
  2697. 0.7f);
  2698. if (mTyping && (S32)mChats.size() >= MAX_BUBBLE_CHAT_UTTERANCES)
  2699. {
  2700. ++chat_iter;
  2701. }
  2702. for ( ; chat_iter != chat_end; ++chat_iter)
  2703. {
  2704. F32 chat_fade_amt =
  2705. llclamp((F32)((LLFrameTimer::getElapsedSeconds() -
  2706. chat_iter->mTime) / CHAT_FADE_TIME),
  2707. 0.f, 4.f);
  2708. LLFontGL::StyleFlags style;
  2709. switch (chat_iter->mChatType)
  2710. {
  2711. case CHAT_TYPE_WHISPER:
  2712. style = LLFontGL::ITALIC;
  2713. break;
  2714. case CHAT_TYPE_SHOUT:
  2715. style = LLFontGL::BOLD;
  2716. break;
  2717. default:
  2718. style = LLFontGL::NORMAL;
  2719. }
  2720. if (chat_fade_amt < 1.f)
  2721. {
  2722. F32 u = clamp_rescale(chat_fade_amt, 0.9f, 1.f, 0.f, 1.f);
  2723. mNameText->addLine(utf8str_to_wstring(chat_iter->mText),
  2724. lerp(new_chat, normal_chat, u),
  2725. style);
  2726. }
  2727. else if (chat_fade_amt < 2.f)
  2728. {
  2729. F32 u = clamp_rescale(chat_fade_amt, 1.9f, 2.f, 0.f, 1.f);
  2730. mNameText->addLine(utf8str_to_wstring(chat_iter->mText),
  2731. lerp(normal_chat, old_chat, u), style);
  2732. }
  2733. else if (chat_fade_amt < 3.f)
  2734. {
  2735. // *NOTE: only remove lines down to minimum number
  2736. mNameText->addLine(utf8str_to_wstring(chat_iter->mText),
  2737. old_chat, style);
  2738. }
  2739. }
  2740. mNameText->setVisibleOffScreen(true);
  2741. if (mTyping)
  2742. {
  2743. S32 dot_count =
  2744. (llfloor(mTypingTimer.getElapsedTimeF32() * 3.f) + 2) % 3 + 1;
  2745. switch (dot_count)
  2746. {
  2747. case 1:
  2748. mNameText->addLine(".", new_chat);
  2749. break;
  2750. case 2:
  2751. mNameText->addLine("..", new_chat);
  2752. break;
  2753. case 3:
  2754. mNameText->addLine("...", new_chat);
  2755. }
  2756. }
  2757. }
  2758. else
  2759. {
  2760. static LLCachedControl<bool> small_avatar_names(gSavedSettings,
  2761. "SmallAvatarNames");
  2762. if (small_avatar_names)
  2763. {
  2764. mNameText->setFont(LLFontGL::getFontSansSerif());
  2765. }
  2766. else
  2767. {
  2768. mNameText->setFont(LLFontGL::getFontSansSerifLarge());
  2769. }
  2770. mNameText->setTextAlignment(LLHUDText::ALIGN_TEXT_CENTER);
  2771. mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
  2772. mNameText->setVisibleOffScreen(false);
  2773. if (new_name)
  2774. {
  2775. mNameText->setLabel("");
  2776. mNameText->setString(mNameString);
  2777. }
  2778. }
  2779. }
  2780. }
  2781. void LLVOAvatar::setMinimapColor(const LLColor4& color)
  2782. {
  2783. mMinimapColor = color;
  2784. static LLCachedControl<LLColor4U> map_avatar(gColors, "MapAvatar");
  2785. static LLCachedControl<LLColor4U> map_friend(gColors, "MapFriend");
  2786. bool is_friend = LLAvatarTracker::isAgentFriend(mID);
  2787. LLColor4 expected_color = LLColor4(is_friend ? map_friend : map_avatar);
  2788. if (expected_color != color)
  2789. {
  2790. sMinimapColorsMap[mID] = color;
  2791. }
  2792. else
  2793. {
  2794. sMinimapColorsMap.erase(mID);
  2795. }
  2796. }
  2797. //static
  2798. const LLColor4& LLVOAvatar::getMinimapColor(const LLUUID& id)
  2799. {
  2800. if (!sMinimapColorsMap.empty())
  2801. {
  2802. colors_map_t::const_iterator it = sMinimapColorsMap.find(id);
  2803. if (it != sMinimapColorsMap.end())
  2804. {
  2805. return it->second;
  2806. }
  2807. }
  2808. static const LLColor4 normal_color(gColors.getColor4U("MapAvatar"));
  2809. static const LLColor4 friend_color(gColors.getColor4U("MapFriend"));
  2810. return LLAvatarTracker::isAgentFriend(id) ? friend_color : normal_color;
  2811. }
  2812. void LLVOAvatar::setNameTagColor(const LLColor4& color)
  2813. {
  2814. mNameTagColor = color;
  2815. if (mNameText.notNull() && !mNameText->isDead())
  2816. {
  2817. mNameText->setColor(color);
  2818. }
  2819. }
  2820. void LLVOAvatar::deleteNameTag()
  2821. {
  2822. if (mNameText.notNull() && !mNameText->isDead())
  2823. {
  2824. mNameText->markDead();
  2825. mNameText = NULL;
  2826. --sNumVisibleChatBubbles;
  2827. }
  2828. }
  2829. void LLVOAvatar::clearNameTag()
  2830. {
  2831. if (!mIsDummy)
  2832. {
  2833. mNameString.clear();
  2834. if (mNameText.notNull() && !mNameText->isDead())
  2835. {
  2836. mNameText->setLabel("");
  2837. mNameText->setString(mNameString);
  2838. }
  2839. }
  2840. }
  2841. //static
  2842. void LLVOAvatar::invalidateNameTag(const LLUUID& agent_id)
  2843. {
  2844. LLVOAvatar* avatarp = gObjectList.findAvatar(agent_id);
  2845. if (avatarp)
  2846. {
  2847. avatarp->clearNameTag();
  2848. }
  2849. }
  2850. //static
  2851. void LLVOAvatar::invalidateNameTags()
  2852. {
  2853. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  2854. {
  2855. LLVOAvatar* avatar = (LLVOAvatar*)LLCharacter::sInstances[i];
  2856. if (avatar && !avatar->isDead())
  2857. {
  2858. avatar->clearNameTag();
  2859. }
  2860. }
  2861. }
  2862. void LLVOAvatar::idleUpdateBelowWater()
  2863. {
  2864. if (getRegion()) // May be NULL on disconnect during TP
  2865. {
  2866. F32 avatar_height = (F32)(getPositionGlobal().mdV[VZ]);
  2867. mBelowWater = avatar_height < getRegion()->getWaterHeight();
  2868. }
  2869. }
  2870. void LLVOAvatar::slamPosition()
  2871. {
  2872. gAgent.setPositionAgent(getPositionAgent());
  2873. mRoot->setWorldPosition(getPositionAgent()); // teleport
  2874. setChanged(TRANSLATED);
  2875. if (mDrawable.notNull())
  2876. {
  2877. gPipeline.updateMoveNormalAsync(mDrawable);
  2878. }
  2879. mRoot->updateWorldMatrixChildren();
  2880. }
  2881. //virtual
  2882. void LLVOAvatar::onChange()
  2883. {
  2884. bool old_mute = mCachedMute;
  2885. mCachedMute = LLMuteList::isMuted(mID);
  2886. mCachedMuteFlags = LLMuteList::getMuteFlags(mID, mCachedMuteDesc);
  2887. if (mCachedMute != old_mute)
  2888. {
  2889. mCachedVisualMuteUpdateTime = 0.f;
  2890. }
  2891. if (mCachedMute)
  2892. {
  2893. mVisuallyMuteSetting = AV_RENDER_NORMALLY;
  2894. }
  2895. }
  2896. //virtual
  2897. bool LLVOAvatar::isVisuallyMuted()
  2898. {
  2899. if (isDead()) return false;
  2900. bool muted = mCachedVisualMute;
  2901. if (gFrameTimeSeconds > mCachedVisualMuteUpdateTime)
  2902. {
  2903. mCachedVisualMuteUpdateTime = gFrameTimeSeconds + 5.f;
  2904. mMutedAVColor = LLColor4::white;
  2905. if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
  2906. {
  2907. muted = false;
  2908. }
  2909. else if (mVisuallyMuteSetting == AV_DO_NOT_RENDER)
  2910. {
  2911. muted = true;
  2912. mMutedAVColor = LLColor4::grey3;
  2913. }
  2914. else if (mCachedMute)
  2915. {
  2916. muted = true;
  2917. mMutedAVColor = LLColor4::grey4;
  2918. }
  2919. else
  2920. {
  2921. muted = isTooComplex();
  2922. if (muted)
  2923. {
  2924. static LLCachedControl<bool> colored(gSavedSettings,
  2925. "ColoredJellyDolls");
  2926. if (colored)
  2927. {
  2928. // Same silly calculations as in LL's viewer, just slightly
  2929. // optimized...
  2930. static LLColor4* spectrum_color[] = { &LLColor4::red,
  2931. &LLColor4::magenta,
  2932. &LLColor4::blue,
  2933. &LLColor4::cyan,
  2934. &LLColor4::green,
  2935. &LLColor4::yellow,
  2936. &LLColor4::red };
  2937. constexpr F32 SCALING_FACTOR = 6.f / 256.f;
  2938. F32 spectrum = F32(getID().mData[0]) * SCALING_FACTOR;
  2939. S32 spectrum_index_1 = floor(spectrum);
  2940. S32 spectrum_index_2 = spectrum_index_1 + 1;
  2941. F32 fraction = spectrum - (F32)(spectrum_index_1);
  2942. mMutedAVColor = lerp(*spectrum_color[spectrum_index_1],
  2943. *spectrum_color[spectrum_index_2],
  2944. fraction);
  2945. mMutedAVColor.normalize();
  2946. mMutedAVColor *= 0.28f;
  2947. }
  2948. else
  2949. {
  2950. mMutedAVColor = LLColor4::grey3;
  2951. }
  2952. LLFirstUse::useJellyDoll();
  2953. }
  2954. }
  2955. //MK
  2956. bool old_rlv_mute = mCachedRLVMute;
  2957. mCachedRLVMute = gRLenabled &&
  2958. gRLInterface.avatarVisibility(this) != 1;
  2959. if (mCachedRLVMute)
  2960. {
  2961. if (old_rlv_mute != mCachedRLVMute)
  2962. {
  2963. LL_DEBUGS("RestrainedLove") << getFullname(true)
  2964. << " rendering is "
  2965. << (mCachedRLVMute ? "no more"
  2966. : "now")
  2967. << " restricted." << LL_ENDL;
  2968. }
  2969. mMutedAVColor = LLColor4::grey5;
  2970. if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
  2971. {
  2972. mVisuallyMuteSetting = AV_RENDER_NORMALLY;
  2973. }
  2974. mCachedVisualMuteUpdateTime = gFrameTimeSeconds + 1.f;
  2975. }
  2976. //mk
  2977. }
  2978. // We cannot visually mute without impostors !
  2979. muted = muted && sUseImpostors;
  2980. mCachedVisualMute = muted;
  2981. //MK
  2982. muted |= mCachedRLVMute;
  2983. //mk
  2984. return muted;
  2985. }
  2986. void LLVOAvatar::updateFootstepSounds()
  2987. {
  2988. // Find the ground under each foot, these are used for a variety of things
  2989. // that follow
  2990. LLVector3 ankle_left_pos_agent = mFootLeftp->getWorldPosition();
  2991. LLVector3 ankle_right_pos_agent = mFootRightp->getWorldPosition();
  2992. LLVector3 ankle_left_ground_agent = ankle_left_pos_agent;
  2993. LLVector3 ankle_right_ground_agent = ankle_right_pos_agent;
  2994. LLVector3 normal;
  2995. resolveHeightAgent(ankle_left_pos_agent, ankle_left_ground_agent, normal);
  2996. resolveHeightAgent(ankle_right_pos_agent, ankle_right_ground_agent,
  2997. normal);
  2998. F32 left_elev = llmax(-0.2f,
  2999. ankle_left_pos_agent.mV[VZ] -
  3000. ankle_left_ground_agent.mV[VZ]);
  3001. F32 right_elev = llmax(-0.2f,
  3002. ankle_right_pos_agent.mV[VZ] -
  3003. ankle_right_ground_agent.mV[VZ]);
  3004. if (!mIsSitting)
  3005. {
  3006. // Figure out which foot is on ground
  3007. if (!mInAir && (left_elev < 0.f || right_elev < 0.f))
  3008. {
  3009. ankle_left_pos_agent = mFootLeftp->getWorldPosition();
  3010. ankle_right_pos_agent = mFootRightp->getWorldPosition();
  3011. left_elev = ankle_left_pos_agent.mV[VZ] -
  3012. ankle_left_ground_agent.mV[VZ];
  3013. right_elev = ankle_right_pos_agent.mV[VZ] -
  3014. ankle_right_ground_agent.mV[VZ];
  3015. }
  3016. }
  3017. static const LLUUID AGENT_FOOTSTEP_ANIMS[] =
  3018. {
  3019. ANIM_AGENT_WALK,
  3020. ANIM_AGENT_RUN,
  3021. ANIM_AGENT_LAND
  3022. };
  3023. constexpr S32 NUM_AGENT_FOOTSTEP_ANIMS =
  3024. LL_ARRAY_SIZE(AGENT_FOOTSTEP_ANIMS);
  3025. if (gAudiop &&
  3026. isAnyAnimationSignaled(AGENT_FOOTSTEP_ANIMS, NUM_AGENT_FOOTSTEP_ANIMS))
  3027. {
  3028. bool play_sound = false;
  3029. LLVector3 foot_pos_agent;
  3030. bool on_ground_left = left_elev <= 0.05f;
  3031. bool on_ground_right = right_elev <= 0.05f;
  3032. // Did left foot hit the ground ?
  3033. if (on_ground_left && !mWasOnGroundLeft)
  3034. {
  3035. foot_pos_agent = ankle_left_pos_agent;
  3036. play_sound = true;
  3037. }
  3038. // Did right foot hit the ground ?
  3039. if (on_ground_right && !mWasOnGroundRight)
  3040. {
  3041. foot_pos_agent = ankle_right_pos_agent;
  3042. play_sound = true;
  3043. }
  3044. mWasOnGroundLeft = on_ground_left;
  3045. mWasOnGroundRight = on_ground_right;
  3046. if (play_sound)
  3047. {
  3048. #if 0
  3049. F32 gain = clamp_rescale(mSpeedAccum,
  3050. AUDIO_STEP_LO_SPEED, AUDIO_STEP_HI_SPEED,
  3051. AUDIO_STEP_LO_GAIN, AUDIO_STEP_HI_GAIN);
  3052. #endif
  3053. LLVector3d foot_pos = gAgent.getPosGlobalFromAgent(foot_pos_agent);
  3054. if (gViewerParcelMgr.canHearSound(foot_pos) &&
  3055. (mCachedMuteFlags & LLMute::flagObjectSounds))
  3056. {
  3057. constexpr F32 STEP_VOLUME = 0.5f;
  3058. const LLUUID& step_sound_id = getStepSound();
  3059. gAudiop->triggerSound(step_sound_id, mID, STEP_VOLUME,
  3060. LLAudioEngine::AUDIO_TYPE_AMBIENT,
  3061. foot_pos);
  3062. }
  3063. }
  3064. }
  3065. }
  3066. void LLVOAvatar::computeUpdatePeriod(bool& visible)
  3067. {
  3068. if (isSelf() || isUIAvatar())
  3069. {
  3070. // Never change the update period (always 1) for self and UI avatars
  3071. return;
  3072. }
  3073. bool visually_muted = isVisuallyMuted();
  3074. if (visible && mDrawable.notNull() && useImpostors() &&
  3075. !mNeedsAnimUpdate)
  3076. {
  3077. const LLVector4a* ext = mDrawable->getSpatialExtents();
  3078. LLVector4a size;
  3079. size.setSub(ext[1], ext[0]);
  3080. F32 mag = size.getLength3().getF32() * 0.5f;
  3081. F32 impostor_area = 256.f * 512.f *
  3082. (8.125f - LLVOAvatar::sLODFactor * 8.f);
  3083. if (visually_muted
  3084. //MK
  3085. && !mCachedRLVMute)
  3086. //mk
  3087. {
  3088. // Muted avatars update REALLY slow
  3089. mUpdatePeriod = 16;
  3090. }
  3091. else if (mVisibilityRank <= getMaxNonImpostors() ||
  3092. mDrawable->mDistanceWRTCamera < 1.f + mag)
  3093. {
  3094. // Max visible avatars are not impostored. Also, do not impostor
  3095. // avatars whose bounding box may be penetrating the impostor
  3096. // camera near clip plane
  3097. mUpdatePeriod = 1;
  3098. visible = true;
  3099. return;
  3100. }
  3101. else if (mVisibilityRank > getMaxNonImpostors() * 4)
  3102. {
  3103. // Background avatars are REALLY slow updating impostors
  3104. mUpdatePeriod = 16;
  3105. }
  3106. else if (mVisibilityRank > getMaxNonImpostors() * 3)
  3107. {
  3108. // Back 25% of max visible avatars are slow updating impostors
  3109. mUpdatePeriod = 8;
  3110. }
  3111. else if (mImpostorPixelArea <= impostor_area)
  3112. {
  3113. // Stuff in between gets an update period based on pixel area
  3114. mUpdatePeriod = llclamp((S32)sqrtf(impostor_area * 4.f /
  3115. mImpostorPixelArea), 2, 8);
  3116. }
  3117. else
  3118. {
  3119. // Nearby avatars, update the impostors more frequently.
  3120. mUpdatePeriod = 4;
  3121. }
  3122. visible = (LLViewerOctreeEntryData::getCurrentFrame() +
  3123. mID.mData[0]) % mUpdatePeriod == 0;
  3124. }
  3125. else
  3126. {
  3127. mUpdatePeriod = 1;
  3128. }
  3129. }
  3130. void LLVOAvatar::updateTimeStep()
  3131. {
  3132. if (!isSelf() && !isUIAvatar())
  3133. {
  3134. F32 time_quantum = clamp_rescale((F32)sInstances.size(),
  3135. 10.f, 35.f, 0.f, 0.25f);
  3136. F32 pixel_area_scale = clamp_rescale(mPixelArea, 100, 5000, 1.f, 0.f);
  3137. F32 time_step = time_quantum * pixel_area_scale;
  3138. if (time_step != 0.f)
  3139. {
  3140. // Disable walk motion servo controller as it does not work with
  3141. // motion timesteps
  3142. stopMotion(ANIM_AGENT_WALK_ADJUST);
  3143. removeAnimationData("Walk Speed");
  3144. }
  3145. mMotionController.setTimeStep(time_step);
  3146. // We must take into account the slow down caused by any lowered update
  3147. // rate.
  3148. mMotionController.setTimeFactor((F32)mUpdatePeriod);
  3149. }
  3150. }
  3151. void LLVOAvatar::updateRootPositionAndRotation(F32 speed, bool sat_on_ground)
  3152. {
  3153. // This case includes all configurations except sitting on an object, so it
  3154. // does include ground sit.
  3155. if (!mIsSitting || !getParent())
  3156. {
  3157. // Get timing info. Handle initial condition case
  3158. F32 animation_time = mAnimTimer.getElapsedTimeF32();
  3159. if (mTimeLast <= 0.f)
  3160. {
  3161. mTimeLast = animation_time;
  3162. // Put the pelvis at slaved position/mRotation
  3163. mRoot->setWorldPosition(getPositionAgent()); // first frame
  3164. mRoot->setWorldRotation(getRotation());
  3165. }
  3166. // Do not let dT get larger than 1/5th of a second
  3167. F32 delta_time = animation_time - mTimeLast;
  3168. delta_time = llclamp(delta_time, DELTA_TIME_MIN, DELTA_TIME_MAX);
  3169. mTimeLast = animation_time;
  3170. mSpeedAccum = mSpeedAccum * 0.95f + speed * 0.05f;
  3171. // Compute the position of the avatar's root
  3172. bool is_self = isSelf();
  3173. if (is_self)
  3174. {
  3175. gAgent.setPositionAgent(getRenderPosition());
  3176. }
  3177. LLVector3d root_pos =
  3178. gAgent.getPosGlobalFromAgent(getRenderPosition());
  3179. #if 1 // LL's viewer counts twice the Z offset
  3180. static LLCachedControl<F32> factor(gSavedSettings,
  3181. "HoverToZOffsetFactor");
  3182. if (factor > 1.f)
  3183. {
  3184. // Hover should not be accounted here, because it already is in the
  3185. // avatar render position as sent by the server !!! HB
  3186. root_pos.mdV[VZ] += getVisualParamWeight(AVATAR_HOVER);
  3187. }
  3188. #endif
  3189. LLVector3 normal;
  3190. LLVector3d ground_under_pelvis;
  3191. resolveHeightGlobal(root_pos, ground_under_pelvis, normal);
  3192. F32 foot_to_ground = (F32)(root_pos.mdV[VZ] - mPelvisToFoot -
  3193. ground_under_pelvis.mdV[VZ]);
  3194. bool in_air = !gWorld.getRegionFromPosGlobal(ground_under_pelvis) ||
  3195. foot_to_ground > FOOT_GROUND_COLLISION_TOLERANCE;
  3196. if (in_air && !mInAir)
  3197. {
  3198. mTimeInAir.reset();
  3199. }
  3200. mInAir = in_air;
  3201. #if 0 // SL-427: this appears to be too frequent, moving to only do on
  3202. // animation state change.
  3203. computeBodySize();
  3204. #endif
  3205. // Correct for the fact that the pelvis is not necessarily the center
  3206. // of the agent's physical representation
  3207. root_pos.mdV[VZ] -= 0.5f * mBodySize.mV[VZ] - mPelvisToFoot;
  3208. if (!mIsSitting && !sat_on_ground)
  3209. {
  3210. root_pos += LLVector3d(getHoverOffset());
  3211. }
  3212. if (isPuppetAvatar())
  3213. {
  3214. ((LLVOAvatarPuppet*)this)->matchVolumeTransform();
  3215. return;
  3216. }
  3217. // Only for non-puppet av below this point
  3218. LLVector3 new_pos = gAgent.getPosAgentFromGlobal(root_pos);
  3219. if (new_pos != mRoot->getXform()->getWorldPosition())
  3220. {
  3221. mRoot->touch();
  3222. mRoot->setWorldPosition(new_pos); // regular update
  3223. }
  3224. // Propagate viewer object rotation to root of avatar
  3225. if (!isAnyAnimationSignaled(AGENT_NO_ROTATE_ANIMS,
  3226. NUM_AGENT_NO_ROTATE_ANIMS))
  3227. {
  3228. // Compute a forward direction vector derived from the primitive
  3229. // rotation and the velocity vector. When walking or jumping, do
  3230. // not let the body deviate more than 90 from the view; if
  3231. // necessary, flip the velocity vector.
  3232. LLVector3 prim_dir;
  3233. if (is_self)
  3234. {
  3235. prim_dir = gAgent.getAtAxis() -
  3236. projected_vec(gAgent.getAtAxis(),
  3237. gAgent.getReferenceUpVector());
  3238. prim_dir.normalize();
  3239. }
  3240. else
  3241. {
  3242. prim_dir = getRotation().getMatrix3().getFwdRow();
  3243. }
  3244. LLVector3 vel_dir = getVelocity();
  3245. vel_dir.normalize();
  3246. if (mSignaledAnimations.find(ANIM_AGENT_WALK) !=
  3247. mSignaledAnimations.end())
  3248. {
  3249. F32 vpD = vel_dir * prim_dir;
  3250. if (vpD < -0.5f)
  3251. {
  3252. vel_dir *= -1.f;
  3253. }
  3254. }
  3255. LLVector3 fwd_dir = lerp(prim_dir, vel_dir,
  3256. clamp_rescale(speed, 0.5f, 2.f, 0.f,
  3257. 1.f));
  3258. if (isSelf() && gAgent.cameraMouselook())
  3259. {
  3260. // Make sure fwd_dir stays in same general direction as primdir
  3261. if (gAgent.getFlying())
  3262. {
  3263. fwd_dir = gViewerCamera.getAtAxis();
  3264. }
  3265. else
  3266. {
  3267. LLVector3 at_axis = gViewerCamera.getAtAxis();
  3268. LLVector3 up_vector = gAgent.getReferenceUpVector();
  3269. at_axis -= up_vector * (at_axis * up_vector);
  3270. at_axis.normalize();
  3271. F32 dot = fwd_dir * at_axis;
  3272. if (dot < 0.f)
  3273. {
  3274. fwd_dir -= 2.f * at_axis * dot;
  3275. fwd_dir.normalize();
  3276. }
  3277. }
  3278. }
  3279. LLQuaternion root_rotation = mRoot->getWorldMatrix().quaternion();
  3280. F32 root_roll, root_pitch, root_yaw;
  3281. root_rotation.getEulerAngles(&root_roll, &root_pitch, &root_yaw);
  3282. // When moving very slow, the pelvis is allowed to deviate from the
  3283. // forward direction to allow it to hold its position while the
  3284. // torso and head turn. Once in motion, it must conform however.
  3285. bool self_in_mouselook = is_self && gAgent.cameraMouselook();
  3286. F32 pelvis_rot_thres_slow = PELVIS_ROT_THRESHOLD_SLOW;
  3287. if (is_self)
  3288. {
  3289. static LLCachedControl<bool> use_in_mouse_look(gSavedSettings,
  3290. "MouseLookUseRotDeviation");
  3291. static LLCachedControl<U32> max_rot_deviation(gSavedSettings,
  3292. "CameraToPelvisRotDeviation");
  3293. if (use_in_mouse_look || !self_in_mouselook)
  3294. {
  3295. pelvis_rot_thres_slow = llclamp((F32)max_rot_deviation,
  3296. PELVIS_ROT_THRESHOLD_FAST,
  3297. PELVIS_ROT_THRESHOLD_SLOW);
  3298. }
  3299. }
  3300. LLVector3 pelvis_dir(mRoot->getWorldMatrix().getFwdRow4().mV);
  3301. F32 pelvis_rot_thres = clamp_rescale(speed, 0.1f, 1.f,
  3302. pelvis_rot_thres_slow,
  3303. PELVIS_ROT_THRESHOLD_FAST);
  3304. if (self_in_mouselook)
  3305. {
  3306. pelvis_rot_thres *= MOUSELOOK_PELVIS_FOLLOW_FACTOR;
  3307. }
  3308. pelvis_rot_thres *= DEG_TO_RAD;
  3309. F32 angle = angle_between(pelvis_dir, fwd_dir);
  3310. // The avatar's root is allowed to have a yaw that deviates widely
  3311. // from the forward direction, but if roll or pitch are off even
  3312. // a little bit we need to correct the rotation.
  3313. if (root_roll < 1.f * DEG_TO_RAD && root_pitch < 5.f * DEG_TO_RAD)
  3314. {
  3315. // Smaller correction vector means pelvis follows prim direction
  3316. // more closely
  3317. if (!mTurning && angle > pelvis_rot_thres * 0.75f)
  3318. {
  3319. mTurning = true;
  3320. }
  3321. // Use tighter threshold when turning
  3322. if (mTurning)
  3323. {
  3324. pelvis_rot_thres *= 0.4f;
  3325. }
  3326. // Am I done turning ?
  3327. if (angle < pelvis_rot_thres)
  3328. {
  3329. mTurning = false;
  3330. }
  3331. LLVector3 correction_vector = (pelvis_dir - fwd_dir) *
  3332. clamp_rescale(angle,
  3333. pelvis_rot_thres *
  3334. 0.75f,
  3335. pelvis_rot_thres,
  3336. 1.f, 0.f);
  3337. fwd_dir += correction_vector;
  3338. }
  3339. else
  3340. {
  3341. mTurning = false;
  3342. }
  3343. // Now compute the full world space rotation for the whole body (wQv)
  3344. LLVector3 up_dir(0.f, 0.f, 1.f);
  3345. LLVector3 left_dir = up_dir % fwd_dir;
  3346. left_dir.normalize();
  3347. fwd_dir = left_dir % up_dir;
  3348. LLQuaternion wQv(fwd_dir, left_dir, up_dir);
  3349. if (is_self && mTurning)
  3350. {
  3351. if ((fwd_dir % pelvis_dir) * up_dir > 0.f)
  3352. {
  3353. gAgent.setControlFlags(AGENT_CONTROL_TURN_RIGHT);
  3354. }
  3355. else
  3356. {
  3357. gAgent.setControlFlags(AGENT_CONTROL_TURN_LEFT);
  3358. }
  3359. }
  3360. // Set the root rotation, but do so incrementally so that it lags
  3361. // in time by some fixed amount.
  3362. F32 pelvis_lag_time = 0.f;
  3363. if (self_in_mouselook)
  3364. {
  3365. pelvis_lag_time = PELVIS_LAG_MOUSELOOK;
  3366. }
  3367. else if (mInAir)
  3368. {
  3369. pelvis_lag_time = PELVIS_LAG_FLYING;
  3370. // increase pelvis lag time when moving slowly
  3371. pelvis_lag_time *= clamp_rescale(mSpeedAccum, 0.f, 15.f, 3.f,
  3372. 1.f);
  3373. }
  3374. else
  3375. {
  3376. pelvis_lag_time = PELVIS_LAG_WALKING;
  3377. }
  3378. F32 u = llclamp(delta_time / pelvis_lag_time, 0.f, 1.f);
  3379. mRoot->setWorldRotation(slerp(u, mRoot->getWorldRotation(), wQv));
  3380. }
  3381. }
  3382. else if (mDrawable.notNull())
  3383. {
  3384. LLVector3 pos = mDrawable->getPosition();
  3385. pos += getHoverOffset() * mDrawable->getRotation();
  3386. mRoot->setPosition(pos);
  3387. mRoot->setRotation(mDrawable->getRotation());
  3388. }
  3389. }
  3390. // Called on both your avatar and other avatars
  3391. bool LLVOAvatar::updateCharacter()
  3392. {
  3393. // Clear debug text
  3394. mDebugText.clear();
  3395. if (sShowAnimationDebug)
  3396. {
  3397. static const char* fmt_string1 = "%s P%d %.2fs";
  3398. static const char* fmt_string2 = "%s P%d";
  3399. static const char* bento_idle = "bento_idle";
  3400. std::string id_str;
  3401. const char* name;
  3402. for (LLMotionController::motion_list_t::iterator
  3403. iter = mMotionController.getActiveMotions().begin(),
  3404. end = mMotionController.getActiveMotions().end();
  3405. iter != end; ++iter)
  3406. {
  3407. LLMotion* motionp = *iter;
  3408. if (motionp && motionp->getMinPixelArea() < getPixelArea())
  3409. {
  3410. if (motionp->getName().empty())
  3411. {
  3412. const LLUUID& motion_id = motionp->getID();
  3413. if (motion_id == ANIM_AGENT_BENTO_IDLE)
  3414. {
  3415. name = bento_idle;
  3416. }
  3417. else
  3418. {
  3419. id_str = motion_id.asString();
  3420. name = id_str.c_str();
  3421. }
  3422. }
  3423. else
  3424. {
  3425. name = motionp->getName().c_str();
  3426. }
  3427. U32 priority = (U32)motionp->getPriority();
  3428. F32 duration = motionp->getDuration();
  3429. if (duration > 0.01f)
  3430. {
  3431. addDebugText(llformat(fmt_string1, name, priority,
  3432. duration));
  3433. }
  3434. else
  3435. {
  3436. addDebugText(llformat(fmt_string2, name, priority));
  3437. }
  3438. }
  3439. }
  3440. }
  3441. if (!mIsBuilt)
  3442. {
  3443. return false;
  3444. }
  3445. bool visible = isVisible();
  3446. // For fading out the names above heads, only let the timer run if we are
  3447. // visible.
  3448. if (mDrawable.notNull() && !visible)
  3449. {
  3450. mTimeVisible.reset();
  3451. }
  3452. // The rest should only be done occasionally for far away avatars
  3453. // Sets the new value for mUpdatePeriod based on distance and various other
  3454. // factors, also updates our (badly named: it deals with both actual
  3455. // visibility and need to update this frame) "visible" boolean.
  3456. computeUpdatePeriod(visible);
  3457. if (!isPuppetAvatar())
  3458. {
  3459. // Change animation time quanta based on avatar render load. Not
  3460. // for puppet avatars since it breaks their animations ! HB
  3461. updateTimeStep();
  3462. }
  3463. // Do not early out for your own avatar, as we rely on your animations
  3464. // playing reliably for example, the "turn around" animation when entering
  3465. // customize avatar needs to trigger even when your avatar is offscreen.
  3466. // IMPORTANT: this step must be taken *after* we changed the animation
  3467. // quanta (see above), else animations are played ridiculously fast for
  3468. // impostors ! HB
  3469. if (!visible && !isSelf())
  3470. {
  3471. updateMotions(LLCharacter::HIDDEN_UPDATE);
  3472. return false;
  3473. }
  3474. if (getParent())
  3475. {
  3476. if (!mIsSitting)
  3477. {
  3478. if (isSelf())
  3479. {
  3480. LL_DEBUGS("AgentSit") << "Sitting agent on parent" << LL_ENDL;
  3481. }
  3482. sitOnObject((LLViewerObject*)getParent());
  3483. }
  3484. }
  3485. else if (mIsSitting)
  3486. {
  3487. if (!isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED))
  3488. {
  3489. if (isSelf())
  3490. {
  3491. LL_DEBUGS("AgentSit") << "No parent and not sat on ground: unistting agent."
  3492. << LL_ENDL;
  3493. }
  3494. getOffObject();
  3495. }
  3496. }
  3497. // Create local variables in world coords for region position values
  3498. LLVector3 xy_vel = getVelocity();
  3499. xy_vel.mV[VZ] = 0.f;
  3500. F32 speed = xy_vel.length();
  3501. // Remembering the value here prevents a display glitch if the animation
  3502. // gets toggled during this update.
  3503. bool sat_on_ground = isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED);
  3504. // This does a bunch of state updating, including figuring out whether av
  3505. // is in the air, setting mRoot position and rotation.
  3506. updateRootPositionAndRotation(speed, sat_on_ground);
  3507. // Update character motions
  3508. // Store data relevant to motions
  3509. mSpeed = speed;
  3510. // Update animations
  3511. if (mSpecialRenderMode == 1) // Animation Preview
  3512. {
  3513. updateMotions(LLCharacter::FORCE_UPDATE);
  3514. }
  3515. else
  3516. {
  3517. updateMotions(LLCharacter::NORMAL_UPDATE);
  3518. }
  3519. // Special handling for sitting on ground.
  3520. if (!getParent() && (mIsSitting || sat_on_ground))
  3521. {
  3522. F32 off_z = LLVector3d(getHoverOffset()).mdV[VZ];
  3523. if (off_z != 0.f)
  3524. {
  3525. LLVector3 pos = mRoot->getWorldPosition();
  3526. pos.mV[VZ] += off_z;
  3527. mRoot->touch();
  3528. mRoot->setWorldPosition(pos);
  3529. }
  3530. }
  3531. // Update head position
  3532. updateHeadOffset();
  3533. if (!mIsDummy)
  3534. {
  3535. // Generates footstep sounds when feet hit the ground
  3536. updateFootstepSounds();
  3537. }
  3538. mRoot->updateWorldMatrixChildren();
  3539. if (!mDebugText.size() && mText.notNull())
  3540. {
  3541. mText->markDead();
  3542. mText = NULL;
  3543. }
  3544. else if (mDebugText.size())
  3545. {
  3546. setDebugText(mDebugText);
  3547. }
  3548. // Mesh vertices need to be reskinned
  3549. mNeedsSkin = true;
  3550. return true;
  3551. }
  3552. void LLVOAvatar::updateHeadOffset()
  3553. {
  3554. // Since we only care about Z, just grab one of the eyes
  3555. LLVector3 midEyePt = mEyeLeftp->getWorldPosition();
  3556. midEyePt -= mDrawable.notNull() ? mDrawable->getWorldPosition()
  3557. : mRoot->getWorldPosition();
  3558. midEyePt.mV[VZ] = llmax(-mPelvisToFoot + gViewerCamera.getNear(),
  3559. midEyePt.mV[VZ]);
  3560. if (mDrawable.notNull())
  3561. {
  3562. midEyePt = midEyePt * ~mDrawable->getWorldRotation();
  3563. }
  3564. if (mIsSitting)
  3565. {
  3566. mHeadOffset = midEyePt;
  3567. }
  3568. else
  3569. {
  3570. F32 u = llmax(0.f, HEAD_MOVEMENT_AVG_TIME - 1.f / gFPSClamped);
  3571. mHeadOffset = lerp(midEyePt, mHeadOffset, u);
  3572. }
  3573. }
  3574. void LLVOAvatar::postPelvisSetRecalc()
  3575. {
  3576. mRoot->updateWorldMatrixChildren();
  3577. computeBodySize();
  3578. dirtyMesh(2);
  3579. updateHeadOffset();
  3580. }
  3581. void LLVOAvatar::updateVisibility()
  3582. {
  3583. bool visible = false;
  3584. if (isUIAvatar())
  3585. {
  3586. visible = true;
  3587. }
  3588. else if (mDrawable.notNull())
  3589. {
  3590. visible = !mDrawable->getSpatialGroup() ||
  3591. mDrawable->getSpatialGroup()->isVisible();
  3592. if (isSelf())
  3593. {
  3594. if (!gAgentWearables.areWearablesLoaded())
  3595. {
  3596. visible = false;
  3597. }
  3598. }
  3599. else if (!mFirstAppearanceMessageReceived)
  3600. {
  3601. visible = false;
  3602. }
  3603. if (sDebugInvisible)
  3604. {
  3605. llinfos << "Updating visibility for avatar ";
  3606. std::string name = getFullname(true);
  3607. if (name.empty())
  3608. {
  3609. llcont << this;
  3610. }
  3611. else
  3612. {
  3613. llcont << name;
  3614. }
  3615. llcont << ": " << (visible ? "Visible" :"Not visible");
  3616. #if 0
  3617. if (avatar_in_frustum)
  3618. {
  3619. llcont << " - Avatar in frustum";
  3620. }
  3621. else
  3622. {
  3623. llcont << " - Avatar not in frustum";
  3624. }
  3625. if (gViewerCamera.sphereInFrustum(sel_pos_agent, 2.f))
  3626. {
  3627. llcont << " - Sel pos visible - SPA: " << sel_pos_agent;
  3628. }
  3629. if (gViewerCamera.sphereInFrustum(wrist_right_pos_agent, 0.2f))
  3630. {
  3631. llcont << " - Wrist pos visible - WPA: "
  3632. << wrist_right_pos_agent;
  3633. }
  3634. if (gViewerCamera.sphereInFrustum(getPositionAgent(),
  3635. getMaxScale() * 2.f))
  3636. {
  3637. llcont << " - Agent visible";
  3638. }
  3639. #endif
  3640. llcont << " - Agent position: " << getPositionAgent() << llendl;
  3641. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count;
  3642. ++i)
  3643. {
  3644. LLViewerJointAttachment* attachment = mAttachedObjectsVector[i].second;
  3645. if (!attachment) continue; // Paranoia
  3646. std::string name = LLTrans::getString(attachment->getName());
  3647. LLViewerObject* object = mAttachedObjectsVector[i].first;
  3648. if (object && object->mDrawable &&
  3649. object->mDrawable->isVisible())
  3650. {
  3651. llinfos << name << " visible" << llendl;
  3652. }
  3653. else
  3654. {
  3655. llinfos << name << " not visible at "
  3656. << mDrawable->getWorldPosition() << " and radius "
  3657. << mDrawable->getRadius() << llendl;
  3658. }
  3659. }
  3660. }
  3661. }
  3662. if (!visible && mVisible)
  3663. {
  3664. mMeshInvisibleTime.reset();
  3665. }
  3666. if (visible)
  3667. {
  3668. if (!mMeshValid)
  3669. {
  3670. restoreMeshData();
  3671. }
  3672. }
  3673. else
  3674. {
  3675. if (mMeshValid &&
  3676. (isPuppetAvatar() ||
  3677. mMeshInvisibleTime.getElapsedTimeF32() > TIME_BEFORE_MESH_CLEANUP))
  3678. {
  3679. releaseMeshData();
  3680. }
  3681. #if 0 // This breaks off-screen chat bubbles
  3682. deleteNameTag();
  3683. #endif
  3684. }
  3685. mVisible = visible;
  3686. }
  3687. bool LLVOAvatar::shouldAlphaMask()
  3688. {
  3689. // Do not alpha mask when highlight transparent textures.
  3690. return !LLDrawPoolAlpha::sShowDebugAlpha &&
  3691. !LLDrawPoolAvatar::sSkipTransparent;
  3692. }
  3693. U32 LLVOAvatar::renderSkinned()
  3694. {
  3695. U32 num_indices = 0;
  3696. if (!mIsBuilt || mDrawable.isNull())
  3697. {
  3698. return num_indices;
  3699. }
  3700. LLFace* facep = mDrawable->getFace(0);
  3701. bool needs_rebuild = !facep || !facep->getVertexBuffer() ||
  3702. mDrawable->isState(LLDrawable::REBUILD_GEOMETRY);
  3703. if (needs_rebuild || mDirtyMesh)
  3704. {
  3705. // LOD changed or new mesh created, allocate new vertex buffer if
  3706. // needed
  3707. if (needs_rebuild || mDirtyMesh >= 2 || mVisibilityRank <= 4)
  3708. {
  3709. updateMeshData();
  3710. mDirtyMesh = 0;
  3711. mNeedsSkin = true;
  3712. mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
  3713. }
  3714. }
  3715. if (gViewerShaderMgrp->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) <= 0)
  3716. {
  3717. if (mNeedsSkin)
  3718. {
  3719. // Generate animated mesh
  3720. LLViewerJoint* jointmeshp = getViewerJoint(MESH_ID_LOWER_BODY);
  3721. if (jointmeshp)
  3722. {
  3723. jointmeshp->updateJointGeometry();
  3724. }
  3725. jointmeshp = getViewerJoint(MESH_ID_UPPER_BODY);
  3726. if (jointmeshp)
  3727. {
  3728. jointmeshp->updateJointGeometry();
  3729. }
  3730. jointmeshp = getViewerJoint(MESH_ID_SKIRT);
  3731. if (jointmeshp && isWearingWearableType(LLWearableType::WT_SKIRT))
  3732. {
  3733. jointmeshp->updateJointGeometry();
  3734. }
  3735. if (!isSelf() || gAgent.needsRenderHead() ||
  3736. LLPipeline::sShadowRender)
  3737. {
  3738. jointmeshp = getViewerJoint(MESH_ID_EYELASH);
  3739. if (jointmeshp)
  3740. {
  3741. jointmeshp->updateJointGeometry();
  3742. }
  3743. jointmeshp = getViewerJoint(MESH_ID_HEAD);
  3744. if (jointmeshp)
  3745. {
  3746. jointmeshp->updateJointGeometry();
  3747. }
  3748. jointmeshp = getViewerJoint(MESH_ID_HAIR);
  3749. if (jointmeshp)
  3750. {
  3751. jointmeshp->updateJointGeometry();
  3752. }
  3753. }
  3754. mNeedsSkin = false;
  3755. mLastSkinTime = gFrameTimeSeconds;
  3756. facep = mDrawable->getFace(0);
  3757. if (facep)
  3758. {
  3759. LLVertexBuffer* vb = facep->getVertexBuffer();
  3760. if (vb)
  3761. {
  3762. vb->unmapBuffer();
  3763. }
  3764. }
  3765. }
  3766. }
  3767. else
  3768. {
  3769. mNeedsSkin = false;
  3770. }
  3771. if (sDebugInvisible)
  3772. {
  3773. llinfos << "Avatar ";
  3774. std::string name = getFullname(true);
  3775. if (name.empty())
  3776. {
  3777. llcont << this;
  3778. }
  3779. else
  3780. {
  3781. llcont << name;
  3782. }
  3783. llcont << " in render. ";
  3784. if (!mIsBuilt)
  3785. {
  3786. llcont << "Not built.";
  3787. }
  3788. else if (!gAgent.needsRenderAvatar())
  3789. {
  3790. llcont << "Does not need render.";
  3791. }
  3792. else
  3793. {
  3794. llcont << "Rendering.";
  3795. }
  3796. llcont << llendl;
  3797. }
  3798. if (!mIsBuilt)
  3799. {
  3800. return num_indices;
  3801. }
  3802. if (isSelf() && !gAgent.needsRenderAvatar())
  3803. {
  3804. return num_indices;
  3805. }
  3806. // Render all geometry attached to the skeleton
  3807. bool first_pass = true;
  3808. if (!LLDrawPoolAvatar::sSkipOpaque)
  3809. {
  3810. if (mIsDummy && isTextureVisible(TEX_HAIR_BAKED))
  3811. {
  3812. LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
  3813. if (hair_mesh)
  3814. {
  3815. num_indices += hair_mesh->render(mAdjustedPixelArea, true,
  3816. mIsDummy);
  3817. first_pass = false;
  3818. }
  3819. }
  3820. bool jelly_doll = isVisuallyMuted() || isUIAvatar();
  3821. if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
  3822. {
  3823. if (jelly_doll || isTextureVisible(TEX_HEAD_BAKED))
  3824. {
  3825. LLViewerJoint* head_mesh = getViewerJoint(MESH_ID_HEAD);
  3826. if (head_mesh)
  3827. {
  3828. num_indices += head_mesh->render(mAdjustedPixelArea,
  3829. first_pass, mIsDummy);
  3830. first_pass = false;
  3831. }
  3832. }
  3833. }
  3834. if (jelly_doll || isTextureVisible(TEX_UPPER_BAKED))
  3835. {
  3836. LLViewerJoint* upper_mesh = getViewerJoint(MESH_ID_UPPER_BODY);
  3837. if (upper_mesh)
  3838. {
  3839. num_indices += upper_mesh->render(mAdjustedPixelArea,
  3840. first_pass, mIsDummy);
  3841. first_pass = false;
  3842. }
  3843. }
  3844. if (jelly_doll || isTextureVisible(TEX_LOWER_BAKED))
  3845. {
  3846. LLViewerJoint* lower_mesh = getViewerJoint(MESH_ID_LOWER_BODY);
  3847. if (lower_mesh)
  3848. {
  3849. num_indices += lower_mesh->render(mAdjustedPixelArea,
  3850. first_pass, mIsDummy);
  3851. first_pass = false;
  3852. }
  3853. }
  3854. }
  3855. if (!LLDrawPoolAvatar::sSkipTransparent || LLPipeline::sImpostorRender)
  3856. {
  3857. LLGLState blend(GL_BLEND, mIsDummy ? GL_FALSE : GL_TRUE);
  3858. num_indices += renderTransparent(first_pass);
  3859. }
  3860. return num_indices;
  3861. }
  3862. U32 LLVOAvatar::renderTransparent(bool first_pass)
  3863. {
  3864. if (isPuppetAvatar())
  3865. {
  3866. return 0;
  3867. }
  3868. U32 num_indices = 0;
  3869. if (isWearingWearableType(LLWearableType::WT_SKIRT) &&
  3870. (isUIAvatar() || isTextureVisible(TEX_SKIRT_BAKED)))
  3871. {
  3872. LLViewerJoint* skirt_mesh = getViewerJoint(MESH_ID_SKIRT);
  3873. if (skirt_mesh)
  3874. {
  3875. gGL.flush();
  3876. num_indices += skirt_mesh->render(mAdjustedPixelArea, false);
  3877. gGL.flush();
  3878. first_pass = false;
  3879. }
  3880. }
  3881. if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
  3882. {
  3883. if (LLPipeline::sImpostorRender)
  3884. {
  3885. gGL.flush();
  3886. }
  3887. if (isTextureVisible(TEX_HEAD_BAKED))
  3888. {
  3889. LLViewerJoint* eyelash_mesh = getViewerJoint(MESH_ID_EYELASH);
  3890. if (eyelash_mesh)
  3891. {
  3892. num_indices += eyelash_mesh->render(mAdjustedPixelArea,
  3893. first_pass, mIsDummy);
  3894. first_pass = false;
  3895. }
  3896. }
  3897. // Cannot test for baked hair being defined, since that won't always be
  3898. // the case (not all viewers send baked hair)
  3899. // TODO: 1.25 will be able to switch this logic back to calling
  3900. // isTextureVisible()
  3901. if (LLDrawPoolAlpha::sShowDebugAlpha ||
  3902. (getImage(TEX_HAIR_BAKED, 0) &&
  3903. getImage(TEX_HAIR_BAKED, 0)->getID() != IMG_INVISIBLE))
  3904. {
  3905. LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
  3906. if (hair_mesh)
  3907. {
  3908. num_indices += hair_mesh->render(mAdjustedPixelArea,
  3909. first_pass, mIsDummy);
  3910. }
  3911. }
  3912. if (LLPipeline::sImpostorRender)
  3913. {
  3914. gGL.flush();
  3915. }
  3916. }
  3917. return num_indices;
  3918. }
  3919. U32 LLVOAvatar::renderRigid()
  3920. {
  3921. //MK
  3922. if (isSelf() && gRLenabled && gRLInterface.mVisionRestricted &&
  3923. !gRLInterface.mRenderLimitRenderedThisFrame &&
  3924. !LLPipeline::sRenderDeferred && isFullyLoaded())
  3925. {
  3926. LL_TRACY_TIMER(TRC_RLV_RENDER_LIMITS);
  3927. // Possibly draw a big black sphere around our avatar if the camera
  3928. // render is limited
  3929. gRLInterface.drawRenderLimit(false);
  3930. }
  3931. //mk
  3932. if (isSelf() && (!gAgent.needsRenderAvatar() || !gAgent.needsRenderHead()))
  3933. {
  3934. return 0;
  3935. }
  3936. if (!mIsBuilt)
  3937. {
  3938. return 0;
  3939. }
  3940. U32 num_indices = 0;
  3941. if (isTextureVisible(TEX_EYES_BAKED) || isUIAvatar())
  3942. {
  3943. LLViewerJoint* jointp = getViewerJoint(MESH_ID_EYEBALL_LEFT);
  3944. if (jointp)
  3945. {
  3946. num_indices += jointp->render(mAdjustedPixelArea, true, mIsDummy);
  3947. }
  3948. jointp = getViewerJoint(MESH_ID_EYEBALL_RIGHT);
  3949. if (jointp)
  3950. {
  3951. num_indices += jointp->render(mAdjustedPixelArea, true, mIsDummy);
  3952. }
  3953. }
  3954. return num_indices;
  3955. }
  3956. U32 LLVOAvatar::renderImpostor(LLColor4U color, S32 diffuse_channel)
  3957. {
  3958. if (!mImpostor.isComplete())
  3959. {
  3960. return 0;
  3961. }
  3962. LLVector3 pos(getRenderPosition() + mImpostorOffset);
  3963. LLVector3 at = pos - gViewerCamera.getOrigin();
  3964. at.normalize();
  3965. LLVector3 left = gViewerCamera.getUpAxis() % at;
  3966. LLVector3 up = at % left;
  3967. left *= mImpostorDim.mV[0];
  3968. up *= mImpostorDim.mV[1];
  3969. gGL.flush();
  3970. gGL.color4ubv(color.mV);
  3971. gGL.getTexUnit(diffuse_channel)->bind(&mImpostor);
  3972. gGL.begin(LLRender::TRIANGLES);
  3973. {
  3974. gGL.texCoord2f(0.f, 0.f);
  3975. gGL.vertex3fv((pos + left - up).mV);
  3976. gGL.texCoord2f(1.f, 0.f);
  3977. gGL.vertex3fv((pos - left - up).mV);
  3978. gGL.texCoord2f(1.f, 1.f);
  3979. gGL.vertex3fv((pos - left + up).mV);
  3980. gGL.texCoord2f(0.f, 0.f);
  3981. gGL.vertex3fv((pos + left - up).mV);
  3982. gGL.texCoord2f(1.f, 1.f);
  3983. gGL.vertex3fv((pos - left + up).mV);
  3984. gGL.texCoord2f(0.f, 1.f);
  3985. gGL.vertex3fv((pos + left + up).mV);
  3986. }
  3987. gGL.end(true);
  3988. return 6;
  3989. }
  3990. bool LLVOAvatar::allTexturesCompletelyDownloaded(uuid_list_t& ids) const
  3991. {
  3992. for (uuid_list_t::const_iterator it = ids.begin(), end = ids.end();
  3993. it != end; ++it)
  3994. {
  3995. LLViewerFetchedTexture* imagep = gTextureList.findImage(*it);
  3996. if (imagep && imagep->getDiscardLevel() != 0)
  3997. {
  3998. return false;
  3999. }
  4000. }
  4001. return true;
  4002. }
  4003. bool LLVOAvatar::allLocalTexturesCompletelyDownloaded() const
  4004. {
  4005. uuid_list_t local_ids;
  4006. collectLocalTextureUUIDs(local_ids);
  4007. return allTexturesCompletelyDownloaded(local_ids);
  4008. }
  4009. bool LLVOAvatar::allBakedTexturesCompletelyDownloaded() const
  4010. {
  4011. uuid_list_t baked_ids;
  4012. collectBakedTextureUUIDs(baked_ids);
  4013. return allTexturesCompletelyDownloaded(baked_ids);
  4014. }
  4015. void LLVOAvatar::bakedTextureOriginCounts(S32& sb_count, // server-bake, has origin URL.
  4016. S32& host_count, // host-based bake, has host.
  4017. S32& both_count, // error - both host and URL set.
  4018. S32& neither_count) // error - neither set.
  4019. {
  4020. sb_count = host_count = both_count = neither_count = 0;
  4021. uuid_list_t baked_ids;
  4022. collectBakedTextureUUIDs(baked_ids);
  4023. for (uuid_list_t::const_iterator it = baked_ids.begin(),
  4024. end = baked_ids.end();
  4025. it != end; ++it)
  4026. {
  4027. LLViewerFetchedTexture* imagep = gTextureList.findImage(*it);
  4028. if (!imagep) continue; // Paranoia
  4029. bool has_url = !imagep->getUrl().empty();
  4030. bool has_host = imagep->getTargetHost().isOk();
  4031. if (has_url && !has_host)
  4032. {
  4033. ++sb_count;
  4034. }
  4035. else if (has_host && !has_url)
  4036. {
  4037. ++host_count;
  4038. }
  4039. else if (has_host && has_url)
  4040. {
  4041. ++both_count;
  4042. }
  4043. else if (!has_host && !has_url)
  4044. {
  4045. ++neither_count;
  4046. }
  4047. }
  4048. }
  4049. void LLVOAvatar::collectLocalTextureUUIDs(uuid_list_t& ids) const
  4050. {
  4051. for (U32 i = 0, count = getNumTEs(); i < count; ++i)
  4052. {
  4053. LLWearableType::EType wearable_type =
  4054. LLAvatarAppearanceDictionary::getTEWearableType((ETextureIndex)i);
  4055. U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
  4056. for (U32 j = 0; j < num_wearables; ++j)
  4057. {
  4058. LLViewerFetchedTexture* texp =
  4059. LLViewerTextureManager::staticCast(getImage(i, j), true);
  4060. if (texp)
  4061. {
  4062. const LLUUID& id = texp->getID();
  4063. if (id != IMG_DEFAULT && id != IMG_DEFAULT_AVATAR &&
  4064. id != IMG_INVISIBLE)
  4065. {
  4066. const LLAvatarAppearanceDictionary::TextureEntry* dictp =
  4067. gAvatarAppDictp->getTexture((ETextureIndex)i);
  4068. if (dictp && dictp->mIsLocalTexture)
  4069. {
  4070. ids.emplace(id);
  4071. }
  4072. }
  4073. }
  4074. }
  4075. }
  4076. }
  4077. void LLVOAvatar::collectBakedTextureUUIDs(uuid_list_t& ids) const
  4078. {
  4079. for (U32 i = 0, count = getNumTEs(); i < count; ++i)
  4080. {
  4081. if (isIndexBakedTexture((ETextureIndex)i))
  4082. {
  4083. LLViewerFetchedTexture* texp =
  4084. LLViewerTextureManager::staticCast(getImage(i, 0), true);
  4085. if (texp)
  4086. {
  4087. const LLUUID& id = texp->getID();
  4088. if (id != IMG_DEFAULT && id != IMG_DEFAULT_AVATAR &&
  4089. id != IMG_INVISIBLE)
  4090. {
  4091. ids.emplace(id);
  4092. }
  4093. }
  4094. }
  4095. }
  4096. }
  4097. void LLVOAvatar::collectTextureUUIDs(uuid_list_t& ids)
  4098. {
  4099. collectLocalTextureUUIDs(ids);
  4100. collectBakedTextureUUIDs(ids);
  4101. }
  4102. void LLVOAvatar::releaseOldTextures()
  4103. {
  4104. LL_FAST_TIMER(FTM_AV_RELEASE_OLD_TEX);
  4105. // Any textures that we used to be using but are no longer using should no
  4106. // longer be flagged as "NO_DELETE"
  4107. uuid_list_t baked_texture_ids;
  4108. collectBakedTextureUUIDs(baked_texture_ids);
  4109. uuid_list_t local_texture_ids;
  4110. collectLocalTextureUUIDs(local_texture_ids);
  4111. uuid_list_t new_texture_ids;
  4112. new_texture_ids.insert(baked_texture_ids.begin(), baked_texture_ids.end());
  4113. new_texture_ids.insert(local_texture_ids.begin(), local_texture_ids.end());
  4114. for (uuid_list_t::iterator it = mTextureIDs.begin(),
  4115. end = mTextureIDs.end();
  4116. it != end; ++it)
  4117. {
  4118. if (new_texture_ids.count(*it))
  4119. {
  4120. LLViewerFetchedTexture* imagep = gTextureList.findImage(*it);
  4121. if (imagep)
  4122. {
  4123. if (imagep->getTextureState() == LLGLTexture::NO_DELETE)
  4124. {
  4125. // This will allow the texture to be deleted if not in use.
  4126. imagep->forceActive();
  4127. // This resets the clock to texture being flagged as
  4128. // unused, preventing the texture from being deleted
  4129. // immediately. If other avatars or objects are using it,
  4130. // it can still be flagged no-delete by them.
  4131. imagep->forceUpdateBindStats();
  4132. }
  4133. }
  4134. }
  4135. }
  4136. mTextureIDs = new_texture_ids;
  4137. }
  4138. void LLVOAvatar::updateTextures()
  4139. {
  4140. if (mIsDummy)
  4141. {
  4142. return;
  4143. }
  4144. bool render_avatar = true;
  4145. if (!isSelf())
  4146. {
  4147. if (!isVisible())
  4148. {
  4149. return;
  4150. }
  4151. render_avatar = !mCulled;
  4152. }
  4153. LL_FAST_TIMER(FTM_AV_UPDATE_TEXTURES);
  4154. LLTexUnit* unit0 = gGL.getTexUnit(0);
  4155. std::vector<bool> layer_baked;
  4156. bool is_editing_appearance = isSelf() && isUsingLocalAppearance();
  4157. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  4158. {
  4159. bool baked = !is_editing_appearance &&
  4160. isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
  4161. if (isSelf()) // There is no texture stats for non-self avatars
  4162. {
  4163. layer_baked.push_back(baked);
  4164. }
  4165. if (baked && render_avatar && !gGLManager.mIsDisabled &&
  4166. !mBakedTextureDatas[i].mIsLoaded)
  4167. {
  4168. // Bind the texture so that it will be decoded: slightly
  4169. // inefficient, we can short-circuit this if we have to.
  4170. unit0->bind(getImage(mBakedTextureDatas[i].mTextureIndex, 0));
  4171. }
  4172. }
  4173. mMaxPixelArea = 0.f;
  4174. mMinPixelArea = 99999999.f;
  4175. mHasGrey = false; // debug
  4176. for (U32 texture_index = 0, count = getNumTEs(); texture_index < count;
  4177. ++texture_index)
  4178. {
  4179. LLWearableType::EType wearable_type =
  4180. LLAvatarAppearanceDictionary::getTEWearableType((ETextureIndex)texture_index);
  4181. U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
  4182. const LLTextureEntry* te = getTE(texture_index);
  4183. const F32 texel_area_ratio = te ? fabs(te->getScaleS() * te->getScaleT())
  4184. : 1.f;
  4185. LLViewerFetchedTexture* imagep = NULL;
  4186. if (isSelf()) // There is no texture stats for non-self avatars
  4187. {
  4188. for (U32 wearable_index = 0; wearable_index < num_wearables;
  4189. ++wearable_index)
  4190. {
  4191. imagep =
  4192. LLViewerTextureManager::staticCast(getImage(texture_index,
  4193. wearable_index),
  4194. true);
  4195. if (!imagep) continue;
  4196. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  4197. gAvatarAppDictp->getTexture((ETextureIndex)texture_index);
  4198. if (!t_dict) continue;
  4199. // If the image for this texture layer is not fully loaded and
  4200. // we are editing our appearance, we must flag the visual hints
  4201. // for refresh. HB
  4202. if (is_editing_appearance && !imagep->isFullyLoaded())
  4203. {
  4204. LLVisualParamHint::requestHintUpdates();
  4205. }
  4206. if (!t_dict->mIsLocalTexture) continue;
  4207. const EBakedTextureIndex bt_idx = t_dict->mBakedTextureIndex;
  4208. addLocalTextureStats((ETextureIndex)texture_index, imagep,
  4209. texel_area_ratio, render_avatar,
  4210. layer_baked[bt_idx]);
  4211. }
  4212. }
  4213. if (isIndexBakedTexture((ETextureIndex)texture_index) && render_avatar)
  4214. {
  4215. imagep =
  4216. LLViewerTextureManager::staticCast(getImage(texture_index, 0),
  4217. true);
  4218. // Spam if this is a baked texture, not set to default image, without
  4219. // valid host info
  4220. if (isIndexBakedTexture((ETextureIndex)texture_index) &&
  4221. imagep->getID() != IMG_DEFAULT_AVATAR &&
  4222. imagep->getID() != IMG_INVISIBLE &&
  4223. !isUsingServerBakes() && !imagep->getTargetHost().isOk())
  4224. {
  4225. llwarns << "No host for texture " << imagep->getID()
  4226. << " for avatar "
  4227. << (isSelf() ? "<myself>" : getFullname(true))
  4228. << " on host " << getRegion()->getHost() << llendl;
  4229. }
  4230. addBakedTextureStats(imagep, mPixelArea, texel_area_ratio);
  4231. }
  4232. }
  4233. if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
  4234. {
  4235. setDebugText(llformat("%4.0f:%4.0f", sqrtf(mMinPixelArea),
  4236. sqrtf(mMaxPixelArea)));
  4237. }
  4238. }
  4239. void LLVOAvatar::addLocalTextureStats(ETextureIndex idx,
  4240. LLViewerFetchedTexture* imagep,
  4241. F32 texel_area_ratio,
  4242. bool render_avatar,
  4243. bool covered_by_baked)
  4244. {
  4245. // No local texture stats for non-self avatars
  4246. return;
  4247. }
  4248. // need to call updateTextures() at least every 32 frames:
  4249. constexpr S32 MAX_TEXTURE_UPDATE_INTERVAL = 64;
  4250. void LLVOAvatar::checkTextureLoading()
  4251. {
  4252. LL_FAST_TIMER(FTM_AV_CHECK_TEX_LOADING);
  4253. constexpr F32 MAX_INVISIBLE_WAITING_TIME = 15.f; // seconds
  4254. bool pause = !isVisible();
  4255. if (!pause)
  4256. {
  4257. mInvisibleTimer.reset();
  4258. }
  4259. if (mLoadedCallbacksPaused == pause)
  4260. {
  4261. return;
  4262. }
  4263. // When is self or no callbacks. Note: this list for self is always empty.
  4264. if (mCallbackTextureList.empty())
  4265. {
  4266. mLoadedCallbacksPaused = pause;
  4267. return; // Nothing to check.
  4268. }
  4269. if (pause &&
  4270. mInvisibleTimer.getElapsedTimeF32() < MAX_INVISIBLE_WAITING_TIME)
  4271. {
  4272. return; // Have not been invisible for enough time.
  4273. }
  4274. for (uuid_list_t::iterator iter = mCallbackTextureList.begin(),
  4275. end = mCallbackTextureList.end();
  4276. iter != end; ++iter)
  4277. {
  4278. LLViewerFetchedTexture* tex = gTextureList.findImage(*iter);
  4279. if (tex)
  4280. {
  4281. if (pause)
  4282. { // Pause texture fetching.
  4283. tex->pauseLoadedCallbacks(&mCallbackTextureList);
  4284. // Set to terminate texture fetching after
  4285. // MAX_TEXTURE_UPDATE_INTERVAL frames.
  4286. tex->setMaxVirtualSizeResetInterval(MAX_TEXTURE_UPDATE_INTERVAL);
  4287. tex->resetMaxVirtualSizeResetCounter();
  4288. }
  4289. else // Unpause
  4290. {
  4291. tex->unpauseLoadedCallbacks(&mCallbackTextureList);
  4292. // Jump start the fetching again
  4293. constexpr F32 START_AREA = 100.f;
  4294. tex->addTextureStats(START_AREA);
  4295. }
  4296. }
  4297. }
  4298. if (!pause)
  4299. {
  4300. releaseOldTextures();
  4301. updateTextures(); // Refresh texture stats.
  4302. }
  4303. mLoadedCallbacksPaused = pause;
  4304. }
  4305. void LLVOAvatar::addBakedTextureStats(LLViewerFetchedTexture* imagep,
  4306. F32 pixel_area,
  4307. F32 texel_area_ratio)
  4308. {
  4309. imagep->resetTextureStats();
  4310. imagep->setMaxVirtualSizeResetInterval(S32_MAX);
  4311. imagep->resetMaxVirtualSizeResetCounter();
  4312. mMaxPixelArea = llmax(pixel_area, mMaxPixelArea);
  4313. mMinPixelArea = llmin(pixel_area, mMinPixelArea);
  4314. imagep->addTextureStats(pixel_area / texel_area_ratio);
  4315. S32 boost_level;
  4316. F32 added_prio;
  4317. if (isSelf())
  4318. {
  4319. boost_level = LLGLTexture::BOOST_AVATAR_SELF;
  4320. added_prio = SELF_ADDITIONAL_PRI;
  4321. #if !LL_IMPLICIT_SETNODELETE
  4322. imagep->setNoDelete();
  4323. #endif
  4324. }
  4325. else
  4326. {
  4327. boost_level = LLGLTexture::BOOST_AVATAR;
  4328. added_prio = ADDITIONAL_PRI;
  4329. }
  4330. imagep->setAdditionalDecodePriority(added_prio);
  4331. imagep->setBoostLevel(boost_level);
  4332. }
  4333. //virtual
  4334. void LLVOAvatar::setImage(U8 te, LLViewerTexture* imagep, U32 index)
  4335. {
  4336. setTEImage(te, imagep);
  4337. }
  4338. //virtual
  4339. LLViewerTexture* LLVOAvatar::getImage(U8 te, U32) const
  4340. {
  4341. return getTEImage(te);
  4342. }
  4343. std::string LLVOAvatar::getImageURL(U8 te, const LLUUID& id)
  4344. {
  4345. llassert(isIndexBakedTexture(ETextureIndex(te)));
  4346. std::string url;
  4347. if (isUsingServerBakes())
  4348. {
  4349. if (sAgentAppearanceServiceURL.empty())
  4350. {
  4351. // Probably a server-side issue if we get here:
  4352. llwarns << "AgentAppearanceServiceURL not set - Baked texture requests will fail"
  4353. << llendl;
  4354. }
  4355. else
  4356. {
  4357. const LLAvatarAppearanceDictionary::TextureEntry* tep =
  4358. gAvatarAppDictp->getTexture((ETextureIndex)te);
  4359. if (tep && id.notNull())
  4360. {
  4361. url = sAgentAppearanceServiceURL + "texture/" +
  4362. mID.asString() + "/" + tep->mDefaultImageName + "/" +
  4363. id.asString();
  4364. LL_DEBUGS("Avatar") << "Baked texture url: " << url << LL_ENDL;
  4365. }
  4366. }
  4367. }
  4368. return url;
  4369. }
  4370. void LLVOAvatar::resolveHeightAgent(const LLVector3& in_pos_agent,
  4371. LLVector3& out_pos_agent,
  4372. LLVector3& out_norm)
  4373. {
  4374. LLVector3d in_pos_global, out_pos_global;
  4375. in_pos_global = gAgent.getPosGlobalFromAgent(in_pos_agent);
  4376. resolveHeightGlobal(in_pos_global, out_pos_global, out_norm);
  4377. out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
  4378. }
  4379. void LLVOAvatar::resolveRayCollisionAgent(const LLVector3d start_pt,
  4380. const LLVector3d end_pt,
  4381. LLVector3d& out_pos,
  4382. LLVector3& out_norm)
  4383. {
  4384. LLViewerObject* obj;
  4385. gWorld.resolveStepHeightGlobal(this, start_pt, end_pt, out_pos, out_norm,
  4386. &obj);
  4387. }
  4388. void LLVOAvatar::resolveHeightGlobal(const LLVector3d& in_pos,
  4389. LLVector3d& out_pos,
  4390. LLVector3& out_norm)
  4391. {
  4392. const LLVector3d z_vec(0.f, 0.f, 0.5f);
  4393. LLVector3d p0 = in_pos + z_vec;
  4394. LLVector3d p1 = in_pos - z_vec;
  4395. LLViewerObject* obj;
  4396. gWorld.resolveStepHeightGlobal(this, p0, p1, out_pos, out_norm, &obj);
  4397. if (!obj)
  4398. {
  4399. mStepOnLand = true;
  4400. mStepMaterial = 0;
  4401. mStepObjectVelocity.set(0.f, 0.f, 0.f);
  4402. }
  4403. else
  4404. {
  4405. mStepOnLand = false;
  4406. mStepMaterial = obj->getMaterial();
  4407. // We want the primitive velocity, not our velocity (which actually
  4408. // subtracts the step object velocity)...
  4409. LLVector3 angularVelocity = obj->getAngularVelocity();
  4410. LLVector3 relativePos = gAgent.getPosAgentFromGlobal(out_pos) -
  4411. obj->getPositionAgent();
  4412. LLVector3 linearComponent = angularVelocity % relativePos;
  4413. mStepObjectVelocity = obj->getVelocity() + linearComponent;
  4414. }
  4415. }
  4416. const LLUUID& LLVOAvatar::getStepSound() const
  4417. {
  4418. if (gIsInSecondLife)
  4419. {
  4420. return mStepOnLand ? sStepSoundOnLand : sStepSounds[mStepMaterial];
  4421. }
  4422. // Just one collision sound available in OpenSIM...
  4423. return SND_OPENSIM_COLLISION;
  4424. }
  4425. void LLVOAvatar::processAnimationStateChanges()
  4426. {
  4427. // *BUG ? AGENT_WALK_ANIMS does not contains the new walk/run anims
  4428. // neither the female walk anim: is this normal ? HB
  4429. if (isAnyAnimationSignaled(AGENT_WALK_ANIMS, NUM_AGENT_WALK_ANIMS))
  4430. {
  4431. // Do not perform adjustments on dummy/puppets; this would break the
  4432. // walk anims ! HB
  4433. if (mEnableDefaultMotions)
  4434. {
  4435. startMotion(ANIM_AGENT_WALK_ADJUST);
  4436. }
  4437. stopMotion(ANIM_AGENT_FLY_ADJUST);
  4438. }
  4439. else if (mInAir && !mIsSitting)
  4440. {
  4441. stopMotion(ANIM_AGENT_WALK_ADJUST);
  4442. if (mEnableDefaultMotions)
  4443. {
  4444. startMotion(ANIM_AGENT_FLY_ADJUST);
  4445. }
  4446. }
  4447. else
  4448. {
  4449. stopMotion(ANIM_AGENT_WALK_ADJUST);
  4450. stopMotion(ANIM_AGENT_FLY_ADJUST);
  4451. }
  4452. if (isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS))
  4453. {
  4454. if (mEnableDefaultMotions)
  4455. {
  4456. startMotion(ANIM_AGENT_TARGET);
  4457. }
  4458. stopMotion(ANIM_AGENT_BODY_NOISE);
  4459. }
  4460. else
  4461. {
  4462. stopMotion(ANIM_AGENT_TARGET);
  4463. if (mEnableDefaultMotions)
  4464. {
  4465. startMotion(ANIM_AGENT_BODY_NOISE);
  4466. }
  4467. }
  4468. anim_it_t end_signaled_anims = mSignaledAnimations.end();
  4469. // Clear all current animations
  4470. for (anim_it_t it = mPlayingAnimations.begin(),
  4471. end = mPlayingAnimations.end();
  4472. it != end; )
  4473. {
  4474. const LLUUID& id = it->first;
  4475. anim_it_t found_anim = mSignaledAnimations.find(id);
  4476. // Playing, but not signaled, so stop
  4477. if (found_anim == end_signaled_anims)
  4478. {
  4479. processSingleAnimationStateChange(id, false);
  4480. mPlayingAnimations.erase(it++);
  4481. }
  4482. else
  4483. {
  4484. ++it;
  4485. }
  4486. }
  4487. // Start up all new anims
  4488. for (anim_it_t it = mSignaledAnimations.begin(); it != end_signaled_anims;
  4489. ++it)
  4490. {
  4491. const LLUUID& id = it->first;
  4492. anim_it_t found_anim = mPlayingAnimations.find(id);
  4493. // Signaled but not playing, or different sequence id, start motion
  4494. if (found_anim == mPlayingAnimations.end() ||
  4495. found_anim->second != it->second)
  4496. {
  4497. if (processSingleAnimationStateChange(id, true))
  4498. {
  4499. mPlayingAnimations[id] = it->second;
  4500. }
  4501. }
  4502. }
  4503. // Clear source information for animations which have been stopped
  4504. if (isSelf())
  4505. {
  4506. for (anim_src_map_it_t it = mAnimationSources.begin(),
  4507. end = mAnimationSources.end();
  4508. it != end; )
  4509. {
  4510. if (mSignaledAnimations.find(it->second) == end_signaled_anims)
  4511. {
  4512. mAnimationSources.erase(it++);
  4513. }
  4514. else
  4515. {
  4516. ++it;
  4517. }
  4518. }
  4519. }
  4520. }
  4521. bool LLVOAvatar::processSingleAnimationStateChange(const LLUUID& anim_id,
  4522. bool start)
  4523. {
  4524. if (anim_id.isNull())
  4525. {
  4526. // Happens for hand animations (Bento mesh avatar with hand joints and
  4527. // no hands anim defined ?). Just abort.
  4528. return false;
  4529. }
  4530. // Keep track of bad assets, to avoid repeated "Failed to start motion"
  4531. // warnings for them. HB
  4532. static uuid_list_t bad_motions;
  4533. if (!isSelf() && bad_motions.count(anim_id))
  4534. {
  4535. return false;
  4536. }
  4537. // SL-402: with the ability to animate the position of joints that affect
  4538. // the body size calculation, computed body size can get stale much more
  4539. // easily. Simplest fix is to update it frequently.
  4540. computeBodySize();
  4541. if (!start) // Stop animation
  4542. {
  4543. if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
  4544. {
  4545. mIsSitting = false;
  4546. //MK
  4547. if (gRLenabled && isSelf())
  4548. {
  4549. if (gRLInterface.mContainsUnsit)
  4550. {
  4551. gRLInterface.notify("unsat ground illegally");
  4552. }
  4553. else
  4554. {
  4555. gRLInterface.notify("unsat ground legally");
  4556. }
  4557. }
  4558. //mk
  4559. }
  4560. stopMotion(anim_id);
  4561. return true;
  4562. }
  4563. if (anim_id == ANIM_AGENT_TYPE)
  4564. {
  4565. if (gAudiop && gSavedSettings.getBool("UISndTypingEnable"))
  4566. {
  4567. LLVector3d char_pos_global =
  4568. gAgent.getPosGlobalFromAgent(getCharacterPosition());
  4569. if (gViewerParcelMgr.canHearSound(char_pos_global) &&
  4570. (mCachedMuteFlags & LLMute::flagObjectSounds))
  4571. {
  4572. LLUUID sound_id =
  4573. LLUUID(gSavedSettings.getString("UISndTyping"));
  4574. #if 0 // RN: enable this to play on typing sound at fixed volume
  4575. // once sound engine is fixed to support both spatialized and
  4576. // non-spatialized instances of the same sound
  4577. if (isSelf())
  4578. {
  4579. gAudiop->triggerSound(sound_id, 1.f,
  4580. LLAudioEngine::AUDIO_TYPE_UI);
  4581. }
  4582. else
  4583. #endif
  4584. {
  4585. gAudiop->triggerSound(sound_id, mID, 1.f,
  4586. LLAudioEngine::AUDIO_TYPE_SFX,
  4587. char_pos_global);
  4588. }
  4589. }
  4590. }
  4591. }
  4592. else if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
  4593. {
  4594. mIsSitting = true;
  4595. //MK
  4596. if (gRLenabled && isSelf())
  4597. {
  4598. gRLInterface.notify("sat ground legally");
  4599. }
  4600. //mk
  4601. }
  4602. if (startMotion(anim_id))
  4603. {
  4604. return true;
  4605. }
  4606. llwarns << "Failed to start motion: " << anim_id << llendl;
  4607. // If it was supposed to play on our avatar, send a stop request to the
  4608. // server to inform surrounding avatars and scripts we do not play that
  4609. // bogus animation.
  4610. if (isSelf())
  4611. {
  4612. llinfos << "Sending ANIM_REQUEST_STOP for motion: " << anim_id
  4613. << llendl;
  4614. gAgent.sendAnimationRequest(anim_id, ANIM_REQUEST_STOP);
  4615. }
  4616. else
  4617. {
  4618. bad_motions.emplace(anim_id);
  4619. }
  4620. return false;
  4621. }
  4622. bool LLVOAvatar::isAnyAnimationSignaled(const LLUUID* anim_array,
  4623. S32 num_anims) const
  4624. {
  4625. anim_map_t::const_iterator end_signaled_anims = mSignaledAnimations.end();
  4626. for (S32 i = 0; i < num_anims; ++i)
  4627. {
  4628. const LLUUID& id = anim_array[i];
  4629. if (mSignaledAnimations.find(id) != end_signaled_anims)
  4630. {
  4631. return true;
  4632. }
  4633. }
  4634. return false;
  4635. }
  4636. void LLVOAvatar::resetAnimations()
  4637. {
  4638. LLKeyframeMotion::flushKeyframeCache();
  4639. flushAllMotions();
  4640. }
  4641. LLUUID LLVOAvatar::remapMotionID(const LLUUID& id)
  4642. {
  4643. if (mIsDummy)
  4644. {
  4645. // Do not remap animations for dummy avatars or puppets. HB
  4646. return id;
  4647. }
  4648. static LLCachedControl<bool> use_new_anims(gSavedSettings,
  4649. "UseNewWalkRun");
  4650. // Female anims for female avatars
  4651. if (getSex() == SEX_FEMALE)
  4652. {
  4653. if (id == ANIM_AGENT_WALK)
  4654. {
  4655. return use_new_anims ? ANIM_AGENT_FEMALE_WALK_NEW
  4656. : ANIM_AGENT_FEMALE_WALK;
  4657. }
  4658. if (id == ANIM_AGENT_RUN)
  4659. {
  4660. return use_new_anims ? ANIM_AGENT_FEMALE_RUN_NEW : ANIM_AGENT_RUN;
  4661. }
  4662. if (id == ANIM_AGENT_SIT)
  4663. {
  4664. return ANIM_AGENT_SIT_FEMALE;
  4665. }
  4666. }
  4667. // Male avatar below this line.
  4668. else if (id == ANIM_AGENT_SIT_FEMALE)
  4669. {
  4670. // Keep in sync with setSex() related code (viewer controls sit's sex)
  4671. return ANIM_AGENT_SIT;
  4672. }
  4673. else if (use_new_anims)
  4674. {
  4675. if (id == ANIM_AGENT_WALK)
  4676. {
  4677. return ANIM_AGENT_WALK_NEW;
  4678. }
  4679. if (id == ANIM_AGENT_RUN)
  4680. {
  4681. return ANIM_AGENT_RUN_NEW;
  4682. }
  4683. }
  4684. return id; // No change
  4685. }
  4686. // 'id' is the asset if of the animation to start, 'time_offset' is the offset
  4687. // into the animation at which to start playing
  4688. bool LLVOAvatar::startMotion(const LLUUID& id, F32 time_offset)
  4689. {
  4690. LLUUID remap_id = remapMotionID(id);
  4691. LL_DEBUGS("Animation") << "Motion requested: "
  4692. << gAnimLibrary.animationName(id);
  4693. if (id != remap_id)
  4694. {
  4695. LL_CONT << " - Remapped as: " << gAnimLibrary.animationName(remap_id);
  4696. }
  4697. LL_CONT << LL_ENDL;
  4698. if (isSelf() && remap_id == ANIM_AGENT_AWAY)
  4699. {
  4700. gAgent.setAFK();
  4701. }
  4702. return LLCharacter::startMotion(remap_id, time_offset);
  4703. }
  4704. bool LLVOAvatar::stopMotion(const LLUUID& id, bool stop_immediate)
  4705. {
  4706. LLUUID remap_id = remapMotionID(id);
  4707. LL_DEBUGS("Animation") << "Motion requested: "
  4708. << gAnimLibrary.animationName(id);
  4709. if (id != remap_id)
  4710. {
  4711. LL_CONT << " - Remapped as: " << gAnimLibrary.animationName(remap_id);
  4712. }
  4713. LL_CONT << LL_ENDL;
  4714. if (isSelf())
  4715. {
  4716. gAgent.onAnimStop(remap_id);
  4717. }
  4718. return LLCharacter::stopMotion(remap_id, stop_immediate);
  4719. }
  4720. void LLVOAvatar::addDebugText(const std::string& text)
  4721. {
  4722. mDebugText.append(1, '\n');
  4723. mDebugText.append(text);
  4724. }
  4725. // RN: avatar joints are multi-rooted to include screen-based attachments
  4726. LLJoint* LLVOAvatar::getJoint(U32 key)
  4727. {
  4728. LLJoint* jointp = NULL;
  4729. joint_map_t::iterator iter = mJointMap.find(key);
  4730. if (iter == mJointMap.end() || iter->second == NULL)
  4731. {
  4732. // Search for joint and cache it in lookup table
  4733. jointp = mRoot->findJoint(key);
  4734. mJointMap[key] = jointp;
  4735. }
  4736. else
  4737. {
  4738. // Return cached pointer
  4739. jointp = iter->second;
  4740. }
  4741. return jointp;
  4742. }
  4743. LLVOAvatar::rtf_cache_it_t LLVOAvatar::initRiggedMatrixCache(const LLMeshSkinInfo* skin,
  4744. U32& count)
  4745. {
  4746. LL_TRACY_TIMER(TRC_RIGGED_MATRIX);
  4747. const LLUUID& mesh_id = skin->mMeshID;
  4748. rtf_cache_it_t iter = mRiggedMatrixDataCache.find(mesh_id);
  4749. if (iter == mRiggedMatrixDataCache.end())
  4750. {
  4751. // No entry: create a new one for that mesh.
  4752. iter = mRiggedMatrixDataCache.emplace(mesh_id, new RiggedMatrix).first;
  4753. }
  4754. else if (iter->second.isNull())
  4755. {
  4756. // NULL entry (should not happen): affect a new one to that mesh.
  4757. llwarns << "NULL entry in cache for mesh " << mesh_id << llendl;
  4758. iter->second = new RiggedMatrix;
  4759. }
  4760. else if (iter->second->mFrameNumber == gFrameCount &&
  4761. !isEditingAppearance())
  4762. {
  4763. // Entry exists and is still valid, so return its data at once
  4764. count = iter->second->mCount;
  4765. return iter;
  4766. }
  4767. LLPointer<RiggedMatrix>& rigmatp = iter->second;
  4768. // Stamp the cache entry with the current frame number
  4769. rigmatp->mFrameNumber = gFrameCount;
  4770. // Fill-up the matrix
  4771. LLMatrix4a* mat = rigmatp->mMatrix4a;
  4772. count = rigmatp->mCount =
  4773. LLSkinningUtil::initSkinningMatrixPalette(mat, skin, this);
  4774. F32* mp = rigmatp->mMatrix;
  4775. #ifdef __AVX2__
  4776. // Kathrine Jansma's AVX2 optimized code
  4777. // Offsets to copy
  4778. U32 idx = 0;
  4779. __m256i vindex_low = _mm256_setr_epi32(0, 1, 2, 12, 4, 5, 6, 13);
  4780. __m256i vindex_high = _mm256_setr_epi32(8, 9, 10, 14, 8, 8, 8, 8);
  4781. // We only need 128 bit, so mask out the rest
  4782. __m256i high_mask = _mm256_set_epi32(0, 0, 0, 0, -1, -1, -1, -1);
  4783. for (U32 i = 0; i < count; ++i)
  4784. {
  4785. const F32* m = mat[i].mMatrix[0].getF32ptr();
  4786. _mm256_storeu_ps(mp + idx,
  4787. _mm256_i32gather_ps(m, vindex_low, 4));
  4788. _mm256_maskstore_ps(mp + idx + 8, high_mask,
  4789. _mm256_i32gather_ps(m, vindex_high, 4));
  4790. idx += 12;
  4791. }
  4792. #else
  4793. for (U32 i = 0; i < count; ++i)
  4794. {
  4795. const F32* m = mat[i].mMatrix[0].getF32ptr();
  4796. *mp++ = m[0];
  4797. *mp++ = m[1];
  4798. *mp++ = m[2];
  4799. *mp++ = m[12];
  4800. *mp++ = m[4];
  4801. *mp++ = m[5];
  4802. *mp++ = m[6];
  4803. *mp++ = m[13];
  4804. *mp++ = m[8];
  4805. *mp++ = m[9];
  4806. *mp++ = m[10];
  4807. *mp++ = m[14];
  4808. }
  4809. #endif
  4810. return iter;
  4811. }
  4812. const F32* LLVOAvatar::getRiggedMatrix(const LLMeshSkinInfo* skin, U32& count)
  4813. {
  4814. return initRiggedMatrixCache(skin, count)->second->mMatrix;
  4815. }
  4816. const LLMatrix4a* LLVOAvatar::getRiggedMatrix4a(const LLMeshSkinInfo* skin,
  4817. U32& count)
  4818. {
  4819. return initRiggedMatrixCache(skin, count)->second->mMatrix4a;
  4820. }
  4821. // If viewer object is a rigged mesh, set the mesh id and return true.
  4822. // Otherwise, null out the id and return false.
  4823. //static
  4824. bool LLVOAvatar::getRiggedMeshID(LLViewerObject* vobj, LLUUID& mesh_id)
  4825. {
  4826. mesh_id.setNull();
  4827. // If a VO has a skin that we will reset the joint positions to their
  4828. // default
  4829. if (vobj && vobj->mDrawable)
  4830. {
  4831. LLVOVolume* vvo = vobj->mDrawable->getVOVolume();
  4832. if (vvo)
  4833. {
  4834. const LLMeshSkinInfo* skindatap = vvo->getSkinInfo();
  4835. if (skindatap &&
  4836. skindatap->mJointKeys.size() > JOINT_COUNT_REQUIRED_FOR_FULLRIG &&
  4837. !skindatap->mAlternateBindMatrix.empty())
  4838. {
  4839. mesh_id = skindatap->mMeshID;
  4840. return true;
  4841. }
  4842. }
  4843. }
  4844. return false;
  4845. }
  4846. bool LLVOAvatar::jointIsRiggedTo(U32 joint_key)
  4847. {
  4848. // Note: joint key 0 = "unnamed", 1 = "mScreen" (so we skip them)
  4849. return joint_key > 1 && joint_key - 2 < mJointRiggingInfoTab.size() &&
  4850. mJointRiggingInfoTab[joint_key - 2].isRiggedTo();
  4851. }
  4852. void LLVOAvatar::clearAttachmentOverrides()
  4853. {
  4854. // Note: joint key 0 = "unnamed", 1 = "mScreen" (so we skip them)
  4855. for (U32 i = 2; i <= LL_CHARACTER_MAX_ANIMATED_JOINTS; ++i)
  4856. {
  4857. LLJoint* jointp = getJoint(i);
  4858. if (jointp)
  4859. {
  4860. jointp->clearAttachmentPosOverrides();
  4861. jointp->clearAttachmentScaleOverrides();
  4862. }
  4863. }
  4864. if (mPelvisFixups.count())
  4865. {
  4866. mPelvisFixups.clear();
  4867. if (mPelvisp)
  4868. {
  4869. mPelvisp->setPosition(LLVector3::zero);
  4870. }
  4871. postPelvisSetRecalc();
  4872. }
  4873. mActiveOverrideMeshes.clear();
  4874. mJointRiggingInfoTab.setNeedsUpdate();
  4875. }
  4876. void LLVOAvatar::rebuildAttachmentOverrides()
  4877. {
  4878. clearAttachmentOverrides();
  4879. // Handle the case that we are resetting the skeleton of an animated object
  4880. if (isPuppetAvatar())
  4881. {
  4882. LLVOVolume* volp = ((LLVOAvatarPuppet*)this)->mRootVolp;
  4883. if (volp)
  4884. {
  4885. addAttachmentOverridesForObject(volp);
  4886. }
  4887. }
  4888. // Attached objects
  4889. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  4890. {
  4891. LLViewerObject* object = mAttachedObjectsVector[i].first;
  4892. // Attached animated objects affect joints in their puppet, not the
  4893. // avatar to which they are attached.
  4894. if (object && !object->isAnimatedObject())
  4895. {
  4896. addAttachmentOverridesForObject(object);
  4897. }
  4898. }
  4899. }
  4900. void LLVOAvatar::updateAttachmentOverrides()
  4901. {
  4902. uuid_list_t meshes_seen;
  4903. if (isPuppetAvatar())
  4904. {
  4905. LLVOVolume* volp = ((LLVOAvatarPuppet*)this)->mRootVolp;
  4906. if (volp)
  4907. {
  4908. addAttachmentOverridesForObject(volp, &meshes_seen);
  4909. }
  4910. }
  4911. // Attached objects
  4912. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  4913. {
  4914. LLViewerObject* object = mAttachedObjectsVector[i].first;
  4915. // Attached animated objects affect joints in their puppet, not the
  4916. // avatar to which they are attached.
  4917. if (object && !object->isAnimatedObject())
  4918. {
  4919. addAttachmentOverridesForObject(object, &meshes_seen);
  4920. }
  4921. }
  4922. // Remove meshes that are no longer present on the skeleton
  4923. // Use a copy since removeAttachmentOverrides() will change
  4924. // mActiveOverrideMeshes
  4925. uuid_list_t active_override_meshes = mActiveOverrideMeshes;
  4926. for (uuid_list_t::iterator it = active_override_meshes.begin(),
  4927. end = active_override_meshes.end();
  4928. it != end; ++it)
  4929. {
  4930. const LLUUID& mesh_id = *it;
  4931. if (!meshes_seen.count(mesh_id))
  4932. {
  4933. removeAttachmentOverridesForObject(mesh_id);
  4934. }
  4935. }
  4936. }
  4937. void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject* vo,
  4938. uuid_list_t* meshes_seen,
  4939. bool recursive)
  4940. {
  4941. if (!vo) return; // Paranoia
  4942. LLVOAvatar* av = vo->getAvatar();
  4943. if (av != this && vo->getAvatarAncestor() != this)
  4944. {
  4945. // This case is fairly common (on login and TPs, i.e. when not all
  4946. // objects data has been received) and not critical at all. Changed to
  4947. // a debug message to avoid log spam. HB
  4948. LL_DEBUGS("Avatar") << "Called with invalid avatar" << LL_ENDL;
  4949. return;
  4950. }
  4951. if (recursive)
  4952. {
  4953. // Process all children
  4954. LLViewerObject::const_child_list_t& children = vo->getChildren();
  4955. for (LLViewerObject::const_child_list_t::const_iterator
  4956. it = children.begin(), end = children.end();
  4957. it != end; ++it)
  4958. {
  4959. LLViewerObject* childp = *it;
  4960. if (childp)
  4961. {
  4962. addAttachmentOverridesForObject(childp, meshes_seen, true);
  4963. }
  4964. }
  4965. }
  4966. LLVOVolume* vobj = vo->asVolume();
  4967. if (!vobj || !vobj->getVolume() || !vobj->isMesh() ||
  4968. !gMeshRepo.meshRezEnabled() ||
  4969. !vobj->getVolume()->isMeshAssetLoaded())
  4970. {
  4971. return;
  4972. }
  4973. const LLMeshSkinInfo* skindatap = vobj->getSkinInfo();
  4974. if (!skindatap)
  4975. {
  4976. return;
  4977. }
  4978. const S32 bind_count = skindatap->mAlternateBindMatrix.size();
  4979. if (bind_count <= 0)
  4980. {
  4981. return;
  4982. }
  4983. const S32 joint_count = skindatap->mJointKeys.size();
  4984. if (joint_count != bind_count)
  4985. {
  4986. llwarns_once << getFullname(true)
  4987. << " is wearing an invalid rigged mesh. bind_count = "
  4988. << bind_count << " - joint_count = " << joint_count
  4989. << " - Ignoring joint overrides." << llendl;
  4990. return;
  4991. }
  4992. if (joint_count < (S32)JOINT_COUNT_REQUIRED_FOR_FULLRIG)
  4993. {
  4994. return;
  4995. }
  4996. std::string avname = getFullname(true);
  4997. const LLUUID& mesh_id = skindatap->mMeshID;
  4998. if (meshes_seen)
  4999. {
  5000. meshes_seen->emplace(mesh_id);
  5001. }
  5002. if (mActiveOverrideMeshes.count(mesh_id))
  5003. {
  5004. LL_DEBUGS("Avatar") << "Skipping add attachment overrides (already loaded) for mesh "
  5005. << mesh_id << " to root object "
  5006. << vobj->getRootEdit()->getID() << ", on avatar: "
  5007. << avname << LL_ENDL;
  5008. return;
  5009. }
  5010. bool pelvis_got_set = false;
  5011. const F32 pelvis_z_offset = skindatap->mPelvisOffset;
  5012. LLUUID curr_id;
  5013. LLVector3 pos_before, pos_after;
  5014. bool override_changed = false;
  5015. for (S32 i = 0; i < joint_count; ++i)
  5016. {
  5017. U32 joint_key = skindatap->mJointKeys[i];
  5018. LLJoint* jointp = getJoint(joint_key);
  5019. if (jointp)
  5020. {
  5021. // Set the joint position
  5022. const LLVector3& pos =
  5023. skindatap->mAlternateBindMatrix[i].getTranslation();
  5024. if (jointp->aboveJointPosThreshold(pos))
  5025. {
  5026. jointp->addAttachmentPosOverride(pos, mesh_id, avname,
  5027. &override_changed);
  5028. if (override_changed && joint_key == LL_JOINT_KEY_PELVIS)
  5029. {
  5030. pelvis_got_set = true;
  5031. }
  5032. if (skindatap->mLockScaleIfJointPosition)
  5033. {
  5034. // Note that unlike positions, there is no threshold check
  5035. // here, just a lock at the default value.
  5036. jointp->addAttachmentScaleOverride(jointp->getDefaultScale(),
  5037. mesh_id, avname);
  5038. }
  5039. }
  5040. }
  5041. }
  5042. if (pelvis_z_offset != 0.f)
  5043. {
  5044. F32 fixup_before, fixup_after;
  5045. bool has_fixup_before = hasPelvisFixup(fixup_before);
  5046. addPelvisFixup(pelvis_z_offset, mesh_id);
  5047. hasPelvisFixup(fixup_after);
  5048. if (!has_fixup_before || fixup_before != fixup_after)
  5049. {
  5050. pelvis_got_set = true;
  5051. }
  5052. }
  5053. mActiveOverrideMeshes.emplace(mesh_id);
  5054. mJointRiggingInfoTab.setNeedsUpdate();
  5055. // Rebuild body data if we altered joints/pelvis
  5056. if (pelvis_got_set)
  5057. {
  5058. postPelvisSetRecalc();
  5059. }
  5060. }
  5061. void LLVOAvatar::removeAttachmentOverridesForObject(LLViewerObject* vo)
  5062. {
  5063. LLVOAvatar* av = vo ? vo->getAvatar() : NULL;
  5064. if (av != this)
  5065. {
  5066. llwarns << "Called with invalid avatar" << llendl;
  5067. return;
  5068. }
  5069. // Process all children
  5070. LLViewerObject::const_child_list_t& children = vo->getChildren();
  5071. for (LLViewerObject::const_child_list_t::const_iterator
  5072. it = children.begin(), end = children.end();
  5073. it != end; ++it)
  5074. {
  5075. LLViewerObject* childp = *it;
  5076. if (childp)
  5077. {
  5078. removeAttachmentOverridesForObject(childp);
  5079. }
  5080. }
  5081. // Process self.
  5082. LLUUID mesh_id;
  5083. if (getRiggedMeshID(vo ,mesh_id))
  5084. {
  5085. removeAttachmentOverridesForObject(mesh_id);
  5086. }
  5087. }
  5088. void LLVOAvatar::removeAttachmentOverridesForObject(const LLUUID& mesh_id)
  5089. {
  5090. std::string avname = getFullname(true);
  5091. // Note: joint key 0 = "unnamed", 1 = "mScreen" (so we skip them)
  5092. for (U32 i = 2; i <= LL_CHARACTER_MAX_ANIMATED_JOINTS; ++i)
  5093. {
  5094. LLJoint* jointp = getJoint(i);
  5095. if (jointp)
  5096. {
  5097. // Reset joints except for pelvis
  5098. jointp->removeAttachmentPosOverride(mesh_id, avname);
  5099. jointp->removeAttachmentScaleOverride(mesh_id, avname);
  5100. }
  5101. if (jointp == mPelvisp)
  5102. {
  5103. removePelvisFixup(mesh_id);
  5104. jointp->setPosition(LLVector3::zero);
  5105. }
  5106. }
  5107. postPelvisSetRecalc();
  5108. mActiveOverrideMeshes.erase(mesh_id);
  5109. mJointRiggingInfoTab.setNeedsUpdate();
  5110. }
  5111. LLVector3 LLVOAvatar::getCharacterPosition()
  5112. {
  5113. if (mDrawable.notNull())
  5114. {
  5115. return mDrawable->getPositionAgent();
  5116. }
  5117. else
  5118. {
  5119. return getPositionAgent();
  5120. }
  5121. }
  5122. LLQuaternion LLVOAvatar::getCharacterRotation()
  5123. {
  5124. return getRotation();
  5125. }
  5126. LLVector3 LLVOAvatar::getCharacterVelocity()
  5127. {
  5128. return getVelocity() - mStepObjectVelocity;
  5129. }
  5130. LLVector3 LLVOAvatar::getCharacterAngularVelocity()
  5131. {
  5132. return getAngularVelocity();
  5133. }
  5134. void LLVOAvatar::getGround(const LLVector3& in_pos_agent,
  5135. LLVector3& out_pos_agent, LLVector3& out_norm)
  5136. {
  5137. const LLVector3d z_vec(0.f, 0.f, 1.f);
  5138. LLVector3d p0_global, p1_global;
  5139. if (isUIAvatar())
  5140. {
  5141. out_norm.set(z_vec);
  5142. out_pos_agent = in_pos_agent;
  5143. return;
  5144. }
  5145. p0_global = gAgent.getPosGlobalFromAgent(in_pos_agent) + z_vec;
  5146. p1_global = gAgent.getPosGlobalFromAgent(in_pos_agent) - z_vec;
  5147. LLViewerObject* obj;
  5148. LLVector3d out_pos_global;
  5149. gWorld.resolveStepHeightGlobal(this, p0_global, p1_global, out_pos_global,
  5150. out_norm, &obj);
  5151. out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
  5152. }
  5153. F32 LLVOAvatar::getTimeDilation()
  5154. {
  5155. return mRegionp ? mRegionp->getTimeDilation() : 1.f;
  5156. }
  5157. F32 LLVOAvatar::getPixelArea() const
  5158. {
  5159. return isUIAvatar() ? 100000.f : mPixelArea;
  5160. }
  5161. LLVector3d LLVOAvatar::getPosGlobalFromAgent(const LLVector3& position)
  5162. {
  5163. return gAgent.getPosGlobalFromAgent(position);
  5164. }
  5165. LLVector3 LLVOAvatar::getPosAgentFromGlobal(const LLVector3d& position)
  5166. {
  5167. return gAgent.getPosAgentFromGlobal(position);
  5168. }
  5169. //virtual
  5170. void LLVOAvatar::requestStopMotion(LLMotion* motion)
  5171. {
  5172. // Only agent avatars should handle the stop motion notifications.
  5173. }
  5174. // Loads <skeleton> node from XML tree
  5175. //virtual
  5176. bool LLVOAvatar::loadSkeletonNode()
  5177. {
  5178. if (!LLAvatarAppearance::loadSkeletonNode())
  5179. {
  5180. return false;
  5181. }
  5182. initAttachmentPoints();
  5183. return true;
  5184. }
  5185. // Creates attachment points if needed, sets state based on avatar_lad.xml
  5186. void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
  5187. {
  5188. // ATTACHMENTS
  5189. for (LLAvatarXmlInfo::attachment_info_list_t::iterator
  5190. iter = sAvatarXmlInfo->mAttachmentInfoList.begin(),
  5191. end = sAvatarXmlInfo->mAttachmentInfoList.end();
  5192. iter != end; ++iter)
  5193. {
  5194. LLAvatarXmlInfo::LLAvatarAttachmentInfo* info = *iter;
  5195. if (info->mIsHUDAttachment && (ignore_hud_joints || !isSelf()))
  5196. {
  5197. // do not process HUD joint for other avatars, or when performing a
  5198. // skeleton reset.
  5199. continue;
  5200. }
  5201. S32 attachment_id = info->mAttachmentID;
  5202. if (attachment_id < 1 || attachment_id > 255)
  5203. {
  5204. llwarns << "Avatar: " << getFullname(true)
  5205. << " - Attachment point out of range [1-255]: "
  5206. << attachment_id << " on attachment point "
  5207. << info->mName << ", skipping." << llendl;
  5208. continue;
  5209. }
  5210. LLJoint* parent_joint = getJoint(info->mJointKey);
  5211. if (!parent_joint)
  5212. {
  5213. // If the intended location for attachment point is unavailable,
  5214. // stick it in a default location.
  5215. // NOTE: this should not happen, unless avatar_lad.xml is corrupt
  5216. llwarns << "Avatar: " << getFullname(true)
  5217. << " - No parent joint by name " << info->mJointName
  5218. << " found for attachment point " << info->mName
  5219. << ", using pelvis as the default parent." << llendl;
  5220. llassert(false);
  5221. parent_joint = mPelvisp;
  5222. }
  5223. // Check if the attachment already exists, so that we can reload
  5224. // avatars...
  5225. bool newly_created = false;
  5226. LLViewerJointAttachment* attachment = get_ptr_in_map(mAttachmentPoints,
  5227. attachment_id);
  5228. if (!attachment)
  5229. {
  5230. attachment = new LLViewerJointAttachment();
  5231. newly_created = true;
  5232. }
  5233. attachment->setName(info->mName);
  5234. if (info->mHasPosition)
  5235. {
  5236. attachment->setOriginalPosition(info->mPosition);
  5237. attachment->setDefaultPosition(info->mPosition);
  5238. }
  5239. if (info->mHasRotation)
  5240. {
  5241. LLQuaternion rotation;
  5242. rotation.setEulerAngles(info->mRotationEuler.mV[VX] * DEG_TO_RAD,
  5243. info->mRotationEuler.mV[VY] * DEG_TO_RAD,
  5244. info->mRotationEuler.mV[VZ] * DEG_TO_RAD);
  5245. attachment->setRotation(rotation);
  5246. }
  5247. S32 group = info->mGroup;
  5248. if (group >= 0)
  5249. {
  5250. if (group < 0 || group >= 9)
  5251. {
  5252. llwarns << "Avatar: " << getFullname(true)
  5253. << " - Invalid group number (" << group
  5254. << ") for attachment point " << info->mName
  5255. << llendl;
  5256. llassert(false);
  5257. }
  5258. else
  5259. {
  5260. attachment->setGroup(group);
  5261. }
  5262. }
  5263. attachment->setPieSlice(info->mPieMenuSlice);
  5264. attachment->setVisibleInFirstPerson(info->mVisibleFirstPerson);
  5265. attachment->setIsHUDAttachment(info->mIsHUDAttachment);
  5266. // an attachment can potentially be animated and needs a number.
  5267. attachment->setJointNum(mNumBones + mCollisionVolumes.size() +
  5268. attachment_id - 1);
  5269. if (newly_created)
  5270. {
  5271. mAttachmentPoints[attachment_id] = attachment;
  5272. // now add attachment joint
  5273. parent_joint->addChild(attachment);
  5274. }
  5275. }
  5276. }
  5277. void LLVOAvatar::updateVisualParams()
  5278. {
  5279. LL_DEBUGS("Avatar") << "Called for avatar: " << getFullname(true)
  5280. << LL_ENDL;
  5281. setSex(getVisualParamWeight("male") > 0.5f ? SEX_MALE : SEX_FEMALE);
  5282. LLCharacter::updateVisualParams();
  5283. if (mLastSkeletonSerialNum != mSkeletonSerialNum)
  5284. {
  5285. computeBodySize();
  5286. mLastSkeletonSerialNum = mSkeletonSerialNum;
  5287. mRoot->updateWorldMatrixChildren();
  5288. }
  5289. dirtyMesh();
  5290. updateHeadOffset();
  5291. }
  5292. void LLVOAvatar::setPixelAreaAndAngle()
  5293. {
  5294. if (mDrawable.isNull())
  5295. {
  5296. return;
  5297. }
  5298. const LLVector4a* ext = mDrawable->getSpatialExtents();
  5299. LLVector4a center;
  5300. center.setAdd(ext[1], ext[0]);
  5301. center.mul(0.5f);
  5302. LLVector4a size;
  5303. size.setSub(ext[1], ext[0]);
  5304. size.mul(0.5f);
  5305. mImpostorPixelArea = LLPipeline::calcPixelArea(center, size,
  5306. gViewerCamera);
  5307. F32 range = mDrawable->mDistanceWRTCamera;
  5308. if (range < 0.001f) // range == zero
  5309. {
  5310. mAppAngle = 180.f;
  5311. }
  5312. else
  5313. {
  5314. F32 radius = size.getLength3().getF32();
  5315. mAppAngle = atan2f(radius, range) * RAD_TO_DEG;
  5316. }
  5317. // We always want to look good to ourselves
  5318. if (isSelf())
  5319. {
  5320. // Note: used to be 512 / 16, but increased to take into account larger
  5321. // (1024x1024) new bakes. HB
  5322. constexpr F32 MIN_AREA = 1024.f / 16.f;
  5323. mPixelArea = llmax(mPixelArea, MIN_AREA);
  5324. }
  5325. }
  5326. bool LLVOAvatar::updateJointLODs()
  5327. {
  5328. constexpr F32 MAX_PIXEL_AREA = 100000000.f;
  5329. F32 lod_factor = sLODFactor * AVATAR_LOD_TWEAK_RANGE + 1.f -
  5330. AVATAR_LOD_TWEAK_RANGE;
  5331. F32 avatar_num_min_factor = clamp_rescale(sLODFactor, 0.f, 1.f, .25f, .6f);
  5332. F32 avatar_num_factor = clamp_rescale((F32)sNumVisibleAvatars, 8, 25, 1.f,
  5333. avatar_num_min_factor);
  5334. F32 area_scale = 0.16f;
  5335. if (isSelf())
  5336. {
  5337. if (gAgent.cameraCustomizeAvatar() || gAgent.cameraMouselook())
  5338. {
  5339. mAdjustedPixelArea = MAX_PIXEL_AREA;
  5340. }
  5341. else
  5342. {
  5343. mAdjustedPixelArea = mPixelArea * area_scale;
  5344. }
  5345. }
  5346. else if (mIsDummy)
  5347. {
  5348. mAdjustedPixelArea = MAX_PIXEL_AREA;
  5349. }
  5350. else
  5351. {
  5352. // Reported avatar pixel area is dependent on avatar render load,
  5353. // based on number of visible avatars
  5354. mAdjustedPixelArea = (F32)mPixelArea * area_scale * lod_factor *
  5355. lod_factor * avatar_num_factor *
  5356. avatar_num_factor;
  5357. }
  5358. // Now select meshes to render based on adjusted pixel area
  5359. LLAvatarJoint* root = mRoot->asAvatarJoint();
  5360. bool res = false;
  5361. if (root)
  5362. {
  5363. res = root->updateLOD(mAdjustedPixelArea, true);
  5364. }
  5365. if (res)
  5366. {
  5367. ++sNumLODChangesThisFrame;
  5368. dirtyMesh(2);
  5369. return true;
  5370. }
  5371. return false;
  5372. }
  5373. LLDrawable* LLVOAvatar::createDrawable()
  5374. {
  5375. gPipeline.allocDrawable(this);
  5376. mDrawable->setLit(false);
  5377. U32 pool_type, render_type;
  5378. if (isPuppetAvatar())
  5379. {
  5380. pool_type = LLDrawPool::POOL_PUPPET;
  5381. render_type = LLPipeline::RENDER_TYPE_PUPPET;
  5382. }
  5383. else
  5384. {
  5385. pool_type = LLDrawPool::POOL_AVATAR;
  5386. render_type = LLPipeline::RENDER_TYPE_AVATAR;
  5387. }
  5388. // Only a single face (one per avatar); this face will be splitted into
  5389. // several if its vertex buffer is too long.
  5390. mDrawable->setState(LLDrawable::ACTIVE);
  5391. LLDrawPoolAvatar* poolp = (LLDrawPoolAvatar*)gPipeline.getPool(pool_type);
  5392. mDrawable->addFace(poolp, NULL);
  5393. mDrawable->setRenderType(render_type);
  5394. mNumInitFaces = mDrawable->getNumFaces();
  5395. dirtyMesh(2);
  5396. return mDrawable;
  5397. }
  5398. void LLVOAvatar::updateGL()
  5399. {
  5400. if (mMeshTexturesDirty)
  5401. {
  5402. updateMeshTextures();
  5403. mMeshTexturesDirty = false;
  5404. }
  5405. }
  5406. #if 0 // A NOP functions doing pointless tests and always returning true...
  5407. // Replaced with an inlined return true; in llvoavatar.h
  5408. bool LLVOAvatar::updateGeometry(LLDrawable* drawable)
  5409. {
  5410. U32 type = isPuppetAvatar() ? LLPipeline::RENDER_TYPE_PUPPET
  5411. : LLPipeline::RENDER_TYPE_AVATAR;
  5412. if (!gPipeline.hasRenderType(type) || !mMeshValid)
  5413. {
  5414. return true;
  5415. }
  5416. if (!drawable)
  5417. {
  5418. llwarns << getFullname(true) << " got a NULL drawable !" << llendl;
  5419. llassert(false);
  5420. }
  5421. return true;
  5422. }
  5423. #endif
  5424. void LLVOAvatar::updateSexDependentLayerSets(bool upload_bake)
  5425. {
  5426. invalidateComposite(mBakedTextureDatas[BAKED_HEAD].mTexLayerSet,
  5427. upload_bake);
  5428. invalidateComposite(mBakedTextureDatas[BAKED_UPPER].mTexLayerSet,
  5429. upload_bake);
  5430. invalidateComposite(mBakedTextureDatas[BAKED_LOWER].mTexLayerSet,
  5431. upload_bake);
  5432. }
  5433. void LLVOAvatar::dirtyMesh()
  5434. {
  5435. dirtyMesh(1);
  5436. }
  5437. void LLVOAvatar::dirtyMesh(S32 priority)
  5438. {
  5439. mDirtyMesh = llmax(mDirtyMesh, priority);
  5440. }
  5441. LLViewerJoint* LLVOAvatar::getViewerJoint(S32 idx)
  5442. {
  5443. LLAvatarJoint* avjointp = mMeshLOD[idx];
  5444. if (avjointp)
  5445. {
  5446. return avjointp->asViewerJoint();
  5447. }
  5448. return NULL;
  5449. }
  5450. void LLVOAvatar::hideHair()
  5451. {
  5452. mMeshLOD[MESH_ID_HAIR]->setVisible(false, true);
  5453. }
  5454. void LLVOAvatar::hideSkirt()
  5455. {
  5456. mMeshLOD[MESH_ID_SKIRT]->setVisible(false, true);
  5457. }
  5458. bool LLVOAvatar::setParent(LLViewerObject* parent)
  5459. {
  5460. bool ret;
  5461. if (parent)
  5462. {
  5463. ret = LLViewerObject::setParent(parent);
  5464. if (ret)
  5465. {
  5466. if (isSelf())
  5467. {
  5468. LL_DEBUGS("AgentSit") << "Sitting agent on new parent" << LL_ENDL;
  5469. }
  5470. sitOnObject(parent);
  5471. }
  5472. }
  5473. else
  5474. {
  5475. if (isSelf())
  5476. {
  5477. LL_DEBUGS("AgentSit") << "Unsitting agent (NULL parent)" << LL_ENDL;
  5478. }
  5479. getOffObject();
  5480. ret = LLViewerObject::setParent(parent);
  5481. if (isSelf())
  5482. {
  5483. gAgent.resetCamera();
  5484. }
  5485. }
  5486. return ret;
  5487. }
  5488. void LLVOAvatar::addChild(LLViewerObject* childp)
  5489. {
  5490. // Find the inventory item this object is associated with:
  5491. childp->extractAttachmentItemID();
  5492. LLViewerObject::addChild(childp);
  5493. if (childp->mDrawable)
  5494. {
  5495. attachObject(childp);
  5496. }
  5497. else
  5498. {
  5499. mPendingAttachment.push_back(childp);
  5500. }
  5501. if (isSelf())
  5502. {
  5503. gAttachmentsListDirty = true;
  5504. gAttachmentsTimer.reset();
  5505. }
  5506. }
  5507. void LLVOAvatar::removeChild(LLViewerObject* childp)
  5508. {
  5509. if (childp)
  5510. {
  5511. LLViewerObject::removeChild(childp);
  5512. detachObject(childp);
  5513. if (isSelf())
  5514. {
  5515. gAttachmentsListDirty = true;
  5516. gAttachmentsTimer.reset();
  5517. }
  5518. }
  5519. }
  5520. LLViewerJointAttachment* LLVOAvatar::getTargetAttachmentPoint(LLViewerObject* vobj)
  5521. {
  5522. S32 attachment_id = ATTACHMENT_ID_FROM_STATE(vobj->getAttachmentState());
  5523. // This should never happen unless the server did not process the
  5524. // attachment point correctly, but putting this check in here to be safe.
  5525. if (attachment_id & ATTACHMENT_ADD)
  5526. {
  5527. llwarns << "Got an attachment with ATTACHMENT_ADD mask. Removing mask (attach pt: "
  5528. << attachment_id << ")" << llendl;
  5529. attachment_id &= ~ATTACHMENT_ADD;
  5530. }
  5531. LLViewerJointAttachment* attachment = get_ptr_in_map(mAttachmentPoints,
  5532. attachment_id);
  5533. if (!attachment)
  5534. {
  5535. llwarns_once << getFullname(true)
  5536. << " is using invalid attachment point " << attachment_id
  5537. << llendl;
  5538. // Arbitrary using 1 (chest)
  5539. attachment = get_ptr_in_map(mAttachmentPoints, 1);
  5540. }
  5541. return attachment;
  5542. }
  5543. const LLViewerJointAttachment* LLVOAvatar::attachObject(LLViewerObject* vobj)
  5544. {
  5545. LLViewerJointAttachment* attachment = getTargetAttachmentPoint(vobj);
  5546. if (!attachment || !attachment->addObject(vobj, isSelf()))
  5547. {
  5548. return NULL;
  5549. }
  5550. mVisualComplexityStale = true;
  5551. if (vobj->isSelected())
  5552. {
  5553. gSelectMgr.updateSelectionCenter();
  5554. gSelectMgr.updatePointAt();
  5555. }
  5556. // Add the new (vobj, attachment) pair to the vector if not already there
  5557. // (i.e. if not being reattached)
  5558. attachments_vec_t::iterator end = mAttachedObjectsVector.end();
  5559. std::pair<LLViewerObject*, LLViewerJointAttachment*> val(vobj, attachment);
  5560. if (std::find(mAttachedObjectsVector.begin(), end, val) == end)
  5561. {
  5562. mAttachedObjectsVector.emplace_back(val);
  5563. }
  5564. if (!vobj->isAnimatedObject())
  5565. {
  5566. updateAttachmentOverrides();
  5567. vobj->refreshBakeTexture();
  5568. LLViewerObject::const_child_list_t& child_list = vobj->getChildren();
  5569. for (LLViewerObject::child_list_t::const_iterator
  5570. iter = child_list.begin(), end = child_list.end();
  5571. iter != end; ++iter)
  5572. {
  5573. LLViewerObject* childp = *iter;
  5574. if (childp)
  5575. {
  5576. childp->refreshBakeTexture();
  5577. }
  5578. }
  5579. updateMeshVisibility();
  5580. }
  5581. return attachment;
  5582. }
  5583. U32 LLVOAvatar::getNumAttachments() const
  5584. {
  5585. #if 0
  5586. U32 num_attachments = 0;
  5587. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(),
  5588. end = mAttachmentPoints.end();
  5589. iter != end; ++iter)
  5590. {
  5591. const LLViewerJointAttachment* attachment_pt = iter->second;
  5592. if (attachment_pt)
  5593. {
  5594. num_attachments += attachment_pt->getNumObjects();
  5595. }
  5596. else
  5597. {
  5598. llwarns << "NULL joint attachment found for "
  5599. << ((LLVOAvatar*)this)->getFullname(true) << llendl;
  5600. }
  5601. }
  5602. return num_attachments;
  5603. #else
  5604. return mAttachedObjectsVector.size();
  5605. #endif
  5606. }
  5607. U32 LLVOAvatar::getNumAnimatedObjectAttachments() const
  5608. {
  5609. U32 num_attachments = 0;
  5610. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(),
  5611. end = mAttachmentPoints.end();
  5612. iter != end; ++iter)
  5613. {
  5614. const LLViewerJointAttachment* attachment_pt = iter->second;
  5615. if (attachment_pt)
  5616. {
  5617. num_attachments += attachment_pt->getNumAnimatedObjects();
  5618. }
  5619. else
  5620. {
  5621. llwarns << "NULL joint attachment found for "
  5622. << ((LLVOAvatar*)this)->getFullname(true) << llendl;
  5623. }
  5624. }
  5625. return num_attachments;
  5626. }
  5627. //virtual
  5628. S32 LLVOAvatar::getMaxAnimatedObjectAttachments() const
  5629. {
  5630. LLViewerRegion* regionp = gAgent.getRegion();
  5631. if (!regionp || !regionp->getFeaturesReceived())
  5632. {
  5633. return 0;
  5634. }
  5635. const LLSD& info = regionp->getSimulatorFeatures();
  5636. if (!info.has("AnimatedObjects"))
  5637. {
  5638. return 0;
  5639. }
  5640. return info["AnimatedObjects"]["MaxAgentAnimatedObjectAttachments"].asInteger();
  5641. }
  5642. bool LLVOAvatar::canAttachMoreAnimatedObjects(U32 n) const
  5643. {
  5644. return getNumAnimatedObjectAttachments() + n <=
  5645. (U32)getMaxAnimatedObjectAttachments();
  5646. }
  5647. void LLVOAvatar::lazyAttach()
  5648. {
  5649. std::vector<LLPointer<LLViewerObject> > still_pending;
  5650. for (U32 i = 0; i < mPendingAttachment.size(); ++i)
  5651. {
  5652. LLPointer<LLViewerObject> object = mPendingAttachment[i];
  5653. if (object->isDead()) continue;
  5654. const LLViewerJointAttachment* vja = NULL;
  5655. if (object->mDrawable)
  5656. {
  5657. vja = attachObject(object);
  5658. }
  5659. if (vja)
  5660. {
  5661. if (isSelf())
  5662. {
  5663. LL_DEBUGS("Attachment") << "Attaching object "
  5664. << object->mID << " from "
  5665. << LLTrans::getString(vja->getName())
  5666. << LL_ENDL;
  5667. gAttachmentsListDirty = true;
  5668. gAttachmentsTimer.reset();
  5669. }
  5670. }
  5671. else
  5672. {
  5673. still_pending.push_back(object);
  5674. }
  5675. }
  5676. mPendingAttachment = still_pending;
  5677. if (isSelf() && still_pending.size() > 0)
  5678. {
  5679. gAttachmentsListDirty = true;
  5680. gAttachmentsTimer.reset();
  5681. }
  5682. }
  5683. void LLVOAvatar::rebuildRiggedAttachments()
  5684. {
  5685. LL_DEBUGS("Avatar") << "Called for avatar: " << getFullname(true)
  5686. << LL_ENDL;
  5687. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  5688. {
  5689. const LLViewerObject* object = mAttachedObjectsVector[i].first;
  5690. if (object && object->mDrawable.notNull())
  5691. {
  5692. gPipeline.markRebuild(object->mDrawable);
  5693. }
  5694. }
  5695. }
  5696. #if 0 // Would it be at all needed ???
  5697. void LLVOAvatar::cleanupAttachedMesh(LLViewerObject* vobj)
  5698. {
  5699. LLUUID mesh_id;
  5700. if (getRiggedMeshID(vobj, mesh_id))
  5701. {
  5702. // Need to handle the repositioning of the cam, updating rig data etc
  5703. // during outfit editing. This handles the case where we detach a
  5704. // replacement rig.
  5705. if (gAgent.cameraCustomizeAvatar())
  5706. {
  5707. gAgent.unpauseAnimation(); // not yet implemented
  5708. // Still want to refocus on head bone
  5709. gAgent.changeCameraToCustomizeAvatar();
  5710. }
  5711. }
  5712. }
  5713. #endif
  5714. //virtual
  5715. bool LLVOAvatar::detachObject(LLViewerObject* vobj)
  5716. {
  5717. if (!vobj) return false;
  5718. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  5719. end = mAttachmentPoints.end();
  5720. iter != end; ++iter)
  5721. {
  5722. LLViewerJointAttachment* attachment = iter->second;
  5723. if (attachment && attachment->isObjectAttached(vobj))
  5724. {
  5725. if (isSelf())
  5726. {
  5727. LL_DEBUGS("Attachment") << "Detaching object "
  5728. << vobj->mID << " from "
  5729. << LLTrans::getString(attachment->getName())
  5730. << LL_ENDL;
  5731. }
  5732. bool animated = vobj->isAnimatedObject();
  5733. #if 0
  5734. cleanupAttachedMesh(vobj);
  5735. #endif
  5736. vector_replace_with_last(mAttachedObjectsVector,
  5737. std::make_pair(vobj, attachment));
  5738. attachment->removeObject(vobj, isSelf());
  5739. if (!animated)
  5740. {
  5741. updateAttachmentOverrides();
  5742. vobj->refreshBakeTexture();
  5743. LLViewerObject::const_child_list_t& child_list =
  5744. vobj->getChildren();
  5745. for (LLViewerObject::child_list_t::const_iterator
  5746. iter = child_list.begin(), end = child_list.end();
  5747. iter != end; ++iter)
  5748. {
  5749. LLViewerObject* childp = *iter;
  5750. if (childp)
  5751. {
  5752. childp->refreshBakeTexture();
  5753. }
  5754. }
  5755. updateMeshVisibility();
  5756. }
  5757. mVisualComplexityStale = true;
  5758. return true;
  5759. }
  5760. }
  5761. std::vector<LLPointer<LLViewerObject> >::iterator iter;
  5762. iter = std::find(mPendingAttachment.begin(), mPendingAttachment.end(),
  5763. vobj);
  5764. if (iter != mPendingAttachment.end())
  5765. {
  5766. mPendingAttachment.erase(iter);
  5767. return true;
  5768. }
  5769. return false;
  5770. }
  5771. void LLVOAvatar::sitOnObject(LLViewerObject* sit_object)
  5772. {
  5773. if (mDrawable.isNull())
  5774. {
  5775. return;
  5776. }
  5777. if (isSelf())
  5778. {
  5779. // Might be first sit
  5780. LLFirstUse::useSit();
  5781. gAgent.notOnSatGround();
  5782. gAgent.setFlying(false);
  5783. gAgent.setThirdPersonHeadOffset(LLVector3::zero);
  5784. // Interpolate to new camera position
  5785. gAgent.startCameraAnimation();
  5786. if (gSavedSettings.getBool("SitCameraFrontView") &&
  5787. gAgent.getCameraMode() != CAMERA_MODE_MOUSELOOK &&
  5788. !gAgent.mForceMouselook)
  5789. {
  5790. gSavedSettings.setBool("CameraFrontView", true);
  5791. }
  5792. // Make sure we are not trying to autopilot
  5793. gAgentPilot.stopAutoPilot();
  5794. gAgent.setupSitCamera();
  5795. if (gAgent.mForceMouselook)
  5796. {
  5797. gAgent.changeCameraToMouselook();
  5798. }
  5799. }
  5800. LLQuaternion inv_obj_rot = ~sit_object->getRenderRotation();
  5801. LLVector3 obj_pos = sit_object->getRenderPosition();
  5802. LLVector3 rel_pos = getRenderPosition() - obj_pos;
  5803. rel_pos.rotVec(inv_obj_rot);
  5804. mDrawable->mXform.setPosition(rel_pos);
  5805. mDrawable->mXform.setRotation(mDrawable->getWorldRotation() * inv_obj_rot);
  5806. gPipeline.markMoved(mDrawable, true);
  5807. //MK
  5808. if (gRLenabled && isSelf())
  5809. {
  5810. const LLUUID& obj_id = sit_object->getID();
  5811. gRLInterface.setSitTargetId(obj_id);
  5812. gRLInterface.notify("sat object legally", obj_id.asString());
  5813. }
  5814. //mk
  5815. mIsSitting = true;
  5816. mRoot->getXform()->setParent(&sit_object->mDrawable->mXform);
  5817. mRoot->setPosition(getPosition());
  5818. mRoot->updateWorldMatrixChildren();
  5819. stopMotion(ANIM_AGENT_BODY_NOISE);
  5820. if (isSelf())
  5821. {
  5822. // *HACK: Disabling flying mode. This happens when we sat on an object
  5823. // at a high altitude that was a few meters away from where the avatar
  5824. // was standing. See VWR-16986 and VWR-19724.
  5825. gAgent.setFlying(false);
  5826. }
  5827. }
  5828. void LLVOAvatar::getOffObject()
  5829. {
  5830. mIsSitting = false;
  5831. if (mDrawable.isNull())
  5832. {
  5833. return;
  5834. }
  5835. //MK
  5836. bool force_re_sit = false;
  5837. //mk
  5838. LLViewerObject* sit_object = (LLViewerObject*)getParent();
  5839. if (sit_object)
  5840. {
  5841. //MK
  5842. if (gRLenabled && isSelf())
  5843. {
  5844. const LLUUID& obj_id = sit_object->getID();
  5845. force_re_sit = gRLInterface.mContainsUnsit;
  5846. if (force_re_sit)
  5847. {
  5848. gRLInterface.notify("unsat object illegally",
  5849. obj_id.asString());
  5850. }
  5851. else
  5852. {
  5853. gRLInterface.setSitTargetId(LLUUID::null);
  5854. gRLInterface.notify("unsat object legally",
  5855. obj_id.asString());
  5856. }
  5857. }
  5858. //mk
  5859. stopMotionFromSource(sit_object->getID());
  5860. LLFollowCamMgr::setCameraActive(sit_object->getID(), false);
  5861. LLViewerObject::const_child_list_t& child_list =
  5862. sit_object->getChildren();
  5863. for (LLViewerObject::child_list_t::const_iterator
  5864. iter = child_list.begin(), end = child_list.end();
  5865. iter != end; ++iter)
  5866. {
  5867. LLViewerObject* child_objectp = *iter;
  5868. stopMotionFromSource(child_objectp->getID());
  5869. LLFollowCamMgr::setCameraActive(child_objectp->getID(), false);
  5870. }
  5871. if (isSelf() && !sit_object->permYouOwner() &&
  5872. //MK
  5873. !force_re_sit &&
  5874. //mk
  5875. gSavedSettings.getBool("RevokePermsOnStandUp"))
  5876. {
  5877. // First, revoke the animating permissions alone, then attempt to
  5878. // revoke all other permissions: we must do that because for now,
  5879. // in SL, the server trashes the whole message when trying to
  5880. // revoke permissions other than animations-related ones.
  5881. // Proceeding this way, let's a chance for all perms to actually be
  5882. // revoked in OpenSim, and perhaps at a later date in SL...
  5883. U32 permissions = LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TRIGGER_ANIMATION] |
  5884. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS];
  5885. gAgent.sendRevokePermissions(sit_object->getID(), permissions);
  5886. permissions = 0xFFFFFFFF;
  5887. gAgent.sendRevokePermissions(sit_object->getID(), permissions);
  5888. }
  5889. }
  5890. // Assumes that transform will not be updated with drawable still having
  5891. // a parent or that drawable had no parent from the start
  5892. LLVector3 cur_position_world = mDrawable->getWorldPosition();
  5893. LLQuaternion cur_rotation_world = mDrawable->getWorldRotation();
  5894. // set *local* position based on last *world* position, since we're
  5895. // unparenting the avatar
  5896. mDrawable->mXform.setPosition(cur_position_world);
  5897. mDrawable->mXform.setRotation(cur_rotation_world);
  5898. gPipeline.markMoved(mDrawable, true);
  5899. mRoot->getXform()->setParent(NULL);
  5900. mRoot->setPosition(cur_position_world);
  5901. mRoot->setRotation(cur_rotation_world);
  5902. mRoot->getXform()->update();
  5903. if (mEnableDefaultMotions)
  5904. {
  5905. startMotion(ANIM_AGENT_BODY_NOISE);
  5906. }
  5907. if (isSelf())
  5908. {
  5909. LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
  5910. LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation()
  5911. : LLQuaternion::DEFAULT;
  5912. av_rot = av_rot * obj_rot;
  5913. LLVector3 at_axis = LLVector3::x_axis;
  5914. at_axis = at_axis * av_rot;
  5915. at_axis.mV[VZ] = 0.f;
  5916. at_axis.normalize();
  5917. gAgent.resetAxes(at_axis);
  5918. #if 0
  5919. // Reset orientation
  5920. mRoot->setRotation(avWorldRot);
  5921. #endif
  5922. gAgent.setThirdPersonHeadOffset(LLVector3(0.f, 0.f, 1.f));
  5923. if (gSavedSettings.getBool("SitCameraFrontView"))
  5924. {
  5925. gSavedSettings.setBool("CameraFrontView", false);
  5926. }
  5927. gAgent.notOnSatGround();
  5928. gAgent.setSitCamera(LLUUID::null);
  5929. //MK
  5930. #if 0 // Disabled, because this causes a race condition when executing:
  5931. // @sit:<uuid>=force,unsit=n while the avatar is already sitting.
  5932. // If we were sitting and prevented from standing up, and we are here,
  5933. // the we probably received a message from the sim after a call to
  5934. // llUnSit() in a LSL script. While we cannot ignore the sim message,
  5935. // we still can force the avatar back down onto the seat.
  5936. if (force_re_sit && sit_object->getRegion())
  5937. {
  5938. LL_DEBUGS("RestrainedLove") << "Forcing agent to re-sit on object"
  5939. << LL_ENDL;
  5940. LL_DEBUGS("AgentSit") << "RestrainedLove sending agent force-re-sit on object request"
  5941. << LL_ENDL;
  5942. LLMessageSystem* msg = gMessageSystemp;
  5943. msg->newMessageFast(_PREHASH_AgentRequestSit);
  5944. msg->nextBlockFast(_PREHASH_AgentData);
  5945. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5946. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5947. msg->nextBlockFast(_PREHASH_TargetObject);
  5948. msg->addUUIDFast(_PREHASH_TargetID, sit_object->mID);
  5949. # if 0 // Note: for seats without a sit target, transmitting the offset
  5950. // results in a sit failure with "There is no suitable surface to
  5951. // sit on" message, while transmitting a 0 offset seems to work, as
  5952. // long as the seat is close to the avatar (8 meters away at most).
  5953. msg->addVector3Fast(_PREHASH_Offset,
  5954. gAgent.calcFocusOffset(sit_object,
  5955. gAgent.getPositionAgent(),
  5956. 0, 0));
  5957. # else
  5958. msg->addVector3Fast(_PREHASH_Offset, LLVector3::zero);
  5959. # endif
  5960. sit_object->getRegion()->sendReliableMessage();
  5961. }
  5962. #endif
  5963. //mk
  5964. }
  5965. }
  5966. //static
  5967. LLVOAvatar* LLVOAvatar::findAvatarFromAttachment(LLViewerObject* obj)
  5968. {
  5969. if (obj->isAttachment())
  5970. {
  5971. do
  5972. {
  5973. obj = (LLViewerObject*)obj->getParent();
  5974. }
  5975. while (obj && !obj->isAvatar());
  5976. if (obj && !obj->isDead())
  5977. {
  5978. return (LLVOAvatar*)obj;
  5979. }
  5980. }
  5981. return NULL;
  5982. }
  5983. // Unlike most wearable functions, this works for both self and other.
  5984. bool LLVOAvatar::isWearingWearableType(LLWearableType::EType type) const
  5985. {
  5986. if (mIsDummy) return true;
  5987. if (isSelf())
  5988. {
  5989. return LLAvatarAppearance::isWearingWearableType(type);
  5990. }
  5991. switch (type)
  5992. {
  5993. case LLWearableType::WT_SHAPE:
  5994. case LLWearableType::WT_SKIN:
  5995. case LLWearableType::WT_HAIR:
  5996. case LLWearableType::WT_EYES:
  5997. return true; // everyone has all bodyparts
  5998. default:
  5999. break; // Do nothing
  6000. }
  6001. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  6002. tex_iter = gAvatarAppDictp->getTextures().begin(),
  6003. end = gAvatarAppDictp->getTextures().end();
  6004. tex_iter != end; ++tex_iter)
  6005. {
  6006. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  6007. tex_iter->second;
  6008. if (t_dict->mWearableType == type)
  6009. {
  6010. // You are checking another avatar's clothing and you do not have
  6011. // component textures. Thus, you must check to see if the
  6012. // corresponding baked texture is defined.
  6013. // NOTE: this is a poor substitute if you actually want to know
  6014. // about individual pieces of clothing this works for detecting a
  6015. // skirt (most important), but is ineffective at any piece of
  6016. // clothing that gets baked into a texture that always exists
  6017. // (upper or lower).
  6018. if (t_dict->mIsUsedByBakedTexture)
  6019. {
  6020. const EBakedTextureIndex idx = t_dict->mBakedTextureIndex;
  6021. return isTextureDefined(gAvatarAppDictp->getBakedTexture(idx)->mTextureIndex);
  6022. }
  6023. return false;
  6024. }
  6025. }
  6026. return false;
  6027. }
  6028. //virtual
  6029. void LLVOAvatar::onGlobalColorChanged(const LLTexGlobalColor* global_color,
  6030. bool upload_bake)
  6031. {
  6032. if (global_color == mTexSkinColor)
  6033. {
  6034. invalidateComposite(mBakedTextureDatas[BAKED_HEAD].mTexLayerSet,
  6035. upload_bake);
  6036. invalidateComposite(mBakedTextureDatas[BAKED_UPPER].mTexLayerSet,
  6037. upload_bake);
  6038. invalidateComposite(mBakedTextureDatas[BAKED_LOWER].mTexLayerSet,
  6039. upload_bake);
  6040. }
  6041. else if (global_color == mTexHairColor)
  6042. {
  6043. invalidateComposite(mBakedTextureDatas[BAKED_HEAD].mTexLayerSet,
  6044. upload_bake);
  6045. invalidateComposite(mBakedTextureDatas[BAKED_HAIR].mTexLayerSet,
  6046. upload_bake);
  6047. // ! BACKWARDS COMPATIBILITY !
  6048. // Fix for dealing with avatars from viewers that don't bake hair.
  6049. if (!isTextureDefined(mBakedTextureDatas[BAKED_HAIR].mTextureIndex))
  6050. {
  6051. LLColor4 color = mTexHairColor->getColor();
  6052. for (avatar_joint_mesh_list_t::iterator
  6053. iter = mBakedTextureDatas[BAKED_HAIR].mJointMeshes.begin(),
  6054. end = mBakedTextureDatas[BAKED_HAIR].mJointMeshes.end();
  6055. iter != end; ++iter)
  6056. {
  6057. LLAvatarJointMesh* mesh = *iter;
  6058. if (mesh)
  6059. {
  6060. mesh->setColor(color);
  6061. }
  6062. }
  6063. }
  6064. }
  6065. else if (global_color == mTexEyeColor)
  6066. {
  6067. invalidateComposite(mBakedTextureDatas[BAKED_EYES].mTexLayerSet,
  6068. upload_bake);
  6069. }
  6070. updateMeshTextures();
  6071. }
  6072. bool LLVOAvatar::isVisible() const
  6073. {
  6074. return mDrawable.notNull() && (!mOrphaned || isSelf()) &&
  6075. (mDrawable->isVisible() || isUIAvatar());
  6076. }
  6077. // Determine if we have enough avatar data to render
  6078. bool LLVOAvatar::getIsCloud()
  6079. {
  6080. if (mIsDummy)
  6081. {
  6082. return false;
  6083. }
  6084. return visualParamWeightsAreDefault() ||
  6085. !isTextureDefined(TEX_LOWER_BAKED) ||
  6086. !isTextureDefined(TEX_UPPER_BAKED) ||
  6087. !isTextureDefined(TEX_HEAD_BAKED);
  6088. }
  6089. // Call periodically to keep isFullyLoaded up to date. Returns true if the
  6090. // value has changed.
  6091. bool LLVOAvatar::updateIsFullyLoaded()
  6092. {
  6093. bool loading = getIsCloud();
  6094. updateRuthTimer(loading);
  6095. return processFullyLoadedChange(loading);
  6096. }
  6097. void LLVOAvatar::updateRuthTimer(bool loading)
  6098. {
  6099. if (isSelf() || !loading)
  6100. {
  6101. return;
  6102. }
  6103. if (!mPreviousFullyLoaded && sendAvatarTexturesRequest())
  6104. {
  6105. llinfos << "Ruth Timer timeout: Missing texture data for '"
  6106. << getFullname(true) << "' - Params loaded: "
  6107. << !visualParamWeightsAreDefault() << " - Lower: "
  6108. << isTextureDefined(TEX_LOWER_BAKED) << " - Upper: "
  6109. << isTextureDefined(TEX_UPPER_BAKED) << " - Head : "
  6110. << isTextureDefined(TEX_HEAD_BAKED) << llendl;
  6111. }
  6112. }
  6113. bool LLVOAvatar::sendAvatarTexturesRequest(bool force)
  6114. {
  6115. bool sent = false;
  6116. if (force || mRuthTimer.getElapsedTimeF32() > DERUTHING_TIMEOUT_SECONDS)
  6117. {
  6118. std::vector<std::string> strings;
  6119. strings.emplace_back(mID.asString());
  6120. send_generic_message("avatartexturesrequest", strings);
  6121. mRuthTimer.reset();
  6122. sent = true;
  6123. }
  6124. return sent;
  6125. }
  6126. bool LLVOAvatar::processFullyLoadedChange(bool loading)
  6127. {
  6128. // We wait a little bit before giving the all clear, to let textures settle
  6129. // down
  6130. constexpr F32 PAUSE = 1.f;
  6131. if (loading)
  6132. {
  6133. mFullyLoadedTimer.reset();
  6134. }
  6135. mFullyLoaded = mFullyLoadedTimer.getElapsedTimeF32() > PAUSE;
  6136. // Did our loading state "change" from last call ?
  6137. constexpr S32 UPDATE_RATE = 30;
  6138. bool fully_loaded_changed = mFullyLoaded != mPreviousFullyLoaded;
  6139. // Changed... If the value is different from the previous call,
  6140. bool changed = fully_loaded_changed ||
  6141. // or if we have never been called before,
  6142. !mFullyLoadedInitialized ||
  6143. // or every now and then issue a change.
  6144. mFullyLoadedFrameCounter % UPDATE_RATE == 0;
  6145. mPreviousFullyLoaded = mFullyLoaded;
  6146. mFullyLoadedInitialized = true;
  6147. ++mFullyLoadedFrameCounter;
  6148. if (changed && mFullyLoaded)
  6149. {
  6150. mVisualComplexityStale = true;
  6151. }
  6152. #if LL_PUPPETRY
  6153. if (fully_loaded_changed)
  6154. {
  6155. LLPuppetMotion* motionp = getPuppetMotion();
  6156. if (motionp)
  6157. {
  6158. motionp->updateSkeletonGeometry();
  6159. gEventPumps.obtain("SkeletonUpdate").post(LLSD());
  6160. }
  6161. }
  6162. #endif
  6163. return changed;
  6164. }
  6165. bool LLVOAvatar::isFullyLoaded(bool truly) const
  6166. {
  6167. static LLCachedControl<bool> render_unloaded_avatar(gSavedSettings,
  6168. "RenderUnloadedAvatar");
  6169. return mFullyLoaded || (!truly && render_unloaded_avatar);
  6170. }
  6171. bool LLVOAvatar::isTooComplex() const
  6172. {
  6173. static LLCachedControl<bool> always_friends(gSavedSettings,
  6174. "AlwaysRenderFriends");
  6175. static LLCachedControl<U32> max_cost(gSavedSettings,
  6176. "RenderAvatarMaxComplexity");
  6177. static LLCachedControl<F32> max_area(gSavedSettings,
  6178. "RenderAutoMuteSurfaceAreaLimit");
  6179. static LLCachedControl<U32> max_megabytes(gSavedSettings,
  6180. "RenderAutoMuteMemoryLimit");
  6181. if (isSelf() || mVisuallyMuteSetting == AV_ALWAYS_RENDER ||
  6182. (max_cost == 0 && max_area <= 0.f && max_megabytes == 0) ||
  6183. (always_friends && LLAvatarTracker::isAgentFriend(mID)))
  6184. {
  6185. return false;
  6186. }
  6187. U32 max_bytes = max_megabytes * 1048576;
  6188. return (max_cost > 0 && mVisualComplexity > max_cost) ||
  6189. (max_area > 0.f && mAttachmentSurfaceArea > max_area) ||
  6190. (max_bytes > 0 && mAttachmentGeometryBytes > max_bytes);
  6191. }
  6192. LLMotion* LLVOAvatar::findMotion(const LLUUID& id) const
  6193. {
  6194. return mMotionController.findMotion(id);
  6195. }
  6196. void LLVOAvatar::debugColorizeSubMeshes(U32 i, const LLColor4& color)
  6197. {
  6198. static LLCachedControl<bool> debug_avatar_composite_baked(gSavedSettings,
  6199. "DebugAvatarCompositeBaked");
  6200. if (debug_avatar_composite_baked)
  6201. {
  6202. for (avatar_joint_mesh_list_t::iterator
  6203. iter = mBakedTextureDatas[i].mJointMeshes.begin(),
  6204. end = mBakedTextureDatas[i].mJointMeshes.end();
  6205. iter != end; ++iter)
  6206. {
  6207. LLAvatarJointMesh* mesh = *iter;
  6208. if (mesh)
  6209. {
  6210. mesh->setColor(color);
  6211. }
  6212. }
  6213. }
  6214. }
  6215. //virtual
  6216. void LLVOAvatar::updateMeshTextures()
  6217. {
  6218. // If user has never specified a texture, assign the default
  6219. for (U32 i = 0, count = getNumTEs(); i < count; ++i)
  6220. {
  6221. const LLViewerTexture* te_image = getImage(i, 0);
  6222. if (!te_image || te_image->getID().isNull() ||
  6223. te_image->getID() == IMG_DEFAULT)
  6224. {
  6225. // IMG_DEFAULT_AVATAR is a special texture that is never rendered.
  6226. const LLUUID& image_id = i == TEX_HAIR ? IMG_DEFAULT
  6227. : IMG_DEFAULT_AVATAR;
  6228. setImage(i,
  6229. LLViewerTextureManager::getFetchedTexture(image_id), 0);
  6230. }
  6231. }
  6232. const bool other_culled = !isSelf() && mCulled;
  6233. uuid_list_t* src_cb_list = NULL;
  6234. bool paused = false;
  6235. if (!isSelf())
  6236. {
  6237. src_cb_list = &mCallbackTextureList;
  6238. paused = !isVisible();
  6239. }
  6240. U32 count = mBakedTextureDatas.size();
  6241. std::vector<bool> is_layer_baked;
  6242. is_layer_baked.resize(count, false);
  6243. std::vector<bool> use_lkg_baked_layer; // lkg = "last known good"
  6244. use_lkg_baked_layer.resize(count, false);
  6245. for (U32 i = 0; i < count; ++i)
  6246. {
  6247. is_layer_baked[i] = isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
  6248. const LLUUID& last_tex_id = mBakedTextureDatas[i].mLastTextureID;
  6249. if (other_culled)
  6250. {
  6251. use_lkg_baked_layer[i] = !is_layer_baked[i] &&
  6252. last_tex_id.notNull() &&
  6253. last_tex_id != IMG_DEFAULT_AVATAR;
  6254. continue;
  6255. }
  6256. // When an avatar is changing clothes and not in Appearance mode, use
  6257. // the last-known good baked texture until it finishes the first render
  6258. // of the new layerset.
  6259. LLViewerTexLayerSet* layerset = getTexLayerSet(i);
  6260. bool layerset_invalid =
  6261. layerset && (!layerset->isLocalTextureDataAvailable() ||
  6262. !layerset->getViewerComposite()->isInitialized());
  6263. use_lkg_baked_layer[i] = !is_layer_baked[i] && layerset_invalid &&
  6264. last_tex_id.notNull() &&
  6265. last_tex_id != IMG_DEFAULT_AVATAR;
  6266. if (use_lkg_baked_layer[i])
  6267. {
  6268. layerset->setUpdatesEnabled(true);
  6269. }
  6270. }
  6271. bool local_appearance = isUsingLocalAppearance();
  6272. LLViewerFetchedTexture* baked_img;
  6273. for (U32 i = 0; i < count; ++i)
  6274. {
  6275. debugColorizeSubMeshes(i, LLColor4::white);
  6276. LLViewerTexLayerSet* layerset = getTexLayerSet(i);
  6277. if (use_lkg_baked_layer[i] && !local_appearance)
  6278. {
  6279. const LLUUID& last_tex_id = mBakedTextureDatas[i].mLastTextureID;
  6280. #if 0 // Causes failures to rebake...
  6281. baked_img =
  6282. LLViewerTextureManager::getFetchedTexture(last_tex_id);
  6283. #else
  6284. ETextureIndex te = ETextureIndex(mBakedTextureDatas[i].mTextureIndex);
  6285. std::string url = getImageURL(te, last_tex_id);
  6286. if (url.empty())
  6287. {
  6288. // Baked textures should be requested from the sim this avatar
  6289. // is on. JC
  6290. const LLHost target_host = getObjectHost();
  6291. if (!target_host.isOk())
  6292. {
  6293. llwarns << "invalid host for avatar: " << mID << llendl;
  6294. }
  6295. baked_img =
  6296. LLViewerTextureManager::getFetchedTextureFromHost(last_tex_id,
  6297. FTT_HOST_BAKE,
  6298. target_host);
  6299. }
  6300. else
  6301. {
  6302. baked_img =
  6303. LLViewerTextureManager::getFetchedTextureFromUrl(url,
  6304. FTT_SERVER_BAKE,
  6305. true,
  6306. LLGLTexture::BOOST_NONE,
  6307. LLViewerTexture::LOD_TEXTURE,
  6308. 0, 0,
  6309. last_tex_id);
  6310. }
  6311. #endif
  6312. mBakedTextureDatas[i].mIsUsed = true;
  6313. debugColorizeSubMeshes(i, LLColor4::red);
  6314. for (avatar_joint_mesh_list_t::iterator
  6315. iter = mBakedTextureDatas[i].mJointMeshes.begin(),
  6316. end = mBakedTextureDatas[i].mJointMeshes.end();
  6317. iter != end; ++iter)
  6318. {
  6319. LLAvatarJointMesh* mesh = *iter;
  6320. if (mesh)
  6321. {
  6322. mesh->setTexture(baked_img);
  6323. }
  6324. }
  6325. }
  6326. else if (!local_appearance && is_layer_baked[i])
  6327. {
  6328. baked_img =
  6329. LLViewerTextureManager::staticCast(getImage(mBakedTextureDatas[i].mTextureIndex,
  6330. 0),
  6331. true);
  6332. if (baked_img->getID() == mBakedTextureDatas[i].mLastTextureID)
  6333. {
  6334. // Even though the file may not be finished loading, we will
  6335. // consider it loaded and use it (rather than doing
  6336. // compositing).
  6337. useBakedTexture(baked_img->getID());
  6338. }
  6339. else
  6340. {
  6341. mBakedTextureDatas[i].mIsLoaded = false;
  6342. if (baked_img->getID() != IMG_INVISIBLE &&
  6343. (i == BAKED_HEAD || i == BAKED_UPPER || i == BAKED_LOWER))
  6344. {
  6345. baked_img->setLoadedCallback(onBakedTextureMasksLoaded,
  6346. MORPH_MASK_REQUESTED_DISCARD,
  6347. true, true,
  6348. new LLTextureMaskData(mID),
  6349. src_cb_list, paused);
  6350. }
  6351. baked_img->setLoadedCallback(onBakedTextureLoaded,
  6352. SWITCH_TO_BAKED_DISCARD,
  6353. false, false, new LLUUID(mID),
  6354. src_cb_list, paused);
  6355. }
  6356. }
  6357. else if (layerset && local_appearance)
  6358. {
  6359. debugColorizeSubMeshes(i, LLColor4::yellow);
  6360. layerset->createComposite();
  6361. layerset->setUpdatesEnabled(true);
  6362. mBakedTextureDatas[i].mIsUsed = false;
  6363. for (avatar_joint_mesh_list_t::iterator
  6364. iter = mBakedTextureDatas[i].mJointMeshes.begin(),
  6365. end = mBakedTextureDatas[i].mJointMeshes.end();
  6366. iter != end; ++iter)
  6367. {
  6368. LLAvatarJointMesh* mesh = *iter;
  6369. if (mesh)
  6370. {
  6371. mesh->setLayerSet(layerset);
  6372. }
  6373. }
  6374. }
  6375. else
  6376. {
  6377. debugColorizeSubMeshes(i, LLColor4::blue);
  6378. }
  6379. }
  6380. // Set texture and color of hair manually if we are not using a baked
  6381. // image. This can happen while loading hair for yourself, or for clients
  6382. // that did not bake a hair texture. Still needed for yourself after 1.22
  6383. // is deprecated.
  6384. if (!is_layer_baked[BAKED_HAIR] || mIsEditingAppearance)
  6385. {
  6386. const LLColor4 color = mTexHairColor ? mTexHairColor->getColor()
  6387. : LLColor4(1, 1, 1, 1);
  6388. LLViewerTexture* hair_img = getImage(TEX_HAIR, 0);
  6389. for (avatar_joint_mesh_list_t::iterator
  6390. iter = mBakedTextureDatas[BAKED_HAIR].mJointMeshes.begin(),
  6391. end = mBakedTextureDatas[BAKED_HAIR].mJointMeshes.end();
  6392. iter != end; ++iter)
  6393. {
  6394. LLAvatarJointMesh* mesh = *iter;
  6395. if (mesh)
  6396. {
  6397. mesh->setColor(color);
  6398. mesh->setTexture(hair_img);
  6399. }
  6400. }
  6401. }
  6402. if (isSelf())
  6403. {
  6404. for (LLAvatarAppearanceDictionary::BakedTextures::const_iterator
  6405. baked_iter = gAvatarAppDictp->getBakedTextures().begin(),
  6406. end = gAvatarAppDictp->getBakedTextures().end();
  6407. baked_iter != end; ++baked_iter)
  6408. {
  6409. const EBakedTextureIndex baked_idx = baked_iter->first;
  6410. const LLAvatarAppearanceDictionary::BakedEntry* baked_dict =
  6411. baked_iter->second;
  6412. for (texture_vec_t::const_iterator
  6413. local_tex_iter = baked_dict->mLocalTextures.begin(),
  6414. end2 = baked_dict->mLocalTextures.end();
  6415. local_tex_iter != end2; ++local_tex_iter)
  6416. {
  6417. const ETextureIndex texture_index = *local_tex_iter;
  6418. bool is_baked_ready =
  6419. is_layer_baked[baked_idx] &&
  6420. mBakedTextureDatas[baked_idx].mIsLoaded;
  6421. setBakedReady(texture_index, is_baked_ready);
  6422. }
  6423. }
  6424. }
  6425. // removeMissingBakedTextures() calls back into this routine when something
  6426. // is removed, and would blow up the stack without this static flag trick.
  6427. static bool call_remove_missing = true;
  6428. if (call_remove_missing)
  6429. {
  6430. call_remove_missing = false;
  6431. // May call back into this function if anything is removed:
  6432. removeMissingBakedTextures();
  6433. call_remove_missing = true;
  6434. }
  6435. }
  6436. // Hides the mesh joints if attachments are using baked textures
  6437. void LLVOAvatar::updateMeshVisibility()
  6438. {
  6439. bool bake_flag[BAKED_NUM_INDICES];
  6440. memset(bake_flag, 0, BAKED_NUM_INDICES * sizeof(bool));
  6441. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  6442. {
  6443. LLViewerObject* objectp = mAttachedObjectsVector[i].first;
  6444. if (!objectp || objectp->isDead())
  6445. {
  6446. continue;
  6447. }
  6448. for (U8 te = 0, entries = objectp->getNumTEs(); te < entries; ++te)
  6449. {
  6450. LLTextureEntry* tep = objectp->getTE(te);
  6451. if (!tep) continue;
  6452. const LLUUID& tex_id = tep->getID();
  6453. bake_flag[BAKED_HEAD] |= tex_id == IMG_USE_BAKED_HEAD;
  6454. bake_flag[BAKED_UPPER] |= tex_id == IMG_USE_BAKED_UPPER;
  6455. bake_flag[BAKED_LOWER] |= tex_id == IMG_USE_BAKED_LOWER;
  6456. bake_flag[BAKED_HAIR] |= tex_id == IMG_USE_BAKED_HAIR;
  6457. bake_flag[BAKED_EYES] |= tex_id == IMG_USE_BAKED_EYES;
  6458. bake_flag[BAKED_SKIRT] |= tex_id == IMG_USE_BAKED_SKIRT;
  6459. bake_flag[BAKED_LEFT_ARM] |= tex_id == IMG_USE_BAKED_LEFTARM;
  6460. bake_flag[BAKED_LEFT_LEG] |= tex_id == IMG_USE_BAKED_LEFTLEG;
  6461. bake_flag[BAKED_AUX1] |= tex_id == IMG_USE_BAKED_AUX1;
  6462. bake_flag[BAKED_AUX2] |= tex_id == IMG_USE_BAKED_AUX2;
  6463. bake_flag[BAKED_AUX3] |= tex_id == IMG_USE_BAKED_AUX3;
  6464. }
  6465. LLViewerObject::const_child_list_t& child_list =
  6466. objectp->getChildren();
  6467. for (LLViewerObject::child_list_t::const_iterator
  6468. it = child_list.begin(), end = child_list.end();
  6469. it != end; ++it)
  6470. {
  6471. LLViewerObject* childp = *it;
  6472. if (!childp || childp->isDead()) continue;
  6473. for (U8 te = 0, entries = childp->getNumTEs(); te < entries; ++te)
  6474. {
  6475. LLTextureEntry* tep = childp->getTE(te);
  6476. if (!tep) continue;
  6477. const LLUUID& tex_id = tep->getID();
  6478. bake_flag[BAKED_HEAD] |= tex_id == IMG_USE_BAKED_HEAD;
  6479. bake_flag[BAKED_UPPER] |= tex_id == IMG_USE_BAKED_UPPER;
  6480. bake_flag[BAKED_LOWER] |= tex_id == IMG_USE_BAKED_LOWER;
  6481. bake_flag[BAKED_HAIR] |= tex_id == IMG_USE_BAKED_HAIR;
  6482. bake_flag[BAKED_EYES] |= tex_id == IMG_USE_BAKED_EYES;
  6483. bake_flag[BAKED_SKIRT] |= tex_id == IMG_USE_BAKED_SKIRT;
  6484. bake_flag[BAKED_LEFT_ARM] |= tex_id == IMG_USE_BAKED_LEFTARM;
  6485. bake_flag[BAKED_LEFT_LEG] |= tex_id == IMG_USE_BAKED_LEFTLEG;
  6486. bake_flag[BAKED_AUX1] |= tex_id == IMG_USE_BAKED_AUX1;
  6487. bake_flag[BAKED_AUX2] |= tex_id == IMG_USE_BAKED_AUX2;
  6488. bake_flag[BAKED_AUX3] |= tex_id == IMG_USE_BAKED_AUX3;
  6489. }
  6490. }
  6491. }
  6492. LL_DEBUGS("Avatar") << "Baked mesh status for avatar "
  6493. << getFullname(true) << ":" << " head="
  6494. << bake_flag[BAKED_HEAD] << " - upper="
  6495. << bake_flag[BAKED_UPPER] << " - lower="
  6496. << bake_flag[BAKED_LOWER] << " - eyes="
  6497. << bake_flag[BAKED_EYES] << " - hair="
  6498. << bake_flag[BAKED_HAIR] << " - skirt="
  6499. << bake_flag[BAKED_LEFT_ARM] << " - leftarm="
  6500. << bake_flag[BAKED_LEFT_LEG] << " - leftleg="
  6501. << bake_flag[BAKED_AUX1] << " - aux1="
  6502. << bake_flag[BAKED_AUX2] << " - aux2="
  6503. << bake_flag[BAKED_AUX3] << " - aux3="
  6504. << bake_flag[BAKED_SKIRT] << LL_ENDL;
  6505. for (S32 i = 0, count = mMeshLOD.size(); i < count; ++i)
  6506. {
  6507. LLAvatarJoint* joint = mMeshLOD[i];
  6508. if (!joint) continue;
  6509. if (i == MESH_ID_HEAD)
  6510. {
  6511. joint->setVisible(!bake_flag[BAKED_HEAD], true);
  6512. }
  6513. else if (i == MESH_ID_UPPER_BODY)
  6514. {
  6515. joint->setVisible(!bake_flag[BAKED_UPPER], true);
  6516. }
  6517. else if (i == MESH_ID_LOWER_BODY)
  6518. {
  6519. joint->setVisible(!bake_flag[BAKED_LOWER], true);
  6520. }
  6521. else if (i == MESH_ID_HAIR)
  6522. {
  6523. joint->setVisible(!bake_flag[BAKED_HAIR], true);
  6524. }
  6525. else if (i == MESH_ID_EYEBALL_LEFT)
  6526. {
  6527. joint->setVisible(!bake_flag[BAKED_EYES], true);
  6528. }
  6529. else if (i == MESH_ID_EYEBALL_RIGHT)
  6530. {
  6531. joint->setVisible(!bake_flag[BAKED_EYES], true);
  6532. }
  6533. else if (i == MESH_ID_EYELASH)
  6534. {
  6535. joint->setVisible(!bake_flag[BAKED_HEAD], true);
  6536. }
  6537. else if (i == MESH_ID_SKIRT)
  6538. {
  6539. joint->setVisible(!bake_flag[BAKED_SKIRT], true);
  6540. }
  6541. }
  6542. }
  6543. //virtual
  6544. void LLVOAvatar::setLocalTexture(ETextureIndex type, LLViewerTexture* in_tex,
  6545. bool baked_version_ready, U32 index)
  6546. {
  6547. // Invalid for anyone but self
  6548. llassert(false);
  6549. }
  6550. //virtual
  6551. void LLVOAvatar::setBakedReady(LLAvatarAppearanceDefines::ETextureIndex type,
  6552. bool baked_version_exists, U32 index)
  6553. {
  6554. // Invalid for anyone but self
  6555. llassert(false);
  6556. }
  6557. void LLVOAvatar::addChat(const LLChat& chat)
  6558. {
  6559. std::deque<LLChat>::iterator chat_iter;
  6560. mChats.emplace_back(chat);
  6561. S32 chat_length = 0;
  6562. for (chat_iter = mChats.begin(); chat_iter != mChats.end(); ++chat_iter)
  6563. {
  6564. chat_length += chat_iter->mText.size();
  6565. }
  6566. // Remove any excess chat
  6567. chat_iter = mChats.begin();
  6568. while ((chat_length > MAX_BUBBLE_CHAT_LENGTH ||
  6569. (S32)mChats.size() > MAX_BUBBLE_CHAT_UTTERANCES) &&
  6570. chat_iter != mChats.end())
  6571. {
  6572. chat_length -= chat_iter->mText.size();
  6573. mChats.pop_front();
  6574. chat_iter = mChats.begin();
  6575. }
  6576. mChatTimer.reset();
  6577. }
  6578. void LLVOAvatar::clearChat()
  6579. {
  6580. mChats.clear();
  6581. }
  6582. // Adds a morph mask to the appropriate baked texture structure
  6583. void LLVOAvatar::applyMorphMask(U8* tex_data, S32 width, S32 height,
  6584. S32 num_components,
  6585. LLAvatarAppearanceDefines::EBakedTextureIndex index)
  6586. {
  6587. if (index >= BAKED_NUM_INDICES)
  6588. {
  6589. llwarns << "invalid baked texture index passed to applyMorphMask"
  6590. << llendl;
  6591. return;
  6592. }
  6593. for (morph_list_t::const_iterator
  6594. iter = mBakedTextureDatas[index].mMaskedMorphs.begin(),
  6595. end = mBakedTextureDatas[index].mMaskedMorphs.end();
  6596. iter != end; ++iter)
  6597. {
  6598. const LLMaskedMorph* masked_morph = *iter;
  6599. LLPolyMorphTarget* morph_target =
  6600. masked_morph->mMorphTarget->asPolyMorphTarget();
  6601. if (morph_target)
  6602. {
  6603. morph_target->applyMask(tex_data, width, height, num_components,
  6604. masked_morph->mInvert);
  6605. }
  6606. }
  6607. }
  6608. // Releases any component texture UUIDs for which we have a baked texture
  6609. // ! BACKWARDS COMPATIBILITY !
  6610. // This is only called for non-self avatars, it can be taken out once component
  6611. // textures are not communicated by non-self avatars.
  6612. void LLVOAvatar::releaseComponentTextures()
  6613. {
  6614. // ! BACKWARDS COMPATIBILITY !
  6615. // Detect if the baked hair texture actually was not sent, and if so set to
  6616. // default
  6617. if (isTextureDefined(TEX_HAIR_BAKED) && getImage(TEX_HAIR_BAKED, 0) &&
  6618. getImage(TEX_SKIRT_BAKED, 0) &&
  6619. getImage(TEX_HAIR_BAKED, 0)->getID() == getImage(TEX_SKIRT_BAKED, 0)->getID())
  6620. {
  6621. if (getImage(TEX_HAIR_BAKED, 0)->getID() != IMG_INVISIBLE)
  6622. {
  6623. // Regression case of messaging system. Expected 21 textures,
  6624. // received 20. Last texture is not valid so set to default.
  6625. setTETexture(TEX_HAIR_BAKED, IMG_DEFAULT_AVATAR);
  6626. }
  6627. }
  6628. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  6629. for (U8 baked_idx = 0; baked_idx < BAKED_NUM_INDICES; ++baked_idx)
  6630. {
  6631. const LLAvatarAppearanceDictionary::BakedEntry* baked_entry =
  6632. gAvatarAppDictp->getBakedTexture((EBakedTextureIndex)baked_idx);
  6633. // Skip if this is a skirt and av is not wearing one, or if we do not
  6634. // have a baked texture UUID
  6635. if ((baked_idx != BAKED_SKIRT || wearing_skirt) &&
  6636. !isTextureDefined(baked_entry->mTextureIndex))
  6637. {
  6638. continue;
  6639. }
  6640. for (U8 texture = 0, count = baked_entry->mLocalTextures.size();
  6641. texture < count; ++texture)
  6642. {
  6643. const U8 te = (ETextureIndex)baked_entry->mLocalTextures[texture];
  6644. setTETexture(te, IMG_DEFAULT_AVATAR);
  6645. }
  6646. }
  6647. }
  6648. void LLVOAvatar::dumpAvatarTEs(const std::string& context) const
  6649. {
  6650. llinfos << (isSelf() ? "Self: " : "Other: ") << context << llendl;
  6651. std::string message;
  6652. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  6653. iter = gAvatarAppDictp->getTextures().begin(),
  6654. end = gAvatarAppDictp->getTextures().end();
  6655. iter != end; ++iter)
  6656. {
  6657. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  6658. iter->second;
  6659. // *TODO: MULTI-WEARABLE: handle multiple textures for self
  6660. const LLViewerTexture* te_image = getImage(iter->first, 0);
  6661. if (!te_image)
  6662. {
  6663. message = "null pointer";
  6664. }
  6665. else if (te_image->getID().isNull())
  6666. {
  6667. message = "null UUID";
  6668. }
  6669. else if (te_image->getID() == IMG_DEFAULT)
  6670. {
  6671. message = "IMG_DEFAULT";
  6672. }
  6673. else if (te_image->getID() == IMG_INVISIBLE)
  6674. {
  6675. message = "IMG_INVISIBLE";
  6676. }
  6677. else if (te_image->getID() == IMG_DEFAULT_AVATAR)
  6678. {
  6679. message = "IMG_DEFAULT_AVATAR";
  6680. }
  6681. else
  6682. {
  6683. message = te_image->getID().asString();
  6684. }
  6685. llinfos << " " << t_dict->mName << ": " << message << llendl;
  6686. }
  6687. }
  6688. void LLVOAvatar::clampAttachmentPositions()
  6689. {
  6690. if (isDead())
  6691. {
  6692. return;
  6693. }
  6694. for (attachment_map_t::iterator iter = mAttachmentPoints.begin(),
  6695. end = mAttachmentPoints.end();
  6696. iter != end; ++iter)
  6697. {
  6698. LLViewerJointAttachment* attachment = iter->second;
  6699. if (attachment)
  6700. {
  6701. attachment->clampObjectPosition();
  6702. }
  6703. }
  6704. }
  6705. bool LLVOAvatar::hasHUDAttachment() const
  6706. {
  6707. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(),
  6708. end = mAttachmentPoints.end();
  6709. iter != end; ++iter)
  6710. {
  6711. LLViewerJointAttachment* attachment = iter->second;
  6712. if (attachment && attachment->getIsHUDAttachment() &&
  6713. attachment->getNumObjects() > 0)
  6714. {
  6715. return true;
  6716. }
  6717. }
  6718. return false;
  6719. }
  6720. LLBBox LLVOAvatar::getHUDBBox() const
  6721. {
  6722. LLBBox bbox;
  6723. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  6724. {
  6725. const LLViewerObject* object = mAttachedObjectsVector[i].first;
  6726. if (object && object->isHUDAttachment())
  6727. {
  6728. // Initialize bounding box to contain identity orientation and
  6729. // center point for attached object
  6730. bbox.addPointLocal(object->getPosition());
  6731. // add rotated bounding box for attached object
  6732. bbox.addBBoxAgent(object->getBoundingBoxAgent());
  6733. LLViewerObject::const_child_list_t& child_list =
  6734. object->getChildren();
  6735. for (LLViewerObject::child_list_t::const_iterator
  6736. iter = child_list.begin(), end = child_list.end();
  6737. iter != end; ++iter)
  6738. {
  6739. const LLViewerObject* child_objectp = *iter;
  6740. bbox.addBBoxAgent(child_objectp->getBoundingBoxAgent());
  6741. }
  6742. }
  6743. }
  6744. return bbox;
  6745. }
  6746. void LLVOAvatar::onFirstTEMessageReceived()
  6747. {
  6748. if (!mFirstTEMessageReceived)
  6749. {
  6750. mFirstTEMessageReceived = true;
  6751. uuid_list_t* src_cb_list = NULL;
  6752. bool paused = false;
  6753. if (!isSelf())
  6754. {
  6755. src_cb_list = &mCallbackTextureList;
  6756. paused = !isVisible();
  6757. }
  6758. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  6759. {
  6760. const bool layer_baked =
  6761. isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
  6762. // Use any baked textures that we have even if they have not
  6763. // downloaded yet (that is, do not do a transition from unbaked to
  6764. // baked).
  6765. if (layer_baked)
  6766. {
  6767. LLViewerFetchedTexture* image =
  6768. LLViewerTextureManager::staticCast(getImage(mBakedTextureDatas[i].mTextureIndex,
  6769. 0),
  6770. true);
  6771. mBakedTextureDatas[i].mLastTextureID = image->getID();
  6772. // If we have more than one texture for the other baked layers,
  6773. // we'll want to call this for them too.
  6774. if (image->getID() != IMG_INVISIBLE &&
  6775. (i == BAKED_HEAD || i == BAKED_UPPER || i == BAKED_LOWER))
  6776. {
  6777. image->setLoadedCallback(onBakedTextureMasksLoaded,
  6778. MORPH_MASK_REQUESTED_DISCARD,
  6779. true, true,
  6780. new LLTextureMaskData(mID),
  6781. src_cb_list, paused);
  6782. }
  6783. image->setLoadedCallback(onInitialBakedTextureLoaded,
  6784. MAX_DISCARD_LEVEL, false, false,
  6785. new LLUUID(mID), src_cb_list, paused);
  6786. }
  6787. }
  6788. mMeshTexturesDirty = true;
  6789. gPipeline.markGLRebuild(this);
  6790. LL_DEBUGS("MarkGLRebuild") << "Marked for GL rebuild: " << std::hex
  6791. << (intptr_t)this << std::dec << " ("
  6792. << getFullname(true) << ")" << LL_ENDL;
  6793. }
  6794. }
  6795. bool LLVOAvatar::visualParamWeightsAreDefault()
  6796. {
  6797. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  6798. for (LLVisualParam* param = getFirstVisualParam(); param;
  6799. param = getNextVisualParam())
  6800. {
  6801. if (param->isTweakable())
  6802. {
  6803. LLViewerVisualParam* vparam = param->asViewerVisualParam();
  6804. bool is_skirt_param =
  6805. vparam &&
  6806. vparam->getWearableType() == LLWearableType::WT_SKIRT;
  6807. // We have to ignore whether skirt weights are default, if we are
  6808. // not actually wearing a skirt
  6809. if ((wearing_skirt || !is_skirt_param) &&
  6810. param->getWeight() != param->getDefaultWeight())
  6811. {
  6812. return false;
  6813. }
  6814. }
  6815. }
  6816. return true;
  6817. }
  6818. struct LLAppearanceMessageContents : public LLRefCount
  6819. {
  6820. LLAppearanceMessageContents()
  6821. : mAppearanceVersion(-1),
  6822. mParamAppearanceVersion(-1),
  6823. mCOFVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
  6824. {
  6825. }
  6826. // Note: the first member variable is 32 bits in order to align on 64 bits
  6827. // for the next variable, counting the 32 bits counter from LLRefCount. HB
  6828. S32 mCOFVersion;
  6829. S32 mAppearanceVersion;
  6830. S32 mParamAppearanceVersion;
  6831. std::vector<F32> mParamWeights;
  6832. std::vector<LLVisualParam*> mParams;
  6833. LLTEContents mTEContents;
  6834. LLVector3 mHoverOffset;
  6835. bool mHoverOffsetWasSet;
  6836. };
  6837. void LLVOAvatar::parseAppearanceMessage(LLMessageSystem* msg,
  6838. LLAppearanceMessageContents& contents)
  6839. {
  6840. parseTEMessage(msg, _PREHASH_ObjectData, -1, contents.mTEContents);
  6841. // Parse the AppearanceData field, if any.
  6842. if (msg->has(_PREHASH_AppearanceData))
  6843. {
  6844. U8 av_u8;
  6845. msg->getU8Fast(_PREHASH_AppearanceData, _PREHASH_AppearanceVersion,
  6846. av_u8, 0);
  6847. contents.mAppearanceVersion = av_u8;
  6848. LL_DEBUGS("Avatar") << "Avatar: " << getFullname(true)
  6849. << " - appversion set by AppearanceData field: "
  6850. << contents.mAppearanceVersion << LL_ENDL;
  6851. msg->getS32Fast(_PREHASH_AppearanceData, _PREHASH_CofVersion,
  6852. contents.mCOFVersion, 0);
  6853. # if 0 // For future use:
  6854. msg->getU32Fast(_PREHASH_AppearanceData, _PREHASH_Flags,
  6855. appearance_flags, 0);
  6856. # endif
  6857. }
  6858. // Parse the AppearanceData field, if any.
  6859. contents.mHoverOffsetWasSet = false;
  6860. if (msg->has(_PREHASH_AppearanceHover))
  6861. {
  6862. LLVector3 hover;
  6863. msg->getVector3Fast(_PREHASH_AppearanceHover, _PREHASH_HoverHeight,
  6864. hover);
  6865. LL_DEBUGS("Avatar") << "Avatar: " << getFullname(true)
  6866. << " - hover received: " << hover.mV[VX] << ","
  6867. << hover.mV[VY] << "," << hover.mV[VZ] << LL_ENDL;
  6868. contents.mHoverOffset = hover;
  6869. contents.mHoverOffsetWasSet = true;
  6870. }
  6871. // Parse visual params, if any.
  6872. S32 num_blocks = msg->getNumberOfBlocksFast(_PREHASH_VisualParam);
  6873. if (num_blocks > 1)
  6874. {
  6875. LL_DEBUGS("Avatar") << getFullname(true)
  6876. << ": handle visual params, num_blocks "
  6877. << num_blocks << LL_ENDL;
  6878. LLVisualParam* param = getFirstVisualParam();
  6879. // if this ever fires, we should do the same as when num_blocks <= 1:
  6880. llassert(param);
  6881. if (!param)
  6882. {
  6883. llwarns << "No visual parameter !" << llendl;
  6884. }
  6885. else
  6886. {
  6887. for (S32 i = 0; i < num_blocks; ++i)
  6888. {
  6889. // Should not be any of group
  6890. // VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
  6891. while (param &&
  6892. param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE)
  6893. {
  6894. param = getNextVisualParam();
  6895. }
  6896. if (!param)
  6897. {
  6898. // More visual params supplied than expected; just process
  6899. // what we know about
  6900. break;
  6901. }
  6902. U8 value;
  6903. msg->getU8Fast(_PREHASH_VisualParam, _PREHASH_ParamValue,
  6904. value, i);
  6905. F32 new_weight = U8_to_F32(value, param->getMinWeight(),
  6906. param->getMaxWeight());
  6907. contents.mParamWeights.push_back(new_weight);
  6908. contents.mParams.push_back(param);
  6909. param = getNextVisualParam();
  6910. }
  6911. }
  6912. }
  6913. LLVisualParam* appearance_version_param = getVisualParam(11000);
  6914. if (appearance_version_param)
  6915. {
  6916. std::vector<LLVisualParam*>::iterator it =
  6917. std::find(contents.mParams.begin(), contents.mParams.end(),
  6918. appearance_version_param);
  6919. if (it != contents.mParams.end())
  6920. {
  6921. S32 index = it - contents.mParams.begin();
  6922. contents.mParamAppearanceVersion =
  6923. ll_round(contents.mParamWeights[index]);
  6924. LL_DEBUGS("Avatar") << "Index: " << index
  6925. << "appversion req by appearance_version param: "
  6926. << contents.mParamAppearanceVersion << LL_ENDL;
  6927. }
  6928. }
  6929. }
  6930. bool resolve_appearance_version(const LLAppearanceMessageContents& contents,
  6931. S32& appearance_version)
  6932. {
  6933. appearance_version = -1;
  6934. if (contents.mAppearanceVersion >= 0 &&
  6935. contents.mParamAppearanceVersion >= 0 &&
  6936. contents.mAppearanceVersion != contents.mParamAppearanceVersion)
  6937. {
  6938. llwarns << "inconsistent appearance_version settings - field: "
  6939. << contents.mAppearanceVersion << ", param: "
  6940. << contents.mParamAppearanceVersion << llendl;
  6941. return false;
  6942. }
  6943. if (contents.mParamAppearanceVersion >= 0) // use visual param if available.
  6944. {
  6945. appearance_version = contents.mParamAppearanceVersion;
  6946. }
  6947. if (contents.mAppearanceVersion >= 0)
  6948. {
  6949. appearance_version = contents.mAppearanceVersion;
  6950. }
  6951. if (appearance_version < 0) // still not set, go with 0.
  6952. {
  6953. appearance_version = 0;
  6954. }
  6955. LL_DEBUGS("Avatar") << "appearance version info - field "
  6956. << contents.mAppearanceVersion
  6957. << " param: " << contents.mParamAppearanceVersion
  6958. << " final: " << appearance_version << LL_ENDL;
  6959. return true;
  6960. }
  6961. void LLVOAvatar::processAvatarAppearance(LLMessageSystem* msg)
  6962. {
  6963. static LLCachedControl<bool> block_messages(gSavedSettings,
  6964. "BlockAvatarAppearanceMessages");
  6965. if (block_messages)
  6966. {
  6967. llwarns << "DEBUG MODE: Blocking AvatarAppearance message for: "
  6968. << getFullname(true) << llendl;
  6969. return;
  6970. }
  6971. if (isSelf() && mIsEditingAppearance)
  6972. {
  6973. llinfos << "Ignoring appearance message while in appearance edit mode."
  6974. << llendl;
  6975. return;
  6976. }
  6977. LL_DEBUGS("Avatar") << getFullname(true) << "("
  6978. << (isSelf() ? "self" : mID.asString())
  6979. << (!mFirstAppearanceMessageReceived ? ") - FIRST" : ") -")
  6980. << " AvatarAppearance message processing" << LL_ENDL;
  6981. LLPointer<LLAppearanceMessageContents> contents(new LLAppearanceMessageContents);
  6982. parseAppearanceMessage(msg, *contents);
  6983. S32 num_params = contents->mParamWeights.size();
  6984. if (num_params <= 1)
  6985. {
  6986. // In this case, we have no reliable basis for knowing appearance
  6987. // version, which may cause us to look for baked textures in the wrong
  6988. // place and flag them as missing assets.
  6989. llinfos << "Ignoring appearance message due to lack of parameters"
  6990. << llendl;
  6991. return;
  6992. }
  6993. S32 appearance_version;
  6994. if (!resolve_appearance_version(*contents, appearance_version))
  6995. {
  6996. llwarns << "Bad appearance version info, discarding." << llendl;
  6997. return;
  6998. }
  6999. S32 this_update_cof_version = contents->mCOFVersion;
  7000. S32 last_update_request_cof_version = mLastUpdateRequestCOFVersion;
  7001. // Only now that we have result of appearance_version can we decide whether
  7002. // to bail out.
  7003. if (isSelf())
  7004. {
  7005. LL_DEBUGS("Avatar") << "this_update_cof_version = "
  7006. << this_update_cof_version
  7007. << " - last_update_request_cof_version = "
  7008. << last_update_request_cof_version
  7009. << " - my_cof_version = "
  7010. << gAppearanceMgr.getCOFVersion() << LL_ENDL;
  7011. if (!LLVOAvatarSelf::canUseServerBaking())
  7012. {
  7013. llwarns << "Received AvatarAppearance message for self in non-server-bake region"
  7014. << llendl;
  7015. }
  7016. if (mFirstTEMessageReceived && appearance_version == 0)
  7017. {
  7018. return;
  7019. }
  7020. // Check for stale update.
  7021. if (appearance_version > 0 &&
  7022. this_update_cof_version < last_update_request_cof_version)
  7023. {
  7024. llwarns << "Stale appearance update, wanted version "
  7025. << last_update_request_cof_version << ", got "
  7026. << this_update_cof_version << ". Ignoring." << llendl;
  7027. return;
  7028. }
  7029. }
  7030. // No backsies zone, if we get here, the message should be valid and usable
  7031. if (appearance_version > 0)
  7032. {
  7033. mLastUpdateReceivedCOFVersion = this_update_cof_version;
  7034. }
  7035. setIsUsingServerBakes(appearance_version > 0);
  7036. mLastProcessedAppearance = contents;
  7037. applyParsedAppearanceMessage(*contents);
  7038. }
  7039. void LLVOAvatar::applyParsedAppearanceMessage(LLAppearanceMessageContents& contents,
  7040. bool slam_params)
  7041. {
  7042. S32 num_params = contents.mParamWeights.size();
  7043. ESex old_sex = getSex();
  7044. if (applyParsedTEMessage(contents.mTEContents) > 0 && isChanged(TEXTURE))
  7045. {
  7046. mVisualComplexityStale = true;
  7047. }
  7048. // Prevent the overwriting of valid baked textures with invalid baked
  7049. // textures
  7050. for (U8 baked_idx = 0, count = mBakedTextureDatas.size();
  7051. baked_idx < count; ++baked_idx)
  7052. {
  7053. if (baked_idx != BAKED_SKIRT &&
  7054. baked_idx != BAKED_LEFT_ARM && baked_idx != BAKED_LEFT_LEG &&
  7055. baked_idx != BAKED_AUX1 && baked_idx != BAKED_AUX2 &&
  7056. baked_idx != BAKED_AUX3 &&
  7057. !isTextureDefined(mBakedTextureDatas[baked_idx].mTextureIndex) &&
  7058. mBakedTextureDatas[baked_idx].mLastTextureID != IMG_DEFAULT)
  7059. {
  7060. setTEImage(mBakedTextureDatas[baked_idx].mTextureIndex,
  7061. LLViewerTextureManager::getFetchedTexture(mBakedTextureDatas[baked_idx].mLastTextureID,
  7062. FTT_DEFAULT,
  7063. true,
  7064. LLGLTexture::BOOST_NONE,
  7065. LLViewerTexture::LOD_TEXTURE));
  7066. }
  7067. }
  7068. bool is_first_appearance_message = !mFirstAppearanceMessageReceived;
  7069. mFirstAppearanceMessageReceived = true;
  7070. // "Runway" fix was "if (!is_first_appearance_message)" which means it
  7071. // would be called on second appearance message - Probably wrong.
  7072. if (is_first_appearance_message)
  7073. {
  7074. onFirstTEMessageReceived();
  7075. }
  7076. setCompositeUpdatesEnabled(false);
  7077. gPipeline.markGLRebuild(this);
  7078. LL_DEBUGS("MarkGLRebuild") << "Marked for GL rebuild: " << std::hex
  7079. << (intptr_t)this << std::dec << " ("
  7080. << getFullname(true) << ")" << LL_ENDL;
  7081. // Apply visual params
  7082. if (num_params > 1)
  7083. {
  7084. LL_DEBUGS("Avatar") << getFullname(true)
  7085. << ": handle visual params, num_blocks "
  7086. << num_params << LL_ENDL;
  7087. bool params_changed = false;
  7088. bool interp_params = false;
  7089. for (S32 i = 0; i < num_params; ++i)
  7090. {
  7091. LLVisualParam* param = contents.mParams[i];
  7092. if (!param) continue; // Paranoia
  7093. F32 new_weight = contents.mParamWeights[i];
  7094. if (is_first_appearance_message ||
  7095. param->getWeight() != new_weight)
  7096. {
  7097. params_changed = true;
  7098. if (is_first_appearance_message || slam_params)
  7099. {
  7100. param->setWeight(new_weight, false);
  7101. }
  7102. else
  7103. {
  7104. interp_params = true;
  7105. param->setAnimationTarget(new_weight, false);
  7106. }
  7107. }
  7108. }
  7109. // Do not worry about VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
  7110. const S32 expected_tweakable_count =
  7111. getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TWEAKABLE);
  7112. if (num_params != expected_tweakable_count)
  7113. {
  7114. llwarns_once << getFullname(true)
  7115. << " - Number of params in AvatarAppearance msg ("
  7116. << num_params
  7117. << ") does not match number of tweakable params in avatar xml file ("
  7118. << expected_tweakable_count << "). Processing what we can."
  7119. << llendl;
  7120. }
  7121. if (params_changed)
  7122. {
  7123. if (interp_params)
  7124. {
  7125. startAppearanceAnimation();
  7126. }
  7127. updateVisualParams();
  7128. ESex new_sex = getSex();
  7129. if (old_sex != new_sex)
  7130. {
  7131. updateSexDependentLayerSets(false);
  7132. }
  7133. }
  7134. }
  7135. else
  7136. {
  7137. llwarns << getFullname(true)
  7138. << " - AvatarAppearance msg received without any visual parameter."
  7139. << llendl;
  7140. // This is not really a problem if we already have a non-default shape
  7141. if (visualParamWeightsAreDefault())
  7142. {
  7143. if (sendAvatarTexturesRequest())
  7144. {
  7145. // Re-requested appearance, hoping that it comes back with a
  7146. // shape next time
  7147. llinfos << "Re-requested AvatarAppearance for "
  7148. << getFullname(true) << llendl;
  7149. }
  7150. }
  7151. else
  7152. {
  7153. // We do not really care.
  7154. llinfos << "It is OK, we already have a non-default shape for "
  7155. << getFullname(true) << llendl;
  7156. }
  7157. }
  7158. // Ignore hover updates for self because we have a more authoritative value
  7159. // in the preferences.
  7160. if (!isSelf())
  7161. {
  7162. if (contents.mHoverOffsetWasSet)
  7163. {
  7164. // Got an update for some other avatar.
  7165. setHoverOffset(contents.mHoverOffset);
  7166. LL_DEBUGS("Avatar") << "Avatar: " << getFullname(true)
  7167. << " - Setting hover from message: "
  7168. << contents.mHoverOffset.mV[VZ] << "m"
  7169. << LL_ENDL;
  7170. }
  7171. else
  7172. {
  7173. // If we do not get a value at all, we are presumably in a region
  7174. // that does not support hover height.
  7175. LL_DEBUGS("Avatar") << "Avatar: " << getFullname(true)
  7176. << " - Zeroing hover because not defined in appearance message"
  7177. << LL_ENDL;
  7178. setHoverOffset(LLVector3::zero);
  7179. }
  7180. }
  7181. setCompositeUpdatesEnabled(true);
  7182. sAvatarCullingDirty = true;
  7183. if (isSelf())
  7184. {
  7185. mUseLocalAppearance = false;
  7186. }
  7187. updateMeshTextures();
  7188. refreshAttachmentBakes();
  7189. }
  7190. void LLVOAvatar::refreshAttachmentBakes()
  7191. {
  7192. LL_DEBUGS("AttachmentBakes") << "Refreshing attachments bake textures for avatar "
  7193. << getFullname(true) << LL_ENDL;
  7194. // Refresh bakes on any attached objects
  7195. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  7196. {
  7197. LLViewerObject* objectp = mAttachedObjectsVector[i].first;
  7198. if (!objectp || objectp->isDead()) continue;
  7199. objectp->refreshBakeTexture();
  7200. LLViewerObject::const_child_list_t& child_list =
  7201. objectp->getChildren();
  7202. for (LLViewerObject::child_list_t::const_iterator
  7203. it = child_list.begin(), end = child_list.end();
  7204. it != end; ++it)
  7205. {
  7206. LLViewerObject* childp = *it;
  7207. if (childp || childp->isDead())
  7208. {
  7209. childp->refreshBakeTexture();
  7210. }
  7211. }
  7212. }
  7213. updateMeshVisibility();
  7214. }
  7215. //static
  7216. void LLVOAvatar::getAnimLabels(std::vector<std::string>* labels)
  7217. {
  7218. labels->reserve(gUserAnimStatesCount);
  7219. for (S32 i = 0; i < gUserAnimStatesCount; ++i)
  7220. {
  7221. labels->emplace_back(LLAnimStateLabels::getStateLabel(gUserAnimStates[i].mName));
  7222. }
  7223. // Special case to trigger away (AFK) state
  7224. labels->emplace_back("Away From Keyboard");
  7225. }
  7226. //static
  7227. void LLVOAvatar::getAnimNames(std::vector<std::string>* names)
  7228. {
  7229. names->reserve(gUserAnimStatesCount);
  7230. for (S32 i = 0; i < gUserAnimStatesCount; ++i)
  7231. {
  7232. names->emplace_back(gUserAnimStates[i].mName);
  7233. }
  7234. // Special case to trigger away (AFK) state
  7235. names->emplace_back("enter_away_from_keyboard_state");
  7236. }
  7237. void LLVOAvatar::onBakedTextureMasksLoaded(bool success,
  7238. LLViewerFetchedTexture* src_vi,
  7239. LLImageRaw* src,
  7240. LLImageRaw* aux_src,
  7241. S32 discard_level,
  7242. bool is_final,
  7243. void* userdata)
  7244. {
  7245. if (!userdata) return;
  7246. const LLUUID& id = src_vi->getID();
  7247. LLTextureMaskData* maskData = (LLTextureMaskData*)userdata;
  7248. LLVOAvatar* self = gObjectList.findAvatar(maskData->mAvatarID);
  7249. // if discard level is 2 less than last discard level we processed, or we
  7250. // hit 0, then generate morph masks
  7251. if (self && success && (discard_level == 0 ||
  7252. discard_level < maskData->mLastDiscardLevel - 2))
  7253. {
  7254. if (aux_src && aux_src->getComponents() == 1)
  7255. {
  7256. if (!aux_src->getData())
  7257. {
  7258. llerrs << "Missing auxiliary source data !" << llendl;
  7259. return;
  7260. }
  7261. U32 gl_name;
  7262. LLImageGL::generateTextures(1, &gl_name);
  7263. LLTexUnit* unit = gGL.getTexUnit(0);
  7264. unit->bindManual(LLTexUnit::TT_TEXTURE, gl_name);
  7265. LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_ALPHA8,
  7266. aux_src->getWidth(), aux_src->getHeight(),
  7267. GL_ALPHA, GL_UNSIGNED_BYTE,
  7268. aux_src->getData());
  7269. unit->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
  7270. bool found_texture_id = false;
  7271. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  7272. iter = gAvatarAppDictp->getTextures().begin(),
  7273. end = gAvatarAppDictp->getTextures().end();
  7274. iter != end; ++iter)
  7275. {
  7276. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  7277. iter->second;
  7278. if (t_dict->mIsUsedByBakedTexture)
  7279. {
  7280. const ETextureIndex texture_index = iter->first;
  7281. const LLViewerTexture* baked_img =
  7282. self->getImage(texture_index, 0);
  7283. if (baked_img && id == baked_img->getID())
  7284. {
  7285. const EBakedTextureIndex baked_idx =
  7286. t_dict->mBakedTextureIndex;
  7287. self->applyMorphMask(aux_src->getData(),
  7288. aux_src->getWidth(),
  7289. aux_src->getHeight(),
  7290. 1,
  7291. baked_idx);
  7292. maskData->mLastDiscardLevel = discard_level;
  7293. if (self->mBakedTextureDatas[baked_idx].mMaskTexName)
  7294. {
  7295. LLImageGL::deleteTextures(1,
  7296. &(self->mBakedTextureDatas[baked_idx].mMaskTexName));
  7297. }
  7298. self->mBakedTextureDatas[baked_idx].mMaskTexName =
  7299. gl_name;
  7300. found_texture_id = true;
  7301. break;
  7302. }
  7303. }
  7304. }
  7305. if (!found_texture_id)
  7306. {
  7307. llwarns_once << "Unexpected image id: " << id << llendl;
  7308. }
  7309. self->dirtyMesh();
  7310. stop_glerror();
  7311. }
  7312. else
  7313. {
  7314. // This can happen when someone uses an old baked texture possibly
  7315. // provided by viewer-side baked texture caching.
  7316. // This is a very common and normal case, so let's make it a
  7317. // llinfos instead of a llwarns...
  7318. llinfos << "Masks loaded callback without aux source" << llendl;
  7319. }
  7320. }
  7321. if (is_final || !success)
  7322. {
  7323. delete maskData;
  7324. }
  7325. }
  7326. //static
  7327. void LLVOAvatar::onInitialBakedTextureLoaded(bool success,
  7328. LLViewerFetchedTexture* src_vi,
  7329. LLImageRaw* src,
  7330. LLImageRaw* aux_src,
  7331. S32 discard_level,
  7332. bool is_final,
  7333. void* userdata)
  7334. {
  7335. LLUUID* avatar_idp = (LLUUID*)userdata;
  7336. LLVOAvatar* selfp = gObjectList.findAvatar(*avatar_idp);
  7337. if (!success && selfp)
  7338. {
  7339. selfp->removeMissingBakedTextures();
  7340. }
  7341. if (is_final || !success)
  7342. {
  7343. delete avatar_idp;
  7344. }
  7345. }
  7346. void LLVOAvatar::onBakedTextureLoaded(bool success,
  7347. LLViewerFetchedTexture* src_vi,
  7348. LLImageRaw* src,
  7349. LLImageRaw* aux_src,
  7350. S32 discard_level,
  7351. bool is_final,
  7352. void* userdata)
  7353. {
  7354. LLUUID id = src_vi->getID();
  7355. LLUUID* avatar_idp = (LLUUID*)userdata;
  7356. LLVOAvatar* avatarp = gObjectList.findAvatar(*avatar_idp);
  7357. if (avatarp && !success)
  7358. {
  7359. avatarp->removeMissingBakedTextures();
  7360. }
  7361. if (is_final || !success)
  7362. {
  7363. delete avatar_idp;
  7364. }
  7365. if (is_final && avatarp && success)
  7366. {
  7367. avatarp->useBakedTexture(id);
  7368. }
  7369. }
  7370. // Called when baked texture is loaded and also when we start up with a baked
  7371. // texture
  7372. void LLVOAvatar::useBakedTexture(const LLUUID& id)
  7373. {
  7374. for (U32 i = 0, count = mBakedTextureDatas.size(); i < count; ++i)
  7375. {
  7376. LLViewerTexture* image_baked =
  7377. getImage(mBakedTextureDatas[i].mTextureIndex, 0);
  7378. if (id == image_baked->getID())
  7379. {
  7380. mBakedTextureDatas[i].mIsLoaded = true;
  7381. mBakedTextureDatas[i].mLastTextureID = id;
  7382. mBakedTextureDatas[i].mIsUsed = true;
  7383. if (isUsingLocalAppearance())
  7384. {
  7385. LL_DEBUGS("Avatar") << "Not changing to baked texture while using local appearance"
  7386. << LL_ENDL;
  7387. }
  7388. else
  7389. {
  7390. debugColorizeSubMeshes(i, LLColor4::green);
  7391. for (avatar_joint_mesh_list_t::iterator
  7392. iter = mBakedTextureDatas[i].mJointMeshes.begin(),
  7393. end = mBakedTextureDatas[i].mJointMeshes.end();
  7394. iter != end; ++iter)
  7395. {
  7396. LLAvatarJointMesh* mesh = *iter;
  7397. if (mesh)
  7398. {
  7399. mesh->setTexture(image_baked);
  7400. }
  7401. }
  7402. }
  7403. if (isSelf())
  7404. {
  7405. const LLAvatarAppearanceDictionary::BakedEntry* baked_dict =
  7406. gAvatarAppDictp->getBakedTexture((EBakedTextureIndex)i);
  7407. for (texture_vec_t::const_iterator
  7408. local_tex_iter = baked_dict->mLocalTextures.begin(),
  7409. local_tex_end = baked_dict->mLocalTextures.end();
  7410. local_tex_iter != local_tex_end; ++local_tex_iter)
  7411. {
  7412. setBakedReady(*local_tex_iter, true);
  7413. }
  7414. }
  7415. // ! BACKWARDS COMPATIBILITY !
  7416. // Workaround for viewing avatars from old viewers that do not have
  7417. // baked hair textures. This is paired with similar code in
  7418. // updateMeshTextures that sets hair mesh color.
  7419. if (i == BAKED_HAIR)
  7420. {
  7421. for (avatar_joint_mesh_list_t::iterator
  7422. iter = mBakedTextureDatas[i].mJointMeshes.begin(),
  7423. end = mBakedTextureDatas[i].mJointMeshes.end();
  7424. iter != end; ++iter)
  7425. {
  7426. LLAvatarJointMesh* mesh = *iter;
  7427. if (mesh)
  7428. {
  7429. mesh->setColor(LLColor4::white);
  7430. }
  7431. }
  7432. }
  7433. }
  7434. }
  7435. dirtyMesh();
  7436. }
  7437. void LLVOAvatar::getSortedJointNames(S32 joint_type,
  7438. std::vector<std::string>& result) const
  7439. {
  7440. result.clear();
  7441. if (joint_type == 0)
  7442. {
  7443. for (avatar_joint_list_t::const_iterator iter = mSkeleton.begin(),
  7444. end = mSkeleton.end();
  7445. iter != end; ++iter)
  7446. {
  7447. LLJoint* jointp = *iter;
  7448. if (jointp)
  7449. {
  7450. result.emplace_back(jointp->getName());
  7451. }
  7452. }
  7453. }
  7454. else if (joint_type == 1)
  7455. {
  7456. for (S32 i = 0, count = mCollisionVolumes.size(); i < count; ++i)
  7457. {
  7458. LLAvatarJointCollisionVolume* jointp = mCollisionVolumes[i];
  7459. if (jointp)
  7460. {
  7461. result.emplace_back(jointp->getName());
  7462. }
  7463. }
  7464. }
  7465. else if (joint_type == 2)
  7466. {
  7467. for (attachment_map_t::const_iterator iter = mAttachmentPoints.begin(),
  7468. end = mAttachmentPoints.end();
  7469. iter != end; ++iter)
  7470. {
  7471. LLViewerJointAttachment* jointp = iter->second;
  7472. if (jointp)
  7473. {
  7474. result.emplace_back(jointp->getName());
  7475. }
  7476. }
  7477. }
  7478. std::sort(result.begin(), result.end());
  7479. }
  7480. void LLVOAvatar::dumpArchetypeXML(const std::string& filename)
  7481. {
  7482. if (filename.empty()) return;
  7483. LLFile outfile(filename, "wb");
  7484. if (!outfile)
  7485. {
  7486. return;
  7487. }
  7488. fprintf(outfile,
  7489. "<?xml version=\"1.0\" encoding=\"US-ASCII\" standalone=\"yes\"?>\n");
  7490. fprintf(outfile, "<linden_genepool version=\"1.0\">\n");
  7491. std::string name;
  7492. gAgent.getName(name);
  7493. fprintf(outfile, "\n\t<archetype name=\"%s\">\n", name.c_str());
  7494. bool is_god = gAgent.isGodlikeWithoutAdminMenuFakery();
  7495. std::string uuid_str;
  7496. // Body parts and clothing.
  7497. for (S32 type = LLWearableType::WT_SHAPE; type < LLWearableType::WT_COUNT;
  7498. ++type)
  7499. {
  7500. if (type > LLWearableType::WT_EYES && isSelf() &&
  7501. !LLAgentWearables::selfHasWearable((LLWearableType::EType)type))
  7502. {
  7503. continue;
  7504. }
  7505. const std::string& wearable_name =
  7506. LLWearableType::getTypeName((LLWearableType::EType)type);
  7507. if (type <= LLWearableType::WT_EYES)
  7508. {
  7509. fprintf(outfile, "\n\t\t<!-- body part: %s -->\n",
  7510. wearable_name.c_str());
  7511. }
  7512. else
  7513. {
  7514. fprintf(outfile, "\n\t\t<!-- wearable: %s -->\n",
  7515. wearable_name.c_str());
  7516. }
  7517. for (LLVisualParam* param = getFirstVisualParam();
  7518. param; param = getNextVisualParam())
  7519. {
  7520. LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
  7521. if (viewer_param->getWearableType() == type &&
  7522. viewer_param->isTweakable())
  7523. {
  7524. fprintf(outfile,
  7525. "\t\t<param id=\"%d\" name=\"%s\" value=\"%.3f\"/>\n",
  7526. viewer_param->getID(),
  7527. viewer_param->getName().c_str(),
  7528. viewer_param->getWeight());
  7529. }
  7530. }
  7531. for (U8 te = 0; te < TEX_NUM_INDICES; ++te)
  7532. {
  7533. if (LLAvatarAppearanceDictionary::getTEWearableType((ETextureIndex)te) == type)
  7534. {
  7535. // MULTIPLE_WEARABLES: extend to multiple wearables ?
  7536. LLViewerTexture* te_image = getTEImage((ETextureIndex)te);
  7537. if (!te_image)
  7538. {
  7539. continue;
  7540. }
  7541. const LLUUID& te_id = te_image->getID();
  7542. if (is_god || HBObjectBackup::validateAssetPerms(te_id))
  7543. {
  7544. te_id.toString(uuid_str);
  7545. }
  7546. else
  7547. {
  7548. uuid_str = LLUUID::null.asString();
  7549. }
  7550. fprintf(outfile, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", te,
  7551. uuid_str.c_str());
  7552. }
  7553. }
  7554. }
  7555. // Root joint
  7556. fprintf(outfile, "\n\t\t<!-- root -->\n");
  7557. {
  7558. const LLVector3& pos = mRoot->getPosition();
  7559. const LLVector3& scale = mRoot->getScale();
  7560. fprintf(outfile,
  7561. "\t\t<root name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
  7562. mRoot->getName().c_str(), pos[0], pos[1], pos[2], scale[0],
  7563. scale[1], scale[2]);
  7564. }
  7565. // Bones
  7566. fprintf(outfile, "\n\t\t<!-- bones -->\n");
  7567. for (avatar_joint_list_t::iterator iter = mSkeleton.begin(),
  7568. end = mSkeleton.end();
  7569. iter != end; ++iter)
  7570. {
  7571. LLJoint* jointp = *iter;
  7572. if (!jointp) continue; // Paranoia
  7573. const LLVector3& pos = jointp->getPosition();
  7574. const LLVector3& scale = jointp->getScale();
  7575. fprintf(outfile,
  7576. "\t\t<bone name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
  7577. jointp->getName().c_str(), pos[0], pos[1], pos[2],
  7578. scale[0], scale[1], scale[2]);
  7579. }
  7580. // Collision volumes
  7581. fprintf(outfile, "\n\t\t<!-- collision volumes -->\n");
  7582. for (S32 i = 0, count = mCollisionVolumes.size(); i < count; ++i)
  7583. {
  7584. LLJoint* jointp = mCollisionVolumes[i];
  7585. if (!jointp) continue; // Paranoia
  7586. const LLVector3& pos = jointp->getPosition();
  7587. const LLVector3& scale = jointp->getScale();
  7588. fprintf(outfile,
  7589. "\t\t<collision_volume name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
  7590. jointp->getName().c_str(), pos[0], pos[1], pos[2],
  7591. scale[0], scale[1], scale[2]);
  7592. }
  7593. // Attachment joints
  7594. fprintf(outfile, "\n\t\t<!-- attachments -->\n");
  7595. for (attachment_map_t::iterator
  7596. iter = mAttachmentPoints.begin(),
  7597. end = mAttachmentPoints.end();
  7598. iter != end; ++iter)
  7599. {
  7600. LLViewerJointAttachment* jointp = iter->second;
  7601. if (!jointp) continue;
  7602. const LLVector3& pos = jointp->getPosition();
  7603. const LLVector3& scale = jointp->getScale();
  7604. fprintf(outfile,
  7605. "\t\t<attachment_point name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
  7606. jointp->getName().c_str(), pos[0], pos[1], pos[2],
  7607. scale[0], scale[1], scale[2]);
  7608. }
  7609. LLUUID mesh_id;
  7610. bool got_some = false;
  7611. std::set<LLVector3> distinct_overrides;
  7612. // Joint pos overrides
  7613. for (avatar_joint_list_t::iterator iter = mSkeleton.begin(),
  7614. end = mSkeleton.end();
  7615. iter != end; ++iter)
  7616. {
  7617. LLJoint* jointp = *iter;
  7618. if (!jointp) continue; // Paranoia
  7619. LLVector3 pos;
  7620. if (jointp->hasAttachmentPosOverride(pos, mesh_id))
  7621. {
  7622. if (!got_some)
  7623. {
  7624. got_some = true;
  7625. fprintf(outfile, "\n\t\t<!-- joint position overrides -->\n");
  7626. }
  7627. distinct_overrides.clear();
  7628. S32 n = jointp->getAllAttachmentPosOverrides(distinct_overrides);
  7629. fprintf(outfile,
  7630. "\t\t<joint_offset name=\"%s\" position=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n",
  7631. jointp->getName().c_str(), pos[0], pos[1], pos[2],
  7632. mesh_id.asString().c_str(), n,
  7633. (S32)distinct_overrides.size());
  7634. }
  7635. }
  7636. // Joint scale overrides
  7637. got_some = false;
  7638. LLVector3 scale;
  7639. for (avatar_joint_list_t::iterator iter = mSkeleton.begin(),
  7640. end = mSkeleton.end();
  7641. iter != end; ++iter)
  7642. {
  7643. LLJoint* jointp = *iter;
  7644. if (!jointp || !jointp->hasAttachmentScaleOverride(scale, mesh_id))
  7645. {
  7646. continue;
  7647. }
  7648. if (!got_some)
  7649. {
  7650. got_some = true;
  7651. fprintf(outfile, "\n\t\t<!-- joint scale overrides -->\n");
  7652. }
  7653. distinct_overrides.clear();
  7654. S32 n = jointp->getAllAttachmentScaleOverrides(distinct_overrides);
  7655. fprintf(outfile,
  7656. "\t\t<joint_scale name=\"%s\" scale=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n",
  7657. jointp->getName().c_str(), scale[0], scale[1], scale[2],
  7658. mesh_id.asString().c_str(), n, (S32)distinct_overrides.size());
  7659. }
  7660. F32 pelvis_fixup;
  7661. if (hasPelvisFixup(pelvis_fixup, mesh_id))
  7662. {
  7663. fprintf(outfile,
  7664. "\n\t\t<pelvis_fixup z=\"%f\" mesh_id=\"%s\"/>\n",
  7665. pelvis_fixup, mesh_id.asString().c_str());
  7666. }
  7667. fprintf(outfile, "\t</archetype>\n");
  7668. fprintf(outfile, "\n</linden_genepool>\n");
  7669. }
  7670. // Assumes LLVOAvatar::sInstances has already been sorted.
  7671. S32 LLVOAvatar::getUnbakedPixelAreaRank()
  7672. {
  7673. S32 rank = 1;
  7674. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  7675. {
  7676. LLVOAvatar* inst = (LLVOAvatar*)LLCharacter::sInstances[i];
  7677. if (inst == this)
  7678. {
  7679. return rank;
  7680. }
  7681. else if (!inst->isDead() && !inst->isFullyBaked())
  7682. {
  7683. ++rank;
  7684. }
  7685. }
  7686. llassert(false);
  7687. return 0;
  7688. }
  7689. struct CompareScreenAreaGreater
  7690. {
  7691. bool operator()(const LLCharacter* const& lhs,
  7692. const LLCharacter* const& rhs)
  7693. {
  7694. return lhs->getPixelArea() > rhs->getPixelArea();
  7695. }
  7696. };
  7697. //static
  7698. void LLVOAvatar::cullAvatarsByPixelArea()
  7699. {
  7700. LL_FAST_TIMER(FTM_CULL_AVATARS);
  7701. sAvatarCullingDirty = false;
  7702. std::sort(LLCharacter::sInstances.begin(), LLCharacter::sInstances.end(),
  7703. CompareScreenAreaGreater());
  7704. // Update the avatars that have changed status
  7705. bool has_non_baked_avatars = false;
  7706. bool has_grey_avatars = false;
  7707. U32 rank = 1; // Avatar rank 0 is reserved for self
  7708. U32 prank = 1; // Animeshes have their own ranks.
  7709. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  7710. {
  7711. LLVOAvatar* avatarp = (LLVOAvatar*)LLCharacter::sInstances[i];
  7712. if (!avatarp || avatarp->isDead())
  7713. {
  7714. continue;
  7715. }
  7716. bool culled = false;
  7717. if (!avatarp->isFullyBaked())
  7718. {
  7719. has_non_baked_avatars = culled = true;
  7720. has_grey_avatars |= avatarp->mHasGrey;
  7721. }
  7722. if (avatarp->isSelf())
  7723. {
  7724. // We never cull neither change the 0 visibility rank for self
  7725. continue;
  7726. }
  7727. if (avatarp->mDrawable.isNull() || avatarp->mDrawable->isDead())
  7728. {
  7729. avatarp->mCulled = true;
  7730. continue;
  7731. }
  7732. if (avatarp->mCulled != culled)
  7733. {
  7734. avatarp->mCulled = culled;
  7735. LL_DEBUGS("Avatar") << "Avatar " << avatarp->getFullname(true)
  7736. << (culled ? " " : " not ") << "culled"
  7737. << LL_ENDL;
  7738. avatarp->updateMeshTextures();
  7739. }
  7740. if (avatarp->mDrawable->isVisible())
  7741. {
  7742. avatarp->mVisibilityRank = avatarp->isPuppetAvatar() ? prank++
  7743. : rank++;
  7744. }
  7745. }
  7746. if (has_non_baked_avatars)
  7747. {
  7748. // Update at most once per frame
  7749. if (gFrameTimeSeconds != sUnbakedUpdateTime)
  7750. {
  7751. sUnbakedUpdateTime = gFrameTimeSeconds;
  7752. sUnbakedTime += gFrameIntervalSeconds;
  7753. }
  7754. if (has_grey_avatars && gFrameTimeSeconds != sGreyUpdateTime)
  7755. {
  7756. sGreyUpdateTime = gFrameTimeSeconds;
  7757. sGreyTime += gFrameIntervalSeconds;
  7758. }
  7759. }
  7760. }
  7761. void LLVOAvatar::startAppearanceAnimation()
  7762. {
  7763. if (!mAppearanceAnimating)
  7764. {
  7765. mAppearanceAnimating = true;
  7766. mAppearanceMorphTimer.reset();
  7767. mLastAppearanceBlendTime = 0.f;
  7768. }
  7769. }
  7770. //virtual
  7771. void LLVOAvatar::bodySizeChanged()
  7772. {
  7773. if (isSelf())
  7774. {
  7775. // Notify simulator of change in size
  7776. // NOTE: sendAgentSetAppearance() already checks to see if the
  7777. // appearance is being modified and aborts in the latter case, so we
  7778. // don't need to test for it here.
  7779. gAgent.sendAgentSetAppearance();
  7780. }
  7781. }
  7782. bool LLVOAvatar::isUsingServerBakes() const
  7783. {
  7784. #if 0
  7785. // Sanity check - visual param for appearance version should match
  7786. // mUseServerBakes
  7787. LLVisualParam* appearance_version_param = getVisualParam(11000);
  7788. llassert(appearance_version_param);
  7789. F32 wt = appearance_version_param->getWeight();
  7790. F32 expect_wt = mUseServerBakes ? 1.f : 0.f;
  7791. if (!is_approx_equal(wt, expect_wt))
  7792. {
  7793. llwarns << "wt " << wt << " differs from expected " << expect_wt
  7794. << llendl;
  7795. }
  7796. #endif
  7797. return mUseServerBakes;
  7798. }
  7799. void LLVOAvatar::setIsUsingServerBakes(bool newval)
  7800. {
  7801. mUseServerBakes = newval;
  7802. LLVisualParam* appearance_version_paramp = getVisualParam(11000);
  7803. if (appearance_version_paramp)
  7804. {
  7805. appearance_version_paramp->setWeight(newval ? 1.f : 0.f, false);
  7806. }
  7807. }
  7808. std::string LLVOAvatar::getFullname(bool omit_resident)
  7809. {
  7810. if (mLegacyName.empty())
  7811. {
  7812. LLNameValue* first = getNVPair("FirstName");
  7813. if (first)
  7814. {
  7815. mLegacyName = first->getString();
  7816. }
  7817. LLNameValue* last = getNVPair("LastName");
  7818. if (last)
  7819. {
  7820. std::string last_name = last->getString();
  7821. if (!last_name.empty())
  7822. {
  7823. mNewResident = last_name == "Resident";
  7824. if (!mNewResident)
  7825. {
  7826. mLegacyName += " ";
  7827. mLegacyName += last_name;
  7828. }
  7829. }
  7830. }
  7831. }
  7832. if (omit_resident || !mNewResident ||
  7833. LLAvatarName::sOmitResidentAsLastName)
  7834. {
  7835. return mLegacyName;
  7836. }
  7837. return mLegacyName + " Resident";
  7838. }
  7839. const LLHost& LLVOAvatar::getObjectHost() const
  7840. {
  7841. if (isDead())
  7842. {
  7843. return LLHost::invalid;
  7844. }
  7845. LLViewerRegion* regionp = getRegion();
  7846. return regionp ? regionp->getHost() : LLHost::invalid;
  7847. }
  7848. bool LLVOAvatar::updateLOD()
  7849. {
  7850. if (mDrawable.isNull()) return false;
  7851. if (isImpostor() && mDrawable->getNumFaces() != 0 &&
  7852. mDrawable->getFace(0)->hasGeometry())
  7853. {
  7854. return true;
  7855. }
  7856. bool res = updateJointLODs();
  7857. LLFace* facep = mDrawable->getFace(0);
  7858. if (facep && !facep->getVertexBuffer())
  7859. {
  7860. dirtyMesh(2);
  7861. }
  7862. if (mDirtyMesh >= 2 || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY))
  7863. {
  7864. // LOD changed or new mesh created, allocate new vertex buffer if
  7865. // needed
  7866. updateMeshData();
  7867. mDirtyMesh = 0;
  7868. mNeedsSkin = true;
  7869. mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
  7870. }
  7871. updateVisibility();
  7872. return res;
  7873. }
  7874. void LLVOAvatar::updateLODRiggedAttachments()
  7875. {
  7876. updateLOD();
  7877. rebuildRiggedAttachments();
  7878. }
  7879. //virtual
  7880. void LLVOAvatar::updateRiggingInfo()
  7881. {
  7882. mTempVolumes.clear();
  7883. uuid_vec_t rigging_info_ids;
  7884. std::vector<S32> rigging_info_lods;
  7885. size_t rigs_count = mLastRiggingInfoLODs.size();
  7886. rigging_info_ids.reserve(rigs_count);
  7887. rigging_info_lods.reserve(rigs_count);
  7888. // Will be set to true should we detect a change in the meshes or their LOD
  7889. bool changed = false;
  7890. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  7891. {
  7892. LLViewerObject* object = mAttachedObjectsVector[i].first;
  7893. if (!object || object->isHUDAttachment())
  7894. {
  7895. continue;
  7896. }
  7897. LLVOVolume* volp = object->asVolume();
  7898. if (!volp)
  7899. {
  7900. continue;
  7901. }
  7902. mTempVolumes.push_back(volp);
  7903. if (volp->isMesh() && volp->getVolume())
  7904. {
  7905. const LLUUID& mesh_id =
  7906. volp->getVolume()->getParams().getSculptID();
  7907. rigging_info_ids.emplace_back(mesh_id);
  7908. S32 max_lod = llmax(volp->getLOD(), volp->mLastRiggingInfoLOD);
  7909. rigging_info_lods.push_back(max_lod);
  7910. if (!changed)
  7911. {
  7912. size_t i = rigging_info_lods.size() - 1;
  7913. changed = i >= rigs_count ||
  7914. mLastRiggingInfoLODs[i] != max_lod ||
  7915. mLastRiggingInfoIDs[i] != mesh_id;
  7916. }
  7917. }
  7918. if (volp->isAnimatedObject())
  7919. {
  7920. // For animated object attachments, we do not need the children. We
  7921. // will just get bounding box from the puppet avatar.
  7922. continue;
  7923. }
  7924. const_child_list_t& children = object->getChildren();
  7925. for (const_child_list_t::const_iterator it = children.begin(),
  7926. end = children.end();
  7927. it != end; ++it)
  7928. {
  7929. LLViewerObject* child = *it;
  7930. if (!child) // Paranoia
  7931. {
  7932. continue;
  7933. }
  7934. LLVOVolume* volp = child->asVolume();
  7935. if (!volp)
  7936. {
  7937. continue;
  7938. }
  7939. mTempVolumes.push_back(volp);
  7940. if (volp->isMesh() && volp->getVolume())
  7941. {
  7942. const LLUUID& mesh_id =
  7943. volp->getVolume()->getParams().getSculptID();
  7944. rigging_info_ids.emplace_back(mesh_id);
  7945. S32 max_lod = llmax(volp->getLOD(), volp->mLastRiggingInfoLOD);
  7946. rigging_info_lods.push_back(max_lod);
  7947. if (!changed)
  7948. {
  7949. size_t i = rigging_info_lods.size() - 1;
  7950. changed = i >= rigs_count ||
  7951. mLastRiggingInfoLODs[i] != max_lod ||
  7952. mLastRiggingInfoIDs[i] != mesh_id;
  7953. }
  7954. }
  7955. }
  7956. }
  7957. if (isPuppetAvatar())
  7958. {
  7959. LLVOVolume* volp = ((LLVOAvatarPuppet*)this)->mRootVolp;
  7960. if (volp)
  7961. {
  7962. mTempVolumes.push_back(volp);
  7963. LLViewerObject::const_child_list_t& children = volp->getChildren();
  7964. for (const_child_list_t::const_iterator it = children.begin(),
  7965. end = children.end();
  7966. it != end; ++it)
  7967. {
  7968. LLViewerObject* child = *it;
  7969. if (!child) // Paranoia
  7970. {
  7971. continue;
  7972. }
  7973. volp = child->asVolume();
  7974. if (!volp)
  7975. {
  7976. continue;
  7977. }
  7978. mTempVolumes.push_back(volp);
  7979. if (volp->isMesh() && volp->getVolume())
  7980. {
  7981. const LLUUID& mesh_id =
  7982. volp->getVolume()->getParams().getSculptID();
  7983. rigging_info_ids.emplace_back(mesh_id);
  7984. S32 max_lod = llmax(volp->getLOD(),
  7985. volp->mLastRiggingInfoLOD);
  7986. rigging_info_lods.push_back(max_lod);
  7987. if (!changed)
  7988. {
  7989. size_t i = rigging_info_lods.size() - 1;
  7990. changed = i >= rigs_count ||
  7991. mLastRiggingInfoLODs[i] != max_lod ||
  7992. mLastRiggingInfoIDs[i] != mesh_id;
  7993. }
  7994. }
  7995. }
  7996. }
  7997. }
  7998. // Check for key change, which indicates some change in volume composition
  7999. // or LOD.
  8000. if (changed)
  8001. {
  8002. mLastRiggingInfoIDs.swap(rigging_info_ids);
  8003. mLastRiggingInfoLODs.swap(rigging_info_lods);
  8004. mJointRiggingInfoTab.clear();
  8005. for (S32 i = 0, count = mTempVolumes.size(); i < count; ++i)
  8006. {
  8007. LLVOVolume* volp = mTempVolumes[i];
  8008. volp->updateRiggingInfo();
  8009. mJointRiggingInfoTab.merge(volp->mJointRiggingInfoTab);
  8010. }
  8011. }
  8012. }
  8013. //virtual
  8014. U32 LLVOAvatar::getPartitionType() const
  8015. {
  8016. // Avatars merely exist as drawables in the avatar partition
  8017. return LLViewerRegion::PARTITION_AVATAR;
  8018. }
  8019. //static
  8020. void LLVOAvatar::updateImpostors()
  8021. {
  8022. for (S32 i = 0, count = LLCharacter::sInstances.size(); i < count; ++i)
  8023. {
  8024. LLVOAvatar* avatar = (LLVOAvatar*)LLCharacter::sInstances[i];
  8025. if (avatar && !avatar->isDead() && avatar->isVisible() &&
  8026. avatar->isImpostor() && avatar->needsImpostorUpdate())
  8027. {
  8028. gPipeline.generateImpostor(avatar);
  8029. }
  8030. }
  8031. }
  8032. //virtual
  8033. bool LLVOAvatar::isImpostor()
  8034. {
  8035. return useImpostors() && mVisuallyMuteSetting != AV_ALWAYS_RENDER &&
  8036. (mUpdatePeriod >= IMPOSTOR_PERIOD || isVisuallyMuted());
  8037. }
  8038. void LLVOAvatar::cacheImpostorValues()
  8039. {
  8040. getImpostorValues(mImpostorExtents, mImpostorAngle, mImpostorDistance);
  8041. }
  8042. void LLVOAvatar::getImpostorValues(LLVector4a* extents, LLVector3& angle,
  8043. F32& distance) const
  8044. {
  8045. const LLVector4a* ext = mDrawable->getSpatialExtents();
  8046. extents[0] = ext[0];
  8047. extents[1] = ext[1];
  8048. LLVector3 at = gViewerCamera.getOrigin() - getRenderPosition() -
  8049. mImpostorOffset;
  8050. distance = at.normalize();
  8051. F32 da = 1.f - at * gViewerCamera.getAtAxis();
  8052. angle.mV[0] = gViewerCamera.getYaw() * da;
  8053. angle.mV[1] = gViewerCamera.getPitch() * da;
  8054. angle.mV[2] = da;
  8055. }
  8056. //static
  8057. void LLVOAvatar::updateSettings()
  8058. {
  8059. static LLCachedControl<F32> lod_factor(gSavedSettings,
  8060. "RenderAvatarLODFactor");
  8061. sLODFactor = llclamp((F32)lod_factor, 0.01f, 1.f);
  8062. static LLCachedControl<F32> phys_lod(gSavedSettings,
  8063. "RenderAvatarPhysicsLODFactor");
  8064. sPhysicsLODFactor = llclamp((F32)phys_lod, 0.f, 1.f);
  8065. static LLCachedControl<S32> render_name(gSavedSettings, "RenderName");
  8066. sRenderName = llclamp((S32)render_name, RENDER_NAME_NEVER,
  8067. RENDER_NAME_ALWAYS);
  8068. static LLCachedControl<bool> hide_titles(gSavedSettings,
  8069. "RenderHideGroupTitleAll");
  8070. sRenderGroupTitles = !hide_titles;
  8071. static LLCachedControl<bool> self_visible(gSavedSettings,
  8072. "FirstPersonAvatarVisible");
  8073. sVisibleInFirstPerson = self_visible;
  8074. static LLCachedControl<U32> non_impostors(gSavedSettings,
  8075. "RenderAvatarMaxNonImpostors");
  8076. sMaxNonImpostors = non_impostors;
  8077. //MK
  8078. if (!gRLenabled || gRLInterface.mShowavsDistMax >= EXTREMUM)
  8079. //mk
  8080. {
  8081. sUseImpostors = sMaxNonImpostors != 0;
  8082. }
  8083. //MK
  8084. if (sMaxNonImpostors == 0)
  8085. {
  8086. // This is needed because RestrainedLove can force sUseImpostors to
  8087. // true while the user configured RenderAvatarMaxNonImpostors to 0
  8088. // (for "do not use impostors") and sMaxNonImpostors gets used if and
  8089. // only if sUseImpostors is true (which would lead to impostoring all
  8090. // avatars while the user didn't want any impostor at all).
  8091. sMaxNonImpostors = 1000; // No practical limit to non-impostors
  8092. }
  8093. //mk
  8094. LL_DEBUGS("Avatar") << "Use impostors: " << (sUseImpostors ? "yes" : "no")
  8095. << " - Max non-impostors: " << sMaxNonImpostors
  8096. << LL_ENDL;
  8097. static LLCachedControl<U32> max_puppets(gSavedSettings,
  8098. "RenderAvatarMaxPuppets");
  8099. sMaxNonImpostorsPuppets = max_puppets;
  8100. sUsePuppetImpostors = max_puppets != 0;
  8101. LL_DEBUGS("Avatar") << "Use puppet impostors: "
  8102. << (sMaxNonImpostorsPuppets ? "yes" : "no")
  8103. << " - Max non-impostor puppets: "
  8104. << sMaxNonImpostorsPuppets << LL_ENDL;
  8105. }
  8106. void LLVOAvatar::idleUpdateRenderComplexity()
  8107. {
  8108. if (isPuppetAvatar())
  8109. {
  8110. LLVOVolume* volp = ((LLVOAvatarPuppet*)this)->mRootVolp;
  8111. if (volp && volp->isAttachment())
  8112. {
  8113. // Render cost for attached animated objects is accounted as any
  8114. // other attachment.
  8115. return;
  8116. }
  8117. }
  8118. calculateUpdateRenderComplexity(); // Update mVisualComplexity if needed
  8119. if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_DRAW_INFO))
  8120. {
  8121. setDebugText(llformat("%d\nrank %d\nperiod %d", mVisualComplexity,
  8122. mVisibilityRank, mUpdatePeriod));
  8123. static LLCachedControl<U32> max_cost(gSavedSettings,
  8124. "RenderAvatarMaxComplexity");
  8125. if (max_cost)
  8126. {
  8127. F32 green = 1.f - llclamp(((F32)mVisualComplexity - (F32)max_cost) /
  8128. (F32)max_cost, 0.f, 1.f);
  8129. F32 red = llmin((F32)mVisualComplexity / (F32)max_cost, 1.f);
  8130. mText->setColor(LLColor4(red, green, 0.f, 1.f));
  8131. }
  8132. }
  8133. else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_ATTACHMENT_INFO))
  8134. {
  8135. setDebugText(llformat("%.1f MB, %.2f m2",
  8136. (F32)mAttachmentGeometryBytes / 1048576.f,
  8137. mAttachmentSurfaceArea));
  8138. static LLCachedControl<U32> max_megabytes(gSavedSettings,
  8139. "RenderAutoMuteMemoryLimit");
  8140. static LLCachedControl<F32> max_area(gSavedSettings,
  8141. "RenderAutoMuteSurfaceAreaLimit");
  8142. bool mem_limit = max_megabytes > 0;
  8143. bool area_limit = max_area > 0.f;
  8144. if (!mem_limit && !area_limit)
  8145. {
  8146. return;
  8147. }
  8148. F32 green = 0.f;
  8149. F32 red = 1.f;
  8150. F32 current_value = (F32)mAttachmentGeometryBytes / 1048576.f;
  8151. if (!(mem_limit && current_value >= (F32)max_megabytes) &&
  8152. !(area_limit && mAttachmentSurfaceArea >= (F32)max_area))
  8153. {
  8154. F32 max_value = 0.f;
  8155. if (mem_limit)
  8156. {
  8157. max_value = (F32)max_megabytes;
  8158. }
  8159. else
  8160. {
  8161. current_value = 0.f;
  8162. }
  8163. if (area_limit)
  8164. {
  8165. max_value += max_area;
  8166. current_value += mAttachmentSurfaceArea;
  8167. }
  8168. green = 1.f - llclamp((current_value - max_value) / max_value,
  8169. 0.f, 1.f);
  8170. red = llmin(current_value / max_value, 1.f);
  8171. }
  8172. mText->setColor(LLColor4(red, green, 0.f, 1.f));
  8173. }
  8174. }
  8175. void LLVOAvatar::accountRenderComplexityForObject(LLViewerObject* object,
  8176. U32& cost)
  8177. {
  8178. if (!object || object->isHUDAttachment())
  8179. {
  8180. return;
  8181. }
  8182. const LLDrawable* drawable = object->mDrawable;
  8183. if (!drawable) return;
  8184. const LLVOVolume* volume = drawable->getVOVolume();
  8185. if (!volume) return;
  8186. F32 attachment_total_cost = 0.f;
  8187. F32 attachment_volume_cost = 0.f;
  8188. F32 attachment_texture_cost = 0.f;
  8189. F32 attachment_children_cost = 0.f;
  8190. constexpr F32 animated_object_attachment_surcharge = 1000.f;
  8191. if (object->isAnimatedObject())
  8192. {
  8193. attachment_volume_cost += animated_object_attachment_surcharge;
  8194. }
  8195. static LLVOVolume::texture_cost_t textures;
  8196. textures.clear();
  8197. attachment_volume_cost = volume->getRenderCost(textures);
  8198. const_child_list_t& children = volume->getChildren();
  8199. for (const_child_list_t::const_iterator
  8200. child_iter = children.begin(), child_end = children.end();
  8201. child_iter != child_end; ++child_iter)
  8202. {
  8203. LLViewerObject* child_obj = *child_iter;
  8204. if (!child_obj) continue; // Paranoia
  8205. LLVOVolume* child = child_obj->asVolume();
  8206. if (child)
  8207. {
  8208. attachment_children_cost += child->getRenderCost(textures);
  8209. }
  8210. }
  8211. for (LLVOVolume::texture_cost_t::iterator
  8212. tex_iter = textures.begin(), tex_end = textures.end();
  8213. tex_iter != tex_end; ++tex_iter)
  8214. {
  8215. // Add the cost of each individual texture in the linkset
  8216. attachment_texture_cost += tex_iter->second;
  8217. }
  8218. attachment_total_cost = attachment_volume_cost + attachment_texture_cost +
  8219. attachment_children_cost;
  8220. LL_DEBUGS("ARCdetail") << getFullname(true) << ", costs for attachment: "
  8221. << object-> getAttachmentItemID() << " - total: "
  8222. << attachment_total_cost << " - volumes: "
  8223. << attachment_volume_cost << " - textures: "
  8224. << attachment_texture_cost << " - "
  8225. << volume->numChildren() << " children: "
  8226. << attachment_children_cost << LL_ENDL;
  8227. // Limit attachment complexity to avoid signed integer flipping of the
  8228. // wearer's ACI
  8229. cost += (U32)llclamp(attachment_total_cost, 0.f,
  8230. MAX_ATTACHMENT_COMPLEXITY);
  8231. }
  8232. // Calculations for mVisualComplexity value
  8233. void LLVOAvatar::calculateUpdateRenderComplexity()
  8234. {
  8235. if (!mVisualComplexityStale ||
  8236. gFrameTimeSeconds - mComplexityUpdateTime < COMPLEXITY_UPDATE_INTERVAL)
  8237. {
  8238. return;
  8239. }
  8240. /**************************************************************************
  8241. * This calculation should not be modified by third party viewers, since it
  8242. * is used to limit rendering and should be uniform for everyone. If you
  8243. * have suggested improvements, submit them to the official viewer for
  8244. * consideration.
  8245. *************************************************************************/
  8246. constexpr U32 COMPLEXITY_BODY_PART_COST = 200;
  8247. U32 cost = 0;
  8248. bool wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
  8249. bool debug_alpha = LLDrawPoolAlpha::sShowDebugAlpha;
  8250. for (U8 baked_idx = 0; baked_idx <= BAKED_HAIR; ++baked_idx)
  8251. {
  8252. const LLAvatarAppearanceDictionary::BakedEntry* baked_dict =
  8253. gAvatarAppDictp->getBakedTexture((EBakedTextureIndex)baked_idx);
  8254. ETextureIndex tex_index = baked_dict->mTextureIndex;
  8255. if (tex_index == TEX_SKIRT_BAKED && !wearing_skirt)
  8256. {
  8257. continue;
  8258. }
  8259. // Same as logic as in isTextureVisible(), but does not account for
  8260. // isSelf() so to ensure identical numbers for all avatars.
  8261. if (isIndexLocalTexture(tex_index))
  8262. {
  8263. if (isTextureDefined(tex_index))
  8264. {
  8265. cost += COMPLEXITY_BODY_PART_COST;
  8266. }
  8267. continue;
  8268. }
  8269. // Baked textures can use TE images directly
  8270. if (isTextureDefined(tex_index) &&
  8271. (debug_alpha || getTEImage(tex_index)->getID() != IMG_INVISIBLE))
  8272. {
  8273. cost += COMPLEXITY_BODY_PART_COST;
  8274. }
  8275. }
  8276. LL_DEBUGS("ARCdetail") << getFullname(true) << "'s body parts complexity: "
  8277. << cost << LL_ENDL;
  8278. // A standalone animated object needs to be accounted for using its
  8279. // associated volume. Attached animated objects will be covered by the
  8280. // subsequent loop over attachments.
  8281. if (isPuppetAvatar())
  8282. {
  8283. LLVOVolume* volp = ((LLVOAvatarPuppet*)this)->mRootVolp;
  8284. if (volp && !volp->isAttachment())
  8285. {
  8286. accountRenderComplexityForObject((LLViewerObject*)volp, cost);
  8287. }
  8288. }
  8289. // Account for complexity of all attachments.
  8290. for (S32 i = 0, count = mAttachedObjectsVector.size(); i < count; ++i)
  8291. {
  8292. LLViewerObject* object = mAttachedObjectsVector[i].first;
  8293. if (!object->isTempAttachment())
  8294. {
  8295. accountRenderComplexityForObject(object, cost);
  8296. }
  8297. }
  8298. static LLCachedControl<bool> show_changes(gSavedSettings,
  8299. "ShowMyComplexityChanges");
  8300. if (isSelf() && show_changes && mVisualComplexity != cost)
  8301. {
  8302. static LLUUID last_notif_id;
  8303. if (last_notif_id.notNull())
  8304. {
  8305. LLNotificationPtr n = gNotifications.find(last_notif_id);
  8306. if (n)
  8307. {
  8308. gNotifications.cancel(n);
  8309. }
  8310. last_notif_id.setNull();
  8311. }
  8312. LLSD args;
  8313. args["AGENT_COMPLEXITY"] = llformat("%d", cost);
  8314. U32 attachments = getNumAttachments();
  8315. args["[ATTACHMENTS]"] = llformat("%d", attachments);
  8316. args["[SLOTS]"] = llformat("%d", gMaxSelfAttachments - attachments);
  8317. LLNotificationPtr n = gNotifications.add("AgentComplexity", args);
  8318. if (n)
  8319. {
  8320. last_notif_id = n->getID();
  8321. }
  8322. }
  8323. mVisualComplexity = cost;
  8324. mVisualComplexityStale = false;
  8325. mComplexityUpdateTime = gFrameTimeSeconds;
  8326. }
  8327. void LLVOAvatar::setVisualMuteSettings(VisualMuteSettings value)
  8328. {
  8329. if (!mCachedMute && !isUIAvatar())
  8330. {
  8331. //MK
  8332. if (gRLenabled && mCachedRLVMute && value == AV_ALWAYS_RENDER)
  8333. {
  8334. // Allow to switch from AV_DO_NOT_RENDER to normal rendering, but
  8335. // do not let the user override the RLV mute with AV_ALWAYS_RENDER
  8336. value = AV_RENDER_NORMALLY;
  8337. }
  8338. //mk
  8339. mVisuallyMuteSetting = value;
  8340. mNeedsImpostorUpdate = true;
  8341. mCachedVisualMuteUpdateTime = 0.f;
  8342. }
  8343. }
  8344. //static
  8345. bool LLVOAvatar::isIndexLocalTexture(ETextureIndex index)
  8346. {
  8347. if (index < 0 || index >= TEX_NUM_INDICES) return false;
  8348. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  8349. gAvatarAppDictp->getTexture(index);
  8350. return t_dict && t_dict->mIsLocalTexture;
  8351. }
  8352. //static
  8353. bool LLVOAvatar::isIndexBakedTexture(ETextureIndex index)
  8354. {
  8355. if (index < 0 || index >= TEX_NUM_INDICES) return false;
  8356. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  8357. gAvatarAppDictp->getTexture(index);
  8358. return t_dict && t_dict->mIsBakedTexture;
  8359. }
  8360. const std::string LLVOAvatar::getBakedStatusForPrintout() const
  8361. {
  8362. std::string line;
  8363. for (LLAvatarAppearanceDictionary::Textures::const_iterator
  8364. iter = gAvatarAppDictp->getTextures().begin(),
  8365. end = gAvatarAppDictp->getTextures().end();
  8366. iter != end; ++iter)
  8367. {
  8368. const ETextureIndex index = iter->first;
  8369. const LLAvatarAppearanceDictionary::TextureEntry* t_dict =
  8370. iter->second;
  8371. if (t_dict && t_dict->mIsBakedTexture &&
  8372. t_dict->mBakedTextureIndex < gAgent.mUploadedBakes)
  8373. {
  8374. line += t_dict->mName;
  8375. if (isTextureDefined(index))
  8376. {
  8377. line += "_baked";
  8378. }
  8379. line += " ";
  8380. }
  8381. }
  8382. return line;
  8383. }
  8384. //-----------------------------------------------------------------------------
  8385. // Utility functions
  8386. //-----------------------------------------------------------------------------
  8387. F32 calc_bouncy_animation(F32 x)
  8388. {
  8389. return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO)) * (0.4f + x * -0.1f) +
  8390. x * 1.3f;
  8391. }
  8392. //virtual
  8393. bool LLVOAvatar::isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex te,
  8394. U32 index) const
  8395. {
  8396. if (isIndexLocalTexture(te))
  8397. {
  8398. return false;
  8399. }
  8400. LLViewerTexture* imagep = getImage(te, index);
  8401. if (imagep)
  8402. {
  8403. const LLUUID& id = imagep->getID();
  8404. return id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT;
  8405. }
  8406. llwarns << "getImage(" << te << ", " << index << ") returned NULL !"
  8407. << llendl;
  8408. return false;
  8409. }
  8410. //virtual
  8411. bool LLVOAvatar::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type,
  8412. U32 index) const
  8413. {
  8414. if (isIndexLocalTexture(type))
  8415. {
  8416. return isTextureDefined(type, index);
  8417. }
  8418. // Baked textures can use TE images directly
  8419. return ((isTextureDefined(type) || isSelf()) &&
  8420. (getTEImage(type)->getID() != IMG_INVISIBLE ||
  8421. LLDrawPoolAlpha::sShowDebugAlpha));
  8422. }
  8423. //virtual
  8424. bool LLVOAvatar::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type,
  8425. LLViewerWearable* wearable) const
  8426. {
  8427. // Non-self avatars do not have wearables
  8428. return false;
  8429. }
  8430. ///////////////////////////////////////////////////////////////////////////////
  8431. // LLVOAvatarUI class
  8432. ///////////////////////////////////////////////////////////////////////////////
  8433. LLVOAvatarUI::LLVOAvatarUI(const LLUUID& id, LLViewerRegion* regionp)
  8434. : LLVOAvatar(id, regionp)
  8435. {
  8436. mIsDummy = true;
  8437. }
  8438. //virtual
  8439. void LLVOAvatarUI::initInstance()
  8440. {
  8441. LLVOAvatar::initInstance();
  8442. createDrawable();
  8443. setPositionAgent(LLVector3::zero);
  8444. slamPosition();
  8445. updateJointLODs();
  8446. updateGeometry(mDrawable);
  8447. }