llviewerobject.cpp 192 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837
  1. /**
  2. * @file llviewerobject.cpp
  3. * @brief Base class for viewer objects
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include <sstream>
  34. #include <utility>
  35. #include "boost/lexical_cast.hpp"
  36. #include "llviewerobject.h"
  37. #include "imageids.h"
  38. #include "llaudioengine.h"
  39. #include "lldatapacker.h"
  40. #include "lldir.h"
  41. #include "lldispatcher.h"
  42. #include "llfasttimer.h"
  43. #include "llglslshader.h" // For gUsePBRShaders
  44. #include "llinventory.h"
  45. #include "llmaterialid.h"
  46. #include "llmaterialtable.h"
  47. #include "llnamevalue.h"
  48. #include "llprimitive.h"
  49. #include "llregionhandle.h"
  50. #include "llsdserialize.h"
  51. #include "llsdutil.h"
  52. #include "lltree_common.h"
  53. #include "llvolume.h"
  54. #include "llvolumemessage.h"
  55. #include "llxfermanager.h"
  56. #include "llmessage.h"
  57. #include "object_flags.h"
  58. #include "llagent.h"
  59. #include "llaudiosourcevo.h"
  60. #include "lldrawable.h"
  61. #include "llface.h"
  62. #include "llflexibleobject.h"
  63. #include "hbfloaterdebugtags.h"
  64. #include "llfloaterproperties.h"
  65. #include "llfloatertools.h"
  66. #include "llfollowcam.h"
  67. #include "llgltfmateriallist.h"
  68. #include "llgridmanager.h"
  69. #include "llhudtext.h"
  70. #include "llinventorymodel.h"
  71. #include "lllocalbitmaps.h"
  72. #include "llmanip.h"
  73. #include "llmutelist.h"
  74. #include "llpipeline.h"
  75. #include "llselectmgr.h"
  76. #include "lltooldraganddrop.h"
  77. #include "llviewercamera.h"
  78. #include "llviewercontrol.h"
  79. #include "llviewertexturelist.h"
  80. #include "llviewerinventory.h"
  81. #include "llviewermessage.h" // For gGenericDispatcher;
  82. #include "llviewerobjectlist.h"
  83. #include "llviewerparceloverlay.h"
  84. #include "llviewerpartsim.h"
  85. #include "llviewerpartsource.h"
  86. #include "llviewerregion.h"
  87. #include "llviewertextureanim.h"
  88. #include "llvoavatarpuppet.h"
  89. #include "llvoavatarself.h"
  90. #include "llvocache.h"
  91. #include "llvoclouds.h"
  92. #include "llvograss.h"
  93. #include "llvopartgroup.h"
  94. #include "llvosky.h"
  95. #include "llvosurfacepatch.h"
  96. #include "llvotree.h"
  97. #include "llvovolume.h"
  98. #include "llvowater.h"
  99. #include "llvowlsky.h"
  100. #include "llworld.h"
  101. using namespace LLAvatarAppearanceDefines;
  102. // At 45 Hz collisions seem stable and objects seem to settle down at a
  103. // reasonable rate. JC 3/18/2003
  104. constexpr F32 PHYSICS_TIMESTEP = 1.f / 45.f;
  105. // Maximum number of unknown tokens in inventory files
  106. constexpr U32 MAX_INV_FILE_READ_FAILS = 25;
  107. //constexpr U8 LL_SOUND_FLAG_NONE = 0x0;
  108. constexpr U8 LL_SOUND_FLAG_LOOP = 1 << 0;
  109. constexpr U8 LL_SOUND_FLAG_SYNC_MASTER = 1 << 1;
  110. constexpr U8 LL_SOUND_FLAG_SYNC_SLAVE = 1 << 2;
  111. //constexpr U8 LL_SOUND_FLAG_SYNC_PENDING = 1 << 3;
  112. constexpr U8 LL_SOUND_FLAG_QUEUE = 1 << 4;
  113. constexpr U8 LL_SOUND_FLAG_STOP = 1 << 5;
  114. // The maximum size of an object extra parameters binary (packed) block
  115. #define MAX_OBJECT_PARAMS_SIZE 1024
  116. bool LLViewerObject::sVelocityInterpolate = true;
  117. bool LLViewerObject::sPingInterpolate = true;
  118. // For motion interpolation: after X seconds with no updates, don't predict
  119. // object motion. NOTE: sMaxUpdateInterpolationTime must be greater than
  120. // sPhaseOutUpdateInterpolationTime.
  121. F64 LLViewerObject::sMaxUpdateInterpolationTime = 3.0;
  122. // For motion interpolation: after Y seconds with no updates, taper off motion
  123. // prediction
  124. F64 LLViewerObject::sPhaseOutUpdateInterpolationTime = 1.0;
  125. // For motion interpolation: do not interpolate over this time on region
  126. // crossing
  127. F64 LLViewerObject::sMaxRegionCrossingInterpolationTime = 1.0;
  128. S32 LLViewerObject::sNumObjects = 0;
  129. bool LLViewerObject::sUseNewTargetOmegaCode = false;
  130. std::map<std::string, U32> LLViewerObject::sObjectDataMap;
  131. LLUUID LLViewerObject::sDebugObjectId;
  132. //static
  133. LLViewerObject* LLViewerObject::createObject(const LLUUID& id, LLPCode pcode,
  134. LLViewerRegion* regionp,
  135. S32 flags)
  136. {
  137. LL_FAST_TIMER(FTM_CREATE_OBJECT);
  138. switch (pcode)
  139. {
  140. case LL_PCODE_VOLUME:
  141. return (LLViewerObject*)new LLVOVolume(id, regionp);
  142. case LL_PCODE_LEGACY_AVATAR:
  143. {
  144. if (id == gAgentID)
  145. {
  146. if (!gAgentAvatarp)
  147. {
  148. gAgentAvatarp = new LLVOAvatarSelf(id, regionp);
  149. gAgentAvatarp->initInstance();
  150. }
  151. else if (isAgentAvatarValid())
  152. {
  153. gAgentAvatarp->updateRegion(regionp);
  154. }
  155. return gAgentAvatarp;
  156. }
  157. if (flags & CO_FLAG_UI_AVATAR)
  158. {
  159. LLVOAvatarUI* avatarp = new LLVOAvatarUI(id, regionp);
  160. avatarp->initInstance();
  161. return avatarp;
  162. }
  163. if (flags & CO_FLAG_PUPPET_AVATAR)
  164. {
  165. LLVOAvatarPuppet* avatarp = new LLVOAvatarPuppet(id, regionp);
  166. avatarp->initInstance();
  167. return avatarp;
  168. }
  169. LLVOAvatar* avatarp = new LLVOAvatar(id, regionp);
  170. avatarp->initInstance();
  171. return avatarp;
  172. }
  173. case LL_PCODE_LEGACY_GRASS:
  174. return new LLVOGrass(id, regionp);
  175. case LL_PCODE_LEGACY_TREE:
  176. return new LLVOTree(id, regionp);
  177. case LL_VO_CLOUDS:
  178. return new LLVOClouds(id, regionp);
  179. case LL_VO_SURFACE_PATCH:
  180. return new LLVOSurfacePatch(id, regionp);
  181. case LL_VO_SKY:
  182. return new LLVOSky(id, regionp);
  183. case LL_VO_VOID_WATER:
  184. return new LLVOVoidWater(id, regionp);
  185. case LL_VO_WATER:
  186. return new LLVOWater(id, regionp);
  187. case LL_VO_PART_GROUP:
  188. return new LLVOPartGroup(id, regionp);
  189. case LL_VO_HUD_PART_GROUP:
  190. return new LLVOHUDPartGroup(id, regionp);
  191. case LL_VO_WL_SKY:
  192. return new LLVOWLSky(id, regionp);
  193. default:
  194. llwarns_once << "Unknown or deperecated object pcode: "
  195. << (S32)pcode << llendl;
  196. }
  197. return NULL;
  198. }
  199. LLViewerObject::LLViewerObject(const LLUUID& id, LLPCode pcode,
  200. LLViewerRegion* regionp, bool is_global)
  201. : mID(id),
  202. mLocalID(0),
  203. mTotalCRC(0),
  204. mListIndex(-1),
  205. mCanSelect(true),
  206. mFlags(0),
  207. mFlagsLoaded(false),
  208. mPhysicsShapeType(0),
  209. mPhysicsGravity(0),
  210. mPhysicsFriction(0),
  211. mPhysicsDensity(0),
  212. mPhysicsRestitution(0),
  213. mCreateSelected(false),
  214. mIsReflectionProbe(false),
  215. mIsHeroProbe(false),
  216. mBestUpdatePrecision(0),
  217. mLastInterpUpdateSecs(LLFrameTimer::getElapsedSeconds()),
  218. mRegionCrossExpire(0.0),
  219. mLastMessageUpdateSecs(0.0),
  220. mLatestRecvPacketID(0),
  221. mData(NULL),
  222. mAudioSourcep(NULL),
  223. mAudioGain(1.f),
  224. mSoundCutOffRadius(0.f),
  225. mAppAngle(0.f),
  226. mPixelArea(1024.f),
  227. mInventory(NULL),
  228. mInventorySerialNum(0),
  229. mExpectedInventorySerialNum(0),
  230. mInvRequestState(INVENTORY_REQUEST_STOPPED),
  231. mInvRequestXFerId(0),
  232. mInventoryDirty(false),
  233. mRegionp(regionp),
  234. mDead(false),
  235. mOrphaned(false),
  236. mUserSelected(false),
  237. mOnActiveList(false),
  238. mOnMap(false),
  239. mStatic(false),
  240. mNumFaces(0),
  241. mRotTime(0.f),
  242. mAttachmentState(0),
  243. mMedia(NULL),
  244. mClickAction(0),
  245. mObjectCost(0.f),
  246. mLinksetCost(0.f),
  247. mPhysicsCost(0.f),
  248. mLinksetPhysicsCost(0.f),
  249. mCostStale(true),
  250. mShouldShrinkWrap(false),
  251. mPhysicsShapeUnknown(true),
  252. mAttachmentItemID(LLUUID::null),
  253. mLastUpdateType(OUT_UNKNOWN),
  254. mLastUpdateCached(false)
  255. {
  256. if (!is_global)
  257. {
  258. llassert(mRegionp);
  259. }
  260. setPCode(pcode);
  261. // Initialize the extra parameters data arrays to NULL pointers and false
  262. // 'in use' booleans.
  263. memset((void*)&mExtraParameters[0], 0,
  264. LL_EPARAMS_COUNT * sizeof(LLNetworkData*));
  265. memset((void*)&mExtraParameterInUse[0], (int)false,
  266. LL_EPARAMS_COUNT * sizeof(bool));
  267. mDebugUpdateMsg = id == sDebugObjectId;
  268. if (mDebugUpdateMsg)
  269. {
  270. llinfos << "Debugged object created with Id: " << id << llendl;
  271. }
  272. if (!is_global && mRegionp)
  273. {
  274. mPositionAgent = mRegionp->getOriginAgent();
  275. }
  276. if (sUseNewTargetOmegaCode)
  277. {
  278. resetRot();
  279. }
  280. ++sNumObjects;
  281. }
  282. LLViewerObject::~LLViewerObject()
  283. {
  284. if (!mDead) // Paranoia
  285. {
  286. llwarns << "Object " << std::hex << intptr_t(this) << std::dec
  287. << " destroyed while not yet marked dead." << llendl;
  288. llassert(false);
  289. markDead();
  290. }
  291. deleteTEImages();
  292. // Unhook from reflection probe manager
  293. if (mReflectionProbe.notNull())
  294. {
  295. mReflectionProbe->mViewerObject = NULL;
  296. mReflectionProbe = NULL;
  297. }
  298. if (mInventory)
  299. {
  300. mInventory->clear(); // Will de-reference and delete entries
  301. delete mInventory;
  302. mInventory = NULL;
  303. }
  304. if (mPartSourcep)
  305. {
  306. mPartSourcep->setDead();
  307. mPartSourcep = NULL;
  308. }
  309. // Delete memory associated with extra parameters.
  310. for (S32 i = 0; i < LL_EPARAMS_COUNT; ++i)
  311. {
  312. LLNetworkData* param = mExtraParameters[i];
  313. if (param)
  314. {
  315. delete param;
  316. }
  317. }
  318. std::for_each(mNameValuePairs.begin(), mNameValuePairs.end(),
  319. DeletePairedPointer());
  320. mNameValuePairs.clear();
  321. mJointRiggingInfoTab.clear();
  322. delete[] mData;
  323. mData = NULL;
  324. delete mMedia;
  325. mMedia = NULL;
  326. --sNumObjects;
  327. llassert(mChildList.size() == 0);
  328. clearInventoryListeners();
  329. }
  330. void LLViewerObject::deleteTEImages()
  331. {
  332. mTEImages.clear();
  333. mTENormalMaps.clear();
  334. mTESpecularMaps.clear();
  335. }
  336. void LLViewerObject::markDead()
  337. {
  338. if (mDead)
  339. {
  340. return;
  341. }
  342. if (mUserSelected)
  343. {
  344. gSelectMgr.deselectObjectAndFamily(this);
  345. }
  346. // Do this before the following removeChild()...
  347. LLVOAvatar* av = getAvatar();
  348. // Root object of this hierarchy unlinks itself.
  349. if (getParent())
  350. {
  351. ((LLViewerObject*)getParent())->removeChild(this);
  352. }
  353. LLUUID mesh_id;
  354. if (av && LLVOAvatar::getRiggedMeshID(this, mesh_id))
  355. {
  356. // This case is needed for indirectly attached mesh objects.
  357. av->updateAttachmentOverrides();
  358. }
  359. LLVOInventoryListener::removeObjectFromListeners(this);
  360. // Mark itself as dead
  361. mDead = true;
  362. if (mRegionp)
  363. {
  364. mRegionp->removeFromCreatedList(getLocalID());
  365. }
  366. gObjectList.cleanupReferences(this);
  367. while (mChildList.size() > 0)
  368. {
  369. LLViewerObject* childp = mChildList.back();
  370. if (childp->isAvatar())
  371. {
  372. // Make sure avatar is no longer parented, so we can properly set
  373. // its position
  374. childp->setDrawableParent(NULL);
  375. LLVOAvatar* avatarp = (LLVOAvatar*)childp;
  376. if (avatarp->isSelf())
  377. {
  378. LL_DEBUGS("AgentSit") << "Unsitting agent from dead object"
  379. << LL_ENDL;
  380. }
  381. avatarp->getOffObject();
  382. childp->setParent(NULL);
  383. }
  384. else
  385. {
  386. childp->setParent(NULL);
  387. childp->markDead();
  388. }
  389. mChildList.pop_back();
  390. }
  391. if (mDrawable.notNull())
  392. {
  393. // Drawables are reference counted, mark as dead, then nuke the
  394. // pointer.
  395. mDrawable->markDead();
  396. mDrawable = NULL;
  397. }
  398. // Unhook from reflection probe manager
  399. if (mReflectionProbe.notNull())
  400. {
  401. mReflectionProbe->mViewerObject = NULL;
  402. mReflectionProbe = NULL;
  403. }
  404. // Free any reference to a GLTF asset. HB
  405. mGLTFAsset = NULL;
  406. if (mText)
  407. {
  408. mText->markDead();
  409. mText = NULL;
  410. }
  411. if (mIcon)
  412. {
  413. mIcon->markDead();
  414. mIcon = NULL;
  415. }
  416. if (mPartSourcep)
  417. {
  418. mPartSourcep->setDead();
  419. mPartSourcep = NULL;
  420. }
  421. if (mAudioSourcep)
  422. {
  423. // Do some cleanup
  424. if (gAudiop)
  425. {
  426. gAudiop->cleanupAudioSource(mAudioSourcep);
  427. }
  428. mAudioSourcep = NULL;
  429. }
  430. if (flagAnimSource())
  431. {
  432. if (isAgentAvatarValid())
  433. {
  434. // Stop motions associated with this object
  435. gAgentAvatarp->stopMotionFromSource(mID);
  436. }
  437. }
  438. if (flagCameraSource())
  439. {
  440. LLFollowCamMgr::removeFollowCamParams(mID);
  441. }
  442. // Do this last, since this will destroy ourselves if we are the puppet
  443. // avatar object...
  444. if (av && av->isPuppetAvatar())
  445. {
  446. unlinkPuppetAvatar();
  447. }
  448. }
  449. void LLViewerObject::dump() const
  450. {
  451. llinfos << "Type: " << pCodeToString(mPrimitiveCode) << llendl;
  452. llinfos << "Drawable: " << (LLDrawable *)mDrawable << llendl;
  453. llinfos << "Update Age: "
  454. << LLFrameTimer::getElapsedSeconds() - mLastMessageUpdateSecs
  455. << llendl;
  456. llinfos << "Parent: " << getParent() << llendl;
  457. llinfos << "ID: " << mID << llendl;
  458. llinfos << "LocalID: " << mLocalID << llendl;
  459. llinfos << "PositionRegion: " << getPositionRegion() << llendl;
  460. llinfos << "PositionAgent: " << getPositionAgent() << llendl;
  461. llinfos << "PositionGlobal: " << getPositionGlobal() << llendl;
  462. llinfos << "Velocity: " << getVelocity() << llendl;
  463. llinfos << "Angular velocity: " << getAngularVelocity() << llendl;
  464. if (mDrawable.notNull() && mDrawable->getNumFaces() &&
  465. mDrawable->getFace(0))
  466. {
  467. LLFacePool* poolp = mDrawable->getFace(0)->getPool();
  468. if (poolp)
  469. {
  470. llinfos << "Pool: " << poolp << llendl;
  471. llinfos << "Pool reference count: " << poolp->mReferences.size()
  472. << llendl;
  473. }
  474. else
  475. {
  476. llinfos << "No pool for this object." << llendl;
  477. }
  478. }
  479. #if 0
  480. llinfos << "BoxTree Min: " << mDrawable->getBox()->getMin() << llendl;
  481. llinfos << "BoxTree Max: " << mDrawable->getBox()->getMin() << llendl;
  482. llinfos << "Velocity: " << getVelocity() << llendl;
  483. llinfos << "AnyOwner: " << permAnyOwner() << " YouOwner: "
  484. << permYouOwner() << " Edit: " << mPermEdit << llendl;
  485. llinfos << "UsePhysics: " << flagUsePhysics() << " CanSelect "
  486. << mCanSelect << " UserSelected " << mUserSelected << llendl;
  487. llinfos << "AppAngle: " << mAppAngle << llendl;
  488. llinfos << "PixelArea: " << mPixelArea << llendl;
  489. char buffer[1000];
  490. for (char* key = mNameValuePairs.getFirstKey(); key;
  491. key = mNameValuePairs.getNextKey())
  492. {
  493. mNameValuePairs[key]->printNameValue(buffer);
  494. llinfos << buffer << llendl;
  495. }
  496. for (child_list_t::iterator iter = mChildList.begin();
  497. iter != mChildList.end(); ++iter)
  498. {
  499. LLViewerObject* child = *iter;
  500. llinfos << " child " << child->mID << llendl;
  501. }
  502. #endif
  503. }
  504. void LLViewerObject::printNameValuePairs() const
  505. {
  506. for (name_value_map_t::const_iterator iter = mNameValuePairs.begin(),
  507. end = mNameValuePairs.end();
  508. iter != end; ++iter)
  509. {
  510. LLNameValue* nv = iter->second;
  511. llinfos << nv->printNameValue() << llendl;
  512. }
  513. }
  514. void LLViewerObject::initVOClasses()
  515. {
  516. sPingInterpolate = gSavedSettings.getBool("PingInterpolate");
  517. sVelocityInterpolate = gSavedSettings.getBool("VelocityInterpolate");
  518. setUpdateInterpolationTimes(gSavedSettings.getF32("InterpolationTime"),
  519. gSavedSettings.getF32("InterpolationPhaseOut"),
  520. gSavedSettings.getF32("RegionCrossingInterpolationTime"));
  521. sDebugObjectId.set(gSavedSettings.getString("DebugObjectId"), false);
  522. if (sDebugObjectId.notNull())
  523. {
  524. llinfos << "Debugging enabled on object Id: " << sDebugObjectId
  525. << llendl;
  526. }
  527. // New, experimental code paths toggles (get rid of them once confirmed):
  528. sUseNewTargetOmegaCode = gSavedSettings.getBool("UseNewTargetOmegaCode");
  529. // Initialized shared class stuff first.
  530. LLVOAvatar::initClass();
  531. LLVOTree::initClass();
  532. llinfos << "LLViewerObject size: " << sizeof(LLViewerObject) << llendl;
  533. LLVOGrass::initClass();
  534. LLVOWater::initClass();
  535. LLVOVolume::initClass();
  536. LLVOWLSky::initClass();
  537. LLVolumeImplFlexible::sUpdateFactor =
  538. gSavedSettings.getF32("RenderFlexTimeFactor");
  539. LLVOCacheEntry::updateSettings();
  540. initObjectDataMap();
  541. }
  542. void LLViewerObject::cleanupVOClasses()
  543. {
  544. LLVOWLSky::cleanupClass();
  545. LLVOGrass::cleanupClass();
  546. LLVOWater::cleanupClass();
  547. LLVOTree::cleanupClass();
  548. LLVOAvatar::cleanupClass();
  549. LLVOVolume::cleanupClass();
  550. sObjectDataMap.clear();
  551. }
  552. void LLViewerObject::toggleDebugUpdateMsg()
  553. {
  554. mDebugUpdateMsg = !mDebugUpdateMsg;
  555. llinfos << "Debugging " << (mDebugUpdateMsg ? "enabled" : "disabled")
  556. << " on object Id: " << mID << llendl;
  557. }
  558. void LLViewerObject::setlocalID(U32 local_id)
  559. {
  560. if (mLocalID != local_id)
  561. {
  562. mLocalID = local_id;
  563. if (sDebugObjectId == mID)
  564. {
  565. llinfos << "Received local Id " << local_id << " for object "
  566. << mID << llendl;
  567. }
  568. }
  569. }
  570. //static
  571. void LLViewerObject::setDebugObjectId(const LLUUID& id)
  572. {
  573. if (id == sDebugObjectId)
  574. {
  575. return;
  576. }
  577. if (sDebugObjectId.notNull())
  578. {
  579. LLViewerObject* objectp = gObjectList.findObject(sDebugObjectId);
  580. if (objectp)
  581. {
  582. objectp->mDebugUpdateMsg = false;
  583. }
  584. }
  585. sDebugObjectId = id;
  586. if (id.isNull())
  587. {
  588. return;
  589. }
  590. LLViewerObject* objectp = gObjectList.findObject(sDebugObjectId);
  591. if (objectp)
  592. {
  593. objectp->mDebugUpdateMsg = true;
  594. llinfos << "Debugging enabled on object Id: " << id << llendl;
  595. }
  596. }
  597. // Object data map for compressed && !OUT_TERSE_IMPROVED
  598. //static
  599. void LLViewerObject::initObjectDataMap()
  600. {
  601. U32 count = 0;
  602. sObjectDataMap["ID"] = count;
  603. count += sizeof(LLUUID);
  604. sObjectDataMap["LocalID"] = count;
  605. count += sizeof(U32);
  606. sObjectDataMap["PCode"] = count;
  607. count += sizeof(U8);
  608. sObjectDataMap["State"] = count;
  609. count += sizeof(U8);
  610. sObjectDataMap["CRC"] = count;
  611. count += sizeof(U32);
  612. sObjectDataMap["Material"] = count;
  613. count += sizeof(U8);
  614. sObjectDataMap["ClickAction"] = count;
  615. count += sizeof(U8);
  616. sObjectDataMap["Scale"] = count;
  617. count += sizeof(LLVector3);
  618. sObjectDataMap["Pos"] = count;
  619. count += sizeof(LLVector3);
  620. sObjectDataMap["Rot"] = count;
  621. count += sizeof(LLVector3);
  622. sObjectDataMap["SpecialCode"] = count;
  623. count += sizeof(U32);
  624. sObjectDataMap["Owner"] = count;
  625. count += sizeof(LLUUID);
  626. // LLVector3, when SpecialCode & 0x80 is set
  627. sObjectDataMap["Omega"] = count;
  628. count += sizeof(LLVector3);
  629. // ParentID is after Omega if there is Omega, otherwise is after Owner.
  630. // U32, when SpecialCode & 0x20 is set
  631. sObjectDataMap["ParentID"] = count;
  632. count += sizeof(U32);
  633. // The rest items are not included here
  634. }
  635. //static
  636. void LLViewerObject::unpackVector3(LLDataPackerBinaryBuffer* dp,
  637. LLVector3& value, std::string name)
  638. {
  639. dp->shift(sObjectDataMap[name]);
  640. dp->unpackVector3(value, name.c_str());
  641. dp->reset();
  642. }
  643. //static
  644. void LLViewerObject::unpackUUID(LLDataPackerBinaryBuffer* dp, LLUUID& value,
  645. std::string name)
  646. {
  647. dp->shift(sObjectDataMap[name]);
  648. dp->unpackUUID(value, name.c_str());
  649. dp->reset();
  650. }
  651. //static
  652. void LLViewerObject::unpackU32(LLDataPackerBinaryBuffer* dp, U32& value,
  653. std::string name)
  654. {
  655. dp->shift(sObjectDataMap[name]);
  656. dp->unpackU32(value, name.c_str());
  657. dp->reset();
  658. }
  659. //static
  660. void LLViewerObject::unpackU8(LLDataPackerBinaryBuffer* dp, U8& value,
  661. std::string name)
  662. {
  663. dp->shift(sObjectDataMap[name]);
  664. dp->unpackU8(value, name.c_str());
  665. dp->reset();
  666. }
  667. //static
  668. U32 LLViewerObject::unpackParentID(LLDataPackerBinaryBuffer* dp,
  669. U32& parent_id)
  670. {
  671. dp->shift(sObjectDataMap["SpecialCode"]);
  672. U32 value;
  673. dp->unpackU32(value, "SpecialCode");
  674. parent_id = 0;
  675. if (value & 0x20)
  676. {
  677. S32 offset = sObjectDataMap["ParentID"];
  678. if (!(value & 0x80))
  679. {
  680. offset -= sizeof(LLVector3);
  681. }
  682. dp->shift(offset);
  683. dp->unpackU32(parent_id, "ParentID");
  684. }
  685. dp->reset();
  686. return parent_id;
  687. }
  688. // Replaces all name value pairs with data from \n delimited list. Does not
  689. // update the server.
  690. void LLViewerObject::setNameValueList(const std::string& name_value_list)
  691. {
  692. // Clear out the old
  693. for_each(mNameValuePairs.begin(), mNameValuePairs.end(),
  694. DeletePairedPointer());
  695. mNameValuePairs.clear();
  696. // Bring in the new
  697. std::string::size_type length = name_value_list.length();
  698. std::string::size_type start = 0;
  699. std::string::size_type end;
  700. while (start < length)
  701. {
  702. end = name_value_list.find_first_of("\n", start);
  703. if (end == std::string::npos)
  704. {
  705. end = length;
  706. }
  707. if (end > start)
  708. {
  709. std::string tok = name_value_list.substr(start, end - start);
  710. addNVPair(tok);
  711. }
  712. start = end + 1;
  713. }
  714. }
  715. // This method returns true if the object is over land owned by the agent.
  716. bool LLViewerObject::isReturnable()
  717. {
  718. if (isAttachment())
  719. {
  720. return false;
  721. }
  722. std::vector<LLBBox> boxes;
  723. boxes.push_back(LLBBox(getPositionRegion(), getRotationRegion(),
  724. getScale() * -0.5f, getScale() * 0.5f).getAxisAligned());
  725. for (child_list_t::iterator iter = mChildList.begin(),
  726. end = mChildList.end();
  727. iter != end; ++iter)
  728. {
  729. LLViewerObject* child = *iter;
  730. if (!child) return false; // Paranoia
  731. boxes.push_back(LLBBox(child->getPositionRegion(),
  732. child->getRotationRegion(),
  733. child->getScale() * -0.5f,
  734. child->getScale() * 0.5f).getAxisAligned());
  735. }
  736. bool result = mRegionp && mRegionp->objectIsReturnable(getPositionRegion(),
  737. boxes);
  738. if (!result)
  739. {
  740. // Get list of neighboring regions relative to this VO's region
  741. std::vector<LLViewerRegion*> unique_regions;
  742. mRegionp->getNeighboringRegions(unique_regions);
  743. // Build AABB's for root and all children
  744. returnable_vec_t returnables;
  745. for (std::vector<LLViewerRegion*>::iterator
  746. reg_it = unique_regions.begin(),
  747. reg_end = unique_regions.end();
  748. reg_it != reg_end; ++reg_it)
  749. {
  750. LLViewerRegion* target_regionp = *reg_it;
  751. // Add the root vo as there may be no children and we still want
  752. // to test for any edge overlap
  753. buildReturnablesForChildrenVO(returnables, this, target_regionp);
  754. // Add its children
  755. for (child_list_t::iterator iter = mChildList.begin(),
  756. end = mChildList.end();
  757. iter != end; ++iter)
  758. {
  759. LLViewerObject* childp = *iter;
  760. buildReturnablesForChildrenVO(returnables, childp,
  761. target_regionp);
  762. }
  763. }
  764. // TBD: eventually create a region -> box list map
  765. for (returnable_vec_t::iterator it = returnables.begin(),
  766. end = returnables.end();
  767. it != end; ++it)
  768. {
  769. boxes.clear();
  770. LLViewerRegion* regionp = it->region;
  771. boxes.push_back(it->box);
  772. if (regionp && regionp->childrenObjectReturnable(boxes) &&
  773. regionp->canManageEstate())
  774. {
  775. result = true;
  776. break;
  777. }
  778. }
  779. }
  780. return result;
  781. }
  782. void LLViewerObject::buildReturnablesForChildrenVO(returnable_vec_t& returnables,
  783. LLViewerObject* childp,
  784. LLViewerRegion* target_regionp)
  785. {
  786. if (!childp)
  787. {
  788. llerrs << "Child viewerobject is NULL" << llendl;
  789. }
  790. constructAndAddReturnable(returnables, childp, target_regionp);
  791. // We want to handle any children VO's as well
  792. for (child_list_t::iterator iter = childp->mChildList.begin(),
  793. end = childp->mChildList.end();
  794. iter != end; ++iter)
  795. {
  796. LLViewerObject* obj = *iter;
  797. buildReturnablesForChildrenVO(returnables, obj, target_regionp);
  798. }
  799. }
  800. void LLViewerObject::constructAndAddReturnable(returnable_vec_t& returnables,
  801. LLViewerObject* childp,
  802. LLViewerRegion* target_regionp)
  803. {
  804. LLVector3 target_region_pos;
  805. target_region_pos.set(childp->getPositionGlobal());
  806. LLBBox child_bbox = LLBBox(target_region_pos, childp->getRotationRegion(),
  807. childp->getScale() * -0.5f,
  808. childp->getScale() * 0.5f).getAxisAligned();
  809. LLVector3 edge_a = target_region_pos + child_bbox.getMinLocal();
  810. LLVector3 edge_b = target_region_pos + child_bbox.getMaxLocal();
  811. LLVector3d edge_a_3d, edge_b_3d;
  812. edge_a_3d.set(edge_a);
  813. edge_b_3d.set(edge_b);
  814. // Only add the box when either of the extents are in a neighboring region
  815. if (target_regionp->pointInRegionGlobal(edge_a_3d) ||
  816. target_regionp->pointInRegionGlobal(edge_b_3d))
  817. {
  818. PotentialReturnableObject returnable_obj;
  819. returnable_obj.box = child_bbox;
  820. returnable_obj.region = target_regionp;
  821. returnables.push_back(returnable_obj);
  822. }
  823. }
  824. bool LLViewerObject::setParent(LLViewerObject* parent)
  825. {
  826. if (mParent != parent)
  827. {
  828. LLViewerObject* old_parent = (LLViewerObject*)mParent;
  829. bool ret = LLPrimitive::setParent(parent);
  830. if (ret && old_parent && parent)
  831. {
  832. old_parent->removeChild(this);
  833. }
  834. return ret;
  835. }
  836. return false;
  837. }
  838. void LLViewerObject::addChild(LLViewerObject* childp)
  839. {
  840. for (child_list_t::iterator i = mChildList.begin(), end = mChildList.end();
  841. i != end; ++i)
  842. {
  843. if (*i == childp)
  844. {
  845. // Already has child
  846. return;
  847. }
  848. }
  849. if (!isAvatar())
  850. {
  851. // Propagate selection properties
  852. childp->mCanSelect = mCanSelect;
  853. }
  854. if (childp->setParent(this))
  855. {
  856. mChildList.push_back(childp);
  857. childp->afterReparent();
  858. }
  859. }
  860. void LLViewerObject::removeChild(LLViewerObject* childp)
  861. {
  862. if (!childp) return;
  863. for (child_list_t::iterator i = mChildList.begin(), end = mChildList.end();
  864. i != end; ++i)
  865. {
  866. if (*i == childp)
  867. {
  868. if (!childp->isAvatar() && mDrawable.notNull() &&
  869. mDrawable->isActive() && childp->mDrawable.notNull() &&
  870. !isAvatar())
  871. {
  872. gPipeline.markRebuild(childp->mDrawable,
  873. LLDrawable::REBUILD_VOLUME);
  874. }
  875. mChildList.erase(i);
  876. if (childp->getParent() == this)
  877. {
  878. childp->setParent(NULL);
  879. }
  880. break;
  881. }
  882. }
  883. if (childp->mUserSelected)
  884. {
  885. gSelectMgr.deselectObjectAndFamily(childp);
  886. gSelectMgr.selectObjectAndFamily(childp, true);
  887. }
  888. }
  889. void LLViewerObject::addThisAndAllChildren(std::vector<LLViewerObject*>& objects)
  890. {
  891. objects.push_back(this);
  892. for (child_list_t::iterator iter = mChildList.begin(),
  893. end = mChildList.end();
  894. iter != end; ++iter)
  895. {
  896. LLViewerObject* child = *iter;
  897. if (child && !child->isAvatar())
  898. {
  899. child->addThisAndAllChildren(objects);
  900. }
  901. }
  902. }
  903. void LLViewerObject::addThisAndNonJointChildren(std::vector<LLViewerObject*>& objects)
  904. {
  905. objects.push_back(this);
  906. // Do not add any attachments when temporarily selecting avatar
  907. if (isAvatar())
  908. {
  909. return;
  910. }
  911. for (child_list_t::iterator iter = mChildList.begin(),
  912. end = mChildList.end();
  913. iter != end; ++iter)
  914. {
  915. LLViewerObject* child = *iter;
  916. if (child && !child->isAvatar())
  917. {
  918. child->addThisAndNonJointChildren(objects);
  919. }
  920. }
  921. }
  922. bool LLViewerObject::isChild(LLViewerObject* childp) const
  923. {
  924. for (child_list_t::const_iterator iter = mChildList.begin(),
  925. end = mChildList.end();
  926. iter != end; ++iter)
  927. {
  928. LLViewerObject* testchild = *iter;
  929. if (testchild == childp)
  930. {
  931. return true;
  932. }
  933. }
  934. return false;
  935. }
  936. bool LLViewerObject::isSeat() const
  937. {
  938. for (child_list_t::const_iterator iter = mChildList.begin(),
  939. end = mChildList.end();
  940. iter != end; ++iter)
  941. {
  942. LLViewerObject* child = *iter;
  943. if (child && child->isAvatar())
  944. {
  945. return true;
  946. }
  947. }
  948. return false;
  949. }
  950. bool LLViewerObject::isAgentSeat() const
  951. {
  952. if (!isAgentAvatarValid() || !gAgentAvatarp->mIsSitting)
  953. {
  954. // Agent is not even sitting, so do not bother to check further
  955. return false;
  956. }
  957. for (child_list_t::const_iterator iter = mChildList.begin(),
  958. end = mChildList.end();
  959. iter != end; ++iter)
  960. {
  961. LLViewerObject* child = *iter;
  962. if (child && child == (LLViewerObject*)gAgentAvatarp)
  963. {
  964. return true;
  965. }
  966. }
  967. return false;
  968. }
  969. bool LLViewerObject::setDrawableParent(LLDrawable* parentp)
  970. {
  971. if (mDrawable.isNull())
  972. {
  973. return false;
  974. }
  975. bool ret = mDrawable->mXform.setParent(parentp ? &parentp->mXform : NULL);
  976. if (!ret)
  977. {
  978. return false;
  979. }
  980. LLDrawable* old_parent = mDrawable->mParent;
  981. mDrawable->mParent = parentp;
  982. if (parentp && mDrawable->isActive())
  983. {
  984. parentp->makeActive();
  985. parentp->setState(LLDrawable::ACTIVE_CHILD);
  986. }
  987. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
  988. if ((old_parent != parentp && old_parent) ||
  989. (parentp && parentp->isActive()))
  990. {
  991. // *TODO: we should not be relying on setDrawable parent to call
  992. // markMoved()
  993. gPipeline.markMoved(mDrawable, false);
  994. }
  995. else if (!mDrawable->isAvatar())
  996. {
  997. mDrawable->updateXform(true);
  998. #if 0
  999. if (!mDrawable->getSpatialGroup())
  1000. {
  1001. mDrawable->movePartition();
  1002. }
  1003. #endif
  1004. }
  1005. return ret;
  1006. }
  1007. // Show or hide particles, icon and HUD
  1008. void LLViewerObject::hideExtraDisplayItems(bool hidden)
  1009. {
  1010. if (mPartSourcep.notNull())
  1011. {
  1012. LLViewerPartSourceScript* ps = mPartSourcep.get();
  1013. ps->setSuspended(hidden);
  1014. }
  1015. if (mText.notNull())
  1016. {
  1017. LLHUDText* hudtext = mText.get();
  1018. hudtext->setHidden(hidden);
  1019. }
  1020. if (mIcon.notNull())
  1021. {
  1022. LLHUDIcon* hudicon = mIcon.get();
  1023. hudicon->setHidden(hidden);
  1024. }
  1025. }
  1026. U32 LLViewerObject::checkMediaURL(const std::string& media_url)
  1027. {
  1028. U32 retval = 0;
  1029. if (!mMedia && !media_url.empty())
  1030. {
  1031. retval |= MEDIA_URL_ADDED;
  1032. mMedia = new LLViewerObjectMedia;
  1033. mMedia->mMediaURL = media_url;
  1034. mMedia->mMediaType = LLViewerObject::MEDIA_SET;
  1035. mMedia->mPassedWhitelist = false;
  1036. }
  1037. else if (mMedia)
  1038. {
  1039. if (media_url.empty())
  1040. {
  1041. retval |= MEDIA_URL_REMOVED;
  1042. delete mMedia;
  1043. mMedia = NULL;
  1044. }
  1045. else if (mMedia->mMediaURL != media_url)
  1046. {
  1047. // We just added or changed a media.
  1048. retval |= MEDIA_URL_UPDATED;
  1049. mMedia->mMediaURL = media_url;
  1050. mMedia->mPassedWhitelist = false;
  1051. }
  1052. }
  1053. return retval;
  1054. }
  1055. // Extracts spatial information from object update message. Return parent_id.
  1056. //static
  1057. U32 LLViewerObject::extractSpatialExtents(LLDataPackerBinaryBuffer* dp,
  1058. LLVector3& pos, LLVector3& scale,
  1059. LLQuaternion& rot)
  1060. {
  1061. U32 parent_id = 0;
  1062. LLViewerObject::unpackParentID(dp, parent_id);
  1063. LLViewerObject::unpackVector3(dp, scale, "Scale");
  1064. LLViewerObject::unpackVector3(dp, pos, "Pos");
  1065. LLVector3 vec;
  1066. LLViewerObject::unpackVector3(dp, vec, "Rot");
  1067. rot.unpackFromVector3(vec);
  1068. return parent_id;
  1069. }
  1070. U32 LLViewerObject::processUpdateMessage(LLMessageSystem* mesgsys,
  1071. void** user_data, U32 block_num,
  1072. EObjectUpdateType update_type,
  1073. LLDataPacker* dp)
  1074. {
  1075. U32 retval = 0x0;
  1076. // If region is removed from the list it is also deleted.
  1077. if (!gWorld.isRegionListed(mRegionp))
  1078. {
  1079. llwarns << "Updating object in an invalid region" << llendl;
  1080. return retval;
  1081. }
  1082. // Coordinates of objects on simulators are region-local.
  1083. U64 region_handle;
  1084. if (mesgsys)
  1085. {
  1086. mesgsys->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle,
  1087. region_handle);
  1088. LLViewerRegion* regionp = gWorld.getRegionFromHandle(region_handle);
  1089. if (regionp != mRegionp && regionp && mRegionp) // region cross
  1090. {
  1091. // This is the redundant position and region update, but it is
  1092. // necessary in case the viewer misses the following position and
  1093. // region update messages from sim. This redundant update should
  1094. // not cause any problems.
  1095. LLVector3 delta_pos = mRegionp->getOriginAgent() -
  1096. regionp->getOriginAgent();
  1097. // Update to the new region position immediately:
  1098. setPositionParent(getPosition() + delta_pos);
  1099. // Change the region:
  1100. setRegion(regionp);
  1101. }
  1102. else if (regionp != mRegionp)
  1103. {
  1104. if (mRegionp)
  1105. {
  1106. mRegionp->removeFromCreatedList(getLocalID());
  1107. }
  1108. if (regionp)
  1109. {
  1110. regionp->addToCreatedList(getLocalID());
  1111. }
  1112. mRegionp = regionp;
  1113. }
  1114. }
  1115. if (!mRegionp)
  1116. {
  1117. U32 x, y;
  1118. from_region_handle(region_handle, &x, &y);
  1119. llerrs << "Object has invalid region " << x << ":" << y << llendl;
  1120. return retval;
  1121. }
  1122. if (mesgsys)
  1123. {
  1124. U16 time_dilation16;
  1125. mesgsys->getU16Fast(_PREHASH_RegionData, _PREHASH_TimeDilation,
  1126. time_dilation16);
  1127. F32 time_dilation = ((F32)time_dilation16) / 65535.f;
  1128. mRegionp->setTimeDilation(time_dilation);
  1129. }
  1130. // This will be used to determine if we have really changed position. Use
  1131. // getPosition, not getPositionRegion, since this is what we're comparing
  1132. // directly against.
  1133. LLVector3 test_pos_parent = getPosition();
  1134. // This needs to match the largest size below.
  1135. constexpr S32 MAX_DATA_SIZE = 60 + 16;
  1136. static U8 data[MAX_DATA_SIZE];
  1137. #if LL_BIG_ENDIAN
  1138. U16 valswizzle[4];
  1139. #endif
  1140. U16* val;
  1141. constexpr F32 MAX_HEIGHT = MAX_OBJECT_Z;
  1142. // Variable region size support:
  1143. const F32 size = mRegionp->getWidth();
  1144. const F32 min_height = -size;
  1145. S32 length, count;
  1146. S32 this_update_precision = 32; // in bits
  1147. // Temporaries, because we need to compare with previous to set dirty flags
  1148. LLVector3 new_pos_parent, new_vel, new_acc, new_angv;
  1149. LLVector3 new_scale = getScale();
  1150. LLVector3 old_angv = getAngularVelocity();
  1151. LLQuaternion new_rot;
  1152. U8 material = 0;
  1153. U8 click_action = 0;
  1154. U32 crc = 0;
  1155. U32 parent_id = 0;
  1156. LLViewerObject* cur_parentp = (LLViewerObject*)getParent();
  1157. if (cur_parentp)
  1158. {
  1159. parent_id = cur_parentp->mLocalID;
  1160. }
  1161. // If needed, enable the "UpdateType" debug tag for this method call with
  1162. // this debugged LLViewerObject instance. HB
  1163. bool set_debug_tag = mDebugUpdateMsg &&
  1164. !HBFloaterDebugTags::debugTagActive("UpdateType");
  1165. if (set_debug_tag)
  1166. {
  1167. HBFloaterDebugTags::setTag("UpdateType", true);
  1168. }
  1169. if (!dp)
  1170. {
  1171. if (mDebugUpdateMsg)
  1172. {
  1173. llinfos << "Update message received for object " << mID << ":"
  1174. << llendl;
  1175. }
  1176. switch (update_type)
  1177. {
  1178. case OUT_FULL:
  1179. {
  1180. LL_DEBUGS("UpdateType") << "Full: " << mID << LL_ENDL;
  1181. // Clear cost and linkset cost
  1182. setObjectCostStale();
  1183. if (gFloaterToolsp && mUserSelected)
  1184. {
  1185. gFloaterToolsp->dirty();
  1186. }
  1187. mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_CRC, crc,
  1188. block_num);
  1189. mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ParentID,
  1190. parent_id, block_num);
  1191. LLUUID audio_uuid;
  1192. mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_Sound,
  1193. audio_uuid, block_num);
  1194. // *HACK: Owner Id only valid if non-null sound Id or particle
  1195. // system and if audio_uuid or particle system is not null:
  1196. LLUUID owner_id;
  1197. mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID,
  1198. owner_id, block_num);
  1199. F32 gain;
  1200. mesgsys->getF32Fast(_PREHASH_ObjectData, _PREHASH_Gain, gain,
  1201. block_num);
  1202. F32 cutoff;
  1203. mesgsys->getF32Fast(_PREHASH_ObjectData, _PREHASH_Radius,
  1204. cutoff, block_num);
  1205. U8 sound_flags;
  1206. mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_Flags,
  1207. sound_flags, block_num);
  1208. mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_Material,
  1209. material, block_num);
  1210. mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_ClickAction,
  1211. click_action, block_num);
  1212. mesgsys->getVector3Fast(_PREHASH_ObjectData, _PREHASH_Scale,
  1213. new_scale, block_num);
  1214. length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num,
  1215. _PREHASH_ObjectData);
  1216. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  1217. _PREHASH_ObjectData, data, length,
  1218. block_num, MAX_DATA_SIZE);
  1219. mTotalCRC = crc;
  1220. // Might need to update mSourceMuted here to properly pick up
  1221. // the new cutoff radius.
  1222. mSoundCutOffRadius = cutoff;
  1223. // Owner Id used for sound muting or particle system muting
  1224. mOwnerID = owner_id;
  1225. setAttachedSound(audio_uuid, owner_id, gain, sound_flags);
  1226. U8 old_material = getMaterial();
  1227. if (old_material != material)
  1228. {
  1229. setMaterial(material);
  1230. if (mDrawable.notNull())
  1231. {
  1232. gPipeline.markMoved(mDrawable, false); // Undamped
  1233. }
  1234. }
  1235. setClickAction(click_action);
  1236. count = 0;
  1237. LLVector4 collision_plane;
  1238. switch (length)
  1239. {
  1240. case (60 + 16):
  1241. // Pull out collision normal for avatar
  1242. htonmemcpy(collision_plane.mV, &data[count], MVT_LLVector4,
  1243. sizeof(LLVector4));
  1244. if (isAvatar())
  1245. {
  1246. ((LLVOAvatar*)this)->setFootPlane(collision_plane);
  1247. }
  1248. count += sizeof(LLVector4);
  1249. // Fall through
  1250. case 60:
  1251. {
  1252. this_update_precision = 32;
  1253. // This is a terse update
  1254. htonmemcpy(new_pos_parent.mV, &data[count], MVT_LLVector3,
  1255. sizeof(LLVector3));
  1256. count += sizeof(LLVector3);
  1257. htonmemcpy((void*)getVelocity().mV, &data[count],
  1258. MVT_LLVector3, sizeof(LLVector3));
  1259. count += sizeof(LLVector3);
  1260. htonmemcpy((void*)getAcceleration().mV, &data[count],
  1261. MVT_LLVector3, sizeof(LLVector3));
  1262. count += sizeof(LLVector3);
  1263. // Theta
  1264. LLVector3 vec;
  1265. htonmemcpy(vec.mV, &data[count], MVT_LLVector3,
  1266. sizeof(LLVector3));
  1267. new_rot.unpackFromVector3(vec);
  1268. count += sizeof(LLVector3);
  1269. // Target omega
  1270. htonmemcpy((void*)new_angv.mV, &data[count], MVT_LLVector3,
  1271. sizeof(LLVector3));
  1272. if (new_angv.isExactlyZero())
  1273. {
  1274. resetRot();
  1275. }
  1276. setAngularVelocity(new_angv);
  1277. if (mDebugUpdateMsg)
  1278. {
  1279. llinfos << "Angular velocity (1): " << new_angv << llendl;
  1280. }
  1281. #if LL_DARWIN // Why is that ??? HB
  1282. if (length == 76)
  1283. {
  1284. setAngularVelocity(LLVector3::zero);
  1285. }
  1286. #endif
  1287. break;
  1288. }
  1289. case (32 + 16):
  1290. // Pull out collision normal for avatar
  1291. htonmemcpy(collision_plane.mV, &data[count], MVT_LLVector4,
  1292. sizeof(LLVector4));
  1293. if (isAvatar())
  1294. {
  1295. ((LLVOAvatar*)this)->setFootPlane(collision_plane);
  1296. }
  1297. count += sizeof(LLVector4);
  1298. // Fall through
  1299. case 32:
  1300. this_update_precision = 16;
  1301. test_pos_parent.quantize16(-0.5f * size, 1.5f * size,
  1302. min_height, MAX_HEIGHT);
  1303. // This is a terse 16 update, so treat data as an array of U16's.
  1304. #if LL_BIG_ENDIAN
  1305. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1306. val = valswizzle;
  1307. #else
  1308. val = (U16*)&data[count];
  1309. #endif
  1310. count += sizeof(U16) * 3;
  1311. new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f * size,
  1312. 1.5f * size);
  1313. new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f * size,
  1314. 1.5f * size);
  1315. new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], min_height,
  1316. MAX_HEIGHT);
  1317. #if LL_BIG_ENDIAN
  1318. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1319. val = valswizzle;
  1320. #else
  1321. val = (U16*)&data[count];
  1322. #endif
  1323. count += sizeof(U16) * 3;
  1324. setVelocity(LLVector3(U16_to_F32(val[VX], -size, size),
  1325. U16_to_F32(val[VY], -size, size),
  1326. U16_to_F32(val[VZ], -size, size)));
  1327. #if LL_BIG_ENDIAN
  1328. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1329. val = valswizzle;
  1330. #else
  1331. val = (U16*)&data[count];
  1332. #endif
  1333. count += sizeof(U16) * 3;
  1334. setAcceleration(LLVector3(U16_to_F32(val[VX], -size, size),
  1335. U16_to_F32(val[VY], -size, size),
  1336. U16_to_F32(val[VZ], -size,
  1337. size)));
  1338. #if LL_BIG_ENDIAN
  1339. htonmemcpy(valswizzle, &data[count], MVT_U16Quat, 4);
  1340. val = valswizzle;
  1341. #else
  1342. val = (U16*)&data[count];
  1343. #endif
  1344. count += sizeof(U16) * 4;
  1345. new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
  1346. new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
  1347. new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
  1348. new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
  1349. #if LL_BIG_ENDIAN
  1350. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1351. val = valswizzle;
  1352. #else
  1353. val = (U16*)&data[count];
  1354. #endif
  1355. new_angv.set(U16_to_F32(val[VX], -size, size),
  1356. U16_to_F32(val[VY], -size, size),
  1357. U16_to_F32(val[VZ], -size, size));
  1358. if (new_angv.isExactlyZero())
  1359. {
  1360. resetRot();
  1361. }
  1362. setAngularVelocity(new_angv);
  1363. if (mDebugUpdateMsg)
  1364. {
  1365. llinfos << "Angular velocity (2): " << new_angv << llendl;
  1366. }
  1367. break;
  1368. case 16:
  1369. this_update_precision = 8;
  1370. test_pos_parent.quantize8(-0.5f * size, 1.5f * size,
  1371. min_height, MAX_HEIGHT);
  1372. // This is a terse 8 update
  1373. new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f * size,
  1374. 1.5f * size);
  1375. new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f * size,
  1376. 1.5f * size);
  1377. new_pos_parent.mV[VZ] = U8_to_F32(data[2], min_height,
  1378. MAX_HEIGHT);
  1379. setVelocity(U8_to_F32(data[3], -size, size),
  1380. U8_to_F32(data[4], -size, size),
  1381. U8_to_F32(data[5], -size, size));
  1382. setAcceleration(U8_to_F32(data[6], -size, size),
  1383. U8_to_F32(data[7], -size, size),
  1384. U8_to_F32(data[8], -size, size));
  1385. new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
  1386. new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
  1387. new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
  1388. new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
  1389. new_angv.set(U8_to_F32(data[13], -size, size),
  1390. U8_to_F32(data[14], -size, size),
  1391. U8_to_F32(data[15], -size, size));
  1392. if (new_angv.isExactlyZero())
  1393. {
  1394. resetRot();
  1395. }
  1396. setAngularVelocity(new_angv);
  1397. if (mDebugUpdateMsg)
  1398. {
  1399. llinfos << "Angular velocity (3): " << new_angv << llendl;
  1400. }
  1401. break;
  1402. }
  1403. ////////////////////////////////////////////////////
  1404. // Here we handle data specific to the full message.
  1405. U32 flags;
  1406. mesgsys->getU32Fast(_PREHASH_ObjectData,
  1407. _PREHASH_UpdateFlags, flags, block_num);
  1408. // Clear all but local flags
  1409. mFlags &= FLAGS_LOCAL;
  1410. mFlags |= flags;
  1411. mFlagsLoaded = true;
  1412. U8 state;
  1413. mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state,
  1414. block_num);
  1415. mAttachmentState = state;
  1416. // ...new objects that should come in selected need to be added
  1417. // to the selected list
  1418. mCreateSelected = ((flags & FLAGS_CREATE_SELECTED) != 0);
  1419. // Set all name value pairs
  1420. S32 nv_size = mesgsys->getSizeFast(_PREHASH_ObjectData,
  1421. block_num,
  1422. _PREHASH_NameValue);
  1423. if (nv_size > 0)
  1424. {
  1425. std::string name_value_list;
  1426. mesgsys->getStringFast(_PREHASH_ObjectData,
  1427. _PREHASH_NameValue, name_value_list,
  1428. block_num);
  1429. setNameValueList(name_value_list);
  1430. }
  1431. // Clear out any existing generic data
  1432. if (mData)
  1433. {
  1434. delete[] mData;
  1435. }
  1436. // Check for appended generic data
  1437. S32 data_size = mesgsys->getSizeFast(_PREHASH_ObjectData,
  1438. block_num, _PREHASH_Data);
  1439. if (data_size <= 0)
  1440. {
  1441. mData = NULL;
  1442. }
  1443. else
  1444. {
  1445. // ...has generic data
  1446. mData = new U8[data_size];
  1447. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  1448. _PREHASH_Data, mData, data_size,
  1449. block_num);
  1450. }
  1451. // Reset the cached values used for debug info display toggle.
  1452. mHudTextString.clear();
  1453. mHudTextColor = LLColor4U::white;
  1454. S32 text_size = mesgsys->getSizeFast(_PREHASH_ObjectData,
  1455. block_num, _PREHASH_Text);
  1456. if (text_size > 1)
  1457. {
  1458. // Setup object text
  1459. if (!mText)
  1460. {
  1461. mText = (LLHUDText*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
  1462. mText->setFont(LLFontGL::getFontSansSerif());
  1463. mText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
  1464. mText->setMaxLines(-1);
  1465. mText->setSourceObject(this);
  1466. mText->setOnHUDAttachment(isHUDAttachment());
  1467. }
  1468. mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_Text,
  1469. mHudTextString, block_num);
  1470. LLColor4U coloru;
  1471. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  1472. _PREHASH_TextColor, coloru.mV,
  1473. 4, block_num);
  1474. // Alpha was flipped so that it zero encoded better
  1475. coloru.mV[3] = 255 - coloru.mV[3];
  1476. mHudTextColor = LLColor4(coloru);
  1477. // Fading is disabled only when the hovetext is being
  1478. // overridden by debug text.
  1479. if (mText->getDoFade())
  1480. {
  1481. mText->setColor(mHudTextColor);
  1482. mText->setStringUTF8(mHudTextString);
  1483. }
  1484. //MK
  1485. mText->mLastMessageText = mHudTextString;
  1486. //mk
  1487. setChanged(MOVED | SILHOUETTE);
  1488. }
  1489. else if (mText.notNull())
  1490. {
  1491. mText->markDead();
  1492. mText = NULL;
  1493. }
  1494. std::string media_url;
  1495. mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_MediaURL,
  1496. media_url, block_num);
  1497. retval |= checkMediaURL(media_url);
  1498. //
  1499. // Unpack particle system data
  1500. //
  1501. unpackParticleSource(block_num, owner_id);
  1502. // Mark all extra parameters not used
  1503. for (S32 i = 0; i < LL_EPARAMS_COUNT; ++i)
  1504. {
  1505. mExtraParameterInUse[i] = false;
  1506. }
  1507. // Unpack extra parameters
  1508. S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num,
  1509. _PREHASH_ExtraParams);
  1510. if (size > 0)
  1511. {
  1512. U8* buffer = new U8[size];
  1513. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  1514. _PREHASH_ExtraParams,
  1515. buffer, size, block_num);
  1516. LLDataPackerBinaryBuffer dp(buffer, size);
  1517. U8 num_parameters;
  1518. dp.unpackU8(num_parameters, "num_params");
  1519. U8 param_block[MAX_OBJECT_PARAMS_SIZE];
  1520. for (U8 param = 0; param < num_parameters; ++param)
  1521. {
  1522. U16 param_type;
  1523. S32 param_size;
  1524. dp.unpackU16(param_type, "param_type");
  1525. dp.unpackBinaryData(param_block, param_size,
  1526. "param_data");
  1527. LLDataPackerBinaryBuffer dp2(param_block, param_size);
  1528. unpackParameterEntry(param_type, &dp2);
  1529. }
  1530. delete[] buffer;
  1531. }
  1532. for (S32 i = 0; i < LL_EPARAMS_COUNT; ++i)
  1533. {
  1534. if (!mExtraParameterInUse[i])
  1535. {
  1536. parameterChanged(LL_EPARAM_TYPE(i),
  1537. mExtraParameters[i], false, false);
  1538. }
  1539. }
  1540. break;
  1541. }
  1542. case OUT_TERSE_IMPROVED:
  1543. {
  1544. LL_DEBUGS("UpdateType") << "TI:" << mID << LL_ENDL;
  1545. length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num,
  1546. _PREHASH_ObjectData);
  1547. mesgsys->getBinaryDataFast(_PREHASH_ObjectData,
  1548. _PREHASH_ObjectData, data, length,
  1549. block_num, MAX_DATA_SIZE);
  1550. count = 0;
  1551. LLVector4 collision_plane;
  1552. switch (length)
  1553. {
  1554. case (60 + 16):
  1555. // Pull out collision normal for avatar
  1556. htonmemcpy(collision_plane.mV, &data[count], MVT_LLVector4,
  1557. sizeof(LLVector4));
  1558. if (isAvatar())
  1559. {
  1560. ((LLVOAvatar*)this)->setFootPlane(collision_plane);
  1561. }
  1562. count += sizeof(LLVector4);
  1563. // Fall through
  1564. case 60:
  1565. {
  1566. // This is a terse 32 update
  1567. this_update_precision = 32;
  1568. htonmemcpy(new_pos_parent.mV, &data[count], MVT_LLVector3,
  1569. sizeof(LLVector3));
  1570. count += sizeof(LLVector3);
  1571. htonmemcpy((void*)getVelocity().mV, &data[count],
  1572. MVT_LLVector3, sizeof(LLVector3));
  1573. count += sizeof(LLVector3);
  1574. htonmemcpy((void*)getAcceleration().mV, &data[count],
  1575. MVT_LLVector3, sizeof(LLVector3));
  1576. count += sizeof(LLVector3);
  1577. // Theta
  1578. {
  1579. LLVector3 vec;
  1580. htonmemcpy(vec.mV, &data[count], MVT_LLVector3,
  1581. sizeof(LLVector3));
  1582. new_rot.unpackFromVector3(vec);
  1583. }
  1584. count += sizeof(LLVector3);
  1585. // Target omega
  1586. htonmemcpy((void*)new_angv.mV, &data[count], MVT_LLVector3,
  1587. sizeof(LLVector3));
  1588. if (new_angv.isExactlyZero())
  1589. {
  1590. resetRot();
  1591. }
  1592. setAngularVelocity(new_angv);
  1593. if (mDebugUpdateMsg)
  1594. {
  1595. llinfos << "Angular velocity (4): " << new_angv << llendl;
  1596. }
  1597. #if LL_DARWIN // Why is that ??? HB
  1598. if (length == 76)
  1599. {
  1600. setAngularVelocity(LLVector3::zero);
  1601. }
  1602. #endif
  1603. break;
  1604. }
  1605. case (32 + 16):
  1606. // Pull out collision normal for avatar
  1607. htonmemcpy(collision_plane.mV, &data[count], MVT_LLVector4,
  1608. sizeof(LLVector4));
  1609. if (isAvatar())
  1610. {
  1611. ((LLVOAvatar*)this)->setFootPlane(collision_plane);
  1612. }
  1613. count += sizeof(LLVector4);
  1614. // fall through
  1615. case 32:
  1616. // This is a terse 16 update
  1617. this_update_precision = 16;
  1618. test_pos_parent.quantize16(-0.5f * size, 1.5f * size,
  1619. min_height, MAX_HEIGHT);
  1620. #if LL_BIG_ENDIAN
  1621. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1622. val = valswizzle;
  1623. #else
  1624. val = (U16*)&data[count];
  1625. #endif
  1626. count += sizeof(U16) * 3;
  1627. new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f * size,
  1628. 1.5f * size);
  1629. new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f * size,
  1630. 1.5f * size);
  1631. new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], min_height,
  1632. MAX_HEIGHT);
  1633. #if LL_BIG_ENDIAN
  1634. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1635. val = valswizzle;
  1636. #else
  1637. val = (U16*)&data[count];
  1638. #endif
  1639. count += sizeof(U16) * 3;
  1640. setVelocity(U16_to_F32(val[VX], -size, size),
  1641. U16_to_F32(val[VY], -size, size),
  1642. U16_to_F32(val[VZ], -size, size));
  1643. #if LL_BIG_ENDIAN
  1644. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1645. val = valswizzle;
  1646. #else
  1647. val = (U16*)&data[count];
  1648. #endif
  1649. count += sizeof(U16) * 3;
  1650. setAcceleration(U16_to_F32(val[VX], -size, size),
  1651. U16_to_F32(val[VY], -size, size),
  1652. U16_to_F32(val[VZ], -size, size));
  1653. #if LL_BIG_ENDIAN
  1654. htonmemcpy(valswizzle, &data[count], MVT_U16Quat, 8);
  1655. val = valswizzle;
  1656. #else
  1657. val = (U16*)&data[count];
  1658. #endif
  1659. count += sizeof(U16) * 4;
  1660. new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
  1661. new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
  1662. new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
  1663. new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
  1664. #if LL_BIG_ENDIAN
  1665. htonmemcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
  1666. val = valswizzle;
  1667. #else
  1668. val = (U16*)&data[count];
  1669. #endif
  1670. new_angv.set(U16_to_F32(val[VX], -size, size),
  1671. U16_to_F32(val[VY], -size, size),
  1672. U16_to_F32(val[VZ], -size, size));
  1673. setAngularVelocity(new_angv);
  1674. if (mDebugUpdateMsg)
  1675. {
  1676. llinfos << "Angular velocity (5): " << new_angv << llendl;
  1677. }
  1678. break;
  1679. case 16:
  1680. // This is a terse 8 update
  1681. this_update_precision = 8;
  1682. test_pos_parent.quantize8(-0.5f * size, 1.5f * size,
  1683. min_height, MAX_HEIGHT);
  1684. new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f * size,
  1685. 1.5f * size);
  1686. new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f * size,
  1687. 1.5f * size);
  1688. new_pos_parent.mV[VZ] = U8_to_F32(data[2], min_height,
  1689. MAX_HEIGHT);
  1690. setVelocity(U8_to_F32(data[3], -size, size),
  1691. U8_to_F32(data[4], -size, size),
  1692. U8_to_F32(data[5], -size, size));
  1693. setAcceleration(U8_to_F32(data[6], -size, size),
  1694. U8_to_F32(data[7], -size, size),
  1695. U8_to_F32(data[8], -size, size));
  1696. new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
  1697. new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
  1698. new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
  1699. new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
  1700. new_angv.set(U8_to_F32(data[13], -size, size),
  1701. U8_to_F32(data[14], -size, size),
  1702. U8_to_F32(data[15], -size, size));
  1703. setAngularVelocity(new_angv);
  1704. if (mDebugUpdateMsg)
  1705. {
  1706. llinfos << "Angular velocity (6): " << new_angv << llendl;
  1707. }
  1708. break;
  1709. }
  1710. U8 state;
  1711. mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state,
  1712. block_num);
  1713. mAttachmentState = state;
  1714. break;
  1715. }
  1716. default:
  1717. break;
  1718. }
  1719. }
  1720. else
  1721. {
  1722. // Handle the compressed case
  1723. LLUUID sound_uuid, owner_id;
  1724. F32 gain = 0;
  1725. U8 sound_flags = 0;
  1726. F32 cutoff = 0;
  1727. U16 val[4];
  1728. U8 state;
  1729. dp->unpackU8(state, "State");
  1730. mAttachmentState = state;
  1731. switch (update_type)
  1732. {
  1733. case OUT_TERSE_IMPROVED:
  1734. {
  1735. LL_DEBUGS("UpdateType") << "CompTI:" << mID << LL_ENDL;
  1736. U8 value;
  1737. dp->unpackU8(value, "agent");
  1738. if (value)
  1739. {
  1740. LLVector4 collision_plane;
  1741. dp->unpackVector4(collision_plane, "Plane");
  1742. if (isAvatar())
  1743. {
  1744. ((LLVOAvatar*)this)->setFootPlane(collision_plane);
  1745. }
  1746. }
  1747. test_pos_parent = getPosition();
  1748. dp->unpackVector3(new_pos_parent, "Pos");
  1749. dp->unpackU16(val[VX], "VelX");
  1750. dp->unpackU16(val[VY], "VelY");
  1751. dp->unpackU16(val[VZ], "VelZ");
  1752. setVelocity(U16_to_F32(val[VX], -128.f, 128.f),
  1753. U16_to_F32(val[VY], -128.f, 128.f),
  1754. U16_to_F32(val[VZ], -128.f, 128.f));
  1755. dp->unpackU16(val[VX], "AccX");
  1756. dp->unpackU16(val[VY], "AccY");
  1757. dp->unpackU16(val[VZ], "AccZ");
  1758. setAcceleration(U16_to_F32(val[VX], -64.f, 64.f),
  1759. U16_to_F32(val[VY], -64.f, 64.f),
  1760. U16_to_F32(val[VZ], -64.f, 64.f));
  1761. dp->unpackU16(val[VX], "ThetaX");
  1762. dp->unpackU16(val[VY], "ThetaY");
  1763. dp->unpackU16(val[VZ], "ThetaZ");
  1764. dp->unpackU16(val[VS], "ThetaS");
  1765. new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
  1766. new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
  1767. new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
  1768. new_rot.mQ[VS] = U16_to_F32(val[VS], -1.f, 1.f);
  1769. dp->unpackU16(val[VX], "AccX");
  1770. dp->unpackU16(val[VY], "AccY");
  1771. dp->unpackU16(val[VZ], "AccZ");
  1772. new_angv.set(U16_to_F32(val[VX], -64.f, 64.f),
  1773. U16_to_F32(val[VY], -64.f, 64.f),
  1774. U16_to_F32(val[VZ], -64.f, 64.f));
  1775. setAngularVelocity(new_angv);
  1776. if (mDebugUpdateMsg)
  1777. {
  1778. llinfos << "Angular velocity (7): " << new_angv << llendl;
  1779. }
  1780. break;
  1781. }
  1782. case OUT_FULL_COMPRESSED:
  1783. case OUT_FULL_CACHED:
  1784. {
  1785. LL_DEBUGS("UpdateType") << "CompFull:" << mID << LL_ENDL;
  1786. setObjectCostStale();
  1787. if (gFloaterToolsp && mUserSelected)
  1788. {
  1789. gFloaterToolsp->dirty();
  1790. }
  1791. dp->unpackU32(crc, "CRC");
  1792. mTotalCRC = crc;
  1793. dp->unpackU8(material, "Material");
  1794. U8 old_material = getMaterial();
  1795. if (old_material != material)
  1796. {
  1797. setMaterial(material);
  1798. if (mDrawable.notNull())
  1799. {
  1800. gPipeline.markMoved(mDrawable, false); // undamped
  1801. }
  1802. }
  1803. dp->unpackU8(click_action, "ClickAction");
  1804. setClickAction(click_action);
  1805. dp->unpackVector3(new_scale, "Scale");
  1806. dp->unpackVector3(new_pos_parent, "Pos");
  1807. LLVector3 vec;
  1808. dp->unpackVector3(vec, "Rot");
  1809. new_rot.unpackFromVector3(vec);
  1810. setAcceleration(LLVector3::zero);
  1811. U32 value;
  1812. dp->unpackU32(value, "SpecialCode");
  1813. dp->setPassFlags(value);
  1814. dp->unpackUUID(owner_id, "Owner");
  1815. mOwnerID = owner_id;
  1816. if (value & 0x80)
  1817. {
  1818. dp->unpackVector3(new_angv, "Omega");
  1819. setAngularVelocity(new_angv);
  1820. if (mDebugUpdateMsg)
  1821. {
  1822. llinfos << "Angular velocity (8): " << new_angv
  1823. << llendl;
  1824. }
  1825. }
  1826. if (value & 0x20)
  1827. {
  1828. dp->unpackU32(parent_id, "ParentID");
  1829. }
  1830. else
  1831. {
  1832. parent_id = 0;
  1833. }
  1834. S32 sp_size;
  1835. U32 size;
  1836. if (value & 0x2)
  1837. {
  1838. sp_size = 1;
  1839. delete[] mData;
  1840. mData = new U8[1];
  1841. dp->unpackU8(((U8*)mData)[0], "TreeData");
  1842. }
  1843. else if (value & 0x1)
  1844. {
  1845. dp->unpackU32(size, "ScratchPadSize");
  1846. delete[] mData;
  1847. mData = new U8[size];
  1848. dp->unpackBinaryData((U8 *)mData, sp_size, "PartData");
  1849. }
  1850. else
  1851. {
  1852. mData = NULL;
  1853. }
  1854. // Reset the cached values used for debug info display toggle.
  1855. mHudTextString.clear();
  1856. mHudTextColor = LLColor4U::white;
  1857. // Setup object text
  1858. if (!mText && (value & 0x4))
  1859. {
  1860. mText = (LLHUDText*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
  1861. mText->setFont(LLFontGL::getFontSansSerif());
  1862. mText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
  1863. mText->setMaxLines(-1); // Set to match current agni behavior.
  1864. mText->setSourceObject(this);
  1865. mText->setOnHUDAttachment(isHUDAttachment());
  1866. }
  1867. if (value & 0x4)
  1868. {
  1869. dp->unpackString(mHudTextString, "Text");
  1870. LLColor4U coloru;
  1871. dp->unpackBinaryDataFixed(coloru.mV, 4, "Color");
  1872. coloru.mV[3] = 255 - coloru.mV[3];
  1873. mHudTextColor = LLColor4(coloru);
  1874. // Fading is disabled only when the hovetext is being
  1875. // overridden by debug text.
  1876. if (mText->getDoFade())
  1877. {
  1878. mText->setColor(mHudTextColor);
  1879. mText->setStringUTF8(mHudTextString);
  1880. }
  1881. //MK
  1882. mText->mLastMessageText = mHudTextString;
  1883. //mk
  1884. setChanged(TEXTURE);
  1885. }
  1886. else if (mText.notNull())
  1887. {
  1888. mText->markDead();
  1889. mText = NULL;
  1890. }
  1891. std::string media_url;
  1892. if (value & 0x200)
  1893. {
  1894. dp->unpackString(media_url, "MediaURL");
  1895. }
  1896. retval |= checkMediaURL(media_url);
  1897. //
  1898. // Unpack particle system data (legacy)
  1899. //
  1900. if (value & 0x8)
  1901. {
  1902. unpackParticleSource(*dp, owner_id, true);
  1903. }
  1904. else if (!(value & 0x400))
  1905. {
  1906. deleteParticleSource();
  1907. }
  1908. // Mark all extra parameters not used
  1909. for (S32 i = 0; i < LL_EPARAMS_COUNT; ++i)
  1910. {
  1911. mExtraParameterInUse[i] = false;
  1912. }
  1913. // Unpack extra params
  1914. U8 num_parameters;
  1915. dp->unpackU8(num_parameters, "num_params");
  1916. U8 param_block[MAX_OBJECT_PARAMS_SIZE];
  1917. for (U8 param = 0; param < num_parameters; ++param)
  1918. {
  1919. U16 param_type;
  1920. S32 param_size;
  1921. dp->unpackU16(param_type, "param_type");
  1922. dp->unpackBinaryData(param_block, param_size,
  1923. "param_data");
  1924. LLDataPackerBinaryBuffer dp2(param_block, param_size);
  1925. unpackParameterEntry(param_type, &dp2);
  1926. }
  1927. for (S32 i = 0; i < LL_EPARAMS_COUNT; ++i)
  1928. {
  1929. if (!mExtraParameterInUse[i])
  1930. {
  1931. parameterChanged(LL_EPARAM_TYPE(i),
  1932. mExtraParameters[i], false, false);
  1933. }
  1934. }
  1935. if (value & 0x10)
  1936. {
  1937. dp->unpackUUID(sound_uuid, "SoundUUID");
  1938. dp->unpackF32(gain, "SoundGain");
  1939. dp->unpackU8(sound_flags, "SoundFlags");
  1940. dp->unpackF32(cutoff, "SoundRadius");
  1941. }
  1942. if (value & 0x100)
  1943. {
  1944. std::string name_value_list;
  1945. dp->unpackString(name_value_list, "NV");
  1946. setNameValueList(name_value_list);
  1947. }
  1948. mTotalCRC = crc;
  1949. mSoundCutOffRadius = cutoff;
  1950. setAttachedSound(sound_uuid, owner_id, gain, sound_flags);
  1951. // Only get these flags on updates from sim, not cached ones.
  1952. // Preload these five flags for every object. Finer shades
  1953. // require the object to be selected, and the selection manager
  1954. // stores the extended permission info.
  1955. if (mesgsys)
  1956. {
  1957. U32 flags;
  1958. mesgsys->getU32Fast(_PREHASH_ObjectData,
  1959. _PREHASH_UpdateFlags,
  1960. flags, block_num);
  1961. loadFlags(flags);
  1962. }
  1963. break;
  1964. }
  1965. default:
  1966. break;
  1967. }
  1968. }
  1969. if (set_debug_tag)
  1970. {
  1971. HBFloaterDebugTags::setTag("UpdateType", false);
  1972. }
  1973. //
  1974. // Fix object parenting.
  1975. //
  1976. bool b_changed_status = false;
  1977. // We only need to update parenting on full updates, terse updates
  1978. // do not send parenting information.
  1979. if (update_type != OUT_TERSE_IMPROVED)
  1980. {
  1981. U32 ip, port;
  1982. if (mesgsys)
  1983. {
  1984. ip = mesgsys->getSenderIP();
  1985. port = mesgsys->getSenderPort();
  1986. }
  1987. else
  1988. {
  1989. const LLHost& host = mRegionp->getHost();
  1990. ip = host.getAddress();
  1991. port = host.getPort();
  1992. }
  1993. LLViewerObject* sent_parentp = NULL;
  1994. if (parent_id)
  1995. {
  1996. LLUUID parent_uuid;
  1997. gObjectList.getUUIDFromLocal(parent_uuid, parent_id, ip, port);
  1998. sent_parentp = gObjectList.findObject(parent_uuid);
  1999. }
  2000. if (!cur_parentp)
  2001. {
  2002. if (parent_id)
  2003. {
  2004. // No parent now, new parent in message -> attach to that
  2005. // parent if possible
  2006. // Check to see if we have the corresponding viewer object for
  2007. // the parent.
  2008. if (sent_parentp && sent_parentp->getParent() == this)
  2009. {
  2010. // Try to recover if we attempt to attach a parent to its
  2011. // child
  2012. llwarns << "Attempt to attach a parent to its child: "
  2013. << mID << " to " << sent_parentp->mID
  2014. << llendl;
  2015. removeChild(sent_parentp);
  2016. sent_parentp->setDrawableParent(NULL);
  2017. }
  2018. if (sent_parentp && sent_parentp != this &&
  2019. !sent_parentp->isDead())
  2020. {
  2021. // We have a viewer object for the parent, and it is not
  2022. // dead. Do the actual reparenting here.
  2023. b_changed_status = true;
  2024. // ...no current parent, so do not try to remove child
  2025. if (mDrawable.notNull())
  2026. {
  2027. if (mDrawable->isDead() || !mDrawable->getVObj())
  2028. {
  2029. llwarns << "Drawable is dead or no VObj !"
  2030. << llendl;
  2031. sent_parentp->addChild(this);
  2032. }
  2033. else
  2034. {
  2035. // LLViewerObject::processUpdateMessage 1
  2036. if (!setDrawableParent(sent_parentp->mDrawable))
  2037. {
  2038. // Bad, we got a cycle somehow. Kill both the
  2039. // parent and the child, and set cache misses
  2040. // for both of them.
  2041. llwarns << "Attempting to recover from parenting cycle ! Killing "
  2042. << sent_parentp->mID << " and "
  2043. << mID << " and adding them to the cache miss list."
  2044. << llendl;
  2045. setParent(NULL);
  2046. sent_parentp->setParent(NULL);
  2047. getRegion()->addCacheMissFull(getLocalID());
  2048. getRegion()->addCacheMissFull(sent_parentp->getLocalID());
  2049. gObjectList.killObject(sent_parentp);
  2050. gObjectList.killObject(this);
  2051. return retval;
  2052. }
  2053. sent_parentp->addChild(this);
  2054. // Make sure this object gets a non-damped update
  2055. if (sent_parentp->mDrawable.notNull())
  2056. {
  2057. gPipeline.markMoved(sent_parentp->mDrawable,
  2058. // undamped
  2059. false);
  2060. }
  2061. }
  2062. }
  2063. else
  2064. {
  2065. sent_parentp->addChild(this);
  2066. }
  2067. // Show particles, icon and HUD
  2068. hideExtraDisplayItems(false);
  2069. setChanged(MOVED | SILHOUETTE);
  2070. }
  2071. else
  2072. {
  2073. // No corresponding viewer object for the parent: put the
  2074. // various pieces on the orphan list.
  2075. gObjectList.orphanize(this, parent_id, ip, port);
  2076. // Hide particles, icon and HUD
  2077. hideExtraDisplayItems(true);
  2078. }
  2079. }
  2080. }
  2081. else
  2082. {
  2083. if (parent_id && !sent_parentp)
  2084. {
  2085. if (isAvatar())
  2086. {
  2087. // This logic is meant to handle the case where a
  2088. // sitting avatar has reached a new sim ahead of the
  2089. // object it was sitting on (which is common as objects
  2090. // are transfered through a slower route than agents).
  2091. // In this case, the local id for the object will not
  2092. // be valid, since the viewer has not received a full
  2093. // update for the object from that sim yet, so we
  2094. // assume that the agent is still sitting where she was
  2095. // originally. --RN
  2096. sent_parentp = cur_parentp;
  2097. }
  2098. else
  2099. {
  2100. // Switching parents, but we do not know the new
  2101. // parent. We are an orphan, flag things appropriately.
  2102. gObjectList.orphanize(this, parent_id, ip, port);
  2103. }
  2104. }
  2105. // Reparent if possible.
  2106. if (sent_parentp && sent_parentp != cur_parentp &&
  2107. sent_parentp != this)
  2108. {
  2109. // New parent is valid, detach and reattach
  2110. b_changed_status = true;
  2111. if (mDrawable.notNull())
  2112. {
  2113. // LLViewerObject::processUpdateMessage 2
  2114. if (!setDrawableParent(sent_parentp->mDrawable))
  2115. {
  2116. // Bad, we got a cycle somehow. Kill both the parent
  2117. // and the child, and set cache misses for both of them
  2118. llwarns << "Attempting to recover from parenting cycle ! Killing "
  2119. << sent_parentp->mID << " and "
  2120. << mID << " and adding them to cache miss list."
  2121. << llendl;
  2122. setParent(NULL);
  2123. sent_parentp->setParent(NULL);
  2124. getRegion()->addCacheMissFull(getLocalID());
  2125. getRegion()->addCacheMissFull(sent_parentp->getLocalID());
  2126. gObjectList.killObject(sent_parentp);
  2127. gObjectList.killObject(this);
  2128. return retval;
  2129. }
  2130. // Make sure this object gets a non-damped update
  2131. }
  2132. cur_parentp->removeChild(this);
  2133. sent_parentp->addChild(this);
  2134. setChanged(MOVED | SILHOUETTE);
  2135. sent_parentp->setChanged(MOVED | SILHOUETTE);
  2136. if (sent_parentp->mDrawable.notNull())
  2137. {
  2138. // false = undamped
  2139. gPipeline.markMoved(sent_parentp->mDrawable, false);
  2140. }
  2141. }
  2142. else if (!sent_parentp)
  2143. {
  2144. bool remove_parent = true;
  2145. // No new parent, or the parent that we sent does not exist on
  2146. // the viewer.
  2147. LLViewerObject* parentp = (LLViewerObject*)getParent();
  2148. if (parentp && parentp->getRegion() != getRegion())
  2149. {
  2150. // This is probably an object flying across a region
  2151. // boundary, the object probably ISN'T being reparented,
  2152. // but just got an object update out of order (child
  2153. // update before parent).
  2154. remove_parent = false;
  2155. }
  2156. if (remove_parent)
  2157. {
  2158. if (parentp && parentp == gAgentAvatarp)
  2159. {
  2160. LL_DEBUGS("Attachment") << "Detaching object " << mID
  2161. << LL_ENDL;
  2162. }
  2163. b_changed_status = true;
  2164. if (mDrawable.notNull())
  2165. {
  2166. // Clear parent so that removeChild can put the
  2167. // drawable on the damped list
  2168. // LLViewerObject::processUpdateMessage 3
  2169. setDrawableParent(NULL);
  2170. }
  2171. cur_parentp->removeChild(this);
  2172. setChanged(MOVED | SILHOUETTE);
  2173. if (mDrawable.notNull())
  2174. {
  2175. // Make sure this object gets a non-damped update
  2176. gPipeline.markMoved(mDrawable, false); // undamped
  2177. }
  2178. }
  2179. }
  2180. }
  2181. }
  2182. new_rot.normalize();
  2183. if (sPingInterpolate && mesgsys)
  2184. {
  2185. LLCircuitData* cdp =
  2186. mesgsys->mCircuitInfo.findCircuit(mesgsys->getSender());
  2187. if (cdp)
  2188. {
  2189. F32 time_dilation = mRegionp ? mRegionp->getTimeDilation() : 1.f;
  2190. F32 ping_delay = 0.5f * time_dilation *
  2191. ((F32)cdp->getPingDelay() * 0.001f +
  2192. gFrameDT);
  2193. LLVector3 diff = getVelocity() * ping_delay;
  2194. new_pos_parent += diff;
  2195. }
  2196. else
  2197. {
  2198. llwarns << "findCircuit() returned NULL; skipping interpolation"
  2199. << llendl;
  2200. }
  2201. }
  2202. //////////////////////////
  2203. //
  2204. // Set the generic change flags...
  2205. //
  2206. // If we are going to skip this message, why are we doing all the
  2207. // parenting, etc above ?
  2208. if (mesgsys)
  2209. {
  2210. U32 packet_id = mesgsys->getCurrentRecvPacketID();
  2211. if (packet_id < mLatestRecvPacketID &&
  2212. mLatestRecvPacketID - packet_id < 65536)
  2213. {
  2214. // Skip application of this message, it is old
  2215. return retval;
  2216. }
  2217. mLatestRecvPacketID = packet_id;
  2218. }
  2219. // Set the change flags for scale
  2220. if (new_scale != getScale())
  2221. {
  2222. setChanged(SCALED | SILHOUETTE);
  2223. setScale(new_scale); // Must follow setting permYouOwner()
  2224. }
  2225. // Add to mini-map objects if not yet in them and of interest; this is
  2226. // particularly important for scripted objects which may change their
  2227. // path-finding or physical status.
  2228. if (!mOnMap && getPCode() == LL_PCODE_VOLUME && !isDead() &&
  2229. (flagUsePhysics() || flagCharacter()) && !isAttachment() && isRoot())
  2230. {
  2231. gObjectList.addToMap(this);
  2232. mOnMap = true;
  2233. }
  2234. // First, let's see if the new position is actually a change
  2235. F32 vel_mag_sq = getVelocity().lengthSquared();
  2236. F32 accel_mag_sq = getAcceleration().lengthSquared();
  2237. if (b_changed_status || test_pos_parent != new_pos_parent ||
  2238. (!mUserSelected &&
  2239. (vel_mag_sq != 0.f || accel_mag_sq != 0.f ||
  2240. this_update_precision > mBestUpdatePrecision)))
  2241. {
  2242. mBestUpdatePrecision = this_update_precision;
  2243. LLVector3 diff = new_pos_parent - test_pos_parent;
  2244. F32 mag_sqr = diff.lengthSquared();
  2245. if (llfinite(mag_sqr))
  2246. {
  2247. setPositionParent(new_pos_parent);
  2248. }
  2249. else
  2250. {
  2251. llwarns << "Cannot move the object/avatar to an infinite location !"
  2252. << llendl;
  2253. retval |= INVALID_UPDATE;
  2254. }
  2255. if (mParent && mParent->isAvatar())
  2256. {
  2257. // We have changed the position of an attachment, so we need to
  2258. // clamp it
  2259. ((LLVOAvatar*)mParent)->clampAttachmentPositions();
  2260. }
  2261. }
  2262. if (sUseNewTargetOmegaCode)
  2263. {
  2264. // New, experimental code
  2265. bool is_new_rot = new_rot.isNotEqualEps(getRotation(), F_ALMOST_ZERO);
  2266. if (mDebugUpdateMsg)
  2267. {
  2268. llinfos << "Rotation changed: " << (is_new_rot ? "yes" : "no")
  2269. << " - Angular velocity changed: "
  2270. << (new_angv != old_angv ? "yes" : "no") << llendl;
  2271. }
  2272. if (is_new_rot || new_angv != old_angv)
  2273. {
  2274. if (new_angv != old_angv)
  2275. {
  2276. if (new_rot != mPreviousRotation || flagUsePhysics())
  2277. {
  2278. resetRot();
  2279. }
  2280. else
  2281. {
  2282. mRotTime = 0.f;
  2283. }
  2284. }
  2285. // Remember the last rotation value
  2286. mPreviousRotation = new_rot;
  2287. // Set the rotation of the object followed by adjusting for the
  2288. // accumulated angular velocity (llSetTargetOmega)
  2289. setRotation(new_rot * mAngularVelocityRot);
  2290. setChanged(ROTATED | SILHOUETTE);
  2291. }
  2292. }
  2293. else
  2294. {
  2295. // Old code
  2296. bool is_new_rot = new_rot.isNotEqualEps(mPreviousRotation,
  2297. F_ALMOST_ZERO);
  2298. if (mDebugUpdateMsg)
  2299. {
  2300. llinfos << "Rotation changed: " << (is_new_rot ? "yes" : "no")
  2301. << " - Angular velocity changed: "
  2302. << (new_angv != old_angv ? "yes" : "no") << llendl;
  2303. }
  2304. if (is_new_rot || new_angv != old_angv)
  2305. {
  2306. if (is_new_rot)
  2307. {
  2308. mPreviousRotation = new_rot;
  2309. setRotation(new_rot);
  2310. }
  2311. mRotTime = 0.f;
  2312. setChanged(ROTATED | SILHOUETTE);
  2313. }
  2314. }
  2315. if (gShowObjectUpdates)
  2316. {
  2317. LLColor4 color;
  2318. if (update_type == OUT_TERSE_IMPROVED)
  2319. {
  2320. color.set(0.f, 0.f, 1.f, 1.f);
  2321. }
  2322. else
  2323. {
  2324. color.set(1.f, 0.f, 0.f, 1.f);
  2325. }
  2326. gPipeline.addDebugBlip(getPositionAgent(), color);
  2327. }
  2328. constexpr F32 MAG_CUTOFF = F_APPROXIMATELY_ZERO;
  2329. mStatic = vel_mag_sq <= MAG_CUTOFF && accel_mag_sq <= MAG_CUTOFF &&
  2330. getAngularVelocity().lengthSquared() <= MAG_CUTOFF;
  2331. // *BUG: This code leads to problems during group rotate and any scale
  2332. // operation. Small discepencies between the simulator and viewer
  2333. // representations cause the selection center to creep, leading to objects
  2334. // moving around the wrong center.
  2335. //
  2336. // Removing this, however, means that if someone else drags an object you
  2337. // have selected, your selection center and dialog boxes will be wrong. It
  2338. // also means that higher precision information on selected objects will be
  2339. // ignored.
  2340. //
  2341. // I believe the group rotation problem is fixed. JNC 1.21.2002
  2342. // Additionally, if any child is selected, need to update the dialogs and
  2343. // selection center.
  2344. bool needs_refresh = mUserSelected;
  2345. if (!needs_refresh)
  2346. {
  2347. for (child_list_t::iterator iter = mChildList.begin(),
  2348. end = mChildList.end();
  2349. iter != end; ++iter)
  2350. {
  2351. LLViewerObject* child = *iter;
  2352. if (child && child->mUserSelected)
  2353. {
  2354. needs_refresh = true;
  2355. break;
  2356. }
  2357. }
  2358. }
  2359. if (needs_refresh)
  2360. {
  2361. gSelectMgr.updateSelectionCenter();
  2362. dialog_refresh_all();
  2363. }
  2364. // Mark update time as approx. now, with the ping delay. Ping delay is off
  2365. // because it is not set for velocity interpolation, causing much jumping
  2366. // and hopping around...
  2367. #if 0
  2368. U32 ping_delay = mesgsys->mCircuitInfo.getPingDelay();
  2369. #endif
  2370. mLastInterpUpdateSecs = LLFrameTimer::getElapsedSeconds();
  2371. mLastMessageUpdateSecs = mLastInterpUpdateSecs;
  2372. if (mDrawable.notNull())
  2373. {
  2374. // Do not clear invisibility flag on update if still orphaned !
  2375. if (mDrawable->isState(LLDrawable::FORCE_INVISIBLE) && !mOrphaned)
  2376. {
  2377. LL_DEBUGS("ViewerObject") << "Clearing force invisible: " << mID
  2378. << " : " << getPCodeString() << " : "
  2379. << getPositionAgent() << LL_ENDL;
  2380. mDrawable->clearState(LLDrawable::FORCE_INVISIBLE);
  2381. gPipeline.markRebuild(mDrawable);
  2382. }
  2383. }
  2384. return retval;
  2385. }
  2386. // Load flags from cache or from message
  2387. void LLViewerObject::loadFlags(U32 flags)
  2388. {
  2389. if (flags == 0xffffffff)
  2390. {
  2391. LL_DEBUGS("ObjectCache") << "Invalid flags for object "
  2392. << mID << "; ignoring." << LL_ENDL;
  2393. return; // invalid
  2394. }
  2395. LL_DEBUGS("ObjectCacheSpam") << "Flags for object " << mID << " set to: "
  2396. << flags << LL_ENDL;
  2397. // Keep local flags and overwrite remote-controlled flags
  2398. mFlags = (mFlags & FLAGS_LOCAL) | flags;
  2399. mFlagsLoaded = true;
  2400. // ...new objects that should come in selected need to be added to the
  2401. // selected list
  2402. mCreateSelected = (flags & FLAGS_CREATE_SELECTED) != 0;
  2403. }
  2404. void LLViewerObject::idleUpdate(F64 time)
  2405. {
  2406. if (!mDead)
  2407. {
  2408. if (!mStatic && sVelocityInterpolate && !mUserSelected)
  2409. {
  2410. // Calculate dt from last update
  2411. F32 time_dilation = mRegionp ? mRegionp->getTimeDilation() : 1.f;
  2412. F32 dt = time_dilation * (F32)(time - mLastInterpUpdateSecs);
  2413. applyAngularVelocity(dt);
  2414. if (isAttachment())
  2415. {
  2416. mLastInterpUpdateSecs = time;
  2417. return;
  2418. }
  2419. // Move object based on its velocity and rotation
  2420. interpolateLinearMotion(time, dt);
  2421. }
  2422. updateDrawable(false);
  2423. }
  2424. }
  2425. // Moves an object due to idle-time viewer side updates by iterpolating motion
  2426. void LLViewerObject::interpolateLinearMotion(F64 time, F32 dt)
  2427. {
  2428. // Linear motion
  2429. // PHYSICS_TIMESTEP is used below to correct for the fact that the velocity
  2430. // in object updates represents the average velocity of the last timestep,
  2431. // rather than the final velocity. The time dilation above should guarantee
  2432. // that dt is never less than PHYSICS_TIMESTEP, theoretically...
  2433. // *TODO: should also wrap linear accel/velocity in check to see if object
  2434. // is selected, instead of explicitly zeroing it out
  2435. F64 time_since_last_update = time - mLastMessageUpdateSecs;
  2436. if (time_since_last_update <= 0.0 || dt <= 0.f)
  2437. {
  2438. return;
  2439. }
  2440. LLVector3 accel = getAcceleration();
  2441. LLVector3 vel = getVelocity();
  2442. if (sMaxUpdateInterpolationTime <= 0.0)
  2443. {
  2444. // Old code path... unbounded, simple interpolation.
  2445. if (!accel.isExactlyZero() || !vel.isExactlyZero())
  2446. {
  2447. LLVector3 pos = (vel + 0.5f * (dt - PHYSICS_TIMESTEP) * accel) * dt;
  2448. // Region local
  2449. setPositionRegion(pos + getPositionRegion());
  2450. setVelocity(vel + accel * dt);
  2451. // For objects that are spinning but not translating, make sure to
  2452. // flag them as having moved
  2453. setChanged(MOVED | SILHOUETTE);
  2454. }
  2455. }
  2456. else if (!accel.isExactlyZero() || !vel.isExactlyZero())
  2457. {
  2458. // Object is moving, and has not been too long since we got an update
  2459. // from the server.
  2460. // Calculate predicted position and velocity
  2461. LLVector3 new_pos = (vel + 0.5f * (dt - PHYSICS_TIMESTEP) * accel) * dt;
  2462. LLVector3 new_v = accel * dt;
  2463. if (time_since_last_update > sPhaseOutUpdateInterpolationTime &&
  2464. sPhaseOutUpdateInterpolationTime > 0.0)
  2465. {
  2466. // Have not seen a viewer update in a while, check to see if the
  2467. // ciruit is still active
  2468. if (mRegionp)
  2469. {
  2470. // The simulator will NOT send updates if the object continues
  2471. // normally on the path predicted by the velocity and the
  2472. // acceleration (often gravity) sent to the viewer. So check to
  2473. // see if the circuit is blocked, which means the sim is likely
  2474. // in a long lag.
  2475. LLCircuitData* cdp =
  2476. gMessageSystemp->mCircuitInfo.findCircuit(mRegionp->getHost());
  2477. if (cdp)
  2478. {
  2479. // Find out how many seconds since last packet arrived on
  2480. // the circuit
  2481. F64 time_since_last_packet =
  2482. LLMessageSystem::getMessageTimeSeconds() -
  2483. cdp->getLastPacketInTime();
  2484. if (!cdp->isAlive() || // Circuit is dead or blocked
  2485. cdp->isBlocked() || // or doesn't seem to be getting any packets
  2486. time_since_last_packet > sPhaseOutUpdateInterpolationTime)
  2487. {
  2488. // Start to reduce motion interpolation since we
  2489. // haven't seen a server update in a while
  2490. F64 time_since_last_interpolation = time - mLastInterpUpdateSecs;
  2491. F64 phase_out = 1.0;
  2492. if (time_since_last_update > sMaxUpdateInterpolationTime)
  2493. {
  2494. // Past the time limit, so stop the object
  2495. phase_out = 0.0;
  2496. LL_DEBUGS("MotionInterpolate") << "Motion phase out to zero"
  2497. << LL_ENDL;
  2498. #if 0 // Not adding this due to paranoia about stopping
  2499. // rotation for/ TargetOmega objects and not having
  2500. // it restart
  2501. setAngularVelocity(LLVector3::zero);
  2502. #endif
  2503. }
  2504. else if (mLastInterpUpdateSecs - mLastMessageUpdateSecs >
  2505. sPhaseOutUpdateInterpolationTime)
  2506. {
  2507. // Last update was already phased out a bit
  2508. phase_out = (sMaxUpdateInterpolationTime -
  2509. time_since_last_update) /
  2510. (sMaxUpdateInterpolationTime -
  2511. time_since_last_interpolation);
  2512. LL_DEBUGS("MotionInterpolate") << "Continuing motion phase out of "
  2513. << (F32)phase_out
  2514. << LL_ENDL;
  2515. }
  2516. else
  2517. {
  2518. // Phase out from full value
  2519. phase_out = (sMaxUpdateInterpolationTime -
  2520. time_since_last_update) /
  2521. (sMaxUpdateInterpolationTime -
  2522. sPhaseOutUpdateInterpolationTime);
  2523. LL_DEBUGS("MotionInterpolate") << "Starting motion phase out of "
  2524. << (F32)phase_out
  2525. << LL_ENDL;
  2526. }
  2527. phase_out = llclamp(phase_out, 0.0, 1.0);
  2528. new_pos = new_pos * (F32)phase_out;
  2529. new_v = new_v * (F32)phase_out;
  2530. }
  2531. }
  2532. }
  2533. }
  2534. new_pos = new_pos + getPositionRegion();
  2535. new_v = new_v + vel;
  2536. // Clamp interpolated position to minimum underground and maximum
  2537. // region height
  2538. LLVector3d new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);
  2539. F32 min_height;
  2540. if (isAvatar())
  2541. {
  2542. // Make a better guess about AVs not going underground
  2543. min_height = gWorld.resolveLandHeightGlobal(new_pos_global);
  2544. min_height += 0.5f * getScale().mV[VZ];
  2545. }
  2546. else
  2547. {
  2548. // This will put the object underground, but we cannot tell if it
  2549. // will stop at ground level or not
  2550. min_height = gWorld.getMinAllowedZ(this, new_pos_global);
  2551. // Cap maximum height
  2552. new_pos.mV[VZ] = llmin(MAX_OBJECT_Z, new_pos.mV[VZ]);
  2553. }
  2554. new_pos.mV[VZ] = llmax(min_height, new_pos.mV[VZ]);
  2555. // Check to see if it is going off the region
  2556. LLVector3 temp(new_pos.mV[VX], new_pos.mV[VY], 0.f);
  2557. // Frame time we detected region crossing in + wait time
  2558. if (temp.clamp(0.f, mRegionp->getWidth()))
  2559. {
  2560. // Going off this region, so see if we might end up on another
  2561. // region
  2562. LLVector3d old_pos_global =
  2563. mRegionp->getPosGlobalFromRegion(getPositionRegion());
  2564. // Re-fetch in case it got clipped above
  2565. new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);
  2566. // Clip the positions to known regions
  2567. LLVector3d clip_pos_global =
  2568. gWorld.clipToVisibleRegions(old_pos_global, new_pos_global);
  2569. if (clip_pos_global != new_pos_global)
  2570. {
  2571. // Was clipped, so this means we hit a edge where there is no
  2572. // region to enter
  2573. LL_DEBUGS("MotionInterpolate") << "Hit empty region edge, clipped predicted position to "
  2574. << mRegionp->getPosRegionFromGlobal(clip_pos_global)
  2575. << " from " << new_pos
  2576. << LL_ENDL;
  2577. new_pos = mRegionp->getPosRegionFromGlobal(clip_pos_global);
  2578. // Stop motion and get server update for bouncing on the edge
  2579. new_v.clear();
  2580. setAcceleration(LLVector3::zero);
  2581. }
  2582. else if (mRegionCrossExpire == 0.0)
  2583. {
  2584. // Workaround: we cannot accurately figure out time when we
  2585. // cross border so just write down time "after the fact".
  2586. // It is far from optimal in case of lag, but then
  2587. // sMaxUpdateInterpolationTime will kick in first.
  2588. LL_DEBUGS("MotionInterpolate") << "Predicted region crossing, new position"
  2589. << new_pos << LL_ENDL;
  2590. mRegionCrossExpire = time + sMaxRegionCrossingInterpolationTime;
  2591. }
  2592. else if (time > mRegionCrossExpire)
  2593. {
  2594. // Predicting crossing over 1s, stop motion
  2595. LL_DEBUGS("MotionInterpolate") << "Predicting region crossing for too long, stopping at "
  2596. << new_pos << LL_ENDL;
  2597. new_v.clear();
  2598. setAcceleration(LLVector3::zero);
  2599. mRegionCrossExpire = 0.0;
  2600. }
  2601. }
  2602. else
  2603. {
  2604. mRegionCrossExpire = 0.0;
  2605. }
  2606. // Set new position and velocity
  2607. setPositionRegion(new_pos);
  2608. setVelocity(new_v);
  2609. // For objects that are spinning but not translating, make sure to flag
  2610. // them as having moved
  2611. setChanged(MOVED | SILHOUETTE);
  2612. }
  2613. // Update the last time we did anything
  2614. mLastInterpUpdateSecs = time;
  2615. }
  2616. bool LLViewerObject::setData(const U8* datap, U32 data_size)
  2617. {
  2618. delete[] mData;
  2619. if (datap)
  2620. {
  2621. mData = new U8[data_size];
  2622. if (!mData)
  2623. {
  2624. return false;
  2625. }
  2626. memcpy(mData, datap, data_size);
  2627. }
  2628. return true;
  2629. }
  2630. // Delete an item in the inventory, but do not tell the server. This is used
  2631. // internally by remove, update, and savescript. This will only delete the
  2632. // first item with an item_id in the list.
  2633. void LLViewerObject::deleteInventoryItem(const LLUUID& item_id)
  2634. {
  2635. if (mInventory)
  2636. {
  2637. for (LLInventoryObject::object_list_t::iterator
  2638. it = mInventory->begin(), end = mInventory->end();
  2639. it != end; ++it)
  2640. {
  2641. LLInventoryObject* obj = *it;
  2642. if (obj && obj->getUUID() == item_id)
  2643. {
  2644. // This is safe only because we return immediatly.
  2645. mInventory->erase(it); // will deref and delete it
  2646. return;
  2647. }
  2648. }
  2649. doInventoryCallback();
  2650. }
  2651. }
  2652. void LLViewerObject::doUpdateInventory(LLPointer<LLViewerInventoryItem>& itemp,
  2653. bool is_new)
  2654. {
  2655. if (is_new)
  2656. {
  2657. ++mExpectedInventorySerialNum;
  2658. return;
  2659. }
  2660. if (!mInventory)
  2661. {
  2662. return;
  2663. }
  2664. LLUUID item_id;
  2665. LLUUID new_owner;
  2666. LLUUID new_group;
  2667. bool group_owned = false;
  2668. LLViewerInventoryItem* old_itemp =
  2669. (LLViewerInventoryItem*)getInventoryObject(itemp->getUUID());
  2670. if (old_itemp)
  2671. {
  2672. item_id = old_itemp->getUUID();
  2673. new_owner = old_itemp->getPermissions().getOwner();
  2674. new_group = old_itemp->getPermissions().getGroup();
  2675. group_owned = old_itemp->getPermissions().isGroupOwned();
  2676. }
  2677. else
  2678. {
  2679. item_id = itemp->getUUID();
  2680. }
  2681. // Attempt to update the local inventory. If we can get the object
  2682. // permissions, we have perfect visibility, so we want the serial number to
  2683. // match. Otherwise, take our best guess and make sure that the serial
  2684. // number does not match.
  2685. deleteInventoryItem(item_id);
  2686. LLPermissions perm(itemp->getPermissions());
  2687. LLPermissions* obj_permp = gSelectMgr.findObjectPermissions(this);
  2688. bool is_atomic = itemp->getType() != (S32)LLAssetType::AT_OBJECT;
  2689. if (obj_permp)
  2690. {
  2691. perm.setOwnerAndGroup(LLUUID::null, obj_permp->getOwner(),
  2692. obj_permp->getGroup(), is_atomic);
  2693. }
  2694. else if (group_owned)
  2695. {
  2696. perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
  2697. }
  2698. else if (new_owner.notNull())
  2699. {
  2700. // The object used to be in inventory, so we can assume the owner and
  2701. // group will match what they are there.
  2702. perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
  2703. }
  2704. // *FIXME: could make an even better guess by using the mPermGroup flags
  2705. else if (permYouOwner())
  2706. {
  2707. // Best guess.
  2708. perm.setOwnerAndGroup(LLUUID::null, gAgentID,
  2709. itemp->getPermissions().getGroup(), is_atomic);
  2710. --mExpectedInventorySerialNum;
  2711. }
  2712. else
  2713. {
  2714. // Dummy it up.
  2715. perm.setOwnerAndGroup(LLUUID::null, LLUUID::null, LLUUID::null,
  2716. is_atomic);
  2717. --mExpectedInventorySerialNum;
  2718. }
  2719. LLViewerInventoryItem* new_itemp = new LLViewerInventoryItem(itemp.get());
  2720. new_itemp->setPermissions(perm);
  2721. mInventory->emplace_front(new_itemp);
  2722. doInventoryCallback();
  2723. ++mExpectedInventorySerialNum;
  2724. }
  2725. // Saves a script, which involves removing the old one, and rezzing in the new
  2726. // one. This method should be called with the asset id of the new and old
  2727. // script AFTER the bytecode has been saved.
  2728. void LLViewerObject::saveScript(const LLViewerInventoryItem* item, bool active,
  2729. bool is_new)
  2730. {
  2731. /*
  2732. * XXXPAM Investigate not making this copy. Seems unecessary, but I am
  2733. * unsure about the interaction with doUpdateInventory() called below.
  2734. */
  2735. LL_DEBUGS("ViewerObject") << "Saving script for object: " << mID
  2736. << ". Inventory item Id: " << item->getUUID()
  2737. << ". Asset Id: " << item->getAssetUUID()
  2738. << LL_ENDL;
  2739. LLPointer<LLViewerInventoryItem> task_item =
  2740. new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
  2741. item->getAssetUUID(), item->getType(),
  2742. item->getInventoryType(),
  2743. item->getName(), item->getDescription(),
  2744. item->getSaleInfo(), item->getFlags(),
  2745. item->getCreationDate());
  2746. task_item->setTransactionID(item->getTransactionID());
  2747. LLMessageSystem* msg = gMessageSystemp;
  2748. msg->newMessageFast(_PREHASH_RezScript);
  2749. msg->nextBlockFast(_PREHASH_AgentData);
  2750. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2751. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2752. msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
  2753. msg->nextBlockFast(_PREHASH_UpdateBlock);
  2754. msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
  2755. msg->addBoolFast(_PREHASH_Enabled, active);
  2756. msg->nextBlockFast(_PREHASH_InventoryBlock);
  2757. task_item->packMessage(msg);
  2758. msg->sendReliable(mRegionp->getHost());
  2759. // Do the internal logic
  2760. doUpdateInventory(task_item, is_new);
  2761. }
  2762. void LLViewerObject::moveInventory(const LLUUID& folder_id,
  2763. const LLUUID& item_id)
  2764. {
  2765. LL_DEBUGS("ViewerObject") << "Moving inventory item " << item_id
  2766. << LL_ENDL;
  2767. LLMessageSystem* msg = gMessageSystemp;
  2768. msg->newMessageFast(_PREHASH_MoveTaskInventory);
  2769. msg->nextBlockFast(_PREHASH_AgentData);
  2770. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2771. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2772. msg->addUUIDFast(_PREHASH_FolderID, folder_id);
  2773. msg->nextBlockFast(_PREHASH_InventoryData);
  2774. msg->addU32Fast(_PREHASH_LocalID, mLocalID);
  2775. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  2776. msg->sendReliable(mRegionp->getHost());
  2777. LLInventoryObject* inv_obj = getInventoryObject(item_id);
  2778. if (inv_obj)
  2779. {
  2780. LLViewerInventoryItem* item = (LLViewerInventoryItem*)inv_obj;
  2781. if (!item->getPermissions().allowCopyBy(gAgentID))
  2782. {
  2783. deleteInventoryItem(item_id);
  2784. ++mExpectedInventorySerialNum;
  2785. }
  2786. }
  2787. }
  2788. void LLViewerObject::dirtyInventory()
  2789. {
  2790. // If there is no LLVOInventoryListener, we will not be able to update our
  2791. // mInventory when it comes back from the simulator, so we should not clear
  2792. // the inventory either.
  2793. if (mInventory && !mInventoryCallbacks.empty())
  2794. {
  2795. mInventory->clear(); // will deref and delete entries
  2796. delete mInventory;
  2797. mInventory = NULL;
  2798. }
  2799. mInventoryDirty = true;
  2800. }
  2801. void LLViewerObject::registerInventoryListener(LLVOInventoryListener* listener,
  2802. void* user_data)
  2803. {
  2804. LLInventoryCallbackInfo* info = new LLInventoryCallbackInfo;
  2805. info->mObject = this;
  2806. info->mListener = listener;
  2807. info->mInventoryData = user_data;
  2808. mInventoryCallbacks.push_front(info);
  2809. }
  2810. void LLViewerObject::removeInventoryListener(LLVOInventoryListener* listener)
  2811. {
  2812. if (!listener) return;
  2813. for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
  2814. iter != mInventoryCallbacks.end(); )
  2815. {
  2816. callback_list_t::iterator curiter = iter++;
  2817. LLInventoryCallbackInfo* info = *curiter;
  2818. if (info && info->mListener == listener)
  2819. {
  2820. delete info;
  2821. mInventoryCallbacks.erase(curiter);
  2822. break;
  2823. }
  2824. }
  2825. }
  2826. void LLViewerObject::clearInventoryListeners()
  2827. {
  2828. for_each(mInventoryCallbacks.begin(), mInventoryCallbacks.end(),
  2829. DeletePointer());
  2830. mInventoryCallbacks.clear();
  2831. }
  2832. void LLViewerObject::requestInventory()
  2833. {
  2834. if (mInventoryDirty && mInventory && !mInventoryCallbacks.empty())
  2835. {
  2836. mInventory->clear(); // Will deref and delete it
  2837. delete mInventory;
  2838. mInventory = NULL;
  2839. }
  2840. if (mInventory)
  2841. {
  2842. // Inventory is either up to date or does not have a listener if it is
  2843. // dirty, leave it this way in case we gain a listener.
  2844. doInventoryCallback();
  2845. }
  2846. else
  2847. {
  2848. // Since we are going to request it now.
  2849. mInventoryDirty = false;
  2850. // Throw away duplicate requests.
  2851. fetchInventoryFromServer();
  2852. }
  2853. }
  2854. void LLViewerObject::fetchInventoryFromServer()
  2855. {
  2856. if (!isInventoryPending())
  2857. {
  2858. delete mInventory;
  2859. mInventory = NULL;
  2860. LLMessageSystem* msg = gMessageSystemp;
  2861. msg->newMessageFast(_PREHASH_RequestTaskInventory);
  2862. msg->nextBlockFast(_PREHASH_AgentData);
  2863. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2864. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2865. msg->nextBlockFast(_PREHASH_InventoryData);
  2866. msg->addU32Fast(_PREHASH_LocalID, mLocalID);
  2867. msg->sendReliable(mRegionp->getHost());
  2868. // this will get reset by dirtyInventory or doInventoryCallback
  2869. mInvRequestState = INVENTORY_REQUEST_PENDING;
  2870. }
  2871. }
  2872. LLVOAvatarPuppet* LLViewerObject::getPuppetAvatar()
  2873. {
  2874. return getRootEdit()->mPuppetAvatar.get();
  2875. }
  2876. LLVOAvatarPuppet* LLViewerObject::getPuppetAvatar() const
  2877. {
  2878. return getRootEdit()->mPuppetAvatar.get();
  2879. }
  2880. void LLViewerObject::linkPuppetAvatar()
  2881. {
  2882. LLVOAvatarPuppet* puppet = getPuppetAvatar();
  2883. if (!puppet && isRootEdit())
  2884. {
  2885. LLVOVolume* volp = asVolume();
  2886. if (!volp)
  2887. {
  2888. llwarns << "Called with null or non-volume object" << llendl;
  2889. return;
  2890. }
  2891. puppet = mPuppetAvatar = LLVOAvatarPuppet::createAvatarPuppet(volp);
  2892. }
  2893. if (puppet)
  2894. {
  2895. puppet->updateAttachmentOverrides();
  2896. if (!puppet->mPlaying)
  2897. {
  2898. puppet->mPlaying = true;
  2899. #if 0
  2900. if (!puppet->mRootVolp->isAnySelected())
  2901. #endif
  2902. {
  2903. puppet->updateVolumeGeom();
  2904. puppet->mRootVolp->recursiveMarkForUpdate();
  2905. }
  2906. }
  2907. }
  2908. else
  2909. {
  2910. llwarns << "No puppet avatar found !" << llendl;
  2911. }
  2912. }
  2913. void LLViewerObject::unlinkPuppetAvatar()
  2914. {
  2915. LLVOAvatarPuppet* puppet = getPuppetAvatar();
  2916. if (puppet)
  2917. {
  2918. puppet->updateAttachmentOverrides();
  2919. if (isRootEdit())
  2920. {
  2921. // This will remove the entire linkset from the puppet avatar.
  2922. // Note: mPuppetAvatar == puppet for root edit, so it is not NULL
  2923. // here.
  2924. mPuppetAvatar->markForDeath();
  2925. mPuppetAvatar = NULL;
  2926. }
  2927. // For non-root prims, removing from the linkset will automatically
  2928. // remove the puppet avatar connection.
  2929. }
  2930. }
  2931. void LLViewerObject::updatePuppetAvatar()
  2932. {
  2933. LLViewerObject* root = getRootEdit();
  2934. bool animated = root->isAnimatedObject();
  2935. LLVOAvatarPuppet* puppet = root->mPuppetAvatar.get();
  2936. bool no_puppet = puppet == NULL;
  2937. if (no_puppet && !animated)
  2938. {
  2939. return;
  2940. }
  2941. bool is_rigged_mesh = false;
  2942. if (animated)
  2943. {
  2944. is_rigged_mesh = root->isRiggedMesh();
  2945. if (!is_rigged_mesh)
  2946. {
  2947. const_child_list_t& child_list = root->getChildren();
  2948. for (const_child_list_t::const_iterator iter = child_list.begin(),
  2949. end = child_list.end();
  2950. iter != end; ++iter)
  2951. {
  2952. const LLViewerObject* child = *iter;
  2953. if (child && child->isRiggedMesh())
  2954. {
  2955. is_rigged_mesh = true;
  2956. break;
  2957. }
  2958. }
  2959. }
  2960. }
  2961. if (animated && is_rigged_mesh)
  2962. {
  2963. if (no_puppet)
  2964. {
  2965. root->linkPuppetAvatar();
  2966. }
  2967. }
  2968. else if (!no_puppet)
  2969. {
  2970. root->unlinkPuppetAvatar();
  2971. }
  2972. if (puppet)
  2973. {
  2974. puppet->updateAnimations();
  2975. if (mUserSelected)
  2976. {
  2977. gSelectMgr.pauseAssociatedAvatars();
  2978. }
  2979. }
  2980. }
  2981. struct LLFilenameAndTask
  2982. {
  2983. LL_INLINE LLFilenameAndTask(const LLUUID& id, const std::string& fname,
  2984. S16 serial)
  2985. : mTaskID(id),
  2986. mFilename(fname),
  2987. mSerial(serial)
  2988. {
  2989. }
  2990. LLUUID mTaskID;
  2991. std::string mFilename;
  2992. S16 mSerial; // For sequencing in case of multiple updates
  2993. };
  2994. //static
  2995. void LLViewerObject::processTaskInv(LLMessageSystem* msg, void**)
  2996. {
  2997. LLUUID task_id;
  2998. msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_TaskID, task_id);
  2999. LLViewerObject* object = gObjectList.findObject(task_id);
  3000. if (!object)
  3001. {
  3002. llwarns << "Object " << task_id << " does not exist." << llendl;
  3003. return;
  3004. }
  3005. // Note: we can receive multiple task updates simultaneously, make sure we
  3006. // will not rewrite newer with older update
  3007. S16 serial;
  3008. msg->getS16Fast(_PREHASH_InventoryData, _PREHASH_Serial, serial);
  3009. if (serial == object->mInventorySerialNum &&
  3010. serial < object->mExpectedInventorySerialNum)
  3011. {
  3012. // Loop protection. We received same serial twice. Viewer did some
  3013. // changes to inventory that could not be saved yet or something went
  3014. // wrong to cause serial to be out of sync...
  3015. // ... but only warn if inventory has already been received once (else
  3016. // it simply means we are still waiting for initial data: seen while
  3017. // inspecting avatars attachments).
  3018. if (serial)
  3019. {
  3020. llwarns << "Task inventory serial might be out of sync, server serial: "
  3021. << serial << " - Client expected serial: "
  3022. << object->mExpectedInventorySerialNum << llendl;
  3023. }
  3024. object->mExpectedInventorySerialNum = serial;
  3025. }
  3026. if (serial < object->mExpectedInventorySerialNum)
  3027. {
  3028. // Out of date message; record to current serial for loop protection,
  3029. // but do not load it: just drop xfer to restart on idle.
  3030. if (serial < object->mInventorySerialNum)
  3031. {
  3032. llwarns << "Task inventory serial has decreased: out of order packet ? Server serial: "
  3033. << serial << " - Client expected serial: "
  3034. << object->mExpectedInventorySerialNum << llendl;
  3035. }
  3036. object->mInventorySerialNum = serial;
  3037. object->mInvRequestXFerId = 0;
  3038. object->mInvRequestState = INVENTORY_REQUEST_STOPPED;
  3039. return;
  3040. }
  3041. object->mInventorySerialNum = object->mExpectedInventorySerialNum = serial;
  3042. std::string filename;
  3043. msg->getStringFast(_PREHASH_InventoryData, _PREHASH_Filename, filename);
  3044. filename = LLDir::getScrubbedFileName(filename);
  3045. if (filename.empty())
  3046. {
  3047. LL_DEBUGS("ViewerObject") << "Task has no inventory" << LL_ENDL;
  3048. // Mock up some inventory to make a drop target.
  3049. if (object->mInventory)
  3050. {
  3051. object->mInventory->clear(); // Will deref and delete it
  3052. }
  3053. else
  3054. {
  3055. object->mInventory = new LLInventoryObject::object_list_t();
  3056. }
  3057. object->mInventory->emplace_front(new LLInventoryObject(object->mID,
  3058. LLUUID::null,
  3059. LLAssetType::AT_CATEGORY,
  3060. "Contents"));
  3061. object->doInventoryCallback();
  3062. return;
  3063. }
  3064. if (!gXferManagerp)
  3065. {
  3066. llwarns << "Transfer manager gone. Aborted." << llendl;
  3067. return;
  3068. }
  3069. LLFilenameAndTask* ft = new LLFilenameAndTask(task_id, filename, serial);
  3070. U64 new_id =
  3071. gXferManagerp->requestFile(gDirUtil.getFullPath(LL_PATH_CACHE,
  3072. filename),
  3073. filename, LL_PATH_CACHE,
  3074. object->mRegionp->getHost(), true,
  3075. processTaskInvFile, (void**)ft,
  3076. LLXferManager::HIGH_PRIORITY);
  3077. if (object->mInvRequestState == INVENTORY_XFER)
  3078. {
  3079. if (new_id && new_id != object->mInvRequestXFerId)
  3080. {
  3081. // We started a new download. Abort the old one.
  3082. gXferManagerp->abortRequestById(object->mInvRequestXFerId, -1);
  3083. object->mInvRequestXFerId = new_id;
  3084. }
  3085. }
  3086. else
  3087. {
  3088. object->mInvRequestState = INVENTORY_XFER;
  3089. object->mInvRequestXFerId = new_id;
  3090. }
  3091. }
  3092. void LLViewerObject::processTaskInvFile(void** user_data, S32 error_code,
  3093. LLExtStat ext_status)
  3094. {
  3095. LLFilenameAndTask* ft = (LLFilenameAndTask*)user_data;
  3096. LLViewerObject* objectp;
  3097. if (ft && error_code == 0 &&
  3098. (objectp = gObjectList.findObject(ft->mTaskID)) &&
  3099. ft->mSerial >= objectp->mInventorySerialNum)
  3100. {
  3101. objectp->mInventorySerialNum = ft->mSerial;
  3102. LL_DEBUGS("ViewerObject") << "Receiving inventory task file for serial: "
  3103. << objectp->mInventorySerialNum
  3104. << " - Expected serial: "
  3105. << objectp->mExpectedInventorySerialNum
  3106. << " - Task Id: " << ft->mTaskID << LL_ENDL;
  3107. if (objectp->loadTaskInvFile(ft->mFilename))
  3108. {
  3109. uuid_list_t& pending = objectp->mPendingInventoryItemsIDs;
  3110. for (LLInventoryObject::object_list_t::iterator
  3111. it = objectp->mInventory->begin(),
  3112. end = objectp->mInventory->end();
  3113. it != end && !pending.empty(); ++it)
  3114. {
  3115. LLViewerInventoryItem* itemp =
  3116. it->get()->asViewerInventoryItem();
  3117. if (itemp && itemp->getType() != LLAssetType::AT_CATEGORY)
  3118. {
  3119. // Erase if present. No-op when absent.
  3120. pending.erase(itemp->getAssetUUID());
  3121. }
  3122. }
  3123. }
  3124. }
  3125. else
  3126. {
  3127. // This occurs when two requests were made, and the first one has
  3128. // already handled it.
  3129. LL_DEBUGS("ViewerObject") << "Problem loading task inventory. Return code: "
  3130. << error_code << LL_ENDL;
  3131. }
  3132. if (ft)
  3133. {
  3134. delete ft;
  3135. }
  3136. }
  3137. bool LLViewerObject::loadTaskInvFile(const std::string& filename)
  3138. {
  3139. std::string full_path = gDirUtil.getFullPath(LL_PATH_CACHE, filename);
  3140. llifstream ifs(full_path.c_str());
  3141. if (!ifs.good())
  3142. {
  3143. llwarns << "Unable to load task inventory: " << full_path << llendl;
  3144. return false;
  3145. }
  3146. if (mInventory)
  3147. {
  3148. mInventory->clear(); // Will deref and delete it
  3149. }
  3150. else
  3151. {
  3152. mInventory = new LLInventoryObject::object_list_t;
  3153. }
  3154. char buffer[MAX_STRING];
  3155. // *NOTE: This buffer size is hard coded into scanf() below.
  3156. char keyword[MAX_STRING];
  3157. U32 failed = 0;
  3158. while (ifs.good())
  3159. {
  3160. ifs.getline(buffer, MAX_STRING);
  3161. if (sscanf(buffer, " %254s", keyword) < 1)
  3162. {
  3163. continue; // Ignore empty lines. HB
  3164. }
  3165. if (strcmp("inv_item", keyword) == 0)
  3166. {
  3167. LLPointer<LLInventoryObject> inv_objp = new LLViewerInventoryItem;
  3168. inv_objp->importLegacyStream(ifs);
  3169. mInventory->emplace_front(std::move(inv_objp));
  3170. }
  3171. else if (strcmp("inv_object", keyword) == 0)
  3172. {
  3173. LLPointer<LLInventoryObject> inv_objp = new LLInventoryObject;
  3174. inv_objp->importLegacyStream(ifs);
  3175. mInventory->emplace_front(std::move(inv_objp));
  3176. }
  3177. else if (++failed > MAX_INV_FILE_READ_FAILS)
  3178. {
  3179. llwarns << "Too many unknown token in inventory file: " << filename
  3180. << ". Aborting." << llendl;
  3181. break;
  3182. }
  3183. else
  3184. {
  3185. llwarns << "Unknown token '" << keyword << "' in inventory file: "
  3186. << filename << llendl;
  3187. }
  3188. }
  3189. ifs.close();
  3190. LLFile::remove(full_path);
  3191. doInventoryCallback();
  3192. return true;
  3193. }
  3194. void LLViewerObject::doInventoryCallback()
  3195. {
  3196. for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
  3197. iter != mInventoryCallbacks.end(); )
  3198. {
  3199. callback_list_t::iterator curiter = iter++;
  3200. LLInventoryCallbackInfo* info = *curiter;
  3201. if (info && info->mListener)
  3202. {
  3203. info->mListener->inventoryChanged(this, mInventory,
  3204. mInventorySerialNum,
  3205. info->mInventoryData);
  3206. }
  3207. else
  3208. {
  3209. llinfos << "Deleting bad listener entry." << llendl;
  3210. delete info;
  3211. mInventoryCallbacks.erase(curiter);
  3212. }
  3213. }
  3214. // Release inventory loading state
  3215. mInvRequestXFerId = 0;
  3216. mInvRequestState = INVENTORY_REQUEST_STOPPED;
  3217. }
  3218. void LLViewerObject::removeInventory(const LLUUID& item_id)
  3219. {
  3220. // close any associated floater properties
  3221. LLFloaterProperties::closeByID(item_id, mID);
  3222. LLMessageSystem* msg = gMessageSystemp;
  3223. msg->newMessageFast(_PREHASH_RemoveTaskInventory);
  3224. msg->nextBlockFast(_PREHASH_AgentData);
  3225. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  3226. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  3227. msg->nextBlockFast(_PREHASH_InventoryData);
  3228. msg->addU32Fast(_PREHASH_LocalID, mLocalID);
  3229. msg->addUUIDFast(_PREHASH_ItemID, item_id);
  3230. msg->sendReliable(mRegionp->getHost());
  3231. deleteInventoryItem(item_id);
  3232. ++mExpectedInventorySerialNum;
  3233. }
  3234. bool LLViewerObject::isAssetInInventory(LLViewerInventoryItem* itemp,
  3235. LLAssetType::EType type)
  3236. {
  3237. if (!itemp)
  3238. {
  3239. return false;
  3240. }
  3241. // Note: for now mPendingInventoryItemsIDs only stores textures and
  3242. // GLTF materials, but if it gets to store more types, it will need to
  3243. // verify type as well since null can be a shared default UUID and it is
  3244. // fine to need a null script and a null material simultaneously.
  3245. const LLUUID& asset_id = itemp->getAssetUUID();
  3246. return mPendingInventoryItemsIDs.count(asset_id) > 0 ||
  3247. getInventoryItemByAsset(asset_id, type) != NULL;
  3248. }
  3249. void LLViewerObject::updateInventory(LLViewerInventoryItem* itemp, bool is_new)
  3250. {
  3251. if (!itemp) // Paranoia
  3252. {
  3253. return;
  3254. }
  3255. if (is_new)
  3256. {
  3257. LLAssetType::EType type = itemp->getType();
  3258. if (type == LLAssetType::AT_TEXTURE ||
  3259. type == LLAssetType::AT_MATERIAL)
  3260. {
  3261. if (isAssetInInventory(itemp, type))
  3262. {
  3263. return; // Already here
  3264. }
  3265. mPendingInventoryItemsIDs.emplace(itemp->getAssetUUID());
  3266. }
  3267. }
  3268. // This slices the object into what we are concerned about on the viewer.
  3269. // The simulator will take the permissions and transfer ownership.
  3270. LLPointer<LLViewerInventoryItem> task_itemp =
  3271. new LLViewerInventoryItem(itemp->getUUID(), mID,
  3272. itemp->getPermissions(),
  3273. itemp->getAssetUUID(), itemp->getType(),
  3274. itemp->getInventoryType(), itemp->getName(),
  3275. itemp->getDescription(),
  3276. itemp->getSaleInfo(), itemp->getFlags(),
  3277. itemp->getCreationDate());
  3278. task_itemp->setTransactionID(itemp->getTransactionID());
  3279. LLMessageSystem* msg = gMessageSystemp;
  3280. msg->newMessageFast(_PREHASH_UpdateTaskInventory);
  3281. msg->nextBlockFast(_PREHASH_AgentData);
  3282. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  3283. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  3284. msg->nextBlockFast(_PREHASH_UpdateData);
  3285. msg->addU32Fast(_PREHASH_LocalID, mLocalID);
  3286. msg->addU8Fast(_PREHASH_Key, TASK_INVENTORY_ITEM_KEY);
  3287. msg->nextBlockFast(_PREHASH_InventoryData);
  3288. task_itemp->packMessage(msg);
  3289. msg->sendReliable(mRegionp->getHost());
  3290. // Do the internal logic
  3291. doUpdateInventory(task_itemp, is_new);
  3292. }
  3293. LLInventoryObject* LLViewerObject::getInventoryObject(const LLUUID& item_id)
  3294. {
  3295. LLInventoryObject* rv = NULL;
  3296. if (mInventory && item_id.notNull())
  3297. {
  3298. for (LLInventoryObject::object_list_t::const_iterator
  3299. it = mInventory->begin(), end = mInventory->end();
  3300. it != end; ++it)
  3301. {
  3302. LLInventoryObject* obj = *it;
  3303. if (obj && obj->getUUID() == item_id)
  3304. {
  3305. rv = *it;
  3306. break;
  3307. }
  3308. }
  3309. }
  3310. return rv;
  3311. }
  3312. LLInventoryItem* LLViewerObject::getInventoryItem(const LLUUID& item_id)
  3313. {
  3314. LLInventoryObject* invobjp = getInventoryObject(item_id);
  3315. if (invobjp && invobjp->getType() != LLAssetType::AT_CATEGORY)
  3316. {
  3317. return dynamic_cast<LLInventoryItem*>(invobjp);
  3318. }
  3319. return NULL;
  3320. }
  3321. void LLViewerObject::getInventoryContents(LLInventoryObject::object_list_t& objects)
  3322. {
  3323. if (mInventory)
  3324. {
  3325. for (LLInventoryObject::object_list_t::const_iterator
  3326. it = mInventory->begin(), end = mInventory->end();
  3327. it != end; ++it)
  3328. {
  3329. LLInventoryObject* obj = *it;
  3330. if (obj && obj->getType() != LLAssetType::AT_CATEGORY)
  3331. {
  3332. objects.push_back(obj);
  3333. }
  3334. }
  3335. }
  3336. }
  3337. LLInventoryObject* LLViewerObject::getInventoryRoot()
  3338. {
  3339. return mInventory && !mInventory->empty() ? mInventory->back().get()
  3340. : NULL;
  3341. }
  3342. LLViewerInventoryItem* LLViewerObject::getInventoryItemByAsset(const LLUUID& asset_id,
  3343. LLAssetType::EType type)
  3344. {
  3345. if (mInventoryDirty)
  3346. {
  3347. // This is rather common (and harmless), now, while editing PBR objects
  3348. // (since a check is done for the PBR material permissions/presence in
  3349. // the edited primitive), so made it a LL_DEBUGS to avoid spamming the
  3350. // log uselessly. HB
  3351. LL_DEBUGS("ViewerObject") << "Performing inventory lookup for object "
  3352. << mID << " that has dirty inventory."
  3353. << LL_ENDL;
  3354. }
  3355. if (type == LLAssetType::AT_CATEGORY)
  3356. {
  3357. llwarns << "Attempted to get an inventory asset for category Id: "
  3358. << asset_id << llendl;
  3359. // Whatever called this should not be trying to get a folder by asset,
  3360. // since categories do not have any asset !
  3361. llassert(false);
  3362. return NULL;
  3363. }
  3364. if (mInventory)
  3365. {
  3366. for (LLInventoryObject::object_list_t::const_iterator
  3367. it = mInventory->begin(), end = mInventory->end();
  3368. it != end; ++it)
  3369. {
  3370. LLInventoryObject* objp = *it;
  3371. if (!objp) continue;
  3372. LLAssetType::EType atype = objp->getType();
  3373. if (atype != LLAssetType::AT_CATEGORY &&
  3374. atype != LLAssetType::AT_NONE)
  3375. {
  3376. LLViewerInventoryItem* itemp = objp->asViewerInventoryItem();
  3377. if (itemp && itemp->getAssetUUID() == asset_id)
  3378. {
  3379. if (type == LLAssetType::AT_NONE || type == atype)
  3380. {
  3381. return itemp;
  3382. }
  3383. }
  3384. }
  3385. }
  3386. }
  3387. return NULL;
  3388. }
  3389. void LLViewerObject::updateViewerInventoryAsset(const LLViewerInventoryItem* item,
  3390. const LLUUID& new_asset)
  3391. {
  3392. LLPointer<LLViewerInventoryItem> task_item =
  3393. new LLViewerInventoryItem(item);
  3394. task_item->setAssetUUID(new_asset);
  3395. // Do the internal logic
  3396. doUpdateInventory(task_item, false);
  3397. }
  3398. void LLViewerObject::setPixelAreaAndAngle()
  3399. {
  3400. if (getVolume())
  3401. {
  3402. // Volumes calculate pixel area and angle per face
  3403. return;
  3404. }
  3405. LLVector3 viewer_pos_agent = gAgent.getCameraPositionAgent();
  3406. LLVector3 pos_agent = getRenderPosition();
  3407. F32 dx = viewer_pos_agent.mV[VX] - pos_agent.mV[VX];
  3408. F32 dy = viewer_pos_agent.mV[VY] - pos_agent.mV[VY];
  3409. F32 dz = viewer_pos_agent.mV[VZ] - pos_agent.mV[VZ];
  3410. F32 max_scale = getMaxScale();
  3411. F32 mid_scale = getMidScale();
  3412. F32 min_scale = getMinScale();
  3413. // IW: estimate, when close to large objects, computing range based on
  3414. // distance from center is no good to try to get a min distance from face,
  3415. // subtract min_scale/2 from the range. This means we will load too much
  3416. // detail sometimes, but that is better than not enough. I do not think
  3417. // there is a better way to do this without calculating distance per-poly.
  3418. F32 range = sqrtf(dx * dx + dy * dy + dz * dz) - 0.5f * min_scale;
  3419. if (range < 0.001f || isHUDAttachment()) // range == zero
  3420. {
  3421. mAppAngle = 180.f;
  3422. mPixelArea = (F32)gViewerCamera.getScreenPixelArea();
  3423. }
  3424. else
  3425. {
  3426. mAppAngle = atan2f(max_scale, range) * RAD_TO_DEG;
  3427. F32 pixels_per_meter = gViewerCamera.getPixelMeterRatio() / range;
  3428. mPixelArea = (pixels_per_meter * max_scale) *
  3429. (pixels_per_meter * mid_scale);
  3430. if (mPixelArea > gViewerCamera.getScreenPixelArea())
  3431. {
  3432. mAppAngle = 180.f;
  3433. mPixelArea = (F32)gViewerCamera.getScreenPixelArea();
  3434. }
  3435. }
  3436. }
  3437. void LLViewerObject::setScale(const LLVector3& scale, bool damped)
  3438. {
  3439. LLPrimitive::setScale(scale);
  3440. if (mDrawable.notNull())
  3441. {
  3442. // Encompass completely sheared objects by taking the most extreme
  3443. // point possible (<1,1,0.5>)
  3444. mDrawable->setRadius(LLVector3(1.f, 1.f, 0.5f).scaleVec(scale).length());
  3445. updateDrawable(damped);
  3446. }
  3447. if (getPCode() == LL_PCODE_VOLUME && !isDead() && !isAttachment())
  3448. {
  3449. bool plottable = (flagCharacter() || flagUsePhysics()) && isRoot();
  3450. if (plottable || permYouOwner() || scale.lengthSquared() > 7.5f * 7.5f)
  3451. {
  3452. if (!mOnMap)
  3453. {
  3454. gObjectList.addToMap(this);
  3455. mOnMap = true;
  3456. }
  3457. }
  3458. else if (mOnMap)
  3459. {
  3460. gObjectList.removeFromMap(this);
  3461. mOnMap = false;
  3462. }
  3463. }
  3464. }
  3465. void LLViewerObject::setObjectCostStale()
  3466. {
  3467. mCostStale = true;
  3468. // Note: this is harmlessly redundant for Blinn-Phong material updates,
  3469. // since the root prim currently gets set stale anyway due to other
  3470. // property updates. But it is needed for PBR material Id updates.
  3471. LLViewerObject* rootp = getRootEdit();
  3472. if (rootp && rootp != this)
  3473. {
  3474. rootp->mCostStale = true;
  3475. }
  3476. }
  3477. void LLViewerObject::setObjectCost(F32 cost)
  3478. {
  3479. mObjectCost = cost;
  3480. mCostStale = false;
  3481. if (gFloaterToolsp && mUserSelected)
  3482. {
  3483. gFloaterToolsp->dirty();
  3484. }
  3485. }
  3486. void LLViewerObject::setLinksetCost(F32 cost)
  3487. {
  3488. mLinksetCost = cost;
  3489. mCostStale = false;
  3490. if (gFloaterToolsp && mUserSelected)
  3491. {
  3492. gFloaterToolsp->dirty();
  3493. }
  3494. }
  3495. void LLViewerObject::setPhysicsCost(F32 cost)
  3496. {
  3497. mPhysicsCost = cost;
  3498. mCostStale = false;
  3499. if (gFloaterToolsp && mUserSelected)
  3500. {
  3501. gFloaterToolsp->dirty();
  3502. }
  3503. }
  3504. void LLViewerObject::setLinksetPhysicsCost(F32 cost)
  3505. {
  3506. mLinksetPhysicsCost = cost;
  3507. mCostStale = false;
  3508. if (gFloaterToolsp && mUserSelected)
  3509. {
  3510. gFloaterToolsp->dirty();
  3511. }
  3512. }
  3513. F32 LLViewerObject::getObjectCost()
  3514. {
  3515. if (mCostStale)
  3516. {
  3517. gObjectList.updateObjectCost(this);
  3518. }
  3519. return mObjectCost;
  3520. }
  3521. F32 LLViewerObject::getLinksetCost()
  3522. {
  3523. if (mCostStale)
  3524. {
  3525. gObjectList.updateObjectCost(this);
  3526. }
  3527. return mLinksetCost;
  3528. }
  3529. F32 LLViewerObject::getPhysicsCost()
  3530. {
  3531. if (mCostStale)
  3532. {
  3533. gObjectList.updateObjectCost(this);
  3534. }
  3535. return mPhysicsCost;
  3536. }
  3537. F32 LLViewerObject::getLinksetPhysicsCost()
  3538. {
  3539. if (mCostStale)
  3540. {
  3541. gObjectList.updateObjectCost(this);
  3542. }
  3543. return mLinksetPhysicsCost;
  3544. }
  3545. F32 LLViewerObject::recursiveGetEstTrianglesMax() const
  3546. {
  3547. F32 est_tris = getEstTrianglesMax();
  3548. for (child_list_t::const_iterator iter = mChildList.begin(),
  3549. end = mChildList.end();
  3550. iter != end; ++iter)
  3551. {
  3552. const LLViewerObject* childp = *iter;
  3553. if (childp && !childp->isAvatar())
  3554. {
  3555. est_tris += childp->recursiveGetEstTrianglesMax();
  3556. }
  3557. }
  3558. return est_tris;
  3559. }
  3560. U32 LLViewerObject::recursiveGetTriangleCount(S32* vcountp) const
  3561. {
  3562. S32 total_tris = getTriangleCount(vcountp);
  3563. for (child_list_t::const_iterator iter = mChildList.begin(),
  3564. end = mChildList.end();
  3565. iter != end; ++iter)
  3566. {
  3567. const LLViewerObject* childp = *iter;
  3568. if (childp)
  3569. {
  3570. total_tris += childp->getTriangleCount(vcountp);
  3571. }
  3572. }
  3573. return total_tris;
  3574. }
  3575. S32 LLViewerObject::getAnimatedObjectMaxTris() const
  3576. {
  3577. S32 res = 0;
  3578. LLViewerRegion* regionp = gAgent.getRegion();
  3579. if (regionp)
  3580. {
  3581. const LLSD& info = regionp->getSimulatorFeatures();
  3582. if (info.has("AnimatedObjects"))
  3583. {
  3584. res = info["AnimatedObjects"]["AnimatedObjectMaxTris"].asInteger();
  3585. }
  3586. }
  3587. return res;
  3588. }
  3589. void LLViewerObject::updateSpatialExtents(LLVector4a& new_min,
  3590. LLVector4a& new_max)
  3591. {
  3592. if (mDrawable.notNull())
  3593. {
  3594. LLVector4a center;
  3595. center.load3(getRenderPosition().mV);
  3596. LLVector4a size;
  3597. size.load3(getScale().mV);
  3598. new_min.setSub(center, size);
  3599. new_max.setAdd(center, size);
  3600. mDrawable->setPositionGroup(center);
  3601. }
  3602. else
  3603. {
  3604. llwarns << "Call done for an object with NULL mDrawable" << llendl;
  3605. }
  3606. }
  3607. F32 LLViewerObject::getBinRadius()
  3608. {
  3609. if (mDrawable.notNull())
  3610. {
  3611. const LLVector4a* ext = mDrawable->getSpatialExtents();
  3612. LLVector4a diff;
  3613. diff.setSub(ext[1], ext[0]);
  3614. return diff.getLength3().getF32();
  3615. }
  3616. return getScale().length();
  3617. }
  3618. F32 LLViewerObject::getMaxScale() const
  3619. {
  3620. return llmax(getScale().mV[VX],getScale().mV[VY], getScale().mV[VZ]);
  3621. }
  3622. F32 LLViewerObject::getMinScale() const
  3623. {
  3624. return llmin(getScale().mV[0],getScale().mV[1],getScale().mV[2]);
  3625. }
  3626. F32 LLViewerObject::getMidScale() const
  3627. {
  3628. if (getScale().mV[VX] < getScale().mV[VY])
  3629. {
  3630. if (getScale().mV[VY] < getScale().mV[VZ])
  3631. {
  3632. return getScale().mV[VY];
  3633. }
  3634. else if (getScale().mV[VX] < getScale().mV[VZ])
  3635. {
  3636. return getScale().mV[VZ];
  3637. }
  3638. else
  3639. {
  3640. return getScale().mV[VX];
  3641. }
  3642. }
  3643. else if (getScale().mV[VX] < getScale().mV[VZ])
  3644. {
  3645. return getScale().mV[VX];
  3646. }
  3647. else if (getScale().mV[VY] < getScale().mV[VZ])
  3648. {
  3649. return getScale().mV[VZ];
  3650. }
  3651. else
  3652. {
  3653. return getScale().mV[VY];
  3654. }
  3655. }
  3656. void LLViewerObject::boostTexturePriority(bool boost_children)
  3657. {
  3658. if (isDead())
  3659. {
  3660. return;
  3661. }
  3662. for (S32 i = 0, count = getNumTEs(); i < count; ++i)
  3663. {
  3664. LLViewerTexture* texp = getTEImage(i);
  3665. if (texp)
  3666. {
  3667. texp->setBoostLevel(LLGLTexture::BOOST_SELECTED);
  3668. }
  3669. }
  3670. if (isSculpted() && !isMesh())
  3671. {
  3672. const LLSculptParams* sculpt_params = getSculptParams();
  3673. const LLUUID& sculpt_id = sculpt_params->getSculptTexture();
  3674. LLViewerTextureManager::getFetchedTexture(sculpt_id, FTT_DEFAULT, true,
  3675. LLGLTexture::BOOST_NONE,
  3676. LLViewerTexture::LOD_TEXTURE)->setBoostLevel(LLGLTexture::BOOST_SELECTED);
  3677. }
  3678. if (boost_children)
  3679. {
  3680. for (child_list_t::iterator iter = mChildList.begin(),
  3681. end = mChildList.end();
  3682. iter != end; ++iter)
  3683. {
  3684. LLViewerObject* child = *iter;
  3685. if (child) // Paranoia
  3686. {
  3687. child->boostTexturePriority();
  3688. }
  3689. }
  3690. }
  3691. }
  3692. void LLViewerObject::setLineWidthForWindowSize(S32 window_width)
  3693. {
  3694. if (window_width < 700)
  3695. {
  3696. LLUI::setLineWidth(2.f);
  3697. }
  3698. else if (window_width < 1100)
  3699. {
  3700. LLUI::setLineWidth(3.f);
  3701. }
  3702. else if (window_width < 2000)
  3703. {
  3704. LLUI::setLineWidth(4.f);
  3705. }
  3706. else
  3707. {
  3708. LLUI::setLineWidth(5.f);
  3709. }
  3710. }
  3711. // Culled from newsim LLTask::addNVPair
  3712. void LLViewerObject::addNVPair(const std::string& data)
  3713. {
  3714. LLNameValue* nv = new LLNameValue(data.c_str());
  3715. name_value_map_t::iterator iter = mNameValuePairs.find(nv->mName);
  3716. if (iter != mNameValuePairs.end())
  3717. {
  3718. LLNameValue* foundnv = iter->second;
  3719. if (foundnv->mClass != NVC_READ_ONLY)
  3720. {
  3721. delete foundnv;
  3722. mNameValuePairs.erase(iter);
  3723. }
  3724. else
  3725. {
  3726. delete nv;
  3727. return;
  3728. }
  3729. }
  3730. mNameValuePairs[nv->mName] = nv;
  3731. }
  3732. bool LLViewerObject::removeNVPair(const std::string& name)
  3733. {
  3734. char* canonical_name = gNVNameTable.addString(name);
  3735. LL_DEBUGS("ViewerObject") << "Removing: " << name << LL_ENDL;
  3736. name_value_map_t::iterator iter = mNameValuePairs.find(canonical_name);
  3737. if (iter != mNameValuePairs.end())
  3738. {
  3739. if (mRegionp)
  3740. {
  3741. LLNameValue* nv = iter->second;
  3742. #if 0
  3743. std::string buffer = nv->printNameValue();
  3744. LLMessageSystem* msg = gMessageSystemp;
  3745. msg->newMessageFast(_PREHASH_RemoveNameValuePair);
  3746. msg->nextBlockFast(_PREHASH_TaskData);
  3747. msg->addUUIDFast(_PREHASH_ID, mID);
  3748. msg->nextBlockFast(_PREHASH_NameValueData);
  3749. msg->addStringFast(_PREHASH_NVPair, buffer);
  3750. msg->sendReliable(mRegionp->getHost());
  3751. #endif
  3752. // Remove the NV pair from the local list.
  3753. delete nv;
  3754. mNameValuePairs.erase(iter);
  3755. return true;
  3756. }
  3757. else
  3758. {
  3759. LL_DEBUGS("ViewerObject") << "No region for object" << LL_ENDL;
  3760. }
  3761. }
  3762. return false;
  3763. }
  3764. LLNameValue* LLViewerObject::getNVPair(const std::string& name) const
  3765. {
  3766. char* canonical_name = gNVNameTable.addString(name);
  3767. if (!canonical_name)
  3768. {
  3769. return NULL;
  3770. }
  3771. // If you access a map with a name that is not in it, it will add the name
  3772. // and a null pointer. So first check if the data is in the map.
  3773. name_value_map_t::const_iterator it = mNameValuePairs.find(canonical_name);
  3774. if (it != mNameValuePairs.end())
  3775. {
  3776. return it->second;
  3777. }
  3778. return NULL;
  3779. }
  3780. void LLViewerObject::updatePositionCaches() const
  3781. {
  3782. // If region is removed from the list it is also deleted.
  3783. if (mRegionp && gWorld.isRegionListed(mRegionp))
  3784. {
  3785. if (!isRoot())
  3786. {
  3787. LLViewerObject* parent = (LLViewerObject*)getParent();
  3788. if (!parent)
  3789. {
  3790. llwarns_once << "No parent for child object " << mID << llendl;
  3791. llassert(false);
  3792. return;
  3793. }
  3794. mPositionRegion = parent->getPositionRegion() +
  3795. getPosition() * parent->getRotation();
  3796. mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
  3797. }
  3798. else
  3799. {
  3800. mPositionRegion = getPosition();
  3801. mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
  3802. }
  3803. }
  3804. }
  3805. const LLVector3d LLViewerObject::getPositionGlobal() const
  3806. {
  3807. LLVector3d pos_global;
  3808. // If region is removed from the list it is also deleted.
  3809. if (mRegionp && gWorld.isRegionListed(mRegionp))
  3810. {
  3811. if (isAttachment())
  3812. {
  3813. pos_global = gAgent.getPosGlobalFromAgent(getRenderPosition());
  3814. }
  3815. else
  3816. {
  3817. pos_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
  3818. }
  3819. }
  3820. else
  3821. {
  3822. pos_global.set(getPosition());
  3823. }
  3824. return pos_global;
  3825. }
  3826. const LLVector3& LLViewerObject::getPositionAgent() const
  3827. {
  3828. // If region is removed from the list it is also deleted.
  3829. if (mRegionp && gWorld.isRegionListed(mRegionp))
  3830. {
  3831. if (mDrawable.notNull() && !mDrawable->isRoot() && getParent())
  3832. {
  3833. // Do not return cached position if you have a parent, recalculate
  3834. // until all dirtying is done correctly.
  3835. LLVector3 position_region =
  3836. ((LLViewerObject*)getParent())->getPositionRegion() +
  3837. getPosition() * getParent()->getRotation();
  3838. mPositionAgent = mRegionp->getPosAgentFromRegion(position_region);
  3839. }
  3840. else
  3841. {
  3842. mPositionAgent = mRegionp->getPosAgentFromRegion(getPosition());
  3843. }
  3844. }
  3845. return mPositionAgent;
  3846. }
  3847. const LLVector3& LLViewerObject::getPositionRegion() const
  3848. {
  3849. if (!isRoot())
  3850. {
  3851. LLViewerObject* parent = (LLViewerObject*)getParent();
  3852. mPositionRegion = parent->getPositionRegion() +
  3853. getPosition() * parent->getRotation();
  3854. }
  3855. else
  3856. {
  3857. mPositionRegion = getPosition();
  3858. }
  3859. return mPositionRegion;
  3860. }
  3861. const LLVector3 LLViewerObject::getPositionEdit() const
  3862. {
  3863. if (isRootEdit())
  3864. {
  3865. return getPosition();
  3866. }
  3867. else
  3868. {
  3869. LLViewerObject* parent = (LLViewerObject*)getParent();
  3870. LLVector3 position_edit = parent->getPositionEdit() +
  3871. getPosition() * parent->getRotationEdit();
  3872. return position_edit;
  3873. }
  3874. }
  3875. const LLVector3 LLViewerObject::getRenderPosition() const
  3876. {
  3877. if (mDrawable.notNull() && mDrawable->isState(LLDrawable::RIGGED))
  3878. {
  3879. if (isRoot())
  3880. {
  3881. LLVOAvatarPuppet* puppet = getPuppetAvatar();
  3882. if (puppet)
  3883. {
  3884. F32 fixup;
  3885. if (puppet->hasPelvisFixup(fixup))
  3886. {
  3887. LLVector3 pos = mDrawable->getPositionAgent();
  3888. pos[VZ] += fixup;
  3889. return pos;
  3890. }
  3891. }
  3892. }
  3893. LLVOAvatar* avatar = getAvatar();
  3894. #if 0
  3895. if (avatar && !avatar->isPuppetAvatar())
  3896. {
  3897. return avatar->getRenderPosition();
  3898. }
  3899. #else
  3900. if (avatar && !getPuppetAvatar())
  3901. {
  3902. return avatar->getPositionAgent();
  3903. }
  3904. #endif
  3905. }
  3906. if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
  3907. {
  3908. return getPositionAgent();
  3909. }
  3910. return mDrawable->getPositionAgent();
  3911. }
  3912. LLMatrix4a LLViewerObject::getGLTFAssetToAgentTransform() const
  3913. {
  3914. LLMatrix4 root;
  3915. root.initScale(getScale());
  3916. root.rotate(getRenderRotation());
  3917. root.translate(getPositionAgent());
  3918. LLMatrix4a mat;
  3919. mat.loadu(root.getF32ptr());
  3920. return mat;
  3921. }
  3922. LLVector3 LLViewerObject::getGLTFNodePositionAgent(S32 node_index) const
  3923. {
  3924. LLVector3 ret;
  3925. getGLTFNodeTransformAgent(node_index, &ret, NULL, NULL);
  3926. return ret;
  3927. }
  3928. LLMatrix4a LLViewerObject::getAgentToGLTFAssetTransform() const
  3929. {
  3930. LLVector3 scale = getScale();
  3931. scale.mV[0] = 1.f / scale.mV[0];
  3932. scale.mV[1] = 1.f / scale.mV[1];
  3933. scale.mV[2] = 1.f / scale.mV[2];
  3934. LLMatrix4 scale_mat;
  3935. scale_mat.initScale(scale);
  3936. LLMatrix4 root;
  3937. root.translate(-getPositionAgent());
  3938. root.rotate(~getRenderRotation());
  3939. root *= scale_mat;
  3940. LLMatrix4a mat;
  3941. mat.loadu(root.getF32ptr());
  3942. return mat;
  3943. }
  3944. LLMatrix4a LLViewerObject::getGLTFNodeTransformAgent(S32 node_index) const
  3945. {
  3946. LLMatrix4a mat;
  3947. if (mGLTFAsset.notNull() && node_index >= 0 &&
  3948. node_index < (S32)mGLTFAsset->mNodes.size())
  3949. {
  3950. auto& node = mGLTFAsset->mNodes[node_index];
  3951. mat.matMul(node.mAssetMatrix, getGLTFAssetToAgentTransform());
  3952. }
  3953. else
  3954. {
  3955. mat.setIdentity();
  3956. }
  3957. return mat;
  3958. }
  3959. void LLViewerObject::getGLTFNodeTransformAgent(S32 node_index, LLVector3* posp,
  3960. LLQuaternion* rotp,
  3961. LLVector3* scalep) const
  3962. {
  3963. LLMatrix4a node_to_agent = getGLTFNodeTransformAgent(node_index);
  3964. if (posp)
  3965. {
  3966. LLVector4a p = node_to_agent.getTranslation();
  3967. posp->set(p.getF32ptr());
  3968. }
  3969. if (rotp)
  3970. {
  3971. rotp->set(node_to_agent.asMatrix4());
  3972. }
  3973. if (scalep)
  3974. {
  3975. scalep->mV[0] = node_to_agent.mMatrix[0].getLength3().getF32();
  3976. scalep->mV[1] = node_to_agent.mMatrix[1].getLength3().getF32();
  3977. scalep->mV[2] = node_to_agent.mMatrix[2].getLength3().getF32();
  3978. }
  3979. }
  3980. static void decompose_mat(const LLMatrix4a& mat, LLVector3& position,
  3981. LLQuaternion& rotation, LLVector3& scale)
  3982. {
  3983. LLVector4a p = mat.getTranslation();
  3984. position.set(p.getF32ptr());
  3985. rotation.set(mat.asMatrix4());
  3986. scale.mV[0] = mat.mMatrix[0].getLength3().getF32();
  3987. scale.mV[1] = mat.mMatrix[1].getLength3().getF32();
  3988. scale.mV[2] = mat.mMatrix[2].getLength3().getF32();
  3989. }
  3990. void LLViewerObject::setGLTFNodeRotationAgent(S32 node_index,
  3991. const LLQuaternion& rotation)
  3992. {
  3993. if (mGLTFAsset.isNull() || node_index < 0 ||
  3994. node_index >= (S32)mGLTFAsset->mNodes.size())
  3995. {
  3996. return;
  3997. }
  3998. auto& node = mGLTFAsset->mNodes[node_index];
  3999. LLMatrix4a agent_to_asset = getAgentToGLTFAssetTransform();
  4000. LLMatrix4a agent_to_node = agent_to_asset;
  4001. if (node.mParent != -1)
  4002. {
  4003. auto& parent = mGLTFAsset->mNodes[node.mParent];
  4004. agent_to_node.matMul(agent_to_asset, parent.mAssetMatrixInv);
  4005. }
  4006. LLQuaternion agent_to_node_rot(agent_to_node.asMatrix4());
  4007. LLQuaternion new_rot = rotation * agent_to_node_rot;
  4008. new_rot.normalize();
  4009. LLVector3 pos, scale;
  4010. LLQuaternion rot;
  4011. decompose_mat(node.mMatrix, pos, rot, scale);
  4012. node.mMatrix.asMatrix4().initAll(scale, new_rot, pos);
  4013. mGLTFAsset->updateTransforms();
  4014. }
  4015. void LLViewerObject::moveGLTFNode(S32 node_index, const LLVector3& offset)
  4016. {
  4017. if (mGLTFAsset.isNull() || node_index < 0 ||
  4018. node_index >= (S32)mGLTFAsset->mNodes.size())
  4019. {
  4020. return;
  4021. }
  4022. auto& node = mGLTFAsset->mNodes[node_index];
  4023. LLMatrix4a agent_to_asset = getAgentToGLTFAssetTransform();
  4024. LLMatrix4a agent_to_node;
  4025. agent_to_node.matMul(agent_to_asset, node.mAssetMatrixInv);
  4026. LLVector4a offset_v;
  4027. offset_v.load3(offset.mV);
  4028. agent_to_node.affineTransform(offset_v, offset_v);
  4029. LLVector4a origin = LLVector4a::getZero();
  4030. agent_to_node.affineTransform(origin, origin);
  4031. offset_v.sub(origin);
  4032. offset_v.getF32ptr()[3] = 1.f;
  4033. LLMatrix4a trans;
  4034. trans.setIdentity();
  4035. trans.mMatrix[3] = offset_v;
  4036. node.mMatrix.matMul(trans, node.mMatrix);
  4037. // *TODO: only update transforms for this node and its children (or use a
  4038. // dirty flag).
  4039. mGLTFAsset->updateTransforms();
  4040. }
  4041. const LLQuaternion LLViewerObject::getRenderRotation() const
  4042. {
  4043. bool has_drawable = mDrawable.notNull();
  4044. if (has_drawable && mDrawable->isState(LLDrawable::RIGGED) &&
  4045. !isAnimatedObject())
  4046. {
  4047. return LLQuaternion();
  4048. }
  4049. if (!has_drawable || mDrawable->isStatic())
  4050. {
  4051. return getRotationEdit();
  4052. }
  4053. if (!mDrawable->isRoot())
  4054. {
  4055. return getRotation() *
  4056. LLQuaternion(mDrawable->getParent()->getWorldMatrix());
  4057. }
  4058. return LLQuaternion(mDrawable->getWorldMatrix());
  4059. }
  4060. const LLMatrix4& LLViewerObject::getRenderMatrix() const
  4061. {
  4062. return mDrawable->getWorldMatrix();
  4063. }
  4064. const LLQuaternion LLViewerObject::getRotationRegion() const
  4065. {
  4066. if (((LLXform*)this)->isRoot())
  4067. {
  4068. return getRotation();
  4069. }
  4070. return getRotation() * getParent()->getRotation();
  4071. }
  4072. const LLQuaternion LLViewerObject::getRotationEdit() const
  4073. {
  4074. if (((LLXform*)this)->isRootEdit())
  4075. {
  4076. return getRotation();
  4077. }
  4078. return getRotation() * getParent()->getRotation();
  4079. }
  4080. void LLViewerObject::setPositionAbsoluteGlobal(const LLVector3d& pos_global)
  4081. {
  4082. if (isAttachment())
  4083. {
  4084. LLVector3 new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
  4085. if (isRootEdit())
  4086. {
  4087. new_pos -= mDrawable->mXform.getParent()->getWorldPosition();
  4088. LLQuaternion world_rotation =
  4089. mDrawable->mXform.getParent()->getWorldRotation();
  4090. new_pos = new_pos * ~world_rotation;
  4091. }
  4092. else
  4093. {
  4094. LLViewerObject* parentp = (LLViewerObject*)getParent();
  4095. new_pos -= parentp->getPositionAgent();
  4096. new_pos = new_pos * ~parentp->getRotationRegion();
  4097. }
  4098. setPositionLocal(new_pos);
  4099. if (mParent && mParent->isAvatar())
  4100. {
  4101. // We have changed the position of an attachment, so we need to
  4102. // clamp it
  4103. ((LLVOAvatar*)mParent)->clampAttachmentPositions();
  4104. }
  4105. }
  4106. else if (isRoot())
  4107. {
  4108. setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
  4109. }
  4110. else
  4111. {
  4112. // The relative position with the parent is not constant
  4113. LLViewerObject* parent = (LLViewerObject*)getParent();
  4114. // RN: this assumes we are only calling this function from the edit
  4115. // tools
  4116. gPipeline.updateMoveNormalAsync(parent->mDrawable);
  4117. LLVector3 pos_local = mRegionp->getPosRegionFromGlobal(pos_global) -
  4118. parent->getPositionRegion();
  4119. pos_local = pos_local * ~parent->getRotationRegion();
  4120. setPositionLocal(pos_local);
  4121. }
  4122. // RN: assumes we always want to snap the object when calling this function
  4123. gPipeline.updateMoveNormalAsync(mDrawable);
  4124. }
  4125. void LLViewerObject::setPositionLocal(const LLVector3& pos, bool damped)
  4126. {
  4127. if (getPosition() != pos)
  4128. {
  4129. setChanged(TRANSLATED | SILHOUETTE);
  4130. }
  4131. setPosition(pos);
  4132. updateDrawable(damped);
  4133. if (isRoot())
  4134. {
  4135. // Position caches need to be up to date on root objects
  4136. updatePositionCaches();
  4137. }
  4138. }
  4139. void LLViewerObject::setPositionGlobal(const LLVector3d& pos_global,
  4140. bool damped)
  4141. {
  4142. if (isAttachment())
  4143. {
  4144. LLVector3 new_pos;
  4145. if (isRootEdit())
  4146. {
  4147. new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
  4148. new_pos = new_pos - mDrawable->mXform.getParent()->getWorldPosition();
  4149. LLQuaternion inv_world_rot =
  4150. mDrawable->mXform.getParent()->getWorldRotation();
  4151. inv_world_rot.transpose();
  4152. new_pos = new_pos * inv_world_rot;
  4153. setPositionLocal(new_pos);
  4154. }
  4155. else
  4156. {
  4157. // Assumes parent is root editable (root of attachment)
  4158. new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
  4159. new_pos = new_pos - mDrawable->mXform.getParent()->getWorldPosition();
  4160. LLVector3 delta_pos = new_pos - getPosition();
  4161. LLQuaternion invRotation = mDrawable->getRotation();
  4162. invRotation.transpose();
  4163. delta_pos = delta_pos * invRotation;
  4164. // *FIXME: is this right ? Should not we be calling the
  4165. // LLViewerObject version of setPosition ?
  4166. LLVector3 old_pos = mDrawable->mXform.getParent()->getPosition();
  4167. mDrawable->mXform.getParent()->setPosition(old_pos + delta_pos);
  4168. setChanged(TRANSLATED | SILHOUETTE);
  4169. }
  4170. if (mParent && mParent->isAvatar())
  4171. {
  4172. // We have changed the position of an attachment, so we need to
  4173. // clamp it
  4174. ((LLVOAvatar*)mParent)->clampAttachmentPositions();
  4175. }
  4176. }
  4177. else if (isRoot())
  4178. {
  4179. setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
  4180. }
  4181. else
  4182. {
  4183. // The relative position with the parent is constant, but the parent's
  4184. // position needs to be changed
  4185. LLVector3d position_offset;
  4186. position_offset.set(getPosition()*getParent()->getRotation());
  4187. LLVector3d new_pos_global = pos_global - position_offset;
  4188. ((LLViewerObject*)getParent())->setPositionGlobal(new_pos_global);
  4189. }
  4190. updateDrawable(damped);
  4191. }
  4192. void LLViewerObject::setPositionParent(const LLVector3& pos_parent,
  4193. bool damped)
  4194. {
  4195. // Set position relative to parent, if no parent, relative to region
  4196. if (!isRoot())
  4197. {
  4198. setPositionLocal(pos_parent, damped);
  4199. #if 0
  4200. updateDrawable(damped);
  4201. #endif
  4202. }
  4203. else
  4204. {
  4205. setPositionRegion(pos_parent);
  4206. }
  4207. }
  4208. void LLViewerObject::setPositionRegion(const LLVector3& pos_region)
  4209. {
  4210. if (isRootEdit())
  4211. {
  4212. setPositionLocal(pos_region);
  4213. mPositionRegion = pos_region;
  4214. if (mRegionp)
  4215. {
  4216. mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
  4217. }
  4218. }
  4219. else
  4220. {
  4221. LLViewerObject* parent = (LLViewerObject*)getParent();
  4222. setPositionLocal(pos_region - parent->getPositionRegion() *
  4223. ~parent->getRotationRegion());
  4224. }
  4225. }
  4226. void LLViewerObject::setPositionAgent(const LLVector3& pos_agent)
  4227. {
  4228. if (mRegionp)
  4229. {
  4230. setPositionRegion(mRegionp->getPosRegionFromAgent(pos_agent));
  4231. }
  4232. }
  4233. // Identical to setPositionRegion() except it checks for child-joints and does
  4234. // not also move the joint-parent. *TODO: implement similar intelligence for
  4235. // joint-parents toward their joint-children
  4236. void LLViewerObject::setPositionEdit(const LLVector3& pos_edit, bool damped)
  4237. {
  4238. if (isRootEdit())
  4239. {
  4240. if (!mRegionp)
  4241. {
  4242. llwarns << "Region not set; position unchanged for object Id: "
  4243. << mID << llendl;
  4244. return;
  4245. }
  4246. setPositionLocal(pos_edit, damped);
  4247. mPositionRegion = pos_edit;
  4248. mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
  4249. }
  4250. else
  4251. {
  4252. // The relative position with the parent is constant, but the parent's
  4253. // position needs to be changed
  4254. LLVector3 position_offset = getPosition() * getParent()->getRotation();
  4255. ((LLViewerObject*)getParent())->setPositionEdit(pos_edit -
  4256. position_offset);
  4257. updateDrawable(damped);
  4258. }
  4259. }
  4260. LLViewerObject* LLViewerObject::getRootEdit() const
  4261. {
  4262. const LLViewerObject* root = this;
  4263. while (root->mParent && !root->mParent->isAvatar())
  4264. {
  4265. root = (LLViewerObject*)root->mParent;
  4266. }
  4267. return (LLViewerObject*)root;
  4268. }
  4269. bool LLViewerObject::lineSegmentIntersect(const LLVector4a& start,
  4270. const LLVector4a& end,
  4271. S32 face,
  4272. bool pick_transparent,
  4273. bool pick_rigged,
  4274. S32* face_hit,
  4275. LLVector4a* intersection,
  4276. LLVector2* tex_coord,
  4277. LLVector4a* normal,
  4278. LLVector4a* tangent)
  4279. {
  4280. return false;
  4281. }
  4282. bool LLViewerObject::lineSegmentBoundingBox(const LLVector4a& start,
  4283. const LLVector4a& end)
  4284. {
  4285. if (mDrawable.isNull() || mDrawable->isDead())
  4286. {
  4287. return false;
  4288. }
  4289. const LLVector4a* ext = mDrawable->getSpatialExtents();
  4290. // VECTORIZE THIS
  4291. LLVector4a center;
  4292. center.setAdd(ext[1], ext[0]);
  4293. center.mul(0.5f);
  4294. LLVector4a size;
  4295. size.setSub(ext[1], ext[0]);
  4296. size.mul(0.5f);
  4297. return LLLineSegmentBoxIntersect(start, end, center, size);
  4298. }
  4299. void LLViewerObject::setMediaType(U8 media_type)
  4300. {
  4301. // *TODO: what if we do not have a media pointer ?
  4302. if (mMedia && mMedia->mMediaType != media_type)
  4303. {
  4304. mMedia->mMediaType = media_type;
  4305. // *TODO: update materials with new image
  4306. }
  4307. }
  4308. void LLViewerObject::setMediaURL(const std::string& media_url)
  4309. {
  4310. if (!mMedia)
  4311. {
  4312. mMedia = new LLViewerObjectMedia;
  4313. mMedia->mMediaURL = media_url;
  4314. mMedia->mPassedWhitelist = false;
  4315. // *TODO: update materials with new image
  4316. }
  4317. else if (mMedia->mMediaURL != media_url)
  4318. {
  4319. mMedia->mMediaURL = media_url;
  4320. mMedia->mPassedWhitelist = false;
  4321. // *TODO: update materials with new image
  4322. }
  4323. }
  4324. bool LLViewerObject::setMaterial(U8 material)
  4325. {
  4326. bool res = LLPrimitive::setMaterial(material);
  4327. if (res)
  4328. {
  4329. setChanged(TEXTURE);
  4330. }
  4331. return res;
  4332. }
  4333. void LLViewerObject::setNumTEs(U8 num_tes)
  4334. {
  4335. U8 old_num_tes = getNumTEs();
  4336. if (num_tes == old_num_tes)
  4337. {
  4338. return;
  4339. }
  4340. if (num_tes)
  4341. {
  4342. // Duplicate last TE into new ones, when increasing the number of TEs:
  4343. // this happens whenever you slice an object, or hollow it while
  4344. // editing it, for example.
  4345. if (old_num_tes && num_tes > old_num_tes)
  4346. {
  4347. mTEImages.reserve(num_tes);
  4348. mTENormalMaps.reserve(num_tes);
  4349. mTESpecularMaps.reserve(num_tes);
  4350. U8 last = old_num_tes - 1;
  4351. LLViewerTexture* diffusep = mTEImages[last].get();
  4352. LLViewerTexture* normalp = mTENormalMaps[last].get();
  4353. LLViewerTexture* specularp = mTESpecularMaps[last].get();
  4354. for (U8 i = old_num_tes; i < num_tes; ++i)
  4355. {
  4356. mTEImages.emplace_back(diffusep);
  4357. mTENormalMaps.emplace_back(normalp);
  4358. mTESpecularMaps.emplace_back(specularp);
  4359. }
  4360. }
  4361. else
  4362. {
  4363. mTEImages.resize(num_tes);
  4364. mTENormalMaps.resize(num_tes);
  4365. mTESpecularMaps.resize(num_tes);
  4366. }
  4367. }
  4368. else if (!mTEImages.empty())
  4369. {
  4370. mTEImages.clear();
  4371. mTENormalMaps.clear();
  4372. mTESpecularMaps.clear();
  4373. }
  4374. LLPrimitive::setNumTEs(num_tes);
  4375. setChanged(TEXTURE);
  4376. // Duplicate any GLTF material in the same way.
  4377. if (old_num_tes > 0 && old_num_tes < num_tes)
  4378. {
  4379. LLTextureEntry* srcp = getTE(old_num_tes - 1);
  4380. if (srcp)
  4381. {
  4382. LLGLTFMaterial* matp = srcp->getGLTFMaterial();
  4383. LLGLTFMaterial* omatp = srcp->getGLTFMaterialOverride();
  4384. if (matp && omatp)
  4385. {
  4386. const LLUUID& mat_id = getRenderMaterialID(old_num_tes - 1);
  4387. for (U8 i = old_num_tes; i < num_tes; ++i)
  4388. {
  4389. setRenderMaterialID(i, mat_id, false);
  4390. LLTextureEntry* tep = getTE(i);
  4391. if (!tep)
  4392. {
  4393. continue;
  4394. }
  4395. tep->setGLTFMaterialOverride(new LLGLTFMaterial(*omatp));
  4396. LLGLTFMaterial* rmatp = new LLFetchedGLTFMaterial();
  4397. *rmatp = *matp;
  4398. rmatp->applyOverride(*omatp);
  4399. tep->setGLTFRenderMaterial(rmatp);
  4400. }
  4401. }
  4402. }
  4403. }
  4404. if (mDrawable.notNull())
  4405. {
  4406. gPipeline.markTextured(mDrawable);
  4407. }
  4408. }
  4409. void LLViewerObject::sendMaterialUpdate() const
  4410. {
  4411. LLViewerRegion* regionp = getRegion();
  4412. if (!regionp) return;
  4413. LLMessageSystem* msg = gMessageSystemp;
  4414. msg->newMessageFast(_PREHASH_ObjectMaterial);
  4415. msg->nextBlockFast(_PREHASH_AgentData);
  4416. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4417. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4418. msg->nextBlockFast(_PREHASH_ObjectData);
  4419. msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
  4420. msg->addU8Fast(_PREHASH_Material, getMaterial());
  4421. msg->sendReliable(regionp->getHost());
  4422. }
  4423. // formerly send_object_shape(LLViewerObject *object)
  4424. void LLViewerObject::sendShapeUpdate()
  4425. {
  4426. LLViewerRegion* regionp = getRegion();
  4427. if (!regionp) return;
  4428. LLMessageSystem* msg = gMessageSystemp;
  4429. msg->newMessageFast(_PREHASH_ObjectShape);
  4430. msg->nextBlockFast(_PREHASH_AgentData);
  4431. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4432. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4433. msg->nextBlockFast(_PREHASH_ObjectData);
  4434. msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
  4435. LLVolumeMessage::packVolumeParams(&getVolume()->getParams(), msg);
  4436. msg->sendReliable(regionp->getHost());
  4437. }
  4438. void LLViewerObject::sendTEUpdate() const
  4439. {
  4440. LLViewerRegion* regionp = getRegion();
  4441. if (!regionp) return;
  4442. LLMessageSystem* msg = gMessageSystemp;
  4443. msg->newMessageFast(_PREHASH_ObjectImage);
  4444. msg->nextBlockFast(_PREHASH_AgentData);
  4445. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4446. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4447. msg->nextBlockFast(_PREHASH_ObjectData);
  4448. msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
  4449. if (mMedia)
  4450. {
  4451. msg->addString(_PREHASH_MediaURL, mMedia->mMediaURL);
  4452. }
  4453. else
  4454. {
  4455. msg->addString(_PREHASH_MediaURL, NULL);
  4456. }
  4457. // *TODO: send media type
  4458. packTEMessage(msg);
  4459. msg->sendReliable(regionp->getHost());
  4460. }
  4461. LLViewerTexture* LLViewerObject::getBakedTextureForMagicId(const LLUUID& id)
  4462. {
  4463. if (!LLAvatarAppearanceDictionary::isBakedImageId(id))
  4464. {
  4465. return NULL;
  4466. }
  4467. LLViewerObject* root = getRootEdit();
  4468. bool is_animesh = root && root->isAnimatedObject();
  4469. LLVOAvatar* avatarp = is_animesh ? root->getAvatarAncestor() : getAvatar();
  4470. if (avatarp)
  4471. {
  4472. EBakedTextureIndex tex_idx =
  4473. LLAvatarAppearanceDictionary::assetIdToBakedTextureIndex(id);
  4474. LLViewerTexture* baked_tex = avatarp->getBakedTexture(tex_idx);
  4475. if (baked_tex && !baked_tex->isMissingAsset())
  4476. {
  4477. return baked_tex;
  4478. }
  4479. return LLViewerFetchedTexture::sDefaultImagep;
  4480. }
  4481. return LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, true,
  4482. LLGLTexture::BOOST_NONE,
  4483. LLViewerTexture::LOD_TEXTURE);
  4484. }
  4485. void LLViewerObject::updateAvatarMeshVisibility(const LLUUID& id,
  4486. const LLUUID& old_id)
  4487. {
  4488. LLVOAvatar* avatarp = getAvatar();
  4489. if (id != old_id && avatarp &&
  4490. (LLAvatarAppearanceDictionary::isBakedImageId(old_id) ||
  4491. LLAvatarAppearanceDictionary::isBakedImageId(id)))
  4492. {
  4493. avatarp->updateMeshVisibility();
  4494. }
  4495. }
  4496. void LLViewerObject::setTE(U8 te, const LLTextureEntry& texture_entry)
  4497. {
  4498. LLUUID old_image_id;
  4499. LLTextureEntry* tep = getTE(te);
  4500. if (tep)
  4501. {
  4502. old_image_id = tep->getID();
  4503. }
  4504. LLPrimitive::setTE(te, texture_entry);
  4505. tep = getTE(te);
  4506. if (!tep)
  4507. {
  4508. return;
  4509. }
  4510. const LLUUID& image_id = tep->getID();
  4511. LLViewerTexture* baked_tex = getBakedTextureForMagicId(image_id);
  4512. if (baked_tex)
  4513. {
  4514. mTEImages[te] = baked_tex;
  4515. }
  4516. else
  4517. {
  4518. mTEImages[te] =
  4519. LLViewerTextureManager::getFetchedTexture(image_id,
  4520. FTT_DEFAULT, true,
  4521. LLGLTexture::BOOST_NONE,
  4522. LLViewerTexture::LOD_TEXTURE);
  4523. }
  4524. updateAvatarMeshVisibility(image_id, old_image_id);
  4525. updateTEMaterialTextures(te);
  4526. }
  4527. LLViewerFetchedTexture* LLViewerObject::getFetchedTexForMat(const LLUUID& id,
  4528. F32 vsize, U32 prio)
  4529. {
  4530. if (id.isNull())
  4531. {
  4532. return NULL;
  4533. }
  4534. LLViewerFetchedTexture* texp = NULL;
  4535. if (LLAvatarAppearanceDictionary::isBakedImageId(id))
  4536. {
  4537. LLViewerTexture* btexp = getBakedTextureForMagicId(id);
  4538. if (btexp)
  4539. {
  4540. texp = btexp->asFetched();
  4541. }
  4542. }
  4543. else
  4544. {
  4545. texp = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, true,
  4546. (LLGLTexture::EBoostLevel)prio,
  4547. LLViewerTexture::LOD_TEXTURE);
  4548. }
  4549. if (texp)
  4550. {
  4551. texp->addTextureStats(vsize);
  4552. }
  4553. return texp;
  4554. }
  4555. void LLViewerObject::updateTEMaterialTextures(U8 te)
  4556. {
  4557. LLTextureEntry* tep = getTE(te);
  4558. if (!tep)
  4559. {
  4560. return;
  4561. }
  4562. if (tep->getMaterialParams().notNull())
  4563. {
  4564. const LLUUID& norm_id = tep->getMaterialParams()->getNormalID();
  4565. mTENormalMaps[te] =
  4566. LLViewerTextureManager::getFetchedTexture(norm_id,
  4567. FTT_DEFAULT, true,
  4568. LLGLTexture::BOOST_ALM,
  4569. LLViewerTexture::LOD_TEXTURE);
  4570. const LLUUID& spec_id = tep->getMaterialParams()->getSpecularID();
  4571. mTESpecularMaps[te] =
  4572. LLViewerTextureManager::getFetchedTexture(spec_id,
  4573. FTT_DEFAULT, true,
  4574. LLGLTexture::BOOST_ALM,
  4575. LLViewerTexture::LOD_TEXTURE);
  4576. }
  4577. const LLUUID& mat_id = getRenderMaterialID(te);
  4578. LLFetchedGLTFMaterial* matp =
  4579. (LLFetchedGLTFMaterial*)tep->getGLTFRenderMaterial();
  4580. if (matp)
  4581. {
  4582. if (mat_id.isNull())
  4583. {
  4584. tep->setGLTFMaterial(NULL);
  4585. return;
  4586. }
  4587. }
  4588. else if (mat_id.notNull())
  4589. {
  4590. matp = gGLTFMaterialList.getMaterial(mat_id);
  4591. if (!matp) return; // Maybe paranoia ?... Better safe than sorry. HB
  4592. if (matp->isFetching())
  4593. {
  4594. // Material is not loaded yet, rebuild draw info when the object
  4595. // finishes loading.
  4596. matp->onMaterialComplete([id = mID]
  4597. {
  4598. LLViewerObject* objp =
  4599. gObjectList.findObject(id);
  4600. if (!objp) return;
  4601. LLViewerRegion* regionp =
  4602. objp->getRegion();
  4603. if (regionp)
  4604. {
  4605. regionp->loadCacheMiscExtras(objp);
  4606. }
  4607. objp->markForUpdate(false);
  4608. });
  4609. }
  4610. tep->setGLTFMaterial(matp);
  4611. }
  4612. if (!matp)
  4613. {
  4614. return; // Nothing else to do.
  4615. }
  4616. // When enough memory, fetch at a good resolution, else use the discard
  4617. // bias to reduce the initial resolution of the textures. HB
  4618. constexpr F32 MAX_VSIZE = 512.f * 512.f;
  4619. constexpr F32 BIAS_SCALER = 3.f / 5.f; // Bias 0 to 5 -> 0 to 3
  4620. // Factor will be between 1 and 1/4, depending on discard bias
  4621. F32 factor = 1.f / (1.f +
  4622. BIAS_SCALER * LLViewerTexture::sDesiredDiscardBias);
  4623. F32 vsize = MAX_VSIZE * factor * factor;
  4624. matp->mBaseColorTexture =
  4625. getFetchedTexForMat(matp->mTextureId[BASECOLIDX], vsize);
  4626. matp->mNormalTexture = getFetchedTexForMat(matp->mTextureId[NORMALIDX],
  4627. vsize, LLGLTexture::BOOST_ALM);
  4628. matp->mMetallicRoughnessTexture =
  4629. getFetchedTexForMat(matp->mTextureId[MROUGHIDX], vsize);
  4630. matp->mEmissiveTexture =
  4631. getFetchedTexForMat(matp->mTextureId[EMISSIVEIDX], vsize,
  4632. LLGLTexture::BOOST_ALM);
  4633. }
  4634. void LLViewerObject::refreshBakeTexture()
  4635. {
  4636. LL_DEBUGS("AttachmentBakes") << "Refreshing attachment bake textures for object "
  4637. << mID << LL_ENDL;
  4638. bool changed = false;
  4639. for (U8 te = 0, count = getNumTEs(); te < count; ++te)
  4640. {
  4641. LLTextureEntry* tep = getTE(te);
  4642. if (!tep) continue;
  4643. const LLUUID& image_id = tep->getID();
  4644. if (LLAvatarAppearanceDictionary::isBakedImageId(image_id))
  4645. {
  4646. LLViewerTexture* baked_tex = getBakedTextureForMagicId(image_id);
  4647. if (baked_tex)
  4648. {
  4649. LL_DEBUGS("AttachmentBakes") << "Face index: " << (S32)te
  4650. << " - Bake Id: " << image_id
  4651. << " - Baked texture Id: "
  4652. << baked_tex->getID() << LL_ENDL;
  4653. changeTEImage(te, baked_tex);
  4654. changed = true;
  4655. }
  4656. }
  4657. }
  4658. // *HACK: strangely, we need force a LLVOVolume rebuild to see the texture
  4659. // actually changing on the prim. It is probably a result of how textures
  4660. // are batched in the Cool VL Viewer.
  4661. if (changed && mDrawable.notNull())
  4662. {
  4663. LLVOVolume* volp = mDrawable->getVOVolume();
  4664. if (volp)
  4665. {
  4666. volp->tempSetLOD(0);
  4667. volp->faceMappingChanged();
  4668. }
  4669. }
  4670. }
  4671. bool LLViewerObject::hasRenderMaterialParams() const
  4672. {
  4673. return getParameterEntryInUse(LLNetworkData::PARAMS_RENDER_MATERIAL);
  4674. }
  4675. void LLViewerObject::setHasRenderMaterialParams(bool has_materials)
  4676. {
  4677. if (hasRenderMaterialParams() != has_materials)
  4678. {
  4679. setParameterEntryInUse(LLNetworkData::PARAMS_RENDER_MATERIAL,
  4680. has_materials, true);
  4681. }
  4682. }
  4683. const LLUUID& LLViewerObject::getRenderMaterialID(U8 te) const
  4684. {
  4685. LLRenderMaterialParams* paramsp = getMaterialRenderParams();
  4686. return paramsp ? paramsp->getMaterial(te) : LLUUID::null;
  4687. }
  4688. static void set_te_overide_mat(const LLUUID& obj_id, U8 te)
  4689. {
  4690. LLViewerObject* objp = gObjectList.findObject(obj_id);
  4691. if (!objp)
  4692. {
  4693. return;
  4694. }
  4695. LLTextureEntry* tep = objp->getTE(te);
  4696. if (!tep)
  4697. {
  4698. return;
  4699. }
  4700. const LLGLTFMaterial* matp = tep->getGLTFMaterial();
  4701. if (!matp)
  4702. {
  4703. return;
  4704. }
  4705. const LLGLTFMaterial* omatp = tep->getGLTFMaterialOverride();
  4706. if (omatp)
  4707. {
  4708. if (objp->getDebugUpdateMsg())
  4709. {
  4710. llinfos << "Setting material overrides for object: " << obj_id
  4711. << llendl;
  4712. }
  4713. LLGLTFMaterial* rmatp = new LLFetchedGLTFMaterial();
  4714. *rmatp = *matp;
  4715. rmatp->applyOverride(*omatp);
  4716. tep->setGLTFRenderMaterial(rmatp);
  4717. }
  4718. }
  4719. // Implementation is delicate: if update is bound for server, it should always
  4720. // null out GLTFRenderMaterial and clear GLTFMaterialOverride even if Ids have
  4721. // not changed (the case where Ids have not changed indicates the user has
  4722. // reapplied the original material, in which case overrides should be dropped),
  4723. // otherwise it should only null out the render material where Ids or overrides
  4724. // have changed (the case where Ids have changed but overrides are still
  4725. // present is from unsynchronized updates from the simulator, or synchronized
  4726. // updates with solely transform overrides).
  4727. void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id,
  4728. bool update_server, bool local_origin)
  4729. {
  4730. S32 end_idx = getNumTEs();
  4731. if (te_in >= end_idx)
  4732. {
  4733. llwarns << "Out of bound te: " << te_in << ". Aborted." << llendl;
  4734. return;
  4735. }
  4736. S32 start_idx;
  4737. if (te_in < 0)
  4738. {
  4739. start_idx = 0;
  4740. }
  4741. else
  4742. {
  4743. start_idx = te_in;
  4744. end_idx = llmin(start_idx + 1, end_idx);
  4745. }
  4746. // If needed, enable the "GLTF" debug tag for this method call with this
  4747. // debugged LLViewerObject instance. HB
  4748. bool set_debug_tag = mDebugUpdateMsg &&
  4749. !HBFloaterDebugTags::debugTagActive("GLTF");
  4750. if (set_debug_tag)
  4751. {
  4752. HBFloaterDebugTags::setTag("GLTF", true);
  4753. }
  4754. LL_DEBUGS("GLTF") << "Called for object " << mID << " to set PBR material "
  4755. << id << " on face(s) " << start_idx;
  4756. if (end_idx > start_idx + 1)
  4757. {
  4758. LL_CONT << " to " << end_idx - 1;
  4759. }
  4760. LL_CONT << ". update_server = " << (update_server ? "true" : "false")
  4761. << LL_ENDL;
  4762. constexpr U16 PRMAT = LLNetworkData::PARAMS_RENDER_MATERIAL;
  4763. LLRenderMaterialParams* paramsp =
  4764. (LLRenderMaterialParams*)getExtraParameterEntry(PRMAT);
  4765. LL_DEBUGS("GLTF") << "PBR material parameter entry "
  4766. << (paramsp ? "found." : "not found.") << LL_ENDL;
  4767. if (!paramsp && id.notNull())
  4768. {
  4769. paramsp = (LLRenderMaterialParams*)createNewParameterEntry(PRMAT);
  4770. if (!paramsp)
  4771. {
  4772. llwarns << "Could not create an extra parameter entry for: "
  4773. << te_in << ". Aborted." << llendl;
  4774. return;
  4775. }
  4776. }
  4777. LLFetchedGLTFMaterial* matp = NULL;
  4778. if (id.notNull())
  4779. {
  4780. matp = gGLTFMaterialList.getMaterial(id);
  4781. LL_DEBUGS("GLTF") << "PBR material " << (matp ? "found" : "not found")
  4782. << " in the materials list." << LL_ENDL;
  4783. }
  4784. // Update local state
  4785. for (U8 te = start_idx; te < end_idx; ++te)
  4786. {
  4787. LLTextureEntry* tep = getTE(te);
  4788. if (!tep) continue; // Paranoia. HB
  4789. // If local_origin=false (i.e. it is from the server), we know the
  4790. // material has updated or been created, because extra params are
  4791. // checked for equality on unpacking. In that case, checking the
  4792. // material Id for inequality would not work, because the material Id
  4793. // has already been set.
  4794. bool material_changed = !local_origin || !paramsp ||
  4795. paramsp->getMaterial(te) != id;
  4796. if (update_server)
  4797. {
  4798. // Clear most overrides so the render material better matches the
  4799. // material Id (preserve transforms). If overrides become
  4800. // passthrough, set the overrides to NULL.
  4801. if (tep->setBaseMaterial())
  4802. {
  4803. material_changed = true;
  4804. LL_DEBUGS("GLTF") << "Material reset to base material on face: "
  4805. << U32(te) << LL_ENDL;
  4806. }
  4807. }
  4808. if (update_server || material_changed)
  4809. {
  4810. tep->setGLTFRenderMaterial(NULL);
  4811. LL_DEBUGS("GLTF") << "Render material NULLed out on face: "
  4812. << U32(te) << LL_ENDL;
  4813. }
  4814. if (matp != tep->getGLTFMaterial())
  4815. {
  4816. tep->setGLTFMaterial(matp, !update_server);
  4817. LL_DEBUGS("GLTF") << "New material set on face: " << U32(te)
  4818. << LL_ENDL;
  4819. }
  4820. if (material_changed && matp && tep->getGLTFMaterialOverride())
  4821. {
  4822. LL_DEBUGS("GLTF") << "Registering set override callback for face: "
  4823. << U32(te) << LL_ENDL;
  4824. // Sometimes, the material may change out from underneath the
  4825. // overrides. This is usually due to the server sending a new
  4826. // material Id, but the overrides have not changed due to being
  4827. // only texture transforms. Re-apply the overrides to the render
  4828. // material here, if present.
  4829. matp->onMaterialComplete([obj_id = mID, te]()
  4830. {
  4831. set_te_overide_mat(obj_id, te);
  4832. });
  4833. }
  4834. }
  4835. static LLCachedControl<U32> use_basecolor(gSavedSettings,
  4836. "RenderUseBasecolorAsDiffuse");
  4837. if (gUsePBRShaders || use_basecolor)
  4838. {
  4839. // Signal to render pipeline that render batches must be rebuilt for
  4840. // this object
  4841. if (matp)
  4842. {
  4843. LL_DEBUGS("GLTF") << "Registering rebuild material callback for object: "
  4844. << mID << LL_ENDL;
  4845. matp->onMaterialComplete([obj_id = mID]()
  4846. {
  4847. LLViewerObject* objp =
  4848. gObjectList.findObject(obj_id);
  4849. if (objp)
  4850. {
  4851. objp->rebuildMaterial();
  4852. }
  4853. });
  4854. }
  4855. else
  4856. {
  4857. LL_DEBUGS("GLTF") << "Asking for materials rebuild on object: "
  4858. << mID << LL_ENDL;
  4859. rebuildMaterial();
  4860. }
  4861. }
  4862. // Predictively update LLRenderMaterialParams (do not wait for server)
  4863. if (paramsp)
  4864. {
  4865. LL_DEBUGS("GLTF") << "Setting render materials on object: " << mID
  4866. << LL_ENDL;
  4867. // Update existing parameter block
  4868. for (U8 te = start_idx; te < end_idx; ++te)
  4869. {
  4870. paramsp->setMaterial(te, id);
  4871. }
  4872. }
  4873. if (update_server)
  4874. {
  4875. // Update via ModifyMaterialParams cap (server will echo back changes)
  4876. for (U8 te = start_idx; te < end_idx; ++te)
  4877. {
  4878. // This sends a cleared version of this object's current material
  4879. // override, but the override should already be cleared due to
  4880. // calling setBaseMaterial() above.
  4881. LLGLTFMaterialList::queueApply(this, te, id);
  4882. }
  4883. }
  4884. else
  4885. {
  4886. // Land impact may have changed
  4887. setObjectCostStale();
  4888. }
  4889. if (set_debug_tag)
  4890. {
  4891. HBFloaterDebugTags::setTag("GLTF", false);
  4892. }
  4893. }
  4894. void LLViewerObject::setRenderMaterialIDs(const LLRenderMaterialParams* paramsp,
  4895. bool local_origin)
  4896. {
  4897. if (local_origin)
  4898. {
  4899. return; // Nothing to do
  4900. }
  4901. if (paramsp)
  4902. {
  4903. for (U8 te = 0, count = getNumTEs(); te < count; ++te)
  4904. {
  4905. // We know material_params has updated or been created, because
  4906. // extra params are checked for equality on unpacking.
  4907. setRenderMaterialID(te, paramsp->getMaterial(te), false, false);
  4908. }
  4909. }
  4910. else
  4911. {
  4912. for (U8 te = 0, count = getNumTEs(); te < count; ++te)
  4913. {
  4914. setRenderMaterialID(te, LLUUID::null, false, false);
  4915. }
  4916. }
  4917. }
  4918. void LLViewerObject::rebuildMaterial()
  4919. {
  4920. faceMappingChanged();
  4921. if (mDrawable.notNull())
  4922. {
  4923. gPipeline.markTextured(mDrawable);
  4924. }
  4925. }
  4926. void LLViewerObject::shrinkWrap()
  4927. {
  4928. if (!mShouldShrinkWrap)
  4929. {
  4930. mShouldShrinkWrap = true;
  4931. if (mDrawable)
  4932. {
  4933. // We were not shrink-wrapped before but we are now, so update the
  4934. // spatial partition.
  4935. gPipeline.markPartitionMove(mDrawable);
  4936. }
  4937. }
  4938. }
  4939. void LLViewerObject::setTEImage(U8 te, LLViewerTexture* texp)
  4940. {
  4941. if (te != 255 && te < getNumTEs() && texp && mTEImages[te] != texp)
  4942. {
  4943. LLUUID old_image_id;
  4944. LLTextureEntry* tep = getTE(te);
  4945. if (tep)
  4946. {
  4947. old_image_id = tep->getID();
  4948. }
  4949. const LLUUID& image_id = texp->getID();
  4950. LLPrimitive::setTETexture(te, image_id);
  4951. LLViewerTexture* baked_texp = getBakedTextureForMagicId(image_id);
  4952. mTEImages[te] = baked_texp ? baked_texp : texp;
  4953. updateAvatarMeshVisibility(image_id, old_image_id);
  4954. setChanged(TEXTURE);
  4955. if (mDrawable.notNull())
  4956. {
  4957. gPipeline.markTextured(mDrawable);
  4958. }
  4959. }
  4960. }
  4961. S32 LLViewerObject::setTETextureCore(U8 te, LLViewerTexture* texp)
  4962. {
  4963. const LLTextureEntry* tep = getTE(te);
  4964. if (!tep || !texp) return 0;
  4965. const LLUUID& tex_id = texp->getID();
  4966. LLUUID old_tex_id = tep->getID();
  4967. if (tex_id.notNull() && old_tex_id == tex_id)
  4968. {
  4969. return 0;
  4970. }
  4971. S32 retval = LLPrimitive::setTETexture(te, tex_id);
  4972. LLViewerTexture* baked_texp = getBakedTextureForMagicId(tex_id);
  4973. mTEImages[te] = baked_texp ? baked_texp : texp;
  4974. updateAvatarMeshVisibility(tex_id, old_tex_id);
  4975. setChanged(TEXTURE);
  4976. if (mDrawable.notNull())
  4977. {
  4978. gPipeline.markTextured(mDrawable);
  4979. }
  4980. return retval;
  4981. }
  4982. S32 LLViewerObject::setTENormalMapCore(U8 te, LLViewerTexture* texp)
  4983. {
  4984. const LLTextureEntry* tep = getTE(te);
  4985. if (!tep) return 0;
  4986. const LLUUID& tex_id = texp ? texp->getID() : LLUUID::null;
  4987. if (tep->getID() != tex_id || tex_id.isNull())
  4988. {
  4989. LLMaterial* matp = tep->getMaterialParams();
  4990. if (matp)
  4991. {
  4992. LL_DEBUGS("Materials") << "te = "<< (S32)te
  4993. << ", setting normal map id = " << tex_id
  4994. << LL_ENDL;
  4995. matp->setNormalID(tex_id);
  4996. }
  4997. }
  4998. changeTENormalMap(te, texp);
  4999. return TEM_CHANGE_TEXTURE;
  5000. }
  5001. S32 LLViewerObject::setTESpecularMapCore(U8 te, LLViewerTexture* texp)
  5002. {
  5003. const LLTextureEntry* tep = getTE(te);
  5004. if (!tep) return 0;
  5005. const LLUUID& tex_id = texp ? texp->getID() : LLUUID::null;
  5006. if (tep->getID() != tex_id || tex_id.isNull())
  5007. {
  5008. LLMaterial* matp = tep->getMaterialParams();
  5009. if (matp)
  5010. {
  5011. LL_DEBUGS("Materials") << "te = "<< (S32)te
  5012. << ", setting specular map id = " << tex_id
  5013. << LL_ENDL;
  5014. matp->setSpecularID(tex_id);
  5015. }
  5016. }
  5017. changeTESpecularMap(te, texp);
  5018. return TEM_CHANGE_TEXTURE;
  5019. }
  5020. //virtual
  5021. void LLViewerObject::changeTEImage(S32 index, LLViewerTexture* texp)
  5022. {
  5023. if (index >= 0 && index < getNumTEs())
  5024. {
  5025. mTEImages[index] = texp;
  5026. }
  5027. if (mDebugUpdateMsg)
  5028. {
  5029. llinfos << "Changed texture for face " << index << " to texture "
  5030. << (texp ? texp->getID() : LLUUID::null)
  5031. << " on debugged object: " << mID << llendl;
  5032. }
  5033. }
  5034. //virtual
  5035. void LLViewerObject::changeTENormalMap(S32 index, LLViewerTexture* texp)
  5036. {
  5037. if (index >= 0 && index < getNumTEs())
  5038. {
  5039. mTENormalMaps[index] = texp;
  5040. refreshMaterials();
  5041. }
  5042. }
  5043. //virtual
  5044. void LLViewerObject::changeTESpecularMap(S32 index, LLViewerTexture* texp)
  5045. {
  5046. if (index >= 0 && index < getNumTEs())
  5047. {
  5048. mTESpecularMaps[index] = texp;
  5049. refreshMaterials();
  5050. }
  5051. }
  5052. //virtual
  5053. S32 LLViewerObject::setTETexture(U8 te, const LLUUID& tex_id)
  5054. {
  5055. // Invalid host == get from the agent's sim
  5056. LLViewerFetchedTexture* texp =
  5057. LLViewerTextureManager::getFetchedTexture(tex_id, FTT_DEFAULT, true,
  5058. LLGLTexture::BOOST_NONE,
  5059. LLViewerTexture::LOD_TEXTURE);
  5060. return setTETextureCore(te, texp);
  5061. }
  5062. //virtual
  5063. S32 LLViewerObject::setTENormalMap(U8 te, const LLUUID& tex_id)
  5064. {
  5065. LLViewerFetchedTexture* texp = NULL;
  5066. if (tex_id.notNull())
  5067. {
  5068. texp =
  5069. LLViewerTextureManager::getFetchedTexture(tex_id, FTT_DEFAULT,
  5070. true,
  5071. LLGLTexture::BOOST_ALM,
  5072. LLViewerTexture::LOD_TEXTURE);
  5073. }
  5074. return setTENormalMapCore(te, texp);
  5075. }
  5076. //virtual
  5077. S32 LLViewerObject::setTESpecularMap(U8 te, const LLUUID& tex_id)
  5078. {
  5079. LLViewerFetchedTexture* texp = NULL;
  5080. if (tex_id.notNull())
  5081. {
  5082. texp =
  5083. LLViewerTextureManager::getFetchedTexture(tex_id, FTT_DEFAULT,
  5084. true,
  5085. LLGLTexture::BOOST_ALM,
  5086. LLViewerTexture::LOD_TEXTURE);
  5087. }
  5088. return setTESpecularMapCore(te, texp);
  5089. }
  5090. //virtual
  5091. S32 LLViewerObject::setTEColor(U8 te, const LLColor3& color)
  5092. {
  5093. return setTEColor(te, LLColor4(color));
  5094. }
  5095. //virtual
  5096. S32 LLViewerObject::setTEColor(U8 te, const LLColor4& color)
  5097. {
  5098. S32 retval = 0;
  5099. const LLTextureEntry* tep = getTE(te);
  5100. if (!tep)
  5101. {
  5102. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5103. << llendl;
  5104. }
  5105. else if (color != tep->getColor())
  5106. {
  5107. retval = LLPrimitive::setTEColor(te, color);
  5108. if (mDrawable.notNull() && retval)
  5109. {
  5110. // These should only happen on updates which are not the initial
  5111. // update.
  5112. dirtyMesh();
  5113. }
  5114. }
  5115. return retval;
  5116. }
  5117. //virtual
  5118. S32 LLViewerObject::setTEBumpmap(U8 te, U8 bump)
  5119. {
  5120. S32 retval = 0;
  5121. const LLTextureEntry* tep = getTE(te);
  5122. if (!tep)
  5123. {
  5124. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5125. << llendl;
  5126. }
  5127. else if (bump != tep->getBumpmap())
  5128. {
  5129. retval = LLPrimitive::setTEBumpmap(te, bump);
  5130. setChanged(TEXTURE);
  5131. if (mDrawable.notNull() && retval)
  5132. {
  5133. gPipeline.markTextured(mDrawable);
  5134. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
  5135. }
  5136. }
  5137. return retval;
  5138. }
  5139. //virtual
  5140. S32 LLViewerObject::setTETexGen(U8 te, U8 texgen)
  5141. {
  5142. S32 retval = 0;
  5143. const LLTextureEntry* tep = getTE(te);
  5144. if (!tep)
  5145. {
  5146. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5147. << llendl;
  5148. }
  5149. else if (texgen != tep->getTexGen())
  5150. {
  5151. retval = LLPrimitive::setTETexGen(te, texgen);
  5152. setChanged(TEXTURE);
  5153. }
  5154. return retval;
  5155. }
  5156. //virtual
  5157. S32 LLViewerObject::setTEMediaTexGen(U8 te, U8 media)
  5158. {
  5159. S32 retval = 0;
  5160. const LLTextureEntry* tep = getTE(te);
  5161. if (!tep)
  5162. {
  5163. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5164. << llendl;
  5165. }
  5166. else if (media != tep->getMediaTexGen())
  5167. {
  5168. retval = LLPrimitive::setTEMediaTexGen(te, media);
  5169. setChanged(TEXTURE);
  5170. }
  5171. return retval;
  5172. }
  5173. //virtual
  5174. S32 LLViewerObject::setTEShiny(U8 te, U8 shiny)
  5175. {
  5176. S32 retval = 0;
  5177. const LLTextureEntry* tep = getTE(te);
  5178. if (!tep)
  5179. {
  5180. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5181. << llendl;
  5182. }
  5183. else if (shiny != tep->getShiny())
  5184. {
  5185. retval = LLPrimitive::setTEShiny(te, shiny);
  5186. setChanged(TEXTURE);
  5187. }
  5188. return retval;
  5189. }
  5190. //virtual
  5191. S32 LLViewerObject::setTEFullbright(U8 te, U8 fullbright)
  5192. {
  5193. S32 retval = 0;
  5194. const LLTextureEntry* tep = getTE(te);
  5195. if (!tep)
  5196. {
  5197. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5198. << llendl;
  5199. }
  5200. else if (fullbright != tep->getFullbright())
  5201. {
  5202. retval = LLPrimitive::setTEFullbright(te, fullbright);
  5203. setChanged(TEXTURE);
  5204. if (mDrawable.notNull() && retval)
  5205. {
  5206. gPipeline.markTextured(mDrawable);
  5207. }
  5208. }
  5209. return retval;
  5210. }
  5211. //virtual
  5212. S32 LLViewerObject::setTEMediaFlags(U8 te, U8 media_flags)
  5213. {
  5214. // this might need work for media type
  5215. S32 retval = 0;
  5216. const LLTextureEntry* tep = getTE(te);
  5217. if (!tep)
  5218. {
  5219. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5220. << llendl;
  5221. }
  5222. else if (media_flags != tep->getMediaFlags())
  5223. {
  5224. retval = LLPrimitive::setTEMediaFlags(te, media_flags);
  5225. setChanged(TEXTURE);
  5226. if (mDrawable.notNull() && retval)
  5227. {
  5228. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5229. gPipeline.markTextured(mDrawable);
  5230. // JC - probably only need this if changes texture coords
  5231. //gPipeline.markRebuild(mDrawable);
  5232. }
  5233. }
  5234. return retval;
  5235. }
  5236. //virtual
  5237. S32 LLViewerObject::setTEGlow(U8 te, F32 glow)
  5238. {
  5239. S32 retval = 0;
  5240. const LLTextureEntry* tep = getTE(te);
  5241. if (!tep)
  5242. {
  5243. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5244. << llendl;
  5245. }
  5246. else if (glow != tep->getGlow())
  5247. {
  5248. retval = LLPrimitive::setTEGlow(te, glow);
  5249. setChanged(TEXTURE);
  5250. if (mDrawable.notNull() && retval)
  5251. {
  5252. gPipeline.markTextured(mDrawable);
  5253. }
  5254. }
  5255. return retval;
  5256. }
  5257. //virtual
  5258. S32 LLViewerObject::setTEMaterialID(U8 te, const LLMaterialID& matidp)
  5259. {
  5260. const LLTextureEntry* tep = getTE(te);
  5261. if (!tep)
  5262. {
  5263. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5264. << ", material " << matidp << llendl;
  5265. return 0;
  5266. }
  5267. S32 retval = LLPrimitive::setTEMaterialID(te, matidp);
  5268. refreshMaterials();
  5269. LL_DEBUGS("Materials") << "Changed texture entry for te " << (S32)te
  5270. << " - object: " << mID << " - material: " << matidp
  5271. << " - retval = " << retval << LL_ENDL;
  5272. return retval;
  5273. }
  5274. //virtual
  5275. S32 LLViewerObject::setTEMaterialParams(U8 te, const LLMaterialPtr paramsp)
  5276. {
  5277. const LLTextureEntry* tep = getTE(te);
  5278. if (!tep)
  5279. {
  5280. llwarns << "No texture entry for te " << (S32)te << ", object " << mID
  5281. << llendl;
  5282. return 0;
  5283. }
  5284. S32 retval = LLPrimitive::setTEMaterialParams(te, paramsp);
  5285. setTENormalMap(te, paramsp ? paramsp->getNormalID() : LLUUID::null);
  5286. setTESpecularMap(te, paramsp ? paramsp->getSpecularID() : LLUUID::null);
  5287. refreshMaterials();
  5288. LL_DEBUGS("Materials") << "Changed material params for te: " << (S32)te
  5289. << " - object: " << mID << " - retval = " << retval
  5290. << LL_ENDL;
  5291. return retval;
  5292. }
  5293. //virtual
  5294. S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* matp)
  5295. {
  5296. LLTextureEntry* tep = getTE(te);
  5297. if (!tep)
  5298. {
  5299. llwarns << "No texture entry for te " << (S32)te << " of object "
  5300. << mID << llendl;
  5301. return TEM_CHANGE_NONE;
  5302. }
  5303. LLFetchedGLTFMaterial* srcp =
  5304. (LLFetchedGLTFMaterial*)tep->getGLTFMaterial();
  5305. // If an override mat exists, we must also have a source mat; it could
  5306. // however still be in flight (scrp == NULL) or being fetched.
  5307. if (!srcp)
  5308. {
  5309. if (mDebugUpdateMsg)
  5310. {
  5311. llinfos << "Material missing (still in flight ?) for face "
  5312. << (S32)te << " of object " << mID << llendl;
  5313. }
  5314. return TEM_CHANGE_NONE;
  5315. }
  5316. if (srcp->isFetching())
  5317. {
  5318. if (mDebugUpdateMsg)
  5319. {
  5320. llinfos << "Material still being fetched for face " << (S32)te
  5321. << " of object " << mID << llendl;
  5322. }
  5323. else
  5324. {
  5325. LL_DEBUGS("GLTF") << "Material still being fetched for face "
  5326. << (S32)te << " of object " << mID << LL_ENDL;
  5327. }
  5328. return TEM_CHANGE_NONE;
  5329. }
  5330. S32 retval = tep->setGLTFMaterialOverride(matp);
  5331. if (retval)
  5332. {
  5333. if (matp)
  5334. {
  5335. if (mDebugUpdateMsg)
  5336. {
  5337. llinfos << "Setting render material on face " << (S32)te
  5338. << " of object " << mID << llendl;
  5339. }
  5340. LLFetchedGLTFMaterial* rmatp = new LLFetchedGLTFMaterial(*srcp);
  5341. rmatp->applyOverride(*matp);
  5342. tep->setGLTFRenderMaterial(rmatp);
  5343. if (matp->hasLocalTextures())
  5344. {
  5345. for (LLGLTFMaterial::local_tex_map_t::const_iterator
  5346. it = matp->mTrackingIdToLocalTexture.begin(),
  5347. end = matp->mTrackingIdToLocalTexture.end();
  5348. it != end; ++it)
  5349. {
  5350. LLLocalBitmap::associateGLTFMaterial(it->first, matp);
  5351. }
  5352. }
  5353. return TEM_CHANGE_TEXTURE;
  5354. }
  5355. if (tep->setGLTFRenderMaterial(NULL))
  5356. {
  5357. if (mDebugUpdateMsg)
  5358. {
  5359. llinfos << "Material reset on face " << (S32)te
  5360. << " of object " << mID << llendl;
  5361. }
  5362. return TEM_CHANGE_TEXTURE;
  5363. }
  5364. }
  5365. return retval;
  5366. }
  5367. void LLViewerObject::refreshMaterials()
  5368. {
  5369. setChanged(TEXTURE);
  5370. if (mDrawable.notNull())
  5371. {
  5372. gPipeline.markTextured(mDrawable);
  5373. }
  5374. }
  5375. //virtual
  5376. S32 LLViewerObject::setTEScale(U8 te, F32 s, F32 t)
  5377. {
  5378. S32 retval = LLPrimitive::setTEScale(te, s, t);
  5379. setChanged(TEXTURE);
  5380. if (mDrawable.notNull() && retval)
  5381. {
  5382. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5383. }
  5384. return retval;
  5385. }
  5386. //virtual
  5387. S32 LLViewerObject::setTEScaleS(U8 te, F32 s)
  5388. {
  5389. S32 retval = LLPrimitive::setTEScaleS(te, s);
  5390. if (mDrawable.notNull() && retval)
  5391. {
  5392. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5393. }
  5394. return retval;
  5395. }
  5396. //virtual
  5397. S32 LLViewerObject::setTEScaleT(U8 te, F32 t)
  5398. {
  5399. S32 retval = LLPrimitive::setTEScaleT(te, t);
  5400. if (mDrawable.notNull() && retval)
  5401. {
  5402. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5403. }
  5404. return retval;
  5405. }
  5406. //virtual
  5407. S32 LLViewerObject::setTEOffset(U8 te, F32 s, F32 t)
  5408. {
  5409. S32 retval = LLPrimitive::setTEOffset(te, s, t);
  5410. if (mDrawable.notNull() && retval)
  5411. {
  5412. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5413. }
  5414. return retval;
  5415. }
  5416. //virtual
  5417. S32 LLViewerObject::setTEOffsetS(U8 te, F32 s)
  5418. {
  5419. S32 retval = LLPrimitive::setTEOffsetS(te, s);
  5420. if (mDrawable.notNull() && retval)
  5421. {
  5422. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5423. }
  5424. return retval;
  5425. }
  5426. //virtual
  5427. S32 LLViewerObject::setTEOffsetT(U8 te, F32 t)
  5428. {
  5429. S32 retval = LLPrimitive::setTEOffsetT(te, t);
  5430. if (mDrawable.notNull() && retval)
  5431. {
  5432. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5433. }
  5434. return retval;
  5435. }
  5436. //virtual
  5437. S32 LLViewerObject::setTERotation(U8 te, F32 r)
  5438. {
  5439. S32 retval = LLPrimitive::setTERotation(te, r);
  5440. if (retval && mDrawable.notNull())
  5441. {
  5442. gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
  5443. shrinkWrap();
  5444. }
  5445. return retval;
  5446. }
  5447. LLViewerTexture* LLViewerObject::getTEImage(U8 face) const
  5448. {
  5449. if (face < getNumTEs())
  5450. {
  5451. LLViewerTexture* texp = mTEImages[face];
  5452. if (texp)
  5453. {
  5454. return texp;
  5455. }
  5456. return LLViewerFetchedTexture::sDefaultImagep;
  5457. }
  5458. llwarns << "Requested image from invalid face: " << face << "/"
  5459. << getNumTEs() << llendl;
  5460. return NULL;
  5461. }
  5462. LLViewerTexture* LLViewerObject::getTENormalMap(U8 face) const
  5463. {
  5464. if (face < getNumTEs())
  5465. {
  5466. LLViewerTexture* texp = mTENormalMaps[face].get();
  5467. if (texp)
  5468. {
  5469. return texp;
  5470. }
  5471. return LLViewerFetchedTexture::sDefaultImagep;
  5472. }
  5473. llwarns << "Requested image from invalid face: " << face << " / "
  5474. << getNumTEs() << llendl;
  5475. return NULL;
  5476. }
  5477. LLViewerTexture* LLViewerObject::getTESpecularMap(U8 face) const
  5478. {
  5479. if (face < getNumTEs())
  5480. {
  5481. LLViewerTexture* texp = mTESpecularMaps[face];
  5482. if (texp)
  5483. {
  5484. return texp;
  5485. }
  5486. return LLViewerFetchedTexture::sDefaultImagep;
  5487. }
  5488. llwarns << "Requested image from invalid face: " << face << " / "
  5489. << getNumTEs() << llendl;
  5490. return NULL;
  5491. }
  5492. bool LLViewerObject::isImageAlphaBlended(U8 te) const
  5493. {
  5494. LLViewerTexture* texp = getTEImage(te);
  5495. if (!texp)
  5496. {
  5497. return false;
  5498. }
  5499. GLenum format = texp->getPrimaryFormat();
  5500. switch (format)
  5501. {
  5502. case GL_RGB:
  5503. break;
  5504. case GL_RGBA:
  5505. case GL_ALPHA:
  5506. return true;
  5507. default:
  5508. llwarns << "Unexpected tex format, returning no alpha." << llendl;
  5509. }
  5510. return false;
  5511. }
  5512. void LLViewerObject::fitFaceTexture(U8 face)
  5513. {
  5514. llwarns << "Not implemented !" << llendl;
  5515. llassert(false);
  5516. }
  5517. LLBBox LLViewerObject::getBoundingBoxAgent() const
  5518. {
  5519. LLViewerObject* root_edit = (LLViewerObject*)getRootEdit();
  5520. if (root_edit)
  5521. {
  5522. LLXform* root_parent = root_edit->getParent();
  5523. if (!root_parent || !root_parent->isAvatar())
  5524. {
  5525. root_edit = NULL;
  5526. }
  5527. }
  5528. LLVector3 position_agent;
  5529. LLQuaternion rot;
  5530. if (root_edit && root_edit->mDrawable.notNull() &&
  5531. root_edit->mDrawable->getXform() &&
  5532. root_edit->mDrawable->getXform()->getParent())
  5533. {
  5534. LLXform* parent_xform = root_edit->mDrawable->getXform()->getParent();
  5535. position_agent = (getPositionEdit() *
  5536. parent_xform->getWorldRotation()) +
  5537. parent_xform->getWorldPosition();
  5538. rot = getRotationEdit() * parent_xform->getWorldRotation();
  5539. }
  5540. else
  5541. {
  5542. position_agent = getPositionAgent();
  5543. rot = getRotationRegion();
  5544. }
  5545. return LLBBox(position_agent, rot, getScale() * -0.5f, getScale() * 0.5f);
  5546. }
  5547. U32 LLViewerObject::getNumVertices() const
  5548. {
  5549. U32 num_vertices = 0;
  5550. if (mDrawable.notNull())
  5551. {
  5552. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  5553. {
  5554. LLFace* facep = mDrawable->getFace(i);
  5555. if (facep)
  5556. {
  5557. num_vertices += facep->getGeomCount();
  5558. }
  5559. }
  5560. }
  5561. return num_vertices;
  5562. }
  5563. U32 LLViewerObject::getNumIndices() const
  5564. {
  5565. U32 num_indices = 0;
  5566. if (mDrawable.notNull())
  5567. {
  5568. for (S32 i = 0, count = mDrawable->getNumFaces(); i < count; ++i)
  5569. {
  5570. LLFace* facep = mDrawable->getFace(i);
  5571. if (facep)
  5572. {
  5573. num_indices += facep->getIndicesCount();
  5574. }
  5575. }
  5576. }
  5577. return num_indices;
  5578. }
  5579. // Find the number of instances of this object's inventory that are of the
  5580. // given type
  5581. S32 LLViewerObject::countInventoryContents(LLAssetType::EType type)
  5582. {
  5583. S32 count = 0;
  5584. if (mInventory)
  5585. {
  5586. for (LLInventoryObject::object_list_t::const_iterator
  5587. it = mInventory->begin(), end = mInventory->end();
  5588. it != end; ++it)
  5589. {
  5590. LLInventoryObject* obj = *it;
  5591. if (obj && obj->getType() == type)
  5592. {
  5593. ++count;
  5594. }
  5595. }
  5596. }
  5597. return count;
  5598. }
  5599. void LLViewerObject::setDebugText(const std::string& utf8text)
  5600. {
  5601. bool no_debug_text = utf8text.empty();
  5602. if (no_debug_text && mHudTextString.empty())
  5603. {
  5604. if (mText)
  5605. {
  5606. mText->markDead();
  5607. mText = NULL;
  5608. }
  5609. return;
  5610. }
  5611. if (!mText)
  5612. {
  5613. mText = (LLHUDText*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
  5614. mText->setFont(LLFontGL::getFontSansSerif());
  5615. mText->setVertAlignment(LLHUDText::ALIGN_VERT_TOP);
  5616. mText->setMaxLines(-1);
  5617. mText->setSourceObject(this);
  5618. mText->setOnHUDAttachment(isHUDAttachment());
  5619. }
  5620. mText->setColor(no_debug_text ? mHudTextColor : LLColor4::white);
  5621. mText->setStringUTF8(no_debug_text ? mHudTextString : utf8text);
  5622. mText->setZCompare(no_debug_text);
  5623. mText->setDoFade(no_debug_text);
  5624. updateText();
  5625. }
  5626. LLHUDIcon* LLViewerObject::setIcon(LLViewerTexture* texp, F32 scale)
  5627. {
  5628. if (!mIcon)
  5629. {
  5630. mIcon = (LLHUDIcon*)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_ICON);
  5631. mIcon->setSourceObject(this);
  5632. mIcon->setImage(texp);
  5633. mIcon->setScale(scale);
  5634. }
  5635. else
  5636. {
  5637. mIcon->restartLifeTimer();
  5638. }
  5639. return mIcon;
  5640. }
  5641. LLViewerObject* LLViewerObject::getSubParent()
  5642. {
  5643. return (LLViewerObject*)getParent();
  5644. }
  5645. const LLViewerObject* LLViewerObject::getSubParent() const
  5646. {
  5647. return (const LLViewerObject*)getParent();
  5648. }
  5649. void LLViewerObject::updateText()
  5650. {
  5651. if (!isDead() && mText.notNull())
  5652. {
  5653. LLVOAvatar* avatar = getAvatar();
  5654. if (avatar)
  5655. {
  5656. mText->setHidden(avatar->isVisuallyMuted());
  5657. }
  5658. LLVector3 up_offset(0, 0, 0);
  5659. up_offset.mV[2] = getScale().mV[VZ] * 0.6f;
  5660. if (mDrawable.notNull())
  5661. {
  5662. mText->setPositionAgent(getRenderPosition() + up_offset);
  5663. }
  5664. else
  5665. {
  5666. mText->setPositionAgent(getPositionAgent() + up_offset);
  5667. }
  5668. }
  5669. }
  5670. bool LLViewerObject::isParticleSource() const
  5671. {
  5672. return mPartSourcep.notNull() && !mPartSourcep->isDead();
  5673. }
  5674. void LLViewerObject::setParticleSource(const LLPartSysData& particle_params,
  5675. const LLUUID& owner_id)
  5676. {
  5677. if (mPartSourcep)
  5678. {
  5679. deleteParticleSource();
  5680. }
  5681. LLPointer<LLViewerPartSourceScript> pss =
  5682. LLViewerPartSourceScript::createPSS(this, particle_params);
  5683. mPartSourcep = pss;
  5684. if (mPartSourcep)
  5685. {
  5686. mPartSourcep->setOwnerUUID(owner_id);
  5687. if (mPartSourcep->getImage()->getID() !=
  5688. mPartSourcep->mPartSysData.mPartImageID)
  5689. {
  5690. const LLUUID& image_id = mPartSourcep->mPartSysData.mPartImageID;
  5691. LLViewerTexture* image = gImgPixieSmall;
  5692. if (image_id.notNull())
  5693. {
  5694. image = LLViewerTextureManager::getFetchedTexture(image_id);
  5695. }
  5696. mPartSourcep->setImage(image);
  5697. }
  5698. }
  5699. gViewerPartSim.addPartSource(pss);
  5700. }
  5701. void LLViewerObject::unpackParticleSource(S32 block_num,
  5702. const LLUUID& owner_id)
  5703. {
  5704. if (mPartSourcep.notNull() && mPartSourcep->isDead())
  5705. {
  5706. mPartSourcep = NULL;
  5707. }
  5708. if (mPartSourcep)
  5709. {
  5710. // If we have got one already, just update the existing source
  5711. if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep,
  5712. block_num))
  5713. {
  5714. mPartSourcep->setDead();
  5715. mPartSourcep = NULL;
  5716. return;
  5717. }
  5718. }
  5719. else
  5720. {
  5721. LLPointer<LLViewerPartSourceScript> pss =
  5722. LLViewerPartSourceScript::unpackPSS(this, NULL, block_num);
  5723. if (!pss || LLMuteList::isMuted(owner_id, LLMute::flagParticles))
  5724. {
  5725. // Do not create the system
  5726. return;
  5727. }
  5728. // We need to be able to deal with a particle source that has not
  5729. // changed, but still got an update !
  5730. LL_DEBUGS("Particles") << "Making particle system with owner "
  5731. << owner_id << " for object " << mID << LL_ENDL;
  5732. mPartSourcep = pss;
  5733. gViewerPartSim.addPartSource(pss);
  5734. }
  5735. if (mPartSourcep)
  5736. {
  5737. mPartSourcep->setOwnerUUID(owner_id);
  5738. const LLUUID& image_id = mPartSourcep->mPartSysData.mPartImageID;
  5739. if (mPartSourcep->getImage()->getID() != image_id)
  5740. {
  5741. LLViewerTexture* image = gImgPixieSmall;
  5742. if (image_id.notNull())
  5743. {
  5744. image = LLViewerTextureManager::getFetchedTexture(image_id);
  5745. }
  5746. mPartSourcep->setImage(image);
  5747. }
  5748. }
  5749. }
  5750. void LLViewerObject::unpackParticleSource(LLDataPacker& dp,
  5751. const LLUUID& owner_id, bool legacy)
  5752. {
  5753. if (mPartSourcep.notNull() && mPartSourcep->isDead())
  5754. {
  5755. mPartSourcep = NULL;
  5756. }
  5757. if (mPartSourcep)
  5758. {
  5759. // If we have got one already, just update the existing source
  5760. if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, dp,
  5761. legacy))
  5762. {
  5763. mPartSourcep->setDead();
  5764. mPartSourcep = NULL;
  5765. return;
  5766. }
  5767. }
  5768. else
  5769. {
  5770. LLPointer<LLViewerPartSourceScript> pss =
  5771. LLViewerPartSourceScript::unpackPSS(this, NULL, dp, legacy);
  5772. if (!pss || LLMuteList::isMuted(owner_id, LLMute::flagParticles))
  5773. {
  5774. // Do not create the system
  5775. return;
  5776. }
  5777. // We need to be able to deal with a particle source that has not
  5778. // changed, but still got an update !
  5779. LL_DEBUGS("Particles") << "Making particle system with owner "
  5780. << owner_id << " for object " << mID << LL_ENDL;
  5781. pss->setOwnerUUID(owner_id);
  5782. mPartSourcep = pss;
  5783. gViewerPartSim.addPartSource(pss);
  5784. }
  5785. if (mPartSourcep && mPartSourcep->getImage())
  5786. {
  5787. const LLUUID& image_id = mPartSourcep->mPartSysData.mPartImageID;
  5788. if (mPartSourcep->getImage()->getID() != image_id)
  5789. {
  5790. LLViewerTexture* image = gImgPixieSmall;
  5791. if (image_id.notNull())
  5792. {
  5793. image = LLViewerTextureManager::getFetchedTexture(image_id);
  5794. }
  5795. mPartSourcep->setImage(image);
  5796. }
  5797. }
  5798. }
  5799. void LLViewerObject::deleteParticleSource()
  5800. {
  5801. if (mPartSourcep.notNull())
  5802. {
  5803. mPartSourcep->setDead();
  5804. mPartSourcep = NULL;
  5805. }
  5806. }
  5807. // virtual
  5808. void LLViewerObject::updateDrawable(bool force_damped)
  5809. {
  5810. if (LL_UNLIKELY(isChanged(MOVED)) && mDrawable.notNull() &&
  5811. !mDrawable->isState(LLDrawable::ON_MOVE_LIST))
  5812. {
  5813. bool damped_motion =
  5814. // Not shifted between regions this frame and...
  5815. !isChanged(SHIFTED) &&
  5816. // ...forced into damped motion by application logic or...
  5817. (force_damped ||
  5818. // ...not selected and...
  5819. (!mUserSelected &&
  5820. // ... is root or ...
  5821. (mDrawable->isRoot() ||
  5822. // ... parent is not selected and ...
  5823. (getParent() &&
  5824. !((LLViewerObject*)getParent())->mUserSelected)) &&
  5825. // ...is a volume object and...
  5826. getPCode() == LL_PCODE_VOLUME &&
  5827. // ...is not moving physically and...
  5828. getVelocity().isExactlyZero() &&
  5829. // ...was not created this frame.
  5830. mDrawable->getGeneration() != -1));
  5831. gPipeline.markMoved(mDrawable, damped_motion);
  5832. }
  5833. clearChanged(SHIFTED);
  5834. }
  5835. // virtual, overridden by LLVOVolume
  5836. F32 LLViewerObject::getVObjRadius() const
  5837. {
  5838. return mDrawable.notNull() ? mDrawable->getRadius() : 0.f;
  5839. }
  5840. void LLViewerObject::setAttachedSound(const LLUUID& audio_uuid,
  5841. const LLUUID& owner_id, F32 gain,
  5842. U8 flags)
  5843. {
  5844. if (!gAudiop)
  5845. {
  5846. return;
  5847. }
  5848. if (audio_uuid.isNull())
  5849. {
  5850. if (!mAudioSourcep)
  5851. {
  5852. return;
  5853. }
  5854. if (mAudioSourcep->isLoop() && !mAudioSourcep->hasPendingPreloads())
  5855. {
  5856. // We do not clear the sound if it is a loop, it will go away on
  5857. // its own. At least, this appears to be how the scripts work. The
  5858. // attached sound ID is set to NULL to avoid it playing back when
  5859. // the object rezzes in on non-looping sounds.
  5860. LL_DEBUGS("AttachedSound") << "Clearing attached sound "
  5861. << mAudioSourcep->getCurrentData()->getID()
  5862. << LL_ENDL;
  5863. gAudiop->cleanupAudioSource(mAudioSourcep);
  5864. mAudioSourcep = NULL;
  5865. }
  5866. else if (flags & LL_SOUND_FLAG_STOP)
  5867. {
  5868. // Just shut off the sound
  5869. mAudioSourcep->stop();
  5870. }
  5871. return;
  5872. }
  5873. if ((flags & LL_SOUND_FLAG_LOOP) &&
  5874. mAudioSourcep && mAudioSourcep->isLoop() &&
  5875. mAudioSourcep->getCurrentData() &&
  5876. mAudioSourcep->getCurrentData()->getID() == audio_uuid)
  5877. {
  5878. LL_DEBUGS("AttachedSound") << "Already playing sound " << audio_uuid
  5879. << " on a loop, ignoring." << LL_ENDL;
  5880. return;
  5881. }
  5882. // Do not clean up before previous sound is done. Solves: SL-33486
  5883. if (mAudioSourcep && mAudioSourcep->isDone())
  5884. {
  5885. gAudiop->cleanupAudioSource(mAudioSourcep);
  5886. mAudioSourcep = NULL;
  5887. }
  5888. if (mAudioSourcep && mAudioSourcep->isMuted() &&
  5889. mAudioSourcep->getCurrentData() &&
  5890. mAudioSourcep->getCurrentData()->getID() == audio_uuid)
  5891. {
  5892. LL_DEBUGS("AttachedSound") << "Already having sound " << audio_uuid
  5893. << " as muted sound, ignoring." << LL_ENDL;
  5894. return;
  5895. }
  5896. getAudioSource(owner_id);
  5897. if (mAudioSourcep)
  5898. {
  5899. bool queue = flags & LL_SOUND_FLAG_QUEUE;
  5900. mAudioGain = gain;
  5901. mAudioSourcep->setGain(gain);
  5902. mAudioSourcep->setLoop(flags & LL_SOUND_FLAG_LOOP);
  5903. mAudioSourcep->setSyncMaster(flags & LL_SOUND_FLAG_SYNC_MASTER);
  5904. mAudioSourcep->setSyncSlave(flags & LL_SOUND_FLAG_SYNC_SLAVE);
  5905. mAudioSourcep->setQueueSounds(queue);
  5906. if (!queue)
  5907. {
  5908. // Stop any current sound first to avoid "farts of doom" (SL-1541)
  5909. // -MG
  5910. mAudioSourcep->stop();
  5911. }
  5912. // Play this sound if region maturity permits
  5913. if (gAgent.canAccessMaturityAtGlobal(getPositionGlobal()))
  5914. {
  5915. LL_DEBUGS("AttachedSound") << "Playing attached sound: "
  5916. << audio_uuid << LL_ENDL;
  5917. // Check cutoff radius in case this update was an object-update
  5918. // with a new value
  5919. mAudioSourcep->checkCutOffRadius();
  5920. mAudioSourcep->play(audio_uuid);
  5921. }
  5922. }
  5923. }
  5924. LLAudioSource* LLViewerObject::getAudioSource(const LLUUID& owner_id)
  5925. {
  5926. if (!mAudioSourcep)
  5927. {
  5928. // Arbitrary low gain for a sound that is not playing. This is used for
  5929. // sound preloads, for example.
  5930. mAudioSourcep = new LLAudioSourceVO(mID, owner_id, 0.01f, this);
  5931. if (gAudiop)
  5932. {
  5933. gAudiop->addAudioSource(mAudioSourcep);
  5934. }
  5935. }
  5936. return mAudioSourcep;
  5937. }
  5938. void LLViewerObject::adjustAudioGain(F32 gain)
  5939. {
  5940. if (gAudiop && mAudioSourcep)
  5941. {
  5942. mAudioGain = gain;
  5943. mAudioSourcep->setGain(mAudioGain);
  5944. }
  5945. }
  5946. bool LLViewerObject::unpackParameterEntry(U16 param_type, LLDataPacker* dp)
  5947. {
  5948. if (mDebugUpdateMsg)
  5949. {
  5950. llinfos << "Unpacking extra parameter entry type " << param_type
  5951. << " for object " << mID << llendl;
  5952. }
  5953. if (LLNetworkData::PARAMS_MESH == param_type)
  5954. {
  5955. param_type = LLNetworkData::PARAMS_SCULPT;
  5956. }
  5957. LLNetworkData* paramp = getExtraParameterEntryCreate(param_type);
  5958. if (!paramp)
  5959. {
  5960. return false;
  5961. }
  5962. paramp->unpack(*dp);
  5963. mExtraParameterInUse[LL_EPARAM_INDEX(param_type)] = true;
  5964. parameterChanged(param_type, paramp, true, false);
  5965. return true;
  5966. }
  5967. LLNetworkData* LLViewerObject::createNewParameterEntry(U16 param_type)
  5968. {
  5969. LLNetworkData* new_block = NULL;
  5970. switch (param_type)
  5971. {
  5972. case LLNetworkData::PARAMS_FLEXIBLE:
  5973. new_block = new LLFlexibleObjectData();
  5974. break;
  5975. case LLNetworkData::PARAMS_LIGHT:
  5976. new_block = new LLLightParams();
  5977. break;
  5978. case LLNetworkData::PARAMS_SCULPT:
  5979. new_block = new LLSculptParams();
  5980. break;
  5981. case LLNetworkData::PARAMS_LIGHT_IMAGE:
  5982. new_block = new LLLightImageParams();
  5983. break;
  5984. case LLNetworkData::PARAMS_EXTENDED_MESH:
  5985. new_block = new LLExtendedMeshParams();
  5986. break;
  5987. case LLNetworkData::PARAMS_RENDER_MATERIAL:
  5988. new_block = new LLRenderMaterialParams();
  5989. break;
  5990. case LLNetworkData::PARAMS_REFLECTION_PROBE:
  5991. new_block = new LLReflectionProbeParams();
  5992. break;
  5993. default:
  5994. llinfos << "Unknown param type #" << param_type << llendl;
  5995. }
  5996. if (!new_block) return NULL;
  5997. if (mDebugUpdateMsg)
  5998. {
  5999. llinfos << "Created extra parameter entry type " << param_type
  6000. << " for object " << mID << llendl;
  6001. }
  6002. S32 i = LL_EPARAM_INDEX(param_type);
  6003. mExtraParameters[i] = new_block;
  6004. mExtraParameterInUse[i] = false; // Not yet in use
  6005. return new_block;
  6006. }
  6007. LLNetworkData* LLViewerObject::getExtraParameterEntry(U16 param_type) const
  6008. {
  6009. S32 i = LL_EPARAM_INDEX(param_type);
  6010. return i >= 0 && i < LL_EPARAMS_COUNT ? mExtraParameters[i] : NULL;
  6011. }
  6012. LLNetworkData* LLViewerObject::getExtraParameterEntryCreate(U16 param_type)
  6013. {
  6014. LLNetworkData* paramp = getExtraParameterEntry(param_type);
  6015. if (!paramp)
  6016. {
  6017. paramp = createNewParameterEntry(param_type);
  6018. }
  6019. return paramp;
  6020. }
  6021. bool LLViewerObject::getParameterEntryInUse(U16 param_type) const
  6022. {
  6023. S32 i = LL_EPARAM_INDEX(param_type);
  6024. return i >= 0 && i < LL_EPARAMS_COUNT && mExtraParameterInUse[i];
  6025. }
  6026. LLFlexibleObjectData* LLViewerObject::getFlexibleObjectData() const
  6027. {
  6028. constexpr S32 index = LL_EPARAM_INDEX(LLNetworkData::PARAMS_FLEXIBLE);
  6029. if (mExtraParameterInUse[index])
  6030. {
  6031. return (LLFlexibleObjectData*)mExtraParameters[index];
  6032. }
  6033. return NULL;
  6034. }
  6035. LLLightParams* LLViewerObject::getLightParams() const
  6036. {
  6037. constexpr S32 index = LL_EPARAM_INDEX(LLNetworkData::PARAMS_LIGHT);
  6038. if (mExtraParameterInUse[index])
  6039. {
  6040. return (LLLightParams*)mExtraParameters[index];
  6041. }
  6042. return NULL;
  6043. }
  6044. LLSculptParams* LLViewerObject::getSculptParams() const
  6045. {
  6046. constexpr S32 index = LL_EPARAM_INDEX(LLNetworkData::PARAMS_SCULPT);
  6047. if (mExtraParameterInUse[index])
  6048. {
  6049. return (LLSculptParams*)mExtraParameters[index];
  6050. }
  6051. return NULL;
  6052. }
  6053. LLLightImageParams* LLViewerObject::getLightImageParams() const
  6054. {
  6055. constexpr S32 index = LL_EPARAM_INDEX(LLNetworkData::PARAMS_LIGHT_IMAGE);
  6056. if (mExtraParameterInUse[index])
  6057. {
  6058. return (LLLightImageParams*)mExtraParameters[index];
  6059. }
  6060. return NULL;
  6061. }
  6062. LLExtendedMeshParams* LLViewerObject::getExtendedMeshParams() const
  6063. {
  6064. constexpr S32 index = LL_EPARAM_INDEX(LLNetworkData::PARAMS_EXTENDED_MESH);
  6065. if (mExtraParameterInUse[index])
  6066. {
  6067. return (LLExtendedMeshParams*)mExtraParameters[index];
  6068. }
  6069. return NULL;
  6070. }
  6071. LLRenderMaterialParams* LLViewerObject::getMaterialRenderParams() const
  6072. {
  6073. constexpr S32 idx = LL_EPARAM_INDEX(LLNetworkData::PARAMS_RENDER_MATERIAL);
  6074. if (mExtraParameterInUse[idx])
  6075. {
  6076. return (LLRenderMaterialParams*)mExtraParameters[idx];
  6077. }
  6078. return NULL;
  6079. }
  6080. LLReflectionProbeParams* LLViewerObject::getReflectionProbeParams() const
  6081. {
  6082. constexpr S32 idx = LL_EPARAM_INDEX(LLNetworkData::PARAMS_REFLECTION_PROBE);
  6083. if (mExtraParameterInUse[idx])
  6084. {
  6085. return (LLReflectionProbeParams*)mExtraParameters[idx];
  6086. }
  6087. return NULL;
  6088. }
  6089. bool LLViewerObject::setParameterEntry(U16 param_type,
  6090. const LLNetworkData& new_value,
  6091. bool local_origin)
  6092. {
  6093. LLNetworkData* paramp = getExtraParameterEntryCreate(param_type);
  6094. if (!paramp)
  6095. {
  6096. return false;
  6097. }
  6098. bool& in_use = mExtraParameterInUse[LL_EPARAM_INDEX(param_type)];
  6099. if (in_use && new_value == *paramp)
  6100. {
  6101. return false;
  6102. }
  6103. in_use = true;
  6104. paramp->copy(new_value);
  6105. parameterChanged(param_type, paramp, true, local_origin);
  6106. return true;
  6107. }
  6108. // Assumed to be called locally. If in_use is true, will create a new extra
  6109. // parameter if none exists.
  6110. bool LLViewerObject::setParameterEntryInUse(U16 param_type, bool in_use,
  6111. bool local_origin)
  6112. {
  6113. LLNetworkData* paramp = getExtraParameterEntryCreate(param_type);
  6114. if (!paramp)
  6115. {
  6116. return false;
  6117. }
  6118. bool& is_in_use = mExtraParameterInUse[LL_EPARAM_INDEX(param_type)];
  6119. if (is_in_use != in_use)
  6120. {
  6121. is_in_use = in_use;
  6122. parameterChanged(param_type, paramp, in_use, local_origin);
  6123. return true;
  6124. }
  6125. return false;
  6126. }
  6127. //virtual
  6128. void LLViewerObject::parameterChanged(U16 param_type, bool local_origin)
  6129. {
  6130. LLNetworkData* paramp = getExtraParameterEntry(param_type);
  6131. if (paramp)
  6132. {
  6133. parameterChanged(param_type, paramp,
  6134. mExtraParameterInUse[LL_EPARAM_INDEX(param_type)],
  6135. local_origin);
  6136. }
  6137. }
  6138. //virtual
  6139. void LLViewerObject::parameterChanged(U16 param_type, LLNetworkData* data,
  6140. bool in_use, bool local_origin)
  6141. {
  6142. // Special treatment for render materials.
  6143. if (param_type == LLNetworkData::PARAMS_RENDER_MATERIAL)
  6144. {
  6145. if (local_origin)
  6146. {
  6147. // Do not send the render material Id in this way as it will get
  6148. // out-of-sync with other sent client data.
  6149. // See LLViewerObject::setRenderMaterialID() and LLGLTFMaterialList
  6150. llwarns << "Render materials shall not be updated on the server in this way."
  6151. << llendl;
  6152. }
  6153. else
  6154. {
  6155. const LLRenderMaterialParams* params =
  6156. in_use ? getMaterialRenderParams() : NULL;
  6157. setRenderMaterialIDs(params, false);
  6158. }
  6159. return;
  6160. }
  6161. if (!local_origin)
  6162. {
  6163. return;
  6164. }
  6165. LLViewerRegion* regionp = getRegion();
  6166. if (!regionp)
  6167. {
  6168. return;
  6169. }
  6170. // Change happened on the viewer. Send the change up
  6171. U8 tmp[MAX_OBJECT_PARAMS_SIZE];
  6172. LLDataPackerBinaryBuffer dpb(tmp, MAX_OBJECT_PARAMS_SIZE);
  6173. if (data->pack(dpb))
  6174. {
  6175. U32 datasize = (U32)dpb.getCurrentSize();
  6176. LLMessageSystem* msg = gMessageSystemp;
  6177. msg->newMessageFast(_PREHASH_ObjectExtraParams);
  6178. msg->nextBlockFast(_PREHASH_AgentData);
  6179. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6180. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6181. msg->nextBlockFast(_PREHASH_ObjectData);
  6182. msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID);
  6183. msg->addU16Fast(_PREHASH_ParamType, param_type);
  6184. msg->addBoolFast(_PREHASH_ParamInUse, in_use);
  6185. msg->addU32Fast(_PREHASH_ParamSize, datasize);
  6186. msg->addBinaryDataFast(_PREHASH_ParamData, tmp, datasize);
  6187. msg->sendReliable(regionp->getHost());
  6188. }
  6189. else
  6190. {
  6191. llwarns << "Failed to send object extra parameters: " << param_type
  6192. << llendl;
  6193. }
  6194. }
  6195. void LLViewerObject::setDrawableState(U32 state, bool recursive)
  6196. {
  6197. if (mDrawable)
  6198. {
  6199. mDrawable->setState(state);
  6200. }
  6201. if (recursive)
  6202. {
  6203. for (child_list_t::iterator iter = mChildList.begin(),
  6204. end = mChildList.end();
  6205. iter != end; ++iter)
  6206. {
  6207. LLViewerObject* child = *iter;
  6208. if (child) // Paranoia
  6209. {
  6210. child->setDrawableState(state, recursive);
  6211. }
  6212. }
  6213. }
  6214. }
  6215. void LLViewerObject::clearDrawableState(U32 state, bool recursive)
  6216. {
  6217. if (mDrawable)
  6218. {
  6219. mDrawable->clearState(state);
  6220. }
  6221. if (recursive)
  6222. {
  6223. for (child_list_t::iterator iter = mChildList.begin(),
  6224. end = mChildList.end();
  6225. iter != end; ++iter)
  6226. {
  6227. LLViewerObject* child = *iter;
  6228. if (child) // Paranoia
  6229. {
  6230. child->clearDrawableState(state, recursive);
  6231. }
  6232. }
  6233. }
  6234. }
  6235. bool LLViewerObject::isDrawableState(U32 state, bool recursive) const
  6236. {
  6237. bool matches = false;
  6238. if (mDrawable)
  6239. {
  6240. matches = mDrawable->isState(state);
  6241. }
  6242. if (recursive)
  6243. {
  6244. for (child_list_t::const_iterator iter = mChildList.begin();
  6245. (iter != mChildList.end()) && matches; ++iter)
  6246. {
  6247. LLViewerObject* child = *iter;
  6248. if (child) // Paranoia
  6249. {
  6250. matches &= child->isDrawableState(state, recursive);
  6251. }
  6252. }
  6253. }
  6254. return matches;
  6255. }
  6256. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6257. // RN: these functions assume a 2-level hierarchy
  6258. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  6259. // Owned by anyone ?
  6260. bool LLViewerObject::permAnyOwner() const
  6261. {
  6262. if (isRootEdit())
  6263. {
  6264. return flagObjectAnyOwner();
  6265. }
  6266. else
  6267. {
  6268. return ((LLViewerObject*)getParent())->permAnyOwner();
  6269. }
  6270. }
  6271. // Owned by this viewer ?
  6272. bool LLViewerObject::permYouOwner() const
  6273. {
  6274. if (isRootEdit())
  6275. {
  6276. return flagObjectYouOwner();
  6277. }
  6278. else
  6279. {
  6280. return ((LLViewerObject*)getParent())->permYouOwner();
  6281. }
  6282. }
  6283. // Owned by a group ?
  6284. bool LLViewerObject::permGroupOwner() const
  6285. {
  6286. if (isRootEdit())
  6287. {
  6288. return flagObjectGroupOwned();
  6289. }
  6290. else
  6291. {
  6292. return ((LLViewerObject*)getParent())->permGroupOwner();
  6293. }
  6294. }
  6295. // Can the owner edit ?
  6296. bool LLViewerObject::permOwnerModify() const
  6297. {
  6298. if (isRootEdit())
  6299. {
  6300. return flagObjectOwnerModify();
  6301. }
  6302. else
  6303. {
  6304. return ((LLViewerObject*)getParent())->permOwnerModify();
  6305. }
  6306. }
  6307. // Can edit ?
  6308. bool LLViewerObject::permModify() const
  6309. {
  6310. if (isRootEdit())
  6311. {
  6312. return flagObjectModify();
  6313. }
  6314. else
  6315. {
  6316. return ((LLViewerObject*)getParent())->permModify();
  6317. }
  6318. }
  6319. // Can copy ?
  6320. bool LLViewerObject::permCopy() const
  6321. {
  6322. if (isRootEdit())
  6323. {
  6324. return flagObjectCopy();
  6325. }
  6326. else
  6327. {
  6328. return ((LLViewerObject*)getParent())->permCopy();
  6329. }
  6330. }
  6331. // Can move ?
  6332. bool LLViewerObject::permMove() const
  6333. {
  6334. if (isRootEdit())
  6335. {
  6336. return flagObjectMove();
  6337. }
  6338. else
  6339. {
  6340. return ((LLViewerObject*)getParent())->permMove();
  6341. }
  6342. }
  6343. // Can be transferred ?
  6344. bool LLViewerObject::permTransfer() const
  6345. {
  6346. if (isRootEdit())
  6347. {
  6348. return flagObjectTransfer();
  6349. }
  6350. else
  6351. {
  6352. return ((LLViewerObject*)getParent())->permTransfer();
  6353. }
  6354. }
  6355. // Can only open objects that you own, or that someone has
  6356. // given you modify rights to. JC
  6357. bool LLViewerObject::allowOpen() const
  6358. {
  6359. return !flagInventoryEmpty() && (permYouOwner() || permModify());
  6360. }
  6361. LLViewerObject::LLInventoryCallbackInfo::~LLInventoryCallbackInfo()
  6362. {
  6363. if (mListener)
  6364. {
  6365. mListener->clearVOInventoryListener(mObject);
  6366. }
  6367. }
  6368. bool LLViewerObject::recursiveSetMaxLOD(bool lock)
  6369. {
  6370. LLViewerObject* rootp = getRootEdit();
  6371. if (!rootp || rootp->mDead)
  6372. {
  6373. return false;
  6374. }
  6375. bool result = false;
  6376. LLVOVolume* volp = rootp->asVolume();
  6377. if (volp)
  6378. {
  6379. volp->setMaxLOD(lock);
  6380. result = true;
  6381. }
  6382. for (child_list_t::iterator it = rootp->mChildList.begin(),
  6383. end = rootp->mChildList.end();
  6384. it != end; ++it)
  6385. {
  6386. LLViewerObject* childp = *it;
  6387. if (childp)
  6388. {
  6389. LLVOVolume* volp = childp->asVolume();
  6390. if (volp)
  6391. {
  6392. volp->setMaxLOD(lock);
  6393. result = true;
  6394. }
  6395. }
  6396. }
  6397. return result;
  6398. }
  6399. bool LLViewerObject::isLockedAtMaxLOD()
  6400. {
  6401. LLViewerObject* rootp = getRootEdit();
  6402. if (!rootp || rootp->mDead)
  6403. {
  6404. return false;
  6405. }
  6406. LLVOVolume* volp = rootp->asVolume();
  6407. if (volp && volp->getMaxLOD())
  6408. {
  6409. return true;
  6410. }
  6411. for (child_list_t::iterator it = rootp->mChildList.begin(),
  6412. end = rootp->mChildList.end();
  6413. it != end; ++it)
  6414. {
  6415. LLViewerObject* childp = *it;
  6416. if (childp)
  6417. {
  6418. LLVOVolume* volp = childp->asVolume();
  6419. if (volp && volp->getMaxLOD())
  6420. {
  6421. return true;
  6422. }
  6423. }
  6424. }
  6425. return false;
  6426. }
  6427. void LLViewerObject::updateVolume(const LLVolumeParams& volume_params)
  6428. {
  6429. if (setVolume(volume_params, 1)) // *FIX: magic number, ack !
  6430. {
  6431. // Transmit the update to the simulator
  6432. sendShapeUpdate();
  6433. markForUpdate();
  6434. }
  6435. }
  6436. void LLViewerObject::recursiveMarkForUpdate()
  6437. {
  6438. if (mDrawable.notNull())
  6439. {
  6440. for (child_list_t::iterator it = mChildList.begin(),
  6441. end = mChildList.end();
  6442. it != end; ++it)
  6443. {
  6444. LLViewerObject* child = *it;
  6445. if (child) // Paranoia
  6446. {
  6447. child->markForUpdate();
  6448. }
  6449. }
  6450. markForUpdate();
  6451. }
  6452. }
  6453. //virtual
  6454. void LLViewerObject::markForUpdate(bool rebuild_all)
  6455. {
  6456. if (mDrawable.notNull())
  6457. {
  6458. gPipeline.markTextured(mDrawable);
  6459. LLDrawable::EDrawableFlags flags = rebuild_all ?
  6460. // *HACK: used to force-refresh the visibility of objects when they
  6461. // are "missing" (this also should force an octree rebuild)... HB
  6462. LLDrawable::REBUILD_ALL :
  6463. LLDrawable::REBUILD_GEOMETRY;
  6464. gPipeline.markRebuild(mDrawable, flags);
  6465. }
  6466. }
  6467. bool LLViewerObject::isPermanentEnforced() const
  6468. {
  6469. return flagObjectPermanent() && mRegionp != gAgent.getRegion() &&
  6470. !gAgent.isGodlike();
  6471. }
  6472. bool LLViewerObject::getIncludeInSearch() const
  6473. {
  6474. return flagIncludeInSearch();
  6475. }
  6476. void LLViewerObject::setIncludeInSearch(bool include_in_search)
  6477. {
  6478. setFlags(FLAGS_INCLUDE_IN_SEARCH, include_in_search);
  6479. }
  6480. void LLViewerObject::setRegion(LLViewerRegion* regionp)
  6481. {
  6482. if (!regionp)
  6483. {
  6484. llwarns << "viewer object set region to NULL" << llendl;
  6485. }
  6486. if (regionp != mRegionp)
  6487. {
  6488. if (mRegionp)
  6489. {
  6490. mRegionp->removeFromCreatedList(getLocalID());
  6491. }
  6492. if (regionp)
  6493. {
  6494. regionp->addToCreatedList(getLocalID());
  6495. }
  6496. }
  6497. mLatestRecvPacketID = 0;
  6498. mRegionp = regionp;
  6499. for (child_list_t::iterator i = mChildList.begin(), end = mChildList.end();
  6500. i != end; ++i)
  6501. {
  6502. LLViewerObject* child = *i;
  6503. child->setRegion(regionp);
  6504. }
  6505. if (mPuppetAvatar)
  6506. {
  6507. mPuppetAvatar->setRegion(regionp);
  6508. }
  6509. setChanged(MOVED | SILHOUETTE);
  6510. updateDrawable(false);
  6511. }
  6512. bool LLViewerObject::specialHoverCursor() const
  6513. {
  6514. return mClickAction != 0 || flagUsePhysics() || flagHandleTouch();
  6515. }
  6516. void LLViewerObject::updateFlags(bool physics_changed)
  6517. {
  6518. LLViewerRegion* regionp = getRegion();
  6519. if (!regionp) return;
  6520. LLMessageSystem* msg = gMessageSystemp;
  6521. msg->newMessage(_PREHASH_ObjectFlagUpdate);
  6522. msg->nextBlockFast(_PREHASH_AgentData);
  6523. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6524. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6525. msg->addU32Fast(_PREHASH_ObjectLocalID, getLocalID());
  6526. msg->addBoolFast(_PREHASH_UsePhysics, flagUsePhysics());
  6527. msg->addBool(_PREHASH_IsTemporary, flagTemporaryOnRez());
  6528. msg->addBool(_PREHASH_IsPhantom, flagPhantom());
  6529. // Stinson 02/28/2012: this _PREHASH_CastsShadows bool is no longer used
  6530. // in either the viewer or the simulator. The simulator code does not even
  6531. // unpack this value when the message is received, but could be potentially
  6532. // hijacked in the future for another use should the urgent need arise.
  6533. msg->addBool(_PREHASH_CastsShadows, false);
  6534. if (physics_changed)
  6535. {
  6536. msg->nextBlock(_PREHASH_ExtraPhysics);
  6537. msg->addU8(_PREHASH_PhysicsShapeType, getPhysicsShapeType());
  6538. msg->addF32(_PREHASH_Density, getPhysicsDensity());
  6539. msg->addF32(_PREHASH_Friction, getPhysicsFriction());
  6540. msg->addF32(_PREHASH_Restitution, getPhysicsRestitution());
  6541. msg->addF32(_PREHASH_GravityMultiplier, getPhysicsGravity());
  6542. }
  6543. msg->sendReliable(regionp->getHost());
  6544. if (physics_changed)
  6545. {
  6546. setObjectCostStale();
  6547. }
  6548. }
  6549. bool LLViewerObject::setFlags(U32 flags, bool state)
  6550. {
  6551. bool setit = setFlagsWithoutUpdate(flags, state);
  6552. #if 0 // BUG: Sometimes viewer physics and simulator physics get out of sync.
  6553. // To fix this, always send update to simulator.
  6554. if (setit)
  6555. #endif
  6556. {
  6557. updateFlags();
  6558. }
  6559. return setit;
  6560. }
  6561. bool LLViewerObject::setFlagsWithoutUpdate(U32 flags, bool state)
  6562. {
  6563. bool setit = false;
  6564. if (state)
  6565. {
  6566. if ((mFlags & flags) != flags)
  6567. {
  6568. mFlags |= flags;
  6569. setit = true;
  6570. }
  6571. }
  6572. else if ((mFlags & flags) != 0)
  6573. {
  6574. mFlags &= ~flags;
  6575. setit = true;
  6576. }
  6577. return setit;
  6578. }
  6579. void LLViewerObject::setPhysicsShapeType(U8 type)
  6580. {
  6581. mPhysicsShapeUnknown = false;
  6582. if (type != mPhysicsShapeType)
  6583. {
  6584. mPhysicsShapeType = type;
  6585. setObjectCostStale();
  6586. }
  6587. }
  6588. void LLViewerObject::setPhysicsGravity(F32 gravity)
  6589. {
  6590. mPhysicsGravity = gravity;
  6591. }
  6592. void LLViewerObject::setPhysicsFriction(F32 friction)
  6593. {
  6594. mPhysicsFriction = friction;
  6595. }
  6596. void LLViewerObject::setPhysicsDensity(F32 density)
  6597. {
  6598. mPhysicsDensity = density;
  6599. }
  6600. void LLViewerObject::setPhysicsRestitution(F32 restitution)
  6601. {
  6602. mPhysicsRestitution = restitution;
  6603. }
  6604. U8 LLViewerObject::getPhysicsShapeType() const
  6605. {
  6606. if (mPhysicsShapeUnknown)
  6607. {
  6608. mPhysicsShapeUnknown = false;
  6609. gObjectList.updatePhysicsFlags(this);
  6610. }
  6611. return mPhysicsShapeType;
  6612. }
  6613. void LLViewerObject::applyAngularVelocity(F32 dt)
  6614. {
  6615. // Do target omega here
  6616. mRotTime += dt;
  6617. LLVector3 ang_vel = getAngularVelocity();
  6618. F32 omega = ang_vel.lengthSquared();
  6619. F32 angle = 0.f;
  6620. LLQuaternion dQ;
  6621. if (omega > 0.00001f)
  6622. {
  6623. omega = sqrtf(omega);
  6624. angle = omega * dt;
  6625. ang_vel /= omega;
  6626. // Calculate the delta increment based on the object's angular velocity
  6627. dQ.setAngleAxis(angle, ang_vel);
  6628. if (sUseNewTargetOmegaCode)
  6629. {
  6630. // Accumulate the angular velocity rotations to re-apply in the
  6631. // case of an object update
  6632. mAngularVelocityRot *= dQ;
  6633. }
  6634. // Just apply the delta increment to the current rotation
  6635. setRotation(getRotation() * dQ);
  6636. setChanged(MOVED | SILHOUETTE);
  6637. }
  6638. }
  6639. void LLViewerObject::resetRot()
  6640. {
  6641. mRotTime = 0.f;
  6642. if (sUseNewTargetOmegaCode)
  6643. {
  6644. // Reset the accumulated angular velocity rotation
  6645. mAngularVelocityRot.loadIdentity();
  6646. }
  6647. }
  6648. bool LLViewerObject::isAnySelected() const
  6649. {
  6650. if (mUserSelected)
  6651. {
  6652. return true;
  6653. }
  6654. for (child_list_t::const_iterator iter = mChildList.begin(),
  6655. end = mChildList.end();
  6656. iter != end; ++iter)
  6657. {
  6658. const LLViewerObject* child = *iter;
  6659. if (child && child->mUserSelected)
  6660. {
  6661. return true;
  6662. }
  6663. }
  6664. return false;
  6665. }
  6666. //virtual
  6667. void LLViewerObject::setSelected(bool sel)
  6668. {
  6669. mUserSelected = sel;
  6670. if (sUseNewTargetOmegaCode)
  6671. {
  6672. resetRot();
  6673. }
  6674. else
  6675. {
  6676. mRotTime = 0.f;
  6677. }
  6678. if (!sel)
  6679. {
  6680. setAllTESelected(false);
  6681. }
  6682. }
  6683. //virtual
  6684. U32 LLViewerObject::getPartitionType() const
  6685. {
  6686. return LLViewerRegion::PARTITION_NONE;
  6687. }
  6688. void LLViewerObject::dirtySpatialGroup() const
  6689. {
  6690. if (mDrawable)
  6691. {
  6692. LLSpatialGroup* groupp = mDrawable->getSpatialGroup();
  6693. if (groupp)
  6694. {
  6695. groupp->dirtyGeom();
  6696. gPipeline.markRebuild(groupp);
  6697. }
  6698. }
  6699. }
  6700. //virtual
  6701. void LLViewerObject::dirtyMesh()
  6702. {
  6703. if (mDrawable)
  6704. {
  6705. gPipeline.markRebuild(mDrawable);
  6706. #if 0
  6707. LLSpatialGroup* group = mDrawable->getSpatialGroup();
  6708. if (group)
  6709. {
  6710. group->dirtyMesh();
  6711. }
  6712. #endif
  6713. }
  6714. }
  6715. // virtual
  6716. void LLStaticViewerObject::updateDrawable(bool force_damped)
  6717. {
  6718. // Force an immediate rebuild on any update
  6719. if (mDrawable.notNull())
  6720. {
  6721. mDrawable->updateXform(true);
  6722. gPipeline.markRebuild(mDrawable);
  6723. }
  6724. clearChanged(SHIFTED);
  6725. }
  6726. void LLViewerObject::saveUnselectedChildrenPosition(std::vector<LLVector3>& positions)
  6727. {
  6728. if (mChildList.empty() || !positions.empty())
  6729. {
  6730. return;
  6731. }
  6732. for (child_list_t::const_iterator iter = mChildList.begin(),
  6733. end = mChildList.end();
  6734. iter != end; ++iter)
  6735. {
  6736. LLViewerObject* childp = *iter;
  6737. if (childp && !childp->mUserSelected && childp->mDrawable.notNull())
  6738. {
  6739. positions.emplace_back(childp->getPositionEdit());
  6740. }
  6741. }
  6742. }
  6743. void LLViewerObject::saveUnselectedChildrenRotation(std::vector<LLQuaternion>& rotations)
  6744. {
  6745. if (mChildList.empty())
  6746. {
  6747. return;
  6748. }
  6749. for (child_list_t::const_iterator iter = mChildList.begin(),
  6750. end = mChildList.end();
  6751. iter != end; ++iter)
  6752. {
  6753. LLViewerObject* childp = *iter;
  6754. if (childp && !childp->mUserSelected && childp->mDrawable.notNull())
  6755. {
  6756. rotations.emplace_back(childp->getRotationEdit());
  6757. }
  6758. }
  6759. }
  6760. // counter-rotation
  6761. void LLViewerObject::resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations,
  6762. const std::vector<LLVector3>& positions)
  6763. {
  6764. if (mChildList.empty())
  6765. {
  6766. return;
  6767. }
  6768. S32 index = 0;
  6769. LLQuaternion inv_rotation = ~getRotationEdit();
  6770. LLVector3 offset = getPositionEdit();
  6771. for (child_list_t::const_iterator iter = mChildList.begin(),
  6772. end = mChildList.end();
  6773. iter != end; ++iter)
  6774. {
  6775. LLViewerObject* childp = *iter;
  6776. if (childp && !childp->mUserSelected && childp->mDrawable.notNull())
  6777. {
  6778. if (childp->isAvatar())
  6779. {
  6780. LLVector3 reset_pos = (positions[index] - offset) *
  6781. inv_rotation;
  6782. LLQuaternion reset_rot = rotations[index] * inv_rotation;
  6783. LLVOAvatar* av = (LLVOAvatar*)childp;
  6784. av->mDrawable->mXform.setPosition(reset_pos);
  6785. av->mDrawable->mXform.setRotation(reset_rot);
  6786. av->mDrawable->getVObj()->setPositionLocal(reset_pos, true);
  6787. av->mDrawable->getVObj()->setRotation(reset_rot, true);
  6788. LLManip::rebuild(childp);
  6789. }
  6790. else // Not an avatar
  6791. {
  6792. childp->setRotation(rotations[index] * inv_rotation);
  6793. childp->setPositionLocal((positions[index] - offset) *
  6794. inv_rotation);
  6795. LLManip::rebuild(childp);
  6796. }
  6797. ++index;
  6798. }
  6799. }
  6800. }
  6801. // counter-translation
  6802. void LLViewerObject::resetChildrenPosition(const LLVector3& offset,
  6803. bool simplified,
  6804. bool skip_avatar_child)
  6805. {
  6806. if (mChildList.empty())
  6807. {
  6808. return;
  6809. }
  6810. LLVector3 child_offset;
  6811. if (simplified) //translation only, rotation matrix does not change
  6812. {
  6813. child_offset = offset * ~getRotation();
  6814. }
  6815. else // Rotation matrix might change too.
  6816. {
  6817. if (isAttachment() && mDrawable.notNull())
  6818. {
  6819. LLXform* attachment_point_xform = mDrawable->getXform()->getParent();
  6820. LLQuaternion parent_rotation = getRotation() * attachment_point_xform->getWorldRotation();
  6821. child_offset = offset * ~parent_rotation;
  6822. }
  6823. else
  6824. {
  6825. child_offset = offset * ~getRenderRotation();
  6826. }
  6827. }
  6828. for (child_list_t::const_iterator iter = mChildList.begin(),
  6829. end = mChildList.end();
  6830. iter != end; ++iter)
  6831. {
  6832. LLViewerObject* childp = *iter;
  6833. if (childp && !childp->mUserSelected && childp->mDrawable.notNull())
  6834. {
  6835. if (!childp->isAvatar())
  6836. {
  6837. childp->setPositionLocal(childp->getPosition() + child_offset);
  6838. LLManip::rebuild(childp);
  6839. }
  6840. else if (!skip_avatar_child)
  6841. {
  6842. LLVOAvatar* av = (LLVOAvatar*)childp;
  6843. LLVector3 reset_pos = child_offset +
  6844. av->mDrawable->mXform.getPosition();
  6845. av->mDrawable->mXform.setPosition(reset_pos);
  6846. av->mDrawable->getVObj()->setPositionLocal(reset_pos);
  6847. LLManip::rebuild(childp);
  6848. }
  6849. }
  6850. }
  6851. }
  6852. //static
  6853. void LLViewerObject::setUpdateInterpolationTimes(F32 interpolate_time,
  6854. F32 phase_out_time,
  6855. F32 region_interp_time)
  6856. {
  6857. if (interpolate_time < 0.f || phase_out_time < 0.f ||
  6858. phase_out_time > interpolate_time || region_interp_time < 0.5f ||
  6859. region_interp_time > 5.f)
  6860. {
  6861. llwarns << "Invalid values for interpolation or phase out times, resetting to defaults"
  6862. << llendl;
  6863. interpolate_time = 3.f;
  6864. phase_out_time = 1.f;
  6865. region_interp_time = 1.f;
  6866. }
  6867. sMaxUpdateInterpolationTime = (F64)interpolate_time;
  6868. sPhaseOutUpdateInterpolationTime = (F64)phase_out_time;
  6869. sMaxRegionCrossingInterpolationTime = (F64)region_interp_time;
  6870. }
  6871. const LLUUID& LLViewerObject::extractAttachmentItemID()
  6872. {
  6873. LLUUID item_id;
  6874. LLNameValue* item_id_nv = getNVPair("AttachItemID");
  6875. if (item_id_nv)
  6876. {
  6877. const char* s = item_id_nv->getString();
  6878. if (s)
  6879. {
  6880. item_id.set(s);
  6881. }
  6882. }
  6883. setAttachmentItemID(item_id);
  6884. return getAttachmentItemID();
  6885. }
  6886. const std::string& LLViewerObject::getAttachmentItemName()
  6887. {
  6888. if (isAttachment())
  6889. {
  6890. LLInventoryItem* item = gInventory.getItem(getAttachmentItemID());
  6891. if (item)
  6892. {
  6893. return item->getName();
  6894. }
  6895. }
  6896. return LLStringUtil::null;
  6897. }
  6898. //virtual
  6899. LLVOAvatar* LLViewerObject::getAvatar() const
  6900. {
  6901. LLVOAvatar* avatarp = (LLVOAvatar*)getPuppetAvatar();
  6902. if (!avatarp && isAttachment())
  6903. {
  6904. LLViewerObject* vobj = (LLViewerObject*)getParent();
  6905. while (vobj && !vobj->asAvatar())
  6906. {
  6907. vobj = (LLViewerObject*)vobj->getParent();
  6908. }
  6909. avatarp = (LLVOAvatar*)vobj;
  6910. }
  6911. return avatarp;
  6912. }
  6913. // If this object is directly or indirectly parented by an avatar, return it.
  6914. // Normally getAvatar() is the correct function to call and it will give the
  6915. // avatar used for skinning. The exception is with animated objects that are
  6916. // also attachments; in that case, getAvatar() will return the puppet avatar,
  6917. // used for skinning, and getAvatarAncestor() will return the avatar to which
  6918. // the object is attached.
  6919. LLVOAvatar* LLViewerObject::getAvatarAncestor()
  6920. {
  6921. LLViewerObject* vobj = (LLViewerObject*)getParent();
  6922. while (vobj)
  6923. {
  6924. LLVOAvatar* avatarp = vobj->asAvatar();
  6925. if (avatarp)
  6926. {
  6927. return avatarp;
  6928. }
  6929. vobj = (LLViewerObject*)vobj->getParent();
  6930. }
  6931. return NULL;
  6932. }
  6933. bool LLViewerObject::isHiglightedOrBeacon() const
  6934. {
  6935. static LLCachedControl<bool> beacons_always_on(gSavedSettings,
  6936. "BeaconAlwaysOn");
  6937. if (!beacons_always_on && !LLPipeline::sRenderBeaconsFloaterOpen)
  6938. {
  6939. return false;
  6940. }
  6941. if (!LLPipeline::sRenderHighlight || !LLPipeline::highlightable(this))
  6942. {
  6943. return false;
  6944. }
  6945. bool is_scripted = flagScripted();
  6946. return (is_scripted && LLPipeline::sRenderScriptedBeacons) ||
  6947. (is_scripted && flagHandleTouch() &&
  6948. LLPipeline::sRenderScriptedTouchBeacons) ||
  6949. (isAudioSource() && LLPipeline::sRenderSoundBeacons) ||
  6950. (getMediaType() != MEDIA_NONE && LLPipeline::sRenderMOAPBeacons) ||
  6951. (isParticleSource() && LLPipeline::sRenderParticleBeacons) ||
  6952. (flagUsePhysics() && LLPipeline::sRenderPhysicalBeacons);
  6953. }
  6954. class ObjectPhysicsProperties final : public LLHTTPNode
  6955. {
  6956. public:
  6957. void post(LLHTTPNode::ResponsePtr responder, const LLSD& context,
  6958. const LLSD& input) const override
  6959. {
  6960. LLSD object_data = input["body"]["ObjectData"];
  6961. S32 num_entries = object_data.size();
  6962. for (S32 i = 0; i < num_entries; ++i)
  6963. {
  6964. LLSD& curr_object_data = object_data[i];
  6965. U32 local_id = curr_object_data["LocalID"].asInteger();
  6966. // Iterate through nodes at end, since it can be on both the
  6967. // regular AND hover list
  6968. struct f : public LLSelectedNodeFunctor
  6969. {
  6970. LL_INLINE f(const U32& id)
  6971. : mID(id)
  6972. {
  6973. }
  6974. bool LL_INLINE apply(LLSelectNode* node) override
  6975. {
  6976. return node->getObject() &&
  6977. node->getObject()->mLocalID == mID;
  6978. }
  6979. U32 mID;
  6980. } fn(local_id);
  6981. LLSelectNode* nodep = gSelectMgr.getSelection()->getFirstNode(&fn);
  6982. if (!nodep)
  6983. {
  6984. continue;
  6985. }
  6986. LLViewerObject* objp = nodep->getObject();
  6987. if (!objp || objp->isDead())
  6988. {
  6989. continue;
  6990. }
  6991. // The LLSD message builder does not know how to handle U8, so we
  6992. // need to send as S8 and cast.
  6993. U8 type = (U8)curr_object_data["PhysicsShapeType"].asInteger();
  6994. F32 density = (F32)curr_object_data["Density"].asReal();
  6995. F32 friction = (F32)curr_object_data["Friction"].asReal();
  6996. F32 restitution = (F32)curr_object_data["Restitution"].asReal();
  6997. F32 gravity = (F32)curr_object_data["GravityMultiplier"].asReal();
  6998. objp->setPhysicsShapeType(type);
  6999. objp->setPhysicsGravity(gravity);
  7000. objp->setPhysicsFriction(friction);
  7001. objp->setPhysicsDensity(density);
  7002. objp->setPhysicsRestitution(restitution);
  7003. }
  7004. dialog_refresh_all();
  7005. }
  7006. };
  7007. LLHTTPRegistration<ObjectPhysicsProperties>
  7008. gHTTPRegistrationObjectPhysicsProperties("/message/ObjectPhysicsProperties");