llselectmgr.cpp 209 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584
  1. /**
  2. * @file llselectmgr.cpp
  3. * @brief A manager for selected objects and faces.
  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 "llselectmgr.h"
  34. #include "llcachename.h"
  35. #include "lldbstrings.h"
  36. #include "lleconomy.h"
  37. #include "llgl.h"
  38. #include "llmediaentry.h"
  39. #include "llmenugl.h"
  40. #include "llparcel.h"
  41. #include "llpermissions.h"
  42. #include "llpermissionsflags.h"
  43. #include "llrender.h"
  44. #include "lltrans.h"
  45. #include "llundo.h"
  46. #include "llvolume.h"
  47. #include "llmessage.h"
  48. #include "object_flags.h"
  49. #include "llagent.h"
  50. #include "lldrawable.h"
  51. #include "llfloaterinspect.h"
  52. #include "llfloaterproperties.h"
  53. #include "llfloaterreporter.h"
  54. #include "llfloatertools.h"
  55. #include "llgltfmateriallist.h"
  56. #include "llgridmanager.h" // For gIsInSecondLife
  57. #include "llhudeffectspiral.h"
  58. #include "llinventorymodel.h"
  59. #include "llmaterialmgr.h"
  60. #include "llmeshrepository.h"
  61. #include "llmutelist.h"
  62. #include "llpanelface.h"
  63. #include "llpipeline.h"
  64. //MK
  65. #include "mkrlinterface.h"
  66. //mk
  67. #include "llstatusbar.h"
  68. #include "llsurface.h"
  69. #include "lltool.h"
  70. #include "lltooldraganddrop.h"
  71. #include "lltoolmgr.h"
  72. #include "lltoolpie.h"
  73. #include "llviewercamera.h"
  74. #include "llviewercontrol.h"
  75. #include "llviewermedia.h"
  76. #include "llviewermediafocus.h"
  77. #include "llviewermenu.h"
  78. #include "llviewerobjectlist.h"
  79. #include "llviewerparcelmgr.h"
  80. #include "llviewerregion.h"
  81. #include "llviewershadermgr.h"
  82. #include "llviewerstats.h"
  83. #include "llviewertexturelist.h"
  84. #include "llviewerwindow.h"
  85. #include "llvoavatarpuppet.h"
  86. #include "llvoavatarself.h"
  87. #include "llvograss.h"
  88. #include "llvotree.h"
  89. #include "llvovolume.h"
  90. LLSelectMgr gSelectMgr;
  91. // For linked sets
  92. constexpr S32 MAX_CHILDREN_PER_TASK = 255;
  93. constexpr F32 SILHOUETTE_UPDATE_THRESHOLD_SQUARED = 0.02f;
  94. constexpr S32 MAX_SILS_PER_FRAME = 50;
  95. constexpr S32 MAX_OBJECTS_PER_PACKET = 254;
  96. bool LLSelectMgr::sRectSelectInclusive = true;
  97. bool LLSelectMgr::sRenderLightRadius = false;
  98. F32 LLSelectMgr::sHighlightThickness = 0.f;
  99. F32 LLSelectMgr::sHighlightUScale = 0.f;
  100. F32 LLSelectMgr::sHighlightVScale = 0.f;
  101. F32 LLSelectMgr::sHighlightAlpha = 0.f;
  102. F32 LLSelectMgr::sHighlightAlphaTest = 0.f;
  103. F32 LLSelectMgr::sHighlightUAnim = 0.f;
  104. F32 LLSelectMgr::sHighlightVAnim = 0.f;
  105. LLColor4 LLSelectMgr::sSilhouetteParentColor;
  106. LLColor4 LLSelectMgr::sSilhouetteChildColor;
  107. LLColor4 LLSelectMgr::sHighlightInspectColor;
  108. LLColor4 LLSelectMgr::sHighlightParentColor;
  109. LLColor4 LLSelectMgr::sHighlightChildColor;
  110. LLColor4 LLSelectMgr::sContextSilhouetteColor;
  111. uuid_list_t LLSelectMgr::sObjectPropertiesFamilyRequests;
  112. // Used to keep track of important derez info.
  113. struct LLDeRezInfo
  114. {
  115. EDeRezDestination mDestination;
  116. LLUUID mDestinationID;
  117. LLDeRezInfo(EDeRezDestination dest, const LLUUID& dest_id)
  118. : mDestination(dest),
  119. mDestinationID(dest_id)
  120. {
  121. }
  122. };
  123. // Helper function
  124. LLViewerObject* getSelectedParentObject(LLViewerObject* object)
  125. {
  126. LLViewerObject* parent;
  127. while (object && (parent = (LLViewerObject*)object->getParent()))
  128. {
  129. if (parent->isSelected())
  130. {
  131. object = parent;
  132. }
  133. else
  134. {
  135. break;
  136. }
  137. }
  138. return object;
  139. }
  140. //-----------------------------------------------------------------------------
  141. // LLSelectMgr class
  142. //-----------------------------------------------------------------------------
  143. LLSelectMgr::LLSelectMgr()
  144. : mHideSelectedObjects(false),
  145. mRenderSelectionsPolicy(2),
  146. mAllowSelectAvatar(false),
  147. mDebugSelectMgr(false),
  148. mEditLinkedParts(false),
  149. mSelectOwnedOnly(false),
  150. mSelectMovableOnly(false),
  151. mForceSelection(false),
  152. mShowSelection(false),
  153. mTEMode(false),
  154. mRenderSilhouettes(true),
  155. mGridMode(GRID_MODE_WORLD),
  156. mTextureChannel(LLRender::DIFFUSE_MAP)
  157. {
  158. mSelectedObjects = new LLObjectSelection();
  159. mHoverObjects = new LLObjectSelection();
  160. mHighlightedObjects = new LLObjectSelection();
  161. }
  162. LLSelectMgr::~LLSelectMgr()
  163. {
  164. clearSelections();
  165. }
  166. void LLSelectMgr::clearSelections()
  167. {
  168. mHoverObjects->deleteAllNodes();
  169. mSelectedObjects->deleteAllNodes();
  170. mHighlightedObjects->deleteAllNodes();
  171. mRectSelectedObjects.clear();
  172. mGridObjects.deleteAllNodes();
  173. LLPipeline::setRenderHighlightTextureChannel(LLRender::DIFFUSE_MAP);
  174. }
  175. void LLSelectMgr::initClass()
  176. {
  177. connectRefreshCachedSettingsSafe("HideSelectedObjects");
  178. connectRefreshCachedSettingsSafe("RenderHighlightSelectionsPolicy");
  179. connectRefreshCachedSettingsSafe("AllowSelectAvatar");
  180. connectRefreshCachedSettingsSafe("DebugSelectMgr");
  181. connectRefreshCachedSettingsSafe("EditLinkedParts");
  182. connectRefreshCachedSettingsSafe("SelectOwnedOnly");
  183. connectRefreshCachedSettingsSafe("SelectMovableOnly");
  184. connectRefreshCachedSettingsSafe("RectangleSelectInclusive");
  185. connectRefreshCachedSettingsSafe("RenderLightRadius");
  186. connectRefreshCachedSettingsSafe("SelectionHighlightThickness");
  187. connectRefreshCachedSettingsSafe("SelectionHighlightUScale");
  188. connectRefreshCachedSettingsSafe("SelectionHighlightVScale");
  189. connectRefreshCachedSettingsSafe("SelectionHighlightAlpha");
  190. connectRefreshCachedSettingsSafe("SelectionHighlightAlphaTest");
  191. connectRefreshCachedSettingsSafe("SelectionHighlightUAnim");
  192. connectRefreshCachedSettingsSafe("SelectionHighlightVAnim");
  193. connectRefreshCachedSettingsSafe("SilhouetteParentColor");
  194. connectRefreshCachedSettingsSafe("SilhouetteChildColor");
  195. connectRefreshCachedSettingsSafe("HighlightParentColor");
  196. connectRefreshCachedSettingsSafe("HighlightChildColor");
  197. connectRefreshCachedSettingsSafe("HighlightInspectColor");
  198. connectRefreshCachedSettingsSafe("ContextSilhouetteColor");
  199. setGridMode(GRID_MODE_WORLD);
  200. refreshCachedSettings();
  201. llinfos << "Selection manager initialized" << llendl;
  202. }
  203. //static
  204. void LLSelectMgr::connectRefreshCachedSettingsSafe(const char* name)
  205. {
  206. LLControlVariable* controlp = gSavedSettings.getControl(name);
  207. if (!controlp)
  208. {
  209. controlp = gColors.getControl(name);
  210. }
  211. if (!controlp)
  212. {
  213. llwarns << "Setting name not found: " << name << llendl;
  214. return;
  215. }
  216. controlp->getSignal()->connect(boost::bind(&LLSelectMgr::refreshCachedSettings));
  217. }
  218. //static
  219. void LLSelectMgr::refreshCachedSettings()
  220. {
  221. // Note: do not bother using LLCachedControls here: this method is rarely
  222. // called ("EditLinkedParts" is the most frequent trigger and still rare).
  223. gSelectMgr.mHideSelectedObjects =
  224. gSavedSettings.getBool("HideSelectedObjects");
  225. gSelectMgr.mRenderSelectionsPolicy =
  226. gSavedSettings.getU32("RenderHighlightSelectionsPolicy");
  227. gSelectMgr.mAllowSelectAvatar =
  228. gSavedSettings.getBool("AllowSelectAvatar");
  229. gSelectMgr.mDebugSelectMgr = gSavedSettings.getBool("DebugSelectMgr");
  230. gSelectMgr.mEditLinkedParts = gSavedSettings.getBool("EditLinkedParts");
  231. gSelectMgr.mSelectOwnedOnly = gSavedSettings.getBool("SelectOwnedOnly");
  232. gSelectMgr.mSelectMovableOnly =
  233. gSavedSettings.getBool("SelectMovableOnly");
  234. sRectSelectInclusive = gSavedSettings.getBool("RectangleSelectInclusive");
  235. sRenderLightRadius = gSavedSettings.getBool("RenderLightRadius");
  236. sHighlightThickness = gSavedSettings.getF32("SelectionHighlightThickness");
  237. sHighlightUScale = gSavedSettings.getF32("SelectionHighlightUScale");
  238. sHighlightVScale = gSavedSettings.getF32("SelectionHighlightVScale");
  239. sHighlightAlpha = gSavedSettings.getF32("SelectionHighlightAlpha");
  240. sHighlightAlphaTest = gSavedSettings.getF32("SelectionHighlightAlphaTest");
  241. sHighlightUAnim = gSavedSettings.getF32("SelectionHighlightUAnim");
  242. sHighlightVAnim = gSavedSettings.getF32("SelectionHighlightVAnim");
  243. sSilhouetteParentColor = gColors.getColor("SilhouetteParentColor");
  244. sSilhouetteChildColor = gColors.getColor("SilhouetteChildColor");
  245. sHighlightParentColor = gColors.getColor("HighlightParentColor");
  246. sHighlightChildColor = gColors.getColor("HighlightChildColor");
  247. sHighlightInspectColor = gColors.getColor("HighlightInspectColor");
  248. sContextSilhouetteColor = gColors.getColor("ContextSilhouetteColor") *
  249. 0.5f;
  250. }
  251. //static
  252. bool LLSelectMgr::renderHiddenSelection()
  253. {
  254. U32 policy = gSelectMgr.mRenderSelectionsPolicy;
  255. return policy > 2 || (policy == 2 && gToolMgr.inEdit());
  256. }
  257. void LLSelectMgr::update()
  258. {
  259. mSelectedObjects->cleanupNodes();
  260. }
  261. void LLSelectMgr::updateEffects()
  262. {
  263. // Keep reference grid objects active
  264. struct f final : public LLSelectedObjectFunctor
  265. {
  266. bool apply(LLViewerObject* object) override
  267. {
  268. LLDrawable* drawablep = object->mDrawable;
  269. if (drawablep)
  270. {
  271. gPipeline.markMoved(drawablep);
  272. }
  273. return true;
  274. }
  275. } func;
  276. mGridObjects.applyToObjects(&func);
  277. if (mEffectsTimer.getElapsedTimeF32() > 1.f)
  278. {
  279. mSelectedObjects->updateEffects();
  280. mEffectsTimer.reset();
  281. }
  282. }
  283. void LLSelectMgr::overrideObjectUpdates()
  284. {
  285. // Override any position updates from simulator on objects being edited
  286. struct f final : public LLSelectedNodeFunctor
  287. {
  288. bool apply(LLSelectNode* selectNode) override
  289. {
  290. LLViewerObject* object = selectNode->getObject();
  291. if (object && object->permMove() && !object->isPermanentEnforced())
  292. {
  293. if (!selectNode->mLastPositionLocal.isExactlyZero())
  294. {
  295. object->setPositionLocal(selectNode->mLastPositionLocal);
  296. }
  297. if (selectNode->mLastRotation != LLQuaternion())
  298. {
  299. object->setRotation(selectNode->mLastRotation);
  300. }
  301. if (!selectNode->mLastScale.isExactlyZero())
  302. {
  303. object->setScale(selectNode->mLastScale);
  304. }
  305. }
  306. return true;
  307. }
  308. } func;
  309. getSelection()->applyToNodes(&func);
  310. }
  311. // Selects just the object, not any other group members.
  312. LLObjectSelectionHandle LLSelectMgr::selectObjectOnly(LLViewerObject* object,
  313. S32 face, S32 gltf_node,
  314. S32 gltf_prim)
  315. {
  316. llassert(object);
  317. // Remember primary object
  318. mSelectedObjects->mPrimaryObject = object;
  319. // Do not add an object that is already in the list
  320. if (object->isSelected())
  321. {
  322. // Make sure point at position is updated
  323. updatePointAt();
  324. grabMenuHandler();
  325. return NULL;
  326. }
  327. if (!canSelectObject(object))
  328. {
  329. #if 0
  330. make_ui_sound("UISndInvalidOp");
  331. #endif
  332. return NULL;
  333. }
  334. // Place it in the list and tag it.
  335. // This will refresh dialogs.
  336. addAsIndividual(object, face, gltf_node, gltf_prim);
  337. // Stop the object from moving (this anticipates changes on the simulator
  338. // in LLTask::userSelect)
  339. // *FIX: should not zero out these either
  340. object->setVelocity(LLVector3::zero);
  341. object->setAcceleration(LLVector3::zero);
  342. #if 0 // Do not do that: it breaks target-omega seats !
  343. object->setAngularVelocity(LLVector3::zero);
  344. #endif
  345. object->resetRot();
  346. // Always send to simulator, so you get a copy of the permissions structure
  347. // back.
  348. LLMessageSystem* msg = gMessageSystemp;
  349. msg->newMessageFast(_PREHASH_ObjectSelect);
  350. msg->nextBlockFast(_PREHASH_AgentData);
  351. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  352. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  353. msg->nextBlockFast(_PREHASH_ObjectData);
  354. msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
  355. LLViewerRegion* regionp = object->getRegion();
  356. msg->sendReliable(regionp->getHost());
  357. updatePointAt();
  358. updateSelectionCenter();
  359. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  360. // Have selection manager handle edit menu immediately after user selects
  361. // an object
  362. if (mSelectedObjects->getObjectCount())
  363. {
  364. grabMenuHandler();
  365. }
  366. return mSelectedObjects;
  367. }
  368. // Selects the object, parents and children.
  369. LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(LLViewerObject* obj,
  370. bool add_to_end)
  371. {
  372. llassert(obj);
  373. // Remember primary object
  374. mSelectedObjects->mPrimaryObject = obj;
  375. // This may be incorrect if things were not family selected before...
  376. // Do not add an object that is already in the list
  377. if (obj->isSelected())
  378. {
  379. // make sure pointat position is updated
  380. updatePointAt();
  381. grabMenuHandler();
  382. return NULL;
  383. }
  384. if (!canSelectObject(obj))
  385. {
  386. //make_ui_sound("UISndInvalidOp");
  387. return NULL;
  388. }
  389. // Since we are selecting a family, start at the root, but do not include
  390. // an avatar.
  391. LLViewerObject* root = obj;
  392. while (!root->isAvatar() && root->getParent())
  393. {
  394. LLViewerObject* parent = (LLViewerObject*)root->getParent();
  395. if (parent->isAvatar())
  396. {
  397. break;
  398. }
  399. root = parent;
  400. }
  401. // Collect all of the objects
  402. std::vector<LLViewerObject*> objects;
  403. root->addThisAndNonJointChildren(objects);
  404. addAsFamily(objects, add_to_end);
  405. updateSelectionCenter();
  406. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  407. updatePointAt();
  408. dialog_refresh_all();
  409. // Always send to simulator, so you get a copy of the permissions structure
  410. // back.
  411. sendSelect();
  412. // Stop the object from moving (this anticipates changes on the simulator
  413. // in LLTask::userSelect)
  414. root->setVelocity(LLVector3::zero);
  415. root->setAcceleration(LLVector3::zero);
  416. #if 0 // Do not do that: it breaks target-omega seats !
  417. root->setAngularVelocity(LLVector3::zero);
  418. #endif
  419. root->resetRot();
  420. // Leave component mode
  421. if (mEditLinkedParts)
  422. {
  423. gSavedSettings.setBool("EditLinkedParts", false);
  424. promoteSelectionToRoot();
  425. }
  426. // Have selection manager handle edit menu immediately after user selects
  427. // an object
  428. if (mSelectedObjects->getObjectCount())
  429. {
  430. grabMenuHandler();
  431. }
  432. return mSelectedObjects;
  433. }
  434. // Selects the object, parents and children.
  435. LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list,
  436. bool send_to_sim)
  437. {
  438. // Collect all of the objects, children included
  439. std::vector<LLViewerObject*> objects;
  440. // Clear primary object (no primary object)
  441. mSelectedObjects->mPrimaryObject = NULL;
  442. if (object_list.size() < 1)
  443. {
  444. return NULL;
  445. }
  446. // NOTE: we add the objects in REVERSE ORDER to preserve the order in the
  447. // mSelectedObjects list
  448. for (std::vector<LLViewerObject*>::const_reverse_iterator
  449. riter = object_list.rbegin(), rend = object_list.rend();
  450. riter != rend; ++riter)
  451. {
  452. LLViewerObject* object = *riter;
  453. llassert(object);
  454. if (!canSelectObject(object)) continue;
  455. object->addThisAndNonJointChildren(objects);
  456. addAsFamily(objects);
  457. // Stop the object from moving (this anticipates changes on the
  458. // simulator in LLTask::userSelect)
  459. object->setVelocity(LLVector3::zero);
  460. object->setAcceleration(LLVector3::zero);
  461. #if 0 // Do not do that: it breaks target-omega seats !
  462. object->setAngularVelocity(LLVector3::zero);
  463. #endif
  464. object->resetRot();
  465. }
  466. updateSelectionCenter();
  467. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  468. updatePointAt();
  469. dialog_refresh_all();
  470. // Almost always send to simulator, so you get a copy of the permissions
  471. // structure back.
  472. // JC: The one case where you do not want to do this is if you're selecting
  473. // all the objects on a sim.
  474. if (send_to_sim)
  475. {
  476. sendSelect();
  477. }
  478. // leave component mode
  479. if (mEditLinkedParts)
  480. {
  481. gSavedSettings.setBool("EditLinkedParts", false);
  482. promoteSelectionToRoot();
  483. }
  484. // have selection manager handle edit menu immediately after user selects
  485. // an object
  486. if (mSelectedObjects->getObjectCount())
  487. {
  488. grabMenuHandler();
  489. }
  490. return mSelectedObjects;
  491. }
  492. // Use for when the simulator kills an object. This version also handles
  493. // informing the current tool of the object's deletion.
  494. // Caller needs to call dialog_refresh_all if necessary.
  495. bool LLSelectMgr::removeObjectFromSelections(const LLUUID& id)
  496. {
  497. bool object_found = false;
  498. LLTool* tool = gToolMgr.getCurrentTool();
  499. // It is possible that the tool is editing an object that is not selected
  500. LLViewerObject* tool_editing_object = tool->getEditingObject();
  501. if (tool_editing_object && tool_editing_object->mID == id)
  502. {
  503. tool->stopEditing();
  504. object_found = true;
  505. }
  506. // Iterate through selected objects list and kill the object
  507. if (!object_found)
  508. {
  509. for (LLObjectSelection::iterator iter = getSelection()->begin();
  510. iter != getSelection()->end(); )
  511. {
  512. LLSelectNode* node = *iter++;
  513. if (!node) continue; // Paranoia
  514. LLViewerObject* object = node->getObject();
  515. if (!object) continue; // Paranoia
  516. if (object->mID == id)
  517. {
  518. if (tool)
  519. {
  520. tool->stopEditing();
  521. }
  522. // Loose the selection, do not tell simulator, it knows
  523. deselectObjectAndFamily(object, false);
  524. object_found = true;
  525. // Must break here: may have removed multiple objects from list
  526. break;
  527. }
  528. else if (object->isAvatar() && object->getParent() &&
  529. ((LLViewerObject*)object->getParent())->mID == id)
  530. {
  531. // It is possible the item being removed has an avatar sitting
  532. // on it, so remove the avatar that is sitting on the object.
  533. deselectObjectAndFamily(object, false);
  534. // Must break here: may have removed multiple objects from list
  535. break;
  536. }
  537. }
  538. }
  539. return object_found;
  540. }
  541. bool LLSelectMgr::linkObjects()
  542. {
  543. //MK
  544. if (gRLenabled && gRLInterface.mContainsUnsit &&
  545. gRLInterface.isSittingOnAnySelectedObject())
  546. {
  547. return true;
  548. }
  549. //mk
  550. if (!selectGetAllRootsValid())
  551. {
  552. gNotifications.add("UnableToLinkWhileDownloading");
  553. return true;
  554. }
  555. S32 object_count = getSelection()->getObjectCount();
  556. S32 max_linked_prims = MAX_CHILDREN_PER_TASK + 1;
  557. if (!gIsInSecondLife)
  558. {
  559. static LLCachedControl<S32> os_max_prim_scale(gSavedSettings,
  560. "OSMaxLinkedPrims");
  561. if (os_max_prim_scale > max_linked_prims)
  562. {
  563. max_linked_prims = os_max_prim_scale;
  564. }
  565. else if (os_max_prim_scale < 0)
  566. {
  567. max_linked_prims = object_count; // no limit
  568. }
  569. }
  570. if (object_count > max_linked_prims)
  571. {
  572. LLSD args;
  573. args["COUNT"] = llformat("%d", object_count);
  574. args["MAX"] = llformat("%d", max_linked_prims);
  575. gNotifications.add("UnableToLinkObjects", args);
  576. return true;
  577. }
  578. if (getSelection()->getRootObjectCount() < 2)
  579. {
  580. gNotifications.add("CannotLinkIncompleteSet");
  581. return true;
  582. }
  583. if (!selectGetRootsModify())
  584. {
  585. gNotifications.add("CannotLinkModify");
  586. return true;
  587. }
  588. if (!selectGetRootsNonPermanentEnforced())
  589. {
  590. gNotifications.add("CannotLinkPermanent");
  591. return true;
  592. }
  593. LLUUID owner_id;
  594. std::string owner_name;
  595. if (!selectGetOwner(owner_id, owner_name))
  596. {
  597. // We do not actually care if you're the owner, but novices are the
  598. // most likely to be stumped by this one, so offer the easiest and
  599. // most likely solution.
  600. gNotifications.add("CannotLinkDifferentOwners");
  601. return true;
  602. }
  603. sendLink();
  604. return true;
  605. }
  606. bool LLSelectMgr::unlinkObjects()
  607. {
  608. //MK
  609. if (gRLenabled && gRLInterface.mContainsUnsit &&
  610. gRLInterface.isSittingOnAnySelectedObject())
  611. {
  612. return true;
  613. }
  614. //mk
  615. sendDelink();
  616. return true;
  617. }
  618. // In order to link, all objects must have the same owner, and the agent must
  619. // have the ability to modify all of the objects. However, we are not answering
  620. // that question with this method. The question we are answering is: does the
  621. // user have a reasonable expectation that a link operation should work ? If
  622. // so, return true, false otherwise. This allows the handle_link method to more
  623. // finely check the selection and give an error message when the uer has a
  624. // reasonable expectation for the link to work, but it will fail.
  625. // For animated objects, there's additional check that if the selection
  626. // includes at least one animated object, the total mesh triangle count cannot
  627. // exceed the designated limit.
  628. bool LLSelectMgr::enableLinkObjects()
  629. {
  630. bool new_value = false;
  631. // Check if there are at least 2 objects selected, and that the user can
  632. // modify at least one of the selected objects.
  633. // In component mode, cannot link
  634. if (!mEditLinkedParts)
  635. {
  636. if (selectGetAllRootsValid() &&
  637. getSelection()->getRootObjectCount() >= 2)
  638. {
  639. struct f final : public LLSelectedObjectFunctor
  640. {
  641. bool apply(LLViewerObject* object) override
  642. {
  643. LLViewerObject* root_object = object->getRootEdit();
  644. return object->permModify() &&
  645. !object->isPermanentEnforced() &&
  646. (!root_object ||
  647. !root_object->isPermanentEnforced());
  648. }
  649. } func;
  650. constexpr bool firstonly = true;
  651. new_value = getSelection()->applyToRootObjects(&func, firstonly);
  652. }
  653. //MK
  654. if (gRLenabled && gRLInterface.mContainsUnsit &&
  655. gRLInterface.isSittingOnAnySelectedObject())
  656. {
  657. new_value = false;
  658. }
  659. //mk
  660. }
  661. if (!getSelection()->checkAnimatedObjectEstTris())
  662. {
  663. new_value = false;
  664. }
  665. return new_value;
  666. }
  667. bool LLSelectMgr::enableUnlinkObjects()
  668. {
  669. LLViewerObject* first_editable_object =
  670. getSelection()->getFirstEditableObject();
  671. LLViewerObject* root_object =
  672. first_editable_object ? first_editable_object->getRootEdit() : NULL;
  673. bool new_value = selectGetAllRootsValid() &&
  674. first_editable_object &&
  675. !first_editable_object->isAttachment() &&
  676. !first_editable_object->isPermanentEnforced() &&
  677. (!root_object || !root_object->isPermanentEnforced());
  678. //MK
  679. if (gRLenabled && gRLInterface.mContainsUnsit &&
  680. gRLInterface.isSittingOnAnySelectedObject())
  681. {
  682. new_value = false;
  683. }
  684. //mk
  685. return new_value;
  686. }
  687. void LLSelectMgr::deselectObjectAndFamily(LLViewerObject* object,
  688. bool send_to_sim,
  689. bool include_entire_object)
  690. {
  691. // Bail if nothing selected or if object was not selected in the first
  692. // place
  693. if (!object || !object->isSelected()) return;
  694. // Collect all of the objects, and remove them
  695. std::vector<LLViewerObject*> objects;
  696. if (include_entire_object)
  697. {
  698. // Since we are selecting a family, start at the root, but do not
  699. // include an avatar.
  700. LLViewerObject* parent;
  701. while (!object->isAvatar() &&
  702. (parent = (LLViewerObject*)object->getParent()) != NULL &&
  703. !parent->isAvatar())
  704. {
  705. object = parent;
  706. }
  707. }
  708. else
  709. {
  710. object = (LLViewerObject*)object->getRoot();
  711. }
  712. object->addThisAndAllChildren(objects);
  713. remove(objects);
  714. if (!send_to_sim) return;
  715. //-----------------------------------------------------------
  716. // Inform simulator of deselection
  717. //-----------------------------------------------------------
  718. LLViewerRegion* regionp = object->getRegion();
  719. if (!regionp) return;
  720. bool start_new_message = true;
  721. S32 select_count = 0;
  722. LLMessageSystem* msg = gMessageSystemp;
  723. for (U32 i = 0, count = objects.size(); i < count; ++i)
  724. {
  725. if (start_new_message)
  726. {
  727. msg->newMessageFast(_PREHASH_ObjectDeselect);
  728. msg->nextBlockFast(_PREHASH_AgentData);
  729. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  730. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  731. select_count++;
  732. start_new_message = false;
  733. }
  734. msg->nextBlockFast(_PREHASH_ObjectData);
  735. msg->addU32Fast(_PREHASH_ObjectLocalID, (objects[i])->getLocalID());
  736. ++select_count;
  737. #if 0 // Do not do that: it breaks target-omega seats !
  738. // Zap the angular velocity, as the sim will set it to zero
  739. objects[i]->setAngularVelocity(0.f, 0.f, 0.f);
  740. #endif
  741. objects[i]->setVelocity(0.f, 0.f, 0.f);
  742. if (msg->isSendFull(NULL) || select_count >= MAX_OBJECTS_PER_PACKET)
  743. {
  744. msg->sendReliable(regionp->getHost());
  745. select_count = 0;
  746. start_new_message = true;
  747. }
  748. }
  749. if (!start_new_message)
  750. {
  751. msg->sendReliable(regionp->getHost());
  752. }
  753. updatePointAt();
  754. updateSelectionCenter();
  755. }
  756. void LLSelectMgr::deselectObjectOnly(LLViewerObject* object, bool send_to_sim)
  757. {
  758. // Bail if nothing selected or if object was not selected in the first
  759. // place
  760. if (!object || !object->isSelected()) return;
  761. #if 0 // Do not do that: it breaks target-omega seats !
  762. // Zap the angular velocity, as the sim will set it to zero
  763. object->setAngularVelocity(0.f, 0.f, 0.f);
  764. #endif
  765. object->setVelocity(0.f, 0.f, 0.f);
  766. if (send_to_sim)
  767. {
  768. LLViewerRegion* region = object->getRegion();
  769. LLMessageSystem* msg = gMessageSystemp;
  770. msg->newMessageFast(_PREHASH_ObjectDeselect);
  771. msg->nextBlockFast(_PREHASH_AgentData);
  772. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  773. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  774. msg->nextBlockFast(_PREHASH_ObjectData);
  775. msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
  776. msg->sendReliable(region->getHost());
  777. }
  778. // This will refresh dialogs.
  779. remove(object);
  780. updatePointAt();
  781. updateSelectionCenter();
  782. }
  783. void LLSelectMgr::addAsFamily(std::vector<LLViewerObject*>& objects,
  784. bool add_to_end)
  785. {
  786. for (std::vector<LLViewerObject*>::iterator iter = objects.begin(),
  787. end = objects.end();
  788. iter != end; ++iter)
  789. {
  790. LLViewerObject* objectp = *iter;
  791. if (!objectp || objectp->isDead())
  792. {
  793. continue;
  794. }
  795. // Cannot select yourself
  796. if (objectp->mID == gAgentID && !mAllowSelectAvatar)
  797. {
  798. continue;
  799. }
  800. if (!objectp->isSelected())
  801. {
  802. LLSelectNode* nodep = new LLSelectNode(objectp, true);
  803. if (add_to_end)
  804. {
  805. mSelectedObjects->addNodeAtEnd(nodep);
  806. }
  807. else
  808. {
  809. mSelectedObjects->addNode(nodep);
  810. }
  811. objectp->setSelected(true);
  812. if (objectp->getNumTEs() > 0) // Make sure object got a face !
  813. {
  814. nodep->selectAllTEs(true);
  815. objectp->setAllTESelected(true);
  816. }
  817. }
  818. else
  819. {
  820. // We want this object to be selected for real so clear transient
  821. // flag
  822. LLSelectNode* select_node = mSelectedObjects->findNode(objectp);
  823. if (select_node)
  824. {
  825. select_node->setTransient(false);
  826. }
  827. }
  828. }
  829. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  830. }
  831. // Adds a single object, face, etc
  832. void LLSelectMgr::addAsIndividual(LLViewerObject* objectp, S32 face,
  833. bool undoable, S32 gltf_node, S32 gltf_prim)
  834. {
  835. // Check to see if object is already in list
  836. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  837. // Reset in anticipation of being set to an appropriate value by panel
  838. // refresh, if they are up.
  839. setTextureChannel(LLRender::DIFFUSE_MAP);
  840. // If not in list, add it
  841. if (!nodep)
  842. {
  843. nodep = new LLSelectNode(objectp, true);
  844. mSelectedObjects->addNode(nodep);
  845. llassert_always(nodep->getObject());
  846. }
  847. else
  848. {
  849. // Make this a full-fledged selection
  850. nodep->setTransient(false);
  851. // Move it to the front of the list
  852. mSelectedObjects->moveNodeToFront(nodep);
  853. }
  854. // Make sure the object is tagged as selected
  855. objectp->setSelected(true);
  856. // And make sure we do not consider it as part of a family
  857. nodep->mIndividualSelection = true;
  858. // Handle face selection
  859. if (objectp->getNumTEs() > 0) // Make sure object got a face !
  860. {
  861. if (face == SELECT_ALL_TES)
  862. {
  863. nodep->selectAllTEs(true);
  864. objectp->setAllTESelected(true);
  865. }
  866. else if (face >= 0 && face < SELECT_MAX_TES)
  867. {
  868. nodep->selectTE(face, true);
  869. objectp->setTESelected(face, true);
  870. }
  871. else
  872. {
  873. llwarns << "Face " << face << " out of range !" << llendl;
  874. return;
  875. }
  876. }
  877. if (gltf_node >= 0)
  878. {
  879. nodep->mSelectedGLTFNode = gltf_node;
  880. nodep->mSelectedGLTFPrim = gltf_prim;
  881. }
  882. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  883. updateSelectionCenter();
  884. dialog_refresh_all();
  885. }
  886. LLObjectSelectionHandle LLSelectMgr::setHoverObject(LLViewerObject* objectp,
  887. S32 face)
  888. {
  889. if (!objectp ||
  890. // Cannot select yourself
  891. (objectp->mID == gAgentID && !mAllowSelectAvatar) ||
  892. // Cannot select land
  893. (objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH))
  894. {
  895. mHoverObjects->deleteAllNodes();
  896. return NULL;
  897. }
  898. mHoverObjects->mPrimaryObject = objectp;
  899. objectp = objectp->getRootEdit();
  900. // Is the requested object the same as the existing hover object root ?
  901. // NOTE: there is only ever one linked set in mHoverObjects
  902. if (mHoverObjects->getFirstRootObject() != objectp)
  903. {
  904. // Collect all of the objects
  905. std::vector<LLViewerObject*> objects;
  906. objectp = objectp->getRootEdit();
  907. objectp->addThisAndNonJointChildren(objects);
  908. mHoverObjects->deleteAllNodes();
  909. for (std::vector<LLViewerObject*>::iterator iter = objects.begin(),
  910. end = objects.end();
  911. iter != end; ++iter)
  912. {
  913. LLViewerObject* cur_objectp = *iter;
  914. if (cur_objectp && !cur_objectp->isDead())
  915. {
  916. LLSelectNode* nodep = new LLSelectNode(cur_objectp, false);
  917. nodep->selectTE(face, true);
  918. mHoverObjects->addNodeAtEnd(nodep);
  919. }
  920. }
  921. requestObjectPropertiesFamily(objectp);
  922. }
  923. return mHoverObjects;
  924. }
  925. LLSelectNode* LLSelectMgr::getHoverNode()
  926. {
  927. return mHoverObjects->getFirstRootNode();
  928. }
  929. LLSelectNode* LLSelectMgr::getPrimaryHoverNode()
  930. {
  931. return mHoverObjects->mSelectNodeMap[mHoverObjects->mPrimaryObject];
  932. }
  933. void LLSelectMgr::highlightObjectOnly(LLViewerObject* objectp)
  934. {
  935. if (!objectp)
  936. {
  937. return;
  938. }
  939. if (objectp->getPCode() != LL_PCODE_VOLUME &&
  940. objectp->getPCode() != LL_PCODE_LEGACY_TREE &&
  941. objectp->getPCode() != LL_PCODE_LEGACY_GRASS)
  942. {
  943. return;
  944. }
  945. if ((mSelectOwnedOnly && !objectp->permYouOwner()) ||
  946. (mSelectMovableOnly &&
  947. (!objectp->permMove() || objectp->isPermanentEnforced())))
  948. {
  949. // Only select my own objects
  950. return;
  951. }
  952. mRectSelectedObjects.insert(objectp);
  953. }
  954. void LLSelectMgr::highlightObjectAndFamily(LLViewerObject* objectp)
  955. {
  956. if (!objectp)
  957. {
  958. return;
  959. }
  960. LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
  961. highlightObjectOnly(root_obj);
  962. LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
  963. for (LLViewerObject::child_list_t::const_iterator
  964. iter = child_list.begin(), end = child_list.end();
  965. iter != end; ++iter)
  966. {
  967. LLViewerObject* child = *iter;
  968. highlightObjectOnly(child);
  969. }
  970. }
  971. // Note that this ignores the "select owned only" flag. It is also more
  972. // efficient than calling the single-object version over and over.
  973. void LLSelectMgr::highlightObjectAndFamily(const std::vector<LLViewerObject*>& objects)
  974. {
  975. for (std::vector<LLViewerObject*>::const_iterator
  976. iter1 = objects.begin(), end1 = objects.end();
  977. iter1 != end1; ++iter1)
  978. {
  979. LLViewerObject* object = *iter1;
  980. if (!object)
  981. {
  982. continue;
  983. }
  984. LLPCode pcode = object->getPCode();
  985. if (pcode != LL_PCODE_VOLUME && pcode != LL_PCODE_LEGACY_TREE &&
  986. pcode != LL_PCODE_LEGACY_GRASS)
  987. {
  988. continue;
  989. }
  990. LLViewerObject* root = (LLViewerObject*)object->getRoot();
  991. mRectSelectedObjects.insert(root);
  992. LLViewerObject::const_child_list_t& child_list = root->getChildren();
  993. for (LLViewerObject::child_list_t::const_iterator
  994. iter2 = child_list.begin(), end2 = child_list.end();
  995. iter2 != end2; ++iter2)
  996. {
  997. LLViewerObject* child = *iter2;
  998. mRectSelectedObjects.insert(child);
  999. }
  1000. }
  1001. }
  1002. void LLSelectMgr::unhighlightObjectOnly(LLViewerObject* objectp)
  1003. {
  1004. if (!objectp)
  1005. {
  1006. return;
  1007. }
  1008. LLPCode pcode = objectp->getPCode();
  1009. if (pcode == LL_PCODE_VOLUME || pcode == LL_PCODE_LEGACY_TREE ||
  1010. pcode == LL_PCODE_LEGACY_GRASS)
  1011. {
  1012. mRectSelectedObjects.erase(objectp);
  1013. }
  1014. }
  1015. void LLSelectMgr::unhighlightObjectAndFamily(LLViewerObject* objectp)
  1016. {
  1017. if (!objectp)
  1018. {
  1019. return;
  1020. }
  1021. LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
  1022. unhighlightObjectOnly(root_obj);
  1023. LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
  1024. for (LLViewerObject::child_list_t::const_iterator
  1025. iter = child_list.begin(), end = child_list.end();
  1026. iter != end; ++iter)
  1027. {
  1028. LLViewerObject* child = *iter;
  1029. unhighlightObjectOnly(child);
  1030. }
  1031. }
  1032. void LLSelectMgr::unhighlightAll()
  1033. {
  1034. mRectSelectedObjects.clear();
  1035. mHighlightedObjects->deleteAllNodes();
  1036. }
  1037. LLObjectSelectionHandle LLSelectMgr::selectHighlightedObjects()
  1038. {
  1039. if (!mHighlightedObjects->getNumNodes())
  1040. {
  1041. return NULL;
  1042. }
  1043. // Clear primary object
  1044. mSelectedObjects->mPrimaryObject = NULL;
  1045. for (LLObjectSelection::iterator iter = getHighlightedObjects()->begin();
  1046. iter != getHighlightedObjects()->end(); )
  1047. {
  1048. LLSelectNode* nodep = *iter++;
  1049. if (!nodep) continue; // Paranoia
  1050. LLViewerObject* objectp = nodep->getObject();
  1051. if (!objectp || !canSelectObject(objectp))
  1052. {
  1053. continue;
  1054. }
  1055. // Already selected
  1056. if (objectp->isSelected())
  1057. {
  1058. continue;
  1059. }
  1060. LLSelectNode* new_nodep = new LLSelectNode(*nodep);
  1061. mSelectedObjects->addNode(new_nodep);
  1062. // Flag this object as selected
  1063. objectp->setSelected(true);
  1064. objectp->setAllTESelected(true);
  1065. mSelectedObjects->mSelectType = getSelectTypeForObject(objectp);
  1066. // Request properties on root objects
  1067. if (objectp->isRootEdit())
  1068. {
  1069. requestObjectPropertiesFamily(objectp);
  1070. }
  1071. }
  1072. // Pack up messages to let sim know these objects are selected
  1073. sendSelect();
  1074. unhighlightAll();
  1075. updateSelectionCenter();
  1076. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  1077. updatePointAt();
  1078. if (mSelectedObjects->getObjectCount())
  1079. {
  1080. grabMenuHandler();
  1081. }
  1082. return mSelectedObjects;
  1083. }
  1084. void LLSelectMgr::deselectHighlightedObjects()
  1085. {
  1086. bool select_linked_set = !mEditLinkedParts;
  1087. for (std::set<LLPointer<LLViewerObject> >::iterator
  1088. iter = mRectSelectedObjects.begin();
  1089. iter != mRectSelectedObjects.end(); ++iter)
  1090. {
  1091. LLViewerObject* objectp = *iter;
  1092. if (!objectp) continue; // Paranoia
  1093. if (!select_linked_set)
  1094. {
  1095. deselectObjectOnly(objectp);
  1096. }
  1097. else
  1098. {
  1099. LLViewerObject* root_object = (LLViewerObject*)objectp->getRoot();
  1100. if (root_object && root_object->isSelected())
  1101. {
  1102. deselectObjectAndFamily(root_object);
  1103. }
  1104. }
  1105. }
  1106. unhighlightAll();
  1107. }
  1108. void LLSelectMgr::addGridObject(LLViewerObject* objectp)
  1109. {
  1110. LLSelectNode* nodep = new LLSelectNode(objectp, false);
  1111. mGridObjects.addNodeAtEnd(nodep);
  1112. LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
  1113. for (LLViewerObject::child_list_t::const_iterator
  1114. iter = child_list.begin(), end = child_list.end();
  1115. iter != end; ++iter)
  1116. {
  1117. LLViewerObject* child = *iter;
  1118. nodep = new LLSelectNode(child, false);
  1119. mGridObjects.addNodeAtEnd(nodep);
  1120. }
  1121. }
  1122. void LLSelectMgr::clearGridObjects()
  1123. {
  1124. mGridObjects.deleteAllNodes();
  1125. }
  1126. void LLSelectMgr::setGridMode(EGridMode mode)
  1127. {
  1128. mGridMode = mode;
  1129. gSavedSettings.setS32("GridMode", mode);
  1130. updateSelectionCenter();
  1131. }
  1132. void LLSelectMgr::getGrid(LLVector3& origin, LLQuaternion& rotation,
  1133. LLVector3& scale, bool for_snap_guides)
  1134. {
  1135. mGridObjects.cleanupNodes();
  1136. LLViewerObject* first_grid_object = mGridObjects.getFirstObject();
  1137. if (mGridMode == GRID_MODE_LOCAL && mSelectedObjects->getObjectCount())
  1138. {
  1139. #if 0
  1140. LLViewerObject* root =
  1141. getSelectedParentObject(mSelectedObjects->getFirstObject());
  1142. mGridOrigin = mSavedSelectionBBox.getCenterAgent();
  1143. mGridScale = mSavedSelectionBBox.getExtentLocal() * 0.5f;
  1144. // DEV-12570 Just taking the saved selection box rotation prevents wild
  1145. // rotations of linked sets while in local grid mode
  1146. if (mSelectedObjects->getObjectCount() < 2 || !root ||
  1147. root->mDrawable.isNull())
  1148. {
  1149. mGridRotation = mSavedSelectionBBox.getRotation();
  1150. }
  1151. else // set to the root object
  1152. {
  1153. mGridRotation = root->getRenderRotation();
  1154. }
  1155. #else
  1156. mGridOrigin = mSavedSelectionBBox.getCenterAgent();
  1157. mGridScale = mSavedSelectionBBox.getExtentLocal() * 0.5f;
  1158. mGridRotation = mSavedSelectionBBox.getRotation();
  1159. #endif
  1160. }
  1161. else if (mGridMode == GRID_MODE_REF_OBJECT && first_grid_object &&
  1162. first_grid_object->mDrawable.notNull())
  1163. {
  1164. LLSelectNode* node = mSelectedObjects->findNode(first_grid_object);
  1165. if (node && !for_snap_guides)
  1166. {
  1167. mGridRotation = node->mSavedRotation;
  1168. }
  1169. else
  1170. {
  1171. mGridRotation = first_grid_object->getRenderRotation();
  1172. }
  1173. LLVector4a min_extents(F32_MAX);
  1174. LLVector4a max_extents(-F32_MAX);
  1175. bool grid_changed = false;
  1176. for (LLObjectSelection::iterator iter = mGridObjects.begin(),
  1177. end = mGridObjects.end();
  1178. iter != end; ++iter)
  1179. {
  1180. LLViewerObject* object = (*iter)->getObject();
  1181. if (!object) return; // Paranoia
  1182. LLDrawable* drawablep = object->mDrawable;
  1183. if (drawablep)
  1184. {
  1185. const LLVector4a* ext = drawablep->getSpatialExtents();
  1186. update_min_max(min_extents, max_extents, ext[0]);
  1187. update_min_max(min_extents, max_extents, ext[1]);
  1188. grid_changed = true;
  1189. }
  1190. }
  1191. if (grid_changed)
  1192. {
  1193. LLVector4a center, size;
  1194. center.setAdd(min_extents, max_extents);
  1195. center.mul(0.5f);
  1196. size.setSub(max_extents, min_extents);
  1197. size.mul(0.5f);
  1198. mGridOrigin.set(center.getF32ptr());
  1199. LLDrawable* drawablep = first_grid_object->mDrawable;
  1200. if (drawablep && drawablep->isActive())
  1201. {
  1202. mGridOrigin = mGridOrigin *
  1203. first_grid_object->getRenderMatrix();
  1204. }
  1205. mGridScale.set(size.getF32ptr());
  1206. }
  1207. }
  1208. else // GRID_MODE_WORLD or just plain default
  1209. {
  1210. constexpr bool non_root_ok = true;
  1211. LLViewerObject* first_obj =
  1212. mSelectedObjects->getFirstRootObject(non_root_ok);
  1213. mGridOrigin.clear();
  1214. mGridRotation.loadIdentity();
  1215. mSelectedObjects->mSelectType = getSelectTypeForObject(first_obj);
  1216. static LLCachedControl<F32> grid_resolution(gSavedSettings,
  1217. "GridResolution");
  1218. switch (mSelectedObjects->mSelectType)
  1219. {
  1220. case SELECT_TYPE_ATTACHMENT:
  1221. {
  1222. if (first_obj && first_obj->getRootEdit() &&
  1223. first_obj->getRootEdit()->mDrawable.notNull())
  1224. {
  1225. // This means this object *has* to be an attachment
  1226. LLXform* attach_point_xform =
  1227. first_obj->getRootEdit()->mDrawable->mXform.getParent();
  1228. if (attach_point_xform)
  1229. {
  1230. mGridOrigin = attach_point_xform->getWorldPosition();
  1231. mGridRotation = attach_point_xform->getWorldRotation();
  1232. }
  1233. F32 scale = grid_resolution;
  1234. mGridScale.set(scale, scale, scale);
  1235. }
  1236. break;
  1237. }
  1238. case SELECT_TYPE_HUD:
  1239. {
  1240. F32 scale = llmin((F32)grid_resolution, 0.5f);
  1241. mGridScale.set(scale, scale, scale);
  1242. break;
  1243. }
  1244. case SELECT_TYPE_WORLD:
  1245. {
  1246. F32 scale = grid_resolution;
  1247. mGridScale.set(scale, scale, scale);
  1248. }
  1249. }
  1250. }
  1251. llassert(mGridOrigin.isFinite());
  1252. origin = mGridOrigin;
  1253. rotation = mGridRotation;
  1254. scale = mGridScale;
  1255. }
  1256. // Removes an array of objects
  1257. void LLSelectMgr::remove(std::vector<LLViewerObject*>& objects)
  1258. {
  1259. for (std::vector<LLViewerObject*>::iterator iter = objects.begin(),
  1260. end = objects.end();
  1261. iter != end; ++iter)
  1262. {
  1263. LLViewerObject* objectp = *iter;
  1264. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  1265. if (nodep)
  1266. {
  1267. objectp->setSelected(false);
  1268. mSelectedObjects->removeNode(nodep);
  1269. nodep = NULL;
  1270. }
  1271. }
  1272. updateSelectionCenter();
  1273. dialog_refresh_all();
  1274. }
  1275. // Removes a single object
  1276. void LLSelectMgr::remove(LLViewerObject* objectp, S32 te, bool undoable)
  1277. {
  1278. // Get object node (and verify it is in the selected list)
  1279. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  1280. if (!nodep)
  1281. {
  1282. return;
  1283. }
  1284. // If face = all, remove object from list
  1285. if (objectp->getNumTEs() <= 0 || te == SELECT_ALL_TES)
  1286. {
  1287. // Remove all faces (or the object does not have faces) so remove the
  1288. // node.
  1289. mSelectedObjects->removeNode(nodep);
  1290. nodep = NULL;
  1291. objectp->setSelected(false);
  1292. }
  1293. else if (0 <= te && te < SELECT_MAX_TES)
  1294. {
  1295. // Valid face, check to see if it was on
  1296. if (nodep->isTESelected(te))
  1297. {
  1298. nodep->selectTE(te, false);
  1299. objectp->setTESelected(te, false);
  1300. }
  1301. else
  1302. {
  1303. llwarns << "Tried to remove face " << te
  1304. << " that was not selected !" << llendl;
  1305. llassert(false);
  1306. return;
  1307. }
  1308. // Check to see if this operation turned off all faces
  1309. bool found = false;
  1310. for (S32 i = 0, count = nodep->getObject()->getNumTEs(); i < count;
  1311. i++)
  1312. {
  1313. found = found || nodep->isTESelected(i);
  1314. }
  1315. // ...all faces now turned off, so remove
  1316. if (!found)
  1317. {
  1318. mSelectedObjects->removeNode(nodep);
  1319. nodep = NULL;
  1320. objectp->setSelected(false);
  1321. // *FIXME: does not update simulator that object is no longer
  1322. // selected
  1323. }
  1324. }
  1325. else
  1326. {
  1327. // Face number out of range
  1328. llwarns << "Face " << te << " out of range !" << llendl;
  1329. llassert(false);
  1330. return;
  1331. }
  1332. updateSelectionCenter();
  1333. dialog_refresh_all();
  1334. }
  1335. void LLSelectMgr::removeAll()
  1336. {
  1337. for (LLObjectSelection::iterator iter = mSelectedObjects->begin(),
  1338. end = mSelectedObjects->end();
  1339. iter != end; ++iter)
  1340. {
  1341. LLViewerObject* objectp = (*iter)->getObject();
  1342. objectp->setSelected(false);
  1343. }
  1344. mSelectedObjects->deleteAllNodes();
  1345. updateSelectionCenter();
  1346. dialog_refresh_all();
  1347. }
  1348. void LLSelectMgr::promoteSelectionToRoot()
  1349. {
  1350. std::vector<LLViewerObject*> selection_set;
  1351. bool selection_changed = false;
  1352. for (LLObjectSelection::iterator iter = getSelection()->begin();
  1353. iter != getSelection()->end(); )
  1354. {
  1355. LLSelectNode* nodep = *iter++;
  1356. LLViewerObject* object = nodep->getObject();
  1357. if (nodep->mIndividualSelection)
  1358. {
  1359. selection_changed = true;
  1360. }
  1361. LLViewerObject* parentp = object;
  1362. while (parentp->getParent() && !parentp->isRootEdit())
  1363. {
  1364. parentp = (LLViewerObject*)parentp->getParent();
  1365. }
  1366. selection_set.push_back(parentp);
  1367. }
  1368. if (selection_changed)
  1369. {
  1370. deselectAll();
  1371. for (S32 i = 0, count = selection_set.size(); i < count; ++i)
  1372. {
  1373. selectObjectAndFamily(selection_set[i], true);
  1374. }
  1375. }
  1376. }
  1377. void LLSelectMgr::demoteSelectionToIndividuals()
  1378. {
  1379. std::vector<LLViewerObject*> objects;
  1380. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  1381. end = getSelection()->root_end();
  1382. iter != end; ++iter)
  1383. {
  1384. LLViewerObject* object = (*iter)->getObject();
  1385. if (object) // Paranoia
  1386. {
  1387. object->addThisAndNonJointChildren(objects);
  1388. }
  1389. }
  1390. if (!objects.empty())
  1391. {
  1392. deselectAll();
  1393. for (std::vector<LLViewerObject*>::iterator iter = objects.begin(),
  1394. end = objects.end();
  1395. iter != end; ++iter)
  1396. {
  1397. LLViewerObject* objectp = *iter;
  1398. if (objectp && !objectp->isDead())
  1399. {
  1400. selectObjectOnly(objectp);
  1401. }
  1402. }
  1403. }
  1404. }
  1405. void LLSelectMgr::dump()
  1406. {
  1407. llinfos << "Selection Manager: " << mSelectedObjects->getNumNodes()
  1408. << " items" << llendl;
  1409. llinfos << "TE mode " << mTEMode << llendl;
  1410. S32 count = 0;
  1411. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  1412. end = getSelection()->end();
  1413. iter != end; ++iter)
  1414. {
  1415. LLViewerObject* objectp = (*iter)->getObject();
  1416. if (!objectp) continue;
  1417. llinfos << "Object " << count++ << " type "
  1418. << LLPrimitive::pCodeToString(objectp->getPCode()) << llendl;
  1419. llinfos << " hasLSL " << objectp->flagScripted() << llendl;
  1420. llinfos << " hasTouch " << objectp->flagHandleTouch() << llendl;
  1421. llinfos << " hasMoney " << objectp->flagTakesMoney() << llendl;
  1422. llinfos << " getposition " << objectp->getPosition() << llendl;
  1423. llinfos << " getpositionAgent " << objectp->getPositionAgent()
  1424. << llendl;
  1425. llinfos << " getpositionRegion " << objectp->getPositionRegion()
  1426. << llendl;
  1427. llinfos << " getpositionGlobal " << objectp->getPositionGlobal()
  1428. << llendl;
  1429. LLDrawable* drawablep = objectp->mDrawable;
  1430. if (!drawablep) continue;
  1431. llinfos << " " << (drawablep->isVisible() ? "visible" : "invisible")
  1432. << llendl;
  1433. llinfos << " " << (drawablep->isState(LLDrawable::FORCE_INVISIBLE) ?
  1434. "force_invisible" : "")
  1435. << llendl;
  1436. }
  1437. // Face iterator
  1438. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  1439. end = getSelection()->end();
  1440. iter != end; ++iter)
  1441. {
  1442. LLSelectNode* node = *iter;
  1443. LLViewerObject* objectp = node->getObject();
  1444. if (!objectp) continue;
  1445. for (S32 te = 0, count2 = objectp->getNumTEs(); te < count2; ++te)
  1446. {
  1447. if (node->isTESelected(te))
  1448. {
  1449. llinfos << "Object " << objectp << " te " << te << llendl;
  1450. }
  1451. }
  1452. }
  1453. llinfos << mHighlightedObjects->getNumNodes()
  1454. << " objects currently highlighted. Center global: "
  1455. << mSelectionCenterGlobal << llendl;
  1456. }
  1457. void LLSelectMgr::cleanup()
  1458. {
  1459. mSilhouetteImagep = NULL;
  1460. }
  1461. //---------------------------------------------------------------------------
  1462. // Manipulate properties of selected objects
  1463. //---------------------------------------------------------------------------
  1464. struct LLSelectMgrSendFunctor final : public LLSelectedObjectFunctor
  1465. {
  1466. bool apply(LLViewerObject* objectp) override
  1467. {
  1468. if (objectp && objectp->permModify())
  1469. {
  1470. objectp->sendTEUpdate();
  1471. }
  1472. return true;
  1473. }
  1474. };
  1475. struct DropTextureFn final : public LLSelectedTEFunctor
  1476. {
  1477. LLViewerInventoryItem* mItem;
  1478. LLUUID mTextureID;
  1479. DropTextureFn(LLViewerInventoryItem* item, const LLUUID& id)
  1480. : mItem(item),
  1481. mTextureID(id)
  1482. {
  1483. }
  1484. bool apply(LLViewerObject* objectp, S32 te) override
  1485. {
  1486. if (!objectp || !objectp->permModify())
  1487. {
  1488. return false;
  1489. }
  1490. if (mItem)
  1491. {
  1492. if (objectp->isAttachment() &&
  1493. !mItem->getPermissions().unrestricted())
  1494. {
  1495. // Attachments are in both in world and in inventory, which is
  1496. // not a situation supported server side at the moment for
  1497. // applying restricted assets.
  1498. return false;
  1499. }
  1500. constexpr LLToolDragAndDrop::ESource source =
  1501. LLToolDragAndDrop::SOURCE_AGENT;
  1502. if (te == -1) // All faces
  1503. {
  1504. LLToolDragAndDrop::dropTextureAllFaces(objectp, mItem, source);
  1505. return true;
  1506. }
  1507. // One face
  1508. LLToolDragAndDrop::dropTextureOneFace(objectp, te, mItem, source);
  1509. return true;
  1510. }
  1511. // Not an inventory item, meaning a Texture picker default texture or a
  1512. // or a local texture, so we do not need to worry about permissions for
  1513. // them and can just apply the texture and be done with it.
  1514. LLViewerFetchedTexture* texp =
  1515. LLViewerTextureManager::getFetchedTexture(mTextureID,
  1516. FTT_DEFAULT, true,
  1517. LLGLTexture::BOOST_NONE,
  1518. LLViewerTexture::LOD_TEXTURE);
  1519. if (texp)
  1520. {
  1521. objectp->setTEImage(te, texp);
  1522. }
  1523. return true;
  1524. }
  1525. };
  1526. struct SendTEUpdatesFn final : public LLSelectedObjectFunctor
  1527. {
  1528. SendTEUpdatesFn() = default;
  1529. bool apply(LLViewerObject* objectp) override
  1530. {
  1531. if (!objectp || !objectp->permModify())
  1532. {
  1533. return false;
  1534. }
  1535. objectp->sendTEUpdate();
  1536. // 1 particle effect per object
  1537. LLHUDEffectSpiral::agentBeamToObject(objectp);
  1538. return true;
  1539. }
  1540. };
  1541. // *TODO: re-arch texture applying out of LLToolDragAndDrop
  1542. void LLSelectMgr::selectionSetTexture(const LLUUID& tex_id)
  1543. {
  1544. // Check for no copy texture and/or multiple objects selection cases
  1545. LLViewerInventoryItem* itemp = gInventory.getItem(tex_id);
  1546. if (itemp && !itemp->getPermissions().allowCopyBy(gAgentID))
  1547. {
  1548. if (mSelectedObjects->getNumNodes() > 1)
  1549. {
  1550. llwarns << "Attempted to apply no-copy texture to multiple objects"
  1551. << llendl;
  1552. return;
  1553. }
  1554. getSelection()->applyNoCopyTextureToTEs(itemp);
  1555. }
  1556. else
  1557. {
  1558. DropTextureFn setfunc(itemp, tex_id);
  1559. getSelection()->applyToTEs(&setfunc);
  1560. }
  1561. // Nothing more to do when applying an inventory item (sendTEUpdate() and
  1562. // particle effect already performed in LLToolDragAndDrop::dropTexture*()
  1563. // methods)... HB
  1564. if (!itemp)
  1565. {
  1566. SendTEUpdatesFn sendfunc;
  1567. getSelection()->applyToObjects(&sendfunc);
  1568. }
  1569. }
  1570. struct DropMaterialFn final : public LLSelectedTEFunctor
  1571. {
  1572. LLViewerInventoryItem* mItem;
  1573. LLUUID mMaterialID;
  1574. DropMaterialFn(LLViewerInventoryItem* item, const LLUUID& id)
  1575. : mItem(item),
  1576. mMaterialID(id)
  1577. {
  1578. }
  1579. bool apply(LLViewerObject* objectp, S32 te) override
  1580. {
  1581. if (!objectp || !objectp->permModify())
  1582. {
  1583. return false;
  1584. }
  1585. LLUUID asset_id = mMaterialID;
  1586. if (mItem)
  1587. {
  1588. if (objectp->isAttachment() &&
  1589. !mItem->getPermissions().unrestricted())
  1590. {
  1591. // Attachments are in both in world and in inventory, which is
  1592. // not a situation supported server side at the moment for
  1593. // applying restricted assets.
  1594. return false;
  1595. }
  1596. constexpr LLToolDragAndDrop::ESource source =
  1597. LLToolDragAndDrop::SOURCE_AGENT;
  1598. // On success, the material may be copied into the object's
  1599. // inventory.
  1600. if (!LLToolDragAndDrop::handleDropAssetProtections(objectp, mItem,
  1601. source))
  1602. {
  1603. return false;
  1604. }
  1605. asset_id = mItem->getAssetUUID();
  1606. if (asset_id.isNull())
  1607. {
  1608. asset_id = BLANK_MATERIAL_ASSET_ID;
  1609. }
  1610. }
  1611. // Blanks out most override data on the object and send to server.
  1612. objectp->setRenderMaterialID(te, asset_id);
  1613. return true;
  1614. }
  1615. };
  1616. bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id)
  1617. {
  1618. LLViewerInventoryItem* itemp = NULL;
  1619. if (mat_id.notNull())
  1620. {
  1621. itemp = gInventory.getItem(mat_id);
  1622. }
  1623. bool copy_ok = !itemp || itemp->getPermissions().allowCopyBy(gAgentID);
  1624. if (!copy_ok && mSelectedObjects->getNumNodes() > 1)
  1625. {
  1626. llwarns << "Attempted to apply no-copy texture to multiple objects"
  1627. << llendl;
  1628. return false;
  1629. }
  1630. bool untrestricted = true;
  1631. if (itemp)
  1632. {
  1633. const LLPermissions& perm = itemp->getPermissions();
  1634. untrestricted = perm.unrestricted() || perm.fromLibrary() ||
  1635. (copy_ok && perm.allowTransferBy(gAgentID) &&
  1636. perm.allowModifyBy(gAgentID));
  1637. }
  1638. bool success = true;
  1639. if (untrestricted)
  1640. {
  1641. DropMaterialFn setfunc(itemp, mat_id);
  1642. getSelection()->applyToTEs(&setfunc);
  1643. }
  1644. else
  1645. {
  1646. success = getSelection()->applyRestrictedPbrMatToTEs(itemp);
  1647. }
  1648. struct func final : public LLSelectedObjectFunctor
  1649. {
  1650. LLViewerInventoryItem* mItem;
  1651. func(LLViewerInventoryItem* itemp)
  1652. : mItem(itemp)
  1653. {
  1654. }
  1655. bool apply(LLViewerObject* objectp) override
  1656. {
  1657. if (!objectp || !objectp->permModify())
  1658. {
  1659. return false;
  1660. }
  1661. if (mItem && objectp->isAttachment())
  1662. {
  1663. const LLPermissions& perm = mItem->getPermissions();
  1664. if (!perm.unrestricted() && !perm.fromLibrary())
  1665. {
  1666. // Attachments are in both in world and in inventory, which
  1667. // is not a situation supported server side at the moment
  1668. // for applying restricted assets.
  1669. return false;
  1670. }
  1671. }
  1672. if (!mItem)
  1673. {
  1674. // 1 particle effect per object
  1675. LLHUDEffectSpiral::agentBeamToObject(objectp);
  1676. }
  1677. dialog_refresh_all();
  1678. objectp->sendTEUpdate();
  1679. return true;
  1680. }
  1681. } sendfunc(itemp);
  1682. success = success && getSelection()->applyToObjects(&sendfunc);
  1683. LLGLTFMaterialList::flushUpdates();
  1684. return success;
  1685. }
  1686. void LLSelectMgr::selectionSetColor(const LLColor4& color)
  1687. {
  1688. struct f final : public LLSelectedTEFunctor
  1689. {
  1690. LLColor4 mColor;
  1691. f(const LLColor4& c)
  1692. : mColor(c)
  1693. {
  1694. }
  1695. bool apply(LLViewerObject* object, S32 te) override
  1696. {
  1697. if (object->permModify())
  1698. {
  1699. object->setTEColor(te, mColor);
  1700. }
  1701. return true;
  1702. }
  1703. } setfunc(color);
  1704. getSelection()->applyToTEs(&setfunc);
  1705. LLSelectMgrSendFunctor sendfunc;
  1706. getSelection()->applyToObjects(&sendfunc);
  1707. }
  1708. void LLSelectMgr::selectionSetColorOnly(const LLColor4& color)
  1709. {
  1710. struct f final : public LLSelectedTEFunctor
  1711. {
  1712. LLColor4 mColor;
  1713. f(const LLColor4& c)
  1714. : mColor(c)
  1715. {
  1716. }
  1717. bool apply(LLViewerObject* object, S32 te) override
  1718. {
  1719. if (object->permModify())
  1720. {
  1721. LLTextureEntry* tep = object->getTE(te);
  1722. LLColor4 prev_color = tep ? tep->getColor() : LLColor4::white;
  1723. mColor.mV[VALPHA] = prev_color.mV[VALPHA];
  1724. // Update viewer side color in anticipation of update from
  1725. // simulator
  1726. object->setTEColor(te, mColor);
  1727. }
  1728. return true;
  1729. }
  1730. } setfunc(color);
  1731. getSelection()->applyToTEs(&setfunc);
  1732. LLSelectMgrSendFunctor sendfunc;
  1733. getSelection()->applyToObjects(&sendfunc);
  1734. }
  1735. void LLSelectMgr::selectionSetAlphaOnly(F32 alpha)
  1736. {
  1737. struct f final : public LLSelectedTEFunctor
  1738. {
  1739. F32 mAlpha;
  1740. f(const F32& a)
  1741. : mAlpha(a)
  1742. {
  1743. }
  1744. bool apply(LLViewerObject* object, S32 te) override
  1745. {
  1746. if (object->permModify())
  1747. {
  1748. LLTextureEntry* tep = object->getTE(te);
  1749. LLColor4 prev_color = tep ? tep->getColor() : LLColor4::white;
  1750. prev_color.mV[VALPHA] = mAlpha;
  1751. // Update viewer side color in anticipation of update from
  1752. // simulator
  1753. object->setTEColor(te, prev_color);
  1754. }
  1755. return true;
  1756. }
  1757. } setfunc(alpha);
  1758. getSelection()->applyToTEs(&setfunc);
  1759. LLSelectMgrSendFunctor sendfunc;
  1760. getSelection()->applyToObjects(&sendfunc);
  1761. }
  1762. void LLSelectMgr::selectionRevertColors()
  1763. {
  1764. struct f final : public LLSelectedTEFunctor
  1765. {
  1766. LLObjectSelectionHandle mSelectedObjects;
  1767. f(LLObjectSelectionHandle sel)
  1768. : mSelectedObjects(sel)
  1769. {
  1770. }
  1771. bool apply(LLViewerObject* object, S32 te) override
  1772. {
  1773. if (object->permModify())
  1774. {
  1775. LLSelectNode* nodep = mSelectedObjects->findNode(object);
  1776. if (nodep && te < (S32)nodep->mSavedColors.size())
  1777. {
  1778. LLColor4 color = nodep->mSavedColors[te];
  1779. // Update viewer side color in anticipation of update from
  1780. // simulator
  1781. object->setTEColor(te, color);
  1782. }
  1783. }
  1784. return true;
  1785. }
  1786. } setfunc(mSelectedObjects);
  1787. getSelection()->applyToTEs(&setfunc);
  1788. LLSelectMgrSendFunctor sendfunc;
  1789. getSelection()->applyToObjects(&sendfunc);
  1790. }
  1791. bool LLSelectMgr::selectionRevertTextures()
  1792. {
  1793. struct f final : public LLSelectedTEFunctor
  1794. {
  1795. LLObjectSelectionHandle mSelectedObjects;
  1796. f(LLObjectSelectionHandle sel)
  1797. : mSelectedObjects(sel)
  1798. {
  1799. }
  1800. bool apply(LLViewerObject* objectp, S32 te) override
  1801. {
  1802. if (!objectp || !objectp->permModify())
  1803. {
  1804. return true; // Ignore no-mod primitive
  1805. }
  1806. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  1807. if (!nodep || te >= (S32)nodep->mSavedTextures.size())
  1808. {
  1809. return true; // Ignore missing node or out of range te
  1810. }
  1811. const LLUUID& id = nodep->mSavedTextures[te];
  1812. if (id.isNull())
  1813. {
  1814. // This was probably a no-copy texture, leave image as-is and
  1815. // report a failure.
  1816. return false;
  1817. }
  1818. LLViewerTexture* texp =
  1819. LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT,
  1820. true,
  1821. LLGLTexture::BOOST_NONE,
  1822. LLViewerTexture::LOD_TEXTURE);
  1823. if (!texp) // Paranoia ?
  1824. {
  1825. // Report a failure. HB
  1826. return false;
  1827. }
  1828. // Update textures on viewer side
  1829. objectp->setTEImage(te, texp);
  1830. return true;
  1831. }
  1832. } setfunc(mSelectedObjects);
  1833. bool revert_successful = getSelection()->applyToTEs(&setfunc);
  1834. LLSelectMgrSendFunctor sendfunc;
  1835. getSelection()->applyToObjects(&sendfunc);
  1836. return revert_successful;
  1837. }
  1838. void LLSelectMgr::selectionRevertGLTFMaterials()
  1839. {
  1840. struct f final : public LLSelectedTEFunctor
  1841. {
  1842. LLObjectSelectionHandle mSelectedObjects;
  1843. f(LLObjectSelectionHandle sel)
  1844. : mSelectedObjects(sel)
  1845. {
  1846. }
  1847. bool apply(LLViewerObject* objectp, S32 te) override
  1848. {
  1849. if (!objectp || !objectp->permModify())
  1850. {
  1851. return true; // Ignore no-mod primitive
  1852. }
  1853. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  1854. if (!nodep || te >= (S32)nodep->mSavedGLTFMaterialIds.size())
  1855. {
  1856. return true; // Ignore missing node or out of range te
  1857. }
  1858. const LLUUID& asset_id = nodep->mSavedGLTFMaterialIds[te];
  1859. LLGLTFMaterial* matp =
  1860. nodep->mSavedGLTFOverrideMaterials[te].get();
  1861. // Update material locally
  1862. objectp->setRenderMaterialID(te, asset_id, false);
  1863. objectp->setTEGLTFMaterialOverride(te, matp);
  1864. // Enqueue update to server
  1865. if (asset_id.notNull())
  1866. {
  1867. // Restore overrides and base material
  1868. LLGLTFMaterialList::queueApply(objectp, te, asset_id, matp);
  1869. }
  1870. else
  1871. {
  1872. // Blank override out
  1873. LLGLTFMaterialList::queueApply(objectp, te, asset_id);
  1874. }
  1875. return true;
  1876. }
  1877. } setfunc(mSelectedObjects);
  1878. getSelection()->applyToTEs(&setfunc);
  1879. }
  1880. void LLSelectMgr::selectionSetTexGen(U8 texgen)
  1881. {
  1882. struct f final : public LLSelectedTEFunctor
  1883. {
  1884. f(U8 t)
  1885. : mTexgen(t)
  1886. {
  1887. }
  1888. bool apply(LLViewerObject* objectp, S32 te) override
  1889. {
  1890. if (objectp->permModify())
  1891. {
  1892. // Update viewer side tex gen in anticipation of update from
  1893. // simulator
  1894. objectp->setTETexGen(te, mTexgen);
  1895. }
  1896. return true;
  1897. }
  1898. U8 mTexgen;
  1899. } setfunc(texgen);
  1900. getSelection()->applyToTEs(&setfunc);
  1901. LLSelectMgrSendFunctor sendfunc;
  1902. getSelection()->applyToObjects(&sendfunc);
  1903. }
  1904. void LLSelectMgr::selectionSetBumpmap(U8 bumpmap)
  1905. {
  1906. struct f final : public LLSelectedTEFunctor
  1907. {
  1908. f(U8 b)
  1909. : mBump(b)
  1910. {
  1911. }
  1912. bool apply(LLViewerObject* objectp, S32 te) override
  1913. {
  1914. if (objectp->permModify())
  1915. {
  1916. // Update viewer side bump map in anticipation of update from
  1917. // simulator
  1918. objectp->setTEBumpmap(te, mBump);
  1919. }
  1920. return true;
  1921. }
  1922. U8 mBump;
  1923. } setfunc(bumpmap);
  1924. getSelection()->applyToTEs(&setfunc);
  1925. LLSelectMgrSendFunctor sendfunc;
  1926. getSelection()->applyToObjects(&sendfunc);
  1927. }
  1928. void LLSelectMgr::selectionSetShiny(U8 shiny)
  1929. {
  1930. struct f final : public LLSelectedTEFunctor
  1931. {
  1932. f(U8 t)
  1933. : mShiny(t)
  1934. {
  1935. }
  1936. bool apply(LLViewerObject* objectp, S32 te) override
  1937. {
  1938. if (objectp->permModify())
  1939. {
  1940. // Update viewer side shiny in anticipation of update from
  1941. // simulator
  1942. objectp->setTEShiny(te, mShiny);
  1943. }
  1944. return true;
  1945. }
  1946. U8 mShiny;
  1947. } setfunc(shiny);
  1948. getSelection()->applyToTEs(&setfunc);
  1949. LLSelectMgrSendFunctor sendfunc;
  1950. getSelection()->applyToObjects(&sendfunc);
  1951. }
  1952. void LLSelectMgr::selectionSetFullbright(U8 fullbright)
  1953. {
  1954. struct f final : public LLSelectedTEFunctor
  1955. {
  1956. f(U8 t)
  1957. : mFullbright(t)
  1958. {
  1959. }
  1960. bool apply(LLViewerObject* objectp, S32 te) override
  1961. {
  1962. if (objectp->permModify())
  1963. {
  1964. // Update viewer side full bright in anticipation of update
  1965. // from simulator
  1966. objectp->setTEFullbright(te, mFullbright);
  1967. }
  1968. return true;
  1969. }
  1970. U8 mFullbright;
  1971. } setfunc(fullbright);
  1972. getSelection()->applyToTEs(&setfunc);
  1973. struct g final : public LLSelectedObjectFunctor
  1974. {
  1975. g(U8 t)
  1976. : mFullbright(t)
  1977. {
  1978. }
  1979. bool apply(LLViewerObject* objectp) override
  1980. {
  1981. if (objectp->permModify())
  1982. {
  1983. objectp->sendTEUpdate();
  1984. if (mFullbright)
  1985. {
  1986. U8 material = objectp->getMaterial();
  1987. U8 mcode = material & LL_MCODE_MASK;
  1988. if (mcode == LL_MCODE_LIGHT)
  1989. {
  1990. mcode = LL_MCODE_GLASS;
  1991. material = (material & ~LL_MCODE_MASK) | mcode;
  1992. objectp->setMaterial(material);
  1993. objectp->sendMaterialUpdate();
  1994. }
  1995. }
  1996. }
  1997. return true;
  1998. }
  1999. U8 mFullbright;
  2000. } sendfunc(fullbright);
  2001. getSelection()->applyToObjects(&sendfunc);
  2002. }
  2003. // This function expects media_data to be a map containing relevant media data
  2004. // name/value pairs (e.g. home_url, etc).
  2005. void LLSelectMgr::selectionSetMedia(U8 media_type, const LLSD& media_data)
  2006. {
  2007. struct f final : public LLSelectedTEFunctor
  2008. {
  2009. f(U8 t, const LLSD& d)
  2010. : mMediaFlags(t),
  2011. mMediaData(d)
  2012. {
  2013. }
  2014. bool apply(LLViewerObject* objectp, S32 te) override
  2015. {
  2016. if (!objectp || !objectp->permModify())
  2017. {
  2018. return true;
  2019. }
  2020. // If we are removing media, just do it (ignore the passed-in
  2021. // LLSD).
  2022. if (!(mMediaFlags & LLTextureEntry::MF_HAS_MEDIA))
  2023. {
  2024. // Delete media (or just set the flags)
  2025. objectp->setTEMediaFlags(te, mMediaFlags);
  2026. return true;
  2027. }
  2028. // If we are adding media, then check the current state of the
  2029. // media data on this face.
  2030. // - If it does not have media, AND we are NOT setting the
  2031. // HOME URL, then do NOT add media to this face.
  2032. // - If it does not have media, and we ARE setting the HOME URL,
  2033. // add media to this face.
  2034. // - If it does already have media, add/update media to/on this
  2035. // face.
  2036. llassert(mMediaData.isMap());
  2037. const LLTextureEntry* tep = objectp->getTE(te);
  2038. if (!mMediaData.isMap() ||
  2039. (tep && !tep->hasMedia() &&
  2040. !mMediaData.has(LLMediaEntry::HOME_URL_KEY)))
  2041. {
  2042. // Skip adding/updating media
  2043. return true;
  2044. }
  2045. // Add/update media
  2046. objectp->setTEMediaFlags(te, mMediaFlags);
  2047. LLVOVolume* vovolp = objectp->asVolume();
  2048. if (vovolp)
  2049. {
  2050. // 1st true = merge, 2nd true = ignore_agent
  2051. vovolp->syncMediaData(te, mMediaData, true, true);
  2052. }
  2053. else
  2054. {
  2055. llwarns << "Trying to add/update media on non-LLVOVolume !"
  2056. << llendl;
  2057. }
  2058. return true;
  2059. }
  2060. const LLSD& mMediaData;
  2061. U8 mMediaFlags;
  2062. } setfunc(media_type, media_data);
  2063. getSelection()->applyToTEs(&setfunc);
  2064. struct f2 final : public LLSelectedObjectFunctor
  2065. {
  2066. bool apply(LLViewerObject* objectp) override
  2067. {
  2068. if (objectp && objectp->permModify())
  2069. {
  2070. objectp->sendTEUpdate();
  2071. LLVOVolume* vovolp = objectp->asVolume();
  2072. // It is okay to skip this object if hasMedia() is false...
  2073. // the sendTEUpdate() above would remove all media data if it
  2074. // were there.
  2075. if (vovolp && vovolp->hasMedia())
  2076. {
  2077. // Send updated media data FOR THE ENTIRE OBJECT
  2078. vovolp->sendMediaDataUpdate();
  2079. }
  2080. }
  2081. return true;
  2082. }
  2083. } func2;
  2084. mSelectedObjects->applyToObjects(&func2);
  2085. }
  2086. void LLSelectMgr::selectionSetGlow(F32 glow)
  2087. {
  2088. struct f1 final : public LLSelectedTEFunctor
  2089. {
  2090. f1(F32 glow)
  2091. : mGlow(glow)
  2092. {
  2093. }
  2094. bool apply(LLViewerObject* objectp, S32 face) override
  2095. {
  2096. if (objectp->permModify())
  2097. {
  2098. // Update viewer side glow in anticipation of update from
  2099. // simulator
  2100. objectp->setTEGlow(face, mGlow);
  2101. }
  2102. return true;
  2103. }
  2104. F32 mGlow;
  2105. } func1(glow);
  2106. mSelectedObjects->applyToTEs(&func1);
  2107. struct f2 final : public LLSelectedObjectFunctor
  2108. {
  2109. bool apply(LLViewerObject* objectp) override
  2110. {
  2111. if (objectp->permModify())
  2112. {
  2113. objectp->sendTEUpdate();
  2114. }
  2115. return true;
  2116. }
  2117. } func2;
  2118. mSelectedObjects->applyToObjects(&func2);
  2119. }
  2120. void LLSelectMgr::selectionSetMaterialParams(LLSelectedTEMaterialFunctor* mat_fnp,
  2121. S32 te)
  2122. {
  2123. struct f1 final : public LLSelectedTEFunctor
  2124. {
  2125. f1(LLSelectedTEMaterialFunctor* mat_fnp, S32 te)
  2126. : mMaterialFunc(mat_fnp),
  2127. mTE(te)
  2128. {
  2129. }
  2130. bool apply(LLViewerObject* objectp, S32 te) override
  2131. {
  2132. if (mTE != -1 && te != mTE)
  2133. {
  2134. return true;
  2135. }
  2136. if (objectp && objectp->permModify() && mMaterialFunc)
  2137. {
  2138. LLTextureEntry* tep = objectp->getTE(te);
  2139. if (tep)
  2140. {
  2141. LLMaterialPtr current_material = tep->getMaterialParams();
  2142. mMaterialFunc->apply(objectp, te, tep, current_material);
  2143. }
  2144. }
  2145. return true;
  2146. }
  2147. LLMaterialPtr mMaterial;
  2148. LLSelectedTEMaterialFunctor* mMaterialFunc;
  2149. S32 mTE;
  2150. } func1(mat_fnp, te);
  2151. mSelectedObjects->applyToTEs(&func1);
  2152. struct f2 final : public LLSelectedObjectFunctor
  2153. {
  2154. bool apply(LLViewerObject* objectp) override
  2155. {
  2156. if (objectp->permModify())
  2157. {
  2158. objectp->sendTEUpdate();
  2159. }
  2160. return true;
  2161. }
  2162. } func2;
  2163. mSelectedObjects->applyToObjects(&func2);
  2164. }
  2165. #if 1
  2166. void LLSelectMgr::selectionSetMaterials(LLMaterialPtr material)
  2167. {
  2168. struct f1 final : public LLSelectedTEFunctor
  2169. {
  2170. LLMaterialPtr mMaterial;
  2171. f1(LLMaterialPtr material) : mMaterial(material) {}
  2172. bool apply(LLViewerObject* objectp, S32 face) override
  2173. {
  2174. if (objectp->permModify())
  2175. {
  2176. LL_DEBUGS("Materials") << "Putting material on object "
  2177. << objectp->getID() << ", face "
  2178. << face << ", material: "
  2179. << mMaterial->asLLSD() << LL_ENDL;
  2180. LLMaterialMgr::getInstance()->put(objectp->getID(), face,
  2181. *mMaterial);
  2182. objectp->setTEMaterialParams(face, mMaterial);
  2183. }
  2184. return true;
  2185. }
  2186. } func1(material);
  2187. mSelectedObjects->applyToTEs(&func1);
  2188. struct f2 final : public LLSelectedObjectFunctor
  2189. {
  2190. bool apply(LLViewerObject* objectp) override
  2191. {
  2192. if (objectp->permModify())
  2193. {
  2194. objectp->sendTEUpdate();
  2195. }
  2196. return true;
  2197. }
  2198. } func2;
  2199. mSelectedObjects->applyToObjects(&func2);
  2200. }
  2201. #endif
  2202. void LLSelectMgr::selectionRemoveMaterial()
  2203. {
  2204. struct f1 final : public LLSelectedTEFunctor
  2205. {
  2206. bool apply(LLViewerObject* objectp, S32 face) override
  2207. {
  2208. if (objectp->permModify())
  2209. {
  2210. LL_DEBUGS("Materials") << "Removing material from object "
  2211. << objectp->getID() << ", face " << face
  2212. << LL_ENDL;
  2213. LLMaterialMgr::getInstance()->remove(objectp->getID(), face);
  2214. objectp->setTEMaterialParams(face, NULL);
  2215. }
  2216. return true;
  2217. }
  2218. } func1;
  2219. mSelectedObjects->applyToTEs(&func1);
  2220. struct f2 final : public LLSelectedObjectFunctor
  2221. {
  2222. bool apply(LLViewerObject* objectp) override
  2223. {
  2224. if (objectp->permModify())
  2225. {
  2226. objectp->sendTEUpdate();
  2227. }
  2228. return true;
  2229. }
  2230. } func2;
  2231. mSelectedObjects->applyToObjects(&func2);
  2232. }
  2233. LLPermissions* LLSelectMgr::findObjectPermissions(const LLViewerObject* objp)
  2234. {
  2235. for (LLObjectSelection::valid_iterator
  2236. iter = getSelection()->valid_begin(),
  2237. end = getSelection()->valid_end();
  2238. iter != end; ++iter)
  2239. {
  2240. LLSelectNode* nodep = *iter;
  2241. if (nodep && nodep->getObject() == objp)
  2242. {
  2243. return nodep->mPermissions;
  2244. }
  2245. }
  2246. return NULL;
  2247. }
  2248. bool LLSelectMgr::selectionGetGlow(F32* glow)
  2249. {
  2250. bool identical;
  2251. F32 lglow = 0.f;
  2252. struct f1 final : public LLSelectedTEGetFunctor<F32>
  2253. {
  2254. F32 get(LLViewerObject* object, S32 face) override
  2255. {
  2256. LLTextureEntry* tep = object->getTE(face);
  2257. return tep ? tep->getGlow() : 0.f;
  2258. }
  2259. } func;
  2260. identical = mSelectedObjects->getSelectedTEValue(&func, lglow);
  2261. *glow = lglow;
  2262. return identical;
  2263. }
  2264. void LLSelectMgr::selectionSetPhysicsType(U8 type)
  2265. {
  2266. struct f final : public LLSelectedObjectFunctor
  2267. {
  2268. f(const U8& t)
  2269. : mType(t)
  2270. {
  2271. }
  2272. bool apply(LLViewerObject* objectp) override
  2273. {
  2274. if (objectp->permModify())
  2275. {
  2276. objectp->setPhysicsShapeType(mType);
  2277. objectp->updateFlags(true);
  2278. }
  2279. return true;
  2280. }
  2281. U8 mType;
  2282. } sendfunc(type);
  2283. getSelection()->applyToObjects(&sendfunc);
  2284. }
  2285. void LLSelectMgr::selectionSetFriction(F32 friction)
  2286. {
  2287. struct f final : public LLSelectedObjectFunctor
  2288. {
  2289. f(const F32& friction)
  2290. : mFriction(friction)
  2291. {
  2292. }
  2293. bool apply(LLViewerObject* objectp) override
  2294. {
  2295. if (objectp->permModify())
  2296. {
  2297. objectp->setPhysicsFriction(mFriction);
  2298. objectp->updateFlags(true);
  2299. }
  2300. return true;
  2301. }
  2302. F32 mFriction;
  2303. } sendfunc(friction);
  2304. getSelection()->applyToObjects(&sendfunc);
  2305. }
  2306. void LLSelectMgr::selectionSetGravity(F32 gravity)
  2307. {
  2308. struct f final : public LLSelectedObjectFunctor
  2309. {
  2310. f(const F32& gravity)
  2311. : mGravity(gravity)
  2312. {
  2313. }
  2314. bool apply(LLViewerObject* objectp) override
  2315. {
  2316. if (objectp->permModify())
  2317. {
  2318. objectp->setPhysicsGravity(mGravity);
  2319. objectp->updateFlags(true);
  2320. }
  2321. return true;
  2322. }
  2323. F32 mGravity;
  2324. } sendfunc(gravity);
  2325. getSelection()->applyToObjects(&sendfunc);
  2326. }
  2327. void LLSelectMgr::selectionSetDensity(F32 density)
  2328. {
  2329. struct f final : public LLSelectedObjectFunctor
  2330. {
  2331. f(const F32& density)
  2332. : mDensity(density)
  2333. {
  2334. }
  2335. bool apply(LLViewerObject* objectp) override
  2336. {
  2337. if (objectp->permModify())
  2338. {
  2339. objectp->setPhysicsDensity(mDensity);
  2340. objectp->updateFlags(true);
  2341. }
  2342. return true;
  2343. }
  2344. F32 mDensity;
  2345. } sendfunc(density);
  2346. getSelection()->applyToObjects(&sendfunc);
  2347. }
  2348. void LLSelectMgr::selectionSetRestitution(F32 restitution)
  2349. {
  2350. struct f final : public LLSelectedObjectFunctor
  2351. {
  2352. f(const F32& restitution)
  2353. : mRestitution(restitution)
  2354. {
  2355. }
  2356. bool apply(LLViewerObject* objectp) override
  2357. {
  2358. if (objectp->permModify())
  2359. {
  2360. objectp->setPhysicsRestitution(mRestitution);
  2361. objectp->updateFlags(true);
  2362. }
  2363. return true;
  2364. }
  2365. F32 mRestitution;
  2366. } sendfunc(restitution);
  2367. getSelection()->applyToObjects(&sendfunc);
  2368. }
  2369. void LLSelectMgr::selectionSetMaterial(U8 material)
  2370. {
  2371. struct f final : public LLSelectedObjectFunctor
  2372. {
  2373. f(const U8& t)
  2374. : mMaterial(t)
  2375. {
  2376. }
  2377. bool apply(LLViewerObject* objectp) override
  2378. {
  2379. if (objectp->permModify())
  2380. {
  2381. U8 cur_material = objectp->getMaterial();
  2382. U8 material = mMaterial | (cur_material & ~LL_MCODE_MASK);
  2383. objectp->setMaterial(material);
  2384. objectp->sendMaterialUpdate();
  2385. }
  2386. return true;
  2387. }
  2388. U8 mMaterial;
  2389. } sendfunc(material);
  2390. getSelection()->applyToObjects(&sendfunc);
  2391. }
  2392. // Returns true if all selected objects have this PCode
  2393. bool LLSelectMgr::selectionAllPCode(LLPCode code)
  2394. {
  2395. struct f final : public LLSelectedObjectFunctor
  2396. {
  2397. f(LLPCode t)
  2398. : mCode(t)
  2399. {
  2400. }
  2401. bool apply(LLViewerObject* objectp) override
  2402. {
  2403. return objectp->getPCode() == mCode;
  2404. }
  2405. LLPCode mCode;
  2406. } func(code);
  2407. return getSelection()->applyToObjects(&func);
  2408. }
  2409. bool LLSelectMgr::selectionGetIncludeInSearch(bool* include_in_search_out)
  2410. {
  2411. LLViewerObject* objectp = mSelectedObjects->getFirstRootObject();
  2412. if (!objectp)
  2413. {
  2414. return false;
  2415. }
  2416. bool include_in_search = objectp->getIncludeInSearch();
  2417. bool identical = true;
  2418. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2419. end = getSelection()->root_end();
  2420. iter != end; ++iter)
  2421. {
  2422. objectp = (*iter)->getObject();
  2423. if (objectp && include_in_search != objectp->getIncludeInSearch())
  2424. {
  2425. identical = false;
  2426. break;
  2427. }
  2428. }
  2429. *include_in_search_out = include_in_search;
  2430. return identical;
  2431. }
  2432. void LLSelectMgr::selectionSetIncludeInSearch(bool include_in_search)
  2433. {
  2434. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2435. end = getSelection()->root_end();
  2436. iter != end; ++iter)
  2437. {
  2438. LLViewerObject* objectp = (*iter)->getObject();
  2439. objectp->setIncludeInSearch(include_in_search);
  2440. }
  2441. sendListToRegions("ObjectIncludeInSearch", packAgentAndSessionID,
  2442. packObjectIncludeInSearch, &include_in_search,
  2443. SEND_ONLY_ROOTS);
  2444. }
  2445. bool LLSelectMgr::selectionGetClickAction(U8* out_action)
  2446. {
  2447. LLViewerObject* object = mSelectedObjects->getFirstObject();
  2448. if (!object)
  2449. {
  2450. return false;
  2451. }
  2452. U8 action = object->getClickAction();
  2453. *out_action = action;
  2454. struct f final : public LLSelectedObjectFunctor
  2455. {
  2456. f(const U8& t)
  2457. : mAction(t)
  2458. {
  2459. }
  2460. bool apply(LLViewerObject* objectp) override
  2461. {
  2462. return mAction == objectp->getClickAction();
  2463. }
  2464. U8 mAction;
  2465. } func(action);
  2466. return getSelection()->applyToObjects(&func);
  2467. }
  2468. void LLSelectMgr::selectionSetClickAction(U8 action)
  2469. {
  2470. struct f final : public LLSelectedObjectFunctor
  2471. {
  2472. f(const U8& t)
  2473. : mAction(t)
  2474. {
  2475. }
  2476. bool apply(LLViewerObject* objectp) override
  2477. {
  2478. objectp->setClickAction(mAction);
  2479. return true;
  2480. }
  2481. U8 mAction;
  2482. } func(action);
  2483. getSelection()->applyToObjects(&func);
  2484. sendListToRegions("ObjectClickAction", packAgentAndSessionID,
  2485. packObjectClickAction, &action, SEND_INDIVIDUALS);
  2486. }
  2487. typedef std::pair<const std::string, const std::string> godlike_request_t;
  2488. void LLSelectMgr::sendGodlikeRequest(const std::string& request,
  2489. const std::string& param)
  2490. {
  2491. // If the agent is neither godlike nor an estate owner, the server
  2492. // will reject the request.
  2493. std::string message_type;
  2494. if (gAgent.isGodlike())
  2495. {
  2496. message_type = "GodlikeMessage";
  2497. }
  2498. else
  2499. {
  2500. message_type = "EstateOwnerMessage";
  2501. }
  2502. godlike_request_t data(request, param);
  2503. if (!mSelectedObjects->getRootObjectCount())
  2504. {
  2505. LLMessageSystem* msg = gMessageSystemp;
  2506. msg->newMessage(message_type.c_str());
  2507. LLSelectMgr::packGodlikeHead(&data);
  2508. gAgent.sendReliableMessage();
  2509. }
  2510. else
  2511. {
  2512. sendListToRegions(message_type, packGodlikeHead, packObjectIDAsParam,
  2513. &data, SEND_ONLY_ROOTS);
  2514. }
  2515. }
  2516. void LLSelectMgr::packGodlikeHead(void* user_data)
  2517. {
  2518. LLMessageSystem* msg = gMessageSystemp;
  2519. msg->nextBlockFast(_PREHASH_AgentData);
  2520. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  2521. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  2522. msg->addUUID("TransactionID", LLUUID::null);
  2523. godlike_request_t* data = (godlike_request_t*)user_data;
  2524. msg->nextBlock("MethodData");
  2525. msg->addString("Method", data->first);
  2526. msg->addUUID("Invoice", LLUUID::null);
  2527. // The parameters used to be restricted to either string or integer. This
  2528. // mimics that behavior under the new 'string-only' parameter list by not
  2529. // packing a string if there was not one specified. The object ids will be
  2530. // packed in the packObjectIDAsParam() method.
  2531. if (data->second.size() > 0)
  2532. {
  2533. msg->nextBlock("ParamList");
  2534. msg->addString("Parameter", data->second);
  2535. }
  2536. }
  2537. //static
  2538. void LLSelectMgr::packObjectIDAsParam(LLSelectNode* node, void*)
  2539. {
  2540. std::string buf = llformat("%u", node->getObject()->getLocalID());
  2541. LLMessageSystem* msg = gMessageSystemp;
  2542. msg->nextBlock("ParamList");
  2543. msg->addString("Parameter", buf);
  2544. }
  2545. void LLSelectMgr::selectionTexScaleAutofit(F32 repeats_per_meter)
  2546. {
  2547. struct f final : public LLSelectedTEFunctor
  2548. {
  2549. F32 mRepeatsPerMeter;
  2550. f(const F32& t) : mRepeatsPerMeter(t) {}
  2551. bool apply(LLViewerObject* object, S32 te) override
  2552. {
  2553. if (object->permModify())
  2554. {
  2555. // Compute S,T to axis mapping
  2556. U32 s_axis, t_axis;
  2557. if (!LLPrimitive::getTESTAxes(te, &s_axis, &t_axis))
  2558. {
  2559. return true;
  2560. }
  2561. F32 new_s = object->getScale().mV[s_axis] * mRepeatsPerMeter;
  2562. F32 new_t = object->getScale().mV[t_axis] * mRepeatsPerMeter;
  2563. object->setTEScale(te, new_s, new_t);
  2564. }
  2565. return true;
  2566. }
  2567. } setfunc(repeats_per_meter);
  2568. getSelection()->applyToTEs(&setfunc);
  2569. LLSelectMgrSendFunctor sendfunc;
  2570. getSelection()->applyToObjects(&sendfunc);
  2571. }
  2572. // Called at the end of a scale operation, this adjusts the textures to attempt
  2573. // to maintain a constant repeats per meter.
  2574. // BUG: Only works for flex boxes.
  2575. void LLSelectMgr::adjustTexturesByScale(bool send_to_sim, bool stretch)
  2576. {
  2577. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2578. end = getSelection()->end();
  2579. iter != end; ++iter)
  2580. {
  2581. LLSelectNode* nodep = *iter;
  2582. LLViewerObject* object = nodep->getObject();
  2583. if (!object || !object->permModify() || object->getNumTEs() == 0)
  2584. {
  2585. continue;
  2586. }
  2587. bool send = false;
  2588. for (U8 te_num = 0, count = object->getNumTEs(); te_num < count;
  2589. te_num++)
  2590. {
  2591. LLTextureEntry* tep = object->getTE(te_num);
  2592. if (!tep) continue;
  2593. bool planar = tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR;
  2594. if (planar != stretch)
  2595. {
  2596. continue;
  2597. }
  2598. // Figure out how S,T changed with scale operation
  2599. U32 s_axis, t_axis;
  2600. if (!LLPrimitive::getTESTAxes(te_num, &s_axis, &t_axis))
  2601. {
  2602. continue;
  2603. }
  2604. send = send_to_sim;
  2605. LLVector3 object_scale = object->getScale();
  2606. F32 obj_scal_s = object_scale.mV[s_axis];
  2607. F32 obj_scal_t = object_scale.mV[t_axis];
  2608. LLVector3 scale_ratio = nodep->mTextureScaleRatios[te_num];
  2609. F32 scale_s, scale_t;
  2610. if (planar)
  2611. {
  2612. scale_s = scale_ratio.mV[s_axis] / obj_scal_s;
  2613. scale_t = scale_ratio.mV[t_axis] / obj_scal_t;
  2614. }
  2615. else
  2616. {
  2617. scale_s = scale_ratio.mV[s_axis] * obj_scal_s;
  2618. scale_t = scale_ratio.mV[t_axis] * obj_scal_t;
  2619. }
  2620. // Apply new scale to face
  2621. object->setTEScale(te_num, scale_s, scale_t);
  2622. if (tep->getMaterialParams().notNull())
  2623. {
  2624. LLMaterialPtr orig = tep->getMaterialParams();
  2625. LLMaterialPtr p =
  2626. gFloaterToolsp->getPanelFace()->createDefaultMaterial(orig);
  2627. p->setNormalRepeat(scale_s, scale_t);
  2628. p->setSpecularRepeat(scale_s, scale_t);
  2629. LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p);
  2630. }
  2631. // PBR material scaling
  2632. if (!tep->getGLTFMaterial())
  2633. {
  2634. continue;
  2635. }
  2636. LLPointer<LLGLTFMaterial> matp = tep->getGLTFMaterialOverride();
  2637. if (matp.isNull())
  2638. {
  2639. matp = new LLGLTFMaterial();
  2640. tep->setGLTFMaterialOverride(matp);
  2641. }
  2642. scale_s = scale_t = 1.f;
  2643. for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
  2644. {
  2645. LLVector3 scale_ratio = nodep->mGLTFScaleRatios[te_num][i];
  2646. if (planar)
  2647. {
  2648. scale_s = scale_ratio.mV[s_axis] / obj_scal_s;
  2649. scale_t = scale_ratio.mV[t_axis] / obj_scal_t;
  2650. }
  2651. else
  2652. {
  2653. scale_s = scale_ratio.mV[s_axis] * obj_scal_s;
  2654. scale_t = scale_ratio.mV[t_axis] * obj_scal_t;
  2655. }
  2656. matp->mTextureTransform[i].mScale.set(scale_s, scale_t);
  2657. }
  2658. LLFetchedGLTFMaterial* rmatp =
  2659. (LLFetchedGLTFMaterial*)tep->getGLTFRenderMaterial();
  2660. if (rmatp)
  2661. {
  2662. rmatp->applyOverride(*matp);
  2663. }
  2664. if (send_to_sim)
  2665. {
  2666. LLGLTFMaterialList::queueModify(object, te_num, matp);
  2667. }
  2668. }
  2669. if (send)
  2670. {
  2671. object->sendTEUpdate();
  2672. }
  2673. }
  2674. }
  2675. bool LLSelectMgr::selectionIsAvatarAttachment()
  2676. {
  2677. return mSelectedObjects->mSelectType == SELECT_TYPE_ATTACHMENT &&
  2678. mSelectedObjects->getObjectCount();
  2679. }
  2680. // Returns true if the viewer has information on all selected objects
  2681. bool LLSelectMgr::selectGetAllRootsValid()
  2682. {
  2683. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2684. end = getSelection()->root_end();
  2685. iter != end; ++iter)
  2686. {
  2687. LLSelectNode* node = *iter;
  2688. if (!node->mValid)
  2689. {
  2690. return false;
  2691. }
  2692. }
  2693. return true;
  2694. }
  2695. // Returns true if the viewer has information on all selected objects
  2696. bool LLSelectMgr::selectGetAllValid()
  2697. {
  2698. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2699. end = getSelection()->end();
  2700. iter != end; ++iter)
  2701. {
  2702. LLSelectNode* node = *iter;
  2703. if (!node->mValid)
  2704. {
  2705. return false;
  2706. }
  2707. }
  2708. return true;
  2709. }
  2710. // Returns true if current agent can modify all selected objects.
  2711. bool LLSelectMgr::selectGetModify()
  2712. {
  2713. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2714. end = getSelection()->end();
  2715. iter != end; ++iter)
  2716. {
  2717. LLSelectNode* node = *iter;
  2718. LLViewerObject* object = node->getObject();
  2719. if (!object || !node->mValid || !object->permModify())
  2720. {
  2721. return false;
  2722. }
  2723. }
  2724. return true;
  2725. }
  2726. // Returns true if current agent can modify all selected root objects.
  2727. bool LLSelectMgr::selectGetRootsModify()
  2728. {
  2729. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2730. end = getSelection()->root_end();
  2731. iter != end; ++iter)
  2732. {
  2733. LLSelectNode* node = *iter;
  2734. LLViewerObject* object = node->getObject();
  2735. if (!node->mValid || !object->permModify())
  2736. {
  2737. return false;
  2738. }
  2739. }
  2740. return true;
  2741. }
  2742. // Returns true if all objects are not permanent enforced
  2743. bool LLSelectMgr::selectGetNonPermanentEnforced()
  2744. {
  2745. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2746. end = getSelection()->end();
  2747. iter != end; ++iter)
  2748. {
  2749. LLSelectNode* node = *iter;
  2750. LLViewerObject* object = node->getObject();
  2751. if (!node->mValid || !object || object->isPermanentEnforced())
  2752. {
  2753. return false;
  2754. }
  2755. }
  2756. return true;
  2757. }
  2758. // Returns true if all root objects are not permanent enforced
  2759. bool LLSelectMgr::selectGetRootsNonPermanentEnforced()
  2760. {
  2761. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2762. end = getSelection()->root_end();
  2763. iter != end; ++iter)
  2764. {
  2765. LLSelectNode* node = *iter;
  2766. LLViewerObject* object = node->getObject();
  2767. if (!node->mValid || !object || object->isPermanentEnforced())
  2768. {
  2769. return false;
  2770. }
  2771. }
  2772. return true;
  2773. }
  2774. // Returns true if all objects are permanent
  2775. bool LLSelectMgr::selectGetPermanent()
  2776. {
  2777. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2778. end = getSelection()->end();
  2779. iter != end; ++iter)
  2780. {
  2781. LLSelectNode* node = *iter;
  2782. LLViewerObject* object = node->getObject();
  2783. if (!node->mValid || !object || !object->flagObjectPermanent())
  2784. {
  2785. return false;
  2786. }
  2787. }
  2788. return true;
  2789. }
  2790. // Returns true if all root objects are permanent
  2791. bool LLSelectMgr::selectGetRootsPermanent()
  2792. {
  2793. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2794. end = getSelection()->root_end();
  2795. iter != end; ++iter)
  2796. {
  2797. LLSelectNode* node = *iter;
  2798. LLViewerObject* object = node->getObject();
  2799. if (!node->mValid || !object || !object->flagObjectPermanent())
  2800. {
  2801. return false;
  2802. }
  2803. }
  2804. return true;
  2805. }
  2806. // Return true if all objects are characters
  2807. bool LLSelectMgr::selectGetCharacter()
  2808. {
  2809. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2810. end = getSelection()->end();
  2811. iter != end; ++iter)
  2812. {
  2813. LLSelectNode* node = *iter;
  2814. LLViewerObject* object = node->getObject();
  2815. if (!node->mValid || !object || !object->flagCharacter())
  2816. {
  2817. return false;
  2818. }
  2819. }
  2820. return true;
  2821. }
  2822. // Returns true if all root objects are characters
  2823. bool LLSelectMgr::selectGetRootsCharacter()
  2824. {
  2825. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2826. end = getSelection()->root_end();
  2827. iter != end; ++iter)
  2828. {
  2829. LLSelectNode* node = *iter;
  2830. LLViewerObject* object = node->getObject();
  2831. if (!node->mValid || !object || !object->flagCharacter())
  2832. {
  2833. return false;
  2834. }
  2835. }
  2836. return true;
  2837. }
  2838. // Returns true if all objects are not pathfinding
  2839. bool LLSelectMgr::selectGetNonPathfinding()
  2840. {
  2841. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2842. end = getSelection()->end();
  2843. iter != end; ++iter)
  2844. {
  2845. LLSelectNode* node = *iter;
  2846. LLViewerObject* object = node->getObject();
  2847. if (!node->mValid || !object || object->flagObjectPermanent() ||
  2848. object->flagCharacter())
  2849. {
  2850. return false;
  2851. }
  2852. }
  2853. return true;
  2854. }
  2855. // Returns true if all root objects are not pathfinding
  2856. bool LLSelectMgr::selectGetRootsNonPathfinding()
  2857. {
  2858. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2859. end = getSelection()->root_end();
  2860. iter != end; ++iter)
  2861. {
  2862. LLSelectNode* node = *iter;
  2863. LLViewerObject* object = node->getObject();
  2864. if (!node->mValid || !object || object->flagObjectPermanent() ||
  2865. object->flagCharacter())
  2866. {
  2867. return false;
  2868. }
  2869. }
  2870. return true;
  2871. }
  2872. // Return true if all objects are not permanent
  2873. bool LLSelectMgr::selectGetNonPermanent()
  2874. {
  2875. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2876. end = getSelection()->end();
  2877. iter != end; ++iter)
  2878. {
  2879. LLSelectNode* node = *iter;
  2880. LLViewerObject* object = node->getObject();
  2881. if (!node->mValid || !object || object->flagObjectPermanent())
  2882. {
  2883. return false;
  2884. }
  2885. }
  2886. return true;
  2887. }
  2888. // Returns true if all root objects are not permanent
  2889. bool LLSelectMgr::selectGetRootsNonPermanent()
  2890. {
  2891. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2892. end = getSelection()->root_end();
  2893. iter != end; ++iter)
  2894. {
  2895. LLSelectNode* node = *iter;
  2896. LLViewerObject* object = node->getObject();
  2897. if (!node->mValid || !object || object->flagObjectPermanent())
  2898. {
  2899. return false;
  2900. }
  2901. }
  2902. return true;
  2903. }
  2904. // Returns true if all objects are not character
  2905. bool LLSelectMgr::selectGetNonCharacter()
  2906. {
  2907. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2908. end = getSelection()->end();
  2909. iter != end; ++iter)
  2910. {
  2911. LLSelectNode* node = *iter;
  2912. LLViewerObject* object = node->getObject();
  2913. if (!node->mValid || !object || object->flagCharacter())
  2914. {
  2915. return false;
  2916. }
  2917. }
  2918. return true;
  2919. }
  2920. // Returns true if all root objects are not character
  2921. bool LLSelectMgr::selectGetRootsNonCharacter()
  2922. {
  2923. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  2924. end = getSelection()->root_end();
  2925. iter != end; ++iter)
  2926. {
  2927. LLSelectNode* node = *iter;
  2928. LLViewerObject* object = node->getObject();
  2929. if (!node->mValid || !object || object->flagCharacter())
  2930. {
  2931. return false;
  2932. }
  2933. }
  2934. return true;
  2935. }
  2936. // Returns true if all objects are editable pathfinding linksets
  2937. bool LLSelectMgr::selectGetEditableLinksets()
  2938. {
  2939. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2940. end = getSelection()->end();
  2941. iter != end; ++iter)
  2942. {
  2943. LLSelectNode* node = *iter;
  2944. LLViewerObject* object = node->getObject();
  2945. if (!node->mValid || !object ||
  2946. object->flagUsePhysics() ||
  2947. object->flagTemporaryOnRez() ||
  2948. object->flagCharacter() ||
  2949. object->flagVolumeDetect() ||
  2950. object->flagAnimSource() ||
  2951. object->getRegion() != gAgent.getRegion() ||
  2952. (!gAgent.isGodlike() && !gAgent.canManageEstate() &&
  2953. !object->permYouOwner() && !object->permMove()))
  2954. {
  2955. return false;
  2956. }
  2957. }
  2958. return true;
  2959. }
  2960. // Returns true if all objects are characters viewable within the pathfinding
  2961. // characters floater
  2962. bool LLSelectMgr::selectGetViewableCharacters()
  2963. {
  2964. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  2965. end = getSelection()->end();
  2966. iter != end; ++iter)
  2967. {
  2968. LLSelectNode* node = *iter;
  2969. LLViewerObject* object = node->getObject();
  2970. if (!node->mValid || !object || !object->flagCharacter() ||
  2971. object->getRegion() != gAgent.getRegion())
  2972. {
  2973. return false;
  2974. }
  2975. }
  2976. return true;
  2977. }
  2978. std::string LLSelectMgr::getPathFindingAttributeInfo(bool empty_for_none)
  2979. {
  2980. std::string pf_attr_name;
  2981. bool got_root_node = getSelection()->getFirstRootNode() != NULL;
  2982. if (selectGetNonPathfinding() ||
  2983. (got_root_node && selectGetRootsNonPathfinding()))
  2984. {
  2985. if (!empty_for_none)
  2986. {
  2987. pf_attr_name = "Pathfinding_Object_Attr_None";
  2988. }
  2989. }
  2990. else if (selectGetPermanent() ||
  2991. (got_root_node && selectGetRootsPermanent()))
  2992. {
  2993. pf_attr_name = "Pathfinding_Object_Attr_Permanent";
  2994. }
  2995. else if (selectGetCharacter() ||
  2996. (got_root_node && selectGetRootsCharacter()))
  2997. {
  2998. pf_attr_name = "Pathfinding_Object_Attr_Character";
  2999. }
  3000. else
  3001. {
  3002. pf_attr_name = "Pathfinding_Object_Attr_MultiSelect";
  3003. }
  3004. return pf_attr_name.empty() ? "" : LLTrans::getString(pf_attr_name);
  3005. }
  3006. // Returns true if current agent can transfer all selected root objects.
  3007. bool LLSelectMgr::selectGetRootsTransfer()
  3008. {
  3009. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  3010. end = getSelection()->root_end();
  3011. iter != end; ++iter)
  3012. {
  3013. LLSelectNode* node = *iter;
  3014. LLViewerObject* object = node->getObject();
  3015. if (!node->mValid ||!object->permTransfer())
  3016. {
  3017. return false;
  3018. }
  3019. }
  3020. return true;
  3021. }
  3022. // Returns true if current agent can copy all selected root objects.
  3023. bool LLSelectMgr::selectGetRootsCopy()
  3024. {
  3025. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  3026. end = getSelection()->root_end();
  3027. iter != end; ++iter)
  3028. {
  3029. LLSelectNode* node = *iter;
  3030. LLViewerObject* object = node->getObject();
  3031. if (!node->mValid || !object->permCopy())
  3032. {
  3033. return false;
  3034. }
  3035. }
  3036. return true;
  3037. }
  3038. struct LLSelectGetFirstTest
  3039. {
  3040. LLSelectGetFirstTest()
  3041. : mIdentical(true),
  3042. mFirst(true)
  3043. {
  3044. }
  3045. virtual ~LLSelectGetFirstTest() {}
  3046. // Returns false to break out of the iteration.
  3047. bool checkMatchingNode(LLSelectNode* node)
  3048. {
  3049. if (!node || !node->mValid)
  3050. {
  3051. return false;
  3052. }
  3053. if (mFirst)
  3054. {
  3055. mFirstValue = getValueFromNode(node);
  3056. mFirst = false;
  3057. }
  3058. else
  3059. {
  3060. if (mFirstValue != getValueFromNode(node))
  3061. {
  3062. mIdentical = false;
  3063. // Stop testing once we know not all selected are identical.
  3064. return false;
  3065. }
  3066. }
  3067. // Continue testing.
  3068. return true;
  3069. }
  3070. bool mIdentical;
  3071. LLUUID mFirstValue;
  3072. protected:
  3073. virtual const LLUUID& getValueFromNode(LLSelectNode* node) = 0;
  3074. private:
  3075. bool mFirst;
  3076. };
  3077. void LLSelectMgr::getFirst(LLSelectGetFirstTest* test)
  3078. {
  3079. if (!test) return;
  3080. if (mEditLinkedParts)
  3081. {
  3082. for (LLObjectSelection::valid_iterator
  3083. iter = getSelection()->valid_begin(),
  3084. end = getSelection()->valid_end();
  3085. iter != end; ++iter)
  3086. {
  3087. if (!test->checkMatchingNode(*iter))
  3088. {
  3089. break;
  3090. }
  3091. }
  3092. }
  3093. else
  3094. {
  3095. for (LLObjectSelection::root_object_iterator
  3096. iter = getSelection()->root_object_begin(),
  3097. end = getSelection()->root_object_end();
  3098. iter != end; ++iter)
  3099. {
  3100. if (!test->checkMatchingNode(*iter))
  3101. {
  3102. break;
  3103. }
  3104. }
  3105. }
  3106. }
  3107. // Creator information only applies to root objects.
  3108. struct LLSelectGetFirstCreator final : public LLSelectGetFirstTest
  3109. {
  3110. protected:
  3111. const LLUUID& getValueFromNode(LLSelectNode* node) override
  3112. {
  3113. return node->mPermissions->getCreator();
  3114. }
  3115. };
  3116. bool LLSelectMgr::selectGetCreator(LLUUID& result_id, std::string& name)
  3117. {
  3118. LLSelectGetFirstCreator test;
  3119. getFirst(&test);
  3120. if (test.mFirstValue.isNull())
  3121. {
  3122. name = LLTrans::getString("AvatarNameNobody");
  3123. return false;
  3124. }
  3125. result_id = test.mFirstValue;
  3126. if (!gCacheNamep)
  3127. {
  3128. name = "unknown";
  3129. }
  3130. else if (test.mIdentical)
  3131. {
  3132. gCacheNamep->getFullName(result_id, name);
  3133. }
  3134. else
  3135. {
  3136. name = LLTrans::getString("AvatarNameMultiple");
  3137. }
  3138. return test.mIdentical;
  3139. }
  3140. // Owner information only applies to roots.
  3141. struct LLSelectGetFirstOwner final : public LLSelectGetFirstTest
  3142. {
  3143. protected:
  3144. const LLUUID& getValueFromNode(LLSelectNode* node) override
  3145. {
  3146. // Do not use 'getOwnership' since we return a reference, not a copy.
  3147. // Will return LLUUID::null if unowned (which is not allowed and
  3148. // should never happen).
  3149. return node->mPermissions->isGroupOwned() ? node->mPermissions->getGroup()
  3150. : node->mPermissions->getOwner();
  3151. }
  3152. };
  3153. bool LLSelectMgr::selectGetOwner(LLUUID& result_id, std::string& name)
  3154. {
  3155. LLSelectGetFirstOwner test;
  3156. getFirst(&test);
  3157. if (test.mFirstValue.isNull())
  3158. {
  3159. return false;
  3160. }
  3161. result_id = test.mFirstValue;
  3162. if (test.mIdentical)
  3163. {
  3164. bool group_owned = selectIsGroupOwned();
  3165. if (!gCacheNamep)
  3166. {
  3167. name = "unknown";
  3168. }
  3169. else if (group_owned)
  3170. {
  3171. gCacheNamep->getGroupName(result_id, name);
  3172. }
  3173. else
  3174. {
  3175. gCacheNamep->getFullName(result_id, name);
  3176. }
  3177. }
  3178. else
  3179. {
  3180. name = LLTrans::getString("AvatarNameMultiple");
  3181. }
  3182. return test.mIdentical;
  3183. }
  3184. // Owner information only applies to roots.
  3185. struct LLSelectGetFirstLastOwner final : public LLSelectGetFirstTest
  3186. {
  3187. protected:
  3188. const LLUUID& getValueFromNode(LLSelectNode* node) override
  3189. {
  3190. return node->mPermissions->getLastOwner();
  3191. }
  3192. };
  3193. bool LLSelectMgr::selectGetLastOwner(LLUUID& result_id, std::string& name)
  3194. {
  3195. LLSelectGetFirstLastOwner test;
  3196. getFirst(&test);
  3197. if (test.mFirstValue.isNull())
  3198. {
  3199. return false;
  3200. }
  3201. result_id = test.mFirstValue;
  3202. if (gCacheNamep && test.mIdentical)
  3203. {
  3204. gCacheNamep->getFullName(result_id, name);
  3205. }
  3206. else
  3207. {
  3208. name.clear();
  3209. }
  3210. return test.mIdentical;
  3211. }
  3212. // Group information only applies to roots.
  3213. struct LLSelectGetFirstGroup final : public LLSelectGetFirstTest
  3214. {
  3215. protected:
  3216. const LLUUID& getValueFromNode(LLSelectNode* node) override
  3217. {
  3218. return node->mPermissions->getGroup();
  3219. }
  3220. };
  3221. bool LLSelectMgr::selectGetGroup(LLUUID& result_id)
  3222. {
  3223. LLSelectGetFirstGroup test;
  3224. getFirst(&test);
  3225. result_id = test.mFirstValue;
  3226. return test.mIdentical;
  3227. }
  3228. // Only operates on root nodes. Returns true if all have valid data and they
  3229. // are all group owned.
  3230. struct LLSelectGetFirstGroupOwner final : public LLSelectGetFirstTest
  3231. {
  3232. protected:
  3233. const LLUUID& getValueFromNode(LLSelectNode* node) override
  3234. {
  3235. if (node->mPermissions->isGroupOwned())
  3236. {
  3237. return node->mPermissions->getGroup();
  3238. }
  3239. return LLUUID::null;
  3240. }
  3241. };
  3242. bool LLSelectMgr::selectIsGroupOwned()
  3243. {
  3244. LLSelectGetFirstGroupOwner test;
  3245. getFirst(&test);
  3246. return test.mFirstValue.notNull();
  3247. }
  3248. // Only operates on root nodes. Returns true if all have valid data.
  3249. // - mask_on has bits set to true where all permissions are true.
  3250. // - mask_off has bits set to true where all permissions are false.
  3251. // If a bit is off both in mask_on and mask_off, the values differ within the
  3252. // selection.
  3253. bool LLSelectMgr::selectGetPerm(U8 which_perm, U32* mask_on, U32* mask_off)
  3254. {
  3255. U32 mask;
  3256. U32 mask_and = 0xffffffff;
  3257. U32 mask_or = 0x00000000;
  3258. bool all_valid = false;
  3259. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin(),
  3260. end = getSelection()->root_end();
  3261. iter != end; ++iter)
  3262. {
  3263. LLSelectNode* node = *iter;
  3264. if (!node->mValid)
  3265. {
  3266. all_valid = false;
  3267. break;
  3268. }
  3269. all_valid = true;
  3270. switch (which_perm)
  3271. {
  3272. case PERM_BASE:
  3273. mask = node->mPermissions->getMaskBase();
  3274. break;
  3275. case PERM_OWNER:
  3276. mask = node->mPermissions->getMaskOwner();
  3277. break;
  3278. case PERM_GROUP:
  3279. mask = node->mPermissions->getMaskGroup();
  3280. break;
  3281. case PERM_EVERYONE:
  3282. mask = node->mPermissions->getMaskEveryone();
  3283. break;
  3284. case PERM_NEXT_OWNER:
  3285. mask = node->mPermissions->getMaskNextOwner();
  3286. break;
  3287. default:
  3288. mask = 0x0;
  3289. }
  3290. mask_and &= mask;
  3291. mask_or |= mask;
  3292. }
  3293. if (all_valid)
  3294. {
  3295. // ...true through all ANDs means all true
  3296. *mask_on = mask_and;
  3297. // ...false through all ORs means all false
  3298. *mask_off = ~mask_or;
  3299. }
  3300. else
  3301. {
  3302. *mask_on = *mask_off = 0;
  3303. }
  3304. return all_valid;
  3305. }
  3306. bool LLSelectMgr::selectGetPermissions(LLPermissions& result_perm)
  3307. {
  3308. bool first = true;
  3309. LLPermissions perm;
  3310. for (LLObjectSelection::root_iterator
  3311. iter = getSelection()->root_begin(),
  3312. end = getSelection()->root_end();
  3313. iter != end; ++iter)
  3314. {
  3315. LLSelectNode* node = *iter;
  3316. if (!node->mValid)
  3317. {
  3318. return false;
  3319. }
  3320. if (first)
  3321. {
  3322. perm = *(node->mPermissions);
  3323. first = false;
  3324. }
  3325. else
  3326. {
  3327. perm.accumulate(*(node->mPermissions));
  3328. }
  3329. }
  3330. result_perm = perm;
  3331. return true;
  3332. }
  3333. void LLSelectMgr::selectDelete()
  3334. {
  3335. bool can_delete = false;
  3336. bool locked_but_deleteable_object = false;
  3337. bool no_copy_but_deleteable_object = false;
  3338. bool all_owned_by_you = true;
  3339. //MK
  3340. // True when a sit restriction is in force and the agent is sitting
  3341. bool is_rlv_restricted = gRLenabled &&
  3342. (gRLInterface.mSittpMax < EXTREMUM ||
  3343. (gRLInterface.mContainsUnsit &&
  3344. isAgentAvatarValid() &&
  3345. gAgentAvatarp->mIsSitting));
  3346. //mk
  3347. for (LLObjectSelection::iterator iter = getSelection()->begin(),
  3348. end = getSelection()->end();
  3349. iter != end; ++iter)
  3350. {
  3351. LLViewerObject* obj = (*iter)->getObject();
  3352. if (obj->isAttachment())
  3353. {
  3354. continue;
  3355. }
  3356. //MK
  3357. if (is_rlv_restricted && obj->isAgentSeat())
  3358. {
  3359. continue;
  3360. }
  3361. //mk
  3362. can_delete = true;
  3363. // Check to see if you can delete objects which are locked.
  3364. if (!obj->permMove())
  3365. {
  3366. locked_but_deleteable_object = true;
  3367. }
  3368. if (!obj->permCopy())
  3369. {
  3370. no_copy_but_deleteable_object = true;
  3371. }
  3372. if (!obj->permYouOwner())
  3373. {
  3374. all_owned_by_you = false;
  3375. }
  3376. }
  3377. if (!can_delete)
  3378. {
  3379. make_ui_sound("UISndInvalidOp");
  3380. return;
  3381. }
  3382. LLNotification::Params params("ConfirmObjectDeleteLock");
  3383. params.functor(boost::bind(&LLSelectMgr::confirmDelete, _1, _2,
  3384. getSelection()));
  3385. if (locked_but_deleteable_object || no_copy_but_deleteable_object ||
  3386. !all_owned_by_you)
  3387. {
  3388. // Convert any transient pie-menu selections to full selection so this
  3389. // operation has some context.
  3390. // NOTE: if user cancels delete operation, this will potentially leave
  3391. // objects selected outside of build mode but this is ok, if not ideal
  3392. convertTransient();
  3393. // This is messy, but needed to get all english our of the UI.
  3394. if (locked_but_deleteable_object && !no_copy_but_deleteable_object &&
  3395. all_owned_by_you)
  3396. {
  3397. //Locked only
  3398. params.name("ConfirmObjectDeleteLock");
  3399. }
  3400. else if (!locked_but_deleteable_object &&
  3401. no_copy_but_deleteable_object && all_owned_by_you)
  3402. {
  3403. // No Copy only
  3404. params.name("ConfirmObjectDeleteNoCopy");
  3405. }
  3406. else if (!locked_but_deleteable_object &&
  3407. !no_copy_but_deleteable_object && !all_owned_by_you)
  3408. {
  3409. // Not owned only
  3410. params.name("ConfirmObjectDeleteNoOwn");
  3411. }
  3412. else if (locked_but_deleteable_object &&
  3413. no_copy_but_deleteable_object && all_owned_by_you)
  3414. {
  3415. // Locked and no copy
  3416. params.name("ConfirmObjectDeleteLockNoCopy");
  3417. }
  3418. else if (locked_but_deleteable_object &&
  3419. !no_copy_but_deleteable_object && !all_owned_by_you)
  3420. {
  3421. // Locked and not owned
  3422. params.name("ConfirmObjectDeleteLockNoOwn");
  3423. }
  3424. else if (!locked_but_deleteable_object &&
  3425. no_copy_but_deleteable_object && !all_owned_by_you)
  3426. {
  3427. // No copy and not owned
  3428. params.name("ConfirmObjectDeleteNoCopyNoOwn");
  3429. }
  3430. else
  3431. {
  3432. // Locked, no copy and not owned
  3433. params.name("ConfirmObjectDeleteLockNoCopyNoOwn");
  3434. }
  3435. gNotifications.add(params);
  3436. }
  3437. else
  3438. {
  3439. gNotifications.forceResponse(params, 0);
  3440. }
  3441. }
  3442. //static
  3443. bool LLSelectMgr::confirmDelete(const LLSD& notification,
  3444. const LLSD& response,
  3445. LLObjectSelectionHandle handle)
  3446. {
  3447. if (!handle->getObjectCount())
  3448. {
  3449. llwarns << "Nothing to delete !" << llendl;
  3450. }
  3451. else if (LLNotification::getSelectedOption(notification, response) == 0)
  3452. {
  3453. make_ui_sound("UISndObjectDelete");
  3454. // *TODO: Make sure you have delete permissions on all of them.
  3455. const LLUUID& trash_id = gInventory.getTrashID();
  3456. // Attempt to derez into the trash.
  3457. LLDeRezInfo* info = new LLDeRezInfo(DRD_TRASH, trash_id);
  3458. gSelectMgr.sendListToRegions("DeRezObject", packDeRezHeader,
  3459. packObjectLocalID, (void*)info,
  3460. SEND_ONLY_ROOTS);
  3461. S32 objects_count = gSelectMgr.mSelectedObjects->getObjectCount();
  3462. if (gSelectMgr.mSelectedObjects->mSelectType != SELECT_TYPE_HUD)
  3463. {
  3464. // VEFFECT: delete object, with one effect for all deletes
  3465. const LLVector3d& pos = gSelectMgr.getSelectionCenterGlobal();
  3466. F32 duration = 0.5f + (F32)objects_count / 64.f;
  3467. LLHUDEffectSpiral::swirlAtPosition(pos, duration);
  3468. }
  3469. gAgent.setLookAt(LOOKAT_TARGET_CLEAR);
  3470. // Keep track of how many objects have been deleted.
  3471. F64 deleted =
  3472. (F64)objects_count +
  3473. gViewerStats.getStat(LLViewerStats::ST_OBJECT_DELETE_COUNT);
  3474. gViewerStats.setStat(LLViewerStats::ST_OBJECT_DELETE_COUNT, deleted);
  3475. }
  3476. return false;
  3477. }
  3478. void LLSelectMgr::selectForceDelete()
  3479. {
  3480. sendListToRegions("ObjectDelete", packDeleteHeader, packObjectLocalID,
  3481. (void*)true, SEND_ONLY_ROOTS);
  3482. }
  3483. bool LLSelectMgr::selectGetEditMoveLinksetPermissions(bool& move, bool& modify)
  3484. {
  3485. move = modify = true;
  3486. bool select_linked_set = !mEditLinkedParts;
  3487. //MK
  3488. // True when a sit restriction is in force and the agent is sitting
  3489. bool is_rlv_restricted = gRLenabled &&
  3490. (gRLInterface.mSittpMax < EXTREMUM ||
  3491. (gRLInterface.mContainsUnsit &&
  3492. isAgentAvatarValid() &&
  3493. gAgentAvatarp->mIsSitting));
  3494. //mk
  3495. for (LLObjectSelection::root_iterator
  3496. iter = getSelection()->root_begin(),
  3497. end = getSelection()->root_end();
  3498. iter != end; ++iter)
  3499. {
  3500. LLSelectNode* node = *iter;
  3501. if (!node->mValid)
  3502. {
  3503. move = modify = false;
  3504. return false;
  3505. }
  3506. LLViewerObject* object = node->getObject();
  3507. LLViewerObject* root_object = object ? object->getRootEdit() : NULL;
  3508. move &= object && object->permMove() &&
  3509. !object->isPermanentEnforced() &&
  3510. !(root_object && root_object->isPermanentEnforced()) &&
  3511. (select_linked_set || object->permModify());
  3512. //MK
  3513. // Cannot edit objects that the agent is sitting on when sit-restricted
  3514. if (is_rlv_restricted && object && object->isAgentSeat())
  3515. {
  3516. move = false;
  3517. }
  3518. //mk
  3519. modify &= object->permModify();
  3520. }
  3521. return true;
  3522. }
  3523. void LLSelectMgr::selectGetAggregateSaleInfo(U32& num_for_sale,
  3524. bool& is_for_sale_mixed,
  3525. bool& is_sale_price_mixed,
  3526. S32& total_sale_price,
  3527. S32& individual_sale_price)
  3528. {
  3529. num_for_sale = 0;
  3530. is_for_sale_mixed = false;
  3531. is_sale_price_mixed = false;
  3532. total_sale_price = 0;
  3533. individual_sale_price = 0;
  3534. // Empty set.
  3535. if (getSelection()->root_begin() == getSelection()->root_end())
  3536. {
  3537. return;
  3538. }
  3539. LLSelectNode* node = *(getSelection()->root_begin());
  3540. const bool first_node_for_sale = node->mSaleInfo.isForSale();
  3541. const S32 first_node_sale_price = node->mSaleInfo.getSalePrice();
  3542. for (LLObjectSelection::root_iterator
  3543. iter = getSelection()->root_begin(),
  3544. end = getSelection()->root_end();
  3545. iter != end; ++iter)
  3546. {
  3547. LLSelectNode* node = *iter;
  3548. const bool node_for_sale = node->mSaleInfo.isForSale();
  3549. const S32 node_sale_price = node->mSaleInfo.getSalePrice();
  3550. // Set mixed if the fields do not match the first node's fields.
  3551. if (node_for_sale != first_node_for_sale)
  3552. {
  3553. is_for_sale_mixed = true;
  3554. }
  3555. if (node_sale_price != first_node_sale_price)
  3556. {
  3557. is_sale_price_mixed = true;
  3558. }
  3559. if (node_for_sale)
  3560. {
  3561. total_sale_price += node_sale_price;
  3562. ++num_for_sale;
  3563. }
  3564. }
  3565. individual_sale_price = first_node_sale_price;
  3566. if (is_for_sale_mixed)
  3567. {
  3568. is_sale_price_mixed = true;
  3569. individual_sale_price = 0;
  3570. }
  3571. }
  3572. // returns true if all nodes are valid. method also stores an
  3573. // accumulated sale info.
  3574. bool LLSelectMgr::selectGetSaleInfo(LLSaleInfo& result_sale_info)
  3575. {
  3576. bool first = true;
  3577. LLSaleInfo sale_info;
  3578. for (LLObjectSelection::root_iterator
  3579. iter = getSelection()->root_begin(),
  3580. end = getSelection()->root_end();
  3581. iter != end; ++iter)
  3582. {
  3583. LLSelectNode* node = *iter;
  3584. if (!node->mValid)
  3585. {
  3586. return false;
  3587. }
  3588. if (first)
  3589. {
  3590. sale_info = node->mSaleInfo;
  3591. first = false;
  3592. }
  3593. else
  3594. {
  3595. sale_info.accumulate(node->mSaleInfo);
  3596. }
  3597. }
  3598. result_sale_info = sale_info;
  3599. return true;
  3600. }
  3601. bool LLSelectMgr::selectGetAggregatePermissions(LLAggregatePermissions& result_perm)
  3602. {
  3603. bool first = true;
  3604. LLAggregatePermissions perm;
  3605. for (LLObjectSelection::root_iterator
  3606. iter = getSelection()->root_begin(),
  3607. end = getSelection()->root_end();
  3608. iter != end; ++iter)
  3609. {
  3610. LLSelectNode* node = *iter;
  3611. if (!node->mValid)
  3612. {
  3613. return false;
  3614. }
  3615. if (first)
  3616. {
  3617. perm = node->mAggregatePerm;
  3618. first = false;
  3619. }
  3620. else
  3621. {
  3622. perm.aggregate(node->mAggregatePerm);
  3623. }
  3624. }
  3625. result_perm = perm;
  3626. return true;
  3627. }
  3628. bool LLSelectMgr::selectGetAggregateTexturePermissions(LLAggregatePermissions& result_perm)
  3629. {
  3630. bool first = true;
  3631. LLAggregatePermissions perm;
  3632. for (LLObjectSelection::root_iterator
  3633. iter = getSelection()->root_begin(),
  3634. end = getSelection()->root_end();
  3635. iter != end; ++iter)
  3636. {
  3637. LLSelectNode* node = *iter;
  3638. if (!node->mValid)
  3639. {
  3640. return false;
  3641. }
  3642. LLAggregatePermissions t_perm =
  3643. node->getObject()->permYouOwner() ? node->mAggregateTexturePermOwner
  3644. : node->mAggregateTexturePerm;
  3645. if (first)
  3646. {
  3647. perm = t_perm;
  3648. first = false;
  3649. }
  3650. else
  3651. {
  3652. perm.aggregate(t_perm);
  3653. }
  3654. }
  3655. result_perm = perm;
  3656. return true;
  3657. }
  3658. //-----------------------------------------------------------------------------
  3659. // Duplicate objects
  3660. //-----------------------------------------------------------------------------
  3661. // JC - If this does not work right, duplicate the selection list before doing
  3662. // anything, do a deselect, then send the duplicate messages.
  3663. struct LLDuplicateData
  3664. {
  3665. LLVector3 offset;
  3666. U32 flags;
  3667. };
  3668. void LLSelectMgr::selectDuplicate(const LLVector3& offset, bool select_copy)
  3669. {
  3670. if (mSelectedObjects->isAttachment())
  3671. {
  3672. // RN: do not duplicate attachments
  3673. make_ui_sound("UISndInvalidOp");
  3674. return;
  3675. }
  3676. LLDuplicateData data;
  3677. data.offset = offset;
  3678. data.flags = (select_copy ? FLAGS_CREATE_SELECTED : 0x0);
  3679. sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate,
  3680. &data, SEND_ONLY_ROOTS);
  3681. if (select_copy)
  3682. {
  3683. // The new copy will be coming in selected
  3684. deselectAll();
  3685. }
  3686. else
  3687. {
  3688. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin();
  3689. iter != getSelection()->root_end(); ++iter)
  3690. {
  3691. LLSelectNode* node = *iter;
  3692. node->mDuplicated = true;
  3693. node->mDuplicatePos = node->getObject()->getPositionGlobal();
  3694. node->mDuplicateRot = node->getObject()->getRotation();
  3695. }
  3696. }
  3697. }
  3698. void LLSelectMgr::repeatDuplicate()
  3699. {
  3700. if (mSelectedObjects->isAttachment())
  3701. {
  3702. // RN: do not duplicate attachments
  3703. make_ui_sound("UISndInvalidOp");
  3704. return;
  3705. }
  3706. std::vector<LLViewerObject*> non_duplicated_objects;
  3707. for (LLObjectSelection::root_iterator
  3708. iter = getSelection()->root_begin(),
  3709. end = getSelection()->root_end();
  3710. iter != end; ++iter)
  3711. {
  3712. LLSelectNode* node = *iter;
  3713. if (!node->mDuplicated)
  3714. {
  3715. non_duplicated_objects.push_back(node->getObject());
  3716. }
  3717. }
  3718. // make sure only previously duplicated objects are selected
  3719. for (std::vector<LLViewerObject*>::iterator
  3720. iter = non_duplicated_objects.begin(),
  3721. end = non_duplicated_objects.end();
  3722. iter != end; ++iter)
  3723. {
  3724. LLViewerObject* objectp = *iter;
  3725. deselectObjectAndFamily(objectp);
  3726. }
  3727. // duplicate objects in place
  3728. LLDuplicateData data;
  3729. data.offset = LLVector3::zero;
  3730. data.flags = 0x0;
  3731. sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate,
  3732. &data, SEND_ONLY_ROOTS);
  3733. // Move current selection based on delta from duplication position and
  3734. // update duplication position
  3735. for (LLObjectSelection::root_iterator
  3736. iter = getSelection()->root_begin(),
  3737. end = getSelection()->root_end();
  3738. iter != end; ++iter)
  3739. {
  3740. LLSelectNode* node = *iter;
  3741. if (node->mDuplicated)
  3742. {
  3743. LLQuaternion cur_rot = node->getObject()->getRotation();
  3744. LLQuaternion rot_delta = (~node->mDuplicateRot * cur_rot);
  3745. LLQuaternion new_rot = cur_rot * rot_delta;
  3746. LLVector3d cur_pos = node->getObject()->getPositionGlobal();
  3747. LLVector3d new_pos = cur_pos + (cur_pos - node->mDuplicatePos) * rot_delta;
  3748. node->mDuplicatePos = node->getObject()->getPositionGlobal();
  3749. node->mDuplicateRot = node->getObject()->getRotation();
  3750. node->getObject()->setPositionGlobal(new_pos);
  3751. node->getObject()->setRotation(new_rot);
  3752. }
  3753. }
  3754. sendMultipleUpdate(UPD_ROTATION | UPD_POSITION);
  3755. }
  3756. //static
  3757. void LLSelectMgr::packDuplicate(LLSelectNode* node, void* duplicate_data)
  3758. {
  3759. LLMessageSystem* msg = gMessageSystemp;
  3760. msg->nextBlockFast(_PREHASH_ObjectData);
  3761. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  3762. }
  3763. //-----------------------------------------------------------------------------
  3764. // Duplicate On Ray
  3765. //-----------------------------------------------------------------------------
  3766. // Duplicates the selected objects, but places the copy along a cast
  3767. // ray.
  3768. struct LLDuplicateOnRayData
  3769. {
  3770. LLVector3 mRayStartRegion;
  3771. LLVector3 mRayEndRegion;
  3772. bool mBypassRaycast;
  3773. bool mRayEndIsIntersection;
  3774. LLUUID mRayTargetID;
  3775. bool mCopyCenters;
  3776. bool mCopyRotates;
  3777. U32 mFlags;
  3778. };
  3779. void LLSelectMgr::selectDuplicateOnRay(const LLVector3& ray_start_region,
  3780. const LLVector3& ray_end_region,
  3781. bool bypass_raycast,
  3782. bool ray_end_is_intersection,
  3783. const LLUUID& ray_target_id,
  3784. bool copy_centers,
  3785. bool copy_rotates,
  3786. bool select_copy)
  3787. {
  3788. if (mSelectedObjects->isAttachment())
  3789. {
  3790. // Do not duplicate attachments
  3791. make_ui_sound("UISndInvalidOp");
  3792. return;
  3793. }
  3794. LLDuplicateOnRayData data;
  3795. data.mRayStartRegion = ray_start_region;
  3796. data.mRayEndRegion = ray_end_region;
  3797. data.mBypassRaycast = bypass_raycast;
  3798. data.mRayEndIsIntersection = ray_end_is_intersection;
  3799. data.mRayTargetID = ray_target_id;
  3800. data.mCopyCenters = copy_centers;
  3801. data.mCopyRotates = copy_rotates;
  3802. data.mFlags = select_copy ? FLAGS_CREATE_SELECTED : 0x0;
  3803. sendListToRegions("ObjectDuplicateOnRay", packDuplicateOnRayHead,
  3804. packObjectLocalID, &data, SEND_ONLY_ROOTS);
  3805. if (select_copy)
  3806. {
  3807. // the new copy will be coming in selected
  3808. deselectAll();
  3809. }
  3810. }
  3811. //static
  3812. void LLSelectMgr::packDuplicateOnRayHead(void* user_data)
  3813. {
  3814. LLMessageSystem* msg = gMessageSystemp;
  3815. LLDuplicateOnRayData* data = (LLDuplicateOnRayData*)user_data;
  3816. msg->nextBlockFast(_PREHASH_AgentData);
  3817. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  3818. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  3819. LLUUID group_id = gAgent.getGroupID();
  3820. if (gSavedSettings.getBool("RezWithLandGroup"))
  3821. {
  3822. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  3823. if (gAgent.isInGroup(parcel->getGroupID()))
  3824. {
  3825. group_id = parcel->getGroupID();
  3826. }
  3827. else if (gAgent.isInGroup(parcel->getOwnerID()))
  3828. {
  3829. group_id = parcel->getOwnerID();
  3830. }
  3831. }
  3832. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  3833. msg->addVector3Fast(_PREHASH_RayStart, data->mRayStartRegion);
  3834. msg->addVector3Fast(_PREHASH_RayEnd, data->mRayEndRegion);
  3835. msg->addBoolFast(_PREHASH_BypassRaycast, data->mBypassRaycast);
  3836. msg->addBoolFast(_PREHASH_RayEndIsIntersection, data->mRayEndIsIntersection);
  3837. msg->addBoolFast(_PREHASH_CopyCenters, data->mCopyCenters);
  3838. msg->addBoolFast(_PREHASH_CopyRotates, data->mCopyRotates);
  3839. msg->addUUIDFast(_PREHASH_RayTargetID, data->mRayTargetID);
  3840. msg->addU32Fast(_PREHASH_DuplicateFlags, data->mFlags);
  3841. }
  3842. //-----------------------------------------------------------------------------
  3843. // Object position, scale, rotation update, all-in-one
  3844. //-----------------------------------------------------------------------------
  3845. void LLSelectMgr::sendMultipleUpdate(U32 type)
  3846. {
  3847. if (type == UPD_NONE) return;
  3848. // Send individual updates when selecting textures or individual objects
  3849. ESendType send_type = !mEditLinkedParts && !getTEMode() ? SEND_ONLY_ROOTS
  3850. : SEND_ROOTS_FIRST;
  3851. if (send_type == SEND_ONLY_ROOTS)
  3852. {
  3853. // Tell simulator to apply to whole linked sets
  3854. type |= UPD_LINKED_SETS;
  3855. }
  3856. sendListToRegions("MultipleObjectUpdate", packAgentAndSessionID,
  3857. packMultipleUpdate, &type, send_type);
  3858. }
  3859. //static
  3860. void LLSelectMgr::packMultipleUpdate(LLSelectNode* node, void* user_data)
  3861. {
  3862. LLViewerObject* object = node->getObject();
  3863. U32* type32 = (U32*)user_data;
  3864. U8 type = (U8)*type32;
  3865. U8 data[256];
  3866. LLMessageSystem* msg = gMessageSystemp;
  3867. msg->nextBlockFast(_PREHASH_ObjectData);
  3868. msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
  3869. msg->addU8Fast(_PREHASH_Type, type);
  3870. S32 offset = 0;
  3871. // JC: You MUST pack the data in this order. The receiving
  3872. // routine process_multiple_update_message on simulator will
  3873. // extract them in this order.
  3874. if (type & UPD_POSITION)
  3875. {
  3876. htonmemcpy(&data[offset], &(object->getPosition().mV), MVT_LLVector3, 12);
  3877. offset += 12;
  3878. }
  3879. if (type & UPD_ROTATION)
  3880. {
  3881. LLQuaternion quat = object->getRotation();
  3882. LLVector3 vec = quat.packToVector3();
  3883. htonmemcpy(&data[offset], &(vec.mV), MVT_LLQuaternion, 12);
  3884. offset += 12;
  3885. }
  3886. if (type & UPD_SCALE)
  3887. {
  3888. //llinfos << "Sending object scale " << object->getScale() << llendl;
  3889. htonmemcpy(&data[offset], &(object->getScale().mV), MVT_LLVector3, 12);
  3890. offset += 12;
  3891. }
  3892. msg->addBinaryDataFast(_PREHASH_Data, data, offset);
  3893. }
  3894. //-----------------------------------------------------------------------------
  3895. // Ownership
  3896. //-----------------------------------------------------------------------------
  3897. struct LLOwnerData
  3898. {
  3899. LLUUID owner_id;
  3900. LLUUID group_id;
  3901. bool do_override;
  3902. };
  3903. void LLSelectMgr::sendOwner(const LLUUID& owner_id,
  3904. const LLUUID& group_id,
  3905. bool do_override)
  3906. {
  3907. LLOwnerData data;
  3908. data.owner_id = owner_id;
  3909. data.group_id = group_id;
  3910. data.do_override = do_override;
  3911. sendListToRegions("ObjectOwner", packOwnerHead, packObjectLocalID, &data,
  3912. SEND_ONLY_ROOTS);
  3913. }
  3914. //static
  3915. void LLSelectMgr::packOwnerHead(void* user_data)
  3916. {
  3917. LLOwnerData* data = (LLOwnerData*)user_data;
  3918. LLMessageSystem* msg = gMessageSystemp;
  3919. msg->nextBlockFast(_PREHASH_AgentData);
  3920. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  3921. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  3922. msg->nextBlockFast(_PREHASH_HeaderData);
  3923. msg->addBoolFast(_PREHASH_Override, data->do_override);
  3924. msg->addUUIDFast(_PREHASH_OwnerID, data->owner_id);
  3925. msg->addUUIDFast(_PREHASH_GroupID, data->group_id);
  3926. }
  3927. //-----------------------------------------------------------------------------
  3928. // Group
  3929. //-----------------------------------------------------------------------------
  3930. void LLSelectMgr::sendGroup(const LLUUID& group_id)
  3931. {
  3932. LLUUID local_group_id(group_id);
  3933. sendListToRegions("ObjectGroup", packAgentAndSessionAndGroupID,
  3934. packObjectLocalID, &local_group_id, SEND_ONLY_ROOTS);
  3935. }
  3936. //-----------------------------------------------------------------------------
  3937. // Buy
  3938. //-----------------------------------------------------------------------------
  3939. struct LLBuyData
  3940. {
  3941. std::vector<LLViewerObject*> mObjectsSent;
  3942. LLUUID mCategoryID;
  3943. LLSaleInfo mSaleInfo;
  3944. };
  3945. // *NOTE: does not work for multiple objects buy, which UI does not currently
  3946. // support; sale info is used for verification only, if it does not match
  3947. // region info then the sale is cancelled. We need to get sale info -as
  3948. // displayed in the UI- for every item.
  3949. void LLSelectMgr::sendBuy(const LLUUID& buyer_id, const LLUUID& category_id,
  3950. const LLSaleInfo sale_info)
  3951. {
  3952. LLBuyData buy;
  3953. buy.mCategoryID = category_id;
  3954. buy.mSaleInfo = sale_info;
  3955. sendListToRegions("ObjectBuy", packAgentGroupAndCatID, packBuyObjectIDs,
  3956. &buy, SEND_ONLY_ROOTS);
  3957. }
  3958. //static
  3959. void LLSelectMgr::packBuyObjectIDs(LLSelectNode* node, void* data)
  3960. {
  3961. LLBuyData* buy = (LLBuyData*)data;
  3962. LLViewerObject* object = node->getObject();
  3963. if (std::find(buy->mObjectsSent.begin(), buy->mObjectsSent.end(),
  3964. object) == buy->mObjectsSent.end())
  3965. {
  3966. buy->mObjectsSent.push_back(object);
  3967. LLMessageSystem* msg = gMessageSystemp;
  3968. msg->nextBlockFast(_PREHASH_ObjectData);
  3969. msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
  3970. msg->addU8Fast(_PREHASH_SaleType, buy->mSaleInfo.getSaleType());
  3971. msg->addS32Fast(_PREHASH_SalePrice, buy->mSaleInfo.getSalePrice());
  3972. }
  3973. }
  3974. //-----------------------------------------------------------------------------
  3975. // Permissions
  3976. //-----------------------------------------------------------------------------
  3977. struct LLPermData
  3978. {
  3979. U8 mField;
  3980. U32 mMask;
  3981. bool mSet;
  3982. bool mOverride;
  3983. };
  3984. // *TODO: Make this able to fail elegantly.
  3985. void LLSelectMgr::selectionSetObjectPermissions(U8 field, bool set, U32 mask,
  3986. bool do_override)
  3987. {
  3988. LLPermData data;
  3989. data.mField = field;
  3990. data.mSet = set;
  3991. data.mMask = mask;
  3992. data.mOverride = do_override;
  3993. sendListToRegions("ObjectPermissions", packPermissionsHead,
  3994. packPermissions, &data, SEND_ONLY_ROOTS);
  3995. }
  3996. void LLSelectMgr::packPermissionsHead(void* user_data)
  3997. {
  3998. LLPermData* data = (LLPermData*)user_data;
  3999. LLMessageSystem* msg = gMessageSystemp;
  4000. msg->nextBlockFast(_PREHASH_AgentData);
  4001. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4002. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4003. msg->nextBlockFast(_PREHASH_HeaderData);
  4004. msg->addBoolFast(_PREHASH_Override, data->mOverride);
  4005. }
  4006. void LLSelectMgr::deselectAll()
  4007. {
  4008. if (mSelectedObjects->getNumNodes())
  4009. {
  4010. deselectAllForStandingUp();
  4011. }
  4012. }
  4013. // This method is similar deselectAll() except for the if statement which was
  4014. // removed; this is needed as a workaround for DEV-2854.
  4015. void LLSelectMgr::deselectAllForStandingUp()
  4016. {
  4017. // Zap the angular velocity, as the sim will set it to zero
  4018. for (LLObjectSelection::iterator iter = mSelectedObjects->begin(),
  4019. end = mSelectedObjects->end();
  4020. iter != end; ++iter)
  4021. {
  4022. LLViewerObject* objectp = (*iter)->getObject();
  4023. #if 0 // Do not do that: it breaks target-omega seats !
  4024. objectp->setAngularVelocity(0.f, 0.f, 0.f);
  4025. #endif
  4026. objectp->setVelocity(0.f, 0.f, 0.f);
  4027. }
  4028. sendListToRegions("ObjectDeselect", packAgentAndSessionID,
  4029. packObjectLocalID, NULL, SEND_INDIVIDUALS);
  4030. removeAll();
  4031. mLastSentSelectionCenterGlobal.clear();
  4032. updatePointAt();
  4033. }
  4034. void LLSelectMgr::deselectUnused()
  4035. {
  4036. // no more outstanding references to this selection
  4037. if (mSelectedObjects->getNumRefs() == 1)
  4038. {
  4039. deselectAll();
  4040. }
  4041. }
  4042. void LLSelectMgr::convertTransient()
  4043. {
  4044. for (LLObjectSelection::iterator node_it = mSelectedObjects->begin(),
  4045. end = mSelectedObjects->end();
  4046. node_it != end; ++node_it)
  4047. {
  4048. LLSelectNode* nodep = *node_it;
  4049. nodep->setTransient(false);
  4050. }
  4051. }
  4052. void LLSelectMgr::deselectAllIfTooFar()
  4053. {
  4054. if (mSelectedObjects->isEmpty() ||
  4055. mSelectedObjects->mSelectType == SELECT_TYPE_HUD)
  4056. {
  4057. return;
  4058. }
  4059. // Do not deselect when we are navigating an object's pie menu or when we
  4060. // are quitting the application (with gPieObjectp deleted)
  4061. if (!gPieObjectp || gPieObjectp->getVisible())
  4062. {
  4063. return;
  4064. }
  4065. //MK
  4066. if (gRLenabled && gRLInterface.mContainsInteract)
  4067. {
  4068. deselectAll();
  4069. return;
  4070. }
  4071. //mk
  4072. LLVector3d selectionCenter = getSelectionCenterGlobal();
  4073. static LLCachedControl<bool> limit_select_distance(gSavedSettings,
  4074. "LimitSelectDistance");
  4075. static LLCachedControl<F32> max_select_distance(gSavedSettings,
  4076. "MaxSelectDistance");
  4077. if (limit_select_distance &&
  4078. (!mSelectedObjects->getPrimaryObject() ||
  4079. !mSelectedObjects->getPrimaryObject()->isAvatar()) &&
  4080. !mSelectedObjects->isAttachment() &&
  4081. !selectionCenter.isExactlyZero())
  4082. {
  4083. F32 deselect_dist_sq = max_select_distance * max_select_distance;
  4084. LLVector3d select_delta = gAgent.getPositionGlobal() - selectionCenter;
  4085. F32 select_dist_sq = (F32) select_delta.lengthSquared();
  4086. if (select_dist_sq > deselect_dist_sq)
  4087. {
  4088. if (mDebugSelectMgr)
  4089. {
  4090. llinfos << "Selection manager: auto-deselecting, select_dist = "
  4091. << sqrtf(select_dist_sq)
  4092. << " - agent pos global = "
  4093. << gAgent.getPositionGlobal()
  4094. << " - selection pos global = "
  4095. << selectionCenter << llendl;
  4096. }
  4097. deselectAll();
  4098. }
  4099. }
  4100. }
  4101. void LLSelectMgr::selectionSetObjectName(const std::string& name)
  4102. {
  4103. // we only work correctly if 1 object is selected.
  4104. if (mSelectedObjects->getRootObjectCount() == 1)
  4105. {
  4106. sendListToRegions("ObjectName", packAgentAndSessionID, packObjectName,
  4107. (void*)(new std::string(name)), SEND_ONLY_ROOTS);
  4108. }
  4109. else if (mSelectedObjects->getObjectCount() == 1)
  4110. {
  4111. sendListToRegions("ObjectName", packAgentAndSessionID, packObjectName,
  4112. (void*)(new std::string(name)), SEND_INDIVIDUALS);
  4113. }
  4114. }
  4115. void LLSelectMgr::selectionSetObjectDescription(const std::string& desc)
  4116. {
  4117. // we only work correctly if 1 object is selected.
  4118. if (mSelectedObjects->getRootObjectCount() == 1)
  4119. {
  4120. sendListToRegions("ObjectDescription", packAgentAndSessionID,
  4121. packObjectDescription,
  4122. (void*)(new std::string(desc)), SEND_ONLY_ROOTS);
  4123. }
  4124. else if (mSelectedObjects->getObjectCount() == 1)
  4125. {
  4126. sendListToRegions("ObjectDescription", packAgentAndSessionID,
  4127. packObjectDescription,
  4128. (void*)(new std::string(desc)), SEND_INDIVIDUALS);
  4129. }
  4130. }
  4131. void LLSelectMgr::selectionSetObjectCategory(const LLCategory& category)
  4132. {
  4133. // for now, we only want to be able to set one root category at
  4134. // a time.
  4135. if (mSelectedObjects->getRootObjectCount() != 1) return;
  4136. sendListToRegions("ObjectCategory", packAgentAndSessionID,
  4137. packObjectCategory, (void*)&category, SEND_ONLY_ROOTS);
  4138. }
  4139. void LLSelectMgr::selectionSetObjectSaleInfo(const LLSaleInfo& sale_info)
  4140. {
  4141. sendListToRegions("ObjectSaleInfo", packAgentAndSessionID,
  4142. packObjectSaleInfo, (void*)&sale_info, SEND_ONLY_ROOTS);
  4143. }
  4144. //----------------------------------------------------------------------
  4145. // Attachments
  4146. //----------------------------------------------------------------------
  4147. void LLSelectMgr::sendAttach(U8 attachment_point)
  4148. {
  4149. LLViewerObject* attach_object = mSelectedObjects->getFirstRootObject();
  4150. if (!attach_object || !isAgentAvatarValid() ||
  4151. mSelectedObjects->mSelectType != SELECT_TYPE_WORLD)
  4152. {
  4153. return;
  4154. }
  4155. bool build_mode = gToolMgr.inEdit();
  4156. // Special case: Attach to default location for this object.
  4157. if (attachment_point == 0 ||
  4158. get_ptr_in_map(gAgentAvatarp->mAttachmentPoints,
  4159. (S32)attachment_point))
  4160. {
  4161. if (attachment_point != 0)
  4162. {
  4163. // If we know the attachment point then we got here by clicking an
  4164. // "Attach to..." context menu item, so we should add, not replace.
  4165. attachment_point |= ATTACHMENT_ADD;
  4166. }
  4167. sendListToRegions("ObjectAttach", packAgentIDAndSessionAndAttachment,
  4168. packObjectIDAndRotation, &attachment_point,
  4169. SEND_ONLY_ROOTS);
  4170. if (!build_mode)
  4171. {
  4172. // After "ObjectAttach" server will unsubscribe us from properties
  4173. // updates so either deselect objects or resend selection after
  4174. // attach packet reaches server In case of build_mode == true,
  4175. // LLPanelInventory::refresh() will deal with selection.
  4176. deselectAll();
  4177. }
  4178. }
  4179. }
  4180. void LLSelectMgr::sendDetach()
  4181. {
  4182. if (!mSelectedObjects->getNumNodes() ||
  4183. mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
  4184. {
  4185. return;
  4186. }
  4187. sendListToRegions("ObjectDetach", packAgentAndSessionID, packObjectLocalID,
  4188. NULL, SEND_ONLY_ROOTS);
  4189. }
  4190. void LLSelectMgr::sendDropAttachment()
  4191. {
  4192. if (!mSelectedObjects->getNumNodes() ||
  4193. mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
  4194. {
  4195. return;
  4196. }
  4197. sendListToRegions("ObjectDrop", packAgentAndSessionID, packObjectLocalID,
  4198. NULL, SEND_ONLY_ROOTS);
  4199. }
  4200. //----------------------------------------------------------------------
  4201. // Links
  4202. //----------------------------------------------------------------------
  4203. void LLSelectMgr::sendLink()
  4204. {
  4205. if (!mSelectedObjects->getNumNodes())
  4206. {
  4207. return;
  4208. }
  4209. sendListToRegions("ObjectLink", packAgentAndSessionID, packObjectLocalID,
  4210. NULL, SEND_ONLY_ROOTS);
  4211. }
  4212. void LLSelectMgr::sendDelink()
  4213. {
  4214. if (!mSelectedObjects->getNumNodes())
  4215. {
  4216. return;
  4217. }
  4218. struct f final : public LLSelectedObjectFunctor
  4219. {
  4220. f() {}
  4221. bool apply(LLViewerObject* object) override
  4222. {
  4223. if (object->permModify())
  4224. {
  4225. if (object->getPhysicsShapeType() == LLViewerObject::PHYSICS_SHAPE_NONE)
  4226. {
  4227. object->setPhysicsShapeType(LLViewerObject::PHYSICS_SHAPE_CONVEX_HULL);
  4228. object->updateFlags();
  4229. }
  4230. }
  4231. return true;
  4232. }
  4233. } sendfunc;
  4234. getSelection()->applyToObjects(&sendfunc);
  4235. // Delink needs to send individuals so you can unlink a single object from
  4236. // a linked set.
  4237. sendListToRegions("ObjectDelink", packAgentAndSessionID, packObjectLocalID,
  4238. NULL, SEND_INDIVIDUALS);
  4239. }
  4240. #ifdef SEND_HINGES
  4241. //----------------------------------------------------------------------
  4242. // Hinges
  4243. //----------------------------------------------------------------------
  4244. void LLSelectMgr::sendHinge(U8 type)
  4245. {
  4246. if (!mSelectedObjects->getNumNodes())
  4247. {
  4248. return;
  4249. }
  4250. sendListToRegions("ObjectHinge", packHingeHead, packObjectLocalID, &type,
  4251. SEND_ONLY_ROOTS);
  4252. }
  4253. void LLSelectMgr::sendDehinge()
  4254. {
  4255. if (!mSelectedObjects->getNumNodes())
  4256. {
  4257. return;
  4258. }
  4259. sendListToRegions("ObjectDehinge", packAgentAndSessionID, packObjectLocalID,
  4260. NULL, SEND_ONLY_ROOTS);
  4261. }
  4262. //static
  4263. void LLSelectMgr::packHingeHead(void* user_data)
  4264. {
  4265. U8* type = (U8*)user_data;
  4266. LLMessageSystem* msg = gMessageSystemp;
  4267. msg->nextBlockFast(_PREHASH_AgentData);
  4268. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4269. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4270. msg->nextBlockFast(_PREHASH_JointType);
  4271. msg->addU8Fast(_PREHASH_Type, *type);
  4272. }
  4273. #endif
  4274. void LLSelectMgr::sendSelect()
  4275. {
  4276. if (mSelectedObjects->getNumNodes())
  4277. {
  4278. sendListToRegions("ObjectSelect", packAgentAndSessionID,
  4279. packObjectLocalID, NULL, SEND_INDIVIDUALS);
  4280. }
  4281. }
  4282. void LLSelectMgr::selectionDump()
  4283. {
  4284. struct f final : public LLSelectedObjectFunctor
  4285. {
  4286. bool apply(LLViewerObject* object) override
  4287. {
  4288. object->dump();
  4289. return true;
  4290. }
  4291. } func;
  4292. getSelection()->applyToObjects(&func);
  4293. }
  4294. void LLSelectMgr::saveSelectedObjectColors()
  4295. {
  4296. struct f final : public LLSelectedNodeFunctor
  4297. {
  4298. bool apply(LLSelectNode* node) override
  4299. {
  4300. node->saveColors();
  4301. return true;
  4302. }
  4303. } func;
  4304. getSelection()->applyToNodes(&func);
  4305. }
  4306. void LLSelectMgr::saveSelectedObjectTextures()
  4307. {
  4308. // Invalidate current selection so we update saved textures
  4309. struct f final : public LLSelectedNodeFunctor
  4310. {
  4311. bool apply(LLSelectNode* node) override
  4312. {
  4313. node->mValid = false;
  4314. return true;
  4315. }
  4316. } func;
  4317. getSelection()->applyToNodes(&func);
  4318. // Request object properties message to get updated permissions data
  4319. sendSelect();
  4320. }
  4321. // This routine should be called whenever a drag is initiated.
  4322. // Also need to know to which simulator to send update message
  4323. void LLSelectMgr::saveSelectedObjectTransform(EActionType action_type)
  4324. {
  4325. if (mSelectedObjects->isEmpty())
  4326. {
  4327. // Nothing selected, so nothing to save
  4328. return;
  4329. }
  4330. struct f final : public LLSelectedNodeFunctor
  4331. {
  4332. f(EActionType a)
  4333. : mActionType(a)
  4334. {
  4335. }
  4336. bool apply(LLSelectNode* nodep) override
  4337. {
  4338. LLViewerObject* objectp = nodep->getObject();
  4339. if (!objectp)
  4340. {
  4341. return true; // skip
  4342. }
  4343. if (nodep->mSelectedGLTFNode != -1)
  4344. {
  4345. // Save GLTF node state
  4346. objectp->getGLTFNodeTransformAgent(nodep->mSelectedGLTFNode,
  4347. &nodep->mSavedPositionLocal,
  4348. &nodep->mSavedRotation,
  4349. &nodep->mSavedScale);
  4350. nodep->mSavedPositionGlobal =
  4351. gAgent.getPosGlobalFromAgent(nodep->mSavedPositionLocal);
  4352. nodep->mLastMoveLocal.setZero();
  4353. return true;
  4354. }
  4355. nodep->mSavedPositionLocal = objectp->getPosition();
  4356. if (objectp->isAttachment())
  4357. {
  4358. if (objectp->isRootEdit())
  4359. {
  4360. LLXform* xformp =
  4361. objectp->mDrawable->getXform()->getParent();
  4362. if (xformp)
  4363. {
  4364. nodep->mSavedPositionGlobal =
  4365. gAgent.getPosGlobalFromAgent((objectp->getPosition() *
  4366. xformp->getWorldRotation()) +
  4367. xformp->getWorldPosition());
  4368. }
  4369. else
  4370. {
  4371. nodep->mSavedPositionGlobal =
  4372. objectp->getPositionGlobal();
  4373. }
  4374. }
  4375. else
  4376. {
  4377. LLViewerObject* attachment_root =
  4378. (LLViewerObject*)objectp->getParent();
  4379. LLXform* xformp =
  4380. attachment_root ? attachment_root->mDrawable->getXform()->getParent()
  4381. : NULL;
  4382. if (xformp)
  4383. {
  4384. LLVector3 root_pos = (attachment_root->getPosition() *
  4385. xformp->getWorldRotation()) +
  4386. xformp->getWorldPosition();
  4387. LLQuaternion root_rot =
  4388. attachment_root->getRotation() *
  4389. xformp->getWorldRotation();
  4390. nodep->mSavedPositionGlobal =
  4391. gAgent.getPosGlobalFromAgent((objectp->getPosition() *
  4392. root_rot) +
  4393. root_pos);
  4394. }
  4395. else
  4396. {
  4397. nodep->mSavedPositionGlobal =
  4398. objectp->getPositionGlobal();
  4399. }
  4400. }
  4401. nodep->mSavedRotation = objectp->getRenderRotation();
  4402. }
  4403. else
  4404. {
  4405. nodep->mSavedPositionGlobal = objectp->getPositionGlobal();
  4406. nodep->mSavedRotation = objectp->getRotationRegion();
  4407. }
  4408. nodep->mSavedScale = objectp->getScale();
  4409. nodep->saveTextureScaleRatios();
  4410. return true;
  4411. }
  4412. EActionType mActionType;
  4413. } func(action_type);
  4414. getSelection()->applyToNodes(&func);
  4415. mSavedSelectionBBox = getBBoxOfSelection();
  4416. }
  4417. struct LLSelectMgrApplyFlags final : public LLSelectedObjectFunctor
  4418. {
  4419. LLSelectMgrApplyFlags(U32 flags, bool state)
  4420. : mFlags(flags),
  4421. mState(state)
  4422. {}
  4423. U32 mFlags;
  4424. bool mState;
  4425. bool apply(LLViewerObject* object) override
  4426. {
  4427. if (object->permModify() && // Preemptive permissions check
  4428. object->isRoot()) // Do not send for child objects
  4429. {
  4430. object->setFlags(mFlags, mState);
  4431. }
  4432. return true;
  4433. }
  4434. };
  4435. void LLSelectMgr::selectionUpdatePhysics(bool physics)
  4436. {
  4437. LLSelectMgrApplyFlags func(FLAGS_USE_PHYSICS, physics);
  4438. getSelection()->applyToObjects(&func);
  4439. }
  4440. void LLSelectMgr::selectionUpdateTemporary(bool is_temporary)
  4441. {
  4442. LLSelectMgrApplyFlags func(FLAGS_TEMPORARY_ON_REZ, is_temporary);
  4443. getSelection()->applyToObjects(&func);
  4444. }
  4445. void LLSelectMgr::selectionUpdatePhantom(bool is_phantom)
  4446. {
  4447. LLSelectMgrApplyFlags func(FLAGS_PHANTOM, is_phantom);
  4448. getSelection()->applyToObjects(&func);
  4449. }
  4450. //----------------------------------------------------------------------
  4451. // Helpful packing functions for sendObjectMessage()
  4452. //----------------------------------------------------------------------
  4453. //static
  4454. void LLSelectMgr::packAgentIDAndSessionAndAttachment(void* user_data)
  4455. {
  4456. U8* attachment_point = (U8*)user_data;
  4457. LLMessageSystem* msg = gMessageSystemp;
  4458. msg->nextBlockFast(_PREHASH_AgentData);
  4459. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4460. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4461. msg->addU8Fast(_PREHASH_AttachmentPoint, *attachment_point);
  4462. }
  4463. //static
  4464. void LLSelectMgr::packAgentID(void* user_data)
  4465. {
  4466. LLMessageSystem* msg = gMessageSystemp;
  4467. msg->nextBlockFast(_PREHASH_AgentData);
  4468. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4469. }
  4470. //static
  4471. void LLSelectMgr::packAgentAndSessionID(void* user_data)
  4472. {
  4473. LLMessageSystem* msg = gMessageSystemp;
  4474. msg->nextBlockFast(_PREHASH_AgentData);
  4475. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4476. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4477. }
  4478. //static
  4479. void LLSelectMgr::packAgentAndGroupID(void* user_data)
  4480. {
  4481. LLOwnerData *data = (LLOwnerData *)user_data;
  4482. LLMessageSystem* msg = gMessageSystemp;
  4483. msg->nextBlockFast(_PREHASH_AgentData);
  4484. msg->addUUIDFast(_PREHASH_AgentID, data->owner_id);
  4485. msg->addUUIDFast(_PREHASH_GroupID, data->group_id);
  4486. }
  4487. //static
  4488. void LLSelectMgr::packAgentAndSessionAndGroupID(void* user_data)
  4489. {
  4490. LLUUID* group_idp = (LLUUID*)user_data;
  4491. LLMessageSystem* msg = gMessageSystemp;
  4492. msg->nextBlockFast(_PREHASH_AgentData);
  4493. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4494. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4495. msg->addUUIDFast(_PREHASH_GroupID, *group_idp);
  4496. }
  4497. //static
  4498. void LLSelectMgr::packDuplicateHeader(void* data)
  4499. {
  4500. LLUUID group_id(gAgent.getGroupID());
  4501. if (gSavedSettings.getBool("RezWithLandGroup"))
  4502. {
  4503. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  4504. if (gAgent.isInGroup(parcel->getGroupID()))
  4505. {
  4506. group_id = parcel->getGroupID();
  4507. }
  4508. else if (gAgent.isInGroup(parcel->getOwnerID()))
  4509. {
  4510. group_id = parcel->getOwnerID();
  4511. }
  4512. }
  4513. packAgentAndSessionAndGroupID(&group_id);
  4514. LLDuplicateData* dup_data = (LLDuplicateData*)data;
  4515. LLMessageSystem* msg = gMessageSystemp;
  4516. msg->nextBlockFast(_PREHASH_SharedData);
  4517. msg->addVector3Fast(_PREHASH_Offset, dup_data->offset);
  4518. msg->addU32Fast(_PREHASH_DuplicateFlags, dup_data->flags);
  4519. }
  4520. //static
  4521. void LLSelectMgr::packDeleteHeader(void* userdata)
  4522. {
  4523. bool force = (bool)(intptr_t)userdata;
  4524. LLMessageSystem* msg = gMessageSystemp;
  4525. msg->nextBlockFast(_PREHASH_AgentData);
  4526. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4527. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4528. msg->addBoolFast(_PREHASH_Force, force);
  4529. }
  4530. //static
  4531. void LLSelectMgr::packAgentGroupAndCatID(void* user_data)
  4532. {
  4533. LLBuyData* buy = (LLBuyData*)user_data;
  4534. LLMessageSystem* msg = gMessageSystemp;
  4535. msg->nextBlockFast(_PREHASH_AgentData);
  4536. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4537. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4538. msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
  4539. msg->addUUIDFast(_PREHASH_CategoryID, buy->mCategoryID);
  4540. }
  4541. //static
  4542. void LLSelectMgr::packDeRezHeader(void* user_data)
  4543. {
  4544. LLDeRezInfo* info = (LLDeRezInfo*)user_data;
  4545. LLMessageSystem* msg = gMessageSystemp;
  4546. msg->nextBlockFast(_PREHASH_AgentData);
  4547. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4548. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4549. msg->nextBlockFast(_PREHASH_AgentBlock);
  4550. msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
  4551. msg->addU8Fast(_PREHASH_Destination, (U8)info->mDestination);
  4552. msg->addUUIDFast(_PREHASH_DestinationID, info->mDestinationID);
  4553. LLUUID tid;
  4554. tid.generate();
  4555. msg->addUUIDFast(_PREHASH_TransactionID, tid);
  4556. constexpr U8 PACKET = 1;
  4557. msg->addU8Fast(_PREHASH_PacketCount, PACKET);
  4558. msg->addU8Fast(_PREHASH_PacketNumber, PACKET);
  4559. }
  4560. //static
  4561. void LLSelectMgr::packObjectID(LLSelectNode* node, void* user_data)
  4562. {
  4563. LLMessageSystem* msg = gMessageSystemp;
  4564. msg->nextBlockFast(_PREHASH_ObjectData);
  4565. msg->addUUIDFast(_PREHASH_ObjectID, node->getObject()->mID);
  4566. }
  4567. void LLSelectMgr::packObjectIDAndRotation(LLSelectNode* node, void* user_data)
  4568. {
  4569. LLMessageSystem* msg = gMessageSystemp;
  4570. msg->nextBlockFast(_PREHASH_ObjectData);
  4571. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  4572. msg->addQuatFast(_PREHASH_Rotation, node->getObject()->getRotation());
  4573. }
  4574. void LLSelectMgr::packObjectClickAction(LLSelectNode* node, void* user_data)
  4575. {
  4576. LLMessageSystem* msg = gMessageSystemp;
  4577. msg->nextBlockFast(_PREHASH_ObjectData);
  4578. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  4579. msg->addU8("ClickAction", node->getObject()->getClickAction());
  4580. }
  4581. void LLSelectMgr::packObjectIncludeInSearch(LLSelectNode* node,
  4582. void* user_data)
  4583. {
  4584. LLMessageSystem* msg = gMessageSystemp;
  4585. msg->nextBlockFast(_PREHASH_ObjectData);
  4586. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  4587. msg->addBool("IncludeInSearch", node->getObject()->getIncludeInSearch());
  4588. }
  4589. //static
  4590. void LLSelectMgr::packObjectLocalID(LLSelectNode* node, void*)
  4591. {
  4592. LLMessageSystem* msg = gMessageSystemp;
  4593. msg->nextBlockFast(_PREHASH_ObjectData);
  4594. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  4595. }
  4596. //static
  4597. void LLSelectMgr::packObjectName(LLSelectNode* node, void* user_data)
  4598. {
  4599. const std::string* name = (const std::string*)user_data;
  4600. if (!name->empty())
  4601. {
  4602. LLMessageSystem* msg = gMessageSystemp;
  4603. msg->nextBlockFast(_PREHASH_ObjectData);
  4604. msg->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
  4605. msg->addStringFast(_PREHASH_Name, *name);
  4606. }
  4607. delete name;
  4608. }
  4609. //static
  4610. void LLSelectMgr::packObjectDescription(LLSelectNode* node, void* user_data)
  4611. {
  4612. const std::string* desc = (const std::string*)user_data;
  4613. if (desc && !desc->empty())
  4614. {
  4615. LLMessageSystem* msg = gMessageSystemp;
  4616. msg->nextBlockFast(_PREHASH_ObjectData);
  4617. msg->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
  4618. msg->addStringFast(_PREHASH_Description, *desc);
  4619. }
  4620. }
  4621. //static
  4622. void LLSelectMgr::packObjectCategory(LLSelectNode* node, void* user_data)
  4623. {
  4624. LLCategory* category = (LLCategory*)user_data;
  4625. if (category)
  4626. {
  4627. LLMessageSystem* msg = gMessageSystemp;
  4628. msg->nextBlockFast(_PREHASH_ObjectData);
  4629. msg->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
  4630. category->packMessage(msg);
  4631. }
  4632. }
  4633. //static
  4634. void LLSelectMgr::packObjectSaleInfo(LLSelectNode* node, void* user_data)
  4635. {
  4636. LLSaleInfo* sale_info = (LLSaleInfo*)user_data;
  4637. if (sale_info)
  4638. {
  4639. LLMessageSystem* msg = gMessageSystemp;
  4640. msg->nextBlockFast(_PREHASH_ObjectData);
  4641. msg->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
  4642. sale_info->packMessage(msg);
  4643. }
  4644. }
  4645. //static
  4646. void LLSelectMgr::packPhysics(LLSelectNode* node, void* user_data)
  4647. {
  4648. }
  4649. //static
  4650. void LLSelectMgr::packShape(LLSelectNode* node, void* user_data)
  4651. {
  4652. }
  4653. // Because there is a bug in message_template.msg, which define the "Set" field
  4654. // in the ObjectData block of the ObjectPermissions message as an U8 instead of
  4655. // a bool (it does not change anything at the message level, but it causes the
  4656. // viewers to issue warnings when they set "Set" as a bool, which it should be.
  4657. #define MESSAGE_TEMPLATE_FIXED 0
  4658. //static
  4659. void LLSelectMgr::packPermissions(LLSelectNode* node, void* user_data)
  4660. {
  4661. LLPermData* data = (LLPermData*)user_data;
  4662. LLMessageSystem* msg = gMessageSystemp;
  4663. msg->nextBlockFast(_PREHASH_ObjectData);
  4664. msg->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
  4665. msg->addU8Fast(_PREHASH_Field, data->mField);
  4666. #if MESSAGE_TEMPLATE_FIXED
  4667. msg->addBoolFast(_PREHASH_Set, data->mSet);
  4668. #else
  4669. msg->addU8Fast(_PREHASH_Set, data->mSet);
  4670. #endif
  4671. msg->addU32Fast(_PREHASH_Mask, data->mMask);
  4672. }
  4673. // Utility function to send some information to every region containing an
  4674. // object on the selection list. We want to do this to reduce the total number
  4675. // of packets sent by the viewer.
  4676. void LLSelectMgr::sendListToRegions(const std::string& message_name,
  4677. void (*pack_header)(void* user_data),
  4678. void (*pack_body)(LLSelectNode*, void*),
  4679. void* user_data,
  4680. ESendType send_type)
  4681. {
  4682. // Clear update override data (allow next update through)
  4683. struct f final : public LLSelectedNodeFunctor
  4684. {
  4685. bool apply(LLSelectNode* node) override
  4686. {
  4687. node->mLastPositionLocal.set(0, 0, 0);
  4688. node->mLastRotation = LLQuaternion();
  4689. node->mLastScale.set(0, 0, 0);
  4690. return true;
  4691. }
  4692. } func;
  4693. getSelection()->applyToNodes(&func);
  4694. struct push_all final : public LLSelectedNodeFunctor
  4695. {
  4696. std::queue<LLSelectNode*>& nodes_to_send;
  4697. push_all(std::queue<LLSelectNode*>& n)
  4698. : nodes_to_send(n)
  4699. {
  4700. }
  4701. bool apply(LLSelectNode* node) override
  4702. {
  4703. if (node->getObject())
  4704. {
  4705. nodes_to_send.push(node);
  4706. }
  4707. return true;
  4708. }
  4709. };
  4710. struct push_some final : public LLSelectedNodeFunctor
  4711. {
  4712. std::queue<LLSelectNode*>& nodes_to_send;
  4713. bool mRoots;
  4714. push_some(std::queue<LLSelectNode*>& n, bool roots)
  4715. : nodes_to_send(n),
  4716. mRoots(roots)
  4717. {
  4718. }
  4719. bool apply(LLSelectNode* node) override
  4720. {
  4721. LLViewerObject* object = node->getObject();
  4722. if (object)
  4723. {
  4724. bool is_root = object->isRootEdit();
  4725. if ((mRoots && is_root) || (!mRoots && !is_root))
  4726. {
  4727. nodes_to_send.push(node);
  4728. }
  4729. }
  4730. return true;
  4731. }
  4732. };
  4733. std::queue<LLSelectNode*> nodes_to_send;
  4734. struct push_all pushall(nodes_to_send);
  4735. struct push_some pushroots(nodes_to_send, true);
  4736. struct push_some pushnonroots(nodes_to_send, false);
  4737. switch (send_type)
  4738. {
  4739. case SEND_ONLY_ROOTS:
  4740. if (message_name == "ObjectBuy")
  4741. {
  4742. getSelection()->applyToRootNodes(&pushroots);
  4743. }
  4744. else
  4745. {
  4746. getSelection()->applyToRootNodes(&pushall);
  4747. }
  4748. break;
  4749. case SEND_INDIVIDUALS:
  4750. getSelection()->applyToNodes(&pushall);
  4751. break;
  4752. case SEND_ROOTS_FIRST:
  4753. // Roots first...
  4754. getSelection()->applyToNodes(&pushroots);
  4755. // ... then children.
  4756. getSelection()->applyToNodes(&pushnonroots);
  4757. break;
  4758. case SEND_CHILDREN_FIRST:
  4759. // Children first...
  4760. getSelection()->applyToNodes(&pushnonroots);
  4761. // ... then roots.
  4762. getSelection()->applyToNodes(&pushroots);
  4763. break;
  4764. default:
  4765. llwarns << "Bad send type " << send_type << llendl;
  4766. llassert(false);
  4767. return;
  4768. }
  4769. // Bail if nothing selected
  4770. if (nodes_to_send.empty())
  4771. {
  4772. return;
  4773. }
  4774. LLSelectNode* node = nodes_to_send.front();
  4775. nodes_to_send.pop();
  4776. bool link_operation = message_name == "ObjectLink";
  4777. LLSelectNode* linkset_root = NULL;
  4778. S32 objects_in_this_packet = 0;
  4779. // Cache last region information
  4780. LLViewerRegion* current_region = node->getObject()->getRegion();
  4781. // Start duplicate message
  4782. LLMessageSystem* msg = gMessageSystemp;
  4783. msg->newMessage(message_name.c_str());
  4784. (*pack_header)(user_data);
  4785. // For each object
  4786. while (node)
  4787. {
  4788. // Remember the last region, look up the current one
  4789. LLViewerRegion* last_region = current_region;
  4790. LLViewerObject* object = node->getObject();
  4791. current_region = object->getRegion();
  4792. // Ff to same simulator and message not too big
  4793. if (current_region == last_region && !msg->isSendFull(NULL) &&
  4794. objects_in_this_packet < MAX_OBJECTS_PER_PACKET)
  4795. {
  4796. if (link_operation && !linkset_root)
  4797. {
  4798. // Link sets over 254 will be split into multiple messages, but
  4799. // we need to provide same root for all messages or we will get
  4800. // separate linksets
  4801. linkset_root = node;
  4802. }
  4803. // Add another instance of the body of the data
  4804. (*pack_body)(node, user_data);
  4805. ++objects_in_this_packet;
  4806. // and on to the next object
  4807. if (nodes_to_send.empty())
  4808. {
  4809. node = NULL;
  4810. }
  4811. else
  4812. {
  4813. node = nodes_to_send.front();
  4814. nodes_to_send.pop();
  4815. }
  4816. }
  4817. else
  4818. {
  4819. // Otherwise send current message and start new one
  4820. msg->sendReliable(last_region->getHost());
  4821. objects_in_this_packet = 0;
  4822. msg->newMessage(message_name.c_str());
  4823. (*pack_header)(user_data);
  4824. if (linkset_root)
  4825. {
  4826. if (current_region == last_region)
  4827. {
  4828. // add root instance into new message
  4829. (*pack_body)(linkset_root, user_data);
  4830. ++objects_in_this_packet;
  4831. }
  4832. else
  4833. {
  4834. // Root should be in the same region as the children; reset
  4835. // it.
  4836. linkset_root = NULL;
  4837. }
  4838. }
  4839. // Do not move to the next object, we still need to add the body
  4840. // data.
  4841. }
  4842. }
  4843. // Flush messages
  4844. if (msg->getCurrentSendTotal() > 0)
  4845. {
  4846. msg->sendReliable(current_region->getHost());
  4847. }
  4848. else
  4849. {
  4850. msg->clearMessage();
  4851. }
  4852. }
  4853. //
  4854. // Network communications
  4855. //
  4856. void LLSelectMgr::registerObjectPropertiesFamilyRequest(const LLUUID& object_id)
  4857. {
  4858. sObjectPropertiesFamilyRequests.emplace(object_id);
  4859. }
  4860. void LLSelectMgr::requestObjectPropertiesFamily(LLViewerObject* object)
  4861. {
  4862. // Remember that we asked the properties of this object.
  4863. registerObjectPropertiesFamilyRequest(object->mID);
  4864. if (mDebugSelectMgr)
  4865. {
  4866. llinfos << "Registered a request for object: " << object->mID
  4867. << llendl;
  4868. }
  4869. LLMessageSystem* msg = gMessageSystemp;
  4870. msg->newMessageFast(_PREHASH_RequestObjectPropertiesFamily);
  4871. msg->nextBlockFast(_PREHASH_AgentData);
  4872. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4873. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4874. msg->nextBlockFast(_PREHASH_ObjectData);
  4875. msg->addU32Fast(_PREHASH_RequestFlags, 0x0);
  4876. msg->addUUIDFast(_PREHASH_ObjectID, object->mID);
  4877. LLViewerRegion* regionp = object->getRegion();
  4878. msg->sendReliable(regionp->getHost());
  4879. }
  4880. //static
  4881. void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void**)
  4882. {
  4883. S32 count = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
  4884. for (S32 i = 0; i < count; ++i)
  4885. {
  4886. LLUUID id;
  4887. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, id, i);
  4888. LLUUID creator_id, owner_id, group_id, extra_id;
  4889. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_CreatorID, creator_id,
  4890. i);
  4891. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id, i);
  4892. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID, group_id, i);
  4893. U64 creation_date;
  4894. msg->getU64Fast(_PREHASH_ObjectData, _PREHASH_CreationDate,
  4895. creation_date, i);
  4896. U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
  4897. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask, base_mask, i);
  4898. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask, owner_mask,
  4899. i);
  4900. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_GroupMask, group_mask,
  4901. i);
  4902. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask,
  4903. everyone_mask, i);
  4904. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask,
  4905. next_owner_mask, i);
  4906. LLSaleInfo sale_info;
  4907. sale_info.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
  4908. LLAggregatePermissions ag_perms, ag_tex_perms, ag_tex_perms_owner;
  4909. ag_perms.unpackMessage(msg, _PREHASH_ObjectData,
  4910. _PREHASH_AggregatePerms, i);
  4911. ag_tex_perms.unpackMessage(msg, _PREHASH_ObjectData,
  4912. _PREHASH_AggregatePermTextures, i);
  4913. ag_tex_perms_owner.unpackMessage(msg, _PREHASH_ObjectData,
  4914. _PREHASH_AggregatePermTexturesOwner,
  4915. i);
  4916. LLCategory category;
  4917. category.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
  4918. S16 inv_serial = 0;
  4919. msg->getS16Fast(_PREHASH_ObjectData, _PREHASH_InventorySerial,
  4920. inv_serial, i);
  4921. LLUUID item_id, folder_id, from_task_id;
  4922. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ItemID, item_id, i);
  4923. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FolderID, folder_id, i);
  4924. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FromTaskID,
  4925. from_task_id, i);
  4926. LLUUID last_owner_id;
  4927. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID,
  4928. last_owner_id, i);
  4929. std::string name, desc, touch_name, sit_name;
  4930. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name, i);
  4931. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc, i);
  4932. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_TouchName, touch_name,
  4933. i);
  4934. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_SitName, sit_name, i);
  4935. // Unpack TE IDs
  4936. uuid_vec_t texture_ids;
  4937. S32 size = msg->getSizeFast(_PREHASH_ObjectData, i,
  4938. _PREHASH_TextureID);
  4939. if (size > 0)
  4940. {
  4941. S8 packed_buffer[SELECT_MAX_TES * UUID_BYTES];
  4942. msg->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureID,
  4943. packed_buffer, 0, i,
  4944. SELECT_MAX_TES * UUID_BYTES);
  4945. for (S32 buf_offset = 0; buf_offset < size;
  4946. buf_offset += UUID_BYTES)
  4947. {
  4948. LLUUID tid;
  4949. memcpy(tid.mData, packed_buffer + buf_offset, UUID_BYTES);
  4950. texture_ids.emplace_back(tid);
  4951. }
  4952. }
  4953. // Iterate through nodes at end, since it can be on both the regular
  4954. // AND hover list
  4955. struct f final : public LLSelectedNodeFunctor
  4956. {
  4957. LLUUID mID;
  4958. f(const LLUUID& id)
  4959. : mID(id)
  4960. {
  4961. }
  4962. bool apply(LLSelectNode* nodep) override
  4963. {
  4964. LLViewerObject* objectp = nodep->getObject();
  4965. return objectp && objectp->mID == mID;
  4966. }
  4967. } func(id);
  4968. LLSelectNode* nodep = gSelectMgr.getSelection()->getFirstNode(&func);
  4969. if (!nodep) continue;
  4970. // Save texture data as soon as we get texture perms first time
  4971. bool save_textures = !nodep->mValid;
  4972. LLViewerObject* objectp = nodep->getObject();
  4973. if (objectp && objectp->getInventorySerial() != inv_serial)
  4974. {
  4975. objectp->dirtyInventory();
  4976. // Even if this is not object's first udpate, inventory changed and
  4977. // some of the applied textures might have been in inventory, so
  4978. // update texture list.
  4979. save_textures = true;
  4980. }
  4981. if (save_textures)
  4982. {
  4983. bool can_copy = false;
  4984. bool can_transfer = false;
  4985. LLAggregatePermissions::EValue value =
  4986. LLAggregatePermissions::AP_NONE;
  4987. if (objectp && objectp->permYouOwner())
  4988. {
  4989. value = ag_tex_perms_owner.getValue(PERM_COPY);
  4990. if (value == LLAggregatePermissions::AP_EMPTY ||
  4991. value == LLAggregatePermissions::AP_ALL)
  4992. {
  4993. can_copy = true;
  4994. }
  4995. value = ag_tex_perms_owner.getValue(PERM_TRANSFER);
  4996. if (value == LLAggregatePermissions::AP_EMPTY ||
  4997. value == LLAggregatePermissions::AP_ALL)
  4998. {
  4999. can_transfer = true;
  5000. }
  5001. }
  5002. else
  5003. {
  5004. value = ag_tex_perms.getValue(PERM_COPY);
  5005. if (value == LLAggregatePermissions::AP_EMPTY ||
  5006. value == LLAggregatePermissions::AP_ALL)
  5007. {
  5008. can_copy = true;
  5009. }
  5010. value = ag_tex_perms.getValue(PERM_TRANSFER);
  5011. if (value == LLAggregatePermissions::AP_EMPTY ||
  5012. value == LLAggregatePermissions::AP_ALL)
  5013. {
  5014. can_transfer = true;
  5015. }
  5016. }
  5017. if (can_copy && can_transfer)
  5018. {
  5019. // This should be the only place that saved textures is called
  5020. nodep->saveTextures(texture_ids);
  5021. }
  5022. if (can_copy && can_transfer && objectp->getVolume())
  5023. {
  5024. uuid_vec_t mat_ids;
  5025. gltf_mat_vec_t mats;
  5026. LLVOVolume* vobjp = (LLVOVolume*)objectp;
  5027. for (U32 te = 0, tes = vobjp->getNumTEs(); te < tes; ++te)
  5028. {
  5029. mat_ids.push_back(vobjp->getRenderMaterialID(te));
  5030. // Make a copy to ensure we would not affect live material
  5031. // with any potential changes nor live changes will be
  5032. // reflected in a saved copy, like changes from local
  5033. // material (reuses pointer) or from live editor (revert
  5034. // mechanics might modify this).
  5035. LLTextureEntry* tep = objectp->getTE(te);
  5036. LLGLTFMaterial* matp = NULL;
  5037. if (tep)
  5038. {
  5039. matp = tep->getGLTFMaterialOverride();
  5040. }
  5041. if (matp)
  5042. {
  5043. mats.emplace_back(new LLGLTFMaterial(*matp));
  5044. }
  5045. else
  5046. {
  5047. mats.emplace_back(nullptr);
  5048. }
  5049. }
  5050. // processObjectProperties() does not include overrides so this
  5051. // might need to be moved to
  5052. // LLGLTFMaterialOverrideDispatchHandler
  5053. nodep->saveGLTFMaterials(mat_ids, mats);
  5054. }
  5055. }
  5056. nodep->mValid = true;
  5057. nodep->mPermissions->init(creator_id, owner_id, last_owner_id,
  5058. group_id);
  5059. nodep->mPermissions->initMasks(base_mask, owner_mask, everyone_mask,
  5060. group_mask, next_owner_mask);
  5061. nodep->mCreationDate = creation_date;
  5062. nodep->mItemID = item_id;
  5063. nodep->mFolderID = folder_id;
  5064. nodep->mFromTaskID = from_task_id;
  5065. nodep->mName.assign(name);
  5066. nodep->mDescription.assign(desc);
  5067. nodep->mSaleInfo = sale_info;
  5068. nodep->mAggregatePerm = ag_perms;
  5069. nodep->mAggregateTexturePerm = ag_tex_perms;
  5070. nodep->mAggregateTexturePermOwner = ag_tex_perms_owner;
  5071. nodep->mCategory = category;
  5072. nodep->mInventorySerial = inv_serial;
  5073. nodep->mSitName.assign(sit_name);
  5074. nodep->mTouchName.assign(touch_name);
  5075. }
  5076. dialog_refresh_all();
  5077. // *HACK: for left-click buy object
  5078. LLToolPie::selectionPropertiesReceived();
  5079. }
  5080. //static
  5081. void LLSelectMgr::processObjectPropertiesFamily(LLMessageSystem* msg, void**)
  5082. {
  5083. LLUUID id;
  5084. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, id);
  5085. LLUUID owner_id;
  5086. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id);
  5087. // Keep track of the owner's Id for that object.
  5088. LLViewerObject* objectp = gObjectList.findObject(id);
  5089. if (objectp && objectp->mOwnerID.isNull())
  5090. {
  5091. objectp->mOwnerID = owner_id;
  5092. }
  5093. uuid_list_t::iterator it = sObjectPropertiesFamilyRequests.find(id);
  5094. if (it == sObjectPropertiesFamilyRequests.end())
  5095. {
  5096. // This reply is not for us.
  5097. return;
  5098. }
  5099. // We got the reply, so remove the object from the list of pending requests
  5100. sObjectPropertiesFamilyRequests.erase(it);
  5101. if (gSelectMgr.mDebugSelectMgr)
  5102. {
  5103. llinfos << "Got ObjectPropertiesFamily reply for object: " << id
  5104. << llendl;
  5105. }
  5106. U32 request_flags;
  5107. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_RequestFlags, request_flags);
  5108. LLUUID group_id;
  5109. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID, group_id);
  5110. U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
  5111. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask, base_mask);
  5112. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask, owner_mask);
  5113. msg->getU32Fast(_PREHASH_ObjectData,_PREHASH_GroupMask, group_mask);
  5114. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask, everyone_mask);
  5115. msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask,
  5116. next_owner_mask);
  5117. LLSaleInfo sale_info;
  5118. sale_info.unpackMessage(msg, _PREHASH_ObjectData);
  5119. LLCategory category;
  5120. category.unpackMessage(msg, _PREHASH_ObjectData);
  5121. LLUUID last_owner_id;
  5122. msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID, last_owner_id);
  5123. std::string name, desc;
  5124. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name);
  5125. msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc);
  5126. // The reporter widget asks the server for info about picked objects
  5127. if (request_flags & COMPLAINT_REPORT_REQUEST)
  5128. {
  5129. LLFloaterReporter* reporterp = LLFloaterReporter::findInstance();
  5130. if (reporterp)
  5131. {
  5132. std::string fullname;
  5133. if (gCacheNamep)
  5134. {
  5135. gCacheNamep->getFullName(owner_id, fullname);
  5136. }
  5137. reporterp->setPickedObjectProperties(name, fullname, owner_id);
  5138. }
  5139. }
  5140. else if (request_flags & OBJECT_PAY_REQUEST)
  5141. {
  5142. // Check if the owner of the paid object is muted
  5143. LLMuteList::autoRemove(owner_id, LLMuteList::AR_MONEY);
  5144. }
  5145. // Now look through all of the hovered nodes
  5146. struct f final : public LLSelectedNodeFunctor
  5147. {
  5148. f(const LLUUID& id)
  5149. : mID(id)
  5150. {
  5151. }
  5152. bool apply(LLSelectNode* node) override
  5153. {
  5154. return node->getObject() && node->getObject()->mID == mID;
  5155. }
  5156. LLUUID mID;
  5157. } func(id);
  5158. LLSelectNode* node = gSelectMgr.mHoverObjects->getFirstNode(&func);
  5159. if (node)
  5160. {
  5161. node->mValid = true;
  5162. node->mPermissions->init(LLUUID::null, owner_id,
  5163. last_owner_id, group_id);
  5164. node->mPermissions->initMasks(base_mask, owner_mask, everyone_mask,
  5165. group_mask, next_owner_mask);
  5166. node->mSaleInfo = sale_info;
  5167. node->mCategory = category;
  5168. node->mName.assign(name);
  5169. node->mDescription.assign(desc);
  5170. }
  5171. dialog_refresh_all();
  5172. }
  5173. //static
  5174. void LLSelectMgr::processForceObjectSelect(LLMessageSystem* msg, void**)
  5175. {
  5176. bool reset_list;
  5177. msg->getBool("Header", "ResetList", reset_list);
  5178. if (reset_list)
  5179. {
  5180. gSelectMgr.deselectAll();
  5181. }
  5182. std::vector<LLViewerObject*> objects;
  5183. S32 local_id;
  5184. LLUUID full_id;
  5185. U32 ip = msg->getSenderIP();
  5186. U32 port = msg->getSenderPort();
  5187. for (S32 i = 0, count = msg->getNumberOfBlocks("Data"); i < count; ++i)
  5188. {
  5189. msg->getS32("Data", "LocalID", local_id, i);
  5190. gObjectList.getUUIDFromLocal(full_id, local_id, ip, port);
  5191. LLViewerObject* object = gObjectList.findObject(full_id);
  5192. if (object)
  5193. {
  5194. objects.push_back(object);
  5195. }
  5196. }
  5197. // Do not select, just highlight
  5198. gSelectMgr.highlightObjectAndFamily(objects);
  5199. }
  5200. void LLSelectMgr::updateSilhouettes()
  5201. {
  5202. if (!mSilhouetteImagep)
  5203. {
  5204. mSilhouetteImagep =
  5205. LLViewerTextureManager::getFetchedTextureFromFile("silhouette.j2c");
  5206. }
  5207. mHighlightedObjects->cleanupNodes();
  5208. LLVector3d camera_pos = gAgent.getCameraPositionGlobal();
  5209. F32 camera_zoom = gAgent.getCurrentCameraBuildOffset();
  5210. if ((camera_pos - mLastCameraPos).lengthSquared() >
  5211. SILHOUETTE_UPDATE_THRESHOLD_SQUARED * camera_zoom * camera_zoom)
  5212. {
  5213. struct f final : public LLSelectedObjectFunctor
  5214. {
  5215. bool apply(LLViewerObject* object) override
  5216. {
  5217. object->setChanged(LLXform::SILHOUETTE);
  5218. return true;
  5219. }
  5220. } func;
  5221. getSelection()->applyToObjects(&func);
  5222. mLastCameraPos = gAgent.getCameraPositionGlobal();
  5223. }
  5224. std::vector<LLViewerObject*> changed_objects;
  5225. S32 num_sils_genned = 0;
  5226. updateSelectionSilhouette(mSelectedObjects, num_sils_genned,
  5227. changed_objects);
  5228. if (mRectSelectedObjects.size() > 0)
  5229. {
  5230. fast_hset<LLViewerObject*> roots;
  5231. // Sync mHighlightedObjects with mRectSelectedObjects since the latter
  5232. // is rebuilt every frame and former persists from frame to frame to
  5233. // avoid regenerating object silhouettes mHighlightedObjects includes
  5234. // all siblings of rect selected objects
  5235. bool select_linked_set = !mEditLinkedParts;
  5236. // generate list of roots from current object selection
  5237. for (std::set<LLPointer<LLViewerObject> >::iterator
  5238. iter = mRectSelectedObjects.begin(),
  5239. end = mRectSelectedObjects.end();
  5240. iter != end; ++iter)
  5241. {
  5242. LLViewerObject* objectp = *iter;
  5243. if (select_linked_set)
  5244. {
  5245. roots.insert((LLViewerObject*)objectp->getRoot());
  5246. }
  5247. else
  5248. {
  5249. roots.insert(objectp);
  5250. }
  5251. }
  5252. // Remove highlight nodes not in roots list
  5253. std::vector<LLSelectNode*> remove_these_nodes;
  5254. std::vector<LLViewerObject*> remove_these_roots;
  5255. for (LLObjectSelection::iterator iter = mHighlightedObjects->begin(),
  5256. end = mHighlightedObjects->end();
  5257. iter != end; ++iter)
  5258. {
  5259. LLSelectNode* node = *iter;
  5260. LLViewerObject* objectp = node->getObject();
  5261. if (!objectp) continue;
  5262. if (objectp->isRoot() || !select_linked_set)
  5263. {
  5264. if (roots.count(objectp) == 0)
  5265. {
  5266. remove_these_nodes.push_back(node);
  5267. }
  5268. else
  5269. {
  5270. remove_these_roots.push_back(objectp);
  5271. }
  5272. }
  5273. else if (!roots.count((LLViewerObject*)objectp->getRoot()))
  5274. {
  5275. remove_these_nodes.push_back(node);
  5276. }
  5277. }
  5278. // Remove all highlight nodes no longer in rectangle selection
  5279. for (std::vector<LLSelectNode*>::iterator
  5280. iter = remove_these_nodes.begin(),
  5281. end = remove_these_nodes.end();
  5282. iter != end; ++iter)
  5283. {
  5284. LLSelectNode* nodep = *iter;
  5285. mHighlightedObjects->removeNode(nodep);
  5286. }
  5287. // Remove all root objects already being highlighted
  5288. for (std::vector<LLViewerObject*>::iterator
  5289. iter = remove_these_roots.begin(),
  5290. end = remove_these_roots.end();
  5291. iter != end; ++iter)
  5292. {
  5293. LLViewerObject* objectp = *iter;
  5294. roots.erase(objectp);
  5295. }
  5296. // Add all new objects in rectangle selection
  5297. for (fast_hset<LLViewerObject*>::iterator iter = roots.begin(),
  5298. end = roots.end();
  5299. iter != end; ++iter)
  5300. {
  5301. LLViewerObject* objectp = *iter;
  5302. if (!canSelectObject(objectp))
  5303. {
  5304. continue;
  5305. }
  5306. LLSelectNode* rect_select_root_node = new LLSelectNode(objectp,
  5307. true);
  5308. rect_select_root_node->selectAllTEs(true);
  5309. if (!select_linked_set)
  5310. {
  5311. rect_select_root_node->mIndividualSelection = true;
  5312. }
  5313. else
  5314. {
  5315. LLViewerObject::const_child_list_t& child_list =
  5316. objectp->getChildren();
  5317. for (LLViewerObject::child_list_t::const_iterator
  5318. iter2 = child_list.begin(),
  5319. end2 = child_list.end();
  5320. iter2 != end2; ++iter2)
  5321. {
  5322. LLViewerObject* child_objectp = *iter2;
  5323. if (!canSelectObject(child_objectp))
  5324. {
  5325. continue;
  5326. }
  5327. LLSelectNode* rect_select_node =
  5328. new LLSelectNode(child_objectp, true);
  5329. rect_select_node->selectAllTEs(true);
  5330. mHighlightedObjects->addNodeAtEnd(rect_select_node);
  5331. }
  5332. }
  5333. // Add the root last, to preserve order for link operations.
  5334. mHighlightedObjects->addNodeAtEnd(rect_select_root_node);
  5335. }
  5336. num_sils_genned = 0;
  5337. const LLVector3& camera_origin = gViewerCamera.getOrigin();
  5338. // Render silhouettes for highlighted objects
  5339. for (S32 pass = 0; pass < 2; ++pass)
  5340. {
  5341. for (LLObjectSelection::iterator iter = mHighlightedObjects->begin();
  5342. iter != mHighlightedObjects->end(); ++iter)
  5343. {
  5344. LLSelectNode* nodep = *iter;
  5345. if (!nodep) continue; // Paranoia
  5346. LLViewerObject* objectp = nodep->getObject();
  5347. if (!objectp || objectp->isDead())
  5348. {
  5349. continue;
  5350. }
  5351. // Do roots first, then children so that root flags are cleared
  5352. // ASAP
  5353. bool roots_only = pass == 0;
  5354. bool is_root = objectp->isRootEdit();
  5355. if (roots_only != is_root)
  5356. {
  5357. continue;
  5358. }
  5359. if (nodep->mSilhouetteGenerated &&
  5360. !objectp->isChanged(LLXform::SILHOUETTE) &&
  5361. (is_root ||
  5362. !objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
  5363. {
  5364. continue;
  5365. }
  5366. if (num_sils_genned++ < MAX_SILS_PER_FRAME)
  5367. {
  5368. generateSilhouette(nodep, camera_origin);
  5369. changed_objects.push_back(objectp);
  5370. continue;
  5371. }
  5372. if (!objectp->isAttachment())
  5373. {
  5374. continue;
  5375. }
  5376. LLDrawable* drawablep = objectp->getRootEdit()->mDrawable;
  5377. if (!drawablep)
  5378. {
  5379. continue;
  5380. }
  5381. // RN: hack for orthogonal projection of HUD attachments
  5382. LLViewerJointAttachment* attachp =
  5383. (LLViewerJointAttachment*)drawablep->getParent();
  5384. if (attachp && attachp->getIsHUDAttachment())
  5385. {
  5386. generateSilhouette(nodep, LLVector3(-10000.f, 0.f, 0.f));
  5387. }
  5388. }
  5389. }
  5390. }
  5391. else
  5392. {
  5393. mHighlightedObjects->deleteAllNodes();
  5394. }
  5395. for (std::vector<LLViewerObject*>::iterator iter = changed_objects.begin(),
  5396. end = changed_objects.end();
  5397. iter != end; ++iter)
  5398. {
  5399. // Clear flags after traversing node list (as child objects need to
  5400. // refer to parent flags, etc)
  5401. LLViewerObject* objectp = *iter;
  5402. objectp->clearChanged(LLXform::MOVED | LLXform::SILHOUETTE);
  5403. }
  5404. }
  5405. void LLSelectMgr::updateSelectionSilhouette(LLObjectSelectionHandle object_handle,
  5406. S32& num_sils_genned,
  5407. std::vector<LLViewerObject*>& changed_objects)
  5408. {
  5409. if (!object_handle->getNumNodes())
  5410. {
  5411. return;
  5412. }
  5413. const LLVector3& camera_origin = gViewerCamera.getOrigin();
  5414. for (S32 pass = 0; pass < 2; ++pass)
  5415. {
  5416. for (LLObjectSelection::iterator iter = object_handle->begin(),
  5417. end = object_handle->end();
  5418. iter != end; ++iter)
  5419. {
  5420. LLSelectNode* nodep = *iter;
  5421. if (!nodep) continue; // Paranoia
  5422. LLViewerObject* objectp = nodep->getObject();
  5423. if (!objectp || objectp->isDead()) continue;
  5424. // Do roots first, then children so that root flags are cleared
  5425. // ASAP
  5426. bool roots_only = pass == 0;
  5427. bool is_root = objectp->isRootEdit();
  5428. if (roots_only != is_root || objectp->mDrawable.isNull())
  5429. {
  5430. continue;
  5431. }
  5432. if (!nodep->mSilhouetteGenerated ||
  5433. objectp->isChanged(LLXform::SILHOUETTE) ||
  5434. (!is_root &&
  5435. objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
  5436. {
  5437. if (num_sils_genned++ < MAX_SILS_PER_FRAME)
  5438. {
  5439. generateSilhouette(nodep, camera_origin);
  5440. changed_objects.push_back(objectp);
  5441. }
  5442. else if (objectp->isAttachment())
  5443. {
  5444. // RN: hack for orthogonal projection of HUD attachments
  5445. LLViewerJointAttachment* attachment_pt =
  5446. (LLViewerJointAttachment*)objectp->getRootEdit()->mDrawable->getParent();
  5447. if (attachment_pt && attachment_pt->getIsHUDAttachment())
  5448. {
  5449. generateSilhouette(nodep,
  5450. LLVector3(-10000.f, 0.f, 0.f));
  5451. }
  5452. }
  5453. }
  5454. }
  5455. }
  5456. }
  5457. // Helper function for LLSelectMgr::renderMeshSelection().
  5458. static void render_face(LLDrawable* drawablep, LLFace* facep)
  5459. {
  5460. if (!drawablep || drawablep->isDead()) return;
  5461. LLVOVolume* vovolp = drawablep->getVOVolume();
  5462. if (!vovolp || !facep) return;
  5463. LLVolume* volp;
  5464. if (drawablep->isState(LLDrawable::RIGGED))
  5465. {
  5466. volp = vovolp->getRiggedVolume();
  5467. }
  5468. else
  5469. {
  5470. volp = vovolp->getVolume();
  5471. }
  5472. // While rezzing a mesh object, it may happen that the face TE offset is
  5473. // larger than the current object number of faces, because the mesh is not
  5474. // yet fully loaded. Check for this case and skip, to avoid a crash
  5475. // whenever this object is also selected (e.g. when rezzing while in Build
  5476. // mode). HB
  5477. if (volp && facep->getTEOffset() < (S32)volp->getVolumeFaces().size())
  5478. {
  5479. const LLVolumeFace& vf = volp->getVolumeFace(facep->getTEOffset());
  5480. LLVertexBuffer::drawElements(vf.mNumVertices, vf.mPositions, NULL,
  5481. vf.mNumIndices, vf.mIndices);
  5482. }
  5483. }
  5484. // Only used for the PBR renderer (the EE renderer still uses the v1 legacy
  5485. // selection rendering routines). HB
  5486. void LLSelectMgr::renderMeshSelection(LLSelectNode* nodep,
  5487. LLViewerObject* objectp,
  5488. LLDrawable* drawablep,
  5489. LLVOVolume* volp,
  5490. const LLColor4& color, bool no_hidden)
  5491. {
  5492. bool wireframe = renderHiddenSelection() && !no_hidden;
  5493. LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
  5494. gGL.flush();
  5495. if (shaderp)
  5496. {
  5497. gDebugProgram.bind();
  5498. }
  5499. gGL.matrixMode(LLRender::MM_MODELVIEW);
  5500. gGL.pushMatrix();
  5501. bool is_hud_object = objectp->isHUDAttachment();
  5502. if (!is_hud_object)
  5503. {
  5504. gGL.loadIdentity();
  5505. gGL.multMatrix(gGLModelView);
  5506. }
  5507. if (drawablep->isActive())
  5508. {
  5509. gGL.loadMatrix(gGLModelView);
  5510. gGL.multMatrix(objectp->getRenderMatrix().getF32ptr());
  5511. }
  5512. else if (!is_hud_object)
  5513. {
  5514. LLVector3 trans = objectp->getRegion()->getOriginAgent();
  5515. gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
  5516. }
  5517. LLVertexBuffer::unbind();
  5518. gGL.pushMatrix();
  5519. gGL.multMatrix(volp->getRelativeXform().getF32ptr());
  5520. if (drawablep->isState(LLDrawable::RIGGED))
  5521. {
  5522. volp->updateRiggedVolume(true);
  5523. }
  5524. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  5525. for (U32 te = 0,
  5526. count = llmin(objectp->getNumTEs(), objectp->getNumFaces());
  5527. te < count; ++te)
  5528. {
  5529. if (nodep->isTESelected(te))
  5530. {
  5531. LLFace* facep = objectp->mDrawable->getFace(te);
  5532. if (!facep) continue; // Paranoia.
  5533. // Question: would niot it be also drawablep ?... HB
  5534. LLDrawable* drawp = facep->getDrawable().get();
  5535. if (!drawp) continue; // Paranoia.
  5536. // The following code is the simplified form (shader always
  5537. // exists, no stencil since reserved for PBR rendering) of LL's
  5538. // LLFace::renderOneWireframe(), that we do not have. HB
  5539. if (wireframe)
  5540. {
  5541. gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
  5542. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL);
  5543. gGL.diffuseColor4f(color.mV[VRED], color.mV[VGREEN],
  5544. color.mV[VBLUE], 0.4f);
  5545. render_face(drawp, facep);
  5546. }
  5547. gGL.flush();
  5548. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  5549. gGL.diffuseColor4f(color.mV[VRED] * 2.f, color.mV[VGREEN] * 2.f,
  5550. color.mV[VBLUE] * 2.f, color.mV[VALPHA]);
  5551. {
  5552. LLGLDisable depth(wireframe ? 0 : GL_BLEND);
  5553. LLGLEnable offset(GL_POLYGON_OFFSET_LINE);
  5554. glPolygonOffset(3.f, 3.f);
  5555. gGL.lineWidth(5.f);
  5556. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  5557. render_face(drawp, facep);
  5558. }
  5559. }
  5560. }
  5561. gGL.popMatrix();
  5562. gGL.popMatrix();
  5563. gGL.lineWidth(1.f);
  5564. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  5565. if (shaderp)
  5566. {
  5567. shaderp->bind();
  5568. }
  5569. }
  5570. void LLSelectMgr::renderSilhouettes(bool for_hud)
  5571. {
  5572. if (!mRenderSilhouettes || !mRenderSelectionsPolicy)
  5573. {
  5574. return;
  5575. }
  5576. LLTexUnit* unit0 = gGL.getTexUnit(0);
  5577. unit0->bind(mSilhouetteImagep);
  5578. LLGLSPipelineSelection gls_select;
  5579. LLGLEnable blend(GL_BLEND);
  5580. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  5581. if (for_hud && isAgentAvatarValid())
  5582. {
  5583. LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
  5584. F32 cur_zoom = gAgent.mHUDCurZoom;
  5585. // Set-up transform to encompass bounding box of HUD
  5586. gGL.matrixMode(LLRender::MM_PROJECTION);
  5587. gGL.pushMatrix();
  5588. gGL.loadIdentity();
  5589. F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
  5590. gGL.ortho(-0.5f * gViewerCamera.getAspect(),
  5591. 0.5f * gViewerCamera.getAspect(),
  5592. -0.5f, 0.5f, 0.f, depth);
  5593. gGL.matrixMode(LLRender::MM_MODELVIEW);
  5594. gGL.pushMatrix();
  5595. gGL.pushUIMatrix();
  5596. gGL.loadUIIdentity();
  5597. gGL.loadIdentity();
  5598. // Load Cory's favorite reference frame
  5599. gGL.loadMatrix(OGL_TO_CFR_ROT4A);
  5600. gGL.translatef(-hud_bbox.getCenterLocal().mV[VX] + depth * 0.5f,
  5601. 0.f, 0.f);
  5602. gGL.scalef(cur_zoom, cur_zoom, cur_zoom);
  5603. }
  5604. if (mSelectedObjects->getNumNodes())
  5605. {
  5606. LLColor4 color;
  5607. LLUUID inspect_item_id = LLFloaterInspect::getSelectedUUID();
  5608. LLUUID focus_item_id = LLViewerMediaFocus::getInstance()->getFocusedObjectID();
  5609. for (LLObjectSelection::iterator iter = mSelectedObjects->begin(),
  5610. end = mSelectedObjects->end();
  5611. iter != end; ++iter)
  5612. {
  5613. LLSelectNode* nodep = *iter;
  5614. if (!nodep) continue; // Paranoia ?
  5615. LLViewerObject* objectp = nodep->getObject();
  5616. if (!objectp || objectp->isDead() ||
  5617. objectp->isHUDAttachment() != for_hud)
  5618. {
  5619. continue;
  5620. }
  5621. LLDrawable* drawablep = objectp->mDrawable;
  5622. if (!drawablep)
  5623. {
  5624. continue;
  5625. }
  5626. bool no_hidden = false;
  5627. if (objectp->getID() == focus_item_id)
  5628. {
  5629. color = gFocusMgr.getFocusColor();
  5630. }
  5631. else if (objectp->getID() == inspect_item_id)
  5632. {
  5633. color = sHighlightInspectColor;
  5634. }
  5635. else if (nodep->isTransient())
  5636. {
  5637. color = sContextSilhouetteColor;
  5638. no_hidden = true;
  5639. }
  5640. else if (objectp->isRootEdit())
  5641. {
  5642. color = sSilhouetteParentColor;
  5643. }
  5644. else
  5645. {
  5646. color = sSilhouetteChildColor;
  5647. }
  5648. LLVOVolume* volp = drawablep->getVOVolume();
  5649. if (gUsePBRShaders && volp && volp->isMesh())
  5650. {
  5651. renderMeshSelection(nodep, objectp, drawablep, volp, color,
  5652. no_hidden);
  5653. }
  5654. else
  5655. {
  5656. nodep->renderOneSilhouette(color, no_hidden);
  5657. }
  5658. }
  5659. }
  5660. if (mHighlightedObjects->getNumNodes())
  5661. {
  5662. // Render silhouettes for highlighted objects
  5663. bool subtract_from_sel = gKeyboardp &&
  5664. gKeyboardp->currentMask(true) == MASK_CONTROL;
  5665. LLColor4 color = LLColor4::red; // Color for subtract_from_sel
  5666. for (LLObjectSelection::iterator iter = mHighlightedObjects->begin(),
  5667. end = mHighlightedObjects->end();
  5668. iter != end; ++iter)
  5669. {
  5670. LLSelectNode* nodep = *iter;
  5671. if (!nodep) continue; // Paranoia ?
  5672. LLViewerObject* objectp = nodep->getObject();
  5673. if (!objectp || objectp->isDead() ||
  5674. objectp->isHUDAttachment() != for_hud)
  5675. {
  5676. continue;
  5677. }
  5678. LLDrawable* drawablep = objectp->mDrawable;
  5679. if (!drawablep)
  5680. {
  5681. continue;
  5682. }
  5683. if (!subtract_from_sel)
  5684. {
  5685. if (objectp->isSelected())
  5686. {
  5687. continue;
  5688. }
  5689. if (objectp->isRoot())
  5690. {
  5691. color = sHighlightParentColor;
  5692. }
  5693. else
  5694. {
  5695. color = sHighlightChildColor;
  5696. }
  5697. }
  5698. LLVOVolume* volp = drawablep->getVOVolume();
  5699. if (gUsePBRShaders && volp && volp->isMesh())
  5700. {
  5701. renderMeshSelection(nodep, objectp, drawablep, volp, color);
  5702. }
  5703. else
  5704. {
  5705. nodep->renderOneSilhouette(color);
  5706. }
  5707. }
  5708. }
  5709. if (for_hud && isAgentAvatarValid())
  5710. {
  5711. gGL.matrixMode(LLRender::MM_PROJECTION);
  5712. gGL.popMatrix();
  5713. gGL.matrixMode(LLRender::MM_MODELVIEW);
  5714. gGL.popMatrix();
  5715. gGL.popUIMatrix();
  5716. }
  5717. unit0->unbind(LLTexUnit::TT_TEXTURE);
  5718. stop_glerror();
  5719. }
  5720. void LLSelectMgr::generateSilhouette(LLSelectNode* nodep,
  5721. const LLVector3& view_point)
  5722. {
  5723. LLViewerObject* objectp = nodep->getObject();
  5724. if (!objectp) return; // Paranoia
  5725. // Faster than a virtual generateSilhouette() method, beside view_point is
  5726. // not needed for trees and grass.
  5727. LLPCode pcode = objectp->getPCode();
  5728. if (pcode == LL_PCODE_VOLUME)
  5729. {
  5730. ((LLVOVolume*)objectp)->generateSilhouette(nodep, view_point);
  5731. }
  5732. else if (pcode == LL_PCODE_LEGACY_GRASS)
  5733. {
  5734. ((LLVOGrass*)objectp)->generateSilhouette(nodep);
  5735. }
  5736. else if (pcode == LL_PCODE_LEGACY_TREE)
  5737. {
  5738. ((LLVOTree*)objectp)->generateSilhouette(nodep);
  5739. }
  5740. }
  5741. //
  5742. // Utility classes
  5743. //
  5744. LLSelectNode::LLSelectNode(LLViewerObject* object, bool glow)
  5745. : mObject(object),
  5746. mIndividualSelection(false),
  5747. mTransient(false),
  5748. mValid(false),
  5749. mPermissions(new LLPermissions()),
  5750. mInventorySerial(0),
  5751. mSilhouetteGenerated(false),
  5752. mDuplicated(false),
  5753. mTESelectMask(0),
  5754. mLastTESelected(0),
  5755. mSelectedGLTFNode(-1),
  5756. mSelectedGLTFPrim(-1),
  5757. mName(LLStringUtil::null),
  5758. mDescription(LLStringUtil::null),
  5759. mTouchName(LLStringUtil::null),
  5760. mSitName(LLStringUtil::null),
  5761. mCreationDate(0)
  5762. {
  5763. selectAllTEs(false);
  5764. saveColors();
  5765. }
  5766. LLSelectNode::LLSelectNode(const LLSelectNode& nodep)
  5767. {
  5768. mTESelectMask = nodep.mTESelectMask;
  5769. mLastTESelected = nodep.mLastTESelected;
  5770. mIndividualSelection = nodep.mIndividualSelection;
  5771. mValid = nodep.mValid;
  5772. mTransient = nodep.mTransient;
  5773. mPermissions = new LLPermissions(*nodep.mPermissions);
  5774. mSaleInfo = nodep.mSaleInfo;;
  5775. mAggregatePerm = nodep.mAggregatePerm;
  5776. mAggregateTexturePerm = nodep.mAggregateTexturePerm;
  5777. mAggregateTexturePermOwner = nodep.mAggregateTexturePermOwner;
  5778. mName = nodep.mName;
  5779. mDescription = nodep.mDescription;
  5780. mCategory = nodep.mCategory;
  5781. mInventorySerial = 0;
  5782. mSavedPositionLocal = nodep.mSavedPositionLocal;
  5783. mSavedPositionGlobal = nodep.mSavedPositionGlobal;
  5784. mSavedScale = nodep.mSavedScale;
  5785. mSavedRotation = nodep.mSavedRotation;
  5786. mDuplicated = nodep.mDuplicated;
  5787. mDuplicatePos = nodep.mDuplicatePos;
  5788. mDuplicateRot = nodep.mDuplicateRot;
  5789. mItemID = nodep.mItemID;
  5790. mFolderID = nodep.mFolderID;
  5791. mFromTaskID = nodep.mFromTaskID;
  5792. mTouchName = nodep.mTouchName;
  5793. mSitName = nodep.mSitName;
  5794. mCreationDate = nodep.mCreationDate;
  5795. mSilhouetteVertices = nodep.mSilhouetteVertices;
  5796. mSilhouetteNormals = nodep.mSilhouetteNormals;
  5797. mSilhouetteGenerated = nodep.mSilhouetteGenerated;
  5798. mObject = nodep.mObject;
  5799. mSavedColors.clear();
  5800. S32 count = nodep.mSavedColors.size();
  5801. mSavedColors.reserve(count);
  5802. for (S32 i = 0; i < count; ++i)
  5803. {
  5804. mSavedColors.emplace_back(nodep.mSavedColors[i]);
  5805. }
  5806. saveTextures(nodep.mSavedTextures);
  5807. saveGLTFMaterials(nodep.mSavedGLTFMaterialIds,
  5808. nodep.mSavedGLTFOverrideMaterials);
  5809. }
  5810. LLSelectNode::~LLSelectNode()
  5811. {
  5812. delete mPermissions;
  5813. mPermissions = NULL;
  5814. }
  5815. void LLSelectNode::selectAllTEs(bool b)
  5816. {
  5817. mTESelectMask = b ? TE_SELECT_MASK_ALL : 0x0;
  5818. mLastTESelected = 0;
  5819. }
  5820. void LLSelectNode::selectTE(S32 te_index, bool selected)
  5821. {
  5822. if (te_index < 0 || te_index >= SELECT_MAX_TES)
  5823. {
  5824. return;
  5825. }
  5826. S32 mask = 0x1 << te_index;
  5827. if (selected)
  5828. {
  5829. mTESelectMask |= mask;
  5830. }
  5831. else
  5832. {
  5833. mTESelectMask &= ~mask;
  5834. }
  5835. mLastTESelected = te_index;
  5836. }
  5837. bool LLSelectNode::isTESelected(S32 te_index)
  5838. {
  5839. if (te_index < 0 || te_index >= mObject->getNumTEs())
  5840. {
  5841. return false;
  5842. }
  5843. return (mTESelectMask & (0x1 << te_index)) != 0;
  5844. }
  5845. S32 LLSelectNode::getLastSelectedTE()
  5846. {
  5847. if (!isTESelected(mLastTESelected))
  5848. {
  5849. return -1;
  5850. }
  5851. return mLastTESelected;
  5852. }
  5853. LLViewerObject* LLSelectNode::getObject()
  5854. {
  5855. if (!mObject)
  5856. {
  5857. return NULL;
  5858. }
  5859. else if (mObject->isDead())
  5860. {
  5861. mObject = NULL;
  5862. }
  5863. return mObject;
  5864. }
  5865. void LLSelectNode::saveColors()
  5866. {
  5867. if (mObject.notNull())
  5868. {
  5869. mSavedColors.clear();
  5870. for (S32 i = 0, count = mObject->getNumTEs(); i < count; ++i)
  5871. {
  5872. const LLTextureEntry* tep = mObject->getTE(i);
  5873. if (tep)
  5874. {
  5875. mSavedColors.emplace_back(tep->getColor());
  5876. }
  5877. }
  5878. }
  5879. }
  5880. void LLSelectNode::saveTextures(const uuid_vec_t& tex_ids)
  5881. {
  5882. if (mObject.notNull())
  5883. {
  5884. mSavedTextures.clear();
  5885. for (U32 i = 0, count = tex_ids.size(); i < count; ++i)
  5886. {
  5887. mSavedTextures.emplace_back(tex_ids[i]);
  5888. }
  5889. }
  5890. }
  5891. void LLSelectNode::saveGLTFMaterials(const uuid_vec_t& mat_ids,
  5892. const gltf_mat_vec_t& override_mats)
  5893. {
  5894. if (mObject.isNull())
  5895. {
  5896. return;
  5897. }
  5898. mSavedGLTFMaterialIds.clear();
  5899. mSavedGLTFOverrideMaterials.clear();
  5900. for (U32 i = 0, count = mat_ids.size(); i < count; ++i)
  5901. {
  5902. mSavedGLTFMaterialIds.emplace_back(mat_ids[i]);
  5903. }
  5904. for (U32 i = 0, count = override_mats.size(); i < count; ++i)
  5905. {
  5906. mSavedGLTFOverrideMaterials.emplace_back(override_mats[i]);
  5907. }
  5908. }
  5909. void LLSelectNode::saveTextureScaleRatios()
  5910. {
  5911. mTextureScaleRatios.clear();
  5912. mGLTFScaleRatios.clear();
  5913. if (mObject.isNull())
  5914. {
  5915. return;
  5916. }
  5917. LLVector3 scale = mObject->getScale();
  5918. std::vector<LLVector3> mat_scales_vec;
  5919. F32 scale_s, scale_t;
  5920. for (U8 i = 0, count = mObject->getNumTEs(); i < count; ++i)
  5921. {
  5922. const LLTextureEntry* tep = mObject->getTE(i);
  5923. if (!tep) continue;
  5924. // Figure out how S,T changed with scale operation
  5925. U32 s_axis = VX;
  5926. U32 t_axis = VY;
  5927. LLPrimitive::getTESTAxes(i, &s_axis, &t_axis);
  5928. F32 obj_scal_s = scale.mV[s_axis];
  5929. F32 obj_scal_t = scale.mV[t_axis];
  5930. scale_s = scale_t = 1.f;
  5931. tep->getScale(&scale_s, &scale_t);
  5932. bool planar = tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR;
  5933. if (planar)
  5934. {
  5935. scale_s *= obj_scal_s;
  5936. scale_t *= obj_scal_t;
  5937. }
  5938. else
  5939. {
  5940. scale_s /= obj_scal_s;
  5941. scale_t /= obj_scal_t;
  5942. }
  5943. mTextureScaleRatios.emplace_back(scale_s, scale_t, 0.f);
  5944. // PBR materials
  5945. LLGLTFMaterial* matp = tep->getGLTFMaterialOverride();
  5946. for (U32 i = 0; i < LLGLTFMaterial::GLTF_TEXTURE_INFO_COUNT; ++i)
  5947. {
  5948. if (matp)
  5949. {
  5950. const auto& transform = matp->mTextureTransform[i];
  5951. scale_s = transform.mScale[VX];
  5952. scale_t = transform.mScale[VY];
  5953. }
  5954. else
  5955. {
  5956. // Not having an override does not mean that there is no
  5957. // material.
  5958. scale_s = scale_t = 1.f;
  5959. }
  5960. if (planar)
  5961. {
  5962. scale_s *= obj_scal_s;
  5963. scale_t *= obj_scal_t;
  5964. }
  5965. else
  5966. {
  5967. scale_s /= obj_scal_s;
  5968. scale_t /= obj_scal_t;
  5969. }
  5970. mat_scales_vec.emplace_back(scale_s, scale_t, 0.f);
  5971. }
  5972. mGLTFScaleRatios.emplace_back(mat_scales_vec);
  5973. mat_scales_vec.clear();
  5974. }
  5975. }
  5976. // This implementation should be similar to LLTask::allowOperationOnTask
  5977. bool LLSelectNode::allowOperationOnNode(PermissionBit op,
  5978. U64 group_proxy_power) const
  5979. {
  5980. // Extract ownership.
  5981. bool object_is_group_owned = false;
  5982. LLUUID object_owner_id;
  5983. mPermissions->getOwnership(object_owner_id, object_is_group_owned);
  5984. // Operations on invalid or public objects is not allowed.
  5985. if (!mObject || mObject->isDead() || !mPermissions->isOwned())
  5986. {
  5987. return false;
  5988. }
  5989. // The transfer permissions can never be given through proxy.
  5990. if (PERM_TRANSFER == op)
  5991. {
  5992. // The owner of an agent-owned object can transfer to themselves.
  5993. if (!object_is_group_owned && gAgentID == object_owner_id)
  5994. {
  5995. return true;
  5996. }
  5997. else
  5998. {
  5999. // Otherwise check aggregate permissions.
  6000. return mObject->permTransfer();
  6001. }
  6002. }
  6003. if (PERM_MOVE == op || PERM_MODIFY == op)
  6004. {
  6005. // only owners can move or modify their attachments
  6006. // no proxy allowed.
  6007. if (mObject->isAttachment() && object_owner_id != gAgentID)
  6008. {
  6009. return false;
  6010. }
  6011. }
  6012. // Calculate proxy_agent_id and group_id to use for permissions checks.
  6013. // proxy_agent_id may be set to the object owner through group powers.
  6014. // group_id can only be set to the object's group, if the agent is in that
  6015. // group.
  6016. LLUUID group_id;
  6017. LLUUID proxy_agent_id = gAgentID;
  6018. // Gods can always operate.
  6019. if (gAgent.isGodlike())
  6020. {
  6021. return true;
  6022. }
  6023. // Check if the agent is in the same group as the object.
  6024. LLUUID object_group_id = mPermissions->getGroup();
  6025. if (object_group_id.notNull() &&
  6026. gAgent.isInGroup(object_group_id))
  6027. {
  6028. // Assume the object's group during this operation.
  6029. group_id = object_group_id;
  6030. }
  6031. // Only allow proxy powers for PERM_COPY if the actual agent can receive
  6032. // the item (ie has PERM_TRANSFER permissions).
  6033. // NOTE: op == PERM_TRANSFER has already been handled, but if that ever
  6034. // changes we need to BLOCK proxy powers for PERM_TRANSFER. DK 03/28/06
  6035. if (PERM_COPY != op || mPermissions->allowTransferTo(gAgentID))
  6036. {
  6037. // Check if the agent can assume ownership through group proxy or
  6038. // agent-granted proxy.
  6039. if ((object_is_group_owned &&
  6040. gAgent.hasPowerInGroup(object_owner_id, group_proxy_power)) ||
  6041. // Only allow proxy for move, modify, and copy.
  6042. ((PERM_MOVE == op || PERM_MODIFY == op || PERM_COPY == op) &&
  6043. (!object_is_group_owned && gAgent.isGrantedProxy(*mPermissions))))
  6044. {
  6045. // This agent is able to assume the ownership role for this
  6046. // operation.
  6047. proxy_agent_id = object_owner_id;
  6048. }
  6049. }
  6050. // We now have max ownership information.
  6051. if (PERM_OWNER == op)
  6052. {
  6053. // This this was just a check for ownership, we can now return the
  6054. // answer.
  6055. return proxy_agent_id == object_owner_id;
  6056. }
  6057. // Check permissions to see if the agent can operate
  6058. return mPermissions->allowOperationBy(op, proxy_agent_id, group_id);
  6059. }
  6060. // Helper function for pushing relevant vertices from drawable to GL
  6061. void push_wireframe(LLDrawable* drawablep)
  6062. {
  6063. LLVOVolume* vobj = drawablep->getVOVolume();
  6064. if (vobj)
  6065. {
  6066. LLVertexBuffer::unbind();
  6067. gGL.pushMatrix();
  6068. gGL.multMatrix(vobj->getRelativeXform().getF32ptr());
  6069. LLVolume* volume = NULL;
  6070. if (drawablep->isState(LLDrawable::RIGGED))
  6071. {
  6072. vobj->updateRiggedVolume(true);
  6073. volume = vobj->getRiggedVolume();
  6074. }
  6075. else
  6076. {
  6077. volume = vobj->getVolume();
  6078. }
  6079. if (volume)
  6080. {
  6081. for (S32 i = 0, count = volume->getNumVolumeFaces(); i < count;
  6082. ++i)
  6083. {
  6084. const LLVolumeFace& face = volume->getVolumeFace(i);
  6085. LLVertexBuffer::drawElements(face.mNumVertices,
  6086. face.mPositions, NULL,
  6087. face.mNumIndices,
  6088. face.mIndices);
  6089. }
  6090. }
  6091. gGL.popMatrix();
  6092. }
  6093. }
  6094. void LLSelectNode::renderOneWireframe(const LLColor4& color)
  6095. {
  6096. // MAINT-5018: needed because of crash on ATI 3800 (and similar cards)
  6097. LLGLDisable multisample(!gUsePBRShaders && gGLManager.mIsAMD &&
  6098. LLPipeline::RenderFSAASamples > 0 ? GL_MULTISAMPLE
  6099. : 0);
  6100. LLViewerObject* objectp = getObject();
  6101. if (!objectp)
  6102. {
  6103. return;
  6104. }
  6105. LLDrawable* drawablep = objectp->mDrawable;
  6106. if (!drawablep)
  6107. {
  6108. return;
  6109. }
  6110. LLGLSLShader* shaderp = LLGLSLShader::sCurBoundShaderPtr;
  6111. gDebugProgram.bind();
  6112. gGL.matrixMode(LLRender::MM_MODELVIEW);
  6113. gGL.pushMatrix();
  6114. bool is_hud_object = objectp->isHUDAttachment();
  6115. if (drawablep->isActive())
  6116. {
  6117. gGL.loadMatrix(gGLModelView);
  6118. gGL.multMatrix(objectp->getRenderMatrix().getF32ptr());
  6119. }
  6120. else if (!is_hud_object)
  6121. {
  6122. gGL.loadIdentity();
  6123. gGL.multMatrix(gGLModelView);
  6124. LLVector3 trans = objectp->getRegion()->getOriginAgent();
  6125. gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
  6126. }
  6127. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  6128. if (LLSelectMgr::renderHiddenSelection())
  6129. {
  6130. gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
  6131. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL);
  6132. gGL.diffuseColor4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE],
  6133. 0.4f);
  6134. push_wireframe(drawablep);
  6135. }
  6136. gGL.flush();
  6137. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  6138. gGL.diffuseColor4f(color.mV[VRED] * 2, color.mV[VGREEN] * 2,
  6139. color.mV[VBLUE] * 2, LLSelectMgr::sHighlightAlpha * 2);
  6140. LLGLEnable offset(GL_POLYGON_OFFSET_LINE);
  6141. glPolygonOffset(3.f, 3.f);
  6142. gGL.lineWidth(3.f);
  6143. push_wireframe(drawablep);
  6144. gGL.lineWidth(1.f);
  6145. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  6146. gGL.popMatrix();
  6147. if (shaderp)
  6148. {
  6149. shaderp->bind();
  6150. }
  6151. }
  6152. void LLSelectNode::renderOneSilhouette(const LLColor4& color, bool no_hidden)
  6153. {
  6154. LLViewerObject* objectp = getObject();
  6155. if (!objectp)
  6156. {
  6157. return;
  6158. }
  6159. LLDrawable* drawablep = objectp->mDrawable;
  6160. if (!drawablep)
  6161. {
  6162. return;
  6163. }
  6164. LLVOVolume* vobj = drawablep->getVOVolume();
  6165. if (vobj && vobj->isMesh())
  6166. {
  6167. renderOneWireframe(color);
  6168. return;
  6169. }
  6170. if (!mSilhouetteGenerated)
  6171. {
  6172. return;
  6173. }
  6174. bool is_hud_object = objectp->isHUDAttachment();
  6175. if (mSilhouetteVertices.size() == 0 ||
  6176. mSilhouetteNormals.size() != mSilhouetteVertices.size())
  6177. {
  6178. return;
  6179. }
  6180. LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
  6181. if (shader)
  6182. {
  6183. // Use UI program for selection highlights (texture color modulated by
  6184. // vertex color).
  6185. gUIProgram.bind();
  6186. }
  6187. gGL.matrixMode(LLRender::MM_MODELVIEW);
  6188. gGL.pushMatrix();
  6189. gGL.pushUIMatrix();
  6190. gGL.loadUIIdentity();
  6191. if (!is_hud_object)
  6192. {
  6193. gGL.loadIdentity();
  6194. gGL.multMatrix(gGLModelView);
  6195. }
  6196. if (drawablep->isActive())
  6197. {
  6198. gGL.multMatrix(objectp->getRenderMatrix().getF32ptr());
  6199. }
  6200. #if 0 // We used to only call this for volumes, but let's render silhouettes
  6201. // for any node that has them.
  6202. LLVolume* volume = objectp->getVolume();
  6203. if (volume)
  6204. #endif
  6205. {
  6206. F32 silhouette_thickness;
  6207. if (is_hud_object && isAgentAvatarValid())
  6208. {
  6209. silhouette_thickness = LLSelectMgr::sHighlightThickness /
  6210. gAgent.mHUDCurZoom;
  6211. }
  6212. else
  6213. {
  6214. LLVector3 view_vector = gViewerCamera.getOrigin() -
  6215. objectp->getRenderPosition();
  6216. silhouette_thickness = view_vector.length() *
  6217. LLSelectMgr::sHighlightThickness *
  6218. (gViewerCamera.getView() /
  6219. gViewerCamera.getDefaultFOV());
  6220. }
  6221. F32 animationTime = (F32)LLFrameTimer::getElapsedSeconds();
  6222. F32 u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
  6223. F32 v_coord = 1.f - fmod(animationTime * LLSelectMgr::sHighlightVAnim, 1.f);
  6224. F32 u_divisor = 1.f / ((F32)(mSilhouetteVertices.size() - 1));
  6225. if (!no_hidden && LLSelectMgr::renderHiddenSelection())
  6226. {
  6227. gGL.flush();
  6228. gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
  6229. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL);
  6230. gGL.begin(LLRender::LINES);
  6231. gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE],
  6232. 0.4f);
  6233. for (S32 i = 0, count = mSilhouetteVertices.size();
  6234. i < count; i += 2)
  6235. {
  6236. u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
  6237. gGL.texCoord2f(u_coord, v_coord);
  6238. gGL.vertex3fv(mSilhouetteVertices[i].mV);
  6239. u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
  6240. gGL.texCoord2f(u_coord, v_coord);
  6241. gGL.vertex3fv(mSilhouetteVertices[i + 1].mV);
  6242. }
  6243. gGL.end();
  6244. u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
  6245. }
  6246. gGL.flush();
  6247. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  6248. gGL.begin(LLRender::TRIANGLES);
  6249. LLVector3 v[4];
  6250. LLVector2 tc[4];
  6251. for (S32 i = 0, count = mSilhouetteVertices.size(); i < count; i += 2)
  6252. {
  6253. if (!mSilhouetteNormals[i].isFinite() ||
  6254. !mSilhouetteNormals[i+1].isFinite())
  6255. {
  6256. // Skip skewed segments
  6257. continue;
  6258. }
  6259. v[0] = mSilhouetteVertices[i] +
  6260. mSilhouetteNormals[i] * silhouette_thickness;
  6261. tc[0].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
  6262. v[1] = mSilhouetteVertices[i];
  6263. tc[1].set(u_coord, v_coord);
  6264. u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
  6265. v[2] = mSilhouetteVertices[i + 1] +
  6266. mSilhouetteNormals[i + 1] * silhouette_thickness;
  6267. tc[2].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
  6268. v[3] = mSilhouetteVertices[i + 1];
  6269. tc[3].set(u_coord,v_coord);
  6270. gGL.color4f(color.mV[VRED], color.mV[VGREEN],
  6271. color.mV[VBLUE], 0.f); //LLSelectMgr::sHighlightAlpha);
  6272. gGL.texCoord2fv(tc[0].mV);
  6273. gGL.vertex3fv(v[0].mV);
  6274. gGL.color4f(color.mV[VRED] * 2, color.mV[VGREEN] * 2,
  6275. color.mV[VBLUE] * 2, LLSelectMgr::sHighlightAlpha * 2);
  6276. gGL.texCoord2fv(tc[1].mV);
  6277. gGL.vertex3fv(v[1].mV);
  6278. gGL.color4f(color.mV[VRED], color.mV[VGREEN],
  6279. color.mV[VBLUE], 0.f); //LLSelectMgr::sHighlightAlpha);
  6280. gGL.texCoord2fv(tc[2].mV);
  6281. gGL.vertex3fv(v[2].mV);
  6282. gGL.vertex3fv(v[2].mV);
  6283. gGL.color4f(color.mV[VRED] * 2, color.mV[VGREEN] * 2,
  6284. color.mV[VBLUE] * 2, LLSelectMgr::sHighlightAlpha * 2);
  6285. gGL.texCoord2fv(tc[1].mV);
  6286. gGL.vertex3fv(v[1].mV);
  6287. gGL.texCoord2fv(tc[3].mV);
  6288. gGL.vertex3fv(v[3].mV);
  6289. }
  6290. gGL.end(true);
  6291. }
  6292. gGL.popMatrix();
  6293. gGL.popUIMatrix();
  6294. if (shader)
  6295. {
  6296. shader->bind();
  6297. }
  6298. }
  6299. //
  6300. // Utility Functions
  6301. //
  6302. // Update everyone who cares about the selection list
  6303. void dialog_refresh_all()
  6304. {
  6305. // This is the easiest place to fire the update signal, as it will make
  6306. // cleaning up the functions below easier. Also, sometimes entities outside
  6307. // the selection manager change properties of selected objects and call
  6308. // into this function. Yuck.
  6309. gSelectMgr.mUpdateSignal();
  6310. if (gFloaterToolsp)
  6311. {
  6312. gFloaterToolsp->dirty();
  6313. }
  6314. if (gPieObjectp && gPieObjectp->getVisible())
  6315. {
  6316. gPieObjectp->arrange();
  6317. }
  6318. if (gPieAttachmentp && gPieAttachmentp->getVisible())
  6319. {
  6320. gPieAttachmentp->arrange();
  6321. }
  6322. LLFloaterProperties::dirtyAll();
  6323. LLFloaterInspect::dirty();
  6324. }
  6325. void LLSelectMgr::updateSelectionCenter()
  6326. {
  6327. // Movement threshold in meters for updating selection center (tractor
  6328. // beam)
  6329. constexpr F32 MOVE_SELECTION_THRESHOLD = 1.f;
  6330. // Override any object updates received for selected objects
  6331. overrideObjectUpdates();
  6332. LLViewerObject* objp = mSelectedObjects->getFirstObject();
  6333. if (!objp)
  6334. {
  6335. // Nothing selected, probably grabbing. Ignore by setting to avatar
  6336. // origin.
  6337. mSelectionCenterGlobal.clear();
  6338. mShowSelection = false;
  6339. mSelectionBBox = LLBBox();
  6340. gAgent.resetHUDZoom();
  6341. }
  6342. else
  6343. {
  6344. mSelectedObjects->mSelectType = getSelectTypeForObject(objp);
  6345. if (mSelectedObjects->mSelectType != SELECT_TYPE_HUD &&
  6346. isAgentAvatarValid())
  6347. {
  6348. gAgent.resetHUDZoom();
  6349. }
  6350. mShowSelection = false;
  6351. LLBBox bbox;
  6352. // Have stuff selected
  6353. LLVector3d select_center;
  6354. // Keep a list of jointed objects for showing the joint HUDEffects
  6355. // Initialize the bounding box to the root prim, so the BBox orientation
  6356. // matches the root prim's (affecting the orientation of the
  6357. // manipulators).
  6358. bbox.addBBoxAgent((mSelectedObjects->getFirstRootObject(true))->getBoundingBoxAgent());
  6359. for (LLObjectSelection::iterator iter = mSelectedObjects->begin(),
  6360. end = mSelectedObjects->end();
  6361. iter != end; ++iter)
  6362. {
  6363. LLSelectNode* nodep = *iter;
  6364. objp = nodep->getObject();
  6365. if (!objp) continue;
  6366. LLViewerObject* rootp = objp->getRootEdit();
  6367. // Not an attachment
  6368. if (mSelectedObjects->mSelectType == SELECT_TYPE_WORLD &&
  6369. // Not the object you are sitting on
  6370. !rootp->isChild(gAgentAvatarp) &&
  6371. // Not another avatar
  6372. !objp->isAvatar())
  6373. {
  6374. mShowSelection = true;
  6375. }
  6376. bbox.addBBoxAgent(objp->getBoundingBoxAgent());
  6377. }
  6378. LLVector3 bbox_center_agent = bbox.getCenterAgent();
  6379. mSelectionCenterGlobal =
  6380. gAgent.getPosGlobalFromAgent(bbox_center_agent);
  6381. mSelectionBBox = bbox;
  6382. }
  6383. LLTool* toolp = gToolMgr.getCurrentTool();
  6384. if (toolp && mShowSelection)
  6385. {
  6386. LLVector3d sel_center_global;
  6387. if (toolp->isEditing())
  6388. {
  6389. sel_center_global = toolp->getEditingPointGlobal();
  6390. }
  6391. else
  6392. {
  6393. sel_center_global = mSelectionCenterGlobal;
  6394. }
  6395. // Send selection center if moved beyond threshold (used to animate
  6396. // tractor beam)
  6397. LLVector3d diff = sel_center_global - mLastSentSelectionCenterGlobal;
  6398. if (diff.lengthSquared() >
  6399. MOVE_SELECTION_THRESHOLD * MOVE_SELECTION_THRESHOLD)
  6400. {
  6401. // Transmit updated selection center
  6402. mLastSentSelectionCenterGlobal = sel_center_global;
  6403. }
  6404. }
  6405. // Give up edit menu if no objects selected
  6406. if (!mSelectedObjects->getObjectCount())
  6407. {
  6408. releaseMenuHandler();
  6409. }
  6410. pauseAssociatedAvatars();
  6411. }
  6412. // If the selection includes an attachment or an animated object, the parent
  6413. // avatars should pause their animations until they are no longer selected.
  6414. void LLSelectMgr::pauseAssociatedAvatars()
  6415. {
  6416. mPauseRequests.clear();
  6417. bool agent_valid = isAgentAvatarValid();
  6418. for (LLObjectSelection::iterator iter = mSelectedObjects->begin(),
  6419. end = mSelectedObjects->end();
  6420. iter != end; ++iter)
  6421. {
  6422. LLSelectNode* node = *iter;
  6423. if (!node) continue; // Pananoia
  6424. LLViewerObject* object = node->getObject();
  6425. if (!object) continue;
  6426. mSelectedObjects->mSelectType = getSelectTypeForObject(object);
  6427. bool animated_object = object->isAnimatedObject();
  6428. if (mSelectedObjects->mSelectType == SELECT_TYPE_ATTACHMENT &&
  6429. agent_valid && object->getAvatarAncestor())
  6430. {
  6431. if (animated_object)
  6432. {
  6433. // This is an animated object attachment, so pause the
  6434. // puppet avatar as well.
  6435. LLVOAvatarPuppet* puppet = object->getPuppetAvatar();
  6436. if (puppet)
  6437. {
  6438. mPauseRequests.emplace_back(puppet->requestPause());
  6439. }
  6440. }
  6441. mPauseRequests.emplace_back(gAgentAvatarp->requestPause());
  6442. }
  6443. else if (object && animated_object)
  6444. {
  6445. LLVOAvatarPuppet* puppet = object->getPuppetAvatar();
  6446. if (puppet)
  6447. {
  6448. // This is a non-attached animated object, so pause the
  6449. // puppet avatar only.
  6450. mPauseRequests.emplace_back(puppet->requestPause());
  6451. }
  6452. }
  6453. }
  6454. }
  6455. void LLSelectMgr::updatePointAt()
  6456. {
  6457. if (mShowSelection)
  6458. {
  6459. if (mSelectedObjects->getObjectCount())
  6460. {
  6461. const LLPickInfo& pick = gViewerWindowp->getLastPick();
  6462. LLViewerObject* click_object = pick.getObject();
  6463. if (click_object && click_object->isSelected())
  6464. {
  6465. // Clicked on another object in our selection group, use that
  6466. // as target
  6467. LLVector3 select_offset(pick.mObjectOffset);
  6468. select_offset.rotVec(~click_object->getRenderRotation());
  6469. gAgent.setPointAt(POINTAT_TARGET_SELECT, click_object,
  6470. select_offset);
  6471. gAgent.setLookAt(LOOKAT_TARGET_SELECT, click_object,
  6472. select_offset);
  6473. }
  6474. else
  6475. {
  6476. // Did not click on an object this time, revert to pointing at
  6477. // center of first object
  6478. gAgent.setPointAt(POINTAT_TARGET_SELECT,
  6479. mSelectedObjects->getFirstObject());
  6480. gAgent.setLookAt(LOOKAT_TARGET_SELECT,
  6481. mSelectedObjects->getFirstObject());
  6482. }
  6483. }
  6484. else
  6485. {
  6486. gAgent.setPointAt(POINTAT_TARGET_CLEAR);
  6487. gAgent.setLookAt(LOOKAT_TARGET_CLEAR);
  6488. }
  6489. }
  6490. else
  6491. {
  6492. gAgent.setPointAt(POINTAT_TARGET_CLEAR);
  6493. gAgent.setLookAt(LOOKAT_TARGET_CLEAR);
  6494. }
  6495. }
  6496. LLBBox LLSelectMgr::getBBoxOfSelection() const
  6497. {
  6498. return mSelectionBBox;
  6499. }
  6500. bool LLSelectMgr::canUndo() const
  6501. {
  6502. // *HACK: casting away constness - MG
  6503. LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
  6504. // Can edit or move
  6505. return self->mSelectedObjects->getFirstUndoEnabledObject() != NULL;
  6506. }
  6507. void LLSelectMgr::undo()
  6508. {
  6509. bool select_linked_set = !mEditLinkedParts;
  6510. LLUUID group_id(gAgent.getGroupID());
  6511. sendListToRegions("Undo", packAgentAndSessionAndGroupID, packObjectID,
  6512. &group_id, select_linked_set ? SEND_ONLY_ROOTS
  6513. : SEND_CHILDREN_FIRST);
  6514. }
  6515. bool LLSelectMgr::canRedo() const
  6516. {
  6517. // *HACK: casting away constness - MG
  6518. LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
  6519. return self->mSelectedObjects->getFirstEditableObject() != NULL;
  6520. }
  6521. void LLSelectMgr::redo()
  6522. {
  6523. bool select_linked_set = !mEditLinkedParts;
  6524. LLUUID group_id(gAgent.getGroupID());
  6525. sendListToRegions("Redo",
  6526. packAgentAndSessionAndGroupID,
  6527. packObjectID,
  6528. &group_id,
  6529. select_linked_set ? SEND_ONLY_ROOTS
  6530. : SEND_CHILDREN_FIRST);
  6531. }
  6532. bool LLSelectMgr::canDoDelete() const
  6533. {
  6534. // *HACK: casting away constness - MG
  6535. LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
  6536. // Note: Can only delete root objects (see getFirstDeleteableObject() for
  6537. // more info).
  6538. return self->mSelectedObjects->getFirstDeleteableObject() != NULL;
  6539. }
  6540. void LLSelectMgr::doDelete()
  6541. {
  6542. selectDelete();
  6543. }
  6544. bool LLSelectMgr::canDeselect() const
  6545. {
  6546. return !mSelectedObjects->isEmpty();
  6547. }
  6548. void LLSelectMgr::deselect()
  6549. {
  6550. deselectAll();
  6551. }
  6552. bool LLSelectMgr::canDuplicate() const
  6553. {
  6554. // *HACK: casting away constness - MG
  6555. LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
  6556. return self->mSelectedObjects->getFirstCopyableObject() != NULL;
  6557. }
  6558. void LLSelectMgr::duplicate()
  6559. {
  6560. LLVector3 offset(0.5f, 0.5f, 0.f);
  6561. selectDuplicate(offset, true);
  6562. }
  6563. ESelectType LLSelectMgr::getSelectTypeForObject(LLViewerObject* object)
  6564. {
  6565. if (!object)
  6566. {
  6567. return SELECT_TYPE_WORLD;
  6568. }
  6569. if (object->isHUDAttachment())
  6570. {
  6571. return SELECT_TYPE_HUD;
  6572. }
  6573. else if (object->isAttachment())
  6574. {
  6575. return SELECT_TYPE_ATTACHMENT;
  6576. }
  6577. else
  6578. {
  6579. return SELECT_TYPE_WORLD;
  6580. }
  6581. }
  6582. void LLSelectMgr::validateSelection()
  6583. {
  6584. struct f final : public LLSelectedObjectFunctor
  6585. {
  6586. bool apply(LLViewerObject* object) override
  6587. {
  6588. if (!gSelectMgr.canSelectObject(object))
  6589. {
  6590. gSelectMgr.deselectObjectOnly(object);
  6591. }
  6592. return true;
  6593. }
  6594. } func;
  6595. getSelection()->applyToObjects(&func);
  6596. }
  6597. bool LLSelectMgr::canSelectObject(LLViewerObject* object)
  6598. {
  6599. // Never select dead objects
  6600. if (!object || object->isDead())
  6601. {
  6602. return false;
  6603. }
  6604. if (mForceSelection)
  6605. {
  6606. return true;
  6607. }
  6608. // Cannot select orphans, avatars or land
  6609. if (object->isOrphaned() || object->isAvatar() ||
  6610. object->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
  6611. {
  6612. return false;
  6613. }
  6614. if ((mSelectOwnedOnly && !object->permYouOwner()) ||
  6615. (mSelectMovableOnly &&
  6616. (!object->permMove() || object->isPermanentEnforced())))
  6617. {
  6618. // Only select my own objects
  6619. return false;
  6620. }
  6621. ESelectType selection_type = getSelectTypeForObject(object);
  6622. if (mSelectedObjects->getObjectCount() > 0 &&
  6623. mSelectedObjects->mSelectType != selection_type)
  6624. {
  6625. return false;
  6626. }
  6627. return true;
  6628. }
  6629. bool LLSelectMgr::setForceSelection(bool force)
  6630. {
  6631. std::swap(mForceSelection, force);
  6632. return force;
  6633. }
  6634. bool LLSelectMgr::selectionMove(const LLVector3& displ, F32 roll, F32 pitch,
  6635. F32 yaw, U32 update_type)
  6636. {
  6637. if (update_type == UPD_NONE)
  6638. {
  6639. return false;
  6640. }
  6641. LLVector3 displ_global;
  6642. bool update_success = true;
  6643. bool update_position = update_type & UPD_POSITION;
  6644. bool update_rotation = update_type & UPD_ROTATION;
  6645. const bool noedit_linked_parts = !mEditLinkedParts;
  6646. if (update_position)
  6647. {
  6648. // Calculate the distance of the object closest to the camera origin
  6649. F32 min_dist_squared = F32_MAX; // Value will be overridden in the loop
  6650. LLVector3 obj_pos;
  6651. for (LLObjectSelection::root_iterator
  6652. it = getSelection()->root_begin(),
  6653. end = getSelection()->root_end();
  6654. it != end; ++it)
  6655. {
  6656. obj_pos = (*it)->getObject()->getPositionEdit();
  6657. F32 obj_dist_squared = dist_vec_squared(obj_pos,
  6658. gViewerCamera.getOrigin());
  6659. if (obj_dist_squared < min_dist_squared)
  6660. {
  6661. min_dist_squared = obj_dist_squared;
  6662. }
  6663. }
  6664. // Factor the distance inside the displacement vector. This will get us
  6665. // equally visible movements for both close and far away selections.
  6666. F32 min_dist = sqrtf(sqrtf(min_dist_squared)) * 0.5f;
  6667. displ_global.set(displ.mV[0] * min_dist, displ.mV[1] * min_dist,
  6668. displ.mV[2] * min_dist);
  6669. // Equates to: Displ_global = Displ * M_cam_axes_in_global_frame
  6670. displ_global = gViewerCamera.rotateToAbsolute(displ_global);
  6671. }
  6672. LLQuaternion new_rot;
  6673. if (update_rotation)
  6674. {
  6675. // Let's calculate the rotation around each camera axes
  6676. LLQuaternion qx(roll, gViewerCamera.getAtAxis());
  6677. LLQuaternion qy(pitch, gViewerCamera.getLeftAxis());
  6678. LLQuaternion qz(yaw, gViewerCamera.getUpAxis());
  6679. new_rot.set(qx * qy * qz);
  6680. }
  6681. S32 obj_count = getSelection()->getObjectCount();
  6682. for (LLObjectSelection::root_iterator it = getSelection()->root_begin(),
  6683. end = getSelection()->root_end();
  6684. it != end; ++it)
  6685. {
  6686. LLViewerObject* obj = (*it)->getObject();
  6687. if (!obj) continue; // Paranoia
  6688. bool enable_pos = false;
  6689. bool enable_rot = false;
  6690. bool perm_move = obj->permMove() && !obj->isPermanentEnforced();
  6691. bool perm_mod = obj->permModify();
  6692. LLVector3d sel_center(getSelectionCenterGlobal());
  6693. if (update_rotation)
  6694. {
  6695. enable_rot = perm_move &&
  6696. ((perm_mod && !obj->isAttachment()) ||
  6697. noedit_linked_parts);
  6698. if (enable_rot)
  6699. {
  6700. S32 children_count = obj->getChildren().size();
  6701. if (obj_count > 1 && children_count > 0)
  6702. {
  6703. // For linked sets, rotate around the group center
  6704. const LLVector3 t(obj->getPositionGlobal() - sel_center);
  6705. // Ra = T x R x T^-1
  6706. LLMatrix4 mt;
  6707. mt.setTranslation(t);
  6708. const LLMatrix4 mnew_rot(new_rot);
  6709. LLMatrix4 mt_1; mt_1.setTranslation(-t);
  6710. mt *= mnew_rot;
  6711. mt *= mt_1;
  6712. // Rfin = Rcur * Ra
  6713. obj->setRotation(obj->getRotationEdit() * mt.quaternion());
  6714. displ_global += mt.getTranslation();
  6715. }
  6716. else
  6717. {
  6718. obj->setRotation(obj->getRotationEdit() * new_rot);
  6719. }
  6720. }
  6721. else
  6722. {
  6723. update_success = false;
  6724. }
  6725. }
  6726. if (update_position)
  6727. {
  6728. // Establish if object can be moved or not
  6729. enable_pos = perm_move && !obj->isAttachment() &&
  6730. (perm_mod || noedit_linked_parts);
  6731. if (enable_pos)
  6732. {
  6733. obj->setPositionLocal(obj->getPositionEdit() + displ_global);
  6734. }
  6735. else
  6736. {
  6737. update_success = false;
  6738. }
  6739. }
  6740. if (enable_pos && enable_rot && obj->mDrawable.notNull())
  6741. {
  6742. gPipeline.markMoved(obj->mDrawable, true);
  6743. }
  6744. }
  6745. if (update_position && update_success && obj_count > 1)
  6746. {
  6747. updateSelectionCenter();
  6748. }
  6749. return update_success;
  6750. }
  6751. void LLSelectMgr::sendSelectionMove()
  6752. {
  6753. LLSelectNode* node = mSelectedObjects->getFirstRootNode();
  6754. if (!node)
  6755. {
  6756. return;
  6757. }
  6758. #if 0
  6759. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  6760. #endif
  6761. U32 update_type = UPD_POSITION | UPD_ROTATION;
  6762. // Apply to linked objects if unable to select their individual parts
  6763. if (!mEditLinkedParts && !getTEMode())
  6764. {
  6765. // Tell simulator to apply to whole linked sets
  6766. update_type |= UPD_LINKED_SETS;
  6767. }
  6768. LLViewerRegion* curr_region = node->getObject()->getRegion();
  6769. S32 objects_in_this_packet = 0;
  6770. // Prepare first bulk message
  6771. LLMessageSystem* msg = gMessageSystemp;
  6772. msg->newMessage("MultipleObjectUpdate");
  6773. packAgentAndSessionID(&update_type);
  6774. for (LLObjectSelection::root_iterator it = getSelection()->root_begin();
  6775. it != getSelection()->root_end(); ++it)
  6776. {
  6777. node = *it;
  6778. if (!node) continue; // Paranoia
  6779. LLViewerObject* obj = node->getObject();
  6780. if (!obj) continue; // Paranoia
  6781. // Note: following code adapted from sendListToRegions()
  6782. LLViewerRegion* last_region = curr_region;
  6783. curr_region = obj->getRegion();
  6784. // If not simulator or message too big
  6785. if (curr_region != last_region || msg->isSendFull(NULL) ||
  6786. objects_in_this_packet >= MAX_OBJECTS_PER_PACKET)
  6787. {
  6788. // Send the current message to the sim and start new one
  6789. msg->sendReliable(last_region->getHost());
  6790. objects_in_this_packet = 0;
  6791. msg->newMessage("MultipleObjectUpdate");
  6792. packAgentAndSessionID(&update_type);
  6793. }
  6794. // Add another instance of the body of data
  6795. packMultipleUpdate(node, &update_type);
  6796. ++objects_in_this_packet;
  6797. }
  6798. // Flush remaining messages
  6799. if (msg->getCurrentSendTotal() > 0)
  6800. {
  6801. msg->sendReliable(curr_region->getHost());
  6802. }
  6803. else
  6804. {
  6805. msg->clearMessage();
  6806. }
  6807. #if 0
  6808. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  6809. #endif
  6810. }
  6811. /////////////////////////////////////////////////////////////////////////////
  6812. // LLObjectSelection class
  6813. /////////////////////////////////////////////////////////////////////////////
  6814. // Object selection iterator helpers
  6815. bool LLObjectSelection::is_root::operator()(LLSelectNode* node)
  6816. {
  6817. LLViewerObject* object = node->getObject();
  6818. return object && !node->mIndividualSelection && object->isRootEdit();
  6819. }
  6820. bool LLObjectSelection::is_valid_root::operator()(LLSelectNode* node)
  6821. {
  6822. LLViewerObject* object = node->getObject();
  6823. return object && node->mValid && !node->mIndividualSelection &&
  6824. object->isRootEdit();
  6825. }
  6826. bool LLObjectSelection::is_root_object::operator()(LLSelectNode* node)
  6827. {
  6828. LLViewerObject* object = node->getObject();
  6829. return object && object->isRootEdit();
  6830. }
  6831. LLObjectSelection::LLObjectSelection()
  6832. : LLRefCount(),
  6833. mSelectType(SELECT_TYPE_WORLD)
  6834. {
  6835. }
  6836. LLObjectSelection::~LLObjectSelection()
  6837. {
  6838. deleteAllNodes();
  6839. }
  6840. void LLObjectSelection::cleanupNodes()
  6841. {
  6842. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6843. iter != end; )
  6844. {
  6845. list_t::iterator curiter = iter++;
  6846. LLSelectNode* node = *curiter;
  6847. if (!node || !node->getObject() || node->getObject()->isDead())
  6848. {
  6849. mList.erase(curiter);
  6850. delete node;
  6851. }
  6852. }
  6853. }
  6854. S32 LLObjectSelection::getNumNodes()
  6855. {
  6856. return mList.size();
  6857. }
  6858. void LLObjectSelection::addNode(LLSelectNode* nodep)
  6859. {
  6860. llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
  6861. mList.push_front(nodep);
  6862. mSelectNodeMap[nodep->getObject()] = nodep;
  6863. }
  6864. void LLObjectSelection::addNodeAtEnd(LLSelectNode* nodep)
  6865. {
  6866. llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
  6867. mList.push_back(nodep);
  6868. mSelectNodeMap[nodep->getObject()] = nodep;
  6869. }
  6870. void LLObjectSelection::moveNodeToFront(LLSelectNode* nodep)
  6871. {
  6872. mList.remove(nodep);
  6873. mList.push_front(nodep);
  6874. }
  6875. void LLObjectSelection::removeNode(LLSelectNode* nodep)
  6876. {
  6877. mSelectNodeMap.erase(nodep->getObject());
  6878. if (nodep->getObject() == mPrimaryObject)
  6879. {
  6880. mPrimaryObject = NULL;
  6881. }
  6882. nodep->setObject(NULL); // Will get erased in cleanupNodes()
  6883. mList.remove(nodep);
  6884. }
  6885. void LLObjectSelection::deleteAllNodes()
  6886. {
  6887. std::for_each(mList.begin(), mList.end(), DeletePointer());
  6888. mList.clear();
  6889. mSelectNodeMap.clear();
  6890. mPrimaryObject = NULL;
  6891. }
  6892. LLSelectNode* LLObjectSelection::findNode(LLViewerObject* objectp)
  6893. {
  6894. if (objectp)
  6895. {
  6896. std::map<LLPointer<LLViewerObject>, LLSelectNode*>::iterator it =
  6897. mSelectNodeMap.find(objectp);
  6898. if (it != mSelectNodeMap.end())
  6899. {
  6900. return it->second;
  6901. }
  6902. }
  6903. return NULL;
  6904. }
  6905. F32 LLObjectSelection::getSelectedObjectCost()
  6906. {
  6907. cleanupNodes();
  6908. F32 cost = 0.f;
  6909. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6910. iter != end; ++iter)
  6911. {
  6912. LLSelectNode* node = *iter;
  6913. if (!node) continue; // Paranoia
  6914. LLViewerObject* object = node->getObject();
  6915. if (object)
  6916. {
  6917. cost += object->getObjectCost();
  6918. }
  6919. }
  6920. return cost;
  6921. }
  6922. F32 LLObjectSelection::getSelectedLinksetCost()
  6923. {
  6924. cleanupNodes();
  6925. F32 cost = 0.f;
  6926. fast_hset<LLViewerObject*> me_roots;
  6927. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6928. iter != end; ++iter)
  6929. {
  6930. LLSelectNode* node = *iter;
  6931. if (!node) continue; // Paranoia
  6932. LLViewerObject* object = node->getObject();
  6933. if (object && !object->isAttachment())
  6934. {
  6935. LLViewerObject* root = (LLViewerObject*)object->getRoot();
  6936. if (root && !me_roots.count(root))
  6937. {
  6938. me_roots.insert(root);
  6939. cost += root->getLinksetCost();
  6940. }
  6941. }
  6942. }
  6943. return cost;
  6944. }
  6945. F32 LLObjectSelection::getSelectedPhysicsCost()
  6946. {
  6947. cleanupNodes();
  6948. F32 cost = 0.f;
  6949. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6950. iter != end; ++iter)
  6951. {
  6952. LLSelectNode* node = *iter;
  6953. if (!node) continue; // Paranoia
  6954. LLViewerObject* object = node->getObject();
  6955. if (object)
  6956. {
  6957. cost += object->getPhysicsCost();
  6958. }
  6959. }
  6960. return cost;
  6961. }
  6962. F32 LLObjectSelection::getSelectedLinksetPhysicsCost()
  6963. {
  6964. cleanupNodes();
  6965. F32 cost = 0.f;
  6966. fast_hset<LLViewerObject*> me_roots;
  6967. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6968. iter != end; ++iter)
  6969. {
  6970. LLSelectNode* node = *iter;
  6971. if (!node) continue; // Paranoia
  6972. LLViewerObject* object = node->getObject();
  6973. if (object)
  6974. {
  6975. LLViewerObject* root = (LLViewerObject*)object->getRoot();
  6976. if (root && !me_roots.count(root))
  6977. {
  6978. me_roots.insert(root);
  6979. cost += root->getLinksetPhysicsCost();
  6980. }
  6981. }
  6982. }
  6983. return cost;
  6984. }
  6985. F32 LLObjectSelection::getSelectedObjectStreamingCost(S32* total_bytes,
  6986. S32* visible_bytes)
  6987. {
  6988. F32 cost = 0.f;
  6989. for (list_t::iterator iter = mList.begin(), end = mList.end();
  6990. iter != end; ++iter)
  6991. {
  6992. LLSelectNode* node = *iter;
  6993. if (!node) continue; // Paranoia
  6994. LLViewerObject* object = node->getObject();
  6995. if (object)
  6996. {
  6997. S32 bytes = 0;
  6998. S32 visible = 0;
  6999. cost += object->getStreamingCost(&bytes, &visible);
  7000. if (total_bytes)
  7001. {
  7002. *total_bytes += bytes;
  7003. }
  7004. if (visible_bytes)
  7005. {
  7006. *visible_bytes += visible;
  7007. }
  7008. }
  7009. }
  7010. return cost;
  7011. }
  7012. U32 LLObjectSelection::getSelectedObjectTriangleCount(S32* vcount)
  7013. {
  7014. U32 count = 0;
  7015. for (list_t::iterator iter = mList.begin(), end = mList.end();
  7016. iter != end; ++iter)
  7017. {
  7018. LLSelectNode* node = *iter;
  7019. if (!node) continue; // Paranoia
  7020. LLViewerObject* object = node->getObject();
  7021. if (object)
  7022. {
  7023. S32 vt = 0;
  7024. count += object->getTriangleCount(&vt);
  7025. *vcount += vt;
  7026. }
  7027. }
  7028. return count;
  7029. }
  7030. S32 LLObjectSelection::getTECount()
  7031. {
  7032. S32 count = 0;
  7033. for (LLObjectSelection::iterator iter = begin(); iter != end(); ++iter)
  7034. {
  7035. LLSelectNode* node = *iter;
  7036. if (!node) continue; // Paranoia
  7037. LLViewerObject* object = node->getObject();
  7038. if (object)
  7039. {
  7040. S32 num_tes = object->getNumTEs();
  7041. for (S32 te = 0; te < num_tes; ++te)
  7042. {
  7043. if (node->isTESelected(te))
  7044. {
  7045. ++count;
  7046. }
  7047. }
  7048. }
  7049. }
  7050. return count;
  7051. }
  7052. S32 LLObjectSelection::getRootObjectCount()
  7053. {
  7054. S32 count = 0;
  7055. for (LLObjectSelection::root_iterator iter = root_begin();
  7056. iter != root_end(); ++iter)
  7057. {
  7058. ++count;
  7059. }
  7060. return count;
  7061. }
  7062. bool LLObjectSelection::applyToObjects(LLSelectedObjectFunctor* func)
  7063. {
  7064. bool result = true;
  7065. for (iterator iter = begin(); iter != end(); )
  7066. {
  7067. iterator cutiter = iter++;
  7068. LLSelectNode* nodep = *cutiter;
  7069. if (!nodep) continue; // Paranoia
  7070. LLViewerObject* objectp = nodep->getObject();
  7071. if (objectp)
  7072. {
  7073. // Always apply functor, even if result == false already
  7074. bool r = func->apply(objectp);
  7075. // Then, AND the results
  7076. result &= r;
  7077. }
  7078. }
  7079. return result;
  7080. }
  7081. void LLObjectSelection::applyNoCopyTextureToTEs(LLViewerInventoryItem* itemp)
  7082. {
  7083. if (!itemp) return;
  7084. LLViewerTexture* texp =
  7085. LLViewerTextureManager::getFetchedTexture(itemp->getAssetUUID());
  7086. if (!texp) return;
  7087. constexpr LLToolDragAndDrop::ESource source =
  7088. LLToolDragAndDrop::SOURCE_AGENT;
  7089. for (iterator iter = begin(); iter != end(); )
  7090. {
  7091. iterator cutiter = iter++;
  7092. LLSelectNode* nodep = *cutiter;
  7093. if (!nodep) continue; // Paranoia
  7094. LLViewerObject* objectp = nodep->getObject();
  7095. if (!objectp) continue;
  7096. bool texture_copied = false;
  7097. bool updated = false;
  7098. U32 num_tes = llmin(objectp->getNumTEs(), objectp->getNumFaces());
  7099. for (U32 te = 0; te < num_tes; ++te)
  7100. {
  7101. if (!nodep->isTESelected(te)) continue;
  7102. if (!texture_copied)
  7103. {
  7104. texture_copied = true;
  7105. if (LLToolDragAndDrop::handleDropAssetProtections(objectp,
  7106. itemp,
  7107. source))
  7108. {
  7109. gViewerStats.incStat(LLViewerStats::ST_EDIT_TEXTURE_COUNT);
  7110. }
  7111. }
  7112. // Apply texture to the selected face
  7113. objectp->setTEImage(te, texp);
  7114. updated = true;
  7115. }
  7116. // *TODO: check whether this is necessary or not (i.e. not already
  7117. // done).
  7118. if (updated)
  7119. {
  7120. dialog_refresh_all();
  7121. objectp->sendTEUpdate();
  7122. }
  7123. }
  7124. }
  7125. bool LLObjectSelection::applyRestrictedPbrMatToTEs(LLViewerInventoryItem* itemp)
  7126. {
  7127. if (!itemp)
  7128. {
  7129. return false;
  7130. }
  7131. bool success = true;
  7132. LLUUID asset_id = itemp->getAssetUUID();
  7133. if (asset_id.isNull())
  7134. {
  7135. asset_id = BLANK_MATERIAL_ASSET_ID;
  7136. }
  7137. constexpr LLToolDragAndDrop::ESource source =
  7138. LLToolDragAndDrop::SOURCE_AGENT;
  7139. for (iterator iter = begin(); iter != end(); )
  7140. {
  7141. iterator cutiter = iter++;
  7142. LLSelectNode* nodep = *cutiter;
  7143. if (!nodep) continue; // Paranoia
  7144. LLViewerObject* objectp = nodep->getObject();
  7145. if (!objectp) continue;
  7146. bool material_copied = false;
  7147. U32 num_tes = llmin(objectp->getNumTEs(), objectp->getNumFaces());
  7148. for (U32 te = 0; te < num_tes; ++te)
  7149. {
  7150. if (!nodep->isTESelected(te)) continue;
  7151. // No-copy, no-modify, no-transfer materials must be moved to the
  7152. // object inventory only once without making any copies.
  7153. if (!material_copied && asset_id.notNull())
  7154. {
  7155. material_copied =
  7156. LLToolDragAndDrop::handleDropAssetProtections(objectp,
  7157. itemp,
  7158. source);
  7159. if (!material_copied)
  7160. {
  7161. // Applying the material is not possible for this object
  7162. // given the current inventory.
  7163. success = false;
  7164. break;
  7165. }
  7166. }
  7167. // Apply material to the selected face; blanks out most override
  7168. // data on the server.
  7169. objectp->setRenderMaterialID(te, asset_id);
  7170. }
  7171. }
  7172. LLGLTFMaterialList::flushUpdates();
  7173. return success;
  7174. }
  7175. bool LLObjectSelection::checkAnimatedObjectEstTris()
  7176. {
  7177. F32 est_tris = 0.f;
  7178. F32 max_tris = 0.f;
  7179. S32 anim_count = 0;
  7180. for (root_iterator iter = root_begin(), end = root_end();
  7181. iter != end; ++iter)
  7182. {
  7183. LLSelectNode* node = *iter;
  7184. if (!node) continue; // Paranoia
  7185. LLViewerObject* object = node->getObject();
  7186. if (!object) continue;
  7187. if (object->isAnimatedObject())
  7188. {
  7189. ++anim_count;
  7190. }
  7191. est_tris += object->recursiveGetEstTrianglesMax();
  7192. max_tris = llmax(max_tris, (F32)object->getAnimatedObjectMaxTris());
  7193. }
  7194. return anim_count == 0 || est_tris <= max_tris;
  7195. }
  7196. bool LLObjectSelection::applyToRootObjects(LLSelectedObjectFunctor* func,
  7197. bool firstonly)
  7198. {
  7199. bool result = firstonly ? false : true;
  7200. for (root_iterator iter = root_begin(); iter != root_end(); )
  7201. {
  7202. root_iterator nextiter = iter++;
  7203. LLSelectNode* node = *nextiter;
  7204. if (!node) continue; // Paranoia
  7205. LLViewerObject* object = node->getObject();
  7206. if (object)
  7207. {
  7208. bool r = func->apply(object);
  7209. if (firstonly && r)
  7210. {
  7211. return true;
  7212. }
  7213. result = result && r;
  7214. }
  7215. }
  7216. return result;
  7217. }
  7218. bool LLObjectSelection::applyToTEs(LLSelectedTEFunctor* func, bool firstonly)
  7219. {
  7220. bool result = !firstonly;
  7221. for (iterator iter = begin(); iter != end(); )
  7222. {
  7223. iterator nextiter = iter++;
  7224. LLSelectNode* node = *nextiter;
  7225. if (!node) continue; // Paranoia
  7226. LLViewerObject* object = node->getObject();
  7227. if (!object)
  7228. {
  7229. continue;
  7230. }
  7231. // Avatars have TEs but no faces
  7232. S32 num_tes = llmin((S32)object->getNumTEs(),
  7233. (S32)object->getNumFaces());
  7234. for (S32 te = 0; te < num_tes; ++te)
  7235. {
  7236. if (node->isTESelected(te))
  7237. {
  7238. bool r = func->apply(object, te);
  7239. if (firstonly && r)
  7240. {
  7241. return true;
  7242. }
  7243. result = result && r;
  7244. }
  7245. }
  7246. }
  7247. return result;
  7248. }
  7249. bool LLObjectSelection::applyToNodes(LLSelectedNodeFunctor* func,
  7250. bool firstonly)
  7251. {
  7252. bool result = !firstonly;
  7253. for (iterator iter = begin(); iter != end(); )
  7254. {
  7255. iterator nextiter = iter++;
  7256. LLSelectNode* node = *nextiter;
  7257. if (!node) continue; // Paranoia
  7258. bool r = func->apply(node);
  7259. if (firstonly && r)
  7260. {
  7261. return true;
  7262. }
  7263. result = result && r;
  7264. }
  7265. return result;
  7266. }
  7267. bool LLObjectSelection::applyToRootNodes(LLSelectedNodeFunctor *func,
  7268. bool firstonly)
  7269. {
  7270. bool result = !firstonly;
  7271. for (root_iterator iter = root_begin(); iter != root_end(); )
  7272. {
  7273. root_iterator nextiter = iter++;
  7274. LLSelectNode* node = *nextiter;
  7275. if (!node) continue; // Paranoia
  7276. bool r = func->apply(node);
  7277. if (firstonly && r)
  7278. {
  7279. return true;
  7280. }
  7281. else
  7282. {
  7283. result = result && r;
  7284. }
  7285. }
  7286. return result;
  7287. }
  7288. bool LLObjectSelection::isMultipleTESelected()
  7289. {
  7290. bool te_selected = false;
  7291. // ...all faces
  7292. for (LLObjectSelection::iterator iter = begin(); iter != end(); ++iter)
  7293. {
  7294. LLSelectNode* nodep = *iter;
  7295. if (!nodep) continue; // Paranoia
  7296. for (S32 i = 0; i < SELECT_MAX_TES; ++i)
  7297. {
  7298. if (nodep->isTESelected(i))
  7299. {
  7300. if (te_selected)
  7301. {
  7302. return true;
  7303. }
  7304. te_selected = true;
  7305. }
  7306. }
  7307. }
  7308. return false;
  7309. }
  7310. bool LLObjectSelection::getSelectedTEValue(LLSelectedTEGetFunctor<F32>* func,
  7311. F32& res, F32 tolerance)
  7312. {
  7313. bool have_first = false;
  7314. bool have_selected = false;
  7315. F32 selected_value = 0.f;
  7316. // Now iterate through all TEs to test for sameness
  7317. bool identical = true;
  7318. for (iterator iter = begin(); iter != end(); ++iter)
  7319. {
  7320. LLSelectNode* node = *iter;
  7321. LLViewerObject* object = node->getObject();
  7322. S32 selected_te = -1;
  7323. if (object == getPrimaryObject())
  7324. {
  7325. selected_te = node->getLastSelectedTE();
  7326. }
  7327. for (S32 te = 0, count = object->getNumTEs(); te < count; ++te)
  7328. {
  7329. if (!node->isTESelected(te))
  7330. {
  7331. continue;
  7332. }
  7333. F32 value = func->get(object, te);
  7334. if (!have_first)
  7335. {
  7336. have_first = true;
  7337. if (!have_selected)
  7338. {
  7339. selected_value = value;
  7340. }
  7341. }
  7342. else
  7343. {
  7344. if (fabs(value - selected_value) > tolerance)
  7345. {
  7346. identical = false;
  7347. }
  7348. if (te == selected_te)
  7349. {
  7350. selected_value = value;
  7351. have_selected = true;
  7352. }
  7353. }
  7354. }
  7355. if (!identical && have_selected)
  7356. {
  7357. break;
  7358. }
  7359. }
  7360. if (have_first || have_selected)
  7361. {
  7362. res = selected_value;
  7363. }
  7364. return identical;
  7365. }
  7366. bool LLObjectSelection::contains(LLViewerObject* object)
  7367. {
  7368. return findNode(object) != NULL;
  7369. }
  7370. bool LLObjectSelection::contains(LLViewerObject* object, S32 te)
  7371. {
  7372. if (te == SELECT_ALL_TES)
  7373. {
  7374. // ...all faces
  7375. for (LLObjectSelection::iterator iter = begin();
  7376. iter != end(); ++iter)
  7377. {
  7378. LLSelectNode* nodep = *iter;
  7379. if (nodep && nodep->getObject() == object)
  7380. {
  7381. // Optimization
  7382. if (nodep->getTESelectMask() == TE_SELECT_MASK_ALL)
  7383. {
  7384. return true;
  7385. }
  7386. bool all_selected = true;
  7387. for (S32 i = 0, count = object->getNumTEs(); i < count; ++i)
  7388. {
  7389. all_selected = all_selected && nodep->isTESelected(i);
  7390. }
  7391. return all_selected;
  7392. }
  7393. }
  7394. return false;
  7395. }
  7396. else
  7397. {
  7398. // ... one face
  7399. for (LLObjectSelection::iterator iter = begin(); iter != end(); ++iter)
  7400. {
  7401. LLSelectNode* nodep = *iter;
  7402. if (nodep &&
  7403. nodep->getObject() == object && nodep->isTESelected(te))
  7404. {
  7405. return true;
  7406. }
  7407. }
  7408. return false;
  7409. }
  7410. }
  7411. // Returns true is any node is currenly worn as an attachment
  7412. bool LLObjectSelection::isAttachment()
  7413. {
  7414. return mSelectType == SELECT_TYPE_ATTACHMENT ||
  7415. mSelectType == SELECT_TYPE_HUD;
  7416. }
  7417. LLSelectNode* LLObjectSelection::getFirstNode(LLSelectedNodeFunctor* func)
  7418. {
  7419. for (iterator iter = begin(); iter != end(); ++iter)
  7420. {
  7421. LLSelectNode* node = *iter;
  7422. if (!func || (node && func->apply(node)))
  7423. {
  7424. return node;
  7425. }
  7426. }
  7427. return NULL;
  7428. }
  7429. LLSelectNode* LLObjectSelection::getFirstRootNode(LLSelectedNodeFunctor* func,
  7430. bool non_root_ok)
  7431. {
  7432. for (root_iterator iter = root_begin(); iter != root_end(); ++iter)
  7433. {
  7434. LLSelectNode* node = *iter;
  7435. if (!func || (node && func->apply(node)))
  7436. {
  7437. return node;
  7438. }
  7439. }
  7440. if (non_root_ok)
  7441. {
  7442. // Get non root
  7443. return getFirstNode(func);
  7444. }
  7445. return NULL;
  7446. }
  7447. LLViewerObject* LLObjectSelection::getFirstSelectedObject(LLSelectedNodeFunctor* func,
  7448. bool get_parent)
  7449. {
  7450. LLSelectNode* res = getFirstNode(func);
  7451. if (!res)
  7452. {
  7453. return NULL;
  7454. }
  7455. if (get_parent)
  7456. {
  7457. return getSelectedParentObject(res->getObject());
  7458. }
  7459. return res->getObject();
  7460. }
  7461. LLSelectNode* LLObjectSelection::getFirstMoveableNode(bool get_root_first)
  7462. {
  7463. struct f final : public LLSelectedNodeFunctor
  7464. {
  7465. bool apply(LLSelectNode* node) override
  7466. {
  7467. LLViewerObject* obj = node->getObject();
  7468. return obj && obj->permMove() && !obj->isPermanentEnforced();
  7469. }
  7470. } func;
  7471. LLSelectNode* res = get_root_first ? getFirstRootNode(&func, true)
  7472. : getFirstNode(&func);
  7473. return res;
  7474. }
  7475. LLViewerObject* LLObjectSelection::getFirstCopyableObject(bool get_parent)
  7476. {
  7477. struct f final : public LLSelectedNodeFunctor
  7478. {
  7479. bool apply(LLSelectNode* node) override
  7480. {
  7481. LLViewerObject* obj = node->getObject();
  7482. return obj && obj->permCopy() && !obj->isAttachment();
  7483. }
  7484. } func;
  7485. return getFirstSelectedObject(&func, get_parent);
  7486. }
  7487. LLViewerObject* LLObjectSelection::getFirstDeleteableObject()
  7488. {
  7489. // RN: do not currently support deletion of child objects, as that requires
  7490. // separating them first then derezzing to trash
  7491. struct f final : public LLSelectedNodeFunctor
  7492. {
  7493. bool apply(LLSelectNode* node) override
  7494. {
  7495. LLViewerObject* obj = node->getObject();
  7496. // You can delete an object if it is not an attachment and you are
  7497. // the owner or you have permission to modify it.
  7498. if (obj && !obj->isAttachment() && !obj->isPermanentEnforced() &&
  7499. (obj->permModify() || obj->permYouOwner() ||
  7500. !obj->permAnyOwner())) // not public
  7501. {
  7502. return true;
  7503. }
  7504. return false;
  7505. }
  7506. } func;
  7507. LLSelectNode* node = getFirstNode(&func);
  7508. return node ? node->getObject() : NULL;
  7509. }
  7510. LLViewerObject* LLObjectSelection::getFirstEditableObject(bool get_parent)
  7511. {
  7512. struct f final : public LLSelectedNodeFunctor
  7513. {
  7514. bool apply(LLSelectNode* node) override
  7515. {
  7516. LLViewerObject* obj = node->getObject();
  7517. return obj && obj->permModify();
  7518. }
  7519. } func;
  7520. return getFirstSelectedObject(&func, get_parent);
  7521. }
  7522. LLViewerObject* LLObjectSelection::getFirstMoveableObject(bool get_parent)
  7523. {
  7524. struct f final : public LLSelectedNodeFunctor
  7525. {
  7526. bool apply(LLSelectNode* node) override
  7527. {
  7528. LLViewerObject* obj = node->getObject();
  7529. return obj && obj->permMove() && !obj->isPermanentEnforced();
  7530. }
  7531. } func;
  7532. return getFirstSelectedObject(&func, get_parent);
  7533. }
  7534. LLViewerObject* LLObjectSelection::getFirstUndoEnabledObject(bool get_parent)
  7535. {
  7536. struct f final : public LLSelectedNodeFunctor
  7537. {
  7538. bool apply(LLSelectNode* node) override
  7539. {
  7540. LLViewerObject* obj = node->getObject();
  7541. return obj &&
  7542. (obj->permModify() ||
  7543. (obj->permMove() && !obj->isPermanentEnforced()));
  7544. }
  7545. } func;
  7546. return getFirstSelectedObject(&func, get_parent);
  7547. }