SceneObjectPart.cs 198 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829
  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.Collections.Generic;
  29. using System.Drawing;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Threading;
  33. using System.Text;
  34. using System.Xml;
  35. using System.Xml.Serialization;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using OpenSim.Region.PhysicsModules.SharedBase;
  43. using PermissionMask = OpenSim.Framework.PermissionMask;
  44. namespace OpenSim.Region.Framework.Scenes
  45. {
  46. #region Enumerations
  47. [Flags]
  48. public enum Changed : uint
  49. {
  50. INVENTORY = 1,
  51. COLOR = 2,
  52. SHAPE = 4,
  53. SCALE = 8,
  54. TEXTURE = 16,
  55. LINK = 32,
  56. ALLOWED_DROP = 64,
  57. OWNER = 128,
  58. REGION = 256,
  59. TELEPORT = 512,
  60. REGION_RESTART = 1024,
  61. MEDIA = 2048,
  62. ANIMATION = 16384,
  63. POSITION = 32768
  64. }
  65. [Flags]
  66. public enum TextureAnimFlags : byte
  67. {
  68. NONE = 0x00,
  69. ANIM_ON = 0x01,
  70. LOOP = 0x02,
  71. REVERSE = 0x04,
  72. PING_PONG = 0x08,
  73. SMOOTH = 0x10,
  74. ROTATE = 0x20,
  75. SCALE = 0x40
  76. }
  77. public enum PrimType : int
  78. {
  79. BOX = 0,
  80. CYLINDER = 1,
  81. PRISM = 2,
  82. SPHERE = 3,
  83. TORUS = 4,
  84. TUBE = 5,
  85. RING = 6,
  86. SCULPT = 7
  87. }
  88. #endregion Enumerations
  89. public class SceneObjectPart : ISceneEntity
  90. {
  91. /// <value>
  92. /// Denote all sides of the prim
  93. /// </value>
  94. public const int ALL_SIDES = -1;
  95. private const scriptEvents PhysicsNeededSubsEvents = (
  96. scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
  97. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
  98. );
  99. private const scriptEvents PhyscicsPhantonSubsEvents = (
  100. scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
  101. );
  102. private const scriptEvents PhyscicsVolumeDtcSubsEvents = (
  103. scriptEvents.collision_start | scriptEvents.collision_end
  104. );
  105. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  106. /// <summary>
  107. /// Dynamic attributes can be created and deleted as required.
  108. /// </summary>
  109. public DAMap DynAttrs { get; set; }
  110. private DOMap m_dynObjs;
  111. /// <summary>
  112. /// Dynamic objects that can be created and deleted as required.
  113. /// </summary>
  114. public DOMap DynObjs
  115. {
  116. get
  117. {
  118. if (m_dynObjs == null)
  119. m_dynObjs = new DOMap();
  120. return m_dynObjs;
  121. }
  122. set
  123. {
  124. m_dynObjs = value;
  125. }
  126. }
  127. /// <value>
  128. /// Is this a root part?
  129. /// </value>
  130. /// <remarks>
  131. /// This will return true even if the whole object is attached to an avatar.
  132. /// </remarks>
  133. public bool IsRoot
  134. {
  135. get { return Object.ReferenceEquals(ParentGroup.RootPart, this); }
  136. }
  137. /// <summary>
  138. /// Is an explicit sit target set for this part?
  139. /// </summary>
  140. public bool IsSitTargetSet
  141. {
  142. get
  143. {
  144. // assume SitTargetOrientation is normalized (as needed elsewhere)
  145. if( SitTargetPosition != Vector3.Zero ||
  146. SitTargetOrientation.X != 0f ||
  147. SitTargetOrientation.Y != 0f ||
  148. SitTargetOrientation.Z != 0f)
  149. return true;
  150. return false;
  151. }
  152. }
  153. #region Fields
  154. public bool AllowedDrop;
  155. public bool DIE_AT_EDGE;
  156. public bool RETURN_AT_EDGE;
  157. public bool BlockGrab { get; set; }
  158. public bool StatusSandbox;
  159. public Vector3 StatusSandboxPos;
  160. [XmlIgnore]
  161. public int PseudoCRC; // this is local to region. should only be stored on its db.
  162. // This is just a number that needs to change to invalidate prim data caches
  163. [XmlIgnore]
  164. public int[] PayPrice = {-2,-2,-2,-2,-2};
  165. [XmlIgnore]
  166. /// <summary>
  167. /// The representation of this part in the physics scene.
  168. /// </summary>
  169. /// <remarks>
  170. /// If you use this property more than once in a section of code then you must take a reference and use that.
  171. /// If another thread is simultaneously turning physics off on this part then this refernece could become
  172. /// null at any time.
  173. /// </remarks>
  174. public PhysicsActor PhysActor { get; set; }
  175. //Xantor 20080528 Sound stuff:
  176. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  177. // Not a big problem as long as the script that sets it remains in the prim on startup.
  178. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  179. public UUID Sound;
  180. public byte SoundFlags;
  181. public double SoundGain;
  182. public double SoundRadius;
  183. /// <summary>
  184. /// Should sounds played from this prim be queued?
  185. /// </summary>
  186. /// <remarks>
  187. /// This should only be changed by sound modules. It is up to sound modules as to how they interpret this setting.
  188. /// </remarks>
  189. public bool SoundQueueing { get; set; }
  190. [XmlIgnore]
  191. public Quaternion AttachRotation = Quaternion.Identity;
  192. [XmlIgnore]
  193. public int STATUS_ROTATE_X; // this should not be used
  194. [XmlIgnore]
  195. public int STATUS_ROTATE_Y; // this should not be used
  196. [XmlIgnore]
  197. public int STATUS_ROTATE_Z; // this should not be used
  198. private Dictionary<int, string> m_CollisionFilter = new Dictionary<int, string>();
  199. /// <value>
  200. /// The UUID of the user inventory item from which this object was rezzed if this is a root part.
  201. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item.
  202. /// </value>
  203. private UUID m_fromUserInventoryItemID;
  204. public UUID FromUserInventoryItemID
  205. {
  206. get { return m_fromUserInventoryItemID; }
  207. set { m_fromUserInventoryItemID = value; }
  208. }
  209. public scriptEvents AggregatedScriptEvents;
  210. public Vector3 AttachedPos { get; set; }
  211. // rotation locks on local X,Y and or Z axis bit flags
  212. // bits are as in llSetStatus defined in SceneObjectGroup.axisSelect enum
  213. // but reversed logic: bit cleared means free to rotate
  214. public byte RotationAxisLocks = 0;
  215. // WRONG flag in libOmvPrimFlags
  216. private const uint primFlagVolumeDetect = (uint)PrimFlags.JointLP2P;
  217. public bool VolumeDetectActive
  218. {
  219. get
  220. {
  221. return (Flags & (PrimFlags)primFlagVolumeDetect) != 0;
  222. }
  223. set
  224. {
  225. if(value)
  226. Flags |= (PrimFlags)primFlagVolumeDetect;
  227. else
  228. Flags &= (PrimFlags)(~primFlagVolumeDetect);
  229. }
  230. }
  231. public bool IsWaitingForFirstSpinUpdatePacket;
  232. public Quaternion SpinOldOrientation = Quaternion.Identity;
  233. protected bool m_APIDActive = false;
  234. protected Quaternion m_APIDTarget = Quaternion.Identity;
  235. protected float m_APIDDamp = 0;
  236. protected float m_APIDStrength = 0;
  237. /// <summary>
  238. /// This part's inventory
  239. /// </summary>
  240. public IEntityInventory Inventory
  241. {
  242. get { return m_inventory; }
  243. }
  244. protected SceneObjectPartInventory m_inventory;
  245. public bool Undoing;
  246. public bool IgnoreUndoUpdate = false;
  247. public PrimFlags LocalFlags;
  248. private float m_damage = -1.0f;
  249. private byte[] m_TextureAnimation;
  250. private byte m_clickAction;
  251. private Color m_color = Color.Black;
  252. private List<uint> m_lastColliders = new List<uint>();
  253. private bool m_lastLandCollide;
  254. private int m_linkNum;
  255. private int m_scriptAccessPin;
  256. private readonly Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  257. private string m_sitName = String.Empty;
  258. private Quaternion m_sitTargetOrientation = Quaternion.Identity;
  259. private Vector3 m_sitTargetPosition;
  260. private string m_sitAnimation = "SIT";
  261. private string m_text = String.Empty;
  262. private string m_touchName = String.Empty;
  263. private UndoRedoState m_UndoRedo = null;
  264. private object m_UndoLock = new object();
  265. private bool m_passTouches = false;
  266. private bool m_passCollisions = false;
  267. protected Vector3 m_acceleration;
  268. protected Vector3 m_angularVelocity;
  269. //unkown if this will be kept, added as a way of removing the group position from the group class
  270. protected Vector3 m_groupPosition;
  271. protected uint m_localId;
  272. protected Material m_material = OpenMetaverse.Material.Wood;
  273. protected string m_name;
  274. protected Vector3 m_offsetPosition;
  275. protected SceneObjectGroup m_parentGroup;
  276. protected byte[] m_particleSystem = Utils.EmptyBytes;
  277. protected ulong m_regionHandle;
  278. protected Quaternion m_rotationOffset = Quaternion.Identity;
  279. protected PrimitiveBaseShape m_shape;
  280. protected UUID m_uuid;
  281. protected Vector3 m_velocity;
  282. protected Vector3 m_lastPosition;
  283. protected Quaternion m_lastRotation;
  284. protected Vector3 m_lastVelocity;
  285. protected Vector3 m_lastAcceleration; // acceleration is a derived var with high noise
  286. protected Vector3 m_lastAngularVelocity;
  287. protected double m_lastUpdateSentTime;
  288. protected float m_buoyancy = 0.0f;
  289. protected Vector3 m_force;
  290. protected Vector3 m_torque;
  291. protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
  292. protected float m_density = 1000.0f; // in kg/m^3
  293. protected float m_gravitymod = 1.0f;
  294. protected float m_friction = 0.6f; // wood
  295. protected float m_bounce = 0.5f; // wood
  296. protected bool m_isSelected = false;
  297. /// <summary>
  298. /// Stores media texture data
  299. /// </summary>
  300. protected string m_mediaUrl;
  301. // TODO: Those have to be changed into persistent properties at some later point,
  302. // or sit-camera on vehicles will break on sim-crossing.
  303. private Vector3 m_cameraEyeOffset;
  304. private Vector3 m_cameraAtOffset;
  305. private bool m_forceMouselook;
  306. // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
  307. private sbyte m_collisionSoundType = 0;
  308. private UUID m_collisionSound;
  309. private float m_collisionSoundVolume;
  310. private int LastColSoundSentTime;
  311. private SOPVehicle m_vehicleParams = null;
  312. private PhysicsInertiaData m_physicsInertia;
  313. public KeyframeMotion KeyframeMotion
  314. {
  315. get; set;
  316. }
  317. #endregion Fields
  318. // ~SceneObjectPart()
  319. // {
  320. // Console.WriteLine(
  321. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  322. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  323. // m_log.DebugFormat(
  324. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  325. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  326. // }
  327. #region Constructors
  328. /// <summary>
  329. /// No arg constructor called by region restore db code
  330. /// </summary>
  331. public SceneObjectPart()
  332. {
  333. m_TextureAnimation = Utils.EmptyBytes;
  334. m_particleSystem = Utils.EmptyBytes;
  335. Rezzed = DateTime.UtcNow;
  336. Description = String.Empty;
  337. PseudoCRC = (int)DateTime.UtcNow.Ticks; // random could be as good; fallbak if not on region db
  338. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  339. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  340. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  341. m_inventory = new SceneObjectPartInventory(this);
  342. LastColSoundSentTime = Util.EnvironmentTickCount();
  343. }
  344. /// <summary>
  345. /// Create a completely new SceneObjectPart (prim). This will need to be added separately to a SceneObjectGroup
  346. /// </summary>
  347. /// <param name="ownerID"></param>
  348. /// <param name="shape"></param>
  349. /// <param name="position"></param>
  350. /// <param name="rotationOffset"></param>
  351. /// <param name="offsetPosition"></param>
  352. public SceneObjectPart(
  353. UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
  354. Quaternion rotationOffset, Vector3 offsetPosition) : this()
  355. {
  356. m_name = "Object";
  357. CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
  358. RezzerID = LastOwnerID = CreatorID = OwnerID = ownerID;
  359. UUID = UUID.Random();
  360. Shape = shape;
  361. OwnershipCost = 0;
  362. ObjectSaleType = 0;
  363. SalePrice = 0;
  364. Category = 0;
  365. GroupPosition = groupPosition;
  366. OffsetPosition = offsetPosition;
  367. RotationOffset = rotationOffset;
  368. Velocity = Vector3.Zero;
  369. AngularVelocity = Vector3.Zero;
  370. Acceleration = Vector3.Zero;
  371. APIDActive = false;
  372. Flags = 0;
  373. CreateSelected = true;
  374. PseudoCRC = (int)DateTime.UtcNow.Ticks; // random could be as good
  375. TrimPermissions();
  376. AggregateInnerPerms();
  377. }
  378. #endregion Constructors
  379. #region XML Schema
  380. private UUID _rezzerID;
  381. private UUID _lastOwnerID;
  382. private UUID _ownerID;
  383. private UUID _groupID;
  384. private int _ownershipCost;
  385. private byte _objectSaleType;
  386. private int _salePrice;
  387. private uint _category;
  388. private Int32 _creationDate;
  389. private uint _parentID = 0;
  390. private uint _baseMask = (uint)(PermissionMask.All | PermissionMask.Export);
  391. private uint _ownerMask = (uint)(PermissionMask.All | PermissionMask.Export);
  392. private uint _groupMask = (uint)PermissionMask.None;
  393. private uint _everyoneMask = (uint)PermissionMask.None;
  394. private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Transfer);
  395. private PrimFlags _flags = PrimFlags.None;
  396. private DateTime m_expires;
  397. private DateTime m_rezzed;
  398. private bool m_createSelected = false;
  399. private UUID _creatorID;
  400. public UUID CreatorID
  401. {
  402. get { return _creatorID; }
  403. set { _creatorID = value; }
  404. }
  405. private string m_creatorData = string.Empty;
  406. /// <summary>
  407. /// Data about the creator in the form home_url;name
  408. /// </summary>
  409. public string CreatorData
  410. {
  411. get { return m_creatorData; }
  412. set { m_creatorData = value; }
  413. }
  414. /// <summary>
  415. /// Used by the DB layer to retrieve / store the entire user identification.
  416. /// The identification can either be a simple UUID or a string of the form
  417. /// uuid[;home_url[;name]]
  418. /// </summary>
  419. public string CreatorIdentification
  420. {
  421. get
  422. {
  423. if (!string.IsNullOrEmpty(CreatorData))
  424. return CreatorID.ToString() + ';' + CreatorData;
  425. else
  426. return CreatorID.ToString();
  427. }
  428. set
  429. {
  430. CreatorData = string.Empty;
  431. if ((value == null) || (value != null && value == string.Empty))
  432. return;
  433. // value is uuid or uuid;homeuri;firstname lastname
  434. string[] parts = value.Split(';');
  435. if (parts.Length > 0)
  436. {
  437. UUID uuid = UUID.Zero;
  438. UUID.TryParse(parts[0], out uuid);
  439. CreatorID = uuid;
  440. if (parts.Length > 1)
  441. {
  442. CreatorData = parts[1];
  443. if (!CreatorData.EndsWith("/"))
  444. CreatorData += "/";
  445. if (parts.Length > 2)
  446. CreatorData += ';' + parts[2];
  447. else
  448. CreatorData += ";Unknown User";
  449. }
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// A relic from when we we thought that prims contained folder objects. In
  455. /// reality, prim == folder
  456. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  457. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  458. /// </summary>
  459. public UUID FolderID
  460. {
  461. get { return UUID; }
  462. set { } // Don't allow assignment, or legacy prims wil b0rk - but we need the setter for legacy serialization.
  463. }
  464. /// <value>
  465. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  466. /// </value>
  467. public uint InventorySerial
  468. {
  469. get { return m_inventory.Serial; }
  470. set { m_inventory.Serial = value; }
  471. }
  472. /// <value>
  473. /// Get the inventory list
  474. /// </value>
  475. public TaskInventoryDictionary TaskInventory
  476. {
  477. get {
  478. return m_inventory.Items;
  479. }
  480. set {
  481. m_inventory.Items = value;
  482. }
  483. }
  484. /// <summary>
  485. /// This is idential to the Flags property, except that the returned value is uint rather than PrimFlags
  486. /// </summary>
  487. [Obsolete("Use Flags property instead")]
  488. public uint ObjectFlags
  489. {
  490. get { return (uint)Flags; }
  491. set { Flags = (PrimFlags)value; }
  492. }
  493. public UUID UUID
  494. {
  495. get { return m_uuid; }
  496. set
  497. {
  498. m_uuid = value;
  499. // This is necessary so that TaskInventoryItem parent ids correctly reference the new uuid of this part
  500. if (Inventory != null)
  501. Inventory.ResetObjectID();
  502. }
  503. }
  504. public uint LocalId
  505. {
  506. get { return m_localId; }
  507. set
  508. {
  509. m_localId = value;
  510. // m_log.DebugFormat("[SCENE OBJECT PART]: Set part {0} to local id {1}", Name, m_localId);
  511. }
  512. }
  513. public virtual string Name
  514. {
  515. get { return m_name; }
  516. set
  517. {
  518. m_name = value;
  519. if(ParentGroup != null)
  520. ParentGroup.InvalidatePartsLinkMaps();
  521. PhysicsActor pa = PhysActor;
  522. if (pa != null)
  523. pa.SOPName = value;
  524. }
  525. }
  526. [XmlIgnore]
  527. public bool PassTouches
  528. {
  529. get { return m_passTouches; }
  530. set
  531. {
  532. m_passTouches = value;
  533. if (ParentGroup != null)
  534. ParentGroup.HasGroupChanged = true;
  535. }
  536. }
  537. public bool PassCollisions
  538. {
  539. get { return m_passCollisions; }
  540. set
  541. {
  542. m_passCollisions = value;
  543. if (ParentGroup != null)
  544. ParentGroup.HasGroupChanged = true;
  545. }
  546. }
  547. public bool IsSelected
  548. {
  549. get { return m_isSelected; }
  550. set
  551. {
  552. m_isSelected = value;
  553. if (ParentGroup != null)
  554. ParentGroup.PartSelectChanged(value);
  555. }
  556. }
  557. public Dictionary<int, string> CollisionFilter
  558. {
  559. get { return m_CollisionFilter; }
  560. set
  561. {
  562. m_CollisionFilter = value;
  563. }
  564. }
  565. protected bool APIDActive
  566. {
  567. get { return m_APIDActive; }
  568. set { m_APIDActive = value; }
  569. }
  570. protected Quaternion APIDTarget
  571. {
  572. get { return m_APIDTarget; }
  573. set { m_APIDTarget = value; }
  574. }
  575. protected float APIDDamp
  576. {
  577. get { return m_APIDDamp; }
  578. set { m_APIDDamp = value; }
  579. }
  580. protected float APIDStrength
  581. {
  582. get { return m_APIDStrength; }
  583. set { m_APIDStrength = value; }
  584. }
  585. public ulong RegionHandle
  586. {
  587. get { return m_regionHandle; }
  588. set { m_regionHandle = value; }
  589. }
  590. public int ScriptAccessPin
  591. {
  592. get { return m_scriptAccessPin; }
  593. set { m_scriptAccessPin = (int)value; }
  594. }
  595. public Byte[] TextureAnimation
  596. {
  597. get { return m_TextureAnimation; }
  598. set { m_TextureAnimation = value; }
  599. }
  600. public Byte[] ParticleSystem
  601. {
  602. get { return m_particleSystem; }
  603. set { m_particleSystem = value; }
  604. }
  605. public DateTime Expires
  606. {
  607. get { return m_expires; }
  608. set { m_expires = value; }
  609. }
  610. public DateTime Rezzed
  611. {
  612. get { return m_rezzed; }
  613. set { m_rezzed = value; }
  614. }
  615. public float Damage
  616. {
  617. get { return m_damage; }
  618. set { m_damage = value; }
  619. }
  620. public void setGroupPosition(Vector3 pos)
  621. {
  622. m_groupPosition = pos;
  623. }
  624. /// <summary>
  625. /// The position of the entire group that this prim belongs to.
  626. /// </summary>
  627. ///
  628. public Vector3 GroupPosition
  629. {
  630. get
  631. {
  632. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  633. PhysicsActor actor = PhysActor;
  634. if (_parentID == 0)
  635. {
  636. if (actor != null)
  637. m_groupPosition = actor.Position;
  638. return m_groupPosition;
  639. }
  640. // If I'm an attachment, my position is reported as the position of who I'm attached to
  641. if (ParentGroup.IsAttachment)
  642. {
  643. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  644. if (sp != null)
  645. return sp.AbsolutePosition;
  646. }
  647. // use root prim's group position. Physics may have updated it
  648. if (ParentGroup.RootPart != this)
  649. m_groupPosition = ParentGroup.RootPart.GroupPosition;
  650. return m_groupPosition;
  651. }
  652. set
  653. {
  654. m_groupPosition = value;
  655. PhysicsActor actor = PhysActor;
  656. if (actor != null && ParentGroup.Scene.PhysicsScene != null)
  657. {
  658. try
  659. {
  660. // Root prim actually goes at Position
  661. if (_parentID == 0)
  662. {
  663. actor.Position = value;
  664. }
  665. else
  666. {
  667. // The physics engine always sees all objects (root or linked) in world coordinates.
  668. actor.Position = GetWorldPosition();
  669. actor.Orientation = GetWorldRotation();
  670. }
  671. // Tell the physics engines that this prim changed.
  672. if (ParentGroup != null && ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  673. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  674. }
  675. catch (Exception e)
  676. {
  677. m_log.ErrorFormat("[SCENEOBJECTPART]: GROUP POSITION. {0}", e);
  678. }
  679. }
  680. }
  681. }
  682. public void setOffsetPosition(Vector3 pos)
  683. {
  684. m_offsetPosition = pos;
  685. }
  686. public Vector3 OffsetPosition
  687. {
  688. get { return m_offsetPosition; }
  689. set
  690. {
  691. Vector3 oldpos = m_offsetPosition;
  692. m_offsetPosition = value;
  693. if (ParentGroup != null && !ParentGroup.IsDeleted)
  694. {
  695. if((oldpos - m_offsetPosition).LengthSquared() > 1.0f)
  696. ParentGroup.InvalidBoundsRadius();
  697. PhysicsActor actor = PhysActor;
  698. if (_parentID != 0 && actor != null)
  699. {
  700. actor.Position = GetWorldPosition();
  701. actor.Orientation = GetWorldRotation();
  702. // Tell the physics engines that this prim changed.
  703. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  704. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  705. }
  706. if (!m_parentGroup.m_dupeInProgress)
  707. {
  708. List<ScenePresence> avs = ParentGroup.GetSittingAvatars();
  709. foreach (ScenePresence av in avs)
  710. {
  711. if (av.ParentID == m_localId)
  712. {
  713. Vector3 offset = (m_offsetPosition - oldpos);
  714. av.AbsolutePosition += offset;
  715. // av.SendAvatarDataToAllAgents();
  716. av.SendTerseUpdateToAllClients();
  717. }
  718. }
  719. }
  720. }
  721. TriggerScriptChangedEvent(Changed.POSITION);
  722. }
  723. }
  724. public Vector3 RelativePosition
  725. {
  726. get
  727. {
  728. if (IsRoot)
  729. {
  730. if (ParentGroup.IsAttachment)
  731. return AttachedPos;
  732. else
  733. return AbsolutePosition;
  734. }
  735. else
  736. {
  737. return OffsetPosition;
  738. }
  739. }
  740. }
  741. public void setRotationOffset(Quaternion q)
  742. {
  743. m_rotationOffset = q;
  744. }
  745. public Quaternion RotationOffset
  746. {
  747. get
  748. {
  749. // We don't want the physics engine mucking up the rotations in a linkset
  750. PhysicsActor actor = PhysActor;
  751. // If this is a root of a linkset, the real rotation is what the physics engine thinks.
  752. // If not a root prim, the offset rotation is computed by SOG and is relative to the root.
  753. if (_parentID == 0 && (Shape.PCode != 9 || Shape.State == 0) && actor != null)
  754. m_rotationOffset = actor.Orientation;
  755. return m_rotationOffset;
  756. }
  757. set
  758. {
  759. // StoreUndoState();
  760. m_rotationOffset = value;
  761. PhysicsActor actor = PhysActor;
  762. if (actor != null)
  763. {
  764. try
  765. {
  766. // Root prim gets value directly
  767. if (_parentID == 0)
  768. {
  769. actor.Orientation = value;
  770. //m_log.Info("[PART]: RO1:" + actor.Orientation.ToString());
  771. }
  772. else
  773. {
  774. // Child prim we have to calculate it's world rotationwel
  775. Quaternion resultingrotation = GetWorldRotation();
  776. actor.Orientation = resultingrotation;
  777. //m_log.Info("[PART]: RO2:" + actor.Orientation.ToString());
  778. }
  779. if (ParentGroup != null && ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
  780. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  781. //}
  782. }
  783. catch (Exception ex)
  784. {
  785. m_log.Error("[SCENEOBJECTPART]: ROTATIONOFFSET" + ex.Message);
  786. }
  787. }
  788. }
  789. }
  790. /// <summary></summary>
  791. public Vector3 Velocity
  792. {
  793. get
  794. {
  795. PhysicsActor actor = PhysActor;
  796. if (actor != null)
  797. {
  798. if (actor.IsPhysical)
  799. {
  800. m_velocity = actor.Velocity;
  801. }
  802. }
  803. return m_velocity;
  804. }
  805. set
  806. {
  807. if (Util.IsNanOrInfinity(value))
  808. m_velocity = Vector3.Zero;
  809. else
  810. m_velocity = value;
  811. PhysicsActor actor = PhysActor;
  812. if (actor != null)
  813. {
  814. if (actor.IsPhysical)
  815. {
  816. actor.Velocity = m_velocity;
  817. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  818. }
  819. }
  820. }
  821. }
  822. /// <summary>Update angular velocity and schedule terse update.</summary>
  823. public void UpdateAngularVelocity(Vector3 avel)
  824. {
  825. AngularVelocity = avel;
  826. ScheduleTerseUpdate();
  827. ParentGroup.HasGroupChanged = true;
  828. }
  829. /// <summary>Get or set angular velocity. Does not schedule update.</summary>
  830. public Vector3 AngularVelocity
  831. {
  832. get
  833. {
  834. PhysicsActor actor = PhysActor;
  835. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  836. {
  837. m_angularVelocity = actor.RotationalVelocity;
  838. }
  839. return m_angularVelocity;
  840. }
  841. set
  842. {
  843. if (Util.IsNanOrInfinity(value))
  844. m_angularVelocity = Vector3.Zero;
  845. else
  846. m_angularVelocity = value;
  847. PhysicsActor actor = PhysActor;
  848. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  849. {
  850. actor.RotationalVelocity = m_angularVelocity;
  851. }
  852. }
  853. }
  854. /// <summary></summary>
  855. public Vector3 Acceleration
  856. {
  857. get
  858. {
  859. PhysicsActor actor = PhysActor;
  860. if (actor != null && actor.IsPhysical)
  861. {
  862. m_acceleration = actor.Acceleration;
  863. }
  864. return m_acceleration;
  865. }
  866. set
  867. {
  868. if (Util.IsNanOrInfinity(value))
  869. m_acceleration = Vector3.Zero;
  870. else
  871. m_acceleration = value;
  872. PhysicsActor actor = PhysActor;
  873. if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
  874. {
  875. actor.Acceleration = m_acceleration;
  876. }
  877. }
  878. }
  879. public string Description { get; set; }
  880. /// <value>
  881. /// Text color.
  882. /// </value>
  883. public Color Color
  884. {
  885. get { return m_color; }
  886. set { m_color = value; }
  887. }
  888. public string Text
  889. {
  890. get
  891. {
  892. if (m_text.Length > 254)
  893. return m_text.Substring(0, 254);
  894. return m_text;
  895. }
  896. set { m_text = value; }
  897. }
  898. public string SitName
  899. {
  900. get { return m_sitName; }
  901. set { m_sitName = value; }
  902. }
  903. public string TouchName
  904. {
  905. get { return m_touchName; }
  906. set { m_touchName = value; }
  907. }
  908. public int LinkNum
  909. {
  910. get { return m_linkNum; }
  911. set
  912. {
  913. // if (ParentGroup != null)
  914. // {
  915. // m_log.DebugFormat(
  916. // "[SCENE OBJECT PART]: Setting linknum of {0}@{1} to {2} from {3}",
  917. // Name, AbsolutePosition, value, m_linkNum);
  918. // Util.PrintCallStack();
  919. // }
  920. m_linkNum = value;
  921. }
  922. }
  923. public byte ClickAction
  924. {
  925. get { return m_clickAction; }
  926. set
  927. {
  928. m_clickAction = value;
  929. }
  930. }
  931. public PrimitiveBaseShape Shape
  932. {
  933. get { return m_shape; }
  934. set
  935. {
  936. m_shape = value;
  937. }
  938. }
  939. /// <summary>
  940. /// Change the scale of this part.
  941. /// </summary>
  942. public Vector3 Scale
  943. {
  944. get { return m_shape.Scale; }
  945. set
  946. {
  947. if (m_shape != null)
  948. {
  949. Vector3 oldscale = m_shape.Scale;
  950. m_shape.Scale = value;
  951. if (ParentGroup != null && ((value - oldscale).LengthSquared() >1.0f))
  952. ParentGroup.InvalidBoundsRadius();
  953. PhysicsActor actor = PhysActor;
  954. if (actor != null)
  955. {
  956. if (ParentGroup.Scene != null)
  957. {
  958. if (ParentGroup.Scene.PhysicsScene != null)
  959. {
  960. actor.Size = m_shape.Scale;
  961. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  962. }
  963. }
  964. }
  965. }
  966. TriggerScriptChangedEvent(Changed.SCALE);
  967. }
  968. }
  969. public float maxSimpleArea()
  970. {
  971. float a,b;
  972. float sx = m_shape.Scale.X;
  973. float sy = m_shape.Scale.Y;
  974. float sz = m_shape.Scale.Z;
  975. if( sx > sy)
  976. {
  977. a = sx;
  978. if(sy > sz)
  979. b = sy;
  980. else
  981. b = sz;
  982. }
  983. else
  984. {
  985. a = sy;
  986. if(sx > sz)
  987. b = sx;
  988. else
  989. b = sz;
  990. }
  991. return a * b;
  992. }
  993. public PrimUpdateFlags UpdateFlag { get; set; }
  994. public PrimUpdateFlags GetAndClearUpdateFlag()
  995. {
  996. lock(UpdateFlagLock)
  997. {
  998. PrimUpdateFlags ret = UpdateFlag;
  999. UpdateFlag = PrimUpdateFlags.None;
  1000. return ret;
  1001. }
  1002. }
  1003. private object UpdateFlagLock = new object();
  1004. /// <summary>
  1005. /// Used for media on a prim.
  1006. /// </summary>
  1007. /// Do not change this value directly - always do it through an IMoapModule.
  1008. public string MediaUrl
  1009. {
  1010. get
  1011. {
  1012. return m_mediaUrl;
  1013. }
  1014. set
  1015. {
  1016. string old = m_mediaUrl;
  1017. m_mediaUrl = value;
  1018. if (ParentGroup != null && old != m_mediaUrl)
  1019. ParentGroup.HasGroupChanged = true;
  1020. }
  1021. }
  1022. public bool CreateSelected
  1023. {
  1024. get { return m_createSelected; }
  1025. set
  1026. {
  1027. // m_log.DebugFormat("[SOP]: Setting CreateSelected to {0} for {1} {2}", value, Name, UUID);
  1028. m_createSelected = value;
  1029. }
  1030. }
  1031. #endregion
  1032. //---------------
  1033. #region Public Properties with only Get
  1034. public Vector3 AbsolutePosition
  1035. {
  1036. get
  1037. {
  1038. if (_parentID == 0)
  1039. return GroupPosition;
  1040. return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
  1041. }
  1042. }
  1043. public SceneObjectGroup ParentGroup
  1044. {
  1045. get { return m_parentGroup; }
  1046. private set { m_parentGroup = value; }
  1047. }
  1048. public scriptEvents ScriptEvents
  1049. {
  1050. get { return AggregatedScriptEvents; }
  1051. }
  1052. public Quaternion SitTargetOrientation
  1053. {
  1054. get { return m_sitTargetOrientation; }
  1055. set
  1056. {
  1057. m_sitTargetOrientation = value;
  1058. // m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target orientation {0} for {1} {2}", m_sitTargetOrientation, Name, LocalId);
  1059. }
  1060. }
  1061. public Vector3 SitTargetPosition
  1062. {
  1063. get { return m_sitTargetPosition; }
  1064. set
  1065. {
  1066. m_sitTargetPosition = value;
  1067. // m_log.DebugFormat("[SCENE OBJECT PART]: Set sit target position to {0} for {1} {2}", m_sitTargetPosition, Name, LocalId);
  1068. }
  1069. }
  1070. // This sort of sucks, but I'm adding these in to make some of
  1071. // the mappings more consistant.
  1072. public Vector3 SitTargetPositionLL
  1073. {
  1074. get { return m_sitTargetPosition; }
  1075. set { m_sitTargetPosition = value; }
  1076. }
  1077. public Quaternion SitTargetOrientationLL
  1078. {
  1079. get { return m_sitTargetOrientation; }
  1080. set { m_sitTargetOrientation = value; }
  1081. }
  1082. public float SitActiveRange { get; set;}
  1083. public Vector3 StandOffset { get; set;}
  1084. public bool Stopped
  1085. {
  1086. get {
  1087. double threshold = 0.02;
  1088. return (Math.Abs(Velocity.X) < threshold &&
  1089. Math.Abs(Velocity.Y) < threshold &&
  1090. Math.Abs(Velocity.Z) < threshold &&
  1091. Math.Abs(AngularVelocity.X) < threshold &&
  1092. Math.Abs(AngularVelocity.Y) < threshold &&
  1093. Math.Abs(AngularVelocity.Z) < threshold);
  1094. }
  1095. }
  1096. /// <summary>
  1097. /// The parent ID of this part.
  1098. /// </summary>
  1099. /// <remarks>
  1100. /// If this is a root part which is not attached to an avatar then the value will be 0.
  1101. /// If this is a root part which is attached to an avatar then the value is the local id of that avatar.
  1102. /// If this is a child part then the value is the local ID of the root part.
  1103. /// </remarks>
  1104. public uint ParentID
  1105. {
  1106. get { return _parentID; }
  1107. set { _parentID = value; }
  1108. }
  1109. public int CreationDate
  1110. {
  1111. get { return _creationDate; }
  1112. set { _creationDate = value; }
  1113. }
  1114. public uint Category
  1115. {
  1116. get { return _category; }
  1117. set { _category = value; }
  1118. }
  1119. public int SalePrice
  1120. {
  1121. get { return _salePrice; }
  1122. set { _salePrice = value; }
  1123. }
  1124. public byte ObjectSaleType
  1125. {
  1126. get { return _objectSaleType; }
  1127. set { _objectSaleType = value; }
  1128. }
  1129. public int OwnershipCost
  1130. {
  1131. get { return _ownershipCost; }
  1132. set { _ownershipCost = value; }
  1133. }
  1134. public UUID GroupID
  1135. {
  1136. get { return _groupID; }
  1137. set { _groupID = value; }
  1138. }
  1139. public UUID OwnerID
  1140. {
  1141. get { return _ownerID; }
  1142. set { _ownerID = value; }
  1143. }
  1144. public UUID LastOwnerID
  1145. {
  1146. get { return _lastOwnerID; }
  1147. set {
  1148. _lastOwnerID = value; }
  1149. }
  1150. public UUID RezzerID
  1151. {
  1152. get { return _rezzerID; }
  1153. set { _rezzerID = value; }
  1154. }
  1155. public uint BaseMask
  1156. {
  1157. get { return _baseMask; }
  1158. set { _baseMask = value; }
  1159. }
  1160. public uint OwnerMask
  1161. {
  1162. get { return _ownerMask; }
  1163. set { _ownerMask = value; }
  1164. }
  1165. public uint GroupMask
  1166. {
  1167. get { return _groupMask; }
  1168. set { _groupMask = value; }
  1169. }
  1170. public uint EveryoneMask
  1171. {
  1172. get { return _everyoneMask; }
  1173. set { _everyoneMask = value; }
  1174. }
  1175. public uint NextOwnerMask
  1176. {
  1177. get { return _nextOwnerMask; }
  1178. set { _nextOwnerMask = value; }
  1179. }
  1180. /// <summary>
  1181. /// Property flags. See OpenMetaverse.PrimFlags
  1182. /// </summary>
  1183. /// <remarks>
  1184. /// Example properties are PrimFlags.Phantom and PrimFlags.DieAtEdge
  1185. /// </remarks>
  1186. public PrimFlags Flags
  1187. {
  1188. get { return _flags; }
  1189. set
  1190. {
  1191. // m_log.DebugFormat("[SOP]: Setting flags for {0} {1} to {2}", UUID, Name, value);
  1192. _flags = value;
  1193. }
  1194. }
  1195. /// <summary>
  1196. /// ID of the avatar that is sat on us if we have a sit target. If there is no such avatar then is UUID.Zero
  1197. /// </summary>
  1198. public UUID SitTargetAvatar { get; set; }
  1199. /// <summary>
  1200. /// IDs of all avatars sat on this part.
  1201. /// </summary>
  1202. /// <remarks>
  1203. /// We need to track this so that we can stop sat upon prims from being attached.
  1204. /// </remarks>
  1205. /// <value>
  1206. /// null if there are no sitting avatars. This is to save us create a hashset for every prim in a scene.
  1207. /// </value>
  1208. private HashSet<ScenePresence> m_sittingAvatars;
  1209. public virtual UUID RegionID
  1210. {
  1211. get
  1212. {
  1213. if (ParentGroup.Scene != null)
  1214. return ParentGroup.Scene.RegionInfo.RegionID;
  1215. else
  1216. return UUID.Zero;
  1217. }
  1218. set {} // read only
  1219. }
  1220. private UUID _parentUUID = UUID.Zero;
  1221. public UUID ParentUUID
  1222. {
  1223. get
  1224. {
  1225. if (ParentGroup != null)
  1226. _parentUUID = ParentGroup.UUID;
  1227. return _parentUUID;
  1228. }
  1229. set { _parentUUID = value; }
  1230. }
  1231. public string SitAnimation
  1232. {
  1233. get { return m_sitAnimation; }
  1234. set { m_sitAnimation = value; }
  1235. }
  1236. public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
  1237. // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
  1238. // runtime thing.. do not persist
  1239. [XmlIgnore]
  1240. public sbyte CollisionSoundType
  1241. {
  1242. get
  1243. {
  1244. return m_collisionSoundType;
  1245. }
  1246. set
  1247. {
  1248. UUID old = m_collisionSound;
  1249. m_collisionSoundType = value;
  1250. if (value == -1)
  1251. m_collisionSound = invalidCollisionSoundUUID;
  1252. else if (value == 0)
  1253. m_collisionSound = UUID.Zero;
  1254. if(m_collisionSound != old && ParentGroup != null)
  1255. ParentGroup.HasGroupChanged = true;
  1256. }
  1257. }
  1258. public UUID CollisionSound
  1259. {
  1260. get { return m_collisionSound; }
  1261. set
  1262. {
  1263. UUID olds = m_collisionSound;
  1264. m_collisionSound = value;
  1265. if (value == invalidCollisionSoundUUID)
  1266. m_collisionSoundType = -1;
  1267. else if (value == UUID.Zero)
  1268. m_collisionSoundType = 0;
  1269. else
  1270. m_collisionSoundType = 1;
  1271. if(m_collisionSound != olds && ParentGroup != null)
  1272. ParentGroup.HasGroupChanged = true;
  1273. }
  1274. }
  1275. public float CollisionSoundVolume
  1276. {
  1277. get { return m_collisionSoundVolume; }
  1278. set
  1279. {
  1280. float oldvalue = m_collisionSoundVolume;
  1281. if(value >= 0)
  1282. m_collisionSoundVolume = value;
  1283. else
  1284. m_collisionSoundVolume = 0.0f;
  1285. if(m_collisionSoundVolume != oldvalue && ParentGroup != null)
  1286. ParentGroup.HasGroupChanged = true;
  1287. }
  1288. }
  1289. public float Buoyancy
  1290. {
  1291. get
  1292. {
  1293. if (ParentGroup.RootPart == this)
  1294. return m_buoyancy;
  1295. return ParentGroup.RootPart.Buoyancy;
  1296. }
  1297. set
  1298. {
  1299. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1300. {
  1301. ParentGroup.RootPart.Buoyancy = value;
  1302. return;
  1303. }
  1304. m_buoyancy = value;
  1305. if (PhysActor != null)
  1306. PhysActor.Buoyancy = value;
  1307. }
  1308. }
  1309. public Vector3 Force
  1310. {
  1311. get
  1312. {
  1313. if (ParentGroup.RootPart == this)
  1314. return m_force;
  1315. return ParentGroup.RootPart.Force;
  1316. }
  1317. set
  1318. {
  1319. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1320. {
  1321. ParentGroup.RootPart.Force = value;
  1322. return;
  1323. }
  1324. m_force = value;
  1325. if (PhysActor != null)
  1326. PhysActor.Force = value;
  1327. }
  1328. }
  1329. public Vector3 Torque
  1330. {
  1331. get
  1332. {
  1333. if (ParentGroup.RootPart == this)
  1334. return m_torque;
  1335. return ParentGroup.RootPart.Torque;
  1336. }
  1337. set
  1338. {
  1339. if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
  1340. {
  1341. ParentGroup.RootPart.Torque = value;
  1342. return;
  1343. }
  1344. m_torque = value;
  1345. if (PhysActor != null)
  1346. PhysActor.Torque = value;
  1347. }
  1348. }
  1349. public byte Material
  1350. {
  1351. get { return (byte)m_material; }
  1352. set
  1353. {
  1354. if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
  1355. {
  1356. bool update = false;
  1357. if (m_material != (Material)value)
  1358. {
  1359. update = true;
  1360. m_material = (Material)value;
  1361. }
  1362. if (m_friction != SOPMaterialData.friction(m_material))
  1363. {
  1364. update = true;
  1365. m_friction = SOPMaterialData.friction(m_material);
  1366. }
  1367. if (m_bounce != SOPMaterialData.bounce(m_material))
  1368. {
  1369. update = true;
  1370. m_bounce = SOPMaterialData.bounce(m_material);
  1371. }
  1372. if (update)
  1373. {
  1374. if (PhysActor != null)
  1375. {
  1376. PhysActor.SetMaterial((int)value);
  1377. }
  1378. if(ParentGroup != null)
  1379. {
  1380. ParentGroup.HasGroupChanged = true;
  1381. ScheduleFullUpdate();
  1382. }
  1383. }
  1384. }
  1385. }
  1386. }
  1387. // not a propriety to move to methods place later
  1388. private bool HasMesh()
  1389. {
  1390. if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
  1391. return true;
  1392. return false;
  1393. }
  1394. // not a propriety to move to methods place later
  1395. public byte DefaultPhysicsShapeType()
  1396. {
  1397. byte type;
  1398. if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
  1399. type = (byte)PhysShapeType.convex;
  1400. else
  1401. type = (byte)PhysShapeType.prim;
  1402. return type;
  1403. }
  1404. [XmlIgnore]
  1405. public bool UsesComplexCost
  1406. {
  1407. get
  1408. {
  1409. byte pst = PhysicsShapeType;
  1410. if(pst == (byte) PhysShapeType.none || HasMesh())
  1411. return true;
  1412. return false;
  1413. }
  1414. }
  1415. [XmlIgnore]
  1416. public float PhysicsCost
  1417. {
  1418. get
  1419. {
  1420. if(PhysicsShapeType == (byte)PhysShapeType.none)
  1421. return 0;
  1422. float cost = 0.1f;
  1423. if (PhysActor != null)
  1424. cost = PhysActor.PhysicsCost;
  1425. else
  1426. cost = 0.1f;
  1427. if ((Flags & PrimFlags.Physics) != 0)
  1428. cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
  1429. return cost;
  1430. }
  1431. }
  1432. [XmlIgnore]
  1433. public float StreamingCost
  1434. {
  1435. get
  1436. {
  1437. float cost;
  1438. if (PhysActor != null)
  1439. cost = PhysActor.StreamCost;
  1440. else
  1441. cost = 1.0f;
  1442. return 1.0f;
  1443. }
  1444. }
  1445. [XmlIgnore]
  1446. public float SimulationCost
  1447. {
  1448. get
  1449. {
  1450. // ignoring scripts. Don't like considering them for this
  1451. if((Flags & PrimFlags.Physics) != 0)
  1452. return 1.0f;
  1453. return 0.5f;
  1454. }
  1455. }
  1456. public byte PhysicsShapeType
  1457. {
  1458. get
  1459. {
  1460. // if (PhysActor != null)
  1461. // m_physicsShapeType = PhysActor.PhysicsShapeType;
  1462. return m_physicsShapeType;
  1463. }
  1464. set
  1465. {
  1466. byte oldv = m_physicsShapeType;
  1467. if (value >= 0 && value <= (byte)PhysShapeType.convex)
  1468. {
  1469. if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
  1470. m_physicsShapeType = DefaultPhysicsShapeType();
  1471. else
  1472. m_physicsShapeType = value;
  1473. }
  1474. else
  1475. m_physicsShapeType = DefaultPhysicsShapeType();
  1476. if (m_physicsShapeType != oldv && ParentGroup != null)
  1477. {
  1478. if (m_physicsShapeType == (byte)PhysShapeType.none)
  1479. {
  1480. if (PhysActor != null)
  1481. {
  1482. ParentGroup.Scene.RemovePhysicalPrim(1);
  1483. RemoveFromPhysics();
  1484. // Stop();
  1485. }
  1486. }
  1487. else if (PhysActor == null)
  1488. {
  1489. if(oldv == (byte)PhysShapeType.none)
  1490. {
  1491. ApplyPhysics((uint)Flags, VolumeDetectActive, false);
  1492. UpdatePhysicsSubscribedEvents();
  1493. }
  1494. }
  1495. else
  1496. PhysActor.PhysicsShapeType = m_physicsShapeType;
  1497. ParentGroup.HasGroupChanged = true;
  1498. }
  1499. }
  1500. }
  1501. public float Density // in kg/m^3
  1502. {
  1503. get { return m_density; }
  1504. set
  1505. {
  1506. if (value >=1 && value <= 22587.0)
  1507. {
  1508. m_density = value;
  1509. if (ParentGroup != null)
  1510. {
  1511. ParentGroup.HasGroupChanged = true;
  1512. ScheduleFullUpdate();
  1513. }
  1514. PhysicsActor pa = PhysActor;
  1515. if (pa != null)
  1516. pa.Density = m_density;
  1517. }
  1518. }
  1519. }
  1520. public float GravityModifier
  1521. {
  1522. get { return m_gravitymod; }
  1523. set
  1524. {
  1525. if( value >= -1 && value <=28.0f)
  1526. {
  1527. m_gravitymod = value;
  1528. if (ParentGroup != null)
  1529. {
  1530. ParentGroup.HasGroupChanged = true;
  1531. ScheduleFullUpdate();
  1532. }
  1533. PhysicsActor pa = PhysActor;
  1534. if (pa != null)
  1535. pa.GravModifier = m_gravitymod;
  1536. }
  1537. }
  1538. }
  1539. public float Friction
  1540. {
  1541. get { return m_friction; }
  1542. set
  1543. {
  1544. if (value >= 0 && value <= 255.0f)
  1545. {
  1546. m_friction = value;
  1547. if (ParentGroup != null)
  1548. {
  1549. ParentGroup.HasGroupChanged = true;
  1550. ScheduleFullUpdate();
  1551. }
  1552. PhysicsActor pa = PhysActor;
  1553. if (pa != null)
  1554. pa.Friction = m_friction;
  1555. }
  1556. }
  1557. }
  1558. public float Restitution
  1559. {
  1560. get { return m_bounce; }
  1561. set
  1562. {
  1563. if (value >= 0 && value <= 1.0f)
  1564. {
  1565. m_bounce = value;
  1566. if (ParentGroup != null)
  1567. {
  1568. ParentGroup.HasGroupChanged = true;
  1569. ScheduleFullUpdate();
  1570. }
  1571. PhysicsActor pa = PhysActor;
  1572. if (pa != null)
  1573. pa.Restitution = m_bounce;
  1574. }
  1575. }
  1576. }
  1577. #endregion Public Properties with only Get
  1578. private uint ApplyMask(uint val, bool set, uint mask)
  1579. {
  1580. if (set)
  1581. {
  1582. return val |= mask;
  1583. }
  1584. else
  1585. {
  1586. return val &= ~mask;
  1587. }
  1588. }
  1589. /// <summary>
  1590. /// Clear all pending updates of parts to clients
  1591. /// </summary>
  1592. public void ClearUpdateSchedule()
  1593. {
  1594. lock(UpdateFlagLock)
  1595. UpdateFlag = PrimUpdateFlags.None;
  1596. }
  1597. /// <summary>
  1598. /// Send this part's properties (name, description, inventory serial, base mask, etc.) to a client
  1599. /// </summary>
  1600. /// <param name="client"></param>
  1601. public void SendPropertiesToClient(IClientAPI client)
  1602. {
  1603. client.SendObjectPropertiesReply(this);
  1604. }
  1605. // TODO: unused:
  1606. // private void handleTimerAccounting(uint localID, double interval)
  1607. // {
  1608. // if (localID == LocalId)
  1609. // {
  1610. // float sec = (float)interval;
  1611. // if (m_parentGroup != null)
  1612. // {
  1613. // if (sec == 0)
  1614. // {
  1615. // if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  1616. // m_parentGroup.scriptScore = 0;
  1617. //
  1618. // m_parentGroup.scriptScore += 0.001f;
  1619. // return;
  1620. // }
  1621. //
  1622. // if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  1623. // m_parentGroup.scriptScore = 0;
  1624. // m_parentGroup.scriptScore += (0.001f / sec);
  1625. // }
  1626. // }
  1627. // }
  1628. #region Public Methods
  1629. public void ResetExpire()
  1630. {
  1631. Expires = DateTime.UtcNow + new TimeSpan(600000000);
  1632. }
  1633. public void AddFlag(PrimFlags flag)
  1634. {
  1635. // PrimFlags prevflag = Flags;
  1636. if ((Flags & flag) == 0)
  1637. {
  1638. //m_log.Debug("Adding flag: " + ((PrimFlags) flag).ToString());
  1639. Flags |= flag;
  1640. if (flag == PrimFlags.TemporaryOnRez)
  1641. ResetExpire();
  1642. }
  1643. // m_log.Debug("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1644. }
  1645. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1646. {
  1647. m_particleSystem = pSystem.GetBytes();
  1648. }
  1649. public void RemoveParticleSystem()
  1650. {
  1651. m_particleSystem = new byte[0];
  1652. }
  1653. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1654. {
  1655. byte[] data;
  1656. if (pTexAnim.Flags == Primitive.TextureAnimMode.ANIM_OFF)
  1657. {
  1658. data = Utils.EmptyBytes;
  1659. }
  1660. else
  1661. {
  1662. data = new byte[16];
  1663. data[0] = (byte)pTexAnim.Flags;
  1664. data[1] = (byte)pTexAnim.Face;
  1665. data[2] = (byte)pTexAnim.SizeX;
  1666. data[3] = (byte)pTexAnim.SizeY;
  1667. Utils.FloatToBytesSafepos(pTexAnim.Start, data, 4);
  1668. Utils.FloatToBytesSafepos(pTexAnim.Length, data, 8);
  1669. Utils.FloatToBytesSafepos(pTexAnim.Rate, data, 12);
  1670. }
  1671. m_TextureAnimation = data;
  1672. }
  1673. public void AdjustSoundGain(double volume)
  1674. {
  1675. if (volume > 1)
  1676. volume = 1;
  1677. if (volume < 0)
  1678. volume = 0;
  1679. ParentGroup.Scene.ForEachRootClient(delegate(IClientAPI client)
  1680. {
  1681. client.SendAttachedSoundGainChange(UUID, (float)volume);
  1682. });
  1683. }
  1684. /// <summary>
  1685. /// hook to the physics scene to apply impulse
  1686. /// This is sent up to the group, which then finds the root prim
  1687. /// and applies the force on the root prim of the group
  1688. /// </summary>
  1689. /// <param name="impulsei">Vector force</param>
  1690. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1691. public void ApplyImpulse(Vector3 impulse, bool localGlobalTF)
  1692. {
  1693. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1694. return;
  1695. if (localGlobalTF)
  1696. impulse *= GetWorldRotation();
  1697. ParentGroup.applyImpulse(impulse);
  1698. }
  1699. // SetVelocity for LSL llSetVelocity.. may need revision if having other uses in future
  1700. public void SetVelocity(Vector3 pVel, bool localGlobalTF)
  1701. {
  1702. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1703. return;
  1704. if (ParentGroup.IsAttachment)
  1705. return; // don't work on attachments (for now ??)
  1706. SceneObjectPart root = ParentGroup.RootPart;
  1707. if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
  1708. return;
  1709. PhysicsActor pa = root.PhysActor;
  1710. if (pa == null || !pa.IsPhysical)
  1711. return;
  1712. if (localGlobalTF)
  1713. pVel *= GetWorldRotation();
  1714. ParentGroup.Velocity = pVel;
  1715. }
  1716. // SetAngularVelocity for LSL llSetAngularVelocity.. may need revision if having other uses in future
  1717. public void SetAngularVelocity(Vector3 pAngVel, bool localGlobalTF)
  1718. {
  1719. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1720. return;
  1721. if (ParentGroup.IsAttachment)
  1722. return; // don't work on attachments (for now ??)
  1723. SceneObjectPart root = ParentGroup.RootPart;
  1724. if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
  1725. return;
  1726. PhysicsActor pa = root.PhysActor;
  1727. if (pa == null || !pa.IsPhysical)
  1728. return;
  1729. if (localGlobalTF)
  1730. pAngVel *= GetWorldRotation();
  1731. root.AngularVelocity = pAngVel;
  1732. }
  1733. /// <summary>
  1734. /// hook to the physics scene to apply angular impulse
  1735. /// This is sent up to the group, which then finds the root prim
  1736. /// and applies the force on the root prim of the group
  1737. /// </summary>
  1738. /// <param name="impulsei">Vector force</param>
  1739. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1740. public void ApplyAngularImpulse(Vector3 impulse, bool localGlobalTF)
  1741. {
  1742. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  1743. return;
  1744. if (localGlobalTF)
  1745. ParentGroup.ApplyAngularImpulse(impulse * GetWorldRotation());
  1746. else
  1747. ParentGroup.ApplyAngularImpulse(impulse);
  1748. }
  1749. /// <summary>
  1750. /// hook to the physics scene to apply angular impulse
  1751. /// This is sent up to the group, which then finds the root prim
  1752. /// and applies the force on the root prim of the group
  1753. /// </summary>
  1754. /// <param name="impulsei">Vector force</param>
  1755. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1756. // this is actualy Set Torque.. keeping naming so not to edit lslapi also
  1757. public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
  1758. {
  1759. Vector3 torque = torquei;
  1760. if (localGlobalTF)
  1761. torque *= GetWorldRotation();
  1762. Torque = torque;
  1763. }
  1764. /// <summary>
  1765. /// Apply physics to this part.
  1766. /// </summary>
  1767. /// <param name="rootObjectFlags"></param>
  1768. /// <param name="VolumeDetectActive"></param>
  1769. /// <param name="building"></param>
  1770. public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
  1771. {
  1772. VolumeDetectActive = _VolumeDetectActive;
  1773. if (!ParentGroup.Scene.CollidablePrims)
  1774. return;
  1775. if (PhysicsShapeType == (byte)PhysShapeType.none)
  1776. {
  1777. if(ParentID == 0)
  1778. m_physicsShapeType = DefaultPhysicsShapeType();
  1779. else
  1780. return;
  1781. }
  1782. bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
  1783. bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
  1784. if (_VolumeDetectActive)
  1785. isPhantom = true;
  1786. if (IsJoint())
  1787. {
  1788. DoPhysicsPropertyUpdate(isPhysical, true);
  1789. }
  1790. else
  1791. {
  1792. if ((!isPhantom || isPhysical || _VolumeDetectActive)
  1793. && !ParentGroup.IsAttachmentCheckFull()
  1794. && !(Shape.PathCurve == (byte)Extrusion.Flexible))
  1795. {
  1796. AddToPhysics(isPhysical, isPhantom, building, isPhysical);
  1797. UpdatePhysicsSubscribedEvents(); // not sure if appliable here
  1798. }
  1799. else
  1800. {
  1801. PhysActor = null; // just to be sure
  1802. RemFlag(PrimFlags.CameraDecoupled);
  1803. }
  1804. }
  1805. }
  1806. /// <summary>
  1807. /// Duplicates this part.
  1808. /// </summary>
  1809. /// <param name="localID"></param>
  1810. /// <param name="AgentID"></param>
  1811. /// <param name="GroupID"></param>
  1812. /// <param name="linkNum"></param>
  1813. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  1814. /// <returns></returns>
  1815. public SceneObjectPart Copy(uint plocalID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
  1816. {
  1817. // FIXME: This is dangerous since it's easy to forget to reset some references when necessary and end up
  1818. // with bugs that only occur in some circumstances (e.g. crossing between regions on the same simulator
  1819. // but not between regions on different simulators). Really, all copying should be done explicitly.
  1820. SceneObjectPart dupe = (SceneObjectPart)MemberwiseClone();
  1821. dupe.m_shape = m_shape.Copy();
  1822. dupe.m_regionHandle = m_regionHandle;
  1823. if (userExposed)
  1824. dupe.UUID = UUID.Random();
  1825. dupe.PhysActor = null;
  1826. dupe.OwnerID = AgentID;
  1827. dupe.GroupID = GroupID;
  1828. dupe.GroupPosition = GroupPosition;
  1829. dupe.OffsetPosition = OffsetPosition;
  1830. dupe.RotationOffset = RotationOffset;
  1831. dupe.Velocity = Velocity;
  1832. dupe.Acceleration = Acceleration;
  1833. dupe.AngularVelocity = AngularVelocity;
  1834. dupe.Flags = Flags;
  1835. dupe.OwnershipCost = OwnershipCost;
  1836. dupe.ObjectSaleType = ObjectSaleType;
  1837. dupe.SalePrice = SalePrice;
  1838. dupe.Category = Category;
  1839. dupe.m_rezzed = m_rezzed;
  1840. dupe.m_UndoRedo = null;
  1841. dupe.m_isSelected = false;
  1842. dupe.IgnoreUndoUpdate = false;
  1843. dupe.Undoing = false;
  1844. dupe.m_inventory = new SceneObjectPartInventory(dupe);
  1845. dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
  1846. if (userExposed)
  1847. {
  1848. dupe.ResetIDs(linkNum);
  1849. dupe.m_inventory.HasInventoryChanged = true;
  1850. }
  1851. else
  1852. {
  1853. dupe.m_inventory.HasInventoryChanged = m_inventory.HasInventoryChanged;
  1854. }
  1855. // Move afterwards ResetIDs as it clears the localID
  1856. dupe.LocalId = plocalID;
  1857. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1858. if(OwnerID != GroupID)
  1859. dupe.LastOwnerID = OwnerID;
  1860. else
  1861. dupe.LastOwnerID = LastOwnerID; // redundant ?
  1862. dupe.RezzerID = RezzerID;
  1863. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1864. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1865. dupe.Shape.ExtraParams = extraP;
  1866. dupe.m_sittingAvatars = new HashSet<ScenePresence>();
  1867. dupe.SitTargetAvatar = UUID.Zero;
  1868. // safeguard actual copy is done in sog.copy
  1869. dupe.KeyframeMotion = null;
  1870. dupe.PayPrice = (int[])PayPrice.Clone();
  1871. if(DynAttrs != null)
  1872. dupe.DynAttrs.CopyFrom(DynAttrs);
  1873. if (userExposed)
  1874. {
  1875. bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
  1876. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1877. }
  1878. if (dupe.PhysActor != null)
  1879. dupe.PhysActor.LocalID = plocalID;
  1880. dupe.PseudoCRC = (int)(DateTime.UtcNow.Ticks);
  1881. ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
  1882. // m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
  1883. return dupe;
  1884. }
  1885. /// <summary>
  1886. /// Do a physics property update for a NINJA joint.
  1887. /// </summary>
  1888. /// <param name="UsePhysics"></param>
  1889. /// <param name="isNew"></param>
  1890. protected void DoPhysicsPropertyUpdateForNinjaJoint(bool UsePhysics, bool isNew)
  1891. {
  1892. if (UsePhysics)
  1893. {
  1894. // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
  1895. // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.
  1896. PhysicsJointType jointType;
  1897. if (IsHingeJoint())
  1898. {
  1899. jointType = PhysicsJointType.Hinge;
  1900. }
  1901. else if (IsBallJoint())
  1902. {
  1903. jointType = PhysicsJointType.Ball;
  1904. }
  1905. else
  1906. {
  1907. jointType = PhysicsJointType.Ball;
  1908. }
  1909. List<string> bodyNames = new List<string>();
  1910. string RawParams = Description;
  1911. string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
  1912. string trackedBodyName = null;
  1913. if (jointParams.Length >= 2)
  1914. {
  1915. for (int iBodyName = 0; iBodyName < 2; iBodyName++)
  1916. {
  1917. string bodyName = jointParams[iBodyName];
  1918. bodyNames.Add(bodyName);
  1919. if (bodyName != "NULL")
  1920. {
  1921. if (trackedBodyName == null)
  1922. {
  1923. trackedBodyName = bodyName;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. SceneObjectPart trackedBody = ParentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
  1929. Quaternion localRotation = Quaternion.Identity;
  1930. if (trackedBody != null)
  1931. {
  1932. localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
  1933. }
  1934. else
  1935. {
  1936. // error, output it below
  1937. }
  1938. PhysicsJoint joint;
  1939. joint = ParentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
  1940. AbsolutePosition,
  1941. this.RotationOffset,
  1942. Description,
  1943. bodyNames,
  1944. trackedBodyName,
  1945. localRotation);
  1946. if (trackedBody == null)
  1947. {
  1948. ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
  1949. }
  1950. }
  1951. else
  1952. {
  1953. if (isNew)
  1954. {
  1955. // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
  1956. // delete, and if we try to delete it, due to asynchronous processing, the deletion request
  1957. // will get processed later at an indeterminate time, which could cancel a later-arriving
  1958. // joint creation request.
  1959. }
  1960. else
  1961. {
  1962. // here we turn off the joint object, so remove the joint from the physics scene
  1963. ParentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?
  1964. // make sure client isn't interpolating the joint proxy object
  1965. Stop();
  1966. }
  1967. }
  1968. }
  1969. /// <summary>
  1970. /// Do a physics propery update for this part.
  1971. /// now also updates phantom and volume detector
  1972. /// </summary>
  1973. /// <param name="UsePhysics"></param>
  1974. /// <param name="isNew"></param>
  1975. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1976. {
  1977. if (ParentGroup.Scene == null)
  1978. return;
  1979. if (!ParentGroup.Scene.PhysicalPrims && UsePhysics)
  1980. return;
  1981. if (IsJoint())
  1982. {
  1983. DoPhysicsPropertyUpdateForNinjaJoint(UsePhysics, isNew);
  1984. }
  1985. else
  1986. {
  1987. PhysicsActor pa = PhysActor;
  1988. if (pa != null)
  1989. {
  1990. if (UsePhysics != pa.IsPhysical)
  1991. ClampScale(UsePhysics);
  1992. if (UsePhysics != pa.IsPhysical || isNew)
  1993. {
  1994. if (pa.IsPhysical) // implies UsePhysics==false for this block
  1995. {
  1996. if (!isNew) // implies UsePhysics==false for this block
  1997. {
  1998. ParentGroup.Scene.RemovePhysicalPrim(1);
  1999. Stop();
  2000. if (pa.Phantom && !VolumeDetectActive)
  2001. {
  2002. RemoveFromPhysics();
  2003. return;
  2004. }
  2005. pa.IsPhysical = UsePhysics;
  2006. pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  2007. pa.OnOutOfBounds -= PhysicsOutOfBounds;
  2008. pa.delink();
  2009. if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  2010. {
  2011. // destroy all joints connected to this now deactivated body
  2012. ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
  2013. }
  2014. }
  2015. }
  2016. if (pa.IsPhysical != UsePhysics)
  2017. pa.IsPhysical = UsePhysics;
  2018. if (UsePhysics)
  2019. {
  2020. if (ParentGroup.RootPart.KeyframeMotion != null)
  2021. ParentGroup.RootPart.KeyframeMotion.Stop();
  2022. ParentGroup.RootPart.KeyframeMotion = null;
  2023. ParentGroup.Scene.AddPhysicalPrim(1);
  2024. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  2025. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  2026. if (_parentID != 0 && _parentID != LocalId)
  2027. {
  2028. PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
  2029. if (parentPa != null)
  2030. {
  2031. pa.link(parentPa);
  2032. }
  2033. }
  2034. }
  2035. }
  2036. bool phan = ((Flags & PrimFlags.Phantom) != 0);
  2037. if (pa.Phantom != phan)
  2038. pa.Phantom = phan;
  2039. // some engines dont' have this check still
  2040. // if (VolumeDetectActive != pa.IsVolumeDtc)
  2041. {
  2042. if (VolumeDetectActive)
  2043. pa.SetVolumeDetect(1);
  2044. else
  2045. pa.SetVolumeDetect(0);
  2046. }
  2047. // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
  2048. // mesh data.
  2049. // if (Shape.SculptEntry)
  2050. // CheckSculptAndLoad();
  2051. // else
  2052. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  2053. }
  2054. }
  2055. }
  2056. /// <summary>
  2057. /// Restore this part from the serialized xml representation.
  2058. /// </summary>
  2059. /// <param name="xmlReader"></param>
  2060. /// <returns></returns>
  2061. public static SceneObjectPart FromXml(XmlReader xmlReader)
  2062. {
  2063. SceneObjectPart part = SceneObjectSerializer.Xml2ToSOP(xmlReader);
  2064. // for tempOnRez objects, we have to fix the Expire date.
  2065. if ((part.Flags & PrimFlags.TemporaryOnRez) != 0)
  2066. part.ResetExpire();
  2067. return part;
  2068. }
  2069. public bool GetDieAtEdge()
  2070. {
  2071. if (ParentGroup.IsDeleted)
  2072. return false;
  2073. return ParentGroup.RootPart.DIE_AT_EDGE;
  2074. }
  2075. public bool GetReturnAtEdge()
  2076. {
  2077. if (ParentGroup.IsDeleted)
  2078. return false;
  2079. return ParentGroup.RootPart.RETURN_AT_EDGE;
  2080. }
  2081. public void SetReturnAtEdge(bool p)
  2082. {
  2083. if (ParentGroup.IsDeleted)
  2084. return;
  2085. ParentGroup.RootPart.RETURN_AT_EDGE = p;
  2086. }
  2087. public void SetStatusSandbox(bool p)
  2088. {
  2089. if (ParentGroup.IsDeleted)
  2090. return;
  2091. StatusSandboxPos = ParentGroup.RootPart.AbsolutePosition;
  2092. ParentGroup.RootPart.StatusSandbox = p;
  2093. }
  2094. public bool GetStatusSandbox()
  2095. {
  2096. if (ParentGroup.IsDeleted)
  2097. return false;
  2098. return ParentGroup.RootPart.StatusSandbox;
  2099. }
  2100. public int GetAxisRotation(int axis)
  2101. {
  2102. if (!ParentGroup.IsDeleted)
  2103. return ParentGroup.GetAxisRotation(axis);
  2104. return 0;
  2105. }
  2106. public uint GetEffectiveObjectFlags()
  2107. {
  2108. uint eff = (uint)Flags | (uint)LocalFlags;
  2109. if(m_inventory == null || m_inventory.Count == 0)
  2110. eff |= (uint)PrimFlags.InventoryEmpty;
  2111. return eff;
  2112. }
  2113. // some of this lines need be moved to other place later
  2114. // effective permitions considering only this part inventory contents perms
  2115. public uint AggregatedInnerOwnerPerms {get; private set; }
  2116. public uint AggregatedInnerGroupPerms {get; private set; }
  2117. public uint AggregatedInnerEveryonePerms {get; private set; }
  2118. private object InnerPermsLock = new object();
  2119. public void AggregateInnerPerms()
  2120. {
  2121. // assuming child prims permissions masks are irrelevant on a linkset
  2122. // root part is handle at SOG since its masks are the sog masks
  2123. const uint mask = (uint)PermissionMask.AllEffective;
  2124. uint owner = mask;
  2125. uint group = mask;
  2126. uint everyone = mask;
  2127. lock(InnerPermsLock) // do we really need this?
  2128. {
  2129. if(Inventory != null)
  2130. Inventory.AggregateInnerPerms(ref owner, ref group, ref everyone);
  2131. AggregatedInnerOwnerPerms = owner & mask;
  2132. AggregatedInnerGroupPerms = group & mask;
  2133. AggregatedInnerEveryonePerms = everyone & mask;
  2134. }
  2135. if(ParentGroup != null)
  2136. ParentGroup.InvalidateEffectivePerms();
  2137. }
  2138. // same as above but called during group Effective Permission validation
  2139. public void AggregatedInnerPermsForGroup()
  2140. {
  2141. // assuming child prims permissions masks are irrelevant on a linkset
  2142. // root part is handle at SOG since its masks are the sog masks
  2143. const uint mask = (uint)PermissionMask.AllEffective;
  2144. uint owner = mask;
  2145. uint group = mask;
  2146. uint everyone = mask;
  2147. lock(InnerPermsLock) // do we really need this?
  2148. {
  2149. if(Inventory != null)
  2150. Inventory.AggregateInnerPerms(ref owner, ref group, ref everyone);
  2151. AggregatedInnerOwnerPerms = owner & mask;
  2152. AggregatedInnerGroupPerms = group & mask;
  2153. AggregatedInnerEveryonePerms = everyone & mask;
  2154. }
  2155. }
  2156. public Vector3 GetGeometricCenter()
  2157. {
  2158. // this is not real geometric center but a average of positions relative to root prim acording to
  2159. // http://wiki.secondlife.com/wiki/llGetGeometricCenter
  2160. // ignoring tortured prims details since sl also seems to ignore
  2161. // so no real use in doing it on physics
  2162. if (ParentGroup.IsDeleted)
  2163. return new Vector3(0, 0, 0);
  2164. return ParentGroup.GetGeometricCenter();
  2165. }
  2166. public float GetMass()
  2167. {
  2168. PhysicsActor pa = PhysActor;
  2169. if (pa != null)
  2170. return pa.Mass;
  2171. else
  2172. return 0;
  2173. }
  2174. public Vector3 GetCenterOfMass()
  2175. {
  2176. if (ParentGroup.RootPart == this)
  2177. {
  2178. if (ParentGroup.IsDeleted)
  2179. return AbsolutePosition;
  2180. return ParentGroup.GetCenterOfMass();
  2181. }
  2182. PhysicsActor pa = PhysActor;
  2183. if (pa != null)
  2184. {
  2185. Vector3 tmp = pa.CenterOfMass;
  2186. return tmp;
  2187. }
  2188. else
  2189. return AbsolutePosition;
  2190. }
  2191. public Vector3 GetPartCenterOfMass()
  2192. {
  2193. PhysicsActor pa = PhysActor;
  2194. if (pa != null)
  2195. {
  2196. Vector3 tmp = pa.CenterOfMass;
  2197. return tmp;
  2198. }
  2199. else
  2200. return AbsolutePosition;
  2201. }
  2202. public Vector3 GetForce()
  2203. {
  2204. return Force;
  2205. }
  2206. /// <summary>
  2207. /// Method for a prim to get it's world position from the group.
  2208. /// </summary>
  2209. /// <remarks>
  2210. /// Remember, the Group Position simply gives the position of the group itself
  2211. /// </remarks>
  2212. /// <returns>A Linked Child Prim objects position in world</returns>
  2213. public Vector3 GetWorldPosition()
  2214. {
  2215. if (_parentID == 0)
  2216. return GroupPosition;
  2217. // If a child SOP, my position is relative to the root SOP so take
  2218. // my info and add the root's position and rotation to
  2219. // get my world position.
  2220. return ParentGroup.AbsolutePosition + OffsetPosition * ParentGroup.RootPart.RotationOffset;
  2221. }
  2222. /// <summary>
  2223. /// Gets the rotation of this prim offset by the group rotation
  2224. /// </summary>
  2225. /// <returns></returns>
  2226. public Quaternion GetWorldRotation()
  2227. {
  2228. if (_parentID == 0)
  2229. return RotationOffset;
  2230. // A child SOP's rotation is relative to the root SOP's rotation.
  2231. // Combine them to get my absolute rotation.
  2232. return ParentGroup.RootPart.RotationOffset * RotationOffset;
  2233. }
  2234. /// <summary>
  2235. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  2236. /// </summary>
  2237. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  2238. /// <param name="hoverType">Determines what the height is relative to </param>
  2239. /// <param name="tau">Number of seconds over which to reach target</param>
  2240. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  2241. {
  2242. ParentGroup.SetHoverHeight(height, hoverType, tau);
  2243. }
  2244. public void StopHover()
  2245. {
  2246. ParentGroup.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  2247. }
  2248. public virtual void OnGrab(Vector3 offsetPos, IClientAPI remoteClient)
  2249. {
  2250. }
  2251. public bool CollisionFilteredOut(UUID objectID, string objectName)
  2252. {
  2253. if(CollisionFilter.Count == 0)
  2254. return false;
  2255. if (CollisionFilter.ContainsValue(objectID.ToString()) ||
  2256. CollisionFilter.ContainsValue(objectID.ToString() + objectName) ||
  2257. CollisionFilter.ContainsValue(UUID.Zero.ToString() + objectName))
  2258. {
  2259. if (CollisionFilter.ContainsKey(1))
  2260. return false;
  2261. return true;
  2262. }
  2263. if (CollisionFilter.ContainsKey(1))
  2264. return true;
  2265. return false;
  2266. }
  2267. private DetectedObject CreateDetObject(SceneObjectPart obj)
  2268. {
  2269. DetectedObject detobj = new DetectedObject();
  2270. detobj.keyUUID = obj.UUID;
  2271. detobj.nameStr = obj.Name;
  2272. detobj.ownerUUID = obj.OwnerID;
  2273. detobj.posVector = obj.AbsolutePosition;
  2274. detobj.rotQuat = obj.GetWorldRotation();
  2275. detobj.velVector = obj.Velocity;
  2276. detobj.colliderType = 0;
  2277. detobj.groupUUID = obj.GroupID;
  2278. // allow detector link number to be seen, unlike spec
  2279. //if (VolumeDetectActive)
  2280. // detobj.linkNumber = 0;
  2281. //else
  2282. detobj.linkNumber = LinkNum;
  2283. return detobj;
  2284. }
  2285. private DetectedObject CreateDetObject(ScenePresence av)
  2286. {
  2287. DetectedObject detobj = new DetectedObject();
  2288. detobj.keyUUID = av.UUID;
  2289. detobj.nameStr = av.ControllingClient.Name;
  2290. detobj.ownerUUID = av.UUID;
  2291. detobj.posVector = av.AbsolutePosition;
  2292. detobj.rotQuat = av.Rotation;
  2293. detobj.velVector = av.Velocity;
  2294. detobj.colliderType = av.IsNPC ? 0x20 : 0x1; // OpenSim\Region\ScriptEngine\Shared\Helpers.cs
  2295. if(av.IsSatOnObject)
  2296. detobj.colliderType |= 0x4; //passive
  2297. else if(detobj.velVector != Vector3.Zero)
  2298. detobj.colliderType |= 0x2; //active
  2299. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2300. //if (VolumeDetectActive)
  2301. // detobj.linkNumber = 0;
  2302. //else
  2303. detobj.linkNumber = LinkNum;
  2304. return detobj;
  2305. }
  2306. private DetectedObject CreateDetObjectForGround()
  2307. {
  2308. DetectedObject detobj = new DetectedObject();
  2309. detobj.keyUUID = UUID.Zero;
  2310. detobj.nameStr = "";
  2311. detobj.ownerUUID = UUID.Zero;
  2312. detobj.posVector = ParentGroup.RootPart.AbsolutePosition;
  2313. detobj.rotQuat = Quaternion.Identity;
  2314. detobj.velVector = Vector3.Zero;
  2315. detobj.colliderType = 0;
  2316. detobj.groupUUID = UUID.Zero;
  2317. detobj.linkNumber = LinkNum;
  2318. return detobj;
  2319. }
  2320. private ColliderArgs CreateColliderArgs(SceneObjectPart dest, List<uint> colliders)
  2321. {
  2322. ColliderArgs colliderArgs = new ColliderArgs();
  2323. List<DetectedObject> colliding = new List<DetectedObject>();
  2324. Scene parentScene = ParentGroup.Scene;
  2325. foreach (uint localId in colliders)
  2326. {
  2327. if (localId == 0)
  2328. continue;
  2329. SceneObjectPart obj = parentScene.GetSceneObjectPart(localId);
  2330. if (obj != null)
  2331. {
  2332. if (!dest.CollisionFilteredOut(obj.UUID, obj.Name))
  2333. colliding.Add(CreateDetObject(obj));
  2334. }
  2335. else
  2336. {
  2337. ScenePresence av = parentScene.GetScenePresence(localId);
  2338. if (av != null && (!av.IsChildAgent))
  2339. {
  2340. if (!dest.CollisionFilteredOut(av.UUID, av.Name))
  2341. colliding.Add(CreateDetObject(av));
  2342. }
  2343. }
  2344. }
  2345. colliderArgs.Colliders = colliding;
  2346. return colliderArgs;
  2347. }
  2348. private delegate void ScriptCollidingNotification(uint localID, ColliderArgs message);
  2349. private void SendCollisionEvent(scriptEvents ev, List<uint> colliders, ScriptCollidingNotification notify)
  2350. {
  2351. bool sendToRoot = false;
  2352. ColliderArgs CollidingMessage;
  2353. if (colliders.Count > 0)
  2354. {
  2355. if ((ScriptEvents & ev) != 0)
  2356. {
  2357. CollidingMessage = CreateColliderArgs(this, colliders);
  2358. if (CollidingMessage.Colliders.Count > 0)
  2359. notify(LocalId, CollidingMessage);
  2360. if (PassCollisions)
  2361. sendToRoot = true;
  2362. }
  2363. else
  2364. {
  2365. if ((ParentGroup.RootPart.ScriptEvents & ev) != 0)
  2366. sendToRoot = true;
  2367. }
  2368. if (sendToRoot && ParentGroup.RootPart != this)
  2369. {
  2370. CollidingMessage = CreateColliderArgs(ParentGroup.RootPart, colliders);
  2371. if (CollidingMessage.Colliders.Count > 0)
  2372. notify(ParentGroup.RootPart.LocalId, CollidingMessage);
  2373. }
  2374. }
  2375. }
  2376. private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
  2377. {
  2378. bool sendToRoot = true;
  2379. ColliderArgs LandCollidingMessage = new ColliderArgs();
  2380. List<DetectedObject> colliding = new List<DetectedObject>();
  2381. colliding.Add(CreateDetObjectForGround());
  2382. LandCollidingMessage.Colliders = colliding;
  2383. if (Inventory.ContainsScripts())
  2384. {
  2385. if (!PassCollisions)
  2386. sendToRoot = false;
  2387. }
  2388. if ((ScriptEvents & ev) != 0)
  2389. notify(LocalId, LandCollidingMessage);
  2390. if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
  2391. {
  2392. notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
  2393. }
  2394. }
  2395. public void PhysicsCollision(EventArgs e)
  2396. {
  2397. if (ParentGroup.Scene == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  2398. return;
  2399. // this a thread from physics ( heartbeat )
  2400. bool thisHitLand = false;
  2401. bool startLand = false;
  2402. bool endedLand = false;
  2403. CollisionEventUpdate a = (CollisionEventUpdate)e;
  2404. Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
  2405. List<uint> thisHitColliders = new List<uint>();
  2406. List<uint> endedColliders = new List<uint>();
  2407. List<uint> startedColliders = new List<uint>();
  2408. if (collissionswith.Count == 0)
  2409. {
  2410. if (m_lastColliders.Count == 0 && !m_lastLandCollide)
  2411. return; // nothing to do
  2412. endedLand = m_lastLandCollide;
  2413. m_lastLandCollide = false;
  2414. foreach (uint localID in m_lastColliders)
  2415. {
  2416. endedColliders.Add(localID);
  2417. }
  2418. m_lastColliders.Clear();
  2419. }
  2420. else
  2421. {
  2422. List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
  2423. // calculate things that started colliding this time
  2424. // and build up list of colliders this time
  2425. if (!VolumeDetectActive && CollisionSoundType >= 0)
  2426. {
  2427. CollisionForSoundInfo soundinfo;
  2428. ContactPoint curcontact;
  2429. foreach (uint id in collissionswith.Keys)
  2430. {
  2431. if(id == 0)
  2432. {
  2433. thisHitLand = true;
  2434. if (!m_lastLandCollide)
  2435. {
  2436. startLand = true;
  2437. curcontact = collissionswith[id];
  2438. if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
  2439. {
  2440. soundinfo = new CollisionForSoundInfo();
  2441. soundinfo.colliderID = id;
  2442. soundinfo.position = curcontact.Position;
  2443. soundinfo.relativeVel = curcontact.RelativeSpeed;
  2444. soundinfolist.Add(soundinfo);
  2445. }
  2446. }
  2447. }
  2448. else
  2449. {
  2450. thisHitColliders.Add(id);
  2451. if (!m_lastColliders.Contains(id))
  2452. {
  2453. startedColliders.Add(id);
  2454. curcontact = collissionswith[id];
  2455. if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
  2456. {
  2457. soundinfo = new CollisionForSoundInfo();
  2458. soundinfo.colliderID = id;
  2459. soundinfo.position = curcontact.Position;
  2460. soundinfo.relativeVel = curcontact.RelativeSpeed;
  2461. soundinfolist.Add(soundinfo);
  2462. }
  2463. }
  2464. }
  2465. }
  2466. }
  2467. else
  2468. {
  2469. foreach (uint id in collissionswith.Keys)
  2470. {
  2471. if(id == 0)
  2472. {
  2473. thisHitLand = true;
  2474. if (!m_lastLandCollide)
  2475. startLand = true;
  2476. }
  2477. else
  2478. {
  2479. thisHitColliders.Add(id);
  2480. if (!m_lastColliders.Contains(id))
  2481. startedColliders.Add(id);
  2482. }
  2483. }
  2484. }
  2485. // calculate things that ended colliding
  2486. foreach (uint localID in m_lastColliders)
  2487. {
  2488. if (!thisHitColliders.Contains(localID))
  2489. endedColliders.Add(localID);
  2490. }
  2491. //add the items that started colliding this time to the last colliders list.
  2492. foreach (uint localID in startedColliders)
  2493. m_lastColliders.Add(localID);
  2494. // remove things that ended colliding from the last colliders list
  2495. foreach (uint localID in endedColliders)
  2496. m_lastColliders.Remove(localID);
  2497. if(m_lastLandCollide && !thisHitLand)
  2498. endedLand = true;
  2499. m_lastLandCollide = thisHitLand;
  2500. // play sounds.
  2501. if (soundinfolist.Count > 0)
  2502. CollisionSounds.PartCollisionSound(this, soundinfolist);
  2503. }
  2504. EventManager eventmanager = ParentGroup.Scene.EventManager;
  2505. SendCollisionEvent(scriptEvents.collision_start, startedColliders, eventmanager.TriggerScriptCollidingStart);
  2506. if (!VolumeDetectActive)
  2507. SendCollisionEvent(scriptEvents.collision , m_lastColliders , eventmanager.TriggerScriptColliding);
  2508. SendCollisionEvent(scriptEvents.collision_end , endedColliders , eventmanager.TriggerScriptCollidingEnd);
  2509. if (!VolumeDetectActive)
  2510. {
  2511. if (startLand)
  2512. SendLandCollisionEvent(scriptEvents.land_collision_start, eventmanager.TriggerScriptLandCollidingStart);
  2513. if (m_lastLandCollide)
  2514. SendLandCollisionEvent(scriptEvents.land_collision, eventmanager.TriggerScriptLandColliding);
  2515. if (endedLand)
  2516. SendLandCollisionEvent(scriptEvents.land_collision_end, eventmanager.TriggerScriptLandCollidingEnd);
  2517. }
  2518. }
  2519. // The Collision sounds code calls this
  2520. public void SendCollisionSound(UUID soundID, double volume, Vector3 position)
  2521. {
  2522. if (soundID == UUID.Zero)
  2523. return;
  2524. ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
  2525. if (soundModule == null)
  2526. return;
  2527. if (volume > 1)
  2528. volume = 1;
  2529. if (volume < 0)
  2530. volume = 0;
  2531. int now = Util.EnvironmentTickCount();
  2532. if(Util.EnvironmentTickCountSubtract(now, LastColSoundSentTime) < 200)
  2533. return;
  2534. LastColSoundSentTime = now;
  2535. UUID ownerID = OwnerID;
  2536. UUID objectID = ParentGroup.RootPart.UUID;
  2537. UUID parentID = ParentGroup.UUID;
  2538. ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
  2539. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle);
  2540. }
  2541. public void PhysicsOutOfBounds(Vector3 pos)
  2542. {
  2543. // Note: This is only being called on the root prim at this time.
  2544. m_log.ErrorFormat(
  2545. "[SCENE OBJECT PART]: Physical object {0}, localID {1} went out of bounds at {2} in {3}. Stopping at {4} and making non-physical.",
  2546. Name, LocalId, pos, ParentGroup.Scene.Name, AbsolutePosition);
  2547. RemFlag(PrimFlags.Physics);
  2548. DoPhysicsPropertyUpdate(false, true);
  2549. }
  2550. public void PhysicsRequestingTerseUpdate()
  2551. {
  2552. PhysicsActor pa = PhysActor;
  2553. if (pa != null)
  2554. {
  2555. Vector3 newpos = pa.Position;
  2556. if (!ParentGroup.Scene.PositionIsInCurrentRegion(newpos))
  2557. {
  2558. // Setting position outside current region will start region crossing
  2559. ParentGroup.AbsolutePosition = newpos;
  2560. return;
  2561. }
  2562. //ParentGroup.RootPart.m_groupPosition = newpos;
  2563. }
  2564. ScheduleTerseUpdate();
  2565. }
  2566. public void RemFlag(PrimFlags flag)
  2567. {
  2568. // PrimFlags prevflag = Flags;
  2569. if ((Flags & flag) != 0)
  2570. {
  2571. //m_log.Debug("Removing flag: " + ((PrimFlags)flag).ToString());
  2572. Flags &= ~flag;
  2573. }
  2574. //m_log.Debug("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  2575. //ScheduleFullUpdate();
  2576. }
  2577. public void RemoveScriptEvents(UUID scriptid)
  2578. {
  2579. lock (m_scriptEvents)
  2580. {
  2581. if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev))
  2582. {
  2583. if((ev & (scriptEvents.anyTarget)) != 0 && ParentGroup != null)
  2584. ParentGroup.RemoveScriptTargets(scriptid);
  2585. m_scriptEvents.Remove(scriptid);
  2586. aggregateScriptEvents();
  2587. }
  2588. }
  2589. }
  2590. public void RemoveScriptTargets(UUID scriptid)
  2591. {
  2592. if(ParentGroup != null)
  2593. ParentGroup.RemoveScriptTargets(scriptid);
  2594. }
  2595. /// <summary>
  2596. /// Reset UUIDs for this part. This involves generate this part's own UUID and
  2597. /// generating new UUIDs for all the items in the inventory.
  2598. /// </summary>
  2599. /// <param name="linkNum">Link number for the part</param>
  2600. public void ResetIDs(int linkNum)
  2601. {
  2602. UUID = UUID.Random();
  2603. LinkNum = linkNum;
  2604. LocalId = 0;
  2605. Inventory.ResetInventoryIDs();
  2606. ++PseudoCRC;
  2607. }
  2608. private void ClampScale(bool isPhysical)
  2609. {
  2610. float minsize = isPhysical ? ParentGroup.Scene.m_minPhys : ParentGroup.Scene.m_minNonphys;
  2611. float maxsize = isPhysical ? ParentGroup.Scene.m_maxPhys : ParentGroup.Scene.m_maxNonphys;
  2612. Vector3 scale = Scale;
  2613. bool changed = false;
  2614. if (scale.X < minsize)
  2615. {
  2616. scale.X = minsize;
  2617. changed = true;
  2618. }
  2619. else if (scale.X > maxsize)
  2620. {
  2621. scale.X = maxsize;
  2622. changed = true;
  2623. }
  2624. if (scale.Y < minsize)
  2625. {
  2626. scale.Y = minsize;
  2627. changed = true;
  2628. }
  2629. else if (scale.Y > maxsize)
  2630. {
  2631. scale.Y = maxsize;
  2632. changed = true;
  2633. }
  2634. if (scale.Z < minsize)
  2635. {
  2636. scale.Z = minsize;
  2637. changed = true;
  2638. }
  2639. else if (scale.Z > maxsize)
  2640. {
  2641. scale.Z = maxsize;
  2642. changed = true;
  2643. }
  2644. if (changed)
  2645. Scale = scale;
  2646. }
  2647. /// <summary>
  2648. /// Set the scale of this part.
  2649. /// </summary>
  2650. /// <remarks>
  2651. /// Unlike the scale property, this checks the new size against scene limits and schedules a full property
  2652. /// update to viewers.
  2653. /// </remarks>
  2654. /// <param name="scale"></param>
  2655. public void Resize(Vector3 scale)
  2656. {
  2657. PhysicsActor pa = PhysActor;
  2658. if (ParentGroup.Scene != null)
  2659. {
  2660. float minsize = ParentGroup.Scene.m_minNonphys;
  2661. float maxsize = ParentGroup.Scene.m_maxNonphys;
  2662. if (pa != null && pa.IsPhysical)
  2663. {
  2664. minsize = ParentGroup.Scene.m_minPhys;
  2665. maxsize = ParentGroup.Scene.m_maxPhys;
  2666. }
  2667. scale.X = Util.Clamp(scale.X, minsize, maxsize);
  2668. scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
  2669. scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
  2670. }
  2671. // m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale);
  2672. Scale = scale;
  2673. ParentGroup.HasGroupChanged = true;
  2674. ScheduleFullUpdate();
  2675. }
  2676. public void RotLookAt(Quaternion target, float strength, float damping)
  2677. {
  2678. if(ParentGroup.IsDeleted)
  2679. return;
  2680. // for now we only handle physics case
  2681. if(!ParentGroup.UsesPhysics || ParentGroup.IsAttachment)
  2682. return;
  2683. // physical is SOG
  2684. if(ParentGroup.RootPart != this)
  2685. {
  2686. ParentGroup.RotLookAt(target, strength, damping);
  2687. return;
  2688. }
  2689. APIDDamp = damping;
  2690. APIDStrength = strength;
  2691. APIDTarget = target;
  2692. if (APIDStrength <= 0)
  2693. {
  2694. m_log.WarnFormat("[SceneObjectPart] Invalid rotation strength {0}",APIDStrength);
  2695. return;
  2696. }
  2697. APIDActive = true;
  2698. // Necessary to get the lookat deltas applied
  2699. ParentGroup.QueueForUpdateCheck();
  2700. }
  2701. public void StartLookAt(Quaternion target, float strength, float damping)
  2702. {
  2703. if(ParentGroup.IsDeleted)
  2704. return;
  2705. // non physical is done on LSL
  2706. if(ParentGroup.IsAttachment || !ParentGroup.UsesPhysics)
  2707. return;
  2708. // physical is SOG
  2709. if(ParentGroup.RootPart != this)
  2710. ParentGroup.RotLookAt(target, strength, damping);
  2711. else
  2712. RotLookAt(target,strength,damping);
  2713. }
  2714. public void StopLookAt()
  2715. {
  2716. if(ParentGroup.IsDeleted)
  2717. return;
  2718. if(ParentGroup.RootPart != this && ParentGroup.UsesPhysics)
  2719. ParentGroup.StopLookAt();
  2720. // just in case do this always
  2721. if(APIDActive)
  2722. AngularVelocity = Vector3.Zero;
  2723. APIDActive = false;
  2724. }
  2725. /// <summary>
  2726. /// Schedules this prim for a full update
  2727. /// </summary>
  2728. public void ScheduleFullUpdate()
  2729. {
  2730. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2731. return;
  2732. ++PseudoCRC;
  2733. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2734. return;
  2735. ParentGroup.QueueForUpdateCheck(); // just in case
  2736. lock(UpdateFlagLock)
  2737. UpdateFlag |= PrimUpdateFlags.FullUpdate;
  2738. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, true);
  2739. }
  2740. public void ScheduleFullAnimUpdate()
  2741. {
  2742. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2743. return;
  2744. ++PseudoCRC;
  2745. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2746. return;
  2747. PrimUpdateFlags update = PrimUpdateFlags.FullUpdatewithAnim;
  2748. if (Animations == null || !ParentGroup.RootPart.Shape.MeshFlagEntry)
  2749. update = PrimUpdateFlags.FullUpdate;
  2750. ParentGroup.QueueForUpdateCheck(); // just in case
  2751. lock (UpdateFlagLock)
  2752. UpdateFlag |= update;
  2753. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, true);
  2754. }
  2755. /// <summary>
  2756. /// Schedule a terse update for this prim. Terse updates only send position,
  2757. /// rotation, velocity and rotational velocity information.
  2758. /// </summary>
  2759. public void ScheduleTerseUpdate()
  2760. {
  2761. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2762. return;
  2763. ++PseudoCRC;
  2764. ParentGroup.HasGroupChanged = true;
  2765. if(ParentGroup.Scene.GetNumberOfClients() == 0)
  2766. return;
  2767. ParentGroup.QueueForUpdateCheck();
  2768. bool isfull = false;
  2769. PrimUpdateFlags update;
  2770. if (ParentGroup.IsAttachment)
  2771. {
  2772. update = PrimUpdateFlags.FullUpdate;
  2773. isfull = true;
  2774. }
  2775. else
  2776. update = PrimUpdateFlags.TerseUpdate;
  2777. lock (UpdateFlagLock)
  2778. UpdateFlag |= update;
  2779. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, isfull);
  2780. }
  2781. public void ScheduleUpdate(PrimUpdateFlags update)
  2782. {
  2783. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.Scene == null)
  2784. return;
  2785. if (Animations == null)
  2786. update &= ~PrimUpdateFlags.Animations;
  2787. if (update == PrimUpdateFlags.None)
  2788. return;
  2789. ++PseudoCRC;
  2790. ParentGroup.HasGroupChanged = true;
  2791. if (ParentGroup.Scene.GetNumberOfClients() == 0)
  2792. return;
  2793. bool isfull = false;
  2794. if (ParentGroup.IsAttachment)
  2795. {
  2796. update |= PrimUpdateFlags.FullUpdate;
  2797. isfull = true;
  2798. }
  2799. lock (UpdateFlagLock)
  2800. UpdateFlag |= update;
  2801. ParentGroup.QueueForUpdateCheck();
  2802. ParentGroup.Scene.EventManager.TriggerSceneObjectPartUpdated(this, isfull);
  2803. }
  2804. public void ScriptSetPhysicsStatus(bool UsePhysics)
  2805. {
  2806. ParentGroup.ScriptSetPhysicsStatus(UsePhysics);
  2807. }
  2808. /// <summary>
  2809. /// Send a full update to the client for the given part
  2810. /// </summary>
  2811. /// <param name="remoteClient"></param>
  2812. protected internal void SendFullUpdate(IClientAPI remoteClient)
  2813. {
  2814. if (ParentGroup == null)
  2815. return;
  2816. if (ParentGroup.IsAttachment)
  2817. {
  2818. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2819. if (sp != null)
  2820. sp.SendAttachmentUpdate(this, PrimUpdateFlags.FullUpdate);
  2821. }
  2822. else
  2823. {
  2824. SendUpdateToClient(remoteClient, PrimUpdateFlags.FullUpdate);
  2825. }
  2826. }
  2827. protected internal void SendUpdate(IClientAPI remoteClient, PrimUpdateFlags update)
  2828. {
  2829. if (ParentGroup == null)
  2830. return;
  2831. if (ParentGroup.IsAttachment)
  2832. {
  2833. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2834. if (sp != null)
  2835. sp.SendAttachmentUpdate(this, update);
  2836. }
  2837. else
  2838. {
  2839. SendUpdateToClient(remoteClient, update);
  2840. }
  2841. }
  2842. /// <summary>
  2843. /// Send a full update for this part to all clients.
  2844. /// </summary>
  2845. public void SendFullUpdateToAllClientsNoAttachment()
  2846. {
  2847. if (ParentGroup == null)
  2848. return;
  2849. ++PseudoCRC;
  2850. // Update the "last" values
  2851. lock (UpdateFlagLock)
  2852. {
  2853. m_lastPosition = AbsolutePosition;
  2854. m_lastRotation = RotationOffset;
  2855. m_lastVelocity = Velocity;
  2856. m_lastAcceleration = Acceleration;
  2857. m_lastAngularVelocity = AngularVelocity;
  2858. m_lastUpdateSentTime = Util.GetTimeStampMS();
  2859. UpdateFlag &= ~PrimUpdateFlags.FullUpdate;
  2860. }
  2861. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2862. {
  2863. SendUpdateToClient(avatar.ControllingClient, PrimUpdateFlags.FullUpdate);
  2864. });
  2865. }
  2866. public void SendFullUpdateToAllClients()
  2867. {
  2868. if (ParentGroup == null)
  2869. return;
  2870. ++PseudoCRC;
  2871. // Update the "last" values
  2872. lock (UpdateFlagLock)
  2873. {
  2874. m_lastPosition = AbsolutePosition;
  2875. m_lastRotation = RotationOffset;
  2876. m_lastVelocity = Velocity;
  2877. m_lastAcceleration = Acceleration;
  2878. m_lastAngularVelocity = AngularVelocity;
  2879. m_lastUpdateSentTime = Util.GetTimeStampMS();
  2880. UpdateFlag &= ~PrimUpdateFlags.FullUpdate;
  2881. }
  2882. if (ParentGroup.IsAttachment)
  2883. {
  2884. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  2885. if (sp != null)
  2886. sp.SendAttachmentUpdate(this, PrimUpdateFlags.FullUpdate);
  2887. }
  2888. else
  2889. {
  2890. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2891. {
  2892. SendUpdateToClient(avatar.ControllingClient, PrimUpdateFlags.FullUpdate);
  2893. });
  2894. }
  2895. }
  2896. private const float ROTATION_TOLERANCE = 0.01f;
  2897. private const float VELOCITY_TOLERANCE = 0.1f;
  2898. private const float ANGVELOCITY_TOLERANCE = 0.005f;
  2899. private const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
  2900. private const double TIME_MS_TOLERANCE = 250.0; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
  2901. private Vector3 ClampVectorForTerseUpdate(Vector3 v, float max)
  2902. {
  2903. float a, b;
  2904. a = Math.Abs(v.X);
  2905. b = Math.Abs(v.Y);
  2906. if (b > a)
  2907. a = b;
  2908. b = Math.Abs(v.Z);
  2909. if (b > a)
  2910. a = b;
  2911. if (a > max)
  2912. {
  2913. a = max / a;
  2914. v.X *= a;
  2915. v.Y *= a;
  2916. v.Z *= a;
  2917. }
  2918. return v;
  2919. }
  2920. /// <summary>
  2921. /// Tell all the prims which have had updates scheduled
  2922. /// </summary>
  2923. public void SendScheduledUpdates(double now)
  2924. {
  2925. PrimUpdateFlags current;
  2926. lock (UpdateFlagLock)
  2927. {
  2928. current = UpdateFlag;
  2929. if (current == PrimUpdateFlags.None)
  2930. return;
  2931. if(current == PrimUpdateFlags.TerseUpdate)
  2932. {
  2933. while(true) // just to avoid ugly goto
  2934. {
  2935. double elapsed = now - m_lastUpdateSentTime;
  2936. if (elapsed > TIME_MS_TOLERANCE)
  2937. break;
  2938. if ( !Acceleration.ApproxEquals(m_lastAcceleration, VELOCITY_TOLERANCE))
  2939. break;
  2940. Vector3 curvel = ClampVectorForTerseUpdate(Velocity, 128f);
  2941. Vector3 tmp = ClampVectorForTerseUpdate(m_lastVelocity, 128f);
  2942. if (!curvel.ApproxEquals(tmp, VELOCITY_TOLERANCE))
  2943. break;
  2944. if (Math.Abs(curvel.X) < 1e-4 && Math.Abs(curvel.Y) < 1e-4 && Math.Abs(curvel.Z) < 1e-4)
  2945. {
  2946. if (!AbsolutePosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE))
  2947. break;
  2948. if ( Math.Abs(m_lastVelocity.X) > 1e-4 ||
  2949. Math.Abs(m_lastVelocity.Y) > 1e-4 ||
  2950. Math.Abs(m_lastVelocity.Z) > 1e-4
  2951. )
  2952. break;
  2953. }
  2954. Vector3 angvel = ClampVectorForTerseUpdate(AngularVelocity, 64f);
  2955. tmp = ClampVectorForTerseUpdate(m_lastAngularVelocity, 64f);
  2956. if (!angvel.ApproxEquals(tmp, ANGVELOCITY_TOLERANCE))
  2957. break;
  2958. if ( Math.Abs(AngularVelocity.X) < 1e-4 &&
  2959. Math.Abs(AngularVelocity.Y) < 1e-4 &&
  2960. Math.Abs(AngularVelocity.Z) < 1e-4 &&
  2961. !RotationOffset.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE)
  2962. )
  2963. break;
  2964. return;
  2965. }
  2966. }
  2967. if((current & PrimUpdateFlags.TerseUpdate) != 0)
  2968. {
  2969. m_lastPosition = AbsolutePosition;
  2970. m_lastRotation = RotationOffset;
  2971. m_lastVelocity = Velocity;
  2972. m_lastAcceleration = Acceleration;
  2973. m_lastAngularVelocity = AngularVelocity;
  2974. m_lastUpdateSentTime = now;
  2975. }
  2976. UpdateFlag = PrimUpdateFlags.None;
  2977. }
  2978. ParentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2979. {
  2980. SendUpdateToClient(avatar.ControllingClient, current);
  2981. });
  2982. }
  2983. /// <summary>
  2984. /// Send a terse update to all clients
  2985. /// </summary>
  2986. public void SendTerseUpdateToAllClientsInternal()
  2987. {
  2988. if (ParentGroup == null || ParentGroup.Scene == null)
  2989. return;
  2990. lock(UpdateFlagLock)
  2991. {
  2992. UpdateFlag &= ~PrimUpdateFlags.TerseUpdate;
  2993. // Update the "last" values
  2994. m_lastPosition = AbsolutePosition;
  2995. m_lastRotation = RotationOffset;
  2996. m_lastVelocity = Velocity;
  2997. m_lastAcceleration = Acceleration;
  2998. m_lastAngularVelocity = AngularVelocity;
  2999. m_lastUpdateSentTime = Util.GetTimeStampMS();
  3000. }
  3001. ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
  3002. {
  3003. SendTerseUpdateToClient(client);
  3004. });
  3005. }
  3006. public void SendTerseUpdateToAllClients()
  3007. {
  3008. if (ParentGroup == null || ParentGroup.Scene == null)
  3009. return;
  3010. lock(UpdateFlagLock)
  3011. {
  3012. UpdateFlag &= ~PrimUpdateFlags.TerseUpdate;
  3013. // Update the "last" values
  3014. m_lastPosition = AbsolutePosition;
  3015. m_lastRotation = RotationOffset;
  3016. m_lastVelocity = Velocity;
  3017. m_lastAcceleration = Acceleration;
  3018. m_lastAngularVelocity = AngularVelocity;
  3019. m_lastUpdateSentTime = Util.GetTimeStampMS();
  3020. }
  3021. if (ParentGroup.IsAttachment)
  3022. {
  3023. ScenePresence sp = ParentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  3024. if (sp != null)
  3025. {
  3026. sp.SendAttachmentUpdate(this, PrimUpdateFlags.TerseUpdate);
  3027. }
  3028. }
  3029. else
  3030. {
  3031. ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
  3032. {
  3033. SendTerseUpdateToClient(client);
  3034. });
  3035. }
  3036. }
  3037. public void SetAxisRotation(int axis, int rotate)
  3038. {
  3039. ParentGroup.SetAxisRotation(axis, rotate);
  3040. //Cannot use ScriptBaseClass constants as no referance to it currently.
  3041. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_X) != 0)
  3042. STATUS_ROTATE_X = rotate;
  3043. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Y) != 0)
  3044. STATUS_ROTATE_Y = rotate;
  3045. if ((axis & (int)SceneObjectGroup.axisSelect.STATUS_ROTATE_Z) != 0)
  3046. STATUS_ROTATE_Z = rotate;
  3047. }
  3048. public void SetBuoyancy(float fvalue)
  3049. {
  3050. Buoyancy = fvalue;
  3051. }
  3052. public void SetDieAtEdge(bool p)
  3053. {
  3054. if (ParentGroup.IsDeleted)
  3055. return;
  3056. ParentGroup.RootPart.DIE_AT_EDGE = p;
  3057. }
  3058. public void SetFloatOnWater(int floatYN)
  3059. {
  3060. PhysicsActor pa = PhysActor;
  3061. if (pa != null)
  3062. pa.FloatOnWater = (floatYN == 1);
  3063. }
  3064. public void SetForce(Vector3 force)
  3065. {
  3066. Force = force;
  3067. }
  3068. public PhysicsInertiaData PhysicsInertia
  3069. {
  3070. get
  3071. {
  3072. return m_physicsInertia;
  3073. }
  3074. set
  3075. {
  3076. m_physicsInertia = value;
  3077. }
  3078. }
  3079. public SOPVehicle VehicleParams
  3080. {
  3081. get
  3082. {
  3083. return m_vehicleParams;
  3084. }
  3085. set
  3086. {
  3087. m_vehicleParams = value;
  3088. }
  3089. }
  3090. public int VehicleType
  3091. {
  3092. get
  3093. {
  3094. if (m_vehicleParams == null)
  3095. return (int)Vehicle.TYPE_NONE;
  3096. else
  3097. return (int)m_vehicleParams.Type;
  3098. }
  3099. set
  3100. {
  3101. SetVehicleType(value);
  3102. }
  3103. }
  3104. public void SetVehicleType(int type)
  3105. {
  3106. m_vehicleParams = null;
  3107. if (type == (int)Vehicle.TYPE_NONE)
  3108. {
  3109. if (_parentID ==0 && PhysActor != null)
  3110. PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
  3111. return;
  3112. }
  3113. m_vehicleParams = new SOPVehicle();
  3114. m_vehicleParams.ProcessTypeChange((Vehicle)type);
  3115. {
  3116. if (_parentID ==0 && PhysActor != null)
  3117. PhysActor.VehicleType = type;
  3118. return;
  3119. }
  3120. }
  3121. public void SetVehicleFlags(int param, bool remove)
  3122. {
  3123. if (m_vehicleParams == null)
  3124. return;
  3125. m_vehicleParams.ProcessVehicleFlags(param, remove);
  3126. if (_parentID == 0 && PhysActor != null)
  3127. {
  3128. PhysActor.VehicleFlags(param, remove);
  3129. }
  3130. }
  3131. public void SetVehicleFloatParam(int param, float value)
  3132. {
  3133. if (m_vehicleParams == null)
  3134. return;
  3135. m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
  3136. if (_parentID == 0 && PhysActor != null)
  3137. {
  3138. PhysActor.VehicleFloatParam(param, value);
  3139. }
  3140. }
  3141. public void SetVehicleVectorParam(int param, Vector3 value)
  3142. {
  3143. if (m_vehicleParams == null)
  3144. return;
  3145. m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
  3146. if (_parentID == 0 && PhysActor != null)
  3147. {
  3148. PhysActor.VehicleVectorParam(param, value);
  3149. }
  3150. }
  3151. public void SetVehicleRotationParam(int param, Quaternion rotation)
  3152. {
  3153. if (m_vehicleParams == null)
  3154. return;
  3155. m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
  3156. if (_parentID == 0 && PhysActor != null)
  3157. {
  3158. PhysActor.VehicleRotationParam(param, rotation);
  3159. }
  3160. }
  3161. /// <summary>
  3162. /// Set the color & alpha of prim faces
  3163. /// </summary>
  3164. /// <param name="face"></param>
  3165. /// <param name="color"></param>
  3166. /// <param name="alpha"></param>
  3167. public void SetFaceColorAlpha(int face, Vector3 color, double ?alpha)
  3168. {
  3169. Vector3 clippedColor = Util.Clip(color, 0.0f, 1.0f);
  3170. float clippedAlpha = alpha.HasValue ?
  3171. Util.Clip((float)alpha.Value, 0.0f, 1.0f) : 0;
  3172. // The only way to get a deep copy/ If we don't do this, we can
  3173. // never detect color changes further down.
  3174. Byte[] buf = Shape.Textures.GetBytes();
  3175. Primitive.TextureEntry tex = new Primitive.TextureEntry(buf, 0, buf.Length);
  3176. Color4 texcolor;
  3177. int nsides = GetNumberOfSides();
  3178. if (face >= 0 && face < nsides)
  3179. {
  3180. texcolor = tex.CreateFace((uint)face).RGBA;
  3181. texcolor.R = clippedColor.X;
  3182. texcolor.G = clippedColor.Y;
  3183. texcolor.B = clippedColor.Z;
  3184. if (alpha.HasValue)
  3185. {
  3186. texcolor.A = clippedAlpha;
  3187. }
  3188. tex.FaceTextures[face].RGBA = texcolor;
  3189. UpdateTextureEntry(tex);
  3190. return;
  3191. }
  3192. else if (face == ALL_SIDES)
  3193. {
  3194. for (uint i = 0; i < nsides; i++)
  3195. {
  3196. if (tex.FaceTextures[i] != null)
  3197. {
  3198. texcolor = tex.FaceTextures[i].RGBA;
  3199. texcolor.R = clippedColor.X;
  3200. texcolor.G = clippedColor.Y;
  3201. texcolor.B = clippedColor.Z;
  3202. if (alpha.HasValue)
  3203. {
  3204. texcolor.A = clippedAlpha;
  3205. }
  3206. tex.FaceTextures[i].RGBA = texcolor;
  3207. }
  3208. texcolor = tex.DefaultTexture.RGBA;
  3209. texcolor.R = clippedColor.X;
  3210. texcolor.G = clippedColor.Y;
  3211. texcolor.B = clippedColor.Z;
  3212. if (alpha.HasValue)
  3213. {
  3214. texcolor.A = clippedAlpha;
  3215. }
  3216. tex.DefaultTexture.RGBA = texcolor;
  3217. }
  3218. UpdateTextureEntry(tex);
  3219. return;
  3220. }
  3221. }
  3222. /// <summary>
  3223. /// Get the number of sides that this part has.
  3224. /// </summary>
  3225. /// <returns></returns>
  3226. public int GetNumberOfSides()
  3227. {
  3228. int ret = 0;
  3229. int cut;
  3230. if(Shape.SculptEntry)
  3231. {
  3232. if (Shape.SculptType != (byte)SculptType.Mesh)
  3233. return 1; // sculp
  3234. //hack to detect new upload with faces data enconded on pbs
  3235. if ((Shape.ProfileCurve & 0xf0) != (byte)HollowShape.Triangle)
  3236. // old broken upload TODO
  3237. return 8;
  3238. }
  3239. PrimType primType = GetPrimType(true);
  3240. switch (primType)
  3241. {
  3242. case PrimType.BOX:
  3243. ret = 6;
  3244. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut case
  3245. {
  3246. // removed sides
  3247. if (Shape.ProfileBegin > 0)
  3248. {
  3249. cut = Shape.ProfileBegin;
  3250. cut /= 12500;
  3251. ret -= cut;
  3252. }
  3253. if (Shape.ProfileEnd > 0)
  3254. {
  3255. cut = Shape.ProfileEnd;
  3256. cut /= 12500;
  3257. ret -= cut;
  3258. }
  3259. ret += 2;
  3260. }
  3261. break;
  3262. case PrimType.PRISM:
  3263. ret = 5;
  3264. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut case
  3265. {
  3266. // removed sides
  3267. if (Shape.ProfileBegin > 0)
  3268. {
  3269. cut = (Shape.ProfileBegin);
  3270. if(cut >= 16667 )
  3271. ret--;
  3272. if(cut >= 33333 )
  3273. ret--;
  3274. }
  3275. if (Shape.ProfileEnd > 0)
  3276. {
  3277. cut = (Shape.ProfileEnd);
  3278. if(cut >= 16667 )
  3279. ret--;
  3280. if(cut >= 33333 )
  3281. ret--;
  3282. }
  3283. ret += 2; // both cut faces
  3284. }
  3285. break;
  3286. case PrimType.CYLINDER:
  3287. ret = 3;
  3288. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // cut
  3289. ret += 2;
  3290. break;
  3291. case PrimType.SPHERE:
  3292. ret = 1;
  3293. // cut faces exist if cut or skew or unequal twist limits
  3294. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3295. ret += 2;
  3296. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0 || Shape.ProfileHollow > 0) // dimple also if hollow
  3297. ret += 2;
  3298. break;
  3299. case PrimType.TORUS:
  3300. ret = 1;
  3301. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3302. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3303. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3304. ret += 2;
  3305. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3306. ret += 2;
  3307. break;
  3308. case PrimType.TUBE:
  3309. ret = 4;
  3310. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3311. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3312. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3313. ret += 2;
  3314. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3315. {
  3316. if (Shape.ProfileBegin > 0)
  3317. {
  3318. cut = Shape.ProfileBegin;
  3319. cut /= 12500;
  3320. ret -= cut;
  3321. }
  3322. if (Shape.ProfileEnd > 0)
  3323. {
  3324. cut = Shape.ProfileEnd;
  3325. cut /= 12500;
  3326. ret -= cut;
  3327. }
  3328. ret += 2;
  3329. }
  3330. break;
  3331. case PrimType.RING:
  3332. ret = 3;
  3333. if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0
  3334. || Shape.PathTaperX != 0 || Shape.PathTaperY != 0 || Shape.PathRevolutions > 0
  3335. || Shape.PathRadiusOffset != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
  3336. ret += 2;
  3337. if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0) // profile cut
  3338. {
  3339. if (Shape.ProfileBegin > 0)
  3340. {
  3341. cut = Shape.ProfileBegin;
  3342. if(cut >= 16667 )
  3343. ret--;
  3344. if(cut >= 33333 )
  3345. ret--;
  3346. }
  3347. if (Shape.ProfileEnd > 0)
  3348. {
  3349. cut = Shape.ProfileEnd;
  3350. if(cut >= 16667 )
  3351. ret--;
  3352. if(cut >= 33333 )
  3353. ret--;
  3354. }
  3355. ret += 2;
  3356. }
  3357. break;
  3358. }
  3359. // hollow face commum to all
  3360. if (Shape.ProfileHollow > 0)
  3361. ret += 1;
  3362. return ret;
  3363. }
  3364. /// <summary>
  3365. /// Tell us what type this prim is
  3366. /// </summary>
  3367. /// <param name="primShape"></param>
  3368. /// <returns></returns>
  3369. public PrimType GetPrimType(bool ignoreSculpt = false)
  3370. {
  3371. if (Shape.SculptEntry && !ignoreSculpt)
  3372. return PrimType.SCULPT;
  3373. ProfileShape ps = (ProfileShape)(Shape.ProfileCurve & 0x07);
  3374. if (ps == ProfileShape.Square)
  3375. {
  3376. if (Shape.PathCurve == (byte)Extrusion.Straight)
  3377. return PrimType.BOX;
  3378. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3379. return PrimType.TUBE;
  3380. }
  3381. else if (ps == ProfileShape.Circle)
  3382. {
  3383. if (Shape.PathCurve == (byte)Extrusion.Straight || Shape.PathCurve == (byte)Extrusion.Flexible)
  3384. return PrimType.CYLINDER;
  3385. // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
  3386. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3387. return PrimType.TORUS;
  3388. }
  3389. else if (ps == ProfileShape.HalfCircle)
  3390. {
  3391. if (Shape.PathCurve == (byte)Extrusion.Curve1 || Shape.PathCurve == (byte)Extrusion.Curve2)
  3392. return PrimType.SPHERE;
  3393. }
  3394. else if (ps == ProfileShape.EquilateralTriangle)
  3395. {
  3396. if (Shape.PathCurve == (byte)Extrusion.Straight || Shape.PathCurve == (byte)Extrusion.Flexible)
  3397. return PrimType.PRISM;
  3398. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  3399. return PrimType.RING;
  3400. }
  3401. return PrimType.BOX;
  3402. }
  3403. public void SetGroup(UUID groupID, IClientAPI client)
  3404. {
  3405. // Scene.AddNewPrims() calls with client == null so can't use this.
  3406. // m_log.DebugFormat(
  3407. // "[SCENE OBJECT PART]: Setting group for {0} to {1} for {2}",
  3408. // Name, groupID, OwnerID);
  3409. ++PseudoCRC;
  3410. GroupID = groupID;
  3411. // if (client != null)
  3412. // SendPropertiesToClient(client);
  3413. lock(UpdateFlagLock)
  3414. UpdateFlag |= PrimUpdateFlags.FullUpdate;
  3415. }
  3416. /// <summary>
  3417. /// Set the parent group of this prim.
  3418. /// </summary>
  3419. public void SetParent(SceneObjectGroup parent)
  3420. {
  3421. ParentGroup = parent;
  3422. }
  3423. // Use this for attachments! LocalID should be avatar's localid
  3424. public void SetParentLocalId(uint localID)
  3425. {
  3426. ParentID = localID;
  3427. }
  3428. public void SetPhysicsAxisRotation()
  3429. {
  3430. PhysicsActor pa = PhysActor;
  3431. if (pa != null)
  3432. {
  3433. pa.LockAngularMotion(RotationAxisLocks);
  3434. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  3435. }
  3436. }
  3437. /// <summary>
  3438. /// Set the events that this part will pass on to listeners.
  3439. /// </summary>
  3440. /// <param name="scriptid"></param>
  3441. /// <param name="events"></param>
  3442. public void SetScriptEvents(UUID scriptid, int events)
  3443. {
  3444. // m_log.DebugFormat(
  3445. // "[SCENE OBJECT PART]: Set script events for script with id {0} on {1}/{2} to {3} in {4}",
  3446. // scriptid, Name, ParentGroup.Name, events, ParentGroup.Scene.Name);
  3447. // scriptEvents oldparts;
  3448. lock (m_scriptEvents)
  3449. {
  3450. if (m_scriptEvents.TryGetValue(scriptid, out scriptEvents ev))
  3451. {
  3452. if (ev == (scriptEvents)events)
  3453. return;
  3454. }
  3455. m_scriptEvents[scriptid] = (scriptEvents) events;
  3456. }
  3457. aggregateScriptEvents();
  3458. }
  3459. /// <summary>
  3460. /// Set the text displayed for this part.
  3461. /// </summary>
  3462. /// <param name="text"></param>
  3463. public void SetText(string text)
  3464. {
  3465. string oldtext = m_text;
  3466. m_text = text;
  3467. if (ParentGroup != null && oldtext != text)
  3468. {
  3469. ParentGroup.HasGroupChanged = true;
  3470. ScheduleFullUpdate();
  3471. }
  3472. }
  3473. /// <summary>
  3474. /// Set the text displayed for this part.
  3475. /// </summary>
  3476. /// <param name="text"></param>
  3477. /// <param name="color"></param>
  3478. /// <param name="alpha"></param>
  3479. public void SetText(string text, Vector3 color, double alpha)
  3480. {
  3481. Color oldcolor = Color;
  3482. string oldtext = m_text;
  3483. Color = Color.FromArgb((int) (alpha*0xff),
  3484. (int) (color.X*0xff),
  3485. (int) (color.Y*0xff),
  3486. (int) (color.Z*0xff));
  3487. m_text = text;
  3488. if(ParentGroup != null && (oldcolor != Color || oldtext != m_text))
  3489. {
  3490. ParentGroup.HasGroupChanged = true;
  3491. ScheduleFullUpdate();
  3492. }
  3493. }
  3494. public void StoreUndoState(ObjectChangeType change)
  3495. {
  3496. lock (m_UndoLock)
  3497. {
  3498. if (m_UndoRedo == null)
  3499. m_UndoRedo = new UndoRedoState(5);
  3500. if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
  3501. {
  3502. m_UndoRedo.StoreUndo(this, change);
  3503. }
  3504. }
  3505. }
  3506. /// <summary>
  3507. /// Return number of undos on the stack. Here temporarily pending a refactor.
  3508. /// </summary>
  3509. public int UndoCount
  3510. {
  3511. get
  3512. {
  3513. if (m_UndoRedo == null)
  3514. return 0;
  3515. return m_UndoRedo.Count;
  3516. }
  3517. }
  3518. public void Undo()
  3519. {
  3520. lock (m_UndoLock)
  3521. {
  3522. if (m_UndoRedo == null || Undoing || ParentGroup == null)
  3523. return;
  3524. Undoing = true;
  3525. m_UndoRedo.Undo(this);
  3526. Undoing = false;
  3527. }
  3528. }
  3529. public void Redo()
  3530. {
  3531. lock (m_UndoLock)
  3532. {
  3533. if (m_UndoRedo == null || Undoing || ParentGroup == null)
  3534. return;
  3535. Undoing = true;
  3536. m_UndoRedo.Redo(this);
  3537. Undoing = false;
  3538. }
  3539. }
  3540. public void ClearUndoState()
  3541. {
  3542. lock (m_UndoLock)
  3543. {
  3544. if (m_UndoRedo == null || Undoing)
  3545. return;
  3546. m_UndoRedo.Clear();
  3547. }
  3548. }
  3549. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  3550. {
  3551. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  3552. // This breaks down into the ray---> plane equation.
  3553. // TODO: Change to take shape into account
  3554. Vector3[] vertexes = new Vector3[8];
  3555. // float[] distance = new float[6];
  3556. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  3557. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  3558. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  3559. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  3560. Vector3[] normals = new Vector3[6]; // Normal for Facei
  3561. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  3562. AAfacenormals[0] = new Vector3(1, 0, 0);
  3563. AAfacenormals[1] = new Vector3(0, 1, 0);
  3564. AAfacenormals[2] = new Vector3(-1, 0, 0);
  3565. AAfacenormals[3] = new Vector3(0, -1, 0);
  3566. AAfacenormals[4] = new Vector3(0, 0, 1);
  3567. AAfacenormals[5] = new Vector3(0, 0, -1);
  3568. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  3569. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  3570. Vector3 cross = new Vector3();
  3571. Vector3 pos = GetWorldPosition();
  3572. Quaternion rot = GetWorldRotation();
  3573. Quaternion AXrot = rot;
  3574. AXrot.Normalize();
  3575. Vector3 AXpos = pos;
  3576. // tScale is the offset to derive the vertex based on the scale.
  3577. // it's different for each vertex because we've got to rotate it
  3578. // to get the world position of the vertex to produce the Oriented Bounding Box
  3579. Vector3 tScale = Vector3.Zero;
  3580. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  3581. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  3582. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  3583. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  3584. Vector3 rScale = new Vector3();
  3585. // Get Vertexes for Faces Stick them into ABCD for each Face
  3586. // Form: Face<vertex>[face] that corresponds to the below diagram
  3587. #region ABCD Face Vertex Map Comment Diagram
  3588. // A _________ B
  3589. // | |
  3590. // | 4 top |
  3591. // |_________|
  3592. // C D
  3593. // A _________ B
  3594. // | Back |
  3595. // | 3 |
  3596. // |_________|
  3597. // C D
  3598. // A _________ B B _________ A
  3599. // | Left | | Right |
  3600. // | 0 | | 2 |
  3601. // |_________| |_________|
  3602. // C D D C
  3603. // A _________ B
  3604. // | Front |
  3605. // | 1 |
  3606. // |_________|
  3607. // C D
  3608. // C _________ D
  3609. // | |
  3610. // | 5 bot |
  3611. // |_________|
  3612. // A B
  3613. #endregion
  3614. #region Plane Decomposition of Oriented Bounding Box
  3615. tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
  3616. rScale = tScale * AXrot;
  3617. vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3618. // vertexes[0].X = pos.X + vertexes[0].X;
  3619. //vertexes[0].Y = pos.Y + vertexes[0].Y;
  3620. //vertexes[0].Z = pos.Z + vertexes[0].Z;
  3621. FaceA[0] = vertexes[0];
  3622. FaceB[3] = vertexes[0];
  3623. FaceA[4] = vertexes[0];
  3624. tScale = AXscale;
  3625. rScale = tScale * AXrot;
  3626. vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3627. // vertexes[1].X = pos.X + vertexes[1].X;
  3628. // vertexes[1].Y = pos.Y + vertexes[1].Y;
  3629. //vertexes[1].Z = pos.Z + vertexes[1].Z;
  3630. FaceB[0] = vertexes[1];
  3631. FaceA[1] = vertexes[1];
  3632. FaceC[4] = vertexes[1];
  3633. tScale = new Vector3(AXscale.X, -AXscale.Y, -AXscale.Z);
  3634. rScale = tScale * AXrot;
  3635. vertexes[2] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3636. //vertexes[2].X = pos.X + vertexes[2].X;
  3637. //vertexes[2].Y = pos.Y + vertexes[2].Y;
  3638. //vertexes[2].Z = pos.Z + vertexes[2].Z;
  3639. FaceC[0] = vertexes[2];
  3640. FaceD[3] = vertexes[2];
  3641. FaceC[5] = vertexes[2];
  3642. tScale = new Vector3(AXscale.X, AXscale.Y, -AXscale.Z);
  3643. rScale = tScale * AXrot;
  3644. vertexes[3] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3645. //vertexes[3].X = pos.X + vertexes[3].X;
  3646. // vertexes[3].Y = pos.Y + vertexes[3].Y;
  3647. // vertexes[3].Z = pos.Z + vertexes[3].Z;
  3648. FaceD[0] = vertexes[3];
  3649. FaceC[1] = vertexes[3];
  3650. FaceA[5] = vertexes[3];
  3651. tScale = new Vector3(-AXscale.X, AXscale.Y, AXscale.Z);
  3652. rScale = tScale * AXrot;
  3653. vertexes[4] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3654. // vertexes[4].X = pos.X + vertexes[4].X;
  3655. // vertexes[4].Y = pos.Y + vertexes[4].Y;
  3656. // vertexes[4].Z = pos.Z + vertexes[4].Z;
  3657. FaceB[1] = vertexes[4];
  3658. FaceA[2] = vertexes[4];
  3659. FaceD[4] = vertexes[4];
  3660. tScale = new Vector3(-AXscale.X, AXscale.Y, -AXscale.Z);
  3661. rScale = tScale * AXrot;
  3662. vertexes[5] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3663. // vertexes[5].X = pos.X + vertexes[5].X;
  3664. // vertexes[5].Y = pos.Y + vertexes[5].Y;
  3665. // vertexes[5].Z = pos.Z + vertexes[5].Z;
  3666. FaceD[1] = vertexes[5];
  3667. FaceC[2] = vertexes[5];
  3668. FaceB[5] = vertexes[5];
  3669. tScale = new Vector3(-AXscale.X, -AXscale.Y, AXscale.Z);
  3670. rScale = tScale * AXrot;
  3671. vertexes[6] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3672. // vertexes[6].X = pos.X + vertexes[6].X;
  3673. // vertexes[6].Y = pos.Y + vertexes[6].Y;
  3674. // vertexes[6].Z = pos.Z + vertexes[6].Z;
  3675. FaceB[2] = vertexes[6];
  3676. FaceA[3] = vertexes[6];
  3677. FaceB[4] = vertexes[6];
  3678. tScale = new Vector3(-AXscale.X, -AXscale.Y, -AXscale.Z);
  3679. rScale = tScale * AXrot;
  3680. vertexes[7] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3681. // vertexes[7].X = pos.X + vertexes[7].X;
  3682. // vertexes[7].Y = pos.Y + vertexes[7].Y;
  3683. // vertexes[7].Z = pos.Z + vertexes[7].Z;
  3684. FaceD[2] = vertexes[7];
  3685. FaceC[3] = vertexes[7];
  3686. FaceD[5] = vertexes[7];
  3687. #endregion
  3688. // Get our plane normals
  3689. for (int i = 0; i < 6; i++)
  3690. {
  3691. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  3692. // Our Plane direction
  3693. AmBa = FaceA[i] - FaceB[i];
  3694. AmBb = FaceB[i] - FaceC[i];
  3695. cross = Vector3.Cross(AmBb, AmBa);
  3696. // normalize the cross product to get the normal.
  3697. normals[i] = cross / cross.Length();
  3698. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  3699. //distance[i] = (normals[i].X * AmBa.X + normals[i].Y * AmBa.Y + normals[i].Z * AmBa.Z) * -1;
  3700. }
  3701. EntityIntersection result = new EntityIntersection();
  3702. result.distance = 1024;
  3703. float c = 0;
  3704. float a = 0;
  3705. float d = 0;
  3706. Vector3 q = new Vector3();
  3707. #region OBB Version 2 Experiment
  3708. //float fmin = 999999;
  3709. //float fmax = -999999;
  3710. //float s = 0;
  3711. //for (int i=0;i<6;i++)
  3712. //{
  3713. //s = iray.Direction.Dot(normals[i]);
  3714. //d = normals[i].Dot(FaceB[i]);
  3715. //if (s == 0)
  3716. //{
  3717. //if (iray.Origin.Dot(normals[i]) > d)
  3718. //{
  3719. //return result;
  3720. //}
  3721. // else
  3722. //{
  3723. //continue;
  3724. //}
  3725. //}
  3726. //a = (d - iray.Origin.Dot(normals[i])) / s;
  3727. //if (iray.Direction.Dot(normals[i]) < 0)
  3728. //{
  3729. //if (a > fmax)
  3730. //{
  3731. //if (a > fmin)
  3732. //{
  3733. //return result;
  3734. //}
  3735. //fmax = a;
  3736. //}
  3737. //}
  3738. //else
  3739. //{
  3740. //if (a < fmin)
  3741. //{
  3742. //if (a < 0 || a < fmax)
  3743. //{
  3744. //return result;
  3745. //}
  3746. //fmin = a;
  3747. //}
  3748. //}
  3749. //}
  3750. //if (fmax > 0)
  3751. // a= fmax;
  3752. //else
  3753. // a=fmin;
  3754. //q = iray.Origin + a * iray.Direction;
  3755. #endregion
  3756. // Loop over faces (6 of them)
  3757. for (int i = 0; i < 6; i++)
  3758. {
  3759. AmBa = FaceA[i] - FaceB[i];
  3760. AmBb = FaceB[i] - FaceC[i];
  3761. d = Vector3.Dot(normals[i], FaceB[i]);
  3762. //if (faceCenters)
  3763. //{
  3764. // c = normals[i].Dot(normals[i]);
  3765. //}
  3766. //else
  3767. //{
  3768. c = Vector3.Dot(iray.Direction, normals[i]);
  3769. //}
  3770. if (c == 0)
  3771. continue;
  3772. a = (d - Vector3.Dot(iray.Origin, normals[i])) / c;
  3773. if (a < 0)
  3774. continue;
  3775. // If the normal is pointing outside the object
  3776. if (Vector3.Dot(iray.Direction, normals[i]) < 0 || !frontFacesOnly)
  3777. {
  3778. //if (faceCenters)
  3779. //{ //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  3780. // q = iray.Origin + a * normals[i];
  3781. //}
  3782. //else
  3783. //{
  3784. q = iray.Origin + iray.Direction * a;
  3785. //}
  3786. float distance2 = Vector3.Distance(q, AXpos);
  3787. // Is this the closest hit to the object's origin?
  3788. //if (faceCenters)
  3789. //{
  3790. // distance2 = (float)GetDistanceTo(q, iray.Origin);
  3791. //}
  3792. if (distance2 < result.distance)
  3793. {
  3794. result.distance = distance2;
  3795. result.HitTF = true;
  3796. result.ipoint = q;
  3797. result.face = i;
  3798. //m_log.Info("[FACE]:" + i.ToString());
  3799. //m_log.Info("[POINT]: " + q.ToString());
  3800. //m_log.Info("[DIST]: " + distance2.ToString());
  3801. if (faceCenters)
  3802. {
  3803. result.normal = AAfacenormals[i] * AXrot;
  3804. Vector3 scaleComponent = AAfacenormals[i];
  3805. float ScaleOffset = 0.5f;
  3806. if (scaleComponent.X != 0) ScaleOffset = AXscale.X;
  3807. if (scaleComponent.Y != 0) ScaleOffset = AXscale.Y;
  3808. if (scaleComponent.Z != 0) ScaleOffset = AXscale.Z;
  3809. ScaleOffset = Math.Abs(ScaleOffset);
  3810. Vector3 offset = result.normal * ScaleOffset;
  3811. result.ipoint = AXpos + offset;
  3812. ///pos = (intersectionpoint + offset);
  3813. }
  3814. else
  3815. {
  3816. result.normal = normals[i];
  3817. }
  3818. result.AAfaceNormal = AAfacenormals[i];
  3819. }
  3820. }
  3821. }
  3822. return result;
  3823. }
  3824. /// <summary>
  3825. /// Serialize this part to xml.
  3826. /// </summary>
  3827. /// <param name="xmlWriter"></param>
  3828. public void ToXml(XmlTextWriter xmlWriter)
  3829. {
  3830. SceneObjectSerializer.SOPToXml2(xmlWriter, this, new Dictionary<string, object>());
  3831. }
  3832. public void TriggerScriptChangedEvent(Changed val, object data = null)
  3833. {
  3834. if (ParentGroup != null && ParentGroup.Scene != null)
  3835. ParentGroup.Scene.EventManager.TriggerOnScriptChangedEvent(LocalId, (uint)val, data);
  3836. }
  3837. public void TrimPermissions()
  3838. {
  3839. BaseMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3840. OwnerMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3841. GroupMask &= (uint)PermissionMask.All;
  3842. EveryoneMask &= (uint)(PermissionMask.All | PermissionMask.Export);
  3843. NextOwnerMask &= (uint)PermissionMask.All;
  3844. }
  3845. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  3846. {
  3847. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  3848. if (ParentGroup != null)
  3849. {
  3850. ParentGroup.HasGroupChanged = true;
  3851. ScheduleFullAnimUpdate();
  3852. }
  3853. }
  3854. public void UpdateGroupPosition(Vector3 newPos)
  3855. {
  3856. Vector3 oldPos = GroupPosition;
  3857. if ((newPos.X != oldPos.X) ||
  3858. (newPos.Y != oldPos.Y) ||
  3859. (newPos.Z != oldPos.Z))
  3860. {
  3861. GroupPosition = newPos;
  3862. ScheduleTerseUpdate();
  3863. }
  3864. }
  3865. /// <summary>
  3866. /// Update this part's offset position.
  3867. /// </summary>
  3868. /// <param name="pos"></param>
  3869. public void UpdateOffSet(Vector3 newPos)
  3870. {
  3871. Vector3 oldPos = OffsetPosition;
  3872. if ((newPos.X != oldPos.X) ||
  3873. (newPos.Y != oldPos.Y) ||
  3874. (newPos.Z != oldPos.Z))
  3875. {
  3876. if (ParentGroup.RootPart.GetStatusSandbox())
  3877. {
  3878. if (Vector3.DistanceSquared(ParentGroup.RootPart.StatusSandboxPos, newPos) > 100)
  3879. {
  3880. ParentGroup.RootPart.ScriptSetPhysicsStatus(false);
  3881. newPos = OffsetPosition;
  3882. ParentGroup.Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3883. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, ParentGroup.RootPart.AbsolutePosition, Name, UUID, false);
  3884. }
  3885. }
  3886. OffsetPosition = newPos;
  3887. ScheduleTerseUpdate();
  3888. }
  3889. }
  3890. /// <summary>
  3891. /// Update permissions on the SOP. Should only be called from SOG.UpdatePermissions because the SOG
  3892. /// will handle the client notifications once all of its parts are updated.
  3893. /// </summary>
  3894. /// <param name="AgentID"></param>
  3895. /// <param name="field"></param>
  3896. /// <param name="localID"></param>
  3897. /// <param name="mask"></param>
  3898. /// <param name="addRemTF"></param>
  3899. public void UpdatePermissions(UUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  3900. {
  3901. bool set = addRemTF == 1;
  3902. bool god = ParentGroup.Scene.Permissions.IsGod(AgentID);
  3903. uint baseMask = BaseMask;
  3904. if (god)
  3905. baseMask = 0x7ffffff0;
  3906. bool canChange = (AgentID == OwnerID) || god;
  3907. if(!canChange)
  3908. canChange = ParentGroup.Scene.Permissions.CanEditObjectPermissions(ParentGroup, AgentID);
  3909. if (canChange)
  3910. {
  3911. switch (field)
  3912. {
  3913. case 1:
  3914. if (god)
  3915. {
  3916. BaseMask = ApplyMask(BaseMask, set, mask);
  3917. Inventory.ApplyGodPermissions(BaseMask);
  3918. }
  3919. break;
  3920. case 2:
  3921. OwnerMask = ApplyMask(OwnerMask, set, mask) &
  3922. baseMask;
  3923. break;
  3924. case 4:
  3925. GroupMask = ApplyMask(GroupMask, set, mask) &
  3926. baseMask;
  3927. break;
  3928. case 8:
  3929. // Trying to set export permissions - extra checks
  3930. if (set && (mask & (uint)PermissionMask.Export) != 0)
  3931. {
  3932. if ((OwnerMask & (uint)PermissionMask.Export) == 0 || (BaseMask & (uint)PermissionMask.Export) == 0 || (NextOwnerMask & (uint)PermissionMask.All) != (uint)PermissionMask.All)
  3933. mask &= ~(uint)PermissionMask.Export;
  3934. }
  3935. EveryoneMask = ApplyMask(EveryoneMask, set, mask) &
  3936. baseMask;
  3937. break;
  3938. case 16:
  3939. // Force full perm if export
  3940. if ((EveryoneMask & (uint)PermissionMask.Export) != 0)
  3941. {
  3942. NextOwnerMask = (uint)PermissionMask.All;
  3943. break;
  3944. }
  3945. NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) &
  3946. baseMask;
  3947. // Prevent the client from creating no copy, no transfer
  3948. // objects
  3949. if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0)
  3950. NextOwnerMask |= (uint)PermissionMask.Transfer;
  3951. NextOwnerMask |= (uint)PermissionMask.Move;
  3952. break;
  3953. }
  3954. AggregateInnerPerms();
  3955. SendFullUpdateToAllClients();
  3956. }
  3957. }
  3958. public void ClonePermissions(SceneObjectPart source)
  3959. {
  3960. uint prevOwnerMask = OwnerMask;
  3961. uint prevGroupMask = GroupMask;
  3962. uint prevEveryoneMask = EveryoneMask;
  3963. uint prevNextOwnerMask = NextOwnerMask;
  3964. OwnerMask = source.OwnerMask & BaseMask;
  3965. GroupMask = source.GroupMask & BaseMask;
  3966. EveryoneMask = source.EveryoneMask & BaseMask;
  3967. NextOwnerMask = source.NextOwnerMask & BaseMask;
  3968. AggregateInnerPerms();
  3969. if (OwnerMask != prevOwnerMask || GroupMask != prevGroupMask ||
  3970. EveryoneMask != prevEveryoneMask || NextOwnerMask != prevNextOwnerMask)
  3971. SendFullUpdateToAllClients();
  3972. }
  3973. public bool IsHingeJoint()
  3974. {
  3975. // For now, we use the NINJA naming scheme for identifying joints.
  3976. // In the future, we can support other joint specification schemes such as a
  3977. // custom checkbox in the viewer GUI.
  3978. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3979. {
  3980. string hingeString = "hingejoint";
  3981. return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
  3982. }
  3983. else
  3984. {
  3985. return false;
  3986. }
  3987. }
  3988. public bool IsBallJoint()
  3989. {
  3990. // For now, we use the NINJA naming scheme for identifying joints.
  3991. // In the future, we can support other joint specification schemes such as a
  3992. // custom checkbox in the viewer GUI.
  3993. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3994. {
  3995. string ballString = "balljoint";
  3996. return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
  3997. }
  3998. else
  3999. {
  4000. return false;
  4001. }
  4002. }
  4003. public bool IsJoint()
  4004. {
  4005. // For now, we use the NINJA naming scheme for identifying joints.
  4006. // In the future, we can support other joint specification schemes such as a
  4007. // custom checkbox in the viewer GUI.
  4008. if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null && ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  4009. {
  4010. return IsHingeJoint() || IsBallJoint();
  4011. }
  4012. else
  4013. {
  4014. return false;
  4015. }
  4016. }
  4017. public void UpdateExtraPhysics(ExtraPhysicsData physdata)
  4018. {
  4019. if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
  4020. return;
  4021. byte newtype = (byte)physdata.PhysShapeType;
  4022. if (PhysicsShapeType != newtype)
  4023. PhysicsShapeType = newtype;
  4024. if(Density != physdata.Density)
  4025. Density = physdata.Density;
  4026. if(GravityModifier != physdata.GravitationModifier)
  4027. GravityModifier = physdata.GravitationModifier;
  4028. if(Friction != physdata.Friction)
  4029. Friction = physdata.Friction;
  4030. if(Restitution != physdata.Bounce)
  4031. Restitution = physdata.Bounce;
  4032. }
  4033. /// <summary>
  4034. /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
  4035. /// </summary>
  4036. /// <param name="UsePhysics"></param>
  4037. /// <param name="SetTemporary"></param>
  4038. /// <param name="SetPhantom"></param>
  4039. /// <param name="SetVD"></param>
  4040. public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
  4041. {
  4042. bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
  4043. bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
  4044. bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0);
  4045. bool wasVD = VolumeDetectActive;
  4046. if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
  4047. {
  4048. UpdatePhysicsSubscribedEvents();
  4049. return;
  4050. }
  4051. VolumeDetectActive = SetVD;
  4052. // volume detector implies phantom we need to decouple this mess
  4053. if (SetVD)
  4054. SetPhantom = true;
  4055. else if(wasVD)
  4056. SetPhantom = false;
  4057. if (UsePhysics)
  4058. AddFlag(PrimFlags.Physics);
  4059. else
  4060. RemFlag(PrimFlags.Physics);
  4061. if (SetPhantom)
  4062. AddFlag(PrimFlags.Phantom);
  4063. else
  4064. RemFlag(PrimFlags.Phantom);
  4065. if (SetTemporary)
  4066. AddFlag(PrimFlags.TemporaryOnRez);
  4067. else
  4068. RemFlag(PrimFlags.TemporaryOnRez);
  4069. if (ParentGroup.Scene == null)
  4070. return;
  4071. PhysicsActor pa = PhysActor;
  4072. if (pa != null && building && pa.Building != building)
  4073. pa.Building = building;
  4074. if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
  4075. || (Shape.PathCurve == (byte)Extrusion.Flexible))
  4076. {
  4077. Stop();
  4078. if (pa != null)
  4079. {
  4080. if(wasUsingPhysics)
  4081. ParentGroup.Scene.RemovePhysicalPrim(1);
  4082. RemoveFromPhysics();
  4083. }
  4084. }
  4085. else
  4086. {
  4087. if (ParentGroup.Scene.CollidablePrims)
  4088. {
  4089. if (pa == null)
  4090. {
  4091. AddToPhysics(UsePhysics, SetPhantom, building, false);
  4092. pa = PhysActor;
  4093. if (pa != null)
  4094. {
  4095. pa.SetMaterial(Material);
  4096. DoPhysicsPropertyUpdate(UsePhysics, true);
  4097. }
  4098. }
  4099. else // it already has a physical representation
  4100. {
  4101. DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
  4102. if(UsePhysics && !SetPhantom && m_localId == ParentGroup.RootPart.LocalId &&
  4103. m_vehicleParams != null && m_vehicleParams.CameraDecoupled)
  4104. AddFlag(PrimFlags.CameraDecoupled);
  4105. else
  4106. RemFlag(PrimFlags.CameraDecoupled);
  4107. if (pa.Building != building)
  4108. pa.Building = building;
  4109. }
  4110. UpdatePhysicsSubscribedEvents();
  4111. }
  4112. }
  4113. // and last in case we have a new actor and not building
  4114. if (ParentGroup != null)
  4115. {
  4116. ParentGroup.HasGroupChanged = true;
  4117. ScheduleFullUpdate();
  4118. }
  4119. // m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
  4120. }
  4121. /// <summary>
  4122. /// Adds this part to the physics scene.
  4123. /// and sets the PhysActor property
  4124. /// </summary>
  4125. /// <param name="isPhysical">Add this prim as physical.</param>
  4126. /// <param name="isPhantom">Add this prim as phantom.</param>
  4127. /// <param name="building">tells physics to delay full construction of object</param>
  4128. /// <param name="applyDynamics">applies velocities, force and torque</param>
  4129. private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
  4130. {
  4131. if (ParentGroup.Scene != null)
  4132. ClampScale(isPhysical);
  4133. PhysicsActor pa;
  4134. Vector3 velocity = Velocity;
  4135. Vector3 rotationalVelocity = AngularVelocity; ;
  4136. try
  4137. {
  4138. pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
  4139. string.Format("{0}/{1}", Name, UUID),
  4140. Shape,
  4141. AbsolutePosition,
  4142. Scale,
  4143. GetWorldRotation(),
  4144. isPhysical,
  4145. isPhantom,
  4146. PhysicsShapeType,
  4147. m_localId);
  4148. }
  4149. catch (Exception e)
  4150. {
  4151. m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom. e={1}", m_uuid, e);
  4152. pa = null;
  4153. }
  4154. if (pa != null)
  4155. {
  4156. pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
  4157. pa.SetMaterial(Material);
  4158. pa.Density = Density;
  4159. pa.GravModifier = GravityModifier;
  4160. pa.Friction = Friction;
  4161. pa.Restitution = Restitution;
  4162. pa.Buoyancy = Buoyancy;
  4163. if(LocalId == ParentGroup.RootPart.LocalId)
  4164. {
  4165. pa.LockAngularMotion(RotationAxisLocks);
  4166. }
  4167. if (VolumeDetectActive) // change if not the default only
  4168. pa.SetVolumeDetect(1);
  4169. bool isroot = (m_localId == ParentGroup.RootPart.LocalId);
  4170. if(isroot && m_physicsInertia != null)
  4171. pa.SetInertiaData(m_physicsInertia);
  4172. if (isroot && m_vehicleParams != null )
  4173. {
  4174. m_vehicleParams.SetVehicle(pa);
  4175. if(isPhysical && !isPhantom && m_vehicleParams.CameraDecoupled)
  4176. AddFlag(PrimFlags.CameraDecoupled);
  4177. else
  4178. RemFlag(PrimFlags.CameraDecoupled);
  4179. }
  4180. else
  4181. RemFlag(PrimFlags.CameraDecoupled);
  4182. // we are going to tell rest of code about physics so better have this here
  4183. PhysActor = pa;
  4184. // DoPhysicsPropertyUpdate(isPhysical, true);
  4185. // lets expand it here just with what it really needs to do
  4186. if (isPhysical)
  4187. {
  4188. if (ParentGroup.RootPart.KeyframeMotion != null)
  4189. ParentGroup.RootPart.KeyframeMotion.Stop();
  4190. ParentGroup.RootPart.KeyframeMotion = null;
  4191. ParentGroup.Scene.AddPhysicalPrim(1);
  4192. pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  4193. pa.OnOutOfBounds += PhysicsOutOfBounds;
  4194. if (_parentID != 0 && _parentID != LocalId)
  4195. {
  4196. PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
  4197. if (parentPa != null)
  4198. {
  4199. pa.link(parentPa);
  4200. }
  4201. }
  4202. }
  4203. if (applyDynamics && LocalId == ParentGroup.RootPart.LocalId)
  4204. // do independent of isphysical so parameters get setted (at least some)
  4205. {
  4206. Velocity = velocity;
  4207. AngularVelocity = rotationalVelocity;
  4208. // if not vehicle and root part apply force and torque
  4209. if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE))
  4210. {
  4211. pa.Force = Force;
  4212. pa.Torque = Torque;
  4213. }
  4214. }
  4215. // if (Shape.SculptEntry)
  4216. // CheckSculptAndLoad();
  4217. // else
  4218. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4219. if (!building)
  4220. pa.Building = false;
  4221. }
  4222. PhysActor = pa;
  4223. ParentGroup.Scene.EventManager.TriggerObjectAddedToPhysicalScene(this);
  4224. }
  4225. /// <summary>
  4226. /// This removes the part from the physics scene.
  4227. /// </summary>
  4228. /// <remarks>
  4229. /// This isn't the same as turning off physical, since even without being physical the prim has a physics
  4230. /// representation for collision detection.
  4231. /// </remarks>
  4232. public void RemoveFromPhysics()
  4233. {
  4234. PhysicsActor pa = PhysActor;
  4235. if (pa != null)
  4236. {
  4237. pa.OnCollisionUpdate -= PhysicsCollision;
  4238. pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  4239. pa.OnOutOfBounds -= PhysicsOutOfBounds;
  4240. ParentGroup.Scene.PhysicsScene.RemovePrim(pa);
  4241. ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this);
  4242. }
  4243. RemFlag(PrimFlags.CameraDecoupled);
  4244. PhysActor = null;
  4245. }
  4246. /// <summary>
  4247. /// This updates the part's rotation and sends out an update to clients if necessary.
  4248. /// </summary>
  4249. /// <param name="rot"></param>
  4250. public void UpdateRotation(Quaternion rot)
  4251. {
  4252. if (rot != RotationOffset)
  4253. {
  4254. RotationOffset = rot;
  4255. if (ParentGroup != null)
  4256. {
  4257. ParentGroup.HasGroupChanged = true;
  4258. ScheduleTerseUpdate();
  4259. }
  4260. }
  4261. }
  4262. /// <summary>
  4263. /// Update the shape of this part.
  4264. /// </summary>
  4265. /// <param name="shapeBlock"></param>
  4266. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  4267. {
  4268. m_shape.PathBegin = shapeBlock.PathBegin;
  4269. m_shape.PathEnd = shapeBlock.PathEnd;
  4270. m_shape.PathScaleX = shapeBlock.PathScaleX;
  4271. m_shape.PathScaleY = shapeBlock.PathScaleY;
  4272. m_shape.PathShearX = shapeBlock.PathShearX;
  4273. m_shape.PathShearY = shapeBlock.PathShearY;
  4274. m_shape.PathSkew = shapeBlock.PathSkew;
  4275. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  4276. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  4277. m_shape.PathCurve = shapeBlock.PathCurve;
  4278. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  4279. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  4280. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  4281. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  4282. m_shape.PathTaperX = shapeBlock.PathTaperX;
  4283. m_shape.PathTaperY = shapeBlock.PathTaperY;
  4284. m_shape.PathTwist = shapeBlock.PathTwist;
  4285. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  4286. PhysicsActor pa = PhysActor;
  4287. if (pa != null)
  4288. {
  4289. pa.Shape = m_shape;
  4290. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
  4291. }
  4292. // This is what makes vehicle trailers work
  4293. // A script in a child prim re-issues
  4294. // llSetPrimitiveParams(PRIM_TYPE) every few seconds. That
  4295. // prevents autoreturn. This is not well known. It also works
  4296. // in SL.
  4297. //
  4298. if (ParentGroup.RootPart != this)
  4299. ParentGroup.RootPart.Rezzed = DateTime.UtcNow;
  4300. ParentGroup.HasGroupChanged = true;
  4301. TriggerScriptChangedEvent(Changed.SHAPE);
  4302. ScheduleFullUpdate();
  4303. }
  4304. public void UpdateSlice(float begin, float end)
  4305. {
  4306. if (end < begin)
  4307. {
  4308. float temp = begin;
  4309. begin = end;
  4310. end = temp;
  4311. }
  4312. end = Math.Min(1f, Math.Max(0f, end));
  4313. begin = Math.Min(Math.Min(1f, Math.Max(0f, begin)), end - 0.02f);
  4314. if (begin < 0.02f && end < 0.02f)
  4315. {
  4316. begin = 0f;
  4317. end = 0.02f;
  4318. }
  4319. ushort uBegin = (ushort)(50000.0 * begin);
  4320. ushort uEnd = (ushort)(50000.0 * (1f - end));
  4321. bool updatePossiblyNeeded = false;
  4322. PrimType primType = GetPrimType();
  4323. if (primType == PrimType.SPHERE || primType == PrimType.TORUS || primType == PrimType.TUBE || primType == PrimType.RING)
  4324. {
  4325. if (m_shape.ProfileBegin != uBegin || m_shape.ProfileEnd != uEnd)
  4326. {
  4327. m_shape.ProfileBegin = uBegin;
  4328. m_shape.ProfileEnd = uEnd;
  4329. updatePossiblyNeeded = true;
  4330. }
  4331. }
  4332. else if (m_shape.PathBegin != uBegin || m_shape.PathEnd != uEnd)
  4333. {
  4334. m_shape.PathBegin = uBegin;
  4335. m_shape.PathEnd = uEnd;
  4336. updatePossiblyNeeded = true;
  4337. }
  4338. if (updatePossiblyNeeded && ParentGroup != null)
  4339. {
  4340. ParentGroup.HasGroupChanged = true;
  4341. }
  4342. if (updatePossiblyNeeded && PhysActor != null)
  4343. {
  4344. PhysActor.Shape = m_shape;
  4345. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  4346. }
  4347. if (updatePossiblyNeeded)
  4348. {
  4349. ScheduleFullUpdate();
  4350. }
  4351. }
  4352. /// <summary>
  4353. /// Update the texture entry for this part.
  4354. /// </summary>
  4355. /// <param name="serializedTextureEntry"></param>
  4356. public void UpdateTextureEntry(byte[] serializedTextureEntry)
  4357. {
  4358. Primitive.TextureEntry newTex = new Primitive.TextureEntry(serializedTextureEntry, 0, serializedTextureEntry.Length);
  4359. Primitive.TextureEntry oldTex = Shape.Textures;
  4360. Changed changeFlags = 0;
  4361. Primitive.TextureEntryFace defaultNewFace = newTex.DefaultTexture;
  4362. Primitive.TextureEntryFace defaultOldFace = oldTex.DefaultTexture;
  4363. // On Incoming packets, sometimes newText.DefaultTexture is null. The assumption is that all
  4364. // other prim-sides are set, but apparently that's not always the case. Lets assume packet/data corruption at this point.
  4365. if (defaultNewFace == null)
  4366. {
  4367. defaultNewFace = new Primitive.TextureEntry(Util.BLANK_TEXTURE_UUID).CreateFace(0);
  4368. newTex.DefaultTexture = defaultNewFace;
  4369. }
  4370. if (defaultOldFace == null)
  4371. {
  4372. defaultOldFace = new Primitive.TextureEntry(Util.BLANK_TEXTURE_UUID).CreateFace(0);
  4373. oldTex.DefaultTexture = defaultOldFace;
  4374. }
  4375. // Materials capable viewers can send a ObjectImage packet
  4376. // when nothing in TE has changed. MaterialID should be updated
  4377. // by the RenderMaterials CAP handler, so updating it here may cause a
  4378. // race condtion. Therefore, if no non-materials TE fields have not changed,
  4379. // we should ignore any changes and not update Shape.TextureEntry
  4380. bool otherFieldsChanged = false;
  4381. int nsides = GetNumberOfSides();
  4382. for (int i = 0; i < nsides; i++)
  4383. {
  4384. Primitive.TextureEntryFace newFace = defaultNewFace;
  4385. Primitive.TextureEntryFace oldFace = defaultOldFace;
  4386. if (oldTex.FaceTextures[i] != null)
  4387. oldFace = oldTex.FaceTextures[i];
  4388. if (newTex.FaceTextures[i] != null)
  4389. newFace = newTex.FaceTextures[i];
  4390. if (oldFace.TextureID != newFace.TextureID)
  4391. changeFlags |= Changed.TEXTURE;
  4392. Color4 oldRGBA = oldFace.RGBA;
  4393. Color4 newRGBA = newFace.RGBA;
  4394. if (oldRGBA.R != newRGBA.R ||
  4395. oldRGBA.G != newRGBA.G ||
  4396. oldRGBA.B != newRGBA.B ||
  4397. oldRGBA.A != newRGBA.A)
  4398. changeFlags |= Changed.COLOR;
  4399. // Max change, skip the rest of testing
  4400. if (changeFlags == (Changed.TEXTURE | Changed.COLOR))
  4401. break;
  4402. if (!otherFieldsChanged)
  4403. {
  4404. if (oldFace.Bump != newFace.Bump) otherFieldsChanged = true;
  4405. if (oldFace.Fullbright != newFace.Fullbright) otherFieldsChanged = true;
  4406. if (oldFace.Glow != newFace.Glow) otherFieldsChanged = true;
  4407. if (oldFace.MediaFlags != newFace.MediaFlags) otherFieldsChanged = true;
  4408. if (oldFace.OffsetU != newFace.OffsetU) otherFieldsChanged = true;
  4409. if (oldFace.OffsetV != newFace.OffsetV) otherFieldsChanged = true;
  4410. if (oldFace.RepeatU != newFace.RepeatU) otherFieldsChanged = true;
  4411. if (oldFace.RepeatV != newFace.RepeatV) otherFieldsChanged = true;
  4412. if (oldFace.Rotation != newFace.Rotation) otherFieldsChanged = true;
  4413. if (oldFace.Shiny != newFace.Shiny) otherFieldsChanged = true;
  4414. if (oldFace.TexMapType != newFace.TexMapType) otherFieldsChanged = true;
  4415. if (otherFieldsChanged)
  4416. changeFlags |= Changed.TEXTURE;
  4417. }
  4418. }
  4419. if (changeFlags == 0)
  4420. return;
  4421. // we do need better compacter do just the trivial case
  4422. if(nsides == 1 && newTex.FaceTextures[0] != null)
  4423. {
  4424. newTex.DefaultTexture = newTex.GetFace(0);
  4425. newTex.FaceTextures[0] = null;
  4426. }
  4427. m_shape.TextureEntry = newTex.GetBytes(nsides);
  4428. TriggerScriptChangedEvent(changeFlags);
  4429. ParentGroup.HasGroupChanged = true;
  4430. ScheduleUpdate(PrimUpdateFlags.Textures);
  4431. }
  4432. /// <summary>
  4433. /// Update the texture entry for this part.
  4434. /// </summary>
  4435. /// <param name="newTex"></param>
  4436. public void UpdateTextureEntry(Primitive.TextureEntry newTex)
  4437. {
  4438. TextureAttributes dirty = newTex.GetDirtyFlags(32, true);
  4439. dirty &= ~TextureAttributes.MaterialID;
  4440. if(dirty == TextureAttributes.None)
  4441. return;
  4442. Changed changeFlags = 0;
  4443. if((dirty & TextureAttributes.RGBA) != 0)
  4444. {
  4445. changeFlags = Changed.COLOR;
  4446. dirty &= ~TextureAttributes.RGBA;
  4447. }
  4448. if (dirty != TextureAttributes.None)
  4449. changeFlags |= Changed.TEXTURE;
  4450. if (changeFlags == 0)
  4451. return;
  4452. m_shape.TextureEntry = newTex.GetBytes(9);
  4453. TriggerScriptChangedEvent(changeFlags);
  4454. ParentGroup.HasGroupChanged = true;
  4455. ScheduleUpdate(PrimUpdateFlags.Textures);
  4456. }
  4457. internal void UpdatePhysicsSubscribedEvents()
  4458. {
  4459. PhysicsActor pa = PhysActor;
  4460. if (pa == null)
  4461. return;
  4462. pa.OnCollisionUpdate -= PhysicsCollision;
  4463. bool hassound = (!VolumeDetectActive && CollisionSoundType >= 0 && ((Flags & PrimFlags.Physics) != 0));
  4464. scriptEvents CombinedEvents = AggregatedScriptEvents;
  4465. // merge with root part
  4466. if (ParentGroup != null && ParentGroup.RootPart != null)
  4467. CombinedEvents |= ParentGroup.RootPart.AggregatedScriptEvents;
  4468. // submit to this part case
  4469. if (VolumeDetectActive)
  4470. CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
  4471. else if ((Flags & PrimFlags.Phantom) != 0)
  4472. CombinedEvents &= PhyscicsPhantonSubsEvents;
  4473. else
  4474. CombinedEvents &= PhysicsNeededSubsEvents;
  4475. if (hassound || CombinedEvents != 0)
  4476. {
  4477. // subscribe to physics updates.
  4478. pa.OnCollisionUpdate += PhysicsCollision;
  4479. pa.SubscribeEvents(50); // 20 reports per second
  4480. }
  4481. else
  4482. {
  4483. pa.UnSubscribeEvents();
  4484. }
  4485. }
  4486. public void aggregateScriptEvents()
  4487. {
  4488. if (ParentGroup == null || ParentGroup.RootPart == null)
  4489. return;
  4490. AggregatedScriptEvents = 0;
  4491. // Aggregate script events
  4492. lock (m_scriptEvents)
  4493. {
  4494. foreach (scriptEvents s in m_scriptEvents.Values)
  4495. {
  4496. AggregatedScriptEvents |= s;
  4497. }
  4498. }
  4499. uint objectflagupdate = 0;
  4500. if (
  4501. ((AggregatedScriptEvents & scriptEvents.touch) != 0) ||
  4502. ((AggregatedScriptEvents & scriptEvents.touch_end) != 0) ||
  4503. ((AggregatedScriptEvents & scriptEvents.touch_start) != 0)
  4504. )
  4505. {
  4506. objectflagupdate |= (uint) PrimFlags.Touch;
  4507. }
  4508. if ((AggregatedScriptEvents & scriptEvents.money) != 0)
  4509. {
  4510. objectflagupdate |= (uint) PrimFlags.Money;
  4511. }
  4512. if (AllowedDrop)
  4513. {
  4514. objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
  4515. }
  4516. LocalFlags = (PrimFlags)objectflagupdate;
  4517. if (ParentGroup != null && ParentGroup.RootPart == this)
  4518. {
  4519. ParentGroup.aggregateScriptEvents();
  4520. }
  4521. else
  4522. {
  4523. // m_log.DebugFormat(
  4524. // "[SCENE OBJECT PART]: Scheduling part {0} {1} for full update in aggregateScriptEvents()", Name, LocalId);
  4525. UpdatePhysicsSubscribedEvents();
  4526. ScheduleFullUpdate();
  4527. }
  4528. }
  4529. public void SetCameraAtOffset(Vector3 v)
  4530. {
  4531. m_cameraAtOffset = v;
  4532. }
  4533. public void SetCameraEyeOffset(Vector3 v)
  4534. {
  4535. m_cameraEyeOffset = v;
  4536. }
  4537. public void SetForceMouselook(bool force)
  4538. {
  4539. m_forceMouselook = force;
  4540. }
  4541. public Vector3 GetCameraAtOffset()
  4542. {
  4543. return m_cameraAtOffset;
  4544. }
  4545. public Vector3 GetCameraEyeOffset()
  4546. {
  4547. return m_cameraEyeOffset;
  4548. }
  4549. public bool GetForceMouselook()
  4550. {
  4551. return m_forceMouselook;
  4552. }
  4553. public override string ToString()
  4554. {
  4555. return String.Format("{0} {1} (parent {2}))", Name, UUID, ParentGroup);
  4556. }
  4557. #endregion Public Methods
  4558. public void SendUpdateToClient(IClientAPI remoteClient, PrimUpdateFlags update)
  4559. {
  4560. if (ParentGroup.IsDeleted)
  4561. return;
  4562. if (Animations == null)
  4563. {
  4564. update &= ~PrimUpdateFlags.Animations;
  4565. if (update == PrimUpdateFlags.None)
  4566. return;
  4567. }
  4568. if (ParentGroup.IsAttachment &&
  4569. (ParentGroup.RootPart != this || ParentGroup.AttachedAvatar != remoteClient.AgentId && ParentGroup.HasPrivateAttachmentPoint))
  4570. return;
  4571. remoteClient.SendEntityUpdate(this, update);
  4572. ParentGroup.Scene.StatsReporter.AddObjectUpdates(1);
  4573. }
  4574. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  4575. {
  4576. if (ParentGroup.IsDeleted)
  4577. return;
  4578. if (ParentGroup.IsAttachment
  4579. && (ParentGroup.RootPart != this
  4580. || ParentGroup.AttachedAvatar != remoteClient.AgentId && ParentGroup.HasPrivateAttachmentPoint))
  4581. return;
  4582. // Causes this thread to dig into the Client Thread Data.
  4583. // Remember your locking here!
  4584. remoteClient.SendEntityUpdate(this, PrimUpdateFlags.TerseUpdate);
  4585. ParentGroup.Scene.StatsReporter.AddObjectUpdates(1);
  4586. }
  4587. public void AddScriptLPS(int count)
  4588. {
  4589. ParentGroup.AddScriptLPS(count);
  4590. }
  4591. /// <summary>
  4592. /// Sets a prim's owner and permissions when it's rezzed.
  4593. /// </summary>
  4594. /// <param name="item">The inventory item from which the item was rezzed</param>
  4595. /// <param name="userInventory">True: the item is being rezzed from the user's inventory. False: from a prim's inventory.</param>
  4596. /// <param name="scene">The scene the prim is being rezzed into</param>
  4597. public void ApplyPermissionsOnRez(InventoryItemBase item, bool userInventory, Scene scene)
  4598. {
  4599. if ((OwnerID != item.Owner) || ((item.CurrentPermissions & (uint)PermissionMask.Slam) != 0) || ((item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0))
  4600. {
  4601. if (scene.Permissions.PropagatePermissions())
  4602. {
  4603. if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0)
  4604. {
  4605. // Apply the item's permissions to the object
  4606. //LogPermissions("Before applying item permissions");
  4607. if (userInventory)
  4608. {
  4609. EveryoneMask = item.EveryOnePermissions;
  4610. NextOwnerMask = item.NextPermissions;
  4611. }
  4612. else
  4613. {
  4614. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0)
  4615. EveryoneMask = item.EveryOnePermissions;
  4616. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0)
  4617. NextOwnerMask = item.NextPermissions;
  4618. if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0)
  4619. GroupMask = item.GroupPermissions;
  4620. }
  4621. //LogPermissions("After applying item permissions");
  4622. }
  4623. }
  4624. GroupMask = 0; // DO NOT propagate here
  4625. }
  4626. if (OwnerID != item.Owner)
  4627. {
  4628. if(OwnerID != GroupID)
  4629. LastOwnerID = OwnerID;
  4630. OwnerID = item.Owner;
  4631. Inventory.ChangeInventoryOwner(item.Owner);
  4632. if (scene.Permissions.PropagatePermissions())
  4633. ApplyNextOwnerPermissions();
  4634. }
  4635. }
  4636. /// <summary>
  4637. /// Logs the prim's permissions. Useful when debugging permission problems.
  4638. /// </summary>
  4639. /// <param name="message"></param>
  4640. private void LogPermissions(String message)
  4641. {
  4642. PermissionsUtil.LogPermissions(Name, message, BaseMask, OwnerMask, NextOwnerMask);
  4643. }
  4644. public void ApplyNextOwnerPermissions()
  4645. {
  4646. // Export needs to be preserved in the base and everyone
  4647. // mask, but removed in the owner mask as a next owner
  4648. // can never change the export status
  4649. BaseMask &= (NextOwnerMask | (uint)PermissionMask.Export);
  4650. OwnerMask &= NextOwnerMask;
  4651. EveryoneMask &= (NextOwnerMask | (uint)PermissionMask.Export);
  4652. GroupMask = 0; // Giving an object zaps group permissions
  4653. Inventory.ApplyNextOwnerPermissions();
  4654. AggregateInnerPerms();
  4655. }
  4656. public void UpdateLookAt()
  4657. {
  4658. try
  4659. {
  4660. if (APIDActive)
  4661. {
  4662. PhysicsActor pa = ParentGroup.RootPart.PhysActor;
  4663. if (pa == null || !pa.IsPhysical || APIDStrength < 0.04)
  4664. {
  4665. StopLookAt();
  4666. return;
  4667. }
  4668. Quaternion currRot = GetWorldRotation();
  4669. currRot.Normalize();
  4670. // difference between current orientation and desired orientation
  4671. Quaternion dR = currRot / APIDTarget;
  4672. // find axis and angle of rotation to rotate to desired orientation
  4673. Vector3 axis = Vector3.UnitX;
  4674. float angle;
  4675. dR.GetAxisAngle(out axis, out angle);
  4676. axis = axis * currRot;
  4677. // clamp strength to avoid overshoot
  4678. float strength = 1.0f / APIDStrength;
  4679. if (strength > 1.0) strength = 1.0f;
  4680. // set angular velocity to rotate to desired orientation
  4681. // with velocity proportional to strength and angle
  4682. AngularVelocity = axis * angle * strength * (float)Math.PI;
  4683. // This ensures that we'll check this object on the next iteration
  4684. ParentGroup.QueueForUpdateCheck();
  4685. }
  4686. }
  4687. catch (Exception ex)
  4688. {
  4689. m_log.Error("[Physics] " + ex);
  4690. }
  4691. }
  4692. public Color4 GetTextColor()
  4693. {
  4694. Color color = Color;
  4695. return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
  4696. }
  4697. public void ResetOwnerChangeFlag()
  4698. {
  4699. List<UUID> inv = Inventory.GetInventoryList();
  4700. foreach (UUID itemID in inv)
  4701. {
  4702. TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
  4703. item.OwnerChanged = false;
  4704. Inventory.UpdateInventoryItem(item, false, false);
  4705. }
  4706. AggregateInnerPerms();
  4707. }
  4708. /// <summary>
  4709. /// Record an avatar sitting on this part.
  4710. /// </summary>
  4711. /// <remarks>This is called for all the sitting avatars whether there is a sit target set or not.</remarks>
  4712. /// <returns>
  4713. /// true if the avatar was not already recorded, false otherwise.
  4714. /// </returns>
  4715. /// <param name='avatarId'></param>
  4716. protected internal bool AddSittingAvatar(ScenePresence sp)
  4717. {
  4718. lock (ParentGroup.m_sittingAvatars)
  4719. {
  4720. if (IsSitTargetSet && SitTargetAvatar == UUID.Zero)
  4721. SitTargetAvatar = sp.UUID;
  4722. if (m_sittingAvatars == null)
  4723. m_sittingAvatars = new HashSet<ScenePresence>();
  4724. if (m_sittingAvatars.Add(sp))
  4725. {
  4726. if(!ParentGroup.m_sittingAvatars.Contains(sp))
  4727. ParentGroup.m_sittingAvatars.Add(sp);
  4728. return true;
  4729. }
  4730. return false;
  4731. }
  4732. }
  4733. /// <summary>
  4734. /// Remove an avatar recorded as sitting on this part.
  4735. /// </summary>
  4736. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4737. /// <returns>
  4738. /// true if the avatar was present and removed, false if it was not present.
  4739. /// </returns>
  4740. /// <param name='avatarId'></param>
  4741. protected internal bool RemoveSittingAvatar(ScenePresence sp)
  4742. {
  4743. lock (ParentGroup.m_sittingAvatars)
  4744. {
  4745. if (SitTargetAvatar == sp.UUID)
  4746. SitTargetAvatar = UUID.Zero;
  4747. if (m_sittingAvatars == null)
  4748. return false;
  4749. if (m_sittingAvatars.Remove(sp))
  4750. {
  4751. if (m_sittingAvatars.Count == 0)
  4752. m_sittingAvatars = null;
  4753. if(ParentGroup.m_sittingAvatars.Remove(sp))
  4754. ParentGroup.InvalidatePartsLinkMaps(false);
  4755. return true;
  4756. }
  4757. return false;
  4758. }
  4759. }
  4760. /// <summary>
  4761. /// Get a copy of the list of sitting avatars.
  4762. /// </summary>
  4763. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4764. /// <returns>A hashset of the sitting avatars. Returns null if there are no sitting avatars.</returns>
  4765. public HashSet<ScenePresence> GetSittingAvatars()
  4766. {
  4767. lock (ParentGroup.m_sittingAvatars)
  4768. {
  4769. if (m_sittingAvatars == null)
  4770. return null;
  4771. else
  4772. return new HashSet<ScenePresence>(m_sittingAvatars);
  4773. }
  4774. }
  4775. /// <summary>
  4776. /// Gets the number of sitting avatars.
  4777. /// </summary>
  4778. /// <remarks>This applies to all sitting avatars whether there is a sit target set or not.</remarks>
  4779. /// <returns></returns>
  4780. public int GetSittingAvatarsCount()
  4781. {
  4782. lock (ParentGroup.m_sittingAvatars)
  4783. {
  4784. if (m_sittingAvatars == null)
  4785. return 0;
  4786. else
  4787. return m_sittingAvatars.Count;
  4788. }
  4789. }
  4790. public void Stop()
  4791. {
  4792. Velocity = Vector3.Zero;
  4793. AngularVelocity = Vector3.Zero;
  4794. Acceleration = Vector3.Zero;
  4795. APIDActive = false;
  4796. }
  4797. // handle osVolumeDetect
  4798. public void ScriptSetVolumeDetect(bool makeVolumeDetect)
  4799. {
  4800. if(ParentGroup.IsDeleted)
  4801. return;
  4802. if(_parentID == 0)
  4803. {
  4804. // if root prim do it is like llVolumeDetect
  4805. ParentGroup.ScriptSetVolumeDetect(makeVolumeDetect);
  4806. return;
  4807. }
  4808. if(ParentGroup.IsVolumeDetect)
  4809. return; // entire linkset is phantom already
  4810. bool wasUsingPhysics = ParentGroup.UsesPhysics;
  4811. bool wasTemporary = ParentGroup.IsTemporary;
  4812. bool wasPhantom = ParentGroup.IsPhantom;
  4813. if(PhysActor != null)
  4814. PhysActor.Building = true;
  4815. UpdatePrimFlags(wasUsingPhysics, wasTemporary, wasPhantom, makeVolumeDetect, false);
  4816. }
  4817. protected static int m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0x5fffafL);
  4818. public static int NextObjectAnimationSequenceNumber
  4819. {
  4820. get
  4821. {
  4822. int ret = Interlocked.Increment(ref m_animationSequenceNumber);
  4823. if (ret <= 0)
  4824. {
  4825. m_animationSequenceNumber = (int)(Util.GetTimeStampTicks() & 0xafff5fL);
  4826. ret = Interlocked.Increment(ref m_animationSequenceNumber);
  4827. }
  4828. return ret;
  4829. }
  4830. }
  4831. private object animsLock = new object();
  4832. public Dictionary<UUID, int> Animations = null;
  4833. public Dictionary<UUID, string> AnimationsNames = null;
  4834. public bool AddAnimation(UUID animId, string animName)
  4835. {
  4836. if (animId == UUID.Zero || string.IsNullOrEmpty(animName) ||
  4837. ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4838. return false;
  4839. lock (animsLock)
  4840. {
  4841. if (Animations == null)
  4842. Animations = new Dictionary<UUID, int>(1);
  4843. if (AnimationsNames == null)
  4844. AnimationsNames = new Dictionary<UUID, string>(1);
  4845. if (Animations.ContainsKey(animId))
  4846. return false;
  4847. Animations[animId] = NextObjectAnimationSequenceNumber;
  4848. AnimationsNames[animId] = animName;
  4849. ScheduleUpdate(PrimUpdateFlags.Animations);
  4850. }
  4851. return true;
  4852. }
  4853. public bool RemoveAnimation(UUID animId)
  4854. {
  4855. if (animId == UUID.Zero || ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4856. return false;
  4857. lock (animsLock)
  4858. {
  4859. if (Animations == null)
  4860. return false;
  4861. if (Animations.ContainsKey(animId))
  4862. {
  4863. Animations.Remove(animId);
  4864. if(AnimationsNames!=null)
  4865. AnimationsNames.Remove(animId);
  4866. ScheduleUpdate(PrimUpdateFlags.Animations);
  4867. return true;
  4868. }
  4869. }
  4870. return false;
  4871. }
  4872. public int ClearObjectAnimations()
  4873. {
  4874. int ret = 0;
  4875. if(Animations != null)
  4876. {
  4877. ret = Animations.Count;
  4878. Animations.Clear();
  4879. AnimationsNames.Clear();
  4880. }
  4881. else
  4882. {
  4883. Animations = new Dictionary<UUID, int>();
  4884. AnimationsNames = new Dictionary<UUID, string>();
  4885. }
  4886. ScheduleUpdate(PrimUpdateFlags.Animations);
  4887. return ret;
  4888. }
  4889. public int GetAnimations(out UUID[] ids, out int[] seqs)
  4890. {
  4891. ids = null;
  4892. seqs = null;
  4893. if (ParentGroup == null || ParentGroup.IsDeleted || ParentGroup.inTransit)
  4894. return -1;
  4895. lock (animsLock)
  4896. {
  4897. if (Animations == null)
  4898. return -1;
  4899. if(Animations.Count == 0)
  4900. return 0;
  4901. ids = new UUID[Animations.Count];
  4902. Animations.Keys.CopyTo(ids, 0);
  4903. seqs = new int[Animations.Count];
  4904. Animations.Values.CopyTo(seqs, 0);
  4905. return Animations.Count;
  4906. }
  4907. }
  4908. public Byte[] SerializeAnimations()
  4909. {
  4910. if (AnimationsNames == null)
  4911. return null;
  4912. lock (animsLock)
  4913. {
  4914. if (AnimationsNames.Count == 0)
  4915. return new byte[] { 0 };
  4916. using (MemoryStream ms = new MemoryStream())
  4917. {
  4918. byte[] tmp = Utils.UInt16ToBytes((ushort)Animations.Count);
  4919. ms.Write(tmp, 0, 2);
  4920. foreach(KeyValuePair<UUID,string> kvp in AnimationsNames)
  4921. {
  4922. tmp = kvp.Key.GetBytes();
  4923. ms.Write(tmp, 0, 16);
  4924. if(string.IsNullOrEmpty(kvp.Value))
  4925. ms.WriteByte(0);
  4926. else
  4927. {
  4928. byte[] str = Util.StringToBytes(kvp.Value, 64);
  4929. int len = str.Length - 1;
  4930. ms.WriteByte((byte)len);
  4931. ms.Write(str, 0 , len);
  4932. }
  4933. }
  4934. return ms.ToArray();
  4935. }
  4936. }
  4937. }
  4938. public void DeSerializeAnimations(Byte[] data)
  4939. {
  4940. if(data == null)
  4941. {
  4942. Animations = null;
  4943. AnimationsNames = null;
  4944. return;
  4945. }
  4946. if (data.Length < 2)
  4947. {
  4948. Animations = new Dictionary<UUID, int>();
  4949. AnimationsNames = new Dictionary<UUID, string>();
  4950. return;
  4951. }
  4952. try
  4953. {
  4954. int count = (int)Utils.BytesToUInt16(data, 0);
  4955. if(count == 0)
  4956. return;
  4957. Animations = new Dictionary<UUID, int>(count);
  4958. AnimationsNames = new Dictionary<UUID, string>(count);
  4959. int pos = 2;
  4960. while(--count >= 0)
  4961. {
  4962. UUID id = new UUID(data, pos);
  4963. if(id == UUID.Zero)
  4964. break;
  4965. pos += 16;
  4966. int strlen = data[pos++];
  4967. string name = UTF8Encoding.UTF8.GetString(data, pos, strlen);
  4968. if(string.IsNullOrEmpty(name))
  4969. break;
  4970. pos += strlen;
  4971. Animations[id] = NextObjectAnimationSequenceNumber;
  4972. AnimationsNames[id] = name;
  4973. }
  4974. return;
  4975. }
  4976. catch { }
  4977. Animations = null;
  4978. AnimationsNames = null;
  4979. }
  4980. }
  4981. }