SceneObjectGroup.cs 203 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.ComponentModel;
  29. using System.Collections.Generic;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Diagnostics;
  33. using System.Linq;
  34. using System.Threading;
  35. using System.Xml;
  36. using System.Xml.Serialization;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.PhysicsModules.SharedBase;
  42. using OpenSim.Region.Framework.Scenes.Serialization;
  43. using PermissionMask = OpenSim.Framework.PermissionMask;
  44. using OpenSim.Services.Interfaces;
  45. namespace OpenSim.Region.Framework.Scenes
  46. {
  47. [Flags]
  48. public enum scriptEvents
  49. {
  50. None = 0,
  51. attach = 1,
  52. collision = 16,
  53. collision_end = 32,
  54. collision_start = 64,
  55. control = 128,
  56. dataserver = 256,
  57. email = 512,
  58. http_response = 1024,
  59. land_collision = 2048,
  60. land_collision_end = 4096,
  61. land_collision_start = 8192,
  62. at_target = 16384,
  63. at_rot_target = 16777216,
  64. listen = 32768,
  65. money = 65536,
  66. moving_end = 131072,
  67. moving_start = 262144,
  68. not_at_rot_target = 524288,
  69. not_at_target = 1048576,
  70. remote_data = 8388608,
  71. run_time_permissions = 268435456,
  72. state_entry = 1073741824,
  73. state_exit = 2,
  74. timer = 4,
  75. touch = 8,
  76. touch_end = 536870912,
  77. touch_start = 2097152,
  78. transaction_result = 33554432,
  79. object_rez = 4194304,
  80. anytouch = touch | touch_end | touch_start
  81. }
  82. public struct scriptPosTarget
  83. {
  84. public Vector3 targetPos;
  85. public float tolerance;
  86. public uint handle;
  87. }
  88. public struct scriptRotTarget
  89. {
  90. public Quaternion targetRot;
  91. public float tolerance;
  92. public uint handle;
  93. }
  94. public delegate void PrimCountTaintedDelegate();
  95. /// <summary>
  96. /// A scene object group is conceptually an object in the scene. The object is constituted of SceneObjectParts
  97. /// (often known as prims), one of which is considered the root part.
  98. /// </summary>
  99. public partial class SceneObjectGroup : EntityBase, ISceneObject
  100. {
  101. // Axis selection bitmask used by SetAxisRotation()
  102. // Just happen to be the same bits used by llSetStatus() and defined in ScriptBaseClass.
  103. public enum axisSelect : int
  104. {
  105. STATUS_ROTATE_X = 0x002,
  106. STATUS_ROTATE_Y = 0x004,
  107. STATUS_ROTATE_Z = 0x008,
  108. NOT_STATUS_ROTATE_X = 0xFD,
  109. NOT_STATUS_ROTATE_Y = 0xFB,
  110. NOT_STATUS_ROTATE_Z = 0xF7
  111. }
  112. // private PrimCountTaintedDelegate handlerPrimCountTainted = null;
  113. /// <summary>
  114. /// Signal whether the non-inventory attributes of any prims in the group have changed
  115. /// since the group's last persistent backup
  116. /// </summary>
  117. private bool m_hasGroupChanged = false;
  118. private long timeFirstChanged = 0;
  119. private long timeLastChanged = 0;
  120. private long m_maxPersistTime = 0;
  121. private long m_minPersistTime = 0;
  122. // private Random m_rand;
  123. /// <summary>
  124. /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage
  125. /// (the database).
  126. /// </summary>
  127. /// <remarks>
  128. /// Ultimately, this should be managed such that region modules can change it at the end of a set of operations
  129. /// so that either all changes are preserved or none at all. However, currently, a large amount of internal
  130. /// code will set this anyway when some object properties are changed.
  131. /// </remarks>
  132. public bool HasGroupChanged
  133. {
  134. set
  135. {
  136. if (value)
  137. {
  138. if (Backup)
  139. {
  140. m_scene.SceneGraph.FireChangeBackup(this);
  141. }
  142. timeLastChanged = DateTime.UtcNow.Ticks;
  143. if (!m_hasGroupChanged)
  144. timeFirstChanged = DateTime.UtcNow.Ticks;
  145. if (m_rootPart != null && m_scene != null)
  146. {
  147. /*
  148. if (m_rand == null)
  149. {
  150. byte[] val = new byte[16];
  151. m_rootPart.UUID.ToBytes(val, 0);
  152. m_rand = new Random(BitConverter.ToInt32(val, 0));
  153. }
  154. */
  155. if (m_scene.GetRootAgentCount() == 0)
  156. {
  157. //If the region is empty, this change has been made by an automated process
  158. //and thus we delay the persist time by a random amount between 1.5 and 2.5.
  159. // float factor = 1.5f + (float)(m_rand.NextDouble());
  160. float factor = 2.0f;
  161. m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
  162. m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
  163. }
  164. else
  165. {
  166. //If the region is not empty, we want to obey the minimum and maximum persist times
  167. //but add a random factor so we stagger the object persistance a little
  168. // m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
  169. // m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
  170. m_maxPersistTime = m_scene.m_persistAfter;
  171. m_minPersistTime = m_scene.m_dontPersistBefore;
  172. }
  173. }
  174. }
  175. m_hasGroupChanged = value;
  176. // m_log.DebugFormat(
  177. // "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId);
  178. }
  179. get { return m_hasGroupChanged; }
  180. }
  181. private bool m_groupContainsForeignPrims = false;
  182. /// <summary>
  183. /// Whether the group contains prims that came from a different group. This happens when
  184. /// linking or delinking groups. The implication is that until the group is persisted,
  185. /// the prims in the database still use the old SceneGroupID. That's a problem if the group
  186. /// is deleted, because we delete groups by searching for prims by their SceneGroupID.
  187. /// </summary>
  188. public bool GroupContainsForeignPrims
  189. {
  190. private set
  191. {
  192. m_groupContainsForeignPrims = value;
  193. if (m_groupContainsForeignPrims)
  194. HasGroupChanged = true;
  195. }
  196. get { return m_groupContainsForeignPrims; }
  197. }
  198. public bool HasGroupChangedDueToDelink { get; set; }
  199. private bool isTimeToPersist()
  200. {
  201. if (IsSelected || IsDeleted || IsAttachment)
  202. return false;
  203. if (!m_hasGroupChanged)
  204. return false;
  205. if (m_scene.ShuttingDown)
  206. return true;
  207. if (m_minPersistTime == 0 || m_maxPersistTime == 0)
  208. {
  209. m_maxPersistTime = m_scene.m_persistAfter;
  210. m_minPersistTime = m_scene.m_dontPersistBefore;
  211. }
  212. long currentTime = DateTime.UtcNow.Ticks;
  213. if (timeLastChanged == 0) timeLastChanged = currentTime;
  214. if (timeFirstChanged == 0) timeFirstChanged = currentTime;
  215. if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
  216. return true;
  217. return false;
  218. }
  219. /// <summary>
  220. /// Is this scene object acting as an attachment?
  221. /// </summary>
  222. public bool IsAttachment { get; set; }
  223. /// <summary>
  224. /// The avatar to which this scene object is attached.
  225. /// </summary>
  226. /// <remarks>
  227. /// If we're not attached to an avatar then this is UUID.Zero
  228. /// </remarks>
  229. public UUID AttachedAvatar { get; set; }
  230. /// <summary>
  231. /// Attachment point of this scene object to an avatar.
  232. /// </summary>
  233. /// <remarks>
  234. /// 0 if we're not attached to anything
  235. /// </remarks>
  236. public uint AttachmentPoint
  237. {
  238. get
  239. {
  240. return m_rootPart.Shape.State;
  241. }
  242. set
  243. {
  244. IsAttachment = value != 0;
  245. m_rootPart.Shape.State = (byte)value;
  246. }
  247. }
  248. /// <summary>
  249. /// If this scene object has an attachment point then indicate whether there is a point where
  250. /// attachments are perceivable by avatars other than the avatar to which this object is attached.
  251. /// </summary>
  252. /// <remarks>
  253. /// HUDs are not perceivable by other avatars.
  254. /// </remarks>
  255. public bool HasPrivateAttachmentPoint
  256. {
  257. get
  258. {
  259. return AttachmentPoint >= (uint)OpenMetaverse.AttachmentPoint.HUDCenter2
  260. && AttachmentPoint <= (uint)OpenMetaverse.AttachmentPoint.HUDBottomRight;
  261. }
  262. }
  263. public void ClearPartAttachmentData()
  264. {
  265. AttachmentPoint = 0;
  266. // Don't zap trees
  267. if (RootPart.Shape.PCode == (byte)PCode.Tree ||
  268. RootPart.Shape.PCode == (byte)PCode.NewTree)
  269. return;
  270. // Even though we don't use child part state parameters for attachments any more, we still need to set
  271. // these to zero since having them non-zero in rezzed scene objects will crash some clients. Even if
  272. // we store them correctly, scene objects that we receive from elsewhere might not.
  273. foreach (SceneObjectPart part in Parts)
  274. part.Shape.State = 0;
  275. }
  276. /// <summary>
  277. /// Is this scene object phantom?
  278. /// </summary>
  279. /// <remarks>
  280. /// Updating must currently take place through UpdatePrimFlags()
  281. /// </remarks>
  282. public bool IsPhantom
  283. {
  284. get { return (RootPart.Flags & PrimFlags.Phantom) != 0; }
  285. }
  286. /// <summary>
  287. /// Does this scene object use physics?
  288. /// </summary>
  289. /// <remarks>
  290. /// Updating must currently take place through UpdatePrimFlags()
  291. /// </remarks>
  292. public bool UsesPhysics
  293. {
  294. get { return (RootPart.Flags & PrimFlags.Physics) != 0; }
  295. }
  296. /// <summary>
  297. /// Is this scene object temporary?
  298. /// </summary>
  299. /// <remarks>
  300. /// Updating must currently take place through UpdatePrimFlags()
  301. /// </remarks>
  302. public bool IsTemporary
  303. {
  304. get { return (RootPart.Flags & PrimFlags.TemporaryOnRez) != 0; }
  305. }
  306. public bool IsVolumeDetect
  307. {
  308. get { return RootPart.VolumeDetectActive; }
  309. }
  310. /// <summary>
  311. /// Is this entity set to be saved in persistent storage?
  312. /// </summary>
  313. public bool Backup { get; private set; }
  314. protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>();
  315. protected ulong m_regionHandle;
  316. protected SceneObjectPart m_rootPart;
  317. // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  318. private SortedDictionary<uint, scriptPosTarget> m_targets = new SortedDictionary<uint, scriptPosTarget>();
  319. private SortedDictionary<uint, scriptRotTarget> m_rotTargets = new SortedDictionary<uint, scriptRotTarget>();
  320. public SortedDictionary<uint, scriptPosTarget> AtTargets
  321. {
  322. get { return m_targets; }
  323. }
  324. public SortedDictionary<uint, scriptRotTarget> RotTargets
  325. {
  326. get { return m_rotTargets; }
  327. }
  328. private bool m_scriptListens_atTarget;
  329. private bool m_scriptListens_notAtTarget;
  330. private bool m_scriptListens_atRotTarget;
  331. private bool m_scriptListens_notAtRotTarget;
  332. public bool m_dupeInProgress = false;
  333. internal Dictionary<UUID, string> m_savedScriptState;
  334. public UUID MonitoringObject { get; set; }
  335. #region Properties
  336. /// <summary>
  337. /// The name of an object grouping is always the same as its root part
  338. /// </summary>
  339. public override string Name
  340. {
  341. get { return RootPart.Name; }
  342. set { RootPart.Name = value; }
  343. }
  344. public string Description
  345. {
  346. get { return RootPart.Description; }
  347. set { RootPart.Description = value; }
  348. }
  349. /// <summary>
  350. /// Added because the Parcel code seems to use it
  351. /// but not sure a object should have this
  352. /// as what does it tell us? that some avatar has selected it (but not what Avatar/user)
  353. /// think really there should be a list (or whatever) in each scenepresence
  354. /// saying what prim(s) that user has selected.
  355. /// </summary>
  356. protected bool m_isSelected = false;
  357. /// <summary>
  358. /// Number of prims in this group
  359. /// </summary>
  360. public int PrimCount
  361. {
  362. get { return m_parts.Count; }
  363. }
  364. // protected Quaternion m_rotation = Quaternion.Identity;
  365. //
  366. // public virtual Quaternion Rotation
  367. // {
  368. // get { return m_rotation; }
  369. // set {
  370. // m_rotation = value;
  371. // }
  372. // }
  373. public Quaternion GroupRotation
  374. {
  375. get { return m_rootPart.RotationOffset; }
  376. }
  377. public Vector3 GroupScale
  378. {
  379. get
  380. {
  381. Vector3 minScale = new Vector3(Constants.MaximumRegionSize, Constants.MaximumRegionSize, Constants.MaximumRegionSize);
  382. Vector3 maxScale = Vector3.Zero;
  383. Vector3 finalScale = new Vector3(0.5f, 0.5f, 0.5f);
  384. SceneObjectPart[] parts = m_parts.GetArray();
  385. for (int i = 0; i < parts.Length; i++)
  386. {
  387. SceneObjectPart part = parts[i];
  388. Vector3 partscale = part.Scale;
  389. Vector3 partoffset = part.OffsetPosition;
  390. minScale.X = (partscale.X + partoffset.X < minScale.X) ? partscale.X + partoffset.X : minScale.X;
  391. minScale.Y = (partscale.Y + partoffset.Y < minScale.Y) ? partscale.Y + partoffset.Y : minScale.Y;
  392. minScale.Z = (partscale.Z + partoffset.Z < minScale.Z) ? partscale.Z + partoffset.Z : minScale.Z;
  393. maxScale.X = (partscale.X + partoffset.X > maxScale.X) ? partscale.X + partoffset.X : maxScale.X;
  394. maxScale.Y = (partscale.Y + partoffset.Y > maxScale.Y) ? partscale.Y + partoffset.Y : maxScale.Y;
  395. maxScale.Z = (partscale.Z + partoffset.Z > maxScale.Z) ? partscale.Z + partoffset.Z : maxScale.Z;
  396. }
  397. finalScale.X = (minScale.X > maxScale.X) ? minScale.X : maxScale.X;
  398. finalScale.Y = (minScale.Y > maxScale.Y) ? minScale.Y : maxScale.Y;
  399. finalScale.Z = (minScale.Z > maxScale.Z) ? minScale.Z : maxScale.Z;
  400. return finalScale;
  401. }
  402. }
  403. public UUID GroupID
  404. {
  405. get { return m_rootPart.GroupID; }
  406. set { m_rootPart.GroupID = value; }
  407. }
  408. public SceneObjectPart[] Parts
  409. {
  410. get { return m_parts.GetArray(); }
  411. }
  412. public bool ContainsPart(UUID partID)
  413. {
  414. return m_parts.ContainsKey(partID);
  415. }
  416. /// <summary>
  417. /// Does this group contain the given part?
  418. /// should be able to remove these methods once we have a entity index in scene
  419. /// </summary>
  420. /// <param name="localID"></param>
  421. /// <returns></returns>
  422. public bool ContainsPart(uint localID)
  423. {
  424. SceneObjectPart[] parts = m_parts.GetArray();
  425. for (int i = 0; i < parts.Length; i++)
  426. {
  427. if (parts[i].LocalId == localID)
  428. return true;
  429. }
  430. return false;
  431. }
  432. /// <value>
  433. /// The root part of this scene object
  434. /// </value>
  435. public SceneObjectPart RootPart
  436. {
  437. get { return m_rootPart; }
  438. }
  439. public ulong RegionHandle
  440. {
  441. get { return m_regionHandle; }
  442. set
  443. {
  444. m_regionHandle = value;
  445. SceneObjectPart[] parts = m_parts.GetArray();
  446. for (int i = 0; i < parts.Length; i++)
  447. parts[i].RegionHandle = value;
  448. }
  449. }
  450. /// <summary>
  451. /// Check both the attachment property and the relevant properties of the underlying root part.
  452. /// </summary>
  453. /// <remarks>
  454. /// This is necessary in some cases, particularly when a scene object has just crossed into a region and doesn't
  455. /// have the IsAttachment property yet checked.
  456. ///
  457. /// FIXME: However, this should be fixed so that this property
  458. /// propertly reflects the underlying status.
  459. /// </remarks>
  460. /// <returns></returns>
  461. public bool IsAttachmentCheckFull()
  462. {
  463. return (IsAttachment ||
  464. (m_rootPart.Shape.PCode == (byte)PCodeEnum.Primitive && m_rootPart.Shape.State != 0));
  465. }
  466. private struct avtocrossInfo
  467. {
  468. public ScenePresence av;
  469. public uint ParentID;
  470. }
  471. public bool inTransit = false;
  472. private delegate SceneObjectGroup SOGCrossDelegate(SceneObjectGroup sog,Vector3 pos, TeleportObjectData tpData);
  473. /// <summary>
  474. /// The absolute position of this scene object in the scene
  475. /// </summary>
  476. public override Vector3 AbsolutePosition
  477. {
  478. get { return m_rootPart.GroupPosition; }
  479. set
  480. {
  481. Vector3 val = value;
  482. if (Scene != null
  483. && !Scene.PositionIsInCurrentRegion(val)
  484. && !IsAttachmentCheckFull()
  485. && !Scene.LoadingPrims
  486. && !Scene.DisableObjectTransfer
  487. )
  488. {
  489. if (!inTransit)
  490. {
  491. inTransit = true;
  492. SOGCrossDelegate d = CrossAsync;
  493. d.BeginInvoke(this, val, null, CrossAsyncCompleted, d);
  494. }
  495. return;
  496. }
  497. if (RootPart.GetStatusSandbox())
  498. {
  499. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
  500. {
  501. RootPart.ScriptSetPhysicsStatus(false);
  502. if (Scene != null)
  503. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  504. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  505. return;
  506. }
  507. }
  508. bool triggerScriptEvent = m_rootPart.GroupPosition != val;
  509. if (m_dupeInProgress || IsDeleted)
  510. triggerScriptEvent = false;
  511. m_rootPart.GroupPosition = val;
  512. // Restuff the new GroupPosition into each child SOP of the linkset.
  513. // this is needed because physics may not have linksets but just loose SOPs in world
  514. SceneObjectPart[] parts = m_parts.GetArray();
  515. foreach (SceneObjectPart part in parts)
  516. {
  517. if (part != m_rootPart)
  518. part.GroupPosition = val;
  519. }
  520. foreach (ScenePresence av in m_sittingAvatars)
  521. {
  522. av.sitSOGmoved();
  523. }
  524. // now that position is changed tell it to scripts
  525. if (triggerScriptEvent)
  526. {
  527. foreach (SceneObjectPart part in parts)
  528. {
  529. part.TriggerScriptChangedEvent(Changed.POSITION);
  530. }
  531. }
  532. if (Scene != null)
  533. Scene.EventManager.TriggerParcelPrimCountTainted();
  534. }
  535. }
  536. private SceneObjectGroup CrossAsync(SceneObjectGroup sog, Vector3 val, TeleportObjectData tpdata)
  537. {
  538. Scene sogScene = sog.m_scene;
  539. SceneObjectPart root = sog.RootPart;
  540. bool isTeleport = tpdata != null;
  541. if(!isTeleport)
  542. {
  543. if (root.DIE_AT_EDGE)
  544. {
  545. try
  546. {
  547. sogScene.DeleteSceneObject(sog, false);
  548. }
  549. catch (Exception)
  550. {
  551. m_log.Warn("[SCENE]: exception when trying to remove the prim that crossed the border.");
  552. }
  553. return sog;
  554. }
  555. if (root.RETURN_AT_EDGE)
  556. {
  557. // We remove the object here
  558. try
  559. {
  560. List<uint> localIDs = new List<uint>();
  561. localIDs.Add(root.LocalId);
  562. sogScene.AddReturn(sog.OwnerID, sog.Name, sog.AbsolutePosition,
  563. "Returned at region cross");
  564. sogScene.DeRezObjects(null, localIDs, UUID.Zero, DeRezAction.Return, UUID.Zero, false);
  565. }
  566. catch (Exception)
  567. {
  568. m_log.Warn("[SCENE]: exception when trying to return the prim that crossed the border.");
  569. }
  570. return sog;
  571. }
  572. }
  573. if (root.KeyframeMotion != null)
  574. root.KeyframeMotion.StartCrossingCheck();
  575. if(root.PhysActor != null)
  576. root.PhysActor.CrossingStart();
  577. IEntityTransferModule entityTransfer = sogScene.RequestModuleInterface<IEntityTransferModule>();
  578. if (entityTransfer == null)
  579. return sog;
  580. Vector3 newpos = Vector3.Zero;
  581. OpenSim.Services.Interfaces.GridRegion destination = null;
  582. destination = entityTransfer.GetObjectDestination(sog, val, out newpos);
  583. if (destination == null)
  584. return sog;
  585. if (sog.m_sittingAvatars.Count == 0)
  586. {
  587. entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, !isTeleport, true);
  588. return sog;
  589. }
  590. string reason = String.Empty;
  591. EntityTransferContext ctx = new EntityTransferContext();
  592. Vector3 curPos = root.GroupPosition;
  593. foreach (ScenePresence av in sog.m_sittingAvatars)
  594. {
  595. // We need to cross these agents. First, let's find
  596. // out if any of them can't cross for some reason.
  597. // We have to deny the crossing entirely if any
  598. // of them are banned. Alternatively, we could
  599. // unsit banned agents....
  600. // We set the avatar position as being the object
  601. // position to get the region to send to
  602. if(av.IsNPC)
  603. continue;
  604. if(av.IsInTransit)
  605. return sog;
  606. if(!entityTransfer.checkAgentAccessToRegion(av, destination, newpos, ctx, out reason))
  607. return sog;
  608. m_log.DebugFormat("[SCENE OBJECT]: Avatar {0} needs to be crossed to {1}", av.Name, destination.RegionName);
  609. }
  610. // We unparent the SP quietly so that it won't
  611. // be made to stand up
  612. List<avtocrossInfo> avsToCross = new List<avtocrossInfo>();
  613. List<ScenePresence> avsToCrossFar = new List<ScenePresence>();
  614. ulong destHandle = destination.RegionHandle;
  615. List<ScenePresence> sittingAvatars = GetSittingAvatars();
  616. foreach (ScenePresence av in sittingAvatars)
  617. {
  618. byte cflags = 1;
  619. avtocrossInfo avinfo = new avtocrossInfo();
  620. SceneObjectPart parentPart = sogScene.GetSceneObjectPart(av.ParentID);
  621. if (parentPart != null)
  622. {
  623. av.ParentUUID = parentPart.UUID;
  624. if(parentPart.SitTargetAvatar == av.UUID)
  625. cflags = 7; // low 3 bits set
  626. else
  627. cflags = 3;
  628. }
  629. if(!av.knowsNeighbourRegion(destHandle))
  630. cflags |= 8;
  631. // 1 is crossing
  632. // 2 is sitting
  633. // 4 is sitting at sittarget
  634. // 8 far crossing
  635. avinfo.av = av;
  636. avinfo.ParentID = av.ParentID;
  637. avsToCross.Add(avinfo);
  638. if(!av.knowsNeighbourRegion(destHandle))
  639. {
  640. cflags |= 8;
  641. avsToCrossFar.Add(av);
  642. }
  643. if(av.IsNPC)
  644. av.crossingFlags = 0;
  645. else
  646. av.crossingFlags = cflags;
  647. av.PrevSitOffset = av.OffsetPosition;
  648. av.ParentID = 0;
  649. }
  650. Vector3 vel = root.Velocity;
  651. Vector3 avel = root.AngularVelocity;
  652. Vector3 acc = root.Acceleration;
  653. Quaternion ori = root.RotationOffset;
  654. if(isTeleport)
  655. {
  656. root.Stop();
  657. sogScene.ForEachScenePresence(delegate(ScenePresence av)
  658. {
  659. av.ControllingClient.SendEntityUpdate(root,PrimUpdateFlags.SendInTransit);
  660. av.ControllingClient.SendEntityTerseUpdateImmediate(root);
  661. });
  662. root.Velocity = tpdata.vel;
  663. root.AngularVelocity = tpdata.avel;
  664. root.Acceleration = tpdata.acc;
  665. root.RotationOffset = tpdata.ori;
  666. }
  667. if (entityTransfer.CrossPrimGroupIntoNewRegion(destination, newpos, sog, true, false))
  668. {
  669. if(isTeleport)
  670. {
  671. sogScene.ForEachScenePresence(delegate(ScenePresence oav)
  672. {
  673. if(sittingAvatars.Contains(oav))
  674. return;
  675. if(oav.knowsNeighbourRegion(destHandle))
  676. return;
  677. oav.ControllingClient.SendEntityUpdate(root, PrimUpdateFlags.Kill);
  678. foreach (ScenePresence sav in sittingAvatars)
  679. {
  680. sav.SendKillTo(oav);
  681. }
  682. });
  683. }
  684. bool crossedfar = false;
  685. foreach (ScenePresence av in avsToCrossFar)
  686. {
  687. if(entityTransfer.CrossAgentCreateFarChild(av,destination, newpos, ctx))
  688. crossedfar = true;
  689. else
  690. av.crossingFlags = 0;
  691. }
  692. if(crossedfar)
  693. Thread.Sleep(1000);
  694. foreach (avtocrossInfo avinfo in avsToCross)
  695. {
  696. ScenePresence av = avinfo.av;
  697. av.IsInTransit = true;
  698. m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar {0} to {1}", av.Name, val);
  699. if(av.crossingFlags > 0)
  700. entityTransfer.CrossAgentToNewRegionAsync(av, newpos, destination, false, ctx);
  701. if (av.IsChildAgent)
  702. {
  703. // avatar crossed do some extra cleanup
  704. if (av.ParentUUID != UUID.Zero)
  705. {
  706. av.ClearControls();
  707. av.ParentPart = null;
  708. }
  709. av.ParentUUID = UUID.Zero;
  710. av.ParentPart = null;
  711. // In any case
  712. av.IsInTransit = false;
  713. av.crossingFlags = 0;
  714. m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", av.Firstname, av.Lastname);
  715. }
  716. else
  717. {
  718. // avatar cross failed we need do dedicated standUp
  719. // part of it was done at CrossAgentToNewRegionAsync
  720. // so for now just remove the sog controls
  721. // this may need extra care
  722. av.UnRegisterSeatControls(sog.UUID);
  723. av.ParentUUID = UUID.Zero;
  724. av.ParentPart = null;
  725. Vector3 oldp = curPos;
  726. oldp.X = Util.Clamp<float>(oldp.X, 0.5f, sog.m_scene.RegionInfo.RegionSizeX - 0.5f);
  727. oldp.Y = Util.Clamp<float>(oldp.Y, 0.5f, sog.m_scene.RegionInfo.RegionSizeY - 0.5f);
  728. av.AbsolutePosition = oldp;
  729. av.crossingFlags = 0;
  730. av.sitAnimation = "SIT";
  731. av.IsInTransit = false;
  732. if(av.Animator!= null)
  733. av.Animator.SetMovementAnimations("STAND");
  734. av.AddToPhysicalScene(false);
  735. sogScene.ForEachScenePresence(delegate(ScenePresence oav)
  736. {
  737. if(sittingAvatars.Contains(oav))
  738. return;
  739. if(oav.knowsNeighbourRegion(destHandle))
  740. av.SendAvatarDataToAgent(oav);
  741. else
  742. {
  743. av.SendAvatarDataToAgent(oav);
  744. av.SendAppearanceToAgent(oav);
  745. if (av.Animator != null)
  746. av.Animator.SendAnimPackToClient(oav.ControllingClient);
  747. av.SendAttachmentsToAgentNF(oav); // not ok
  748. }
  749. });
  750. m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} failed.", av.Firstname, av.Lastname);
  751. }
  752. }
  753. if(crossedfar)
  754. {
  755. Thread.Sleep(10000);
  756. foreach (ScenePresence av in avsToCrossFar)
  757. {
  758. if(av.IsChildAgent)
  759. {
  760. av.Scene.CloseAgent(av.UUID, false);
  761. }
  762. else
  763. av.RemoveNeighbourRegion(destHandle);
  764. }
  765. }
  766. avsToCrossFar.Clear();
  767. avsToCross.Clear();
  768. sog.RemoveScriptInstances(true);
  769. sog.Clear();
  770. return sog;
  771. }
  772. else
  773. {
  774. if(isTeleport)
  775. {
  776. if((tpdata.flags & OSTPOBJ_STOPONFAIL) == 0)
  777. {
  778. root.Velocity = vel;
  779. root.AngularVelocity = avel;
  780. root.Acceleration = acc;
  781. }
  782. root.RotationOffset = ori;
  783. }
  784. foreach (avtocrossInfo avinfo in avsToCross)
  785. {
  786. ScenePresence av = avinfo.av;
  787. av.ParentUUID = UUID.Zero;
  788. av.ParentID = avinfo.ParentID;
  789. av.crossingFlags = 0;
  790. }
  791. }
  792. avsToCross.Clear();
  793. return sog;
  794. }
  795. public void CrossAsyncCompleted(IAsyncResult iar)
  796. {
  797. SOGCrossDelegate icon = (SOGCrossDelegate)iar.AsyncState;
  798. SceneObjectGroup sog = icon.EndInvoke(iar);
  799. if (!sog.IsDeleted)
  800. {
  801. SceneObjectPart rootp = sog.m_rootPart;
  802. Vector3 oldp = rootp.GroupPosition;
  803. oldp.X = Util.Clamp<float>(oldp.X, 0.5f, sog.m_scene.RegionInfo.RegionSizeX - 0.5f);
  804. oldp.Y = Util.Clamp<float>(oldp.Y, 0.5f, sog.m_scene.RegionInfo.RegionSizeY - 0.5f);
  805. rootp.GroupPosition = oldp;
  806. rootp.Stop();
  807. SceneObjectPart[] parts = sog.m_parts.GetArray();
  808. foreach (SceneObjectPart part in parts)
  809. {
  810. if (part != rootp)
  811. part.GroupPosition = oldp;
  812. }
  813. foreach (ScenePresence av in sog.m_sittingAvatars)
  814. {
  815. av.sitSOGmoved();
  816. }
  817. if (sog.m_rootPart.KeyframeMotion != null)
  818. sog.m_rootPart.KeyframeMotion.CrossingFailure();
  819. if (sog.RootPart.PhysActor != null)
  820. sog.RootPart.PhysActor.CrossingFailure();
  821. sog.inTransit = false;
  822. AttachToBackup();
  823. sog.ScheduleGroupForFullUpdate();
  824. }
  825. }
  826. private class TeleportObjectData
  827. {
  828. public int flags;
  829. public Vector3 vel;
  830. public Vector3 avel;
  831. public Vector3 acc;
  832. public Quaternion ori;
  833. public UUID sourceID;
  834. }
  835. // copy from LSL_constants.cs
  836. const int OSTPOBJ_STOPATTARGET = 0x1; // stops at destination
  837. const int OSTPOBJ_STOPONFAIL = 0x2; // stops at start if tp fails
  838. const int OSTPOBJ_SETROT = 0x4; // the rotation is the final rotation, otherwise is a added rotation
  839. public int TeleportObject(UUID sourceID, Vector3 targetPosition, Quaternion rotation, int flags)
  840. {
  841. if(inTransit || IsDeleted || IsAttachmentCheckFull() || IsSelected || Scene == null)
  842. return -1;
  843. inTransit = true;
  844. PhysicsActor pa = RootPart.PhysActor;
  845. if(pa == null || RootPart.KeyframeMotion != null /*|| m_sittingAvatars.Count == 0*/)
  846. {
  847. inTransit = false;
  848. return -1;
  849. }
  850. bool stop = (flags & OSTPOBJ_STOPATTARGET) != 0;
  851. bool setrot = (flags & OSTPOBJ_SETROT) != 0;
  852. rotation.Normalize();
  853. Quaternion currentRot = RootPart.RotationOffset;
  854. if(setrot)
  855. rotation = Quaternion.Conjugate(currentRot) * rotation;
  856. bool dorot = setrot | (Math.Abs(rotation.W) < 0.99999);
  857. Vector3 vel = Vector3.Zero;
  858. Vector3 avel = Vector3.Zero;
  859. Vector3 acc = Vector3.Zero;
  860. if(!stop)
  861. {
  862. vel = RootPart.Velocity;
  863. avel = RootPart.AngularVelocity;
  864. acc = RootPart.Acceleration;
  865. }
  866. Quaternion ori = RootPart.RotationOffset;
  867. if(dorot)
  868. {
  869. if(!stop)
  870. {
  871. vel *= rotation;
  872. avel *= rotation;
  873. acc *= rotation;
  874. }
  875. ori *= rotation;
  876. }
  877. if(Scene.PositionIsInCurrentRegion(targetPosition))
  878. {
  879. if(Scene.InTeleportTargetsCoolDown(UUID, sourceID, 1.0))
  880. {
  881. inTransit = false;
  882. return -2;
  883. }
  884. Vector3 curPos = AbsolutePosition;
  885. ILandObject curLand = Scene.LandChannel.GetLandObject(curPos.X, curPos.Y);
  886. float posX = targetPosition.X;
  887. float posY = targetPosition.Y;
  888. ILandObject land = Scene.LandChannel.GetLandObject(posX, posY);
  889. if(land != null && land != curLand)
  890. {
  891. if(!Scene.Permissions.CanObjectEnterWithScripts(this, land))
  892. {
  893. inTransit = false;
  894. return -3;
  895. }
  896. UUID agentID;
  897. foreach (ScenePresence av in m_sittingAvatars)
  898. {
  899. agentID = av.UUID;
  900. if(land.IsRestrictedFromLand(agentID) || land.IsBannedFromLand(agentID))
  901. {
  902. inTransit = false;
  903. return -4;
  904. }
  905. }
  906. }
  907. RootPart.Velocity = vel;
  908. RootPart.AngularVelocity = avel;
  909. RootPart.Acceleration = acc;
  910. RootPart.RotationOffset = ori;
  911. Vector3 s = RootPart.Scale * RootPart.RotationOffset;
  912. float h = Scene.GetGroundHeight(posX, posY) + 0.5f * (float)Math.Abs(s.Z) + 0.01f;
  913. if(targetPosition.Z < h)
  914. targetPosition.Z = h;
  915. inTransit = false;
  916. AbsolutePosition = targetPosition;
  917. RootPart.ScheduleTerseUpdate();
  918. return 1;
  919. }
  920. if(Scene.InTeleportTargetsCoolDown(UUID, sourceID, 20.0))
  921. {
  922. inTransit = false;
  923. return -1;
  924. }
  925. TeleportObjectData tdata = new TeleportObjectData();
  926. tdata.flags = flags;
  927. tdata.vel = vel;
  928. tdata.avel = avel;
  929. tdata.acc = acc;
  930. tdata.ori = ori;
  931. tdata.sourceID = sourceID;
  932. SOGCrossDelegate d = CrossAsync;
  933. d.BeginInvoke(this, targetPosition, tdata, CrossAsyncCompleted, d);
  934. return 0;
  935. }
  936. public override Vector3 Velocity
  937. {
  938. get { return RootPart.Velocity; }
  939. set { RootPart.Velocity = value; }
  940. }
  941. public override uint LocalId
  942. {
  943. get { return m_rootPart.LocalId; }
  944. set { m_rootPart.LocalId = value; }
  945. }
  946. public override UUID UUID
  947. {
  948. get { return m_rootPart.UUID; }
  949. set
  950. {
  951. lock (m_parts.SyncRoot)
  952. {
  953. m_parts.Remove(m_rootPart.UUID);
  954. m_rootPart.UUID = value;
  955. m_parts.Add(value, m_rootPart);
  956. }
  957. }
  958. }
  959. public UUID LastOwnerID
  960. {
  961. get { return m_rootPart.LastOwnerID; }
  962. set { m_rootPart.LastOwnerID = value; }
  963. }
  964. public UUID RezzerID
  965. {
  966. get { return m_rootPart.RezzerID; }
  967. set { m_rootPart.RezzerID = value; }
  968. }
  969. public UUID OwnerID
  970. {
  971. get { return m_rootPart.OwnerID; }
  972. set { m_rootPart.OwnerID = value; }
  973. }
  974. public float Damage
  975. {
  976. get { return m_rootPart.Damage; }
  977. set { m_rootPart.Damage = value; }
  978. }
  979. public Color Color
  980. {
  981. get { return m_rootPart.Color; }
  982. set { m_rootPart.Color = value; }
  983. }
  984. public string Text
  985. {
  986. get {
  987. string returnstr = m_rootPart.Text;
  988. if (returnstr.Length > 255)
  989. {
  990. returnstr = returnstr.Substring(0, 255);
  991. }
  992. return returnstr;
  993. }
  994. set { m_rootPart.Text = value; }
  995. }
  996. /// <summary>
  997. /// If set to true then the scene object can be backed up in principle, though this will only actually occur
  998. /// if Backup is set. If false then the scene object will never be backed up, Backup will always be false.
  999. /// </summary>
  1000. protected virtual bool CanBeBackedUp
  1001. {
  1002. get { return true; }
  1003. }
  1004. public bool IsSelected
  1005. {
  1006. get { return m_isSelected; }
  1007. set
  1008. {
  1009. m_isSelected = value;
  1010. // Tell physics engine that group is selected
  1011. // this is not right
  1012. // but ode engines should only really need to know about root part
  1013. // so they can put entire object simulation on hold and not colliding
  1014. // keep as was for now
  1015. PhysicsActor pa = m_rootPart.PhysActor;
  1016. if (pa != null)
  1017. {
  1018. pa.Selected = value;
  1019. // Pass it on to the children.
  1020. SceneObjectPart[] parts = m_parts.GetArray();
  1021. for (int i = 0; i < parts.Length; i++)
  1022. {
  1023. SceneObjectPart child = parts[i];
  1024. PhysicsActor childPa = child.PhysActor;
  1025. if (childPa != null)
  1026. childPa.Selected = value;
  1027. }
  1028. }
  1029. if (RootPart.KeyframeMotion != null)
  1030. RootPart.KeyframeMotion.Selected = value;
  1031. }
  1032. }
  1033. public void PartSelectChanged(bool partSelect)
  1034. {
  1035. // any part selected makes group selected
  1036. if (m_isSelected == partSelect)
  1037. return;
  1038. if (partSelect)
  1039. {
  1040. IsSelected = partSelect;
  1041. // if (!IsAttachment)
  1042. // ScheduleGroupForFullUpdate();
  1043. }
  1044. else
  1045. {
  1046. // bad bad bad 2 heavy for large linksets
  1047. // since viewer does send lot of (un)selects
  1048. // this needs to be replaced by a specific list or count ?
  1049. // but that will require extra code in several places
  1050. SceneObjectPart[] parts = m_parts.GetArray();
  1051. for (int i = 0; i < parts.Length; i++)
  1052. {
  1053. SceneObjectPart part = parts[i];
  1054. if (part.IsSelected)
  1055. return;
  1056. }
  1057. IsSelected = partSelect;
  1058. // if (!IsAttachment)
  1059. // {
  1060. // ScheduleGroupForFullUpdate();
  1061. // }
  1062. }
  1063. }
  1064. // PlaySoundMasterPrim no longer in use to remove
  1065. private SceneObjectPart m_PlaySoundMasterPrim = null;
  1066. public SceneObjectPart PlaySoundMasterPrim
  1067. {
  1068. get { return m_PlaySoundMasterPrim; }
  1069. set { m_PlaySoundMasterPrim = value; }
  1070. }
  1071. // PlaySoundSlavePrims no longer in use to remove
  1072. private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
  1073. public List<SceneObjectPart> PlaySoundSlavePrims
  1074. {
  1075. get { return m_PlaySoundSlavePrims; }
  1076. set { m_PlaySoundSlavePrims = value; }
  1077. }
  1078. // LoopSoundMasterPrim no longer in use to remove
  1079. private SceneObjectPart m_LoopSoundMasterPrim = null;
  1080. public SceneObjectPart LoopSoundMasterPrim
  1081. {
  1082. get { return m_LoopSoundMasterPrim; }
  1083. set { m_LoopSoundMasterPrim = value; }
  1084. }
  1085. // m_LoopSoundSlavePrims no longer in use to remove
  1086. private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
  1087. public List<SceneObjectPart> LoopSoundSlavePrims
  1088. {
  1089. get { return m_LoopSoundSlavePrims; }
  1090. set { m_LoopSoundSlavePrims = value; }
  1091. }
  1092. /// <summary>
  1093. /// The UUID for the region this object is in.
  1094. /// </summary>
  1095. public UUID RegionUUID
  1096. {
  1097. get
  1098. {
  1099. if (m_scene != null)
  1100. {
  1101. return m_scene.RegionInfo.RegionID;
  1102. }
  1103. return UUID.Zero;
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// The item ID that this object was rezzed from, if applicable.
  1108. /// </summary>
  1109. /// <remarks>
  1110. /// If not applicable will be UUID.Zero
  1111. /// </remarks>
  1112. public UUID FromItemID { get; set; }
  1113. /// <summary>
  1114. /// Refers to the SceneObjectPart.UUID property of the object that this object was rezzed from, if applicable.
  1115. /// </summary>
  1116. /// <remarks>
  1117. /// If not applicable will be UUID.Zero
  1118. /// </remarks>
  1119. /// obsolete use RezzerID
  1120. public UUID FromPartID
  1121. {
  1122. get { return RezzerID; }
  1123. set {RezzerID = value; }
  1124. }
  1125. /// <summary>
  1126. /// The folder ID that this object was rezzed from, if applicable.
  1127. /// </summary>
  1128. /// <remarks>
  1129. /// If not applicable will be UUID.Zero
  1130. /// </remarks>
  1131. public UUID FromFolderID { get; set; }
  1132. /// <summary>
  1133. /// If true then grabs are blocked no matter what the individual part BlockGrab setting.
  1134. /// </summary>
  1135. /// <value><c>true</c> if block grab override; otherwise, <c>false</c>.</value>
  1136. public bool BlockGrabOverride { get; set; }
  1137. /// <summary>
  1138. /// IDs of all avatars sat on this scene object.
  1139. /// </summary>
  1140. /// <remarks>
  1141. /// We need this so that we can maintain a linkset wide ordering of avatars sat on different parts.
  1142. /// This must be locked before it is read or written.
  1143. /// SceneObjectPart sitting avatar add/remove code also locks on this object to avoid race conditions.
  1144. /// No avatar should appear more than once in this list.
  1145. /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart.
  1146. /// </remarks>
  1147. protected internal List<ScenePresence> m_sittingAvatars = new List<ScenePresence>();
  1148. #endregion
  1149. // ~SceneObjectGroup()
  1150. // {
  1151. // //m_log.DebugFormat("[SCENE OBJECT GROUP]: Destructor called for {0}, local id {1}", Name, LocalId);
  1152. // Console.WriteLine("Destructor called for {0}, local id {1}", Name, LocalId);
  1153. // }
  1154. #region Constructors
  1155. /// <summary>
  1156. /// Constructor
  1157. /// </summary>
  1158. public SceneObjectGroup()
  1159. {
  1160. }
  1161. /// <summary>
  1162. /// This constructor creates a SceneObjectGroup using a pre-existing SceneObjectPart.
  1163. /// The original SceneObjectPart will be used rather than a copy, preserving
  1164. /// its existing localID and UUID.
  1165. /// </summary>
  1166. /// <param name='part'>Root part for this scene object.</param>
  1167. public SceneObjectGroup(SceneObjectPart part) : this()
  1168. {
  1169. SetRootPart(part);
  1170. }
  1171. /// <summary>
  1172. /// Constructor. This object is added to the scene later via AttachToScene()
  1173. /// </summary>
  1174. public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
  1175. {
  1176. SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
  1177. }
  1178. /// <summary>
  1179. /// Constructor.
  1180. /// </summary>
  1181. public SceneObjectGroup(UUID ownerID, Vector3 pos, PrimitiveBaseShape shape)
  1182. : this(ownerID, pos, Quaternion.Identity, shape)
  1183. {
  1184. }
  1185. public void LoadScriptState(XmlDocument doc)
  1186. {
  1187. XmlNodeList nodes = doc.GetElementsByTagName("SavedScriptState");
  1188. if (nodes.Count > 0)
  1189. {
  1190. if (m_savedScriptState == null)
  1191. m_savedScriptState = new Dictionary<UUID, string>();
  1192. foreach (XmlNode node in nodes)
  1193. {
  1194. if (node.Attributes["UUID"] != null)
  1195. {
  1196. UUID itemid = new UUID(node.Attributes["UUID"].Value);
  1197. if (itemid != UUID.Zero)
  1198. m_savedScriptState[itemid] = node.InnerXml;
  1199. }
  1200. }
  1201. }
  1202. }
  1203. public void LoadScriptState(XmlReader reader)
  1204. {
  1205. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Looking for script state for {0}", Name);
  1206. while (true)
  1207. {
  1208. if (reader.Name == "SavedScriptState" && reader.NodeType == XmlNodeType.Element)
  1209. {
  1210. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Loading script state for {0}", Name);
  1211. if (m_savedScriptState == null)
  1212. m_savedScriptState = new Dictionary<UUID, string>();
  1213. string uuid = reader.GetAttribute("UUID");
  1214. // Even if there is no UUID attribute for some strange reason, we must always read the inner XML
  1215. // so we don't continually keep checking the same SavedScriptedState element.
  1216. string innerXml = reader.ReadInnerXml();
  1217. if (uuid != null)
  1218. {
  1219. // m_log.DebugFormat("[SCENE OBJECT GROUP]: Found state for item ID {0} in object {1}", uuid, Name);
  1220. UUID itemid = new UUID(uuid);
  1221. if (itemid != UUID.Zero)
  1222. m_savedScriptState[itemid] = innerXml;
  1223. }
  1224. else
  1225. {
  1226. m_log.WarnFormat("[SCENE OBJECT GROUP]: SavedScriptState element had no UUID in object {0} id: {1}", Name,UUID);
  1227. }
  1228. }
  1229. else
  1230. {
  1231. if (!reader.Read())
  1232. break;
  1233. }
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// Hooks this object up to the backup event so that it is persisted to the database when the update thread executes.
  1238. /// </summary>
  1239. public virtual void AttachToBackup()
  1240. {
  1241. if (IsAttachment) return;
  1242. m_scene.SceneGraph.FireAttachToBackup(this);
  1243. // if (InSceneBackup)
  1244. {
  1245. // m_log.DebugFormat(
  1246. // "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID);
  1247. if (!Backup)
  1248. m_scene.EventManager.OnBackup += ProcessBackup;
  1249. Backup = true;
  1250. }
  1251. }
  1252. /// <summary>
  1253. /// Attach this object to a scene. It will also now appear to agents.
  1254. /// </summary>
  1255. /// <param name="scene"></param>
  1256. public void AttachToScene(Scene scene)
  1257. {
  1258. m_scene = scene;
  1259. RegionHandle = m_scene.RegionInfo.RegionHandle;
  1260. if (m_rootPart.Shape.PCode != 9 || m_rootPart.Shape.State == 0)
  1261. m_rootPart.ParentID = 0;
  1262. if (m_rootPart.LocalId == 0)
  1263. m_rootPart.LocalId = m_scene.AllocateLocalId();
  1264. SceneObjectPart[] parts = m_parts.GetArray();
  1265. for (int i = 0; i < parts.Length; i++)
  1266. {
  1267. SceneObjectPart part = parts[i];
  1268. if (part.KeyframeMotion != null)
  1269. {
  1270. part.KeyframeMotion.UpdateSceneObject(this);
  1271. }
  1272. if (Object.ReferenceEquals(part, m_rootPart))
  1273. continue;
  1274. if (part.LocalId == 0)
  1275. part.LocalId = m_scene.AllocateLocalId();
  1276. part.ParentID = m_rootPart.LocalId;
  1277. //m_log.DebugFormat("[SCENE]: Given local id {0} to part {1}, linknum {2}, parent {3} {4}", part.LocalId, part.UUID, part.LinkNum, part.ParentID, part.ParentUUID);
  1278. }
  1279. ApplyPhysics();
  1280. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  1281. // for the same object with very different properties. The caller must schedule the update.
  1282. //ScheduleGroupForFullUpdate();
  1283. }
  1284. public EntityIntersection TestIntersection(Ray hRay, bool frontFacesOnly, bool faceCenters)
  1285. {
  1286. // We got a request from the inner_scene to raytrace along the Ray hRay
  1287. // We're going to check all of the prim in this group for intersection with the ray
  1288. // If we get a result, we're going to find the closest result to the origin of the ray
  1289. // and send back the intersection information back to the innerscene.
  1290. EntityIntersection result = new EntityIntersection();
  1291. SceneObjectPart[] parts = m_parts.GetArray();
  1292. // Find closest hit here
  1293. float idist = float.MaxValue;
  1294. for (int i = 0; i < parts.Length; i++)
  1295. {
  1296. SceneObjectPart part = parts[i];
  1297. // Temporary commented to stop compiler warning
  1298. //Vector3 partPosition =
  1299. // new Vector3(part.AbsolutePosition.X, part.AbsolutePosition.Y, part.AbsolutePosition.Z);
  1300. Quaternion parentrotation = GroupRotation;
  1301. // Telling the prim to raytrace.
  1302. //EntityIntersection inter = part.TestIntersection(hRay, parentrotation);
  1303. EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
  1304. if (inter.HitTF)
  1305. {
  1306. // We need to find the closest prim to return to the testcaller along the ray
  1307. if (inter.distance < idist)
  1308. {
  1309. result.HitTF = true;
  1310. result.ipoint = inter.ipoint;
  1311. result.obj = part;
  1312. result.normal = inter.normal;
  1313. result.distance = inter.distance;
  1314. idist = inter.distance;
  1315. }
  1316. }
  1317. }
  1318. return result;
  1319. }
  1320. /// <summary>
  1321. /// Gets a vector representing the size of the bounding box containing all the prims in the group
  1322. /// Treats all prims as rectangular, so no shape (cut etc) is taken into account
  1323. /// offsetHeight is the offset in the Z axis from the centre of the bounding box to the centre of the root prim
  1324. /// </summary>
  1325. /// <returns></returns>
  1326. public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ)
  1327. {
  1328. maxX = float.MinValue;
  1329. maxY = float.MinValue;
  1330. maxZ = float.MinValue;
  1331. minX = float.MaxValue;
  1332. minY = float.MaxValue;
  1333. minZ = float.MaxValue;
  1334. SceneObjectPart[] parts = m_parts.GetArray();
  1335. foreach (SceneObjectPart part in parts)
  1336. {
  1337. Vector3 worldPos = part.GetWorldPosition();
  1338. Vector3 offset = worldPos - AbsolutePosition;
  1339. Quaternion worldRot;
  1340. if (part.ParentID == 0)
  1341. {
  1342. worldRot = part.RotationOffset;
  1343. }
  1344. else
  1345. {
  1346. worldRot = part.GetWorldRotation();
  1347. }
  1348. Vector3 frontTopLeft;
  1349. Vector3 frontTopRight;
  1350. Vector3 frontBottomLeft;
  1351. Vector3 frontBottomRight;
  1352. Vector3 backTopLeft;
  1353. Vector3 backTopRight;
  1354. Vector3 backBottomLeft;
  1355. Vector3 backBottomRight;
  1356. // Vector3[] corners = new Vector3[8];
  1357. Vector3 orig = Vector3.Zero;
  1358. frontTopLeft.X = orig.X - (part.Scale.X / 2);
  1359. frontTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  1360. frontTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  1361. frontTopRight.X = orig.X - (part.Scale.X / 2);
  1362. frontTopRight.Y = orig.Y + (part.Scale.Y / 2);
  1363. frontTopRight.Z = orig.Z + (part.Scale.Z / 2);
  1364. frontBottomLeft.X = orig.X - (part.Scale.X / 2);
  1365. frontBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  1366. frontBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  1367. frontBottomRight.X = orig.X - (part.Scale.X / 2);
  1368. frontBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  1369. frontBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  1370. backTopLeft.X = orig.X + (part.Scale.X / 2);
  1371. backTopLeft.Y = orig.Y - (part.Scale.Y / 2);
  1372. backTopLeft.Z = orig.Z + (part.Scale.Z / 2);
  1373. backTopRight.X = orig.X + (part.Scale.X / 2);
  1374. backTopRight.Y = orig.Y + (part.Scale.Y / 2);
  1375. backTopRight.Z = orig.Z + (part.Scale.Z / 2);
  1376. backBottomLeft.X = orig.X + (part.Scale.X / 2);
  1377. backBottomLeft.Y = orig.Y - (part.Scale.Y / 2);
  1378. backBottomLeft.Z = orig.Z - (part.Scale.Z / 2);
  1379. backBottomRight.X = orig.X + (part.Scale.X / 2);
  1380. backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
  1381. backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
  1382. //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
  1383. //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
  1384. //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
  1385. //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
  1386. //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
  1387. //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
  1388. //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
  1389. //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
  1390. //for (int i = 0; i < 8; i++)
  1391. //{
  1392. // corners[i] = corners[i] * worldRot;
  1393. // corners[i] += offset;
  1394. // if (corners[i].X > maxX)
  1395. // maxX = corners[i].X;
  1396. // if (corners[i].X < minX)
  1397. // minX = corners[i].X;
  1398. // if (corners[i].Y > maxY)
  1399. // maxY = corners[i].Y;
  1400. // if (corners[i].Y < minY)
  1401. // minY = corners[i].Y;
  1402. // if (corners[i].Z > maxZ)
  1403. // maxZ = corners[i].Y;
  1404. // if (corners[i].Z < minZ)
  1405. // minZ = corners[i].Z;
  1406. //}
  1407. frontTopLeft = frontTopLeft * worldRot;
  1408. frontTopRight = frontTopRight * worldRot;
  1409. frontBottomLeft = frontBottomLeft * worldRot;
  1410. frontBottomRight = frontBottomRight * worldRot;
  1411. backBottomLeft = backBottomLeft * worldRot;
  1412. backBottomRight = backBottomRight * worldRot;
  1413. backTopLeft = backTopLeft * worldRot;
  1414. backTopRight = backTopRight * worldRot;
  1415. frontTopLeft += offset;
  1416. frontTopRight += offset;
  1417. frontBottomLeft += offset;
  1418. frontBottomRight += offset;
  1419. backBottomLeft += offset;
  1420. backBottomRight += offset;
  1421. backTopLeft += offset;
  1422. backTopRight += offset;
  1423. //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
  1424. //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
  1425. //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
  1426. //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
  1427. //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
  1428. //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
  1429. //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
  1430. //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
  1431. if (frontTopRight.X > maxX)
  1432. maxX = frontTopRight.X;
  1433. if (frontTopLeft.X > maxX)
  1434. maxX = frontTopLeft.X;
  1435. if (frontBottomRight.X > maxX)
  1436. maxX = frontBottomRight.X;
  1437. if (frontBottomLeft.X > maxX)
  1438. maxX = frontBottomLeft.X;
  1439. if (backTopRight.X > maxX)
  1440. maxX = backTopRight.X;
  1441. if (backTopLeft.X > maxX)
  1442. maxX = backTopLeft.X;
  1443. if (backBottomRight.X > maxX)
  1444. maxX = backBottomRight.X;
  1445. if (backBottomLeft.X > maxX)
  1446. maxX = backBottomLeft.X;
  1447. if (frontTopRight.X < minX)
  1448. minX = frontTopRight.X;
  1449. if (frontTopLeft.X < minX)
  1450. minX = frontTopLeft.X;
  1451. if (frontBottomRight.X < minX)
  1452. minX = frontBottomRight.X;
  1453. if (frontBottomLeft.X < minX)
  1454. minX = frontBottomLeft.X;
  1455. if (backTopRight.X < minX)
  1456. minX = backTopRight.X;
  1457. if (backTopLeft.X < minX)
  1458. minX = backTopLeft.X;
  1459. if (backBottomRight.X < minX)
  1460. minX = backBottomRight.X;
  1461. if (backBottomLeft.X < minX)
  1462. minX = backBottomLeft.X;
  1463. //
  1464. if (frontTopRight.Y > maxY)
  1465. maxY = frontTopRight.Y;
  1466. if (frontTopLeft.Y > maxY)
  1467. maxY = frontTopLeft.Y;
  1468. if (frontBottomRight.Y > maxY)
  1469. maxY = frontBottomRight.Y;
  1470. if (frontBottomLeft.Y > maxY)
  1471. maxY = frontBottomLeft.Y;
  1472. if (backTopRight.Y > maxY)
  1473. maxY = backTopRight.Y;
  1474. if (backTopLeft.Y > maxY)
  1475. maxY = backTopLeft.Y;
  1476. if (backBottomRight.Y > maxY)
  1477. maxY = backBottomRight.Y;
  1478. if (backBottomLeft.Y > maxY)
  1479. maxY = backBottomLeft.Y;
  1480. if (frontTopRight.Y < minY)
  1481. minY = frontTopRight.Y;
  1482. if (frontTopLeft.Y < minY)
  1483. minY = frontTopLeft.Y;
  1484. if (frontBottomRight.Y < minY)
  1485. minY = frontBottomRight.Y;
  1486. if (frontBottomLeft.Y < minY)
  1487. minY = frontBottomLeft.Y;
  1488. if (backTopRight.Y < minY)
  1489. minY = backTopRight.Y;
  1490. if (backTopLeft.Y < minY)
  1491. minY = backTopLeft.Y;
  1492. if (backBottomRight.Y < minY)
  1493. minY = backBottomRight.Y;
  1494. if (backBottomLeft.Y < minY)
  1495. minY = backBottomLeft.Y;
  1496. //
  1497. if (frontTopRight.Z > maxZ)
  1498. maxZ = frontTopRight.Z;
  1499. if (frontTopLeft.Z > maxZ)
  1500. maxZ = frontTopLeft.Z;
  1501. if (frontBottomRight.Z > maxZ)
  1502. maxZ = frontBottomRight.Z;
  1503. if (frontBottomLeft.Z > maxZ)
  1504. maxZ = frontBottomLeft.Z;
  1505. if (backTopRight.Z > maxZ)
  1506. maxZ = backTopRight.Z;
  1507. if (backTopLeft.Z > maxZ)
  1508. maxZ = backTopLeft.Z;
  1509. if (backBottomRight.Z > maxZ)
  1510. maxZ = backBottomRight.Z;
  1511. if (backBottomLeft.Z > maxZ)
  1512. maxZ = backBottomLeft.Z;
  1513. if (frontTopRight.Z < minZ)
  1514. minZ = frontTopRight.Z;
  1515. if (frontTopLeft.Z < minZ)
  1516. minZ = frontTopLeft.Z;
  1517. if (frontBottomRight.Z < minZ)
  1518. minZ = frontBottomRight.Z;
  1519. if (frontBottomLeft.Z < minZ)
  1520. minZ = frontBottomLeft.Z;
  1521. if (backTopRight.Z < minZ)
  1522. minZ = backTopRight.Z;
  1523. if (backTopLeft.Z < minZ)
  1524. minZ = backTopLeft.Z;
  1525. if (backBottomRight.Z < minZ)
  1526. minZ = backBottomRight.Z;
  1527. if (backBottomLeft.Z < minZ)
  1528. minZ = backBottomLeft.Z;
  1529. }
  1530. }
  1531. public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight)
  1532. {
  1533. float minX;
  1534. float maxX;
  1535. float minY;
  1536. float maxY;
  1537. float minZ;
  1538. float maxZ;
  1539. GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ);
  1540. Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ);
  1541. offsetHeight = 0;
  1542. float lower = (minZ * -1);
  1543. if (lower > maxZ)
  1544. {
  1545. offsetHeight = lower - (boundingBox.Z / 2);
  1546. }
  1547. else if (maxZ > lower)
  1548. {
  1549. offsetHeight = maxZ - (boundingBox.Z / 2);
  1550. offsetHeight *= -1;
  1551. }
  1552. // m_log.InfoFormat("BoundingBox is {0} , {1} , {2} ", boundingBox.X, boundingBox.Y, boundingBox.Z);
  1553. return boundingBox;
  1554. }
  1555. #endregion
  1556. private float? m_boundsRadius = null;
  1557. public void InvalidBoundsRadius()
  1558. {
  1559. m_boundsRadius = null;
  1560. }
  1561. private Vector3 m_boundsCenter;
  1562. public Vector3 getBoundsCenter()
  1563. {
  1564. // math is done in GetBoundsRadius();
  1565. if(m_boundsRadius == null)
  1566. GetBoundsRadius();
  1567. return m_boundsCenter;
  1568. }
  1569. private float m_areaFactor;
  1570. public float getAreaFactor()
  1571. {
  1572. // math is done in GetBoundsRadius();
  1573. if(m_boundsRadius == null)
  1574. GetBoundsRadius();
  1575. return m_areaFactor;
  1576. }
  1577. public float GetBoundsRadius()
  1578. {
  1579. // this may need more threading work
  1580. if(m_boundsRadius == null)
  1581. {
  1582. float res = 0;
  1583. float areaF = 0;
  1584. SceneObjectPart p;
  1585. SceneObjectPart[] parts;
  1586. float partR;
  1587. Vector3 offset = Vector3.Zero;
  1588. lock (m_parts)
  1589. {
  1590. parts = m_parts.GetArray();
  1591. }
  1592. int nparts = parts.Length;
  1593. for (int i = 0; i < nparts; i++)
  1594. {
  1595. p = parts[i];
  1596. partR = 0.5f * p.Scale.Length();
  1597. if(p != RootPart)
  1598. {
  1599. partR += p.OffsetPosition.Length();
  1600. offset += p.OffsetPosition;
  1601. }
  1602. if(partR > res)
  1603. res = partR;
  1604. if(p.maxSimpleArea() > areaF)
  1605. areaF = p.maxSimpleArea();
  1606. }
  1607. if(parts.Length > 1)
  1608. {
  1609. offset /= parts.Length; // basicly geometric center
  1610. offset = offset * RootPart.RotationOffset;
  1611. }
  1612. areaF = 10.0f / areaF; // scale it
  1613. areaF = Util.Clamp(areaF, 0.001f, 1000f); // clamp it
  1614. m_areaFactor = (float)Math.Sqrt(areaF);
  1615. m_boundsCenter = offset;
  1616. m_boundsRadius = res;
  1617. return res;
  1618. }
  1619. return m_boundsRadius.Value;
  1620. }
  1621. public void GetResourcesCosts(SceneObjectPart apart,
  1622. out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost)
  1623. {
  1624. // this information may need to be cached
  1625. float cost;
  1626. float tmpcost;
  1627. bool ComplexCost = false;
  1628. SceneObjectPart p;
  1629. SceneObjectPart[] parts;
  1630. lock (m_parts)
  1631. {
  1632. parts = m_parts.GetArray();
  1633. }
  1634. int nparts = parts.Length;
  1635. for (int i = 0; i < nparts; i++)
  1636. {
  1637. p = parts[i];
  1638. if (p.UsesComplexCost)
  1639. {
  1640. ComplexCost = true;
  1641. break;
  1642. }
  1643. }
  1644. if (ComplexCost)
  1645. {
  1646. linksetResCost = 0;
  1647. linksetPhysCost = 0;
  1648. partCost = 0;
  1649. partPhysCost = 0;
  1650. for (int i = 0; i < nparts; i++)
  1651. {
  1652. p = parts[i];
  1653. cost = p.StreamingCost;
  1654. tmpcost = p.SimulationCost;
  1655. if (tmpcost > cost)
  1656. cost = tmpcost;
  1657. tmpcost = p.PhysicsCost;
  1658. if (tmpcost > cost)
  1659. cost = tmpcost;
  1660. linksetPhysCost += tmpcost;
  1661. linksetResCost += cost;
  1662. if (p == apart)
  1663. {
  1664. partCost = cost;
  1665. partPhysCost = tmpcost;
  1666. }
  1667. }
  1668. }
  1669. else
  1670. {
  1671. partPhysCost = 1.0f;
  1672. partCost = 1.0f;
  1673. linksetResCost = (float)nparts;
  1674. linksetPhysCost = linksetResCost;
  1675. }
  1676. }
  1677. public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost)
  1678. {
  1679. SceneObjectPart p;
  1680. SceneObjectPart[] parts;
  1681. lock (m_parts)
  1682. {
  1683. parts = m_parts.GetArray();
  1684. }
  1685. int nparts = parts.Length;
  1686. PhysCost = 0;
  1687. StreamCost = 0;
  1688. SimulCost = 0;
  1689. for (int i = 0; i < nparts; i++)
  1690. {
  1691. p = parts[i];
  1692. StreamCost += p.StreamingCost;
  1693. SimulCost += p.SimulationCost;
  1694. PhysCost += p.PhysicsCost;
  1695. }
  1696. }
  1697. public void SaveScriptedState(XmlTextWriter writer)
  1698. {
  1699. SaveScriptedState(writer, false);
  1700. }
  1701. public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
  1702. {
  1703. XmlDocument doc = new XmlDocument();
  1704. Dictionary<UUID,string> states = new Dictionary<UUID,string>();
  1705. SceneObjectPart[] parts = m_parts.GetArray();
  1706. for (int i = 0; i < parts.Length; i++)
  1707. {
  1708. Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
  1709. foreach (KeyValuePair<UUID, string> kvp in pstates)
  1710. states[kvp.Key] = kvp.Value;
  1711. }
  1712. if (states.Count > 0)
  1713. {
  1714. // Now generate the necessary XML wrappings
  1715. writer.WriteStartElement(String.Empty, "GroupScriptStates", String.Empty);
  1716. foreach (UUID itemid in states.Keys)
  1717. {
  1718. doc.LoadXml(states[itemid]);
  1719. writer.WriteStartElement(String.Empty, "SavedScriptState", String.Empty);
  1720. writer.WriteAttributeString(String.Empty, "UUID", String.Empty, itemid.ToString());
  1721. writer.WriteRaw(doc.DocumentElement.OuterXml); // Writes ScriptState element
  1722. writer.WriteEndElement(); // End of SavedScriptState
  1723. }
  1724. writer.WriteEndElement(); // End of GroupScriptStates
  1725. }
  1726. }
  1727. public byte GetAttachmentPoint()
  1728. {
  1729. return m_rootPart.Shape.State;
  1730. }
  1731. public void DetachToGround()
  1732. {
  1733. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1734. if (avatar == null)
  1735. return;
  1736. m_rootPart.Shape.LastAttachPoint = m_rootPart.Shape.State;
  1737. m_rootPart.AttachedPos = m_rootPart.OffsetPosition;
  1738. avatar.RemoveAttachment(this);
  1739. Vector3 detachedpos = new Vector3(127f,127f,127f);
  1740. if (avatar == null)
  1741. return;
  1742. detachedpos = avatar.AbsolutePosition;
  1743. FromItemID = UUID.Zero;
  1744. AbsolutePosition = detachedpos;
  1745. AttachedAvatar = UUID.Zero;
  1746. //SceneObjectPart[] parts = m_parts.GetArray();
  1747. //for (int i = 0; i < parts.Length; i++)
  1748. // parts[i].AttachedAvatar = UUID.Zero;
  1749. m_rootPart.SetParentLocalId(0);
  1750. AttachmentPoint = (byte)0;
  1751. // must check if buildind should be true or false here
  1752. // m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false);
  1753. ApplyPhysics();
  1754. HasGroupChanged = true;
  1755. RootPart.Rezzed = DateTime.Now;
  1756. RootPart.RemFlag(PrimFlags.TemporaryOnRez);
  1757. AttachToBackup();
  1758. m_scene.EventManager.TriggerParcelPrimCountTainted();
  1759. m_rootPart.ScheduleFullUpdate();
  1760. m_rootPart.ClearUndoState();
  1761. }
  1762. public void DetachToInventoryPrep()
  1763. {
  1764. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  1765. //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
  1766. if (avatar != null)
  1767. {
  1768. //detachedpos = avatar.AbsolutePosition;
  1769. avatar.RemoveAttachment(this);
  1770. }
  1771. AttachedAvatar = UUID.Zero;
  1772. /*SceneObjectPart[] parts = m_parts.GetArray();
  1773. for (int i = 0; i < parts.Length; i++)
  1774. parts[i].AttachedAvatar = UUID.Zero;*/
  1775. m_rootPart.SetParentLocalId(0);
  1776. //m_rootPart.SetAttachmentPoint((byte)0);
  1777. IsAttachment = false;
  1778. AbsolutePosition = m_rootPart.AttachedPos;
  1779. //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
  1780. //AttachToBackup();
  1781. //m_rootPart.ScheduleFullUpdate();
  1782. }
  1783. /// <summary>
  1784. ///
  1785. /// </summary>
  1786. /// <param name="part"></param>
  1787. private void SetPartAsNonRoot(SceneObjectPart part)
  1788. {
  1789. part.ParentID = m_rootPart.LocalId;
  1790. part.ClearUndoState();
  1791. }
  1792. public ushort GetTimeDilation()
  1793. {
  1794. return Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f);
  1795. }
  1796. /// <summary>
  1797. /// Set a part to act as the root part for this scene object
  1798. /// </summary>
  1799. /// <param name="part"></param>
  1800. public void SetRootPart(SceneObjectPart part)
  1801. {
  1802. if (part == null)
  1803. throw new ArgumentNullException("Cannot give SceneObjectGroup a null root SceneObjectPart");
  1804. part.SetParent(this);
  1805. m_rootPart = part;
  1806. if (!IsAttachment)
  1807. part.ParentID = 0;
  1808. part.LinkNum = 0;
  1809. m_parts.Add(m_rootPart.UUID, m_rootPart);
  1810. }
  1811. /// <summary>
  1812. /// Add a new part to this scene object. The part must already be correctly configured.
  1813. /// </summary>
  1814. /// <param name="part"></param>
  1815. public void AddPart(SceneObjectPart part)
  1816. {
  1817. part.SetParent(this);
  1818. m_parts.Add(part.UUID, part);
  1819. part.LinkNum = m_parts.Count;
  1820. if (part.LinkNum == 2)
  1821. RootPart.LinkNum = 1;
  1822. InvalidatePartsLinkMaps();
  1823. }
  1824. /// <summary>
  1825. /// Make sure that every non root part has the proper parent root part local id
  1826. /// </summary>
  1827. private void UpdateParentIDs()
  1828. {
  1829. SceneObjectPart[] parts = m_parts.GetArray();
  1830. for (int i = 0; i < parts.Length; i++)
  1831. {
  1832. SceneObjectPart part = parts[i];
  1833. if (part.UUID != m_rootPart.UUID)
  1834. part.ParentID = m_rootPart.LocalId;
  1835. }
  1836. }
  1837. public void RegenerateFullIDs()
  1838. {
  1839. SceneObjectPart[] parts = m_parts.GetArray();
  1840. for (int i = 0; i < parts.Length; i++)
  1841. parts[i].UUID = UUID.Random();
  1842. }
  1843. // helper provided for parts.
  1844. public int GetSceneMaxUndo()
  1845. {
  1846. if (m_scene != null)
  1847. return m_scene.MaxUndoCount;
  1848. return 5;
  1849. }
  1850. // justincc: I don't believe this hack is needed any longer, especially since the physics
  1851. // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false
  1852. // this method was preventing proper reload of scene objects.
  1853. // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects
  1854. // at region startup
  1855. // teravus: After this was removed from the linking algorithm, Linked prims no longer collided
  1856. // properly when non-physical if they havn't been moved. This breaks ALL builds.
  1857. // see: http://opensimulator.org/mantis/view.php?id=3108
  1858. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  1859. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  1860. // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute
  1861. // Position has been set!
  1862. public void ResetChildPrimPhysicsPositions()
  1863. {
  1864. // Setting this SOG's absolute position also loops through and sets the positions
  1865. // of the SOP's in this SOG's linkset. This has the side affect of making sure
  1866. // the physics world matches the simulated world.
  1867. // AbsolutePosition = AbsolutePosition; // could someone in the know please explain how this works?
  1868. // teravus: AbsolutePosition is NOT a normal property!
  1869. // the code in the getter of AbsolutePosition is significantly different then the code in the setter!
  1870. // jhurliman: Then why is it a property instead of two methods?
  1871. // do only what is supposed to do
  1872. Vector3 groupPosition = m_rootPart.GroupPosition;
  1873. SceneObjectPart[] parts = m_parts.GetArray();
  1874. foreach (SceneObjectPart part in parts)
  1875. {
  1876. if (part != m_rootPart)
  1877. part.GroupPosition = groupPosition;
  1878. }
  1879. }
  1880. public UUID GetPartsFullID(uint localID)
  1881. {
  1882. SceneObjectPart part = GetPart(localID);
  1883. if (part != null)
  1884. {
  1885. return part.UUID;
  1886. }
  1887. return UUID.Zero;
  1888. }
  1889. public void ObjectGrabHandler(uint localId, Vector3 offsetPos, IClientAPI remoteClient)
  1890. {
  1891. if (m_rootPart.LocalId == localId)
  1892. {
  1893. OnGrabGroup(offsetPos, remoteClient);
  1894. }
  1895. else
  1896. {
  1897. SceneObjectPart part = GetPart(localId);
  1898. OnGrabPart(part, offsetPos, remoteClient);
  1899. }
  1900. }
  1901. public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient)
  1902. {
  1903. // m_log.DebugFormat(
  1904. // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}",
  1905. // remoteClient.Name, part.Name, part.LocalId, offsetPos);
  1906. // part.StoreUndoState();
  1907. part.OnGrab(offsetPos, remoteClient);
  1908. }
  1909. public virtual void OnGrabGroup(Vector3 offsetPos, IClientAPI remoteClient)
  1910. {
  1911. m_scene.EventManager.TriggerGroupGrab(UUID, offsetPos, remoteClient.AgentId);
  1912. }
  1913. /// <summary>
  1914. /// Delete this group from its scene.
  1915. /// </summary>
  1916. /// <remarks>
  1917. /// This only handles the in-world consequences of deletion (e.g. any avatars sitting on it are forcibly stood
  1918. /// up and all avatars receive notification of its removal. Removal of the scene object from database backup
  1919. /// must be handled by the caller.
  1920. /// </remarks>
  1921. /// <param name="silent">If true then deletion is not broadcast to clients</param>
  1922. public void DeleteGroupFromScene(bool silent)
  1923. {
  1924. // We need to keep track of this state in case this group is still queued for backup.
  1925. IsDeleted = true;
  1926. DetachFromBackup();
  1927. if(Scene == null) // should not happen unless restart/shutdown ?
  1928. return;
  1929. SceneObjectPart[] parts = m_parts.GetArray();
  1930. for (int i = 0; i < parts.Length; i++)
  1931. {
  1932. SceneObjectPart part = parts[i];
  1933. Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1934. {
  1935. if (!avatar.IsChildAgent && avatar.ParentID == part.LocalId && avatar.ParentUUID == UUID.Zero)
  1936. avatar.StandUp();
  1937. if (!silent)
  1938. {
  1939. part.ClearUpdateSchedule();
  1940. if (part == m_rootPart)
  1941. {
  1942. if (!IsAttachment
  1943. || AttachedAvatar == avatar.ControllingClient.AgentId
  1944. || !HasPrivateAttachmentPoint)
  1945. {
  1946. // Send a kill object immediately
  1947. avatar.ControllingClient.SendKillObject(new List<uint> { part.LocalId });
  1948. //direct enqueue another delayed kill
  1949. avatar.ControllingClient.SendEntityUpdate(part,PrimUpdateFlags.Kill);
  1950. }
  1951. }
  1952. }
  1953. });
  1954. }
  1955. }
  1956. public void AddScriptLPS(int count)
  1957. {
  1958. m_scene.SceneGraph.AddToScriptLPS(count);
  1959. }
  1960. public void AddActiveScriptCount(int count)
  1961. {
  1962. SceneGraph d = m_scene.SceneGraph;
  1963. d.AddActiveScripts(count);
  1964. }
  1965. private const scriptEvents PhysicsNeeedSubsEvents = (
  1966. scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
  1967. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end);
  1968. private scriptEvents lastRootPartPhysEvents = 0;
  1969. public void aggregateScriptEvents()
  1970. {
  1971. PrimFlags objectflagupdate = (PrimFlags)RootPart.GetEffectiveObjectFlags();
  1972. scriptEvents aggregateScriptEvents = 0;
  1973. SceneObjectPart[] parts = m_parts.GetArray();
  1974. for (int i = 0; i < parts.Length; i++)
  1975. {
  1976. SceneObjectPart part = parts[i];
  1977. if (part == null)
  1978. continue;
  1979. if (part != RootPart)
  1980. part.Flags = objectflagupdate;
  1981. aggregateScriptEvents |= part.AggregateScriptEvents;
  1982. }
  1983. m_scriptListens_atTarget = ((aggregateScriptEvents & scriptEvents.at_target) != 0);
  1984. m_scriptListens_notAtTarget = ((aggregateScriptEvents & scriptEvents.not_at_target) != 0);
  1985. if (!m_scriptListens_atTarget && !m_scriptListens_notAtTarget)
  1986. {
  1987. lock (m_targets)
  1988. m_targets.Clear();
  1989. m_scene.RemoveGroupTarget(this);
  1990. }
  1991. m_scriptListens_atRotTarget = ((aggregateScriptEvents & scriptEvents.at_rot_target) != 0);
  1992. m_scriptListens_notAtRotTarget = ((aggregateScriptEvents & scriptEvents.not_at_rot_target) != 0);
  1993. if (!m_scriptListens_atRotTarget && !m_scriptListens_notAtRotTarget)
  1994. {
  1995. lock (m_rotTargets)
  1996. m_rotTargets.Clear();
  1997. m_scene.RemoveGroupTarget(this);
  1998. }
  1999. scriptEvents rootPartPhysEvents = RootPart.AggregateScriptEvents;
  2000. rootPartPhysEvents &= PhysicsNeeedSubsEvents;
  2001. if (rootPartPhysEvents != lastRootPartPhysEvents)
  2002. {
  2003. lastRootPartPhysEvents = rootPartPhysEvents;
  2004. for (int i = 0; i < parts.Length; i++)
  2005. {
  2006. SceneObjectPart part = parts[i];
  2007. if (part == null)
  2008. continue;
  2009. part.UpdatePhysicsSubscribedEvents();
  2010. }
  2011. }
  2012. ScheduleGroupForFullUpdate();
  2013. }
  2014. public void SetText(string text, Vector3 color, double alpha)
  2015. {
  2016. Color = Color.FromArgb(0xff - (int) (alpha * 0xff),
  2017. (int) (color.X * 0xff),
  2018. (int) (color.Y * 0xff),
  2019. (int) (color.Z * 0xff));
  2020. Text = text;
  2021. HasGroupChanged = true;
  2022. m_rootPart.ScheduleFullUpdate();
  2023. }
  2024. /// <summary>
  2025. /// Apply physics to this group
  2026. /// </summary>
  2027. public void ApplyPhysics()
  2028. {
  2029. SceneObjectPart[] parts = m_parts.GetArray();
  2030. if (parts.Length > 1)
  2031. {
  2032. ResetChildPrimPhysicsPositions();
  2033. // Apply physics to the root prim
  2034. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true);
  2035. for (int i = 0; i < parts.Length; i++)
  2036. {
  2037. SceneObjectPart part = parts[i];
  2038. if (part.LocalId != m_rootPart.LocalId)
  2039. part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true);
  2040. }
  2041. // Hack to get the physics scene geometries in the right spot
  2042. // ResetChildPrimPhysicsPositions();
  2043. if (m_rootPart.PhysActor != null)
  2044. m_rootPart.PhysActor.Building = false;
  2045. }
  2046. else
  2047. {
  2048. // Apply physics to the root prim
  2049. m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false);
  2050. }
  2051. }
  2052. public void SetOwnerId(UUID userId)
  2053. {
  2054. ForEachPart(delegate(SceneObjectPart part)
  2055. {
  2056. if (part.OwnerID != userId)
  2057. {
  2058. if(part.GroupID != part.OwnerID)
  2059. part.LastOwnerID = part.OwnerID;
  2060. part.OwnerID = userId;
  2061. }
  2062. });
  2063. }
  2064. public void ForEachPart(Action<SceneObjectPart> whatToDo)
  2065. {
  2066. SceneObjectPart[] parts = m_parts.GetArray();
  2067. for (int i = 0; i < parts.Length; i++)
  2068. whatToDo(parts[i]);
  2069. }
  2070. #region Events
  2071. /// <summary>
  2072. /// Processes backup.
  2073. /// </summary>
  2074. /// <param name="datastore"></param>
  2075. public virtual void ProcessBackup(ISimulationDataService datastore, bool forcedBackup)
  2076. {
  2077. if (!Backup)
  2078. {
  2079. // m_log.DebugFormat(
  2080. // "[WATER WARS]: Ignoring backup of {0} {1} since object is not marked to be backed up", Name, UUID);
  2081. return;
  2082. }
  2083. if (IsDeleted || inTransit || UUID == UUID.Zero)
  2084. {
  2085. // m_log.DebugFormat(
  2086. // "[WATER WARS]: Ignoring backup of {0} {1} since object is marked as already deleted", Name, UUID);
  2087. return;
  2088. }
  2089. if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2090. return;
  2091. // Since this is the top of the section of call stack for backing up a particular scene object, don't let
  2092. // any exception propogate upwards.
  2093. try
  2094. {
  2095. // if shutting down then there will be nothing to handle the return so leave till next restart
  2096. if (!m_scene.ShuttingDown &&
  2097. m_scene.LoginsEnabled && // We're starting up or doing maintenance, don't mess with things
  2098. !m_scene.LoadingPrims) // Land may not be valid yet
  2099. {
  2100. ILandObject parcel = m_scene.LandChannel.GetLandObject(
  2101. m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
  2102. if (parcel != null && parcel.LandData != null &&
  2103. parcel.LandData.OtherCleanTime != 0)
  2104. {
  2105. if (parcel.LandData.OwnerID != OwnerID &&
  2106. (parcel.LandData.GroupID != GroupID ||
  2107. parcel.LandData.GroupID == UUID.Zero))
  2108. {
  2109. if ((DateTime.UtcNow - RootPart.Rezzed).TotalMinutes >
  2110. parcel.LandData.OtherCleanTime)
  2111. {
  2112. // don't autoreturn if we have a sitting avatar
  2113. // mantis 7828 (but none the provided patchs)
  2114. if(GetSittingAvatarsCount() > 0)
  2115. {
  2116. // do not respect npcs
  2117. List<ScenePresence> sitters = GetSittingAvatars();
  2118. foreach(ScenePresence sp in sitters)
  2119. {
  2120. if(!sp.IsDeleted && !sp.IsNPC && sp.IsSatOnObject)
  2121. return;
  2122. }
  2123. }
  2124. DetachFromBackup();
  2125. m_log.DebugFormat(
  2126. "[SCENE OBJECT GROUP]: Returning object {0} due to parcel autoreturn",
  2127. RootPart.UUID);
  2128. m_scene.AddReturn(OwnerID == GroupID ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn");
  2129. m_scene.DeRezObjects(null, new List<uint>() { RootPart.LocalId }, UUID.Zero,
  2130. DeRezAction.Return, UUID.Zero, false);
  2131. return;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. if (m_scene.UseBackup && HasGroupChanged)
  2137. {
  2138. // don't backup while it's selected or you're asking for changes mid stream.
  2139. if (isTimeToPersist() || forcedBackup)
  2140. {
  2141. if (m_rootPart.PhysActor != null &&
  2142. (!m_rootPart.PhysActor.IsPhysical))
  2143. {
  2144. // Possible ghost prim
  2145. if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
  2146. {
  2147. foreach (SceneObjectPart part in m_parts.GetArray())
  2148. {
  2149. // Re-set physics actor positions and
  2150. // orientations
  2151. part.GroupPosition = m_rootPart.GroupPosition;
  2152. }
  2153. }
  2154. }
  2155. // m_log.DebugFormat(
  2156. // "[SCENE]: Storing {0}, {1} in {2}",
  2157. // Name, UUID, m_scene.RegionInfo.RegionName);
  2158. if (RootPart.Shape.PCode == 9 && RootPart.Shape.State != 0)
  2159. {
  2160. RootPart.Shape.LastAttachPoint = RootPart.Shape.State;
  2161. RootPart.Shape.State = 0;
  2162. ScheduleGroupForFullUpdate();
  2163. }
  2164. SceneObjectGroup backup_group = Copy(false);
  2165. backup_group.RootPart.Velocity = RootPart.Velocity;
  2166. backup_group.RootPart.Acceleration = RootPart.Acceleration;
  2167. backup_group.RootPart.AngularVelocity = RootPart.AngularVelocity;
  2168. backup_group.RootPart.ParticleSystem = RootPart.ParticleSystem;
  2169. HasGroupChanged = false;
  2170. GroupContainsForeignPrims = false;
  2171. m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this);
  2172. datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID);
  2173. backup_group.ForEachPart(delegate(SceneObjectPart part)
  2174. {
  2175. part.Inventory.ProcessInventoryBackup(datastore);
  2176. if(part.KeyframeMotion != null)
  2177. {
  2178. part.KeyframeMotion.Delete();
  2179. part.KeyframeMotion = null;
  2180. }
  2181. });
  2182. backup_group.Clear();
  2183. backup_group = null;
  2184. }
  2185. // else
  2186. // {
  2187. // m_log.DebugFormat(
  2188. // "[SCENE]: Did not update persistence of object {0} {1}, selected = {2}",
  2189. // Name, UUID, IsSelected);
  2190. // }
  2191. }
  2192. }
  2193. catch (Exception e)
  2194. {
  2195. m_log.ErrorFormat(
  2196. "[SCENE]: Storing of {0}, {1} in {2} failed with exception {3}{4}",
  2197. Name, UUID, m_scene.RegionInfo.RegionName, e.Message, e.StackTrace);
  2198. }
  2199. }
  2200. #endregion
  2201. /// <summary>
  2202. /// Send the parts of this SOG to a single client
  2203. /// </summary>
  2204. /// <remarks>
  2205. /// Used when the client initially connects and when client sends RequestPrim packet
  2206. /// </remarks>
  2207. /// <param name="remoteClient"></param>
  2208. public void SendFullUpdateToClient(IClientAPI remoteClient)
  2209. {
  2210. RootPart.SendFullUpdate(remoteClient);
  2211. SceneObjectPart[] parts = m_parts.GetArray();
  2212. for (int i = 0; i < parts.Length; i++)
  2213. {
  2214. SceneObjectPart part = parts[i];
  2215. if (part != RootPart)
  2216. part.SendFullUpdate(remoteClient);
  2217. }
  2218. }
  2219. #region Copying
  2220. /// <summary>
  2221. /// Duplicates this object, including operations such as physics set up and attaching to the backup event.
  2222. /// </summary>
  2223. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  2224. /// <returns></returns>
  2225. public SceneObjectGroup Copy(bool userExposed)
  2226. {
  2227. m_dupeInProgress = true;
  2228. SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone();
  2229. dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>();
  2230. // a copy isnt backedup
  2231. dupe.Backup = false;
  2232. dupe.InvalidBoundsRadius();
  2233. // a copy is not in transit hopefully
  2234. dupe.inTransit = false;
  2235. // new group as no sitting avatars
  2236. dupe.m_sittingAvatars = new List<ScenePresence>();
  2237. dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed);
  2238. dupe.m_rootPart.LinkNum = m_rootPart.LinkNum;
  2239. if (userExposed)
  2240. dupe.m_rootPart.TrimPermissions();
  2241. List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
  2242. partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
  2243. {
  2244. return p1.LinkNum.CompareTo(p2.LinkNum);
  2245. }
  2246. );
  2247. foreach (SceneObjectPart part in partList)
  2248. {
  2249. SceneObjectPart newPart;
  2250. if (part.UUID != m_rootPart.UUID)
  2251. {
  2252. newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed);
  2253. newPart.LinkNum = part.LinkNum;
  2254. // if (userExposed)
  2255. newPart.ParentID = dupe.m_rootPart.LocalId;
  2256. }
  2257. else
  2258. {
  2259. newPart = dupe.m_rootPart;
  2260. }
  2261. /*
  2262. bool isphys = ((newPart.Flags & PrimFlags.Physics) != 0);
  2263. bool isphan = ((newPart.Flags & PrimFlags.Phantom) != 0);
  2264. // Need to duplicate the physics actor as well
  2265. if (userExposed && (isphys || !isphan || newPart.VolumeDetectActive))
  2266. {
  2267. PrimitiveBaseShape pbs = newPart.Shape;
  2268. newPart.PhysActor
  2269. = m_scene.PhysicsScene.AddPrimShape(
  2270. string.Format("{0}/{1}", newPart.Name, newPart.UUID),
  2271. pbs,
  2272. newPart.AbsolutePosition,
  2273. newPart.Scale,
  2274. newPart.GetWorldRotation(),
  2275. isphys,
  2276. isphan,
  2277. newPart.LocalId);
  2278. newPart.DoPhysicsPropertyUpdate(isphys, true);
  2279. */
  2280. if (userExposed)
  2281. newPart.ApplyPhysics((uint)newPart.Flags,newPart.VolumeDetectActive,true);
  2282. // }
  2283. // copy keyframemotion
  2284. if (part.KeyframeMotion != null)
  2285. newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe);
  2286. }
  2287. if (userExposed)
  2288. {
  2289. // done above dupe.UpdateParentIDs();
  2290. if (dupe.m_rootPart.PhysActor != null)
  2291. dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building
  2292. dupe.InvalidateDeepEffectivePerms();
  2293. dupe.HasGroupChanged = true;
  2294. dupe.AttachToBackup();
  2295. dupe.ScheduleGroupForFullUpdate();
  2296. }
  2297. dupe.InvalidatePartsLinkMaps();
  2298. m_dupeInProgress = false;
  2299. return dupe;
  2300. }
  2301. /// <summary>
  2302. /// Copy the given part as the root part of this scene object.
  2303. /// </summary>
  2304. /// <param name="part"></param>
  2305. /// <param name="cAgentID"></param>
  2306. /// <param name="cGroupID"></param>
  2307. public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2308. {
  2309. SceneObjectPart newpart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed);
  2310. // SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed);
  2311. // newpart.LocalId = m_scene.AllocateLocalId();
  2312. SetRootPart(newpart);
  2313. if (userExposed)
  2314. RootPart.Velocity = Vector3.Zero; // In case source is moving
  2315. }
  2316. public void ScriptSetPhysicsStatus(bool usePhysics)
  2317. {
  2318. if (usePhysics)
  2319. {
  2320. if (RootPart.KeyframeMotion != null)
  2321. RootPart.KeyframeMotion.Stop();
  2322. RootPart.KeyframeMotion = null;
  2323. }
  2324. UpdatePrimFlags(RootPart.LocalId, usePhysics, IsTemporary, IsPhantom, IsVolumeDetect);
  2325. }
  2326. public void ScriptSetTemporaryStatus(bool makeTemporary)
  2327. {
  2328. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, makeTemporary, IsPhantom, IsVolumeDetect);
  2329. }
  2330. public void ScriptSetPhantomStatus(bool makePhantom)
  2331. {
  2332. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, IsTemporary, makePhantom, IsVolumeDetect);
  2333. }
  2334. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  2335. {
  2336. UpdatePrimFlags(RootPart.LocalId, UsesPhysics, IsTemporary, IsPhantom, makeVolumeDetect);
  2337. /*
  2338. ScriptSetPhantomStatus(false); // What ever it was before, now it's not phantom anymore
  2339. if (PhysActor != null) // Should always be the case now
  2340. {
  2341. PhysActor.SetVolumeDetect(param);
  2342. }
  2343. if (param != 0)
  2344. AddFlag(PrimFlags.Phantom);
  2345. ScheduleFullUpdate();
  2346. */
  2347. }
  2348. public void applyImpulse(Vector3 impulse)
  2349. {
  2350. if (IsAttachment)
  2351. {
  2352. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2353. if (avatar != null)
  2354. {
  2355. avatar.PushForce(impulse);
  2356. }
  2357. }
  2358. else
  2359. {
  2360. PhysicsActor pa = RootPart.PhysActor;
  2361. if (pa != null)
  2362. {
  2363. // false to be applied as a impulse
  2364. pa.AddForce(impulse, false);
  2365. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2366. }
  2367. }
  2368. }
  2369. public void ApplyAngularImpulse(Vector3 impulse)
  2370. {
  2371. PhysicsActor pa = RootPart.PhysActor;
  2372. if (pa != null)
  2373. {
  2374. if (!IsAttachment)
  2375. {
  2376. // false to be applied as a impulse
  2377. pa.AddAngularForce(impulse, false);
  2378. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2379. }
  2380. }
  2381. }
  2382. public Vector3 GetTorque()
  2383. {
  2384. return RootPart.Torque;
  2385. }
  2386. // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object
  2387. public void MoveToTarget(Vector3 target, float tau)
  2388. {
  2389. if (IsAttachment)
  2390. {
  2391. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2392. if (avatar != null)
  2393. avatar.MoveToTarget(target, false, false);
  2394. }
  2395. else
  2396. {
  2397. PhysicsActor pa = RootPart.PhysActor;
  2398. if (pa != null)
  2399. {
  2400. pa.PIDTarget = target;
  2401. pa.PIDTau = tau;
  2402. pa.PIDActive = true;
  2403. }
  2404. }
  2405. }
  2406. public void StopMoveToTarget()
  2407. {
  2408. if (IsAttachment)
  2409. {
  2410. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2411. if (avatar != null)
  2412. {
  2413. avatar.ResetMoveToTarget();
  2414. }
  2415. }
  2416. else
  2417. {
  2418. PhysicsActor pa = RootPart.PhysActor;
  2419. if (pa != null)
  2420. pa.PIDActive = false;
  2421. RootPart.ScheduleTerseUpdate(); // send a stop information
  2422. }
  2423. }
  2424. public void RotLookAt(Quaternion target, float strength, float damping)
  2425. {
  2426. if(IsDeleted)
  2427. return;
  2428. // non physical is handle in LSL api
  2429. if(!UsesPhysics || IsAttachment)
  2430. return;
  2431. SceneObjectPart rootpart = m_rootPart;
  2432. if (rootpart != null)
  2433. {
  2434. /* physics still doesnt suport this
  2435. if (rootpart.PhysActor != null)
  2436. {
  2437. rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
  2438. rootpart.PhysActor.APIDStrength = strength;
  2439. rootpart.PhysActor.APIDDamping = damping;
  2440. rootpart.PhysActor.APIDActive = true;
  2441. }
  2442. */
  2443. // so do it in rootpart
  2444. rootpart.RotLookAt(target, strength, damping);
  2445. }
  2446. }
  2447. public void StartLookAt(Quaternion target, float strength, float damping)
  2448. {
  2449. if(IsDeleted)
  2450. return;
  2451. // non physical is done by LSL APi
  2452. if(!UsesPhysics || IsAttachment)
  2453. return;
  2454. if (m_rootPart != null)
  2455. m_rootPart.RotLookAt(target, strength, damping);
  2456. }
  2457. public void StopLookAt()
  2458. {
  2459. SceneObjectPart rootpart = m_rootPart;
  2460. if (rootpart != null)
  2461. {
  2462. if (rootpart.PhysActor != null)
  2463. {
  2464. rootpart.PhysActor.APIDActive = false;
  2465. }
  2466. rootpart.StopLookAt();
  2467. }
  2468. }
  2469. /// <summary>
  2470. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2471. /// </summary>
  2472. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2473. /// <param name="hoverType">Determines what the height is relative to </param>
  2474. /// <param name="tau">Number of seconds over which to reach target</param>
  2475. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2476. {
  2477. PhysicsActor pa = null;
  2478. if(IsAttachment)
  2479. {
  2480. ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
  2481. if (avatar != null)
  2482. pa = avatar.PhysicsActor;
  2483. }
  2484. else
  2485. pa = RootPart.PhysActor;
  2486. if (pa != null)
  2487. {
  2488. if (height != 0f)
  2489. {
  2490. pa.PIDHoverHeight = height;
  2491. pa.PIDHoverType = hoverType;
  2492. pa.PIDHoverTau = tau;
  2493. pa.PIDHoverActive = true;
  2494. }
  2495. else
  2496. {
  2497. pa.PIDHoverActive = false;
  2498. }
  2499. }
  2500. }
  2501. /// <summary>
  2502. /// Set the owner of all linkset.
  2503. /// </summary>
  2504. /// <param name="cAgentID"></param>
  2505. /// <param name="cGroupID"></param>
  2506. public void SetOwner(UUID cAgentID, UUID cGroupID)
  2507. {
  2508. SceneObjectPart rpart = RootPart;
  2509. UUID oldowner = rpart.OwnerID;
  2510. ForEachPart(delegate(SceneObjectPart part)
  2511. {
  2512. if(part.GroupID != part.OwnerID)
  2513. part.LastOwnerID = part.OwnerID;
  2514. part.OwnerID = cAgentID;
  2515. part.GroupID = cGroupID;
  2516. });
  2517. if (oldowner != cAgentID)
  2518. {
  2519. // Apply Next Owner Permissions if we're not bypassing permissions
  2520. if (!m_scene.Permissions.BypassPermissions())
  2521. {
  2522. ApplyNextOwnerPermissions();
  2523. InvalidateEffectivePerms();
  2524. }
  2525. }
  2526. rpart.ScheduleFullUpdate();
  2527. }
  2528. /// <summary>
  2529. /// Make a copy of the given part.
  2530. /// </summary>
  2531. /// <param name="part"></param>
  2532. /// <param name="cAgentID"></param>
  2533. /// <param name="cGroupID"></param>
  2534. public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
  2535. {
  2536. SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
  2537. // SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed);
  2538. // newPart.LocalId = m_scene.AllocateLocalId();
  2539. AddPart(newPart);
  2540. SetPartAsNonRoot(newPart);
  2541. return newPart;
  2542. }
  2543. /// <summary>
  2544. /// Reset the UUIDs for all the prims that make up this group.
  2545. /// </summary>
  2546. /// <remarks>
  2547. /// This is called by methods which want to add a new group to an existing scene, in order
  2548. /// to ensure that there are no clashes with groups already present.
  2549. /// </remarks>
  2550. public void ResetIDs()
  2551. {
  2552. lock (m_parts.SyncRoot)
  2553. {
  2554. List<SceneObjectPart> partsList = new List<SceneObjectPart>(m_parts.GetArray());
  2555. m_parts.Clear();
  2556. foreach (SceneObjectPart part in partsList)
  2557. {
  2558. part.ResetIDs(part.LinkNum); // Don't change link nums
  2559. m_parts.Add(part.UUID, part);
  2560. }
  2561. }
  2562. }
  2563. /// <summary>
  2564. ///
  2565. /// </summary>
  2566. /// <param name="part"></param>
  2567. public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags)
  2568. {
  2569. remoteClient.SendObjectPropertiesFamilyData(RootPart, RequestFlags);
  2570. // remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask,
  2571. // RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask,
  2572. // RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category,
  2573. // RootPart.CreatorID, RootPart.Name, RootPart.Description);
  2574. }
  2575. public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID)
  2576. {
  2577. part.OwnerID = cAgentID;
  2578. part.GroupID = cGroupID;
  2579. }
  2580. #endregion
  2581. public override void Update()
  2582. {
  2583. // Check that the group was not deleted before the scheduled update
  2584. // FIXME: This is merely a temporary measure to reduce the incidence of failure when
  2585. // an object has been deleted from a scene before update was processed.
  2586. // A more fundamental overhaul of the update mechanism is required to eliminate all
  2587. // the race conditions.
  2588. if (IsDeleted || inTransit)
  2589. return;
  2590. // Even temporary objects take part in physics (e.g. temp-on-rez bullets)
  2591. //if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
  2592. // return;
  2593. // If we somehow got here to updating the SOG and its root part is not scheduled for update,
  2594. // check to see if the physical position or rotation warrant an update.
  2595. if (m_rootPart.UpdateFlag == UpdateRequired.NONE)
  2596. {
  2597. // rootpart SendScheduledUpdates will check if a update is needed
  2598. m_rootPart.UpdateFlag = UpdateRequired.TERSE;
  2599. }
  2600. if (IsAttachment)
  2601. {
  2602. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2603. if (sp != null)
  2604. {
  2605. sp.SendAttachmentScheduleUpdate(this);
  2606. return;
  2607. }
  2608. }
  2609. // while physics doesn't suports LookAt, we do it in RootPart
  2610. if (!IsSelected)
  2611. RootPart.UpdateLookAt();
  2612. SceneObjectPart[] parts = m_parts.GetArray();
  2613. for (int i = 0; i < parts.Length; i++)
  2614. {
  2615. SceneObjectPart part = parts[i];
  2616. part.SendScheduledUpdates();
  2617. }
  2618. }
  2619. /// <summary>
  2620. /// Schedule a full update for this scene object to all interested viewers.
  2621. /// </summary>
  2622. /// <remarks>
  2623. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2624. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2625. /// code will set this anyway when some object properties are changed.
  2626. /// </remarks>
  2627. public void ScheduleGroupForFullUpdate()
  2628. {
  2629. // if (IsAttachment)
  2630. // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId);
  2631. checkAtTargets();
  2632. RootPart.ScheduleFullUpdate();
  2633. SceneObjectPart[] parts = m_parts.GetArray();
  2634. for (int i = 0; i < parts.Length; i++)
  2635. {
  2636. SceneObjectPart part = parts[i];
  2637. if (part != RootPart)
  2638. part.ScheduleFullUpdate();
  2639. }
  2640. }
  2641. /// <summary>
  2642. /// Schedule a terse update for this scene object to all interested viewers.
  2643. /// </summary>
  2644. /// <remarks>
  2645. /// Ultimately, this should be managed such that region modules can invoke it at the end of a set of operations
  2646. /// so that either all changes are sent at once. However, currently, a large amount of internal
  2647. /// code will set this anyway when some object properties are changed.
  2648. /// </remarks>
  2649. public void ScheduleGroupForTerseUpdate()
  2650. {
  2651. // m_log.DebugFormat("[SOG]: Scheduling terse update for {0} {1}", Name, UUID);
  2652. SceneObjectPart[] parts = m_parts.GetArray();
  2653. for (int i = 0; i < parts.Length; i++)
  2654. parts[i].ScheduleTerseUpdate();
  2655. }
  2656. /// <summary>
  2657. /// Immediately send a full update for this scene object.
  2658. /// </summary>
  2659. public void SendGroupFullUpdate()
  2660. {
  2661. if (IsDeleted)
  2662. return;
  2663. // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
  2664. if (IsAttachment)
  2665. {
  2666. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2667. if (sp != null)
  2668. {
  2669. sp.SendAttachmentUpdate(this,UpdateRequired.FULL);
  2670. return;
  2671. }
  2672. }
  2673. RootPart.SendFullUpdateToAllClientsInternal();
  2674. SceneObjectPart[] parts = m_parts.GetArray();
  2675. for (int i = 0; i < parts.Length; i++)
  2676. {
  2677. SceneObjectPart part = parts[i];
  2678. if (part != RootPart)
  2679. part.SendFullUpdateToAllClientsInternal();
  2680. }
  2681. }
  2682. /// <summary>
  2683. /// Immediately send an update for this scene object's root prim only.
  2684. /// This is for updates regarding the object as a whole, and none of its parts in particular.
  2685. /// Note: this may not be used by opensim (it probably should) but it's used by
  2686. /// external modules.
  2687. /// </summary>
  2688. public void SendGroupRootTerseUpdate()
  2689. {
  2690. if (IsDeleted || inTransit)
  2691. return;
  2692. RootPart.SendTerseUpdateToAllClients();
  2693. }
  2694. public void QueueForUpdateCheck()
  2695. {
  2696. if (m_scene == null) // Need to check here as it's null during object creation
  2697. return;
  2698. m_scene.SceneGraph.AddToUpdateList(this);
  2699. }
  2700. /// <summary>
  2701. /// Immediately send a terse update for this scene object.
  2702. /// </summary>
  2703. public void SendGroupTerseUpdate()
  2704. {
  2705. if (IsDeleted || inTransit)
  2706. return;
  2707. if (IsAttachment)
  2708. {
  2709. ScenePresence sp = m_scene.GetScenePresence(AttachedAvatar);
  2710. if (sp != null)
  2711. {
  2712. sp.SendAttachmentUpdate(this, UpdateRequired.TERSE);
  2713. return;
  2714. }
  2715. }
  2716. SceneObjectPart[] parts = m_parts.GetArray();
  2717. for (int i = 0; i < parts.Length; i++)
  2718. parts[i].SendTerseUpdateToAllClientsInternal();
  2719. }
  2720. /// <summary>
  2721. /// Send metadata about the root prim (name, description, sale price, permissions, etc.) to a client.
  2722. /// </summary>
  2723. /// <param name="client"></param>
  2724. public void SendPropertiesToClient(IClientAPI client)
  2725. {
  2726. m_rootPart.SendPropertiesToClient(client);
  2727. }
  2728. #region SceneGroupPart Methods
  2729. /// <summary>
  2730. /// Get the child part by LinkNum
  2731. /// </summary>
  2732. /// <param name="linknum"></param>
  2733. /// <returns>null if no child part with that linknum or child part</returns>
  2734. public SceneObjectPart GetLinkNumPart(int linknum)
  2735. {
  2736. SceneObjectPart[] parts = m_parts.GetArray();
  2737. for (int i = 0; i < parts.Length; i++)
  2738. {
  2739. if (parts[i].LinkNum == linknum)
  2740. return parts[i];
  2741. }
  2742. return null;
  2743. }
  2744. /// <summary>
  2745. /// Get a part with a given UUID
  2746. /// </summary>
  2747. /// <param name="primID"></param>
  2748. /// <returns>null if a part with the primID was not found</returns>
  2749. public SceneObjectPart GetPart(UUID primID)
  2750. {
  2751. SceneObjectPart childPart;
  2752. m_parts.TryGetValue(primID, out childPart);
  2753. return childPart;
  2754. }
  2755. /// <summary>
  2756. /// Get a part with a given local ID
  2757. /// </summary>
  2758. /// <param name="localID"></param>
  2759. /// <returns>null if a part with the local ID was not found</returns>
  2760. public SceneObjectPart GetPart(uint localID)
  2761. {
  2762. SceneObjectPart[] parts = m_parts.GetArray();
  2763. for (int i = 0; i < parts.Length; i++)
  2764. {
  2765. if (parts[i].LocalId == localID)
  2766. return parts[i];
  2767. }
  2768. return null;
  2769. }
  2770. #endregion
  2771. #region Packet Handlers
  2772. /// <summary>
  2773. /// Link the prims in a given group to this group
  2774. /// </summary>
  2775. /// <remarks>
  2776. /// Do not call this method directly - use Scene.LinkObjects() instead to avoid races between threads.
  2777. /// FIXME: There are places where scripts call these methods directly without locking. This is a potential race condition.
  2778. /// </remarks>
  2779. /// <param name="objectGroup">The group of prims which should be linked to this group</param>
  2780. public void LinkToGroup(SceneObjectGroup objectGroup)
  2781. {
  2782. LinkToGroup(objectGroup, false);
  2783. }
  2784. // Link an existing group to this group.
  2785. // The group being linked need not be a linkset -- it can have just one prim.
  2786. public void LinkToGroup(SceneObjectGroup objectGroup, bool insert)
  2787. {
  2788. // m_log.DebugFormat(
  2789. // "[SCENE OBJECT GROUP]: Linking group with root part {0}, {1} to group with root part {2}, {3}",
  2790. // objectGroup.RootPart.Name, objectGroup.RootPart.UUID, RootPart.Name, RootPart.UUID);
  2791. // Linking to ourselves is not a valid operation.
  2792. if (objectGroup == this)
  2793. return;
  2794. // If the configured linkset capacity is greater than zero,
  2795. // and the new linkset would have a prim count higher than this
  2796. // value, do not link it.
  2797. if (m_scene.m_linksetCapacity > 0 &&
  2798. (PrimCount + objectGroup.PrimCount) >
  2799. m_scene.m_linksetCapacity)
  2800. {
  2801. m_log.DebugFormat(
  2802. "[SCENE OBJECT GROUP]: Cannot link group with root" +
  2803. " part {0}, {1} ({2} prims) to group with root part" +
  2804. " {3}, {4} ({5} prims) because the new linkset" +
  2805. " would exceed the configured maximum of {6}",
  2806. objectGroup.RootPart.Name, objectGroup.RootPart.UUID,
  2807. objectGroup.PrimCount, RootPart.Name, RootPart.UUID,
  2808. PrimCount, m_scene.m_linksetCapacity);
  2809. return;
  2810. }
  2811. // physical prims count limit
  2812. // not very eficient :(
  2813. if (UsesPhysics && m_scene.m_linksetPhysCapacity > 0 && (PrimCount + objectGroup.PrimCount) >
  2814. m_scene.m_linksetPhysCapacity)
  2815. {
  2816. int cntr = 0;
  2817. foreach (SceneObjectPart part in Parts)
  2818. {
  2819. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2820. cntr++;
  2821. }
  2822. foreach (SceneObjectPart part in objectGroup.Parts)
  2823. {
  2824. if (part.PhysicsShapeType != (byte)PhysicsShapeType.None)
  2825. cntr++;
  2826. }
  2827. if (cntr > m_scene.m_linksetPhysCapacity)
  2828. {
  2829. // cancel physics
  2830. RootPart.Flags &= ~PrimFlags.Physics;
  2831. ApplyPhysics();
  2832. }
  2833. }
  2834. // 'linkPart' == the root of the group being linked into this group
  2835. SceneObjectPart linkPart = objectGroup.m_rootPart;
  2836. if (m_rootPart.PhysActor != null)
  2837. m_rootPart.PhysActor.Building = true;
  2838. if (linkPart.PhysActor != null)
  2839. linkPart.PhysActor.Building = true;
  2840. // physics flags from group to be applied to linked parts
  2841. bool grpusephys = UsesPhysics;
  2842. bool grptemporary = IsTemporary;
  2843. // Remember where the group being linked thought it was
  2844. Vector3 oldGroupPosition = linkPart.GroupPosition;
  2845. Quaternion oldRootRotation = linkPart.RotationOffset;
  2846. // A linked SOP remembers its location and rotation relative to the root of a group.
  2847. // Convert the root of the group being linked to be relative to the
  2848. // root of the group being linked to.
  2849. // Note: Some of the assignments have complex side effects.
  2850. // First move the new group's root SOP's position to be relative to ours
  2851. // (radams1: Not sure if the multiple setting of OffsetPosition is required. If not,
  2852. // this code can be reordered to have a more logical flow.)
  2853. linkPart.setOffsetPosition(linkPart.GroupPosition - AbsolutePosition);
  2854. // Assign the new parent to the root of the old group
  2855. linkPart.ParentID = m_rootPart.LocalId;
  2856. // Now that it's a child, it's group position is our root position
  2857. linkPart.setGroupPosition(AbsolutePosition);
  2858. // Rotate the linking root SOP's position to be relative to the new root prim
  2859. Quaternion parentRot = m_rootPart.RotationOffset;
  2860. // Make the linking root SOP's rotation relative to the new root prim
  2861. Quaternion oldRot = linkPart.RotationOffset;
  2862. Quaternion newRot = Quaternion.Conjugate(parentRot) * oldRot;
  2863. linkPart.setRotationOffset(newRot);
  2864. Vector3 axPos = linkPart.OffsetPosition;
  2865. axPos *= Quaternion.Conjugate(parentRot);
  2866. linkPart.OffsetPosition = axPos;
  2867. // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset.
  2868. // Now that we know this SOG has at least two SOPs in it, the new root
  2869. // SOP becomes the first in the linkset.
  2870. if (m_rootPart.LinkNum == 0)
  2871. m_rootPart.LinkNum = 1;
  2872. lock (m_parts.SyncRoot)
  2873. {
  2874. // Calculate the new link number for the old root SOP
  2875. int linkNum;
  2876. if (insert)
  2877. {
  2878. linkNum = 2;
  2879. int insertSize = objectGroup.PrimCount;
  2880. foreach (SceneObjectPart part in Parts)
  2881. {
  2882. if (part.LinkNum > 1)
  2883. part.LinkNum += insertSize;
  2884. }
  2885. }
  2886. else
  2887. {
  2888. linkNum = PrimCount + 1;
  2889. }
  2890. // Add the old root SOP as a part in our group's list
  2891. m_parts.Add(linkPart.UUID, linkPart);
  2892. linkPart.SetParent(this);
  2893. m_scene.updateScenePartGroup(linkPart, this);
  2894. linkPart.CreateSelected = true;
  2895. // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
  2896. linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true);
  2897. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2898. if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2899. {
  2900. linkPart.PhysActor.link(m_rootPart.PhysActor);
  2901. this.Scene.PhysicsScene.AddPhysicsActorTaint(linkPart.PhysActor);
  2902. }
  2903. linkPart.LinkNum = linkNum++;
  2904. linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  2905. // Get a list of the SOP's in the source group in order of their linknum's.
  2906. SceneObjectPart[] ogParts = objectGroup.Parts;
  2907. Array.Sort(ogParts, delegate(SceneObjectPart a, SceneObjectPart b)
  2908. {
  2909. return a.LinkNum - b.LinkNum;
  2910. });
  2911. // Add each of the SOP's from the source linkset to our linkset
  2912. for (int i = 0; i < ogParts.Length; i++)
  2913. {
  2914. SceneObjectPart part = ogParts[i];
  2915. if (part.UUID != objectGroup.m_rootPart.UUID)
  2916. {
  2917. LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
  2918. // Update the physics flags for the newly added SOP
  2919. // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??)
  2920. part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true);
  2921. // If the added SOP is physical, also tell the physics engine about the link relationship.
  2922. if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
  2923. {
  2924. part.PhysActor.link(m_rootPart.PhysActor);
  2925. this.Scene.PhysicsScene.AddPhysicsActorTaint(part.PhysActor);
  2926. }
  2927. }
  2928. part.ClearUndoState();
  2929. }
  2930. }
  2931. // Now that we've aquired all of the old SOG's parts, remove the old SOG from the scene.
  2932. m_scene.UnlinkSceneObject(objectGroup, true);
  2933. objectGroup.IsDeleted = true;
  2934. objectGroup.m_parts.Clear();
  2935. // Can't do this yet since backup still makes use of the root part without any synchronization
  2936. // objectGroup.m_rootPart = null;
  2937. // If linking prims with different permissions, fix them
  2938. AdjustChildPrimPermissions(false);
  2939. GroupContainsForeignPrims = true;
  2940. AttachToBackup();
  2941. // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the
  2942. // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and
  2943. // unmoved prims!
  2944. ResetChildPrimPhysicsPositions();
  2945. InvalidBoundsRadius();
  2946. InvalidatePartsLinkMaps();
  2947. if (m_rootPart.PhysActor != null)
  2948. m_rootPart.PhysActor.Building = false;
  2949. //HasGroupChanged = true;
  2950. //ScheduleGroupForFullUpdate();
  2951. }
  2952. /// <summary>
  2953. /// Delink the given prim from this group. The delinked prim is established as
  2954. /// an independent SceneObjectGroup.
  2955. /// </summary>
  2956. /// <remarks>
  2957. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2958. /// condition. But currently there is no
  2959. /// alternative method that does take a lonk to delink a single prim.
  2960. /// </remarks>
  2961. /// <param name="partID"></param>
  2962. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2963. public SceneObjectGroup DelinkFromGroup(uint partID)
  2964. {
  2965. return DelinkFromGroup(partID, true);
  2966. }
  2967. /// <summary>
  2968. /// Delink the given prim from this group. The delinked prim is established as
  2969. /// an independent SceneObjectGroup.
  2970. /// </summary>
  2971. /// <remarks>
  2972. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  2973. /// condition. But currently there is no
  2974. /// alternative method that does take a lonk to delink a single prim.
  2975. /// </remarks>
  2976. /// <param name="partID"></param>
  2977. /// <param name="sendEvents"></param>
  2978. /// <returns>The object group of the newly delinked prim. Null if part could not be found</returns>
  2979. public SceneObjectGroup DelinkFromGroup(uint partID, bool sendEvents)
  2980. {
  2981. SceneObjectPart linkPart = GetPart(partID);
  2982. if (linkPart != null)
  2983. {
  2984. return DelinkFromGroup(linkPart, sendEvents);
  2985. }
  2986. else
  2987. {
  2988. m_log.WarnFormat("[SCENE OBJECT GROUP]: " +
  2989. "DelinkFromGroup(): Child prim {0} not found in object {1}, {2}",
  2990. partID, LocalId, UUID);
  2991. return null;
  2992. }
  2993. }
  2994. /// <summary>
  2995. /// Delink the given prim from this group. The delinked prim is established as
  2996. /// an independent SceneObjectGroup.
  2997. /// </summary>
  2998. /// <remarks>
  2999. /// FIXME: This method should not be called directly since it bypasses update locking, allowing a potential race
  3000. /// condition. But currently there is no
  3001. /// alternative method that does take a lock to delink a single prim.
  3002. /// </remarks>
  3003. /// <param name="partID"></param>
  3004. /// <param name="sendEvents"></param>
  3005. /// <returns>The object group of the newly delinked prim.</returns>
  3006. public SceneObjectGroup DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents)
  3007. {
  3008. // m_log.DebugFormat(
  3009. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3010. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3011. if (m_rootPart.PhysActor != null)
  3012. m_rootPart.PhysActor.Building = true;
  3013. linkPart.ClearUndoState();
  3014. Vector3 worldPos = linkPart.GetWorldPosition();
  3015. Quaternion worldRot = linkPart.GetWorldRotation();
  3016. // Remove the part from this object
  3017. lock (m_parts.SyncRoot)
  3018. {
  3019. m_parts.Remove(linkPart.UUID);
  3020. SceneObjectPart[] parts = m_parts.GetArray();
  3021. // Rejigger the linknum's of the remaining SOP's to fill any gap
  3022. if (parts.Length == 1 && RootPart != null)
  3023. {
  3024. // Single prim left
  3025. RootPart.LinkNum = 0;
  3026. }
  3027. else
  3028. {
  3029. for (int i = 0; i < parts.Length; i++)
  3030. {
  3031. SceneObjectPart part = parts[i];
  3032. if (part.LinkNum > linkPart.LinkNum)
  3033. part.LinkNum--;
  3034. }
  3035. }
  3036. }
  3037. linkPart.ParentID = 0;
  3038. linkPart.LinkNum = 0;
  3039. PhysicsActor linkPartPa = linkPart.PhysActor;
  3040. // Remove the SOP from the physical scene.
  3041. // If the new SOG is physical, it is re-created later.
  3042. // (There is a problem here in that we have not yet told the physics
  3043. // engine about the delink. Someday, linksets should be made first
  3044. // class objects in the physics engine interface).
  3045. if (linkPartPa != null)
  3046. {
  3047. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3048. linkPart.PhysActor = null;
  3049. }
  3050. // We need to reset the child part's position
  3051. // ready for life as a separate object after being a part of another object
  3052. /* This commented out code seems to recompute what GetWorldPosition already does.
  3053. * Replace with a call to GetWorldPosition (before unlinking)
  3054. Quaternion parentRot = m_rootPart.RotationOffset;
  3055. Vector3 axPos = linkPart.OffsetPosition;
  3056. axPos *= parentRot;
  3057. linkPart.OffsetPosition = new Vector3(axPos.X, axPos.Y, axPos.Z);
  3058. linkPart.GroupPosition = AbsolutePosition + linkPart.OffsetPosition;
  3059. linkPart.OffsetPosition = new Vector3(0, 0, 0);
  3060. */
  3061. linkPart.setGroupPosition(worldPos);
  3062. linkPart.setOffsetPosition(Vector3.Zero);
  3063. linkPart.setRotationOffset(worldRot);
  3064. // Create a new SOG to go around this unlinked and unattached SOP
  3065. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3066. m_scene.AddNewSceneObject(objectGroup, true);
  3067. linkPart.Rezzed = RootPart.Rezzed;
  3068. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3069. // (since delete works by deleting all rows which have a given object id)
  3070. // this is as it seems to be in sl now
  3071. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3072. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3073. if (m_rootPart.PhysActor != null)
  3074. m_rootPart.PhysActor.Building = false;
  3075. objectGroup.HasGroupChangedDueToDelink = true;
  3076. InvalidBoundsRadius();
  3077. InvalidatePartsLinkMaps();
  3078. objectGroup.InvalidateEffectivePerms();
  3079. if (sendEvents)
  3080. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3081. return objectGroup;
  3082. }
  3083. /* working on it
  3084. public void DelinkFromGroup(List<SceneObjectPart> linkParts, bool sendEvents)
  3085. {
  3086. // m_log.DebugFormat(
  3087. // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}",
  3088. // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID);
  3089. if(PrimCount == 1)
  3090. return;
  3091. if (m_rootPart.PhysActor != null)
  3092. m_rootPart.PhysActor.Building = true;
  3093. bool unlinkroot = false;
  3094. foreach(SceneObjectPart linkPart in linkParts)
  3095. {
  3096. // first we only remove child parts
  3097. if(linkPart.LocalId == m_rootPart.LocalId)
  3098. {
  3099. unlinkroot = true;
  3100. continue;
  3101. }
  3102. lock (m_parts.SyncRoot)
  3103. if(!m_parts.Remove(linkPart.UUID))
  3104. continue;
  3105. linkPart.ClearUndoState();
  3106. Vector3 worldPos = linkPart.GetWorldPosition();
  3107. Quaternion worldRot = linkPart.GetWorldRotation();
  3108. linkPart.ParentID = 0;
  3109. linkPart.LinkNum = 0;
  3110. PhysicsActor linkPartPa = linkPart.PhysActor;
  3111. // Remove the SOP from the physical scene.
  3112. // If the new SOG is physical, it is re-created later.
  3113. // (There is a problem here in that we have not yet told the physics
  3114. // engine about the delink. Someday, linksets should be made first
  3115. // class objects in the physics engine interface).
  3116. if (linkPartPa != null)
  3117. {
  3118. m_scene.PhysicsScene.RemovePrim(linkPartPa);
  3119. linkPart.PhysActor = null;
  3120. }
  3121. linkPart.setGroupPosition(worldPos);
  3122. linkPart.setOffsetPosition(Vector3.Zero);
  3123. linkPart.setRotationOffset(worldRot);
  3124. // Create a new SOG to go around this unlinked and unattached SOP
  3125. SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart);
  3126. m_scene.AddNewSceneObject(objectGroup, true);
  3127. linkPart.Rezzed = RootPart.Rezzed;
  3128. // this is as it seems to be in sl now
  3129. if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none)
  3130. linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now
  3131. objectGroup.HasGroupChangedDueToDelink = true;
  3132. if (sendEvents)
  3133. linkPart.TriggerScriptChangedEvent(Changed.LINK);
  3134. }
  3135. if(unlinkroot)
  3136. {
  3137. //TODO
  3138. }
  3139. lock (m_parts.SyncRoot)
  3140. {
  3141. SceneObjectPart[] parts = m_parts.GetArray();
  3142. if (parts.Length == 1)
  3143. {
  3144. // Single prim left
  3145. m_rootPart.LinkNum = 0;
  3146. }
  3147. else
  3148. {
  3149. m_rootPart.LinkNum = 1;
  3150. int linknum = 2;
  3151. for (int i = 1; i < parts.Length; i++)
  3152. parts[i].LinkNum = linknum++;
  3153. }
  3154. }
  3155. InvalidBoundsRadius();
  3156. if (m_rootPart.PhysActor != null)
  3157. m_rootPart.PhysActor.Building = false;
  3158. // When we delete a group, we currently have to force persist to the database if the object id has changed
  3159. // (since delete works by deleting all rows which have a given object id)
  3160. Scene.SimulationDataService.RemoveObject(UUID, Scene.RegionInfo.RegionID);
  3161. HasGroupChangedDueToDelink = true;
  3162. TriggerScriptChangedEvent(Changed.LINK);
  3163. return;
  3164. }
  3165. */
  3166. /// <summary>
  3167. /// Stop this object from being persisted over server restarts.
  3168. /// </summary>
  3169. /// <param name="objectGroup"></param>
  3170. public virtual void DetachFromBackup()
  3171. {
  3172. if (m_scene != null)
  3173. {
  3174. m_scene.SceneGraph.FireDetachFromBackup(this);
  3175. if (Backup)
  3176. m_scene.EventManager.OnBackup -= ProcessBackup;
  3177. }
  3178. Backup = false;
  3179. }
  3180. // This links an SOP from a previous linkset into my linkset.
  3181. // The trick is that the SOP's position and rotation are relative to the old root SOP's
  3182. // so we are passed in the position and rotation of the old linkset so this can
  3183. // unjigger this SOP's position and rotation from the previous linkset and
  3184. // then make them relative to my linkset root.
  3185. private void LinkNonRootPart(SceneObjectPart part, Vector3 oldGroupPosition, Quaternion oldGroupRotation, int linkNum)
  3186. {
  3187. Quaternion parentRot = oldGroupRotation;
  3188. Quaternion oldRot = part.RotationOffset;
  3189. // Move our position in world
  3190. Vector3 axPos = part.OffsetPosition;
  3191. axPos *= parentRot;
  3192. Vector3 newPos = oldGroupPosition + axPos;
  3193. part.setGroupPosition(newPos);
  3194. part.setOffsetPosition(Vector3.Zero);
  3195. // Compution our rotation in world
  3196. Quaternion worldRot = parentRot * oldRot;
  3197. part.RotationOffset = worldRot;
  3198. // Add this SOP to our linkset
  3199. part.SetParent(this);
  3200. part.ParentID = m_rootPart.LocalId;
  3201. m_parts.Add(part.UUID, part);
  3202. part.LinkNum = linkNum;
  3203. m_scene.updateScenePartGroup(part, this);
  3204. // Compute the new position of this SOP relative to the group position
  3205. part.setOffsetPosition(newPos - AbsolutePosition);
  3206. // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times.
  3207. // It would have the affect of setting the physics engine position multiple
  3208. // times. In theory, that is not necessary but I don't have a good linkset
  3209. // test to know that cleaning up this code wouldn't break things.)
  3210. // Compute the SOP's rotation relative to the rotation of the group.
  3211. parentRot = m_rootPart.RotationOffset;
  3212. oldRot = part.RotationOffset;
  3213. Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot;
  3214. part.setRotationOffset(newRot);
  3215. Vector3 pos = part.OffsetPosition;
  3216. pos *= Quaternion.Conjugate(parentRot);
  3217. part.OffsetPosition = pos; // update position and orientation on physics also
  3218. // Since this SOP's state has changed, push those changes into the physics engine
  3219. // and the simulator.
  3220. // done on caller
  3221. // part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false);
  3222. }
  3223. /// <summary>
  3224. /// If object is physical, apply force to move it around
  3225. /// If object is not physical, just put it at the resulting location
  3226. /// </summary>
  3227. /// <param name="partID">Part ID to check for grab</param>
  3228. /// <param name="offset">Always seems to be 0,0,0, so ignoring</param>
  3229. /// <param name="pos">New position. We do the math here to turn it into a force</param>
  3230. /// <param name="remoteClient"></param>
  3231. public void GrabMovement(UUID partID, Vector3 offset, Vector3 pos, IClientAPI remoteClient)
  3232. {
  3233. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3234. {
  3235. if (BlockGrabOverride)
  3236. return;
  3237. SceneObjectPart part = GetPart(partID);
  3238. if (part == null)
  3239. return;
  3240. if (part.BlockGrab)
  3241. return;
  3242. PhysicsActor pa = m_rootPart.PhysActor;
  3243. if (pa != null && pa.IsPhysical)
  3244. {
  3245. // empirically convert distance diference to a impulse
  3246. Vector3 grabforce = pos - AbsolutePosition;
  3247. grabforce = grabforce * (pa.Mass * 0.1f);
  3248. pa.AddForce(grabforce, false);
  3249. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3250. }
  3251. else
  3252. {
  3253. NonPhysicalGrabMovement(pos);
  3254. }
  3255. }
  3256. }
  3257. /// <summary>
  3258. /// Apply possition for grabbing non-physical linksets (Ctrl+Drag)
  3259. /// This MUST be blocked for linksets that contain touch scripts because the viewer triggers grab on the touch
  3260. /// event (Viewer Bug?) This would allow anyone to drag a linkset with a touch script. SL behaviour is also to
  3261. /// block grab on prims with touch events.
  3262. /// </summary>
  3263. /// <param name="pos">New Position</param>
  3264. public void NonPhysicalGrabMovement(Vector3 pos)
  3265. {
  3266. if(!IsAttachment && ScriptCount() == 0)
  3267. UpdateGroupPosition(pos);
  3268. }
  3269. /// <summary>
  3270. /// If object is physical, prepare for spinning torques (set flag to save old orientation)
  3271. /// </summary>
  3272. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3273. /// <param name="remoteClient"></param>
  3274. public void SpinStart(IClientAPI remoteClient)
  3275. {
  3276. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3277. return;
  3278. if (m_scene.EventManager.TriggerGroupSpinStart(UUID))
  3279. {
  3280. PhysicsActor pa = m_rootPart.PhysActor;
  3281. if (pa != null)
  3282. {
  3283. if (pa.IsPhysical)
  3284. {
  3285. m_rootPart.IsWaitingForFirstSpinUpdatePacket = true;
  3286. }
  3287. }
  3288. }
  3289. }
  3290. /// <summary>
  3291. /// If object is physical, apply torque to spin it around
  3292. /// </summary>
  3293. /// <param name="rotation">Rotation. We do the math here to turn it into a torque</param>
  3294. /// <param name="remoteClient"></param>
  3295. public void SpinMovement(Quaternion newOrientation, IClientAPI remoteClient)
  3296. {
  3297. // The incoming newOrientation, sent by the client, "seems" to be the
  3298. // desired target orientation. This needs further verification; in particular,
  3299. // one would expect that the initial incoming newOrientation should be
  3300. // fairly close to the original prim's physical orientation,
  3301. // m_rootPart.PhysActor.Orientation. This however does not seem to be the
  3302. // case (might just be an issue with different quaternions representing the
  3303. // same rotation, or it might be a coordinate system issue).
  3304. //
  3305. // Since it's not clear what the relationship is between the PhysActor.Orientation
  3306. // and the incoming orientations sent by the client, we take an alternative approach
  3307. // of calculating the delta rotation between the orientations being sent by the
  3308. // client. (Since a spin is invoked by ctrl+shift+drag in the client, we expect
  3309. // a steady stream of several new orientations coming in from the client.)
  3310. // This ensures that the delta rotations are being calculated from self-consistent
  3311. // pairs of old/new rotations. Given the delta rotation, we apply a torque around
  3312. // the delta rotation axis, scaled by the object mass times an arbitrary scaling
  3313. // factor (to ensure the resulting torque is not "too strong" or "too weak").
  3314. //
  3315. // Ideally we need to calculate (probably iteratively) the exact torque or series
  3316. // of torques needed to arrive exactly at the destination orientation. However, since
  3317. // it is not yet clear how to map the destination orientation (provided by the viewer)
  3318. // into PhysActor orientations (needed by the physics engine), we omit this step.
  3319. // This means that the resulting torque will at least be in the correct direction,
  3320. // but it will result in over-shoot or under-shoot of the target orientation.
  3321. // For the end user, this means that ctrl+shift+drag can be used for relative,
  3322. // but not absolute, adjustments of orientation for physical prims.
  3323. if (BlockGrabOverride || m_rootPart.BlockGrab)
  3324. return;
  3325. if (m_scene.EventManager.TriggerGroupSpin(UUID, newOrientation))
  3326. {
  3327. PhysicsActor pa = m_rootPart.PhysActor;
  3328. if (pa != null && pa.IsPhysical)
  3329. {
  3330. if (m_rootPart.IsWaitingForFirstSpinUpdatePacket)
  3331. {
  3332. // first time initialization of "old" orientation for calculation of delta rotations
  3333. m_rootPart.SpinOldOrientation = newOrientation;
  3334. m_rootPart.IsWaitingForFirstSpinUpdatePacket = false;
  3335. }
  3336. else
  3337. {
  3338. // save and update old orientation
  3339. Quaternion old = m_rootPart.SpinOldOrientation;
  3340. m_rootPart.SpinOldOrientation = newOrientation;
  3341. //m_log.Error("[SCENE OBJECT GROUP]: Old orientation is " + old);
  3342. //m_log.Error("[SCENE OBJECT GROUP]: Incoming new orientation is " + newOrientation);
  3343. // compute difference between previous old rotation and new incoming rotation
  3344. Quaternion minimalRotationFromQ1ToQ2 = newOrientation * Quaternion.Inverse(old);
  3345. float rotationAngle;
  3346. Vector3 spinforce;
  3347. minimalRotationFromQ1ToQ2.GetAxisAngle(out spinforce, out rotationAngle);
  3348. if(Math.Abs(rotationAngle)< 0.001)
  3349. return;
  3350. spinforce.Normalize();
  3351. //m_log.Error("SCENE OBJECT GROUP]: rotation axis is " + rotationAxis);
  3352. if(rotationAngle > 0)
  3353. spinforce = spinforce * pa.Mass * 0.1f; // 0.1 is an arbitrary torque scaling factor
  3354. else
  3355. spinforce = spinforce * pa.Mass * -0.1f; // 0.1 is an arbitrary torque scaling
  3356. pa.AddAngularForce(spinforce,true);
  3357. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3358. }
  3359. }
  3360. else
  3361. {
  3362. NonPhysicalSpinMovement(newOrientation);
  3363. }
  3364. }
  3365. }
  3366. /// <summary>
  3367. /// Apply rotation for spinning non-physical linksets (Ctrl+Shift+Drag)
  3368. /// As with dragging, scripted objects must be blocked from spinning
  3369. /// </summary>
  3370. /// <param name="newOrientation">New Rotation</param>
  3371. private void NonPhysicalSpinMovement(Quaternion newOrientation)
  3372. {
  3373. if(!IsAttachment && ScriptCount() == 0)
  3374. UpdateGroupRotationR(newOrientation);
  3375. }
  3376. /// <summary>
  3377. /// Set the name of a prim
  3378. /// </summary>
  3379. /// <param name="name"></param>
  3380. /// <param name="localID"></param>
  3381. public void SetPartName(string name, uint localID)
  3382. {
  3383. SceneObjectPart part = GetPart(localID);
  3384. if (part != null)
  3385. {
  3386. part.Name = name;
  3387. }
  3388. }
  3389. public void SetPartDescription(string des, uint localID)
  3390. {
  3391. SceneObjectPart part = GetPart(localID);
  3392. if (part != null)
  3393. {
  3394. part.Description = des;
  3395. }
  3396. }
  3397. public void SetPartText(string text, uint localID)
  3398. {
  3399. SceneObjectPart part = GetPart(localID);
  3400. if (part != null)
  3401. {
  3402. part.SetText(text);
  3403. }
  3404. }
  3405. public void SetPartText(string text, UUID partID)
  3406. {
  3407. SceneObjectPart part = GetPart(partID);
  3408. if (part != null)
  3409. {
  3410. part.SetText(text);
  3411. }
  3412. }
  3413. public string GetPartName(uint localID)
  3414. {
  3415. SceneObjectPart part = GetPart(localID);
  3416. if (part != null)
  3417. {
  3418. return part.Name;
  3419. }
  3420. return String.Empty;
  3421. }
  3422. public string GetPartDescription(uint localID)
  3423. {
  3424. SceneObjectPart part = GetPart(localID);
  3425. if (part != null)
  3426. {
  3427. return part.Description;
  3428. }
  3429. return String.Empty;
  3430. }
  3431. /// <summary>
  3432. /// Update prim flags for this group.
  3433. /// </summary>
  3434. /// <param name="localID"></param>
  3435. /// <param name="UsePhysics"></param>
  3436. /// <param name="SetTemporary"></param>
  3437. /// <param name="SetPhantom"></param>
  3438. /// <param name="SetVolumeDetect"></param>
  3439. public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect)
  3440. {
  3441. HasGroupChanged = true;
  3442. SceneObjectPart selectionPart = GetPart(localID);
  3443. if (Scene != null)
  3444. {
  3445. if (SetTemporary)
  3446. {
  3447. DetachFromBackup();
  3448. // Remove from database and parcel prim count
  3449. //
  3450. m_scene.DeleteFromStorage(UUID);
  3451. }
  3452. else if (!Backup)
  3453. {
  3454. // Previously been temporary now switching back so make it
  3455. // available for persisting again
  3456. AttachToBackup();
  3457. }
  3458. m_scene.EventManager.TriggerParcelPrimCountTainted();
  3459. }
  3460. if (selectionPart != null)
  3461. {
  3462. SceneObjectPart[] parts = m_parts.GetArray();
  3463. if (Scene != null && UsePhysics)
  3464. {
  3465. int maxprims = m_scene.m_linksetPhysCapacity;
  3466. bool checkShape = (maxprims > 0 &&
  3467. parts.Length > maxprims);
  3468. for (int i = 0; i < parts.Length; i++)
  3469. {
  3470. SceneObjectPart part = parts[i];
  3471. if(part.PhysicsShapeType == (byte)PhysicsShapeType.None)
  3472. continue; // assuming root type was checked elsewhere
  3473. if (checkShape)
  3474. {
  3475. if (--maxprims < 0)
  3476. {
  3477. UsePhysics = false;
  3478. break;
  3479. }
  3480. }
  3481. if (part.Scale.X > m_scene.m_maxPhys ||
  3482. part.Scale.Y > m_scene.m_maxPhys ||
  3483. part.Scale.Z > m_scene.m_maxPhys )
  3484. {
  3485. UsePhysics = false; // Reset physics
  3486. break;
  3487. }
  3488. }
  3489. }
  3490. if (parts.Length > 1)
  3491. {
  3492. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3493. for (int i = 0; i < parts.Length; i++)
  3494. {
  3495. if (parts[i].UUID != m_rootPart.UUID)
  3496. parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true);
  3497. }
  3498. if (m_rootPart.PhysActor != null)
  3499. m_rootPart.PhysActor.Building = false;
  3500. }
  3501. else
  3502. m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false);
  3503. }
  3504. }
  3505. public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data)
  3506. {
  3507. SceneObjectPart part = GetPart(localID);
  3508. if (part != null)
  3509. {
  3510. part.UpdateExtraParam(type, inUse, data);
  3511. }
  3512. }
  3513. /// <summary>
  3514. /// Gets the number of parts
  3515. /// </summary>
  3516. /// <returns></returns>
  3517. public int GetPartCount()
  3518. {
  3519. return Parts.Count();
  3520. }
  3521. /// <summary>
  3522. /// Update the texture entry for this part
  3523. /// </summary>
  3524. /// <param name="localID"></param>
  3525. /// <param name="textureEntry"></param>
  3526. public void UpdateTextureEntry(uint localID, byte[] textureEntry)
  3527. {
  3528. SceneObjectPart part = GetPart(localID);
  3529. if (part != null)
  3530. {
  3531. part.UpdateTextureEntry(textureEntry);
  3532. }
  3533. }
  3534. public void AdjustChildPrimPermissions(bool forceTaskInventoryPermissive)
  3535. {
  3536. uint newOwnerMask = (uint)(PermissionMask.All | PermissionMask.Export) & 0xfffffff0; // Mask folded bits
  3537. uint foldedPerms = RootPart.OwnerMask & (uint)PermissionMask.FoldedMask;
  3538. ForEachPart(part =>
  3539. {
  3540. newOwnerMask &= part.BaseMask;
  3541. if (part != RootPart)
  3542. part.ClonePermissions(RootPart);
  3543. if (forceTaskInventoryPermissive)
  3544. part.Inventory.ApplyGodPermissions(part.BaseMask);
  3545. });
  3546. uint lockMask = ~(uint)(PermissionMask.Move);
  3547. uint lockBit = RootPart.OwnerMask & (uint)(PermissionMask.Move);
  3548. RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask);
  3549. // m_log.DebugFormat(
  3550. // "[SCENE OBJECT GROUP]: RootPart.OwnerMask now {0} for {1} in {2}",
  3551. // (OpenMetaverse.PermissionMask)RootPart.OwnerMask, Name, Scene.Name);
  3552. InvalidateEffectivePerms();
  3553. RootPart.ScheduleFullUpdate();
  3554. }
  3555. public void UpdatePermissions(UUID AgentID, byte field, uint localID,
  3556. uint mask, byte addRemTF)
  3557. {
  3558. RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF);
  3559. bool god = Scene.Permissions.IsGod(AgentID);
  3560. if (field == 1 && god)
  3561. {
  3562. ForEachPart(part =>
  3563. {
  3564. part.BaseMask = RootPart.BaseMask;
  3565. });
  3566. }
  3567. AdjustChildPrimPermissions(false);
  3568. if (field == 1 && god) // Base mask was set. Update all child part inventories
  3569. {
  3570. foreach (SceneObjectPart part in Parts)
  3571. part.Inventory.ApplyGodPermissions(RootPart.BaseMask);
  3572. InvalidateEffectivePerms();
  3573. }
  3574. HasGroupChanged = true;
  3575. // Send the group's properties to all clients once all parts are updated
  3576. IClientAPI client;
  3577. if (Scene.TryGetClient(AgentID, out client))
  3578. SendPropertiesToClient(client);
  3579. }
  3580. #endregion
  3581. #region Shape
  3582. /// <summary>
  3583. ///
  3584. /// </summary>
  3585. /// <param name="shapeBlock"></param>
  3586. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock, uint localID)
  3587. {
  3588. SceneObjectPart part = GetPart(localID);
  3589. if (part != null)
  3590. {
  3591. part.UpdateShape(shapeBlock);
  3592. PhysicsActor pa = m_rootPart.PhysActor;
  3593. if (pa != null)
  3594. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3595. }
  3596. InvalidBoundsRadius();
  3597. }
  3598. #endregion
  3599. #region Resize
  3600. /// <summary>
  3601. /// Resize the entire group of prims.
  3602. /// </summary>
  3603. /// <param name="scale"></param>
  3604. public void GroupResize(Vector3 scale)
  3605. {
  3606. // m_log.DebugFormat(
  3607. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
  3608. if (Scene == null)
  3609. return;
  3610. PhysicsActor pa = m_rootPart.PhysActor;
  3611. float minsize = Scene.m_minNonphys;
  3612. float maxsize = Scene.m_maxNonphys;
  3613. if (pa != null && pa.IsPhysical)
  3614. {
  3615. minsize = Scene.m_minPhys;
  3616. maxsize = Scene.m_maxPhys;
  3617. }
  3618. scale.X = Util.Clamp(scale.X, minsize, maxsize);
  3619. scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
  3620. scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
  3621. // requested scaling factors
  3622. float x = (scale.X / RootPart.Scale.X);
  3623. float y = (scale.Y / RootPart.Scale.Y);
  3624. float z = (scale.Z / RootPart.Scale.Z);
  3625. SceneObjectPart[] parts = m_parts.GetArray();
  3626. // fix scaling factors so parts don't violate dimensions
  3627. for(int i = 0;i < parts.Length;i++)
  3628. {
  3629. SceneObjectPart obPart = parts[i];
  3630. if(obPart.UUID != m_rootPart.UUID)
  3631. {
  3632. Vector3 oldSize = new Vector3(obPart.Scale);
  3633. float f = 1.0f;
  3634. float a = 1.0f;
  3635. if(oldSize.X * x > maxsize)
  3636. {
  3637. f = maxsize / oldSize.X;
  3638. a = f / x;
  3639. x *= a;
  3640. y *= a;
  3641. z *= a;
  3642. }
  3643. else if(oldSize.X * x < minsize)
  3644. {
  3645. f = minsize / oldSize.X;
  3646. a = f / x;
  3647. x *= a;
  3648. y *= a;
  3649. z *= a;
  3650. }
  3651. if(oldSize.Y * y > maxsize)
  3652. {
  3653. f = maxsize / oldSize.Y;
  3654. a = f / y;
  3655. x *= a;
  3656. y *= a;
  3657. z *= a;
  3658. }
  3659. else if(oldSize.Y * y < minsize)
  3660. {
  3661. f = minsize / oldSize.Y;
  3662. a = f / y;
  3663. x *= a;
  3664. y *= a;
  3665. z *= a;
  3666. }
  3667. if(oldSize.Z * z > maxsize)
  3668. {
  3669. f = maxsize / oldSize.Z;
  3670. a = f / z;
  3671. x *= a;
  3672. y *= a;
  3673. z *= a;
  3674. }
  3675. else if(oldSize.Z * z < minsize)
  3676. {
  3677. f = minsize / oldSize.Z;
  3678. a = f / z;
  3679. x *= a;
  3680. y *= a;
  3681. z *= a;
  3682. }
  3683. }
  3684. }
  3685. Vector3 rootScale = RootPart.Scale;
  3686. rootScale.X *= x;
  3687. rootScale.Y *= y;
  3688. rootScale.Z *= z;
  3689. RootPart.Scale = rootScale;
  3690. for (int i = 0; i < parts.Length; i++)
  3691. {
  3692. SceneObjectPart obPart = parts[i];
  3693. if (obPart.UUID != m_rootPart.UUID)
  3694. {
  3695. Vector3 currentpos = new Vector3(obPart.OffsetPosition);
  3696. currentpos.X *= x;
  3697. currentpos.Y *= y;
  3698. currentpos.Z *= z;
  3699. Vector3 newSize = new Vector3(obPart.Scale);
  3700. newSize.X *= x;
  3701. newSize.Y *= y;
  3702. newSize.Z *= z;
  3703. obPart.Scale = newSize;
  3704. obPart.UpdateOffSet(currentpos);
  3705. }
  3706. }
  3707. InvalidBoundsRadius();
  3708. HasGroupChanged = true;
  3709. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3710. ScheduleGroupForFullUpdate();
  3711. }
  3712. public bool GroupResize(double fscale)
  3713. {
  3714. // m_log.DebugFormat(
  3715. // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, fscale);
  3716. if (Scene == null || IsDeleted || inTransit || fscale < 0)
  3717. return false;
  3718. // ignore lsl restrictions. let them be done a LSL
  3719. PhysicsActor pa = m_rootPart.PhysActor;
  3720. if(RootPart.KeyframeMotion != null)
  3721. RootPart.KeyframeMotion.Suspend();
  3722. float minsize = Scene.m_minNonphys;
  3723. float maxsize = Scene.m_maxNonphys;
  3724. // assuming physics is more restrictive
  3725. if (pa != null && pa.IsPhysical)
  3726. {
  3727. minsize = Scene.m_minPhys;
  3728. maxsize = Scene.m_maxPhys;
  3729. }
  3730. SceneObjectPart[] parts = m_parts.GetArray();
  3731. float tmp;
  3732. // check scaling factor so parts don't violate dimensions
  3733. for(int i = 0; i < parts.Length; i++)
  3734. {
  3735. SceneObjectPart obPart = parts[i];
  3736. Vector3 oldSize = new Vector3(obPart.Scale);
  3737. tmp = (float)(oldSize.X * fscale);
  3738. if(tmp > maxsize)
  3739. return false;
  3740. if(tmp < minsize)
  3741. return false;
  3742. tmp = (float)(oldSize.Y * fscale);
  3743. if(tmp > maxsize)
  3744. return false;
  3745. if(tmp < minsize)
  3746. return false;
  3747. tmp = (float)(oldSize.Z * fscale);
  3748. if(tmp > maxsize)
  3749. return false;
  3750. if(tmp < minsize)
  3751. return false;
  3752. }
  3753. Vector3 newSize = RootPart.Scale;
  3754. newSize.X = (float)(newSize.X * fscale);
  3755. newSize.Y = (float)(newSize.Y * fscale);
  3756. newSize.Z = (float)(newSize.Z * fscale);
  3757. if(pa != null)
  3758. pa.Building = true;
  3759. RootPart.Scale = newSize;
  3760. Vector3 currentpos;
  3761. for (int i = 0; i < parts.Length; i++)
  3762. {
  3763. SceneObjectPart obPart = parts[i];
  3764. if (obPart.UUID != m_rootPart.UUID)
  3765. {
  3766. currentpos = obPart.OffsetPosition;
  3767. currentpos.X = (float)(currentpos.X * fscale);
  3768. currentpos.Y = (float)(currentpos.Y * fscale);
  3769. currentpos.Z = (float)(currentpos.Z * fscale);
  3770. newSize = obPart.Scale;
  3771. newSize.X = (float)(newSize.X * fscale);
  3772. newSize.Y = (float)(newSize.Y * fscale);
  3773. newSize.Z = (float)(newSize.Z * fscale);
  3774. obPart.Scale = newSize;
  3775. obPart.UpdateOffSet(currentpos);
  3776. }
  3777. }
  3778. if(pa != null)
  3779. pa.Building = false;
  3780. InvalidBoundsRadius();
  3781. HasGroupChanged = true;
  3782. m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
  3783. ScheduleGroupForFullUpdate();
  3784. if(RootPart.KeyframeMotion != null)
  3785. RootPart.KeyframeMotion.Resume();
  3786. return true;
  3787. }
  3788. public float GetMaxGroupResizeScale()
  3789. {
  3790. if (Scene == null || IsDeleted || inTransit)
  3791. return 1.0f;
  3792. float maxsize = Scene.m_maxNonphys;
  3793. PhysicsActor pa = m_rootPart.PhysActor;
  3794. // assuming physics is more restrictive
  3795. if (pa != null && pa.IsPhysical)
  3796. maxsize = Scene.m_maxPhys;
  3797. SceneObjectPart[] parts = m_parts.GetArray();
  3798. float larger = float.MinValue;
  3799. for(int i = 0; i < parts.Length; i++)
  3800. {
  3801. SceneObjectPart obPart = parts[i];
  3802. Vector3 oldSize = new Vector3(obPart.Scale);
  3803. if(larger < oldSize.X)
  3804. larger = oldSize.X;
  3805. if(larger < oldSize.Y)
  3806. larger = oldSize.Y;
  3807. if(larger < oldSize.Z)
  3808. larger = oldSize.Z;
  3809. }
  3810. if(larger >= maxsize)
  3811. return 1.0f;
  3812. larger += 1e-3f;
  3813. float fscale = maxsize / larger;
  3814. return fscale;
  3815. }
  3816. public float GetMinGroupResizeScale()
  3817. {
  3818. if (Scene == null || IsDeleted || inTransit)
  3819. return 1.0f;
  3820. float minsize = Scene.m_minNonphys;
  3821. PhysicsActor pa = m_rootPart.PhysActor;
  3822. // assuming physics is more restrictive
  3823. if (pa != null && pa.IsPhysical)
  3824. minsize = Scene.m_minPhys;
  3825. SceneObjectPart[] parts = m_parts.GetArray();
  3826. float smaller = float.MaxValue;
  3827. for(int i = 0; i < parts.Length; i++)
  3828. {
  3829. SceneObjectPart obPart = parts[i];
  3830. Vector3 oldSize = new Vector3(obPart.Scale);
  3831. if(smaller > oldSize.X)
  3832. smaller = oldSize.X;
  3833. if(smaller > oldSize.Y)
  3834. smaller = oldSize.Y;
  3835. if(smaller > oldSize.Z)
  3836. smaller = oldSize.Z;
  3837. }
  3838. if(smaller <= minsize)
  3839. return 1.0f;
  3840. if(smaller > 2e-3f)
  3841. smaller -= 1e-3f;
  3842. float fscale = minsize / smaller;
  3843. if(fscale < 1e-8f)
  3844. fscale = 1e-8f;
  3845. return fscale;
  3846. }
  3847. #endregion
  3848. #region Position
  3849. /// <summary>
  3850. /// Move this scene object
  3851. /// </summary>
  3852. /// <param name="pos"></param>
  3853. public void UpdateGroupPosition(Vector3 pos)
  3854. {
  3855. if (m_scene.EventManager.TriggerGroupMove(UUID, pos))
  3856. {
  3857. if (IsAttachment)
  3858. {
  3859. m_rootPart.AttachedPos = pos;
  3860. }
  3861. if (RootPart.GetStatusSandbox())
  3862. {
  3863. if (Util.GetDistanceTo(RootPart.StatusSandboxPos, pos) > 10)
  3864. {
  3865. RootPart.ScriptSetPhysicsStatus(false);
  3866. pos = AbsolutePosition;
  3867. Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3868. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, RootPart.AbsolutePosition, Name, UUID, false);
  3869. }
  3870. }
  3871. AbsolutePosition = pos;
  3872. HasGroupChanged = true;
  3873. }
  3874. //we need to do a terse update even if the move wasn't allowed
  3875. // so that the position is reset in the client (the object snaps back)
  3876. RootPart.ScheduleTerseUpdate();
  3877. }
  3878. /// <summary>
  3879. /// Update the position of a single part of this scene object
  3880. /// </summary>
  3881. /// <param name="pos"></param>
  3882. /// <param name="localID"></param>
  3883. ///
  3884. public void UpdateSinglePosition(Vector3 pos, uint localID)
  3885. {
  3886. SceneObjectPart part = GetPart(localID);
  3887. if (part != null)
  3888. {
  3889. // unlock parts position change
  3890. if (m_rootPart.PhysActor != null)
  3891. m_rootPart.PhysActor.Building = true;
  3892. if (part.UUID == m_rootPart.UUID)
  3893. {
  3894. UpdateRootPosition(pos);
  3895. }
  3896. else
  3897. {
  3898. part.UpdateOffSet(pos);
  3899. }
  3900. if (m_rootPart.PhysActor != null)
  3901. m_rootPart.PhysActor.Building = false;
  3902. HasGroupChanged = true;
  3903. }
  3904. }
  3905. /// <summary>
  3906. /// Update just the root prim position in a linkset
  3907. /// </summary>
  3908. /// <param name="newPos"></param>
  3909. public void UpdateRootPosition(Vector3 newPos)
  3910. {
  3911. // needs to be called with phys building true
  3912. Vector3 oldPos;
  3913. if (IsAttachment)
  3914. oldPos = m_rootPart.AttachedPos + m_rootPart.OffsetPosition; // OffsetPosition should always be 0 in an attachments's root prim
  3915. else
  3916. oldPos = AbsolutePosition + m_rootPart.OffsetPosition;
  3917. Vector3 diff = oldPos - newPos;
  3918. Quaternion partRotation = m_rootPart.RotationOffset;
  3919. diff *= Quaternion.Inverse(partRotation);
  3920. SceneObjectPart[] parts = m_parts.GetArray();
  3921. for (int i = 0; i < parts.Length; i++)
  3922. {
  3923. SceneObjectPart obPart = parts[i];
  3924. if (obPart.UUID != m_rootPart.UUID)
  3925. obPart.OffsetPosition = obPart.OffsetPosition + diff;
  3926. }
  3927. AbsolutePosition = newPos;
  3928. if (IsAttachment)
  3929. m_rootPart.AttachedPos = newPos;
  3930. HasGroupChanged = true;
  3931. if (m_rootPart.Undoing)
  3932. {
  3933. ScheduleGroupForFullUpdate();
  3934. }
  3935. else
  3936. {
  3937. ScheduleGroupForTerseUpdate();
  3938. }
  3939. }
  3940. #endregion
  3941. #region Rotation
  3942. /// <summary>
  3943. /// Update the rotation of the group.
  3944. /// </summary>
  3945. /// <param name="rot"></param>
  3946. public void UpdateGroupRotationR(Quaternion rot)
  3947. {
  3948. m_rootPart.UpdateRotation(rot);
  3949. /* this is done by rootpart RotationOffset set called by UpdateRotation
  3950. PhysicsActor actor = m_rootPart.PhysActor;
  3951. if (actor != null)
  3952. {
  3953. actor.Orientation = m_rootPart.RotationOffset;
  3954. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3955. }
  3956. */
  3957. HasGroupChanged = true;
  3958. ScheduleGroupForTerseUpdate();
  3959. }
  3960. /// <summary>
  3961. /// Update the position and rotation of a group simultaneously.
  3962. /// </summary>
  3963. /// <param name="pos"></param>
  3964. /// <param name="rot"></param>
  3965. public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot)
  3966. {
  3967. m_rootPart.UpdateRotation(rot);
  3968. PhysicsActor actor = m_rootPart.PhysActor;
  3969. if (actor != null)
  3970. {
  3971. actor.Orientation = m_rootPart.RotationOffset;
  3972. m_scene.PhysicsScene.AddPhysicsActorTaint(actor);
  3973. }
  3974. if (IsAttachment)
  3975. {
  3976. m_rootPart.AttachedPos = pos;
  3977. }
  3978. AbsolutePosition = pos;
  3979. HasGroupChanged = true;
  3980. ScheduleGroupForTerseUpdate();
  3981. }
  3982. /// <summary>
  3983. /// Update the rotation of a single prim within the group.
  3984. /// </summary>
  3985. /// <param name="rot"></param>
  3986. /// <param name="localID"></param>
  3987. public void UpdateSingleRotation(Quaternion rot, uint localID)
  3988. {
  3989. SceneObjectPart part = GetPart(localID);
  3990. SceneObjectPart[] parts = m_parts.GetArray();
  3991. if (part != null)
  3992. {
  3993. if (m_rootPart.PhysActor != null)
  3994. m_rootPart.PhysActor.Building = true;
  3995. if (part.UUID == m_rootPart.UUID)
  3996. {
  3997. UpdateRootRotation(rot);
  3998. }
  3999. else
  4000. {
  4001. part.UpdateRotation(rot);
  4002. }
  4003. if (m_rootPart.PhysActor != null)
  4004. m_rootPart.PhysActor.Building = false;
  4005. }
  4006. }
  4007. /// <summary>
  4008. /// Update the position and rotation simultaneously of a single prim within the group.
  4009. /// </summary>
  4010. /// <param name="rot"></param>
  4011. /// <param name="localID"></param>
  4012. public void UpdateSingleRotation(Quaternion rot, Vector3 pos, uint localID)
  4013. {
  4014. SceneObjectPart part = GetPart(localID);
  4015. if (part != null)
  4016. {
  4017. if (m_rootPart.PhysActor != null)
  4018. m_rootPart.PhysActor.Building = true;
  4019. if (part.UUID == m_rootPart.UUID)
  4020. {
  4021. UpdateRootRotation(rot);
  4022. AbsolutePosition = pos;
  4023. }
  4024. else
  4025. {
  4026. part.UpdateRotation(rot);
  4027. part.OffsetPosition = pos;
  4028. }
  4029. if (m_rootPart.PhysActor != null)
  4030. m_rootPart.PhysActor.Building = false;
  4031. }
  4032. }
  4033. /// <summary>
  4034. /// Update the rotation of just the root prim of a linkset.
  4035. /// </summary>
  4036. /// <param name="rot"></param>
  4037. public void UpdateRootRotation(Quaternion rot)
  4038. {
  4039. // needs to be called with phys building true
  4040. Quaternion axRot = rot;
  4041. Quaternion oldParentRot = m_rootPart.RotationOffset;
  4042. //Don't use UpdateRotation because it schedules an update prematurely
  4043. m_rootPart.RotationOffset = rot;
  4044. PhysicsActor pa = m_rootPart.PhysActor;
  4045. if (pa != null)
  4046. {
  4047. pa.Orientation = m_rootPart.RotationOffset;
  4048. m_scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4049. }
  4050. SceneObjectPart[] parts = m_parts.GetArray();
  4051. for (int i = 0; i < parts.Length; i++)
  4052. {
  4053. SceneObjectPart prim = parts[i];
  4054. if (prim.UUID != m_rootPart.UUID)
  4055. {
  4056. Quaternion NewRot = oldParentRot * prim.RotationOffset;
  4057. NewRot = Quaternion.Inverse(axRot) * NewRot;
  4058. prim.RotationOffset = NewRot;
  4059. Vector3 axPos = prim.OffsetPosition;
  4060. axPos *= oldParentRot;
  4061. axPos *= Quaternion.Inverse(axRot);
  4062. prim.OffsetPosition = axPos;
  4063. }
  4064. }
  4065. HasGroupChanged = true;
  4066. ScheduleGroupForFullUpdate();
  4067. }
  4068. private enum updatetype :int
  4069. {
  4070. none = 0,
  4071. partterse = 1,
  4072. partfull = 2,
  4073. groupterse = 3,
  4074. groupfull = 4
  4075. }
  4076. public void doChangeObject(SceneObjectPart part, ObjectChangeData data)
  4077. {
  4078. // TODO this still as excessive *.Schedule*Update()s
  4079. if (part != null && part.ParentGroup != null)
  4080. {
  4081. ObjectChangeType change = data.change;
  4082. bool togroup = ((change & ObjectChangeType.Group) != 0);
  4083. // bool uniform = ((what & ObjectChangeType.UniformScale) != 0); not in use
  4084. SceneObjectGroup group = part.ParentGroup;
  4085. PhysicsActor pha = group.RootPart.PhysActor;
  4086. updatetype updateType = updatetype.none;
  4087. if (togroup)
  4088. {
  4089. // related to group
  4090. if ((change & (ObjectChangeType.Rotation | ObjectChangeType.Position)) != 0)
  4091. {
  4092. if ((change & ObjectChangeType.Rotation) != 0)
  4093. {
  4094. group.RootPart.UpdateRotation(data.rotation);
  4095. updateType = updatetype.none;
  4096. }
  4097. if ((change & ObjectChangeType.Position) != 0)
  4098. {
  4099. if (IsAttachment || m_scene.Permissions.CanObjectEntry(group, false, data.position))
  4100. UpdateGroupPosition(data.position);
  4101. updateType = updatetype.groupterse;
  4102. }
  4103. else
  4104. // ugly rotation update of all parts
  4105. {
  4106. group.ResetChildPrimPhysicsPositions();
  4107. }
  4108. }
  4109. if ((change & ObjectChangeType.Scale) != 0)
  4110. {
  4111. if (pha != null)
  4112. pha.Building = true;
  4113. group.GroupResize(data.scale);
  4114. updateType = updatetype.none;
  4115. if (pha != null)
  4116. pha.Building = false;
  4117. }
  4118. }
  4119. else
  4120. {
  4121. // related to single prim in a link-set ( ie group)
  4122. if (pha != null)
  4123. pha.Building = true;
  4124. // root part is special
  4125. // parts offset positions or rotations need to change also
  4126. if (part == group.RootPart)
  4127. {
  4128. if ((change & ObjectChangeType.Rotation) != 0)
  4129. group.UpdateRootRotation(data.rotation);
  4130. if ((change & ObjectChangeType.Position) != 0)
  4131. group.UpdateRootPosition(data.position);
  4132. if ((change & ObjectChangeType.Scale) != 0)
  4133. part.Resize(data.scale);
  4134. }
  4135. else
  4136. {
  4137. if ((change & ObjectChangeType.Position) != 0)
  4138. {
  4139. part.OffsetPosition = data.position;
  4140. updateType = updatetype.partterse;
  4141. }
  4142. if ((change & ObjectChangeType.Rotation) != 0)
  4143. {
  4144. part.UpdateRotation(data.rotation);
  4145. updateType = updatetype.none;
  4146. }
  4147. if ((change & ObjectChangeType.Scale) != 0)
  4148. {
  4149. part.Resize(data.scale);
  4150. updateType = updatetype.none;
  4151. }
  4152. }
  4153. if (pha != null)
  4154. pha.Building = false;
  4155. }
  4156. if (updateType != updatetype.none)
  4157. {
  4158. group.HasGroupChanged = true;
  4159. switch (updateType)
  4160. {
  4161. case updatetype.partterse:
  4162. part.ScheduleTerseUpdate();
  4163. break;
  4164. case updatetype.partfull:
  4165. part.ScheduleFullUpdate();
  4166. break;
  4167. case updatetype.groupterse:
  4168. group.ScheduleGroupForTerseUpdate();
  4169. break;
  4170. case updatetype.groupfull:
  4171. group.ScheduleGroupForFullUpdate();
  4172. break;
  4173. default:
  4174. break;
  4175. }
  4176. }
  4177. }
  4178. }
  4179. #endregion
  4180. internal void SetAxisRotation(int axis, int rotate10)
  4181. {
  4182. bool setX = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0);
  4183. bool setY = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0);
  4184. bool setZ = ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0);
  4185. if (setX || setY || setZ)
  4186. {
  4187. bool lockaxis = (rotate10 == 0); // zero means axis locked
  4188. byte locks = RootPart.RotationAxisLocks;
  4189. if (setX)
  4190. {
  4191. if(lockaxis)
  4192. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X;
  4193. else
  4194. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_X;
  4195. }
  4196. if (setY)
  4197. {
  4198. if(lockaxis)
  4199. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y;
  4200. else
  4201. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Y;
  4202. }
  4203. if (setZ)
  4204. {
  4205. if(lockaxis)
  4206. locks |= (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z;
  4207. else
  4208. locks &= (byte)SceneObjectGroup.axisSelect.NOT_STATUS_ROTATE_Z;
  4209. }
  4210. RootPart.RotationAxisLocks = locks;
  4211. RootPart.SetPhysicsAxisRotation();
  4212. }
  4213. }
  4214. public int GetAxisRotation(int axis)
  4215. {
  4216. byte rotAxislocks = RootPart.RotationAxisLocks;
  4217. // if multiple return the one with higher id
  4218. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z)
  4219. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) == 0 ? 1:0;
  4220. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y)
  4221. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) == 0 ? 1:0;
  4222. if (axis == (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X)
  4223. return (rotAxislocks & (byte)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) == 0 ? 1:0;
  4224. return 0;
  4225. }
  4226. public int registerRotTargetWaypoint(Quaternion target, float tolerance)
  4227. {
  4228. scriptRotTarget waypoint = new scriptRotTarget();
  4229. waypoint.targetRot = target;
  4230. waypoint.tolerance = tolerance;
  4231. uint handle = m_scene.AllocateLocalId();
  4232. waypoint.handle = handle;
  4233. lock (m_rotTargets)
  4234. {
  4235. if (m_rotTargets.Count >= 8)
  4236. m_rotTargets.Remove(m_rotTargets.ElementAt(0).Key);
  4237. m_rotTargets.Add(handle, waypoint);
  4238. }
  4239. m_scene.AddGroupTarget(this);
  4240. return (int)handle;
  4241. }
  4242. public void unregisterRotTargetWaypoint(int handle)
  4243. {
  4244. lock (m_targets)
  4245. {
  4246. m_rotTargets.Remove((uint)handle);
  4247. if (m_targets.Count == 0)
  4248. m_scene.RemoveGroupTarget(this);
  4249. }
  4250. }
  4251. public int registerTargetWaypoint(Vector3 target, float tolerance)
  4252. {
  4253. scriptPosTarget waypoint = new scriptPosTarget();
  4254. waypoint.targetPos = target;
  4255. waypoint.tolerance = tolerance;
  4256. uint handle = m_scene.AllocateLocalId();
  4257. waypoint.handle = handle;
  4258. lock (m_targets)
  4259. {
  4260. if (m_targets.Count >= 8)
  4261. m_targets.Remove(m_targets.ElementAt(0).Key);
  4262. m_targets.Add(handle, waypoint);
  4263. }
  4264. m_scene.AddGroupTarget(this);
  4265. return (int)handle;
  4266. }
  4267. public void unregisterTargetWaypoint(int handle)
  4268. {
  4269. lock (m_targets)
  4270. {
  4271. m_targets.Remove((uint)handle);
  4272. if (m_targets.Count == 0)
  4273. m_scene.RemoveGroupTarget(this);
  4274. }
  4275. }
  4276. public void checkAtTargets()
  4277. {
  4278. if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
  4279. {
  4280. if (m_targets.Count > 0)
  4281. {
  4282. bool at_target = false;
  4283. //Vector3 targetPos;
  4284. //uint targetHandle;
  4285. Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
  4286. lock (m_targets)
  4287. {
  4288. foreach (uint idx in m_targets.Keys)
  4289. {
  4290. scriptPosTarget target = m_targets[idx];
  4291. if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
  4292. {
  4293. at_target = true;
  4294. // trigger at_target
  4295. if (m_scriptListens_atTarget)
  4296. {
  4297. scriptPosTarget att = new scriptPosTarget();
  4298. att.targetPos = target.targetPos;
  4299. att.tolerance = target.tolerance;
  4300. att.handle = target.handle;
  4301. atTargets.Add(idx, att);
  4302. }
  4303. }
  4304. }
  4305. }
  4306. if (atTargets.Count > 0)
  4307. {
  4308. SceneObjectPart[] parts = m_parts.GetArray();
  4309. uint[] localids = new uint[parts.Length];
  4310. for (int i = 0; i < parts.Length; i++)
  4311. localids[i] = parts[i].LocalId;
  4312. for (int ctr = 0; ctr < localids.Length; ctr++)
  4313. {
  4314. foreach (uint target in atTargets.Keys)
  4315. {
  4316. scriptPosTarget att = atTargets[target];
  4317. m_scene.EventManager.TriggerAtTargetEvent(
  4318. localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
  4319. }
  4320. }
  4321. return;
  4322. }
  4323. if (m_scriptListens_notAtTarget && !at_target)
  4324. {
  4325. //trigger not_at_target
  4326. SceneObjectPart[] parts = m_parts.GetArray();
  4327. uint[] localids = new uint[parts.Length];
  4328. for (int i = 0; i < parts.Length; i++)
  4329. localids[i] = parts[i].LocalId;
  4330. for (int ctr = 0; ctr < localids.Length; ctr++)
  4331. {
  4332. m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
  4333. }
  4334. }
  4335. }
  4336. }
  4337. if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
  4338. {
  4339. if (m_rotTargets.Count > 0)
  4340. {
  4341. bool at_Rottarget = false;
  4342. Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
  4343. lock (m_rotTargets)
  4344. {
  4345. foreach (uint idx in m_rotTargets.Keys)
  4346. {
  4347. scriptRotTarget target = m_rotTargets[idx];
  4348. double angle
  4349. = Math.Acos(
  4350. target.targetRot.X * m_rootPart.RotationOffset.X
  4351. + target.targetRot.Y * m_rootPart.RotationOffset.Y
  4352. + target.targetRot.Z * m_rootPart.RotationOffset.Z
  4353. + target.targetRot.W * m_rootPart.RotationOffset.W)
  4354. * 2;
  4355. if (angle < 0) angle = -angle;
  4356. if (angle > Math.PI) angle = (Math.PI * 2 - angle);
  4357. if (angle <= target.tolerance)
  4358. {
  4359. // trigger at_rot_target
  4360. if (m_scriptListens_atRotTarget)
  4361. {
  4362. at_Rottarget = true;
  4363. scriptRotTarget att = new scriptRotTarget();
  4364. att.targetRot = target.targetRot;
  4365. att.tolerance = target.tolerance;
  4366. att.handle = target.handle;
  4367. atRotTargets.Add(idx, att);
  4368. }
  4369. }
  4370. }
  4371. }
  4372. if (atRotTargets.Count > 0)
  4373. {
  4374. SceneObjectPart[] parts = m_parts.GetArray();
  4375. uint[] localids = new uint[parts.Length];
  4376. for (int i = 0; i < parts.Length; i++)
  4377. localids[i] = parts[i].LocalId;
  4378. for (int ctr = 0; ctr < localids.Length; ctr++)
  4379. {
  4380. foreach (uint target in atRotTargets.Keys)
  4381. {
  4382. scriptRotTarget att = atRotTargets[target];
  4383. m_scene.EventManager.TriggerAtRotTargetEvent(
  4384. localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
  4385. }
  4386. }
  4387. return;
  4388. }
  4389. if (m_scriptListens_notAtRotTarget && !at_Rottarget)
  4390. {
  4391. //trigger not_at_target
  4392. SceneObjectPart[] parts = m_parts.GetArray();
  4393. uint[] localids = new uint[parts.Length];
  4394. for (int i = 0; i < parts.Length; i++)
  4395. localids[i] = parts[i].LocalId;
  4396. for (int ctr = 0; ctr < localids.Length; ctr++)
  4397. {
  4398. m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
  4399. }
  4400. }
  4401. }
  4402. }
  4403. }
  4404. public Vector3 GetGeometricCenter()
  4405. {
  4406. // this is not real geometric center but a average of positions relative to root prim acording to
  4407. // http://wiki.secondlife.com/wiki/llGetGeometricCenter
  4408. // ignoring tortured prims details since sl also seems to ignore
  4409. // so no real use in doing it on physics
  4410. Vector3 gc = Vector3.Zero;
  4411. SceneObjectPart[] parts = m_parts.GetArray();
  4412. int nparts = parts.Length;
  4413. if (nparts < 2)
  4414. return gc;
  4415. // average all parts positions
  4416. for (int i = 0; i < nparts; i++)
  4417. {
  4418. if (parts[i] != RootPart)
  4419. gc += parts[i].OffsetPosition;
  4420. }
  4421. gc /= nparts;
  4422. return gc;
  4423. }
  4424. public float GetMass()
  4425. {
  4426. float retmass = 0f;
  4427. SceneObjectPart[] parts = m_parts.GetArray();
  4428. for (int i = 0; i < parts.Length; i++)
  4429. retmass += parts[i].GetMass();
  4430. return retmass;
  4431. }
  4432. // center of mass of full object
  4433. public Vector3 GetCenterOfMass()
  4434. {
  4435. PhysicsActor pa = RootPart.PhysActor;
  4436. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4437. {
  4438. // physics knows better about center of mass of physical prims
  4439. Vector3 tmp = pa.CenterOfMass;
  4440. return tmp;
  4441. }
  4442. Vector3 Ptot = Vector3.Zero;
  4443. float totmass = 0f;
  4444. float m;
  4445. SceneObjectPart[] parts = m_parts.GetArray();
  4446. for (int i = 0; i < parts.Length; i++)
  4447. {
  4448. m = parts[i].GetMass();
  4449. Ptot += parts[i].GetPartCenterOfMass() * m;
  4450. totmass += m;
  4451. }
  4452. if (totmass == 0)
  4453. totmass = 0;
  4454. else
  4455. totmass = 1 / totmass;
  4456. Ptot *= totmass;
  4457. return Ptot;
  4458. }
  4459. public void GetInertiaData(out float TotalMass, out Vector3 CenterOfMass, out Vector3 Inertia, out Vector4 aux )
  4460. {
  4461. PhysicsActor pa = RootPart.PhysActor;
  4462. if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null)
  4463. {
  4464. PhysicsInertiaData inertia;
  4465. inertia = pa.GetInertiaData();
  4466. TotalMass = inertia.TotalMass;
  4467. CenterOfMass = inertia.CenterOfMass;
  4468. Inertia = inertia.Inertia;
  4469. aux = inertia.InertiaRotation;
  4470. return;
  4471. }
  4472. TotalMass = GetMass();
  4473. CenterOfMass = GetCenterOfMass() - AbsolutePosition;
  4474. CenterOfMass *= Quaternion.Conjugate(RootPart.RotationOffset);
  4475. Inertia = Vector3.Zero;
  4476. aux = Vector4.Zero;
  4477. }
  4478. public void SetInertiaData(float TotalMass, Vector3 CenterOfMass, Vector3 Inertia, Vector4 aux )
  4479. {
  4480. PhysicsInertiaData inertia = new PhysicsInertiaData();
  4481. inertia.TotalMass = TotalMass;
  4482. inertia.CenterOfMass = CenterOfMass;
  4483. inertia.Inertia = Inertia;
  4484. inertia.InertiaRotation = aux;
  4485. if(TotalMass < 0)
  4486. RootPart.PhysicsInertia = null;
  4487. else
  4488. RootPart.PhysicsInertia = new PhysicsInertiaData(inertia);
  4489. PhysicsActor pa = RootPart.PhysActor;
  4490. if(pa !=null)
  4491. pa.SetInertiaData(inertia);
  4492. }
  4493. /// <summary>
  4494. /// Set the user group to which this scene object belongs.
  4495. /// </summary>
  4496. /// <param name="GroupID"></param>
  4497. /// <param name="client"></param>
  4498. public void SetGroup(UUID GroupID, IClientAPI client)
  4499. {
  4500. SceneObjectPart[] parts = m_parts.GetArray();
  4501. for (int i = 0; i < parts.Length; i++)
  4502. {
  4503. SceneObjectPart part = parts[i];
  4504. part.SetGroup(GroupID, client);
  4505. part.Inventory.ChangeInventoryGroup(GroupID);
  4506. }
  4507. HasGroupChanged = true;
  4508. // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
  4509. // for the same object with very different properties. The caller must schedule the update.
  4510. //ScheduleGroupForFullUpdate();
  4511. }
  4512. public void TriggerScriptChangedEvent(Changed val)
  4513. {
  4514. SceneObjectPart[] parts = m_parts.GetArray();
  4515. for (int i = 0; i < parts.Length; i++)
  4516. parts[i].TriggerScriptChangedEvent(val);
  4517. }
  4518. /// <summary>
  4519. /// Returns a count of the number of scripts in this groups parts.
  4520. /// </summary>
  4521. public int ScriptCount()
  4522. {
  4523. int count = 0;
  4524. SceneObjectPart[] parts = m_parts.GetArray();
  4525. for (int i = 0; i < parts.Length; i++)
  4526. count += parts[i].Inventory.ScriptCount();
  4527. return count;
  4528. }
  4529. /// <summary>
  4530. /// A float the value is a representative execution time in milliseconds of all scripts in the link set.
  4531. /// </summary>
  4532. public float ScriptExecutionTime()
  4533. {
  4534. IScriptModule[] engines = Scene.RequestModuleInterfaces<IScriptModule>();
  4535. if (engines.Length == 0) // No engine at all
  4536. return 0.0f;
  4537. float time = 0.0f;
  4538. // get all the scripts in all parts
  4539. SceneObjectPart[] parts = m_parts.GetArray();
  4540. List<TaskInventoryItem> scripts = new List<TaskInventoryItem>();
  4541. for (int i = 0; i < parts.Length; i++)
  4542. {
  4543. scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL));
  4544. }
  4545. // extract the UUIDs
  4546. List<UUID> ids = new List<UUID>(scripts.Count);
  4547. foreach (TaskInventoryItem script in scripts)
  4548. {
  4549. if (!ids.Contains(script.ItemID))
  4550. {
  4551. ids.Add(script.ItemID);
  4552. }
  4553. }
  4554. // Offer the list of script UUIDs to each engine found and accumulate the time
  4555. foreach (IScriptModule e in engines)
  4556. {
  4557. if (e != null)
  4558. {
  4559. time += e.GetScriptExecutionTime(ids);
  4560. }
  4561. }
  4562. return time;
  4563. }
  4564. /// <summary>
  4565. /// Returns a count of the number of running scripts in this groups parts.
  4566. /// </summary>
  4567. public int RunningScriptCount()
  4568. {
  4569. int count = 0;
  4570. SceneObjectPart[] parts = m_parts.GetArray();
  4571. for (int i = 0; i < parts.Length; i++)
  4572. count += parts[i].Inventory.RunningScriptCount();
  4573. return count;
  4574. }
  4575. /// <summary>
  4576. /// Get a copy of the list of sitting avatars on all prims of this object.
  4577. /// </summary>
  4578. /// <remarks>
  4579. /// This is sorted by the order in which avatars sat down. If an avatar stands up then all avatars that sat
  4580. /// down after it move one place down the list.
  4581. /// </remarks>
  4582. /// <returns>A list of the sitting avatars. Returns an empty list if there are no sitting avatars.</returns>
  4583. public List<ScenePresence> GetSittingAvatars()
  4584. {
  4585. lock (m_sittingAvatars)
  4586. return new List<ScenePresence>(m_sittingAvatars);
  4587. }
  4588. /// <summary>
  4589. /// Gets the number of sitting avatars.
  4590. /// </summary>
  4591. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4592. /// <returns></returns>
  4593. public int GetSittingAvatarsCount()
  4594. {
  4595. lock (m_sittingAvatars)
  4596. return m_sittingAvatars.Count;
  4597. }
  4598. public override string ToString()
  4599. {
  4600. return String.Format("{0} {1} ({2})", Name, UUID, AbsolutePosition);
  4601. }
  4602. #region ISceneObject
  4603. public virtual ISceneObject CloneForNewScene()
  4604. {
  4605. SceneObjectGroup sog = Copy(false);
  4606. sog.IsDeleted = false;
  4607. return sog;
  4608. }
  4609. public virtual string ToXml2()
  4610. {
  4611. return SceneObjectSerializer.ToXml2Format(this);
  4612. }
  4613. public virtual string ExtraToXmlString()
  4614. {
  4615. return "<ExtraFromItemID>" + FromItemID.ToString() + "</ExtraFromItemID>";
  4616. }
  4617. public virtual void ExtraFromXmlString(string xmlstr)
  4618. {
  4619. string id = xmlstr.Substring(xmlstr.IndexOf("<ExtraFromItemID>"));
  4620. id = xmlstr.Replace("<ExtraFromItemID>", "");
  4621. id = id.Replace("</ExtraFromItemID>", "");
  4622. UUID uuid = UUID.Zero;
  4623. UUID.TryParse(id, out uuid);
  4624. FromItemID = uuid;
  4625. }
  4626. public void ResetOwnerChangeFlag()
  4627. {
  4628. ForEachPart(delegate(SceneObjectPart part)
  4629. {
  4630. part.ResetOwnerChangeFlag();
  4631. });
  4632. InvalidateEffectivePerms();
  4633. }
  4634. // clear some references to easy cg
  4635. public void Clear()
  4636. {
  4637. m_parts.Clear();
  4638. m_sittingAvatars.Clear();
  4639. // m_rootPart = null;
  4640. m_PlaySoundMasterPrim = null;
  4641. m_PlaySoundSlavePrims.Clear();
  4642. m_LoopSoundMasterPrim = null;
  4643. m_targets.Clear();
  4644. m_partsNameToLinkMap.Clear();
  4645. }
  4646. private Dictionary<string,int> m_partsNameToLinkMap = new Dictionary<string, int>();
  4647. private string GetLinkNumber_lastname;
  4648. private int GetLinkNumber_lastnumber;
  4649. // this scales bad but so does GetLinkNumPart
  4650. public int GetLinkNumber(string name)
  4651. {
  4652. if(String.IsNullOrEmpty(name) || name == "Object")
  4653. return -1;
  4654. lock(m_partsNameToLinkMap)
  4655. {
  4656. if(m_partsNameToLinkMap.Count == 0)
  4657. {
  4658. GetLinkNumber_lastname = String.Empty;
  4659. GetLinkNumber_lastnumber = -1;
  4660. SceneObjectPart[] parts = m_parts.GetArray();
  4661. for (int i = 0; i < parts.Length; i++)
  4662. {
  4663. string s = parts[i].Name;
  4664. if(String.IsNullOrEmpty(s) || s == "Object" || s == "Primitive")
  4665. continue;
  4666. if(m_partsNameToLinkMap.ContainsKey(s))
  4667. {
  4668. int ol = parts[i].LinkNum;
  4669. if(ol < m_partsNameToLinkMap[s])
  4670. m_partsNameToLinkMap[s] = ol;
  4671. }
  4672. else
  4673. m_partsNameToLinkMap[s] = parts[i].LinkNum;
  4674. }
  4675. }
  4676. if(name == GetLinkNumber_lastname)
  4677. return GetLinkNumber_lastnumber;
  4678. if(m_partsNameToLinkMap.ContainsKey(name))
  4679. {
  4680. lock(m_partsNameToLinkMap)
  4681. {
  4682. GetLinkNumber_lastname = name;
  4683. GetLinkNumber_lastnumber = m_partsNameToLinkMap[name];
  4684. return GetLinkNumber_lastnumber;
  4685. }
  4686. }
  4687. }
  4688. if(m_sittingAvatars.Count > 0)
  4689. {
  4690. int j = m_parts.Count + 1;
  4691. ScenePresence[] avs = m_sittingAvatars.ToArray();
  4692. for (int i = 0; i < avs.Length; i++, j++)
  4693. {
  4694. if (avs[i].Name == name)
  4695. {
  4696. GetLinkNumber_lastname = name;
  4697. GetLinkNumber_lastnumber = j;
  4698. return j;
  4699. }
  4700. }
  4701. }
  4702. return -1;
  4703. }
  4704. public void InvalidatePartsLinkMaps()
  4705. {
  4706. lock(m_partsNameToLinkMap)
  4707. {
  4708. m_partsNameToLinkMap.Clear();
  4709. GetLinkNumber_lastname = String.Empty;
  4710. GetLinkNumber_lastnumber = -1;
  4711. }
  4712. }
  4713. #endregion
  4714. }
  4715. }