SceneObjectPart.cs 197 KB

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