SceneObjectPart.cs 176 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863
  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.Xml;
  35. using System.Xml.Serialization;
  36. using log4net;
  37. using OpenMetaverse;
  38. using OpenMetaverse.Packets;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes.Scripting;
  42. using OpenSim.Region.Framework.Scenes.Serialization;
  43. using OpenSim.Region.Physics.Manager;
  44. namespace OpenSim.Region.Framework.Scenes
  45. {
  46. #region Enumerations
  47. [Flags]
  48. public enum Changed : uint
  49. {
  50. INVENTORY = 1,
  51. COLOR = 2,
  52. SHAPE = 4,
  53. SCALE = 8,
  54. TEXTURE = 16,
  55. LINK = 32,
  56. ALLOWED_DROP = 64,
  57. OWNER = 128,
  58. REGION = 256,
  59. TELEPORT = 512,
  60. REGION_RESTART = 1024,
  61. MEDIA = 2048,
  62. ANIMATION = 16384
  63. }
  64. // I don't really know where to put this except here.
  65. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  66. [Flags]
  67. public enum ExtraParamType
  68. {
  69. Something1 = 1,
  70. Something2 = 2,
  71. Something3 = 4,
  72. Something4 = 8,
  73. Flexible = 16,
  74. Light = 32,
  75. Sculpt = 48,
  76. Something5 = 64,
  77. Something6 = 128
  78. }
  79. [Flags]
  80. public enum TextureAnimFlags : byte
  81. {
  82. NONE = 0x00,
  83. ANIM_ON = 0x01,
  84. LOOP = 0x02,
  85. REVERSE = 0x04,
  86. PING_PONG = 0x08,
  87. SMOOTH = 0x10,
  88. ROTATE = 0x20,
  89. SCALE = 0x40
  90. }
  91. public enum PrimType : int
  92. {
  93. BOX = 0,
  94. CYLINDER = 1,
  95. PRISM = 2,
  96. SPHERE = 3,
  97. TORUS = 4,
  98. TUBE = 5,
  99. RING = 6,
  100. SCULPT = 7
  101. }
  102. #endregion Enumerations
  103. public class SceneObjectPart : IScriptHost, ISceneEntity
  104. {
  105. /// <value>
  106. /// Denote all sides of the prim
  107. /// </value>
  108. public const int ALL_SIDES = -1;
  109. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  110. /// <value>
  111. /// Is this sop a root part?
  112. /// </value>
  113. public bool IsRoot
  114. {
  115. get { return ParentGroup.RootPart == this; }
  116. }
  117. #region Fields
  118. public bool AllowedDrop;
  119. public bool DIE_AT_EDGE;
  120. public bool RETURN_AT_EDGE;
  121. public bool BlockGrab;
  122. public bool StatusSandbox;
  123. public Vector3 StatusSandboxPos;
  124. [XmlIgnore]
  125. public int[] PayPrice = {-2,-2,-2,-2,-2};
  126. [XmlIgnore]
  127. public PhysicsActor PhysActor
  128. {
  129. get { return m_physActor; }
  130. set
  131. {
  132. // m_log.DebugFormat("[SOP]: PhysActor set to {0} for {1} {2}", value, Name, UUID);
  133. m_physActor = value;
  134. }
  135. }
  136. //Xantor 20080528 Sound stuff:
  137. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  138. // Not a big problem as long as the script that sets it remains in the prim on startup.
  139. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  140. public UUID Sound;
  141. public byte SoundFlags;
  142. public double SoundGain;
  143. public double SoundRadius;
  144. public uint TimeStampFull;
  145. public uint TimeStampLastActivity; // Will be used for AutoReturn
  146. public uint TimeStampTerse;
  147. public UUID FromItemID;
  148. public UUID FromFolderID;
  149. public int STATUS_ROTATE_X;
  150. public int STATUS_ROTATE_Y;
  151. public int STATUS_ROTATE_Z;
  152. private Dictionary<int, string> m_CollisionFilter = new Dictionary<int, string>();
  153. /// <value>
  154. /// The UUID of the user inventory item from which this object was rezzed if this is a root part.
  155. /// If UUID.Zero then either this is not a root part or there is no connection with a user inventory item.
  156. /// </value>
  157. private UUID m_fromUserInventoryItemID;
  158. public UUID FromUserInventoryItemID
  159. {
  160. get { return m_fromUserInventoryItemID; }
  161. set { m_fromUserInventoryItemID = value; }
  162. }
  163. public scriptEvents AggregateScriptEvents;
  164. public Vector3 AttachedPos;
  165. public Vector3 RotationAxis = Vector3.One;
  166. public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this
  167. // Certainly this must be a persistant setting finally
  168. public bool IsWaitingForFirstSpinUpdatePacket;
  169. public Quaternion SpinOldOrientation = Quaternion.Identity;
  170. public Quaternion m_APIDTarget = Quaternion.Identity;
  171. public float m_APIDDamp = 0;
  172. public float m_APIDStrength = 0;
  173. /// <summary>
  174. /// This part's inventory
  175. /// </summary>
  176. public IEntityInventory Inventory
  177. {
  178. get { return m_inventory; }
  179. }
  180. protected SceneObjectPartInventory m_inventory;
  181. public bool Undoing;
  182. public bool IgnoreUndoUpdate = false;
  183. private PrimFlags LocalFlags;
  184. private float m_damage = -1.0f;
  185. private byte[] m_TextureAnimation;
  186. private byte m_clickAction;
  187. private Color m_color = Color.Black;
  188. private string m_description = String.Empty;
  189. private readonly List<uint> m_lastColliders = new List<uint>();
  190. private int m_linkNum;
  191. private int m_scriptAccessPin;
  192. private readonly Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>();
  193. private string m_sitName = String.Empty;
  194. private Quaternion m_sitTargetOrientation = Quaternion.Identity;
  195. private Vector3 m_sitTargetPosition;
  196. private string m_sitAnimation = "SIT";
  197. private string m_text = String.Empty;
  198. private string m_touchName = String.Empty;
  199. private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5);
  200. private readonly Stack<UndoState> m_redo = new Stack<UndoState>(5);
  201. private UUID _creatorID;
  202. private bool m_passTouches;
  203. /// <summary>
  204. /// Only used internally to schedule client updates.
  205. /// 0 - no update is scheduled
  206. /// 1 - terse update scheduled
  207. /// 2 - full update scheduled
  208. ///
  209. /// TODO - This should be an enumeration
  210. /// </summary>
  211. private byte m_updateFlag;
  212. private PhysicsActor m_physActor;
  213. protected Vector3 m_acceleration;
  214. protected Vector3 m_angularVelocity;
  215. //unkown if this will be kept, added as a way of removing the group position from the group class
  216. protected Vector3 m_groupPosition;
  217. protected uint m_localId;
  218. protected Material m_material = OpenMetaverse.Material.Wood;
  219. protected string m_name;
  220. protected Vector3 m_offsetPosition;
  221. protected SceneObjectGroup m_parentGroup;
  222. protected byte[] m_particleSystem = Utils.EmptyBytes;
  223. protected ulong m_regionHandle;
  224. protected Quaternion m_rotationOffset = Quaternion.Identity;
  225. protected PrimitiveBaseShape m_shape;
  226. protected UUID m_uuid;
  227. protected Vector3 m_velocity;
  228. protected Vector3 m_lastPosition;
  229. protected Quaternion m_lastRotation;
  230. protected Vector3 m_lastVelocity;
  231. protected Vector3 m_lastAcceleration;
  232. protected Vector3 m_lastAngularVelocity;
  233. protected int m_lastTerseSent;
  234. /// <summary>
  235. /// Stores media texture data
  236. /// </summary>
  237. protected string m_mediaUrl;
  238. // TODO: Those have to be changed into persistent properties at some later point,
  239. // or sit-camera on vehicles will break on sim-crossing.
  240. private Vector3 m_cameraEyeOffset;
  241. private Vector3 m_cameraAtOffset;
  242. private bool m_forceMouselook;
  243. // TODO: Collision sound should have default.
  244. private UUID m_collisionSound;
  245. private float m_collisionSoundVolume;
  246. #endregion Fields
  247. // ~SceneObjectPart()
  248. // {
  249. // m_log.DebugFormat(
  250. // "[SCENE OBJECT PART]: Destructor called for {0}, local id {1}, parent {2} {3}",
  251. // Name, LocalId, ParentGroup.Name, ParentGroup.LocalId);
  252. // }
  253. #region Constructors
  254. /// <summary>
  255. /// No arg constructor called by region restore db code
  256. /// </summary>
  257. public SceneObjectPart()
  258. {
  259. // It's not necessary to persist this
  260. m_TextureAnimation = Utils.EmptyBytes;
  261. m_particleSystem = Utils.EmptyBytes;
  262. Rezzed = DateTime.UtcNow;
  263. m_inventory = new SceneObjectPartInventory(this);
  264. }
  265. /// <summary>
  266. /// Create a completely new SceneObjectPart (prim). This will need to be added separately to a SceneObjectGroup
  267. /// </summary>
  268. /// <param name="ownerID"></param>
  269. /// <param name="shape"></param>
  270. /// <param name="position"></param>
  271. /// <param name="rotationOffset"></param>
  272. /// <param name="offsetPosition"></param>
  273. public SceneObjectPart(
  274. UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
  275. Quaternion rotationOffset, Vector3 offsetPosition)
  276. {
  277. m_name = "Primitive";
  278. Rezzed = DateTime.UtcNow;
  279. _creationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
  280. _ownerID = ownerID;
  281. _creatorID = _ownerID;
  282. _lastOwnerID = UUID.Zero;
  283. UUID = UUID.Random();
  284. Shape = shape;
  285. // Todo: Add More Object Parameter from above!
  286. _ownershipCost = 0;
  287. _objectSaleType = 0;
  288. _salePrice = 0;
  289. _category = 0;
  290. _lastOwnerID = _creatorID;
  291. // End Todo: ///
  292. GroupPosition = groupPosition;
  293. OffsetPosition = offsetPosition;
  294. RotationOffset = rotationOffset;
  295. Velocity = Vector3.Zero;
  296. AngularVelocity = Vector3.Zero;
  297. Acceleration = Vector3.Zero;
  298. m_TextureAnimation = Utils.EmptyBytes;
  299. m_particleSystem = Utils.EmptyBytes;
  300. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  301. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  302. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  303. Flags = 0;
  304. CreateSelected = true;
  305. TrimPermissions();
  306. m_inventory = new SceneObjectPartInventory(this);
  307. }
  308. #endregion Constructors
  309. #region XML Schema
  310. private UUID _lastOwnerID;
  311. private UUID _ownerID;
  312. private UUID _groupID;
  313. private int _ownershipCost;
  314. private byte _objectSaleType;
  315. private int _salePrice;
  316. private uint _category;
  317. private Int32 _creationDate;
  318. private uint _parentID = 0;
  319. private UUID m_sitTargetAvatar = UUID.Zero;
  320. private uint _baseMask = (uint)PermissionMask.All;
  321. private uint _ownerMask = (uint)PermissionMask.All;
  322. private uint _groupMask = (uint)PermissionMask.None;
  323. private uint _everyoneMask = (uint)PermissionMask.None;
  324. private uint _nextOwnerMask = (uint)PermissionMask.All;
  325. private PrimFlags _flags = PrimFlags.None;
  326. private DateTime m_expires;
  327. private DateTime m_rezzed;
  328. private bool m_createSelected = false;
  329. private string m_creatorData = string.Empty;
  330. public UUID CreatorID
  331. {
  332. get
  333. {
  334. return _creatorID;
  335. }
  336. set
  337. {
  338. _creatorID = value;
  339. }
  340. }
  341. /// <summary>
  342. /// Data about the creator in the form profile_url;name
  343. /// </summary>
  344. public string CreatorData
  345. {
  346. get { return m_creatorData; }
  347. set { m_creatorData = value; }
  348. }
  349. /// <summary>
  350. /// Used by the DB layer to retrieve / store the entire user identification.
  351. /// The identification can either be a simple UUID or a string of the form
  352. /// uuid[;profile_url[;name]]
  353. /// </summary>
  354. public string CreatorIdentification
  355. {
  356. get
  357. {
  358. if (m_creatorData != null && m_creatorData != string.Empty)
  359. return _creatorID.ToString() + ';' + m_creatorData;
  360. else
  361. return _creatorID.ToString();
  362. }
  363. set
  364. {
  365. if ((value == null) || (value != null && value == string.Empty))
  366. {
  367. m_creatorData = string.Empty;
  368. return;
  369. }
  370. if (!value.Contains(";")) // plain UUID
  371. {
  372. UUID uuid = UUID.Zero;
  373. UUID.TryParse(value, out uuid);
  374. _creatorID = uuid;
  375. }
  376. else // <uuid>[;<endpoint>[;name]]
  377. {
  378. string name = "Unknown User";
  379. string[] parts = value.Split(';');
  380. if (parts.Length >= 1)
  381. {
  382. UUID uuid = UUID.Zero;
  383. UUID.TryParse(parts[0], out uuid);
  384. _creatorID = uuid;
  385. }
  386. if (parts.Length >= 2)
  387. m_creatorData = parts[1];
  388. if (parts.Length >= 3)
  389. name = parts[2];
  390. m_creatorData += ';' + name;
  391. }
  392. }
  393. }
  394. /// <summary>
  395. /// A relic from when we we thought that prims contained folder objects. In
  396. /// reality, prim == folder
  397. /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
  398. /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
  399. /// </summary>
  400. public UUID FolderID
  401. {
  402. get { return UUID; }
  403. set { } // Don't allow assignment, or legacy prims wil b0rk - but we need the setter for legacy serialization.
  404. }
  405. /// <value>
  406. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  407. /// </value>
  408. public uint InventorySerial
  409. {
  410. get { return m_inventory.Serial; }
  411. set { m_inventory.Serial = value; }
  412. }
  413. /// <value>
  414. /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes
  415. /// </value>
  416. public TaskInventoryDictionary TaskInventory
  417. {
  418. get { return m_inventory.Items; }
  419. set { m_inventory.Items = value; }
  420. }
  421. /// <summary>
  422. /// This is idential to the Flags property, except that the returned value is uint rather than PrimFlags
  423. /// </summary>
  424. [Obsolete("Use Flags property instead")]
  425. public uint ObjectFlags
  426. {
  427. get { return (uint)Flags; }
  428. set { Flags = (PrimFlags)value; }
  429. }
  430. public UUID UUID
  431. {
  432. get { return m_uuid; }
  433. set
  434. {
  435. m_uuid = value;
  436. // This is necessary so that TaskInventoryItem parent ids correctly reference the new uuid of this part
  437. if (Inventory != null)
  438. Inventory.ResetObjectID();
  439. }
  440. }
  441. public uint LocalId
  442. {
  443. get { return m_localId; }
  444. set { m_localId = value; }
  445. }
  446. public virtual string Name
  447. {
  448. get { return m_name; }
  449. set
  450. {
  451. m_name = value;
  452. if (PhysActor != null)
  453. {
  454. PhysActor.SOPName = value;
  455. }
  456. }
  457. }
  458. public byte Material
  459. {
  460. get { return (byte) m_material; }
  461. set
  462. {
  463. m_material = (Material)value;
  464. if (PhysActor != null)
  465. {
  466. PhysActor.SetMaterial((int)value);
  467. }
  468. }
  469. }
  470. public bool PassTouches
  471. {
  472. get { return m_passTouches; }
  473. set
  474. {
  475. m_passTouches = value;
  476. if (ParentGroup != null)
  477. ParentGroup.HasGroupChanged = true;
  478. }
  479. }
  480. public Dictionary<int, string> CollisionFilter
  481. {
  482. get { return m_CollisionFilter; }
  483. set
  484. {
  485. m_CollisionFilter = value;
  486. }
  487. }
  488. public Quaternion APIDTarget
  489. {
  490. get { return m_APIDTarget; }
  491. set { m_APIDTarget = value; }
  492. }
  493. public float APIDDamp
  494. {
  495. get { return m_APIDDamp; }
  496. set { m_APIDDamp = value; }
  497. }
  498. public float APIDStrength
  499. {
  500. get { return m_APIDStrength; }
  501. set { m_APIDStrength = value; }
  502. }
  503. public ulong RegionHandle
  504. {
  505. get { return m_regionHandle; }
  506. set { m_regionHandle = value; }
  507. }
  508. public int ScriptAccessPin
  509. {
  510. get { return m_scriptAccessPin; }
  511. set { m_scriptAccessPin = (int)value; }
  512. }
  513. private SceneObjectPart m_PlaySoundMasterPrim = null;
  514. public SceneObjectPart PlaySoundMasterPrim
  515. {
  516. get { return m_PlaySoundMasterPrim; }
  517. set { m_PlaySoundMasterPrim = value; }
  518. }
  519. private List<SceneObjectPart> m_PlaySoundSlavePrims = new List<SceneObjectPart>();
  520. public List<SceneObjectPart> PlaySoundSlavePrims
  521. {
  522. get { return m_PlaySoundSlavePrims; }
  523. set { m_PlaySoundSlavePrims = value; }
  524. }
  525. private SceneObjectPart m_LoopSoundMasterPrim = null;
  526. public SceneObjectPart LoopSoundMasterPrim
  527. {
  528. get { return m_LoopSoundMasterPrim; }
  529. set { m_LoopSoundMasterPrim = value; }
  530. }
  531. private List<SceneObjectPart> m_LoopSoundSlavePrims = new List<SceneObjectPart>();
  532. public List<SceneObjectPart> LoopSoundSlavePrims
  533. {
  534. get { return m_LoopSoundSlavePrims; }
  535. set { m_LoopSoundSlavePrims = value; }
  536. }
  537. public Byte[] TextureAnimation
  538. {
  539. get { return m_TextureAnimation; }
  540. set { m_TextureAnimation = value; }
  541. }
  542. public Byte[] ParticleSystem
  543. {
  544. get { return m_particleSystem; }
  545. set { m_particleSystem = value; }
  546. }
  547. public DateTime Expires
  548. {
  549. get { return m_expires; }
  550. set { m_expires = value; }
  551. }
  552. public DateTime Rezzed
  553. {
  554. get { return m_rezzed; }
  555. set { m_rezzed = value; }
  556. }
  557. public float Damage
  558. {
  559. get { return m_damage; }
  560. set { m_damage = value; }
  561. }
  562. /// <summary>
  563. /// The position of the entire group that this prim belongs to.
  564. /// </summary>
  565. public Vector3 GroupPosition
  566. {
  567. get
  568. {
  569. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  570. PhysicsActor actor = PhysActor;
  571. if (actor != null && _parentID == 0)
  572. {
  573. m_groupPosition = actor.Position;
  574. }
  575. if (m_parentGroup.IsAttachment)
  576. {
  577. ScenePresence sp = m_parentGroup.Scene.GetScenePresence(ParentGroup.AttachedAvatar);
  578. if (sp != null)
  579. return sp.AbsolutePosition;
  580. }
  581. return m_groupPosition;
  582. }
  583. set
  584. {
  585. m_groupPosition = value;
  586. PhysicsActor actor = PhysActor;
  587. if (actor != null)
  588. {
  589. try
  590. {
  591. // Root prim actually goes at Position
  592. if (_parentID == 0)
  593. {
  594. actor.Position = value;
  595. }
  596. else
  597. {
  598. // To move the child prim in respect to the group position and rotation we have to calculate
  599. actor.Position = GetWorldPosition();
  600. actor.Orientation = GetWorldRotation();
  601. }
  602. // Tell the physics engines that this prim changed.
  603. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  604. }
  605. catch (Exception e)
  606. {
  607. m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
  608. }
  609. }
  610. // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
  611. if (m_sitTargetAvatar != UUID.Zero)
  612. {
  613. ScenePresence avatar;
  614. if (m_parentGroup.Scene.TryGetScenePresence(m_sitTargetAvatar, out avatar))
  615. {
  616. avatar.ParentPosition = GetWorldPosition();
  617. }
  618. }
  619. }
  620. }
  621. public Vector3 OffsetPosition
  622. {
  623. get { return m_offsetPosition; }
  624. set
  625. {
  626. // StoreUndoState();
  627. m_offsetPosition = value;
  628. if (ParentGroup != null && !ParentGroup.IsDeleted)
  629. {
  630. PhysicsActor actor = PhysActor;
  631. if (_parentID != 0 && actor != null)
  632. {
  633. actor.Position = GetWorldPosition();
  634. actor.Orientation = GetWorldRotation();
  635. // Tell the physics engines that this prim changed.
  636. if (m_parentGroup.Scene != null)
  637. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  638. }
  639. }
  640. }
  641. }
  642. public Vector3 RelativePosition
  643. {
  644. get
  645. {
  646. if (IsRoot)
  647. {
  648. if (m_parentGroup.IsAttachment)
  649. return AttachedPos;
  650. else
  651. return AbsolutePosition;
  652. }
  653. else
  654. {
  655. return OffsetPosition;
  656. }
  657. }
  658. }
  659. public Quaternion RotationOffset
  660. {
  661. get
  662. {
  663. // We don't want the physics engine mucking up the rotations in a linkset
  664. PhysicsActor actor = PhysActor;
  665. if (_parentID == 0 && (Shape.PCode != 9 || Shape.State == 0) && actor != null)
  666. {
  667. if (actor.Orientation.X != 0f || actor.Orientation.Y != 0f
  668. || actor.Orientation.Z != 0f || actor.Orientation.W != 0f)
  669. {
  670. m_rotationOffset = actor.Orientation;
  671. }
  672. }
  673. return m_rotationOffset;
  674. }
  675. set
  676. {
  677. StoreUndoState();
  678. m_rotationOffset = value;
  679. PhysicsActor actor = PhysActor;
  680. if (actor != null)
  681. {
  682. try
  683. {
  684. // Root prim gets value directly
  685. if (_parentID == 0)
  686. {
  687. actor.Orientation = value;
  688. //m_log.Info("[PART]: RO1:" + actor.Orientation.ToString());
  689. }
  690. else
  691. {
  692. // Child prim we have to calculate it's world rotationwel
  693. Quaternion resultingrotation = GetWorldRotation();
  694. actor.Orientation = resultingrotation;
  695. //m_log.Info("[PART]: RO2:" + actor.Orientation.ToString());
  696. }
  697. if (m_parentGroup != null)
  698. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  699. //}
  700. }
  701. catch (Exception ex)
  702. {
  703. m_log.Error("[SCENEOBJECTPART]: ROTATIONOFFSET" + ex.Message);
  704. }
  705. }
  706. }
  707. }
  708. /// <summary></summary>
  709. public Vector3 Velocity
  710. {
  711. get
  712. {
  713. PhysicsActor actor = PhysActor;
  714. if (actor != null)
  715. {
  716. if (actor.IsPhysical)
  717. {
  718. m_velocity = actor.Velocity;
  719. }
  720. }
  721. return m_velocity;
  722. }
  723. set
  724. {
  725. m_velocity = value;
  726. PhysicsActor actor = PhysActor;
  727. if (actor != null)
  728. {
  729. if (actor.IsPhysical)
  730. {
  731. actor.Velocity = value;
  732. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
  733. }
  734. }
  735. }
  736. }
  737. /// <summary></summary>
  738. public Vector3 AngularVelocity
  739. {
  740. get
  741. {
  742. PhysicsActor actor = PhysActor;
  743. if ((actor != null) && actor.IsPhysical)
  744. {
  745. m_angularVelocity = actor.RotationalVelocity;
  746. }
  747. return m_angularVelocity;
  748. }
  749. set { m_angularVelocity = value; }
  750. }
  751. /// <summary></summary>
  752. public Vector3 Acceleration
  753. {
  754. get { return m_acceleration; }
  755. set { m_acceleration = value; }
  756. }
  757. public string Description
  758. {
  759. get { return m_description; }
  760. set
  761. {
  762. m_description = value;
  763. PhysicsActor actor = PhysActor;
  764. if (actor != null)
  765. {
  766. actor.SOPDescription = value;
  767. }
  768. }
  769. }
  770. /// <value>
  771. /// Text color.
  772. /// </value>
  773. public Color Color
  774. {
  775. get { return m_color; }
  776. set
  777. {
  778. m_color = value;
  779. /* ScheduleFullUpdate() need not be called b/c after
  780. * setting the color, the text will be set, so then
  781. * ScheduleFullUpdate() will be called. */
  782. //ScheduleFullUpdate();
  783. }
  784. }
  785. public string Text
  786. {
  787. get
  788. {
  789. string returnstr = m_text;
  790. if (returnstr.Length > 255)
  791. {
  792. returnstr = returnstr.Substring(0, 254);
  793. }
  794. return returnstr;
  795. }
  796. set
  797. {
  798. m_text = value;
  799. }
  800. }
  801. public string SitName
  802. {
  803. get { return m_sitName; }
  804. set { m_sitName = value; }
  805. }
  806. public string TouchName
  807. {
  808. get { return m_touchName; }
  809. set { m_touchName = value; }
  810. }
  811. public int LinkNum
  812. {
  813. get { return m_linkNum; }
  814. set { m_linkNum = value; }
  815. }
  816. public byte ClickAction
  817. {
  818. get { return m_clickAction; }
  819. set
  820. {
  821. m_clickAction = value;
  822. }
  823. }
  824. public PrimitiveBaseShape Shape
  825. {
  826. get { return m_shape; }
  827. set { m_shape = value; }
  828. }
  829. /// <summary>
  830. /// Change the scale of this part.
  831. /// </summary>
  832. public Vector3 Scale
  833. {
  834. get { return m_shape.Scale; }
  835. set
  836. {
  837. if (m_shape != null)
  838. {
  839. StoreUndoState();
  840. m_shape.Scale = value;
  841. PhysicsActor actor = PhysActor;
  842. if (actor != null)
  843. {
  844. if (m_parentGroup.Scene != null)
  845. {
  846. if (m_parentGroup.Scene.PhysicsScene != null)
  847. {
  848. actor.Size = m_shape.Scale;
  849. if (Shape.SculptEntry)
  850. CheckSculptAndLoad();
  851. else
  852. ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  853. }
  854. }
  855. }
  856. }
  857. TriggerScriptChangedEvent(Changed.SCALE);
  858. }
  859. }
  860. public byte UpdateFlag
  861. {
  862. get { return m_updateFlag; }
  863. set { m_updateFlag = value; }
  864. }
  865. /// <summary>
  866. /// Used for media on a prim.
  867. /// </summary>
  868. /// Do not change this value directly - always do it through an IMoapModule.
  869. public string MediaUrl
  870. {
  871. get
  872. {
  873. return m_mediaUrl;
  874. }
  875. set
  876. {
  877. m_mediaUrl = value;
  878. if (ParentGroup != null)
  879. ParentGroup.HasGroupChanged = true;
  880. }
  881. }
  882. public bool CreateSelected
  883. {
  884. get { return m_createSelected; }
  885. set
  886. {
  887. // m_log.DebugFormat("[SOP]: Setting CreateSelected to {0} for {1} {2}", value, Name, UUID);
  888. m_createSelected = value;
  889. }
  890. }
  891. #endregion
  892. //---------------
  893. #region Public Properties with only Get
  894. public Vector3 AbsolutePosition
  895. {
  896. get
  897. {
  898. if (m_parentGroup.IsAttachment)
  899. return GroupPosition;
  900. return m_offsetPosition + m_groupPosition;
  901. }
  902. }
  903. public SceneObjectGroup ParentGroup
  904. {
  905. get { return m_parentGroup; }
  906. }
  907. public scriptEvents ScriptEvents
  908. {
  909. get { return AggregateScriptEvents; }
  910. }
  911. public Quaternion SitTargetOrientation
  912. {
  913. get { return m_sitTargetOrientation; }
  914. set { m_sitTargetOrientation = value; }
  915. }
  916. public Vector3 SitTargetPosition
  917. {
  918. get { return m_sitTargetPosition; }
  919. set { m_sitTargetPosition = value; }
  920. }
  921. // This sort of sucks, but I'm adding these in to make some of
  922. // the mappings more consistant.
  923. public Vector3 SitTargetPositionLL
  924. {
  925. get { return new Vector3(m_sitTargetPosition.X, m_sitTargetPosition.Y,m_sitTargetPosition.Z); }
  926. set { m_sitTargetPosition = value; }
  927. }
  928. public Quaternion SitTargetOrientationLL
  929. {
  930. get
  931. {
  932. return new Quaternion(
  933. m_sitTargetOrientation.X,
  934. m_sitTargetOrientation.Y,
  935. m_sitTargetOrientation.Z,
  936. m_sitTargetOrientation.W
  937. );
  938. }
  939. set { m_sitTargetOrientation = new Quaternion(value.X, value.Y, value.Z, value.W); }
  940. }
  941. public bool Stopped
  942. {
  943. get {
  944. double threshold = 0.02;
  945. return (Math.Abs(Velocity.X) < threshold &&
  946. Math.Abs(Velocity.Y) < threshold &&
  947. Math.Abs(Velocity.Z) < threshold &&
  948. Math.Abs(AngularVelocity.X) < threshold &&
  949. Math.Abs(AngularVelocity.Y) < threshold &&
  950. Math.Abs(AngularVelocity.Z) < threshold);
  951. }
  952. }
  953. public uint ParentID
  954. {
  955. get { return _parentID; }
  956. set { _parentID = value; }
  957. }
  958. public int CreationDate
  959. {
  960. get { return _creationDate; }
  961. set { _creationDate = value; }
  962. }
  963. public uint Category
  964. {
  965. get { return _category; }
  966. set { _category = value; }
  967. }
  968. public int SalePrice
  969. {
  970. get { return _salePrice; }
  971. set { _salePrice = value; }
  972. }
  973. public byte ObjectSaleType
  974. {
  975. get { return _objectSaleType; }
  976. set { _objectSaleType = value; }
  977. }
  978. public int OwnershipCost
  979. {
  980. get { return _ownershipCost; }
  981. set { _ownershipCost = value; }
  982. }
  983. public UUID GroupID
  984. {
  985. get { return _groupID; }
  986. set { _groupID = value; }
  987. }
  988. public UUID OwnerID
  989. {
  990. get { return _ownerID; }
  991. set { _ownerID = value; }
  992. }
  993. public UUID LastOwnerID
  994. {
  995. get { return _lastOwnerID; }
  996. set { _lastOwnerID = value; }
  997. }
  998. public uint BaseMask
  999. {
  1000. get { return _baseMask; }
  1001. set { _baseMask = value; }
  1002. }
  1003. public uint OwnerMask
  1004. {
  1005. get { return _ownerMask; }
  1006. set { _ownerMask = value; }
  1007. }
  1008. public uint GroupMask
  1009. {
  1010. get { return _groupMask; }
  1011. set { _groupMask = value; }
  1012. }
  1013. public uint EveryoneMask
  1014. {
  1015. get { return _everyoneMask; }
  1016. set { _everyoneMask = value; }
  1017. }
  1018. public uint NextOwnerMask
  1019. {
  1020. get { return _nextOwnerMask; }
  1021. set { _nextOwnerMask = value; }
  1022. }
  1023. /// <summary>
  1024. /// Property flags. See OpenMetaverse.PrimFlags
  1025. /// </summary>
  1026. /// <remarks>
  1027. /// Example properties are PrimFlags.Phantom and PrimFlags.DieAtEdge
  1028. /// </remarks>
  1029. public PrimFlags Flags
  1030. {
  1031. get { return _flags; }
  1032. set
  1033. {
  1034. // m_log.DebugFormat("[SOP]: Setting flags for {0} {1} to {2}", UUID, Name, value);
  1035. _flags = value;
  1036. }
  1037. }
  1038. public UUID SitTargetAvatar
  1039. {
  1040. get { return m_sitTargetAvatar; }
  1041. set { m_sitTargetAvatar = value; }
  1042. }
  1043. public virtual UUID RegionID
  1044. {
  1045. get
  1046. {
  1047. if (ParentGroup.Scene != null)
  1048. return ParentGroup.Scene.RegionInfo.RegionID;
  1049. else
  1050. return UUID.Zero;
  1051. }
  1052. set {} // read only
  1053. }
  1054. private UUID _parentUUID = UUID.Zero;
  1055. public UUID ParentUUID
  1056. {
  1057. get
  1058. {
  1059. if (ParentGroup != null)
  1060. _parentUUID = ParentGroup.UUID;
  1061. return _parentUUID;
  1062. }
  1063. set { _parentUUID = value; }
  1064. }
  1065. public string SitAnimation
  1066. {
  1067. get { return m_sitAnimation; }
  1068. set { m_sitAnimation = value; }
  1069. }
  1070. public UUID CollisionSound
  1071. {
  1072. get { return m_collisionSound; }
  1073. set
  1074. {
  1075. m_collisionSound = value;
  1076. aggregateScriptEvents();
  1077. }
  1078. }
  1079. public float CollisionSoundVolume
  1080. {
  1081. get { return m_collisionSoundVolume; }
  1082. set { m_collisionSoundVolume = value; }
  1083. }
  1084. #endregion Public Properties with only Get
  1085. private uint ApplyMask(uint val, bool set, uint mask)
  1086. {
  1087. if (set)
  1088. {
  1089. return val |= mask;
  1090. }
  1091. else
  1092. {
  1093. return val &= ~mask;
  1094. }
  1095. }
  1096. /// <summary>
  1097. /// Clear all pending updates of parts to clients
  1098. /// </summary>
  1099. private void ClearUpdateSchedule()
  1100. {
  1101. m_updateFlag = 0;
  1102. }
  1103. /// <summary>
  1104. /// Send this part's properties (name, description, inventory serial, base mask, etc.) to a client
  1105. /// </summary>
  1106. /// <param name="client"></param>
  1107. public void SendPropertiesToClient(IClientAPI client)
  1108. {
  1109. client.SendObjectPropertiesReply(this);
  1110. }
  1111. /// <summary>
  1112. /// For the scene object group to which this part belongs, send that scene object's root part properties to a client.
  1113. /// </summary>
  1114. /// <param name="AgentID"></param>
  1115. private void SendRootPartPropertiesToClient(UUID AgentID)
  1116. {
  1117. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1118. {
  1119. // Ugly reference :(
  1120. if (avatar.UUID == AgentID)
  1121. {
  1122. m_parentGroup.SendPropertiesToClient(avatar.ControllingClient);
  1123. }
  1124. });
  1125. }
  1126. // TODO: unused:
  1127. // private void handleTimerAccounting(uint localID, double interval)
  1128. // {
  1129. // if (localID == LocalId)
  1130. // {
  1131. // float sec = (float)interval;
  1132. // if (m_parentGroup != null)
  1133. // {
  1134. // if (sec == 0)
  1135. // {
  1136. // if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  1137. // m_parentGroup.scriptScore = 0;
  1138. //
  1139. // m_parentGroup.scriptScore += 0.001f;
  1140. // return;
  1141. // }
  1142. //
  1143. // if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  1144. // m_parentGroup.scriptScore = 0;
  1145. // m_parentGroup.scriptScore += (0.001f / sec);
  1146. // }
  1147. // }
  1148. // }
  1149. #region Public Methods
  1150. public void ResetExpire()
  1151. {
  1152. Expires = DateTime.Now + new TimeSpan(600000000);
  1153. }
  1154. public void AddFlag(PrimFlags flag)
  1155. {
  1156. // PrimFlags prevflag = Flags;
  1157. if ((Flags & flag) == 0)
  1158. {
  1159. //m_log.Debug("Adding flag: " + ((PrimFlags) flag).ToString());
  1160. Flags |= flag;
  1161. if (flag == PrimFlags.TemporaryOnRez)
  1162. ResetExpire();
  1163. }
  1164. // m_log.Debug("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1165. }
  1166. /// <summary>
  1167. /// Tell all scene presences that they should send updates for this part to their clients
  1168. /// </summary>
  1169. public void AddFullUpdateToAllAvatars()
  1170. {
  1171. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1172. {
  1173. AddFullUpdateToAvatar(avatar);
  1174. });
  1175. }
  1176. /// <summary>
  1177. /// Tell the scene presence that it should send updates for this part to its client
  1178. /// </summary>
  1179. public void AddFullUpdateToAvatar(ScenePresence presence)
  1180. {
  1181. presence.SceneViewer.QueuePartForUpdate(this);
  1182. }
  1183. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1184. {
  1185. m_particleSystem = pSystem.GetBytes();
  1186. }
  1187. public void RemoveParticleSystem()
  1188. {
  1189. m_particleSystem = new byte[0];
  1190. }
  1191. /// Terse updates
  1192. public void AddTerseUpdateToAllAvatars()
  1193. {
  1194. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  1195. {
  1196. AddTerseUpdateToAvatar(avatar);
  1197. });
  1198. }
  1199. public void AddTerseUpdateToAvatar(ScenePresence presence)
  1200. {
  1201. presence.SceneViewer.QueuePartForUpdate(this);
  1202. }
  1203. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1204. {
  1205. byte[] data = new byte[16];
  1206. int pos = 0;
  1207. // The flags don't like conversion from uint to byte, so we have to do
  1208. // it the crappy way. See the above function :(
  1209. data[pos] = ConvertScriptUintToByte((uint)pTexAnim.Flags); pos++;
  1210. data[pos] = (byte)pTexAnim.Face; pos++;
  1211. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1212. data[pos] = (byte)pTexAnim.SizeY; pos++;
  1213. Utils.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1214. Utils.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4);
  1215. Utils.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1216. m_TextureAnimation = data;
  1217. }
  1218. public void AdjustSoundGain(double volume)
  1219. {
  1220. if (volume > 1)
  1221. volume = 1;
  1222. if (volume < 0)
  1223. volume = 0;
  1224. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
  1225. {
  1226. if (!sp.IsChildAgent)
  1227. sp.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
  1228. });
  1229. }
  1230. /// <summary>
  1231. /// hook to the physics scene to apply impulse
  1232. /// This is sent up to the group, which then finds the root prim
  1233. /// and applies the force on the root prim of the group
  1234. /// </summary>
  1235. /// <param name="impulsei">Vector force</param>
  1236. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1237. public void ApplyImpulse(Vector3 impulsei, bool localGlobalTF)
  1238. {
  1239. Vector3 impulse = impulsei;
  1240. if (localGlobalTF)
  1241. {
  1242. Quaternion grot = GetWorldRotation();
  1243. Quaternion AXgrot = grot;
  1244. Vector3 AXimpulsei = impulsei;
  1245. Vector3 newimpulse = AXimpulsei * AXgrot;
  1246. impulse = newimpulse;
  1247. }
  1248. if (m_parentGroup != null)
  1249. {
  1250. m_parentGroup.applyImpulse(impulse);
  1251. }
  1252. }
  1253. /// <summary>
  1254. /// hook to the physics scene to apply angular impulse
  1255. /// This is sent up to the group, which then finds the root prim
  1256. /// and applies the force on the root prim of the group
  1257. /// </summary>
  1258. /// <param name="impulsei">Vector force</param>
  1259. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1260. public void ApplyAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1261. {
  1262. Vector3 impulse = impulsei;
  1263. if (localGlobalTF)
  1264. {
  1265. Quaternion grot = GetWorldRotation();
  1266. Quaternion AXgrot = grot;
  1267. Vector3 AXimpulsei = impulsei;
  1268. Vector3 newimpulse = AXimpulsei * AXgrot;
  1269. impulse = newimpulse;
  1270. }
  1271. m_parentGroup.applyAngularImpulse(impulse);
  1272. }
  1273. /// <summary>
  1274. /// hook to the physics scene to apply angular impulse
  1275. /// This is sent up to the group, which then finds the root prim
  1276. /// and applies the force on the root prim of the group
  1277. /// </summary>
  1278. /// <param name="impulsei">Vector force</param>
  1279. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  1280. public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF)
  1281. {
  1282. Vector3 impulse = impulsei;
  1283. if (localGlobalTF)
  1284. {
  1285. Quaternion grot = GetWorldRotation();
  1286. Quaternion AXgrot = grot;
  1287. Vector3 AXimpulsei = impulsei;
  1288. Vector3 newimpulse = AXimpulsei * AXgrot;
  1289. impulse = newimpulse;
  1290. }
  1291. m_parentGroup.setAngularImpulse(impulse);
  1292. }
  1293. /// <summary>
  1294. /// Apply physics to this part.
  1295. /// </summary>
  1296. /// <param name="rootObjectFlags"></param>
  1297. /// <param name="m_physicalPrim"></param>
  1298. public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool m_physicalPrim)
  1299. {
  1300. // m_log.DebugFormat("[SCENE OBJECT PART]: Applying physics to {0} {1} {2}", Name, LocalId, UUID);
  1301. bool isPhysical = (((rootObjectFlags & (uint) PrimFlags.Physics) != 0) && m_physicalPrim);
  1302. bool isPhantom = ((rootObjectFlags & (uint) PrimFlags.Phantom) != 0);
  1303. if (IsJoint())
  1304. {
  1305. DoPhysicsPropertyUpdate(isPhysical, true);
  1306. }
  1307. else
  1308. {
  1309. // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
  1310. if (VolumeDetectActive)
  1311. isPhantom = false;
  1312. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  1313. bool RigidBody = isPhysical && !isPhantom;
  1314. // The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
  1315. // or flexible
  1316. if (!isPhantom && !m_parentGroup.IsAttachment && !(Shape.PathCurve == (byte) Extrusion.Flexible))
  1317. {
  1318. try
  1319. {
  1320. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1321. string.Format("{0}/{1}", Name, UUID),
  1322. Shape,
  1323. AbsolutePosition,
  1324. Scale,
  1325. RotationOffset,
  1326. RigidBody,
  1327. m_localId);
  1328. }
  1329. catch
  1330. {
  1331. m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid);
  1332. PhysActor = null;
  1333. }
  1334. // Basic Physics returns null.. joy joy joy.
  1335. if (PhysActor != null)
  1336. {
  1337. PhysActor.SOPName = this.Name; // save object name and desc into the PhysActor so ODE internals know the joint/body info
  1338. PhysActor.SOPDescription = this.Description;
  1339. PhysActor.SetMaterial(Material);
  1340. DoPhysicsPropertyUpdate(RigidBody, true);
  1341. PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
  1342. }
  1343. else
  1344. {
  1345. m_log.DebugFormat("[SOP]: physics actor is null for {0} with parent {1}", UUID, this.ParentGroup.UUID);
  1346. }
  1347. }
  1348. }
  1349. }
  1350. public byte ConvertScriptUintToByte(uint indata)
  1351. {
  1352. byte outdata = (byte)TextureAnimFlags.NONE;
  1353. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1354. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1355. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1356. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1357. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1358. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1359. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1360. return outdata;
  1361. }
  1362. /// <summary>
  1363. /// Duplicates this part.
  1364. /// </summary>
  1365. /// <param name="localID"></param>
  1366. /// <param name="AgentID"></param>
  1367. /// <param name="GroupID"></param>
  1368. /// <param name="linkNum"></param>
  1369. /// <param name="userExposed">True if the duplicate will immediately be in the scene, false otherwise</param>
  1370. /// <returns></returns>
  1371. public SceneObjectPart Copy(uint localID, UUID AgentID, UUID GroupID, int linkNum, bool userExposed)
  1372. {
  1373. SceneObjectPart dupe = (SceneObjectPart)MemberwiseClone();
  1374. dupe.m_shape = m_shape.Copy();
  1375. dupe.m_regionHandle = m_regionHandle;
  1376. if (userExposed)
  1377. dupe.UUID = UUID.Random();
  1378. //memberwiseclone means it also clones the physics actor reference
  1379. // This will make physical prim 'bounce' if not set to null.
  1380. if (!userExposed)
  1381. dupe.PhysActor = null;
  1382. dupe._ownerID = AgentID;
  1383. dupe._groupID = GroupID;
  1384. dupe.GroupPosition = GroupPosition;
  1385. dupe.OffsetPosition = OffsetPosition;
  1386. dupe.RotationOffset = RotationOffset;
  1387. dupe.Velocity = new Vector3(0, 0, 0);
  1388. dupe.Acceleration = new Vector3(0, 0, 0);
  1389. dupe.AngularVelocity = new Vector3(0, 0, 0);
  1390. dupe.Flags = Flags;
  1391. dupe._ownershipCost = _ownershipCost;
  1392. dupe._objectSaleType = _objectSaleType;
  1393. dupe._salePrice = _salePrice;
  1394. dupe._category = _category;
  1395. dupe.m_rezzed = m_rezzed;
  1396. dupe.m_inventory = new SceneObjectPartInventory(dupe);
  1397. dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
  1398. if (userExposed)
  1399. {
  1400. dupe.ResetIDs(linkNum);
  1401. dupe.m_inventory.HasInventoryChanged = true;
  1402. }
  1403. else
  1404. {
  1405. dupe.m_inventory.HasInventoryChanged = m_inventory.HasInventoryChanged;
  1406. }
  1407. // Move afterwards ResetIDs as it clears the localID
  1408. dupe.LocalId = localID;
  1409. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1410. dupe._lastOwnerID = OwnerID;
  1411. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1412. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1413. dupe.Shape.ExtraParams = extraP;
  1414. if (userExposed)
  1415. {
  1416. if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero)
  1417. {
  1418. ParentGroup.Scene.AssetService.Get(
  1419. dupe.m_shape.SculptTexture.ToString(), dupe, dupe.AssetReceived);
  1420. }
  1421. bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
  1422. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1423. }
  1424. ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
  1425. // m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
  1426. return dupe;
  1427. }
  1428. /// <summary>
  1429. /// Called back by asynchronous asset fetch.
  1430. /// </summary>
  1431. /// <param name="id">ID of asset received</param>
  1432. /// <param name="sender">Register</param>
  1433. /// <param name="asset"></param>
  1434. protected void AssetReceived(string id, Object sender, AssetBase asset)
  1435. {
  1436. if (asset != null)
  1437. SculptTextureCallback(asset);
  1438. else
  1439. m_log.WarnFormat(
  1440. "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
  1441. Name, LocalId, id);
  1442. }
  1443. public static SceneObjectPart Create()
  1444. {
  1445. SceneObjectPart part = new SceneObjectPart();
  1446. part.UUID = UUID.Random();
  1447. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  1448. part.Shape = shape;
  1449. part.Name = "Primitive";
  1450. part._ownerID = UUID.Random();
  1451. return part;
  1452. }
  1453. /// <summary>
  1454. /// Do a physics property update for a NINJA joint.
  1455. /// </summary>
  1456. /// <param name="UsePhysics"></param>
  1457. /// <param name="isNew"></param>
  1458. protected void DoPhysicsPropertyUpdateForNinjaJoint(bool UsePhysics, bool isNew)
  1459. {
  1460. if (UsePhysics)
  1461. {
  1462. // by turning a joint proxy object physical, we cause creation of a joint in the ODE scene.
  1463. // note that, as a special case, joints have no bodies or geoms in the physics scene, even though they are physical.
  1464. PhysicsJointType jointType;
  1465. if (IsHingeJoint())
  1466. {
  1467. jointType = PhysicsJointType.Hinge;
  1468. }
  1469. else if (IsBallJoint())
  1470. {
  1471. jointType = PhysicsJointType.Ball;
  1472. }
  1473. else
  1474. {
  1475. jointType = PhysicsJointType.Ball;
  1476. }
  1477. List<string> bodyNames = new List<string>();
  1478. string RawParams = Description;
  1479. string[] jointParams = RawParams.Split(" ".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
  1480. string trackedBodyName = null;
  1481. if (jointParams.Length >= 2)
  1482. {
  1483. for (int iBodyName = 0; iBodyName < 2; iBodyName++)
  1484. {
  1485. string bodyName = jointParams[iBodyName];
  1486. bodyNames.Add(bodyName);
  1487. if (bodyName != "NULL")
  1488. {
  1489. if (trackedBodyName == null)
  1490. {
  1491. trackedBodyName = bodyName;
  1492. }
  1493. }
  1494. }
  1495. }
  1496. SceneObjectPart trackedBody = m_parentGroup.Scene.GetSceneObjectPart(trackedBodyName); // FIXME: causes a sequential lookup
  1497. Quaternion localRotation = Quaternion.Identity;
  1498. if (trackedBody != null)
  1499. {
  1500. localRotation = Quaternion.Inverse(trackedBody.RotationOffset) * this.RotationOffset;
  1501. }
  1502. else
  1503. {
  1504. // error, output it below
  1505. }
  1506. PhysicsJoint joint;
  1507. joint = m_parentGroup.Scene.PhysicsScene.RequestJointCreation(Name, jointType,
  1508. AbsolutePosition,
  1509. this.RotationOffset,
  1510. Description,
  1511. bodyNames,
  1512. trackedBodyName,
  1513. localRotation);
  1514. if (trackedBody == null)
  1515. {
  1516. ParentGroup.Scene.jointErrorMessage(joint, "warning: tracked body name not found! joint location will not be updated properly. joint: " + Name);
  1517. }
  1518. }
  1519. else
  1520. {
  1521. if (isNew)
  1522. {
  1523. // if the joint proxy is new, and it is not physical, do nothing. There is no joint in ODE to
  1524. // delete, and if we try to delete it, due to asynchronous processing, the deletion request
  1525. // will get processed later at an indeterminate time, which could cancel a later-arriving
  1526. // joint creation request.
  1527. }
  1528. else
  1529. {
  1530. // here we turn off the joint object, so remove the joint from the physics scene
  1531. m_parentGroup.Scene.PhysicsScene.RequestJointDeletion(Name); // FIXME: what if the name changed?
  1532. // make sure client isn't interpolating the joint proxy object
  1533. Velocity = Vector3.Zero;
  1534. AngularVelocity = Vector3.Zero;
  1535. Acceleration = Vector3.Zero;
  1536. }
  1537. }
  1538. }
  1539. /// <summary>
  1540. /// Do a physics propery update for this part.
  1541. /// </summary>
  1542. /// <param name="UsePhysics"></param>
  1543. /// <param name="isNew"></param>
  1544. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1545. {
  1546. if (IsJoint())
  1547. {
  1548. DoPhysicsPropertyUpdateForNinjaJoint(UsePhysics, isNew);
  1549. }
  1550. else
  1551. {
  1552. if (PhysActor != null)
  1553. {
  1554. if (UsePhysics != PhysActor.IsPhysical || isNew)
  1555. {
  1556. if (PhysActor.IsPhysical) // implies UsePhysics==false for this block
  1557. {
  1558. if (!isNew)
  1559. ParentGroup.Scene.RemovePhysicalPrim(1);
  1560. PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1561. PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
  1562. PhysActor.delink();
  1563. if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew))
  1564. {
  1565. // destroy all joints connected to this now deactivated body
  1566. m_parentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
  1567. }
  1568. // stop client-side interpolation of all joint proxy objects that have just been deleted
  1569. // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback,
  1570. // which stops client-side interpolation of deactivated joint proxy objects.
  1571. }
  1572. if (!UsePhysics && !isNew)
  1573. {
  1574. // reset velocity to 0 on physics switch-off. Without that, the client thinks the
  1575. // prim still has velocity and continues to interpolate its position along the old
  1576. // velocity-vector.
  1577. Velocity = new Vector3(0, 0, 0);
  1578. Acceleration = new Vector3(0, 0, 0);
  1579. AngularVelocity = new Vector3(0, 0, 0);
  1580. //RotationalVelocity = new Vector3(0, 0, 0);
  1581. }
  1582. PhysActor.IsPhysical = UsePhysics;
  1583. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1584. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1585. /// that's not wholesome. Had to make Scene public
  1586. //PhysActor = null;
  1587. if ((Flags & PrimFlags.Phantom) == 0)
  1588. {
  1589. if (UsePhysics)
  1590. {
  1591. ParentGroup.Scene.AddPhysicalPrim(1);
  1592. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1593. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  1594. if (_parentID != 0 && _parentID != LocalId)
  1595. {
  1596. if (ParentGroup.RootPart.PhysActor != null)
  1597. {
  1598. PhysActor.link(ParentGroup.RootPart.PhysActor);
  1599. }
  1600. }
  1601. }
  1602. }
  1603. }
  1604. // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
  1605. // mesh data.
  1606. if (Shape.SculptEntry)
  1607. CheckSculptAndLoad();
  1608. else
  1609. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1610. }
  1611. }
  1612. }
  1613. /// <summary>
  1614. /// Restore this part from the serialized xml representation.
  1615. /// </summary>
  1616. /// <param name="xmlReader"></param>
  1617. /// <returns></returns>
  1618. public static SceneObjectPart FromXml(XmlTextReader xmlReader)
  1619. {
  1620. SceneObjectPart part = SceneObjectSerializer.Xml2ToSOP(xmlReader);
  1621. // for tempOnRez objects, we have to fix the Expire date.
  1622. if ((part.Flags & PrimFlags.TemporaryOnRez) != 0)
  1623. part.ResetExpire();
  1624. return part;
  1625. }
  1626. public UUID GetAvatarOnSitTarget()
  1627. {
  1628. return m_sitTargetAvatar;
  1629. }
  1630. public bool GetDieAtEdge()
  1631. {
  1632. if (m_parentGroup.IsDeleted)
  1633. return false;
  1634. return m_parentGroup.RootPart.DIE_AT_EDGE;
  1635. }
  1636. public bool GetReturnAtEdge()
  1637. {
  1638. if (m_parentGroup.IsDeleted)
  1639. return false;
  1640. return m_parentGroup.RootPart.RETURN_AT_EDGE;
  1641. }
  1642. public void SetReturnAtEdge(bool p)
  1643. {
  1644. if (m_parentGroup.IsDeleted)
  1645. return;
  1646. m_parentGroup.RootPart.RETURN_AT_EDGE = p;
  1647. }
  1648. public bool GetBlockGrab()
  1649. {
  1650. if (m_parentGroup.IsDeleted)
  1651. return false;
  1652. return m_parentGroup.RootPart.BlockGrab;
  1653. }
  1654. public void SetBlockGrab(bool p)
  1655. {
  1656. if (m_parentGroup.IsDeleted)
  1657. return;
  1658. m_parentGroup.RootPart.BlockGrab = p;
  1659. }
  1660. public void SetStatusSandbox(bool p)
  1661. {
  1662. if (m_parentGroup.IsDeleted)
  1663. return;
  1664. StatusSandboxPos = m_parentGroup.RootPart.AbsolutePosition;
  1665. m_parentGroup.RootPart.StatusSandbox = p;
  1666. }
  1667. public bool GetStatusSandbox()
  1668. {
  1669. if (m_parentGroup.IsDeleted)
  1670. return false;
  1671. return m_parentGroup.RootPart.StatusSandbox;
  1672. }
  1673. public int GetAxisRotation(int axis)
  1674. {
  1675. //Cannot use ScriptBaseClass constants as no referance to it currently.
  1676. if (axis == 2)//STATUS_ROTATE_X
  1677. return STATUS_ROTATE_X;
  1678. if (axis == 4)//STATUS_ROTATE_Y
  1679. return STATUS_ROTATE_Y;
  1680. if (axis == 8)//STATUS_ROTATE_Z
  1681. return STATUS_ROTATE_Z;
  1682. return 0;
  1683. }
  1684. public double GetDistanceTo(Vector3 a, Vector3 b)
  1685. {
  1686. float dx = a.X - b.X;
  1687. float dy = a.Y - b.Y;
  1688. float dz = a.Z - b.Z;
  1689. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  1690. }
  1691. public uint GetEffectiveObjectFlags()
  1692. {
  1693. // Commenting this section of code out since it doesn't actually do anything, as enums are handled by
  1694. // value rather than reference
  1695. // PrimFlags f = _flags;
  1696. // if (m_parentGroup == null || m_parentGroup.RootPart == this)
  1697. // f &= ~(PrimFlags.Touch | PrimFlags.Money);
  1698. return (uint)Flags | (uint)LocalFlags;
  1699. }
  1700. public Vector3 GetGeometricCenter()
  1701. {
  1702. if (PhysActor != null)
  1703. return new Vector3(PhysActor.CenterOfMass.X, PhysActor.CenterOfMass.Y, PhysActor.CenterOfMass.Z);
  1704. else
  1705. return new Vector3(0, 0, 0);
  1706. }
  1707. public float GetMass()
  1708. {
  1709. if (PhysActor != null)
  1710. return PhysActor.Mass;
  1711. else
  1712. return 0;
  1713. }
  1714. public Vector3 GetForce()
  1715. {
  1716. if (PhysActor != null)
  1717. return PhysActor.Force;
  1718. else
  1719. return Vector3.Zero;
  1720. }
  1721. /// <summary>
  1722. /// Method for a prim to get it's world position from the group.
  1723. /// </summary>
  1724. /// <remarks>
  1725. /// Remember, the Group Position simply gives the position of the group itself
  1726. /// </remarks>
  1727. /// <returns>A Linked Child Prim objects position in world</returns>
  1728. public Vector3 GetWorldPosition()
  1729. {
  1730. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1731. Vector3 axPos = OffsetPosition;
  1732. axPos *= parentRot;
  1733. Vector3 translationOffsetPosition = axPos;
  1734. // m_log.DebugFormat("[SCENE OBJECT PART]: Found group pos {0} for part {1}", GroupPosition, Name);
  1735. Vector3 worldPos = GroupPosition + translationOffsetPosition;
  1736. // m_log.DebugFormat("[SCENE OBJECT PART]: Found world pos {0} for part {1}", worldPos, Name);
  1737. return worldPos;
  1738. }
  1739. /// <summary>
  1740. /// Gets the rotation of this prim offset by the group rotation
  1741. /// </summary>
  1742. /// <returns></returns>
  1743. public Quaternion GetWorldRotation()
  1744. {
  1745. Quaternion newRot;
  1746. if (this.LinkNum == 0 || this.LinkNum == 1)
  1747. {
  1748. newRot = RotationOffset;
  1749. }
  1750. else
  1751. {
  1752. Quaternion parentRot = ParentGroup.RootPart.RotationOffset;
  1753. Quaternion oldRot = RotationOffset;
  1754. newRot = parentRot * oldRot;
  1755. }
  1756. return newRot;
  1757. }
  1758. public void MoveToTarget(Vector3 target, float tau)
  1759. {
  1760. if (tau > 0)
  1761. {
  1762. m_parentGroup.moveToTarget(target, tau);
  1763. }
  1764. else
  1765. {
  1766. StopMoveToTarget();
  1767. }
  1768. }
  1769. /// <summary>
  1770. /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
  1771. /// </summary>
  1772. /// <param name="height">Height to hover. Height of zero disables hover.</param>
  1773. /// <param name="hoverType">Determines what the height is relative to </param>
  1774. /// <param name="tau">Number of seconds over which to reach target</param>
  1775. public void SetHoverHeight(float height, PIDHoverType hoverType, float tau)
  1776. {
  1777. m_parentGroup.SetHoverHeight(height, hoverType, tau);
  1778. }
  1779. public void StopHover()
  1780. {
  1781. m_parentGroup.SetHoverHeight(0f, PIDHoverType.Ground, 0f);
  1782. }
  1783. public virtual void OnGrab(Vector3 offsetPos, IClientAPI remoteClient)
  1784. {
  1785. }
  1786. public void PhysicsCollision(EventArgs e)
  1787. {
  1788. // single threaded here
  1789. if (e == null)
  1790. {
  1791. return;
  1792. }
  1793. CollisionEventUpdate a = (CollisionEventUpdate)e;
  1794. Dictionary<uint, ContactPoint> collissionswith = a.m_objCollisionList;
  1795. List<uint> thisHitColliders = new List<uint>();
  1796. List<uint> endedColliders = new List<uint>();
  1797. List<uint> startedColliders = new List<uint>();
  1798. // calculate things that started colliding this time
  1799. // and build up list of colliders this time
  1800. foreach (uint localid in collissionswith.Keys)
  1801. {
  1802. thisHitColliders.Add(localid);
  1803. if (!m_lastColliders.Contains(localid))
  1804. {
  1805. startedColliders.Add(localid);
  1806. }
  1807. //m_log.Debug("[OBJECT]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
  1808. }
  1809. // calculate things that ended colliding
  1810. foreach (uint localID in m_lastColliders)
  1811. {
  1812. if (!thisHitColliders.Contains(localID))
  1813. {
  1814. endedColliders.Add(localID);
  1815. }
  1816. }
  1817. //add the items that started colliding this time to the last colliders list.
  1818. foreach (uint localID in startedColliders)
  1819. {
  1820. m_lastColliders.Add(localID);
  1821. }
  1822. // remove things that ended colliding from the last colliders list
  1823. foreach (uint localID in endedColliders)
  1824. {
  1825. m_lastColliders.Remove(localID);
  1826. }
  1827. if (m_parentGroup.IsDeleted)
  1828. return;
  1829. // play the sound.
  1830. if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f)
  1831. {
  1832. SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false);
  1833. }
  1834. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_start) != 0)
  1835. {
  1836. // do event notification
  1837. if (startedColliders.Count > 0)
  1838. {
  1839. ColliderArgs StartCollidingMessage = new ColliderArgs();
  1840. List<DetectedObject> colliding = new List<DetectedObject>();
  1841. foreach (uint localId in startedColliders)
  1842. {
  1843. if (localId == 0)
  1844. continue;
  1845. if (m_parentGroup.Scene == null)
  1846. return;
  1847. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1848. string data = "";
  1849. if (obj != null)
  1850. {
  1851. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
  1852. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  1853. {
  1854. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1855. //If it is 1, it is to accept ONLY collisions from this object
  1856. if (found)
  1857. {
  1858. DetectedObject detobj = new DetectedObject();
  1859. detobj.keyUUID = obj.UUID;
  1860. detobj.nameStr = obj.Name;
  1861. detobj.ownerUUID = obj._ownerID;
  1862. detobj.posVector = obj.AbsolutePosition;
  1863. detobj.rotQuat = obj.GetWorldRotation();
  1864. detobj.velVector = obj.Velocity;
  1865. detobj.colliderType = 0;
  1866. detobj.groupUUID = obj._groupID;
  1867. colliding.Add(detobj);
  1868. }
  1869. //If it is 0, it is to not accept collisions from this object
  1870. else
  1871. {
  1872. }
  1873. }
  1874. else
  1875. {
  1876. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1877. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  1878. if (!found)
  1879. {
  1880. DetectedObject detobj = new DetectedObject();
  1881. detobj.keyUUID = obj.UUID;
  1882. detobj.nameStr = obj.Name;
  1883. detobj.ownerUUID = obj._ownerID;
  1884. detobj.posVector = obj.AbsolutePosition;
  1885. detobj.rotQuat = obj.GetWorldRotation();
  1886. detobj.velVector = obj.Velocity;
  1887. detobj.colliderType = 0;
  1888. detobj.groupUUID = obj._groupID;
  1889. colliding.Add(detobj);
  1890. }
  1891. }
  1892. }
  1893. else
  1894. {
  1895. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  1896. {
  1897. if (av.LocalId == localId)
  1898. {
  1899. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  1900. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  1901. {
  1902. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  1903. //If it is 1, it is to accept ONLY collisions from this avatar
  1904. if (found)
  1905. {
  1906. DetectedObject detobj = new DetectedObject();
  1907. detobj.keyUUID = av.UUID;
  1908. detobj.nameStr = av.ControllingClient.Name;
  1909. detobj.ownerUUID = av.UUID;
  1910. detobj.posVector = av.AbsolutePosition;
  1911. detobj.rotQuat = av.Rotation;
  1912. detobj.velVector = av.Velocity;
  1913. detobj.colliderType = 0;
  1914. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1915. colliding.Add(detobj);
  1916. }
  1917. //If it is 0, it is to not accept collisions from this avatar
  1918. else
  1919. {
  1920. }
  1921. }
  1922. else
  1923. {
  1924. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  1925. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  1926. if (!found)
  1927. {
  1928. DetectedObject detobj = new DetectedObject();
  1929. detobj.keyUUID = av.UUID;
  1930. detobj.nameStr = av.ControllingClient.Name;
  1931. detobj.ownerUUID = av.UUID;
  1932. detobj.posVector = av.AbsolutePosition;
  1933. detobj.rotQuat = av.Rotation;
  1934. detobj.velVector = av.Velocity;
  1935. detobj.colliderType = 0;
  1936. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  1937. colliding.Add(detobj);
  1938. }
  1939. }
  1940. }
  1941. });
  1942. }
  1943. }
  1944. if (colliding.Count > 0)
  1945. {
  1946. StartCollidingMessage.Colliders = colliding;
  1947. if (m_parentGroup.Scene == null)
  1948. return;
  1949. if (m_parentGroup.PassCollision == true)
  1950. {
  1951. //TODO: Add pass to root prim!
  1952. }
  1953. m_parentGroup.Scene.EventManager.TriggerScriptCollidingStart(LocalId, StartCollidingMessage);
  1954. }
  1955. }
  1956. }
  1957. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision) != 0)
  1958. {
  1959. if (m_lastColliders.Count > 0)
  1960. {
  1961. ColliderArgs CollidingMessage = new ColliderArgs();
  1962. List<DetectedObject> colliding = new List<DetectedObject>();
  1963. foreach (uint localId in m_lastColliders)
  1964. {
  1965. // always running this check because if the user deletes the object it would return a null reference.
  1966. if (localId == 0)
  1967. continue;
  1968. if (m_parentGroup.Scene == null)
  1969. return;
  1970. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  1971. string data = "";
  1972. if (obj != null)
  1973. {
  1974. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString())
  1975. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  1976. {
  1977. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  1978. //If it is 1, it is to accept ONLY collisions from this object
  1979. if (found)
  1980. {
  1981. DetectedObject detobj = new DetectedObject();
  1982. detobj.keyUUID = obj.UUID;
  1983. detobj.nameStr = obj.Name;
  1984. detobj.ownerUUID = obj._ownerID;
  1985. detobj.posVector = obj.AbsolutePosition;
  1986. detobj.rotQuat = obj.GetWorldRotation();
  1987. detobj.velVector = obj.Velocity;
  1988. detobj.colliderType = 0;
  1989. detobj.groupUUID = obj._groupID;
  1990. colliding.Add(detobj);
  1991. }
  1992. //If it is 0, it is to not accept collisions from this object
  1993. else
  1994. {
  1995. }
  1996. }
  1997. else
  1998. {
  1999. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  2000. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  2001. if (!found)
  2002. {
  2003. DetectedObject detobj = new DetectedObject();
  2004. detobj.keyUUID = obj.UUID;
  2005. detobj.nameStr = obj.Name;
  2006. detobj.ownerUUID = obj._ownerID;
  2007. detobj.posVector = obj.AbsolutePosition;
  2008. detobj.rotQuat = obj.GetWorldRotation();
  2009. detobj.velVector = obj.Velocity;
  2010. detobj.colliderType = 0;
  2011. detobj.groupUUID = obj._groupID;
  2012. colliding.Add(detobj);
  2013. }
  2014. }
  2015. }
  2016. else
  2017. {
  2018. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  2019. {
  2020. if (av.LocalId == localId)
  2021. {
  2022. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  2023. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  2024. {
  2025. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2026. //If it is 1, it is to accept ONLY collisions from this avatar
  2027. if (found)
  2028. {
  2029. DetectedObject detobj = new DetectedObject();
  2030. detobj.keyUUID = av.UUID;
  2031. detobj.nameStr = av.ControllingClient.Name;
  2032. detobj.ownerUUID = av.UUID;
  2033. detobj.posVector = av.AbsolutePosition;
  2034. detobj.rotQuat = av.Rotation;
  2035. detobj.velVector = av.Velocity;
  2036. detobj.colliderType = 0;
  2037. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2038. colliding.Add(detobj);
  2039. }
  2040. //If it is 0, it is to not accept collisions from this avatar
  2041. else
  2042. {
  2043. }
  2044. }
  2045. else
  2046. {
  2047. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2048. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  2049. if (!found)
  2050. {
  2051. DetectedObject detobj = new DetectedObject();
  2052. detobj.keyUUID = av.UUID;
  2053. detobj.nameStr = av.ControllingClient.Name;
  2054. detobj.ownerUUID = av.UUID;
  2055. detobj.posVector = av.AbsolutePosition;
  2056. detobj.rotQuat = av.Rotation;
  2057. detobj.velVector = av.Velocity;
  2058. detobj.colliderType = 0;
  2059. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2060. colliding.Add(detobj);
  2061. }
  2062. }
  2063. }
  2064. });
  2065. }
  2066. }
  2067. if (colliding.Count > 0)
  2068. {
  2069. CollidingMessage.Colliders = colliding;
  2070. if (m_parentGroup.Scene == null)
  2071. return;
  2072. m_parentGroup.Scene.EventManager.TriggerScriptColliding(LocalId, CollidingMessage);
  2073. }
  2074. }
  2075. }
  2076. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.collision_end) != 0)
  2077. {
  2078. if (endedColliders.Count > 0)
  2079. {
  2080. ColliderArgs EndCollidingMessage = new ColliderArgs();
  2081. List<DetectedObject> colliding = new List<DetectedObject>();
  2082. foreach (uint localId in endedColliders)
  2083. {
  2084. if (localId == 0)
  2085. continue;
  2086. if (m_parentGroup.Scene == null)
  2087. return;
  2088. SceneObjectPart obj = m_parentGroup.Scene.GetSceneObjectPart(localId);
  2089. string data = "";
  2090. if (obj != null)
  2091. {
  2092. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.UUID.ToString()) || m_parentGroup.RootPart.CollisionFilter.ContainsValue(obj.Name))
  2093. {
  2094. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  2095. //If it is 1, it is to accept ONLY collisions from this object
  2096. if (found)
  2097. {
  2098. DetectedObject detobj = new DetectedObject();
  2099. detobj.keyUUID = obj.UUID;
  2100. detobj.nameStr = obj.Name;
  2101. detobj.ownerUUID = obj._ownerID;
  2102. detobj.posVector = obj.AbsolutePosition;
  2103. detobj.rotQuat = obj.GetWorldRotation();
  2104. detobj.velVector = obj.Velocity;
  2105. detobj.colliderType = 0;
  2106. detobj.groupUUID = obj._groupID;
  2107. colliding.Add(detobj);
  2108. }
  2109. //If it is 0, it is to not accept collisions from this object
  2110. else
  2111. {
  2112. }
  2113. }
  2114. else
  2115. {
  2116. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1,out data);
  2117. //If it is 1, it is to accept ONLY collisions from this object, so this other object will not work
  2118. if (!found)
  2119. {
  2120. DetectedObject detobj = new DetectedObject();
  2121. detobj.keyUUID = obj.UUID;
  2122. detobj.nameStr = obj.Name;
  2123. detobj.ownerUUID = obj._ownerID;
  2124. detobj.posVector = obj.AbsolutePosition;
  2125. detobj.rotQuat = obj.GetWorldRotation();
  2126. detobj.velVector = obj.Velocity;
  2127. detobj.colliderType = 0;
  2128. detobj.groupUUID = obj._groupID;
  2129. colliding.Add(detobj);
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence av)
  2136. {
  2137. if (av.LocalId == localId)
  2138. {
  2139. if (m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.UUID.ToString())
  2140. || m_parentGroup.RootPart.CollisionFilter.ContainsValue(av.Name))
  2141. {
  2142. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2143. //If it is 1, it is to accept ONLY collisions from this avatar
  2144. if (found)
  2145. {
  2146. DetectedObject detobj = new DetectedObject();
  2147. detobj.keyUUID = av.UUID;
  2148. detobj.nameStr = av.ControllingClient.Name;
  2149. detobj.ownerUUID = av.UUID;
  2150. detobj.posVector = av.AbsolutePosition;
  2151. detobj.rotQuat = av.Rotation;
  2152. detobj.velVector = av.Velocity;
  2153. detobj.colliderType = 0;
  2154. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2155. colliding.Add(detobj);
  2156. }
  2157. //If it is 0, it is to not accept collisions from this avatar
  2158. else
  2159. {
  2160. }
  2161. }
  2162. else
  2163. {
  2164. bool found = m_parentGroup.RootPart.CollisionFilter.TryGetValue(1, out data);
  2165. //If it is 1, it is to accept ONLY collisions from this avatar, so this other avatar will not work
  2166. if (!found)
  2167. {
  2168. DetectedObject detobj = new DetectedObject();
  2169. detobj.keyUUID = av.UUID;
  2170. detobj.nameStr = av.ControllingClient.Name;
  2171. detobj.ownerUUID = av.UUID;
  2172. detobj.posVector = av.AbsolutePosition;
  2173. detobj.rotQuat = av.Rotation;
  2174. detobj.velVector = av.Velocity;
  2175. detobj.colliderType = 0;
  2176. detobj.groupUUID = av.ControllingClient.ActiveGroupId;
  2177. colliding.Add(detobj);
  2178. }
  2179. }
  2180. }
  2181. });
  2182. }
  2183. }
  2184. if (colliding.Count > 0)
  2185. {
  2186. EndCollidingMessage.Colliders = colliding;
  2187. if (m_parentGroup.Scene == null)
  2188. return;
  2189. m_parentGroup.Scene.EventManager.TriggerScriptCollidingEnd(LocalId, EndCollidingMessage);
  2190. }
  2191. }
  2192. }
  2193. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_start) != 0)
  2194. {
  2195. if (startedColliders.Count > 0)
  2196. {
  2197. ColliderArgs LandStartCollidingMessage = new ColliderArgs();
  2198. List<DetectedObject> colliding = new List<DetectedObject>();
  2199. foreach (uint localId in startedColliders)
  2200. {
  2201. if (localId == 0)
  2202. {
  2203. //Hope that all is left is ground!
  2204. DetectedObject detobj = new DetectedObject();
  2205. detobj.keyUUID = UUID.Zero;
  2206. detobj.nameStr = "";
  2207. detobj.ownerUUID = UUID.Zero;
  2208. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2209. detobj.rotQuat = Quaternion.Identity;
  2210. detobj.velVector = Vector3.Zero;
  2211. detobj.colliderType = 0;
  2212. detobj.groupUUID = UUID.Zero;
  2213. colliding.Add(detobj);
  2214. }
  2215. }
  2216. if (colliding.Count > 0)
  2217. {
  2218. LandStartCollidingMessage.Colliders = colliding;
  2219. if (m_parentGroup.Scene == null)
  2220. return;
  2221. m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingStart(LocalId, LandStartCollidingMessage);
  2222. }
  2223. }
  2224. }
  2225. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision) != 0)
  2226. {
  2227. if (m_lastColliders.Count > 0)
  2228. {
  2229. ColliderArgs LandCollidingMessage = new ColliderArgs();
  2230. List<DetectedObject> colliding = new List<DetectedObject>();
  2231. foreach (uint localId in startedColliders)
  2232. {
  2233. if (localId == 0)
  2234. {
  2235. //Hope that all is left is ground!
  2236. DetectedObject detobj = new DetectedObject();
  2237. detobj.keyUUID = UUID.Zero;
  2238. detobj.nameStr = "";
  2239. detobj.ownerUUID = UUID.Zero;
  2240. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2241. detobj.rotQuat = Quaternion.Identity;
  2242. detobj.velVector = Vector3.Zero;
  2243. detobj.colliderType = 0;
  2244. detobj.groupUUID = UUID.Zero;
  2245. colliding.Add(detobj);
  2246. }
  2247. }
  2248. if (colliding.Count > 0)
  2249. {
  2250. LandCollidingMessage.Colliders = colliding;
  2251. if (m_parentGroup.Scene == null)
  2252. return;
  2253. m_parentGroup.Scene.EventManager.TriggerScriptLandColliding(LocalId, LandCollidingMessage);
  2254. }
  2255. }
  2256. }
  2257. if ((m_parentGroup.RootPart.ScriptEvents & scriptEvents.land_collision_end) != 0)
  2258. {
  2259. if (endedColliders.Count > 0)
  2260. {
  2261. ColliderArgs LandEndCollidingMessage = new ColliderArgs();
  2262. List<DetectedObject> colliding = new List<DetectedObject>();
  2263. foreach (uint localId in startedColliders)
  2264. {
  2265. if (localId == 0)
  2266. {
  2267. //Hope that all is left is ground!
  2268. DetectedObject detobj = new DetectedObject();
  2269. detobj.keyUUID = UUID.Zero;
  2270. detobj.nameStr = "";
  2271. detobj.ownerUUID = UUID.Zero;
  2272. detobj.posVector = m_parentGroup.RootPart.AbsolutePosition;
  2273. detobj.rotQuat = Quaternion.Identity;
  2274. detobj.velVector = Vector3.Zero;
  2275. detobj.colliderType = 0;
  2276. detobj.groupUUID = UUID.Zero;
  2277. colliding.Add(detobj);
  2278. }
  2279. }
  2280. if (colliding.Count > 0)
  2281. {
  2282. LandEndCollidingMessage.Colliders = colliding;
  2283. if (m_parentGroup.Scene == null)
  2284. return;
  2285. m_parentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd(LocalId, LandEndCollidingMessage);
  2286. }
  2287. }
  2288. }
  2289. }
  2290. public void PhysicsOutOfBounds(Vector3 pos)
  2291. {
  2292. m_log.Error("[PHYSICS]: Physical Object went out of bounds.");
  2293. RemFlag(PrimFlags.Physics);
  2294. DoPhysicsPropertyUpdate(false, true);
  2295. //m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2296. }
  2297. public void PhysicsRequestingTerseUpdate()
  2298. {
  2299. if (PhysActor != null)
  2300. {
  2301. Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0);
  2302. if (m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
  2303. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
  2304. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
  2305. | m_parentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
  2306. {
  2307. m_parentGroup.AbsolutePosition = newpos;
  2308. return;
  2309. }
  2310. //m_parentGroup.RootPart.m_groupPosition = newpos;
  2311. }
  2312. ScheduleTerseUpdate();
  2313. //SendTerseUpdateToAllClients();
  2314. }
  2315. public void PreloadSound(string sound)
  2316. {
  2317. // UUID ownerID = OwnerID;
  2318. UUID objectID = ParentGroup.RootPart.UUID;
  2319. UUID soundID = UUID.Zero;
  2320. if (!UUID.TryParse(sound, out soundID))
  2321. {
  2322. //Trys to fetch sound id from prim's inventory.
  2323. //Prim's inventory doesn't support non script items yet
  2324. lock (TaskInventory)
  2325. {
  2326. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  2327. {
  2328. if (item.Value.Name == sound)
  2329. {
  2330. soundID = item.Value.ItemID;
  2331. break;
  2332. }
  2333. }
  2334. }
  2335. }
  2336. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence sp)
  2337. {
  2338. if (sp.IsChildAgent)
  2339. return;
  2340. if (!(Util.GetDistanceTo(sp.AbsolutePosition, AbsolutePosition) >= 100))
  2341. sp.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  2342. });
  2343. }
  2344. public void RemFlag(PrimFlags flag)
  2345. {
  2346. // PrimFlags prevflag = Flags;
  2347. if ((Flags & flag) != 0)
  2348. {
  2349. //m_log.Debug("Removing flag: " + ((PrimFlags)flag).ToString());
  2350. Flags &= ~flag;
  2351. }
  2352. //m_log.Debug("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  2353. //ScheduleFullUpdate();
  2354. }
  2355. public void RemoveScriptEvents(UUID scriptid)
  2356. {
  2357. lock (m_scriptEvents)
  2358. {
  2359. if (m_scriptEvents.ContainsKey(scriptid))
  2360. {
  2361. scriptEvents oldparts = scriptEvents.None;
  2362. oldparts = (scriptEvents) m_scriptEvents[scriptid];
  2363. // remove values from aggregated script events
  2364. AggregateScriptEvents &= ~oldparts;
  2365. m_scriptEvents.Remove(scriptid);
  2366. aggregateScriptEvents();
  2367. }
  2368. }
  2369. }
  2370. /// <summary>
  2371. /// Reset UUIDs for this part. This involves generate this part's own UUID and
  2372. /// generating new UUIDs for all the items in the inventory.
  2373. /// </summary>
  2374. /// <param name="linkNum">Link number for the part</param>
  2375. public void ResetIDs(int linkNum)
  2376. {
  2377. UUID = UUID.Random();
  2378. LinkNum = linkNum;
  2379. LocalId = 0;
  2380. Inventory.ResetInventoryIDs();
  2381. }
  2382. /// <summary>
  2383. /// Set the scale of this part.
  2384. /// </summary>
  2385. /// <remarks>
  2386. /// Unlike the scale property, this checks the new size against scene limits and schedules a full property
  2387. /// update to viewers.
  2388. /// </remarks>
  2389. /// <param name="scale"></param>
  2390. public void Resize(Vector3 scale)
  2391. {
  2392. scale.X = Math.Min(scale.X, ParentGroup.Scene.m_maxNonphys);
  2393. scale.Y = Math.Min(scale.Y, ParentGroup.Scene.m_maxNonphys);
  2394. scale.Z = Math.Min(scale.Z, ParentGroup.Scene.m_maxNonphys);
  2395. if (PhysActor != null && PhysActor.IsPhysical)
  2396. {
  2397. scale.X = Math.Min(scale.X, ParentGroup.Scene.m_maxPhys);
  2398. scale.Y = Math.Min(scale.Y, ParentGroup.Scene.m_maxPhys);
  2399. scale.Z = Math.Min(scale.Z, ParentGroup.Scene.m_maxPhys);
  2400. }
  2401. // m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale);
  2402. Scale = scale;
  2403. ParentGroup.HasGroupChanged = true;
  2404. ScheduleFullUpdate();
  2405. }
  2406. public void RotLookAt(Quaternion target, float strength, float damping)
  2407. {
  2408. rotLookAt(target, strength, damping);
  2409. }
  2410. public void rotLookAt(Quaternion target, float strength, float damping)
  2411. {
  2412. if (m_parentGroup.IsAttachment)
  2413. {
  2414. /*
  2415. ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
  2416. if (avatar != null)
  2417. {
  2418. Rotate the Av?
  2419. } */
  2420. }
  2421. else
  2422. {
  2423. APIDDamp = damping;
  2424. APIDStrength = strength;
  2425. APIDTarget = target;
  2426. }
  2427. }
  2428. public void startLookAt(Quaternion rot, float damp, float strength)
  2429. {
  2430. APIDDamp = damp;
  2431. APIDStrength = strength;
  2432. APIDTarget = rot;
  2433. }
  2434. public void stopLookAt()
  2435. {
  2436. APIDTarget = Quaternion.Identity;
  2437. }
  2438. /// <summary>
  2439. /// Schedules this prim for a full update
  2440. /// </summary>
  2441. public void ScheduleFullUpdate()
  2442. {
  2443. // m_log.DebugFormat("[SCENE OBJECT PART]: Scheduling full update for {0} {1}", Name, LocalId);
  2444. if (m_parentGroup == null)
  2445. return;
  2446. m_parentGroup.QueueForUpdateCheck();
  2447. int timeNow = Util.UnixTimeSinceEpoch();
  2448. // If multiple updates are scheduled on the same second, we still need to perform all of them
  2449. // So we'll force the issue by bumping up the timestamp so that later processing sees these need
  2450. // to be performed.
  2451. if (timeNow <= TimeStampFull)
  2452. {
  2453. TimeStampFull += 1;
  2454. }
  2455. else
  2456. {
  2457. TimeStampFull = (uint)timeNow;
  2458. }
  2459. m_updateFlag = 2;
  2460. // m_log.DebugFormat(
  2461. // "[SCENE OBJECT PART]: Scheduling full update for {0}, {1} at {2}",
  2462. // UUID, Name, TimeStampFull);
  2463. }
  2464. /// <summary>
  2465. /// Schedule a terse update for this prim. Terse updates only send position,
  2466. /// rotation, velocity, rotational velocity and shape information.
  2467. /// </summary>
  2468. public void ScheduleTerseUpdate()
  2469. {
  2470. if (m_parentGroup == null)
  2471. return;
  2472. if (m_updateFlag < 1)
  2473. {
  2474. m_parentGroup.HasGroupChanged = true;
  2475. m_parentGroup.QueueForUpdateCheck();
  2476. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  2477. m_updateFlag = 1;
  2478. // m_log.DebugFormat(
  2479. // "[SCENE OBJECT PART]: Scheduling terse update for {0}, {1} at {2}",
  2480. // UUID, Name, TimeStampTerse);
  2481. }
  2482. }
  2483. public void ScriptSetPhysicsStatus(bool UsePhysics)
  2484. {
  2485. m_parentGroup.ScriptSetPhysicsStatus(UsePhysics);
  2486. }
  2487. /// <summary>
  2488. /// Set sculpt and mesh data, and tell the physics engine to process the change.
  2489. /// </summary>
  2490. /// <param name="texture">The mesh itself.</param>
  2491. public void SculptTextureCallback(AssetBase texture)
  2492. {
  2493. if (m_shape.SculptEntry)
  2494. {
  2495. // commented out for sculpt map caching test - null could mean a cached sculpt map has been found
  2496. //if (texture != null)
  2497. {
  2498. if (texture != null)
  2499. {
  2500. // m_log.DebugFormat(
  2501. // "[SCENE OBJECT PART]: Setting sculpt data for {0} on SculptTextureCallback()", Name);
  2502. m_shape.SculptData = texture.Data;
  2503. }
  2504. if (PhysActor != null)
  2505. {
  2506. // Update the physics actor with the new loaded sculpt data and set the taint signal.
  2507. PhysActor.Shape = m_shape;
  2508. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2509. }
  2510. }
  2511. }
  2512. }
  2513. /// <summary>
  2514. /// Send a full update to the client for the given part
  2515. /// </summary>
  2516. /// <param name="remoteClient"></param>
  2517. /// <param name="clientFlags"></param>
  2518. protected internal void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  2519. {
  2520. if (m_parentGroup == null)
  2521. return;
  2522. // m_log.DebugFormat(
  2523. // "[SOG]: Sendinging part full update to {0} for {1} {2}", remoteClient.Name, part.Name, part.LocalId);
  2524. if (IsRoot)
  2525. {
  2526. if (m_parentGroup.IsAttachment)
  2527. {
  2528. SendFullUpdateToClient(remoteClient, AttachedPos, clientFlags);
  2529. }
  2530. else
  2531. {
  2532. SendFullUpdateToClient(remoteClient, AbsolutePosition, clientFlags);
  2533. }
  2534. }
  2535. else
  2536. {
  2537. SendFullUpdateToClient(remoteClient, clientFlags);
  2538. }
  2539. }
  2540. /// <summary>
  2541. /// Send a full update for this part to all clients.
  2542. /// </summary>
  2543. public void SendFullUpdateToAllClients()
  2544. {
  2545. if (m_parentGroup == null)
  2546. return;
  2547. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2548. {
  2549. SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
  2550. });
  2551. }
  2552. /// <summary>
  2553. /// Send a full update to all clients except the one nominated.
  2554. /// </summary>
  2555. /// <param name="agentID"></param>
  2556. public void SendFullUpdateToAllClientsExcept(UUID agentID)
  2557. {
  2558. if (m_parentGroup == null)
  2559. return;
  2560. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2561. {
  2562. // Ugly reference :(
  2563. if (avatar.UUID != agentID)
  2564. SendFullUpdate(avatar.ControllingClient, avatar.GenerateClientFlags(UUID));
  2565. });
  2566. }
  2567. /// <summary>
  2568. /// Sends a full update to the client
  2569. /// </summary>
  2570. /// <param name="remoteClient"></param>
  2571. /// <param name="clientFlags"></param>
  2572. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  2573. {
  2574. Vector3 lPos;
  2575. lPos = OffsetPosition;
  2576. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  2577. }
  2578. /// <summary>
  2579. /// Sends a full update to the client
  2580. /// </summary>
  2581. /// <param name="remoteClient"></param>
  2582. /// <param name="lPos"></param>
  2583. /// <param name="clientFlags"></param>
  2584. public void SendFullUpdateToClient(IClientAPI remoteClient, Vector3 lPos, uint clientFlags)
  2585. {
  2586. if (ParentGroup == null)
  2587. return;
  2588. // Suppress full updates during attachment editing
  2589. //
  2590. if (ParentGroup.IsSelected && ParentGroup.IsAttachment)
  2591. return;
  2592. if (ParentGroup.IsDeleted)
  2593. return;
  2594. clientFlags &= ~(uint) PrimFlags.CreateSelected;
  2595. if (remoteClient.AgentId == _ownerID)
  2596. {
  2597. if ((Flags & PrimFlags.CreateSelected) != 0)
  2598. {
  2599. clientFlags |= (uint) PrimFlags.CreateSelected;
  2600. Flags &= ~PrimFlags.CreateSelected;
  2601. }
  2602. }
  2603. //bool isattachment = IsAttachment;
  2604. //if (LocalId != ParentGroup.RootPart.LocalId)
  2605. //isattachment = ParentGroup.RootPart.IsAttachment;
  2606. remoteClient.SendPrimUpdate(this, PrimUpdateFlags.FullUpdate);
  2607. }
  2608. /// <summary>
  2609. /// Tell all the prims which have had updates scheduled
  2610. /// </summary>
  2611. public void SendScheduledUpdates()
  2612. {
  2613. const float ROTATION_TOLERANCE = 0.01f;
  2614. const float VELOCITY_TOLERANCE = 0.001f;
  2615. const float POSITION_TOLERANCE = 0.05f;
  2616. const int TIME_MS_TOLERANCE = 3000;
  2617. if (m_updateFlag == 1)
  2618. {
  2619. // Throw away duplicate or insignificant updates
  2620. if (!RotationOffset.ApproxEquals(m_lastRotation, ROTATION_TOLERANCE) ||
  2621. !Acceleration.Equals(m_lastAcceleration) ||
  2622. !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) ||
  2623. Velocity.ApproxEquals(Vector3.Zero, VELOCITY_TOLERANCE) ||
  2624. !AngularVelocity.ApproxEquals(m_lastAngularVelocity, VELOCITY_TOLERANCE) ||
  2625. !OffsetPosition.ApproxEquals(m_lastPosition, POSITION_TOLERANCE) ||
  2626. Environment.TickCount - m_lastTerseSent > TIME_MS_TOLERANCE)
  2627. {
  2628. AddTerseUpdateToAllAvatars();
  2629. ClearUpdateSchedule();
  2630. // This causes the Scene to 'poll' physical objects every couple of frames
  2631. // bad, so it's been replaced by an event driven method.
  2632. //if ((ObjectFlags & (uint)PrimFlags.Physics) != 0)
  2633. //{
  2634. // Only send the constant terse updates on physical objects!
  2635. //ScheduleTerseUpdate();
  2636. //}
  2637. // Update the "last" values
  2638. m_lastPosition = OffsetPosition;
  2639. m_lastRotation = RotationOffset;
  2640. m_lastVelocity = Velocity;
  2641. m_lastAcceleration = Acceleration;
  2642. m_lastAngularVelocity = AngularVelocity;
  2643. m_lastTerseSent = Environment.TickCount;
  2644. }
  2645. }
  2646. else
  2647. {
  2648. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  2649. {
  2650. AddFullUpdateToAllAvatars();
  2651. ClearUpdateSchedule();
  2652. }
  2653. }
  2654. ClearUpdateSchedule();
  2655. }
  2656. /// <summary>
  2657. /// Trigger or play an attached sound in this part's inventory.
  2658. /// </summary>
  2659. /// <param name="sound"></param>
  2660. /// <param name="volume"></param>
  2661. /// <param name="triggered"></param>
  2662. /// <param name="flags"></param>
  2663. public void SendSound(string sound, double volume, bool triggered, byte flags, float radius, bool useMaster, bool isMaster)
  2664. {
  2665. if (volume > 1)
  2666. volume = 1;
  2667. if (volume < 0)
  2668. volume = 0;
  2669. UUID ownerID = _ownerID;
  2670. UUID objectID = ParentGroup.RootPart.UUID;
  2671. UUID parentID = ParentGroup.UUID;
  2672. UUID soundID = UUID.Zero;
  2673. Vector3 position = AbsolutePosition; // region local
  2674. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  2675. if (!UUID.TryParse(sound, out soundID))
  2676. {
  2677. // search sound file from inventory
  2678. lock (TaskInventory)
  2679. {
  2680. foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
  2681. {
  2682. if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
  2683. {
  2684. soundID = item.Value.ItemID;
  2685. break;
  2686. }
  2687. }
  2688. }
  2689. }
  2690. if (soundID == UUID.Zero)
  2691. return;
  2692. ISoundModule soundModule = m_parentGroup.Scene.RequestModuleInterface<ISoundModule>();
  2693. if (soundModule != null)
  2694. {
  2695. if (useMaster)
  2696. {
  2697. if (isMaster)
  2698. {
  2699. if (triggered)
  2700. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2701. else
  2702. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2703. ParentGroup.PlaySoundMasterPrim = this;
  2704. ownerID = _ownerID;
  2705. objectID = ParentGroup.RootPart.UUID;
  2706. parentID = ParentGroup.UUID;
  2707. position = AbsolutePosition; // region local
  2708. regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
  2709. if (triggered)
  2710. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2711. else
  2712. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2713. foreach (SceneObjectPart prim in ParentGroup.PlaySoundSlavePrims)
  2714. {
  2715. ownerID = prim._ownerID;
  2716. objectID = prim.ParentGroup.RootPart.UUID;
  2717. parentID = prim.ParentGroup.UUID;
  2718. position = prim.AbsolutePosition; // region local
  2719. regionHandle = prim.ParentGroup.Scene.RegionInfo.RegionHandle;
  2720. if (triggered)
  2721. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2722. else
  2723. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2724. }
  2725. ParentGroup.PlaySoundSlavePrims.Clear();
  2726. ParentGroup.PlaySoundMasterPrim = null;
  2727. }
  2728. else
  2729. {
  2730. ParentGroup.PlaySoundSlavePrims.Add(this);
  2731. }
  2732. }
  2733. else
  2734. {
  2735. if (triggered)
  2736. soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, radius);
  2737. else
  2738. soundModule.PlayAttachedSound(soundID, ownerID, objectID, volume, position, flags, radius);
  2739. }
  2740. }
  2741. }
  2742. /// <summary>
  2743. /// Send a terse update to all clients
  2744. /// </summary>
  2745. public void SendTerseUpdateToAllClients()
  2746. {
  2747. m_parentGroup.Scene.ForEachScenePresence(delegate(ScenePresence avatar)
  2748. {
  2749. SendTerseUpdateToClient(avatar.ControllingClient);
  2750. });
  2751. }
  2752. public void SetAxisRotation(int axis, int rotate)
  2753. {
  2754. m_parentGroup.SetAxisRotation(axis, rotate);
  2755. //Cannot use ScriptBaseClass constants as no referance to it currently.
  2756. if (axis == 2)//STATUS_ROTATE_X
  2757. STATUS_ROTATE_X = rotate;
  2758. if (axis == 4)//STATUS_ROTATE_Y
  2759. STATUS_ROTATE_Y = rotate;
  2760. if (axis == 8)//STATUS_ROTATE_Z
  2761. STATUS_ROTATE_Z = rotate;
  2762. }
  2763. public void SetBuoyancy(float fvalue)
  2764. {
  2765. if (PhysActor != null)
  2766. {
  2767. PhysActor.Buoyancy = fvalue;
  2768. }
  2769. }
  2770. public void SetDieAtEdge(bool p)
  2771. {
  2772. if (m_parentGroup.IsDeleted)
  2773. return;
  2774. m_parentGroup.RootPart.DIE_AT_EDGE = p;
  2775. }
  2776. public void SetFloatOnWater(int floatYN)
  2777. {
  2778. if (PhysActor != null)
  2779. {
  2780. if (floatYN == 1)
  2781. {
  2782. PhysActor.FloatOnWater = true;
  2783. }
  2784. else
  2785. {
  2786. PhysActor.FloatOnWater = false;
  2787. }
  2788. }
  2789. }
  2790. public void SetForce(Vector3 force)
  2791. {
  2792. if (PhysActor != null)
  2793. {
  2794. PhysActor.Force = force;
  2795. }
  2796. }
  2797. public void SetVehicleType(int type)
  2798. {
  2799. if (PhysActor != null)
  2800. {
  2801. PhysActor.VehicleType = type;
  2802. }
  2803. }
  2804. public void SetVehicleFloatParam(int param, float value)
  2805. {
  2806. if (PhysActor != null)
  2807. {
  2808. PhysActor.VehicleFloatParam(param, value);
  2809. }
  2810. }
  2811. public void SetVehicleVectorParam(int param, Vector3 value)
  2812. {
  2813. if (PhysActor != null)
  2814. {
  2815. PhysActor.VehicleVectorParam(param, value);
  2816. }
  2817. }
  2818. public void SetVehicleRotationParam(int param, Quaternion rotation)
  2819. {
  2820. if (PhysActor != null)
  2821. {
  2822. PhysActor.VehicleRotationParam(param, rotation);
  2823. }
  2824. }
  2825. /// <summary>
  2826. /// Set the color of prim faces
  2827. /// </summary>
  2828. /// <param name="color"></param>
  2829. /// <param name="face"></param>
  2830. public void SetFaceColor(Vector3 color, int face)
  2831. {
  2832. Primitive.TextureEntry tex = Shape.Textures;
  2833. Color4 texcolor;
  2834. if (face >= 0 && face < GetNumberOfSides())
  2835. {
  2836. texcolor = tex.CreateFace((uint)face).RGBA;
  2837. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2838. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2839. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2840. tex.FaceTextures[face].RGBA = texcolor;
  2841. UpdateTexture(tex);
  2842. TriggerScriptChangedEvent(Changed.COLOR);
  2843. return;
  2844. }
  2845. else if (face == ALL_SIDES)
  2846. {
  2847. for (uint i = 0; i < GetNumberOfSides(); i++)
  2848. {
  2849. if (tex.FaceTextures[i] != null)
  2850. {
  2851. texcolor = tex.FaceTextures[i].RGBA;
  2852. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2853. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2854. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2855. tex.FaceTextures[i].RGBA = texcolor;
  2856. }
  2857. texcolor = tex.DefaultTexture.RGBA;
  2858. texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
  2859. texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
  2860. texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
  2861. tex.DefaultTexture.RGBA = texcolor;
  2862. }
  2863. UpdateTexture(tex);
  2864. TriggerScriptChangedEvent(Changed.COLOR);
  2865. return;
  2866. }
  2867. }
  2868. /// <summary>
  2869. /// Get the number of sides that this part has.
  2870. /// </summary>
  2871. /// <returns></returns>
  2872. public int GetNumberOfSides()
  2873. {
  2874. int ret = 0;
  2875. bool hasCut;
  2876. bool hasHollow;
  2877. bool hasDimple;
  2878. bool hasProfileCut;
  2879. PrimType primType = GetPrimType();
  2880. HasCutHollowDimpleProfileCut(primType, Shape, out hasCut, out hasHollow, out hasDimple, out hasProfileCut);
  2881. switch (primType)
  2882. {
  2883. case PrimType.BOX:
  2884. ret = 6;
  2885. if (hasCut) ret += 2;
  2886. if (hasHollow) ret += 1;
  2887. break;
  2888. case PrimType.CYLINDER:
  2889. ret = 3;
  2890. if (hasCut) ret += 2;
  2891. if (hasHollow) ret += 1;
  2892. break;
  2893. case PrimType.PRISM:
  2894. ret = 5;
  2895. if (hasCut) ret += 2;
  2896. if (hasHollow) ret += 1;
  2897. break;
  2898. case PrimType.SPHERE:
  2899. ret = 1;
  2900. if (hasCut) ret += 2;
  2901. if (hasDimple) ret += 2;
  2902. if (hasHollow) ret += 1;
  2903. break;
  2904. case PrimType.TORUS:
  2905. ret = 1;
  2906. if (hasCut) ret += 2;
  2907. if (hasProfileCut) ret += 2;
  2908. if (hasHollow) ret += 1;
  2909. break;
  2910. case PrimType.TUBE:
  2911. ret = 4;
  2912. if (hasCut) ret += 2;
  2913. if (hasProfileCut) ret += 2;
  2914. if (hasHollow) ret += 1;
  2915. break;
  2916. case PrimType.RING:
  2917. ret = 3;
  2918. if (hasCut) ret += 2;
  2919. if (hasProfileCut) ret += 2;
  2920. if (hasHollow) ret += 1;
  2921. break;
  2922. case PrimType.SCULPT:
  2923. ret = 1;
  2924. break;
  2925. }
  2926. return ret;
  2927. }
  2928. /// <summary>
  2929. /// Tell us what type this prim is
  2930. /// </summary>
  2931. /// <param name="primShape"></param>
  2932. /// <returns></returns>
  2933. public PrimType GetPrimType()
  2934. {
  2935. if (Shape.SculptEntry)
  2936. return PrimType.SCULPT;
  2937. if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
  2938. {
  2939. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2940. return PrimType.BOX;
  2941. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2942. return PrimType.TUBE;
  2943. }
  2944. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
  2945. {
  2946. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2947. return PrimType.CYLINDER;
  2948. // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
  2949. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2950. return PrimType.TORUS;
  2951. }
  2952. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
  2953. {
  2954. if (Shape.PathCurve == (byte)Extrusion.Curve1 || Shape.PathCurve == (byte)Extrusion.Curve2)
  2955. return PrimType.SPHERE;
  2956. }
  2957. else if ((Shape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
  2958. {
  2959. if (Shape.PathCurve == (byte)Extrusion.Straight)
  2960. return PrimType.PRISM;
  2961. else if (Shape.PathCurve == (byte)Extrusion.Curve1)
  2962. return PrimType.RING;
  2963. }
  2964. return PrimType.BOX;
  2965. }
  2966. /// <summary>
  2967. /// Tell us if this object has cut, hollow, dimple, and other factors affecting the number of faces
  2968. /// </summary>
  2969. /// <param name="primType"></param>
  2970. /// <param name="shape"></param>
  2971. /// <param name="hasCut"></param>
  2972. /// <param name="hasHollow"></param>
  2973. /// <param name="hasDimple"></param>
  2974. /// <param name="hasProfileCut"></param>
  2975. protected static void HasCutHollowDimpleProfileCut(PrimType primType, PrimitiveBaseShape shape, out bool hasCut, out bool hasHollow,
  2976. out bool hasDimple, out bool hasProfileCut)
  2977. {
  2978. if (primType == PrimType.BOX
  2979. ||
  2980. primType == PrimType.CYLINDER
  2981. ||
  2982. primType == PrimType.PRISM)
  2983. hasCut = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0);
  2984. else
  2985. hasCut = (shape.PathBegin > 0) || (shape.PathEnd > 0);
  2986. hasHollow = shape.ProfileHollow > 0;
  2987. hasDimple = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); // taken from llSetPrimitiveParms
  2988. hasProfileCut = hasDimple; // is it the same thing?
  2989. }
  2990. public void SetVehicleFlags(int param, bool remove)
  2991. {
  2992. if (PhysActor != null)
  2993. {
  2994. PhysActor.VehicleFlags(param, remove);
  2995. }
  2996. }
  2997. public void SetGroup(UUID groupID, IClientAPI client)
  2998. {
  2999. _groupID = groupID;
  3000. if (client != null)
  3001. SendPropertiesToClient(client);
  3002. m_updateFlag = 2;
  3003. }
  3004. /// <summary>
  3005. /// Set the parent group of this prim.
  3006. /// </summary>
  3007. public void SetParent(SceneObjectGroup parent)
  3008. {
  3009. m_parentGroup = parent;
  3010. }
  3011. // Use this for attachments! LocalID should be avatar's localid
  3012. public void SetParentLocalId(uint localID)
  3013. {
  3014. _parentID = localID;
  3015. }
  3016. public void SetPhysicsAxisRotation()
  3017. {
  3018. if (PhysActor != null)
  3019. {
  3020. PhysActor.LockAngularMotion(RotationAxis);
  3021. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  3022. }
  3023. }
  3024. /// <summary>
  3025. /// Set the events that this part will pass on to listeners.
  3026. /// </summary>
  3027. /// <param name="scriptid"></param>
  3028. /// <param name="events"></param>
  3029. public void SetScriptEvents(UUID scriptid, int events)
  3030. {
  3031. // scriptEvents oldparts;
  3032. lock (m_scriptEvents)
  3033. {
  3034. if (m_scriptEvents.ContainsKey(scriptid))
  3035. {
  3036. // oldparts = m_scriptEvents[scriptid];
  3037. // remove values from aggregated script events
  3038. if (m_scriptEvents[scriptid] == (scriptEvents) events)
  3039. return;
  3040. m_scriptEvents[scriptid] = (scriptEvents) events;
  3041. }
  3042. else
  3043. {
  3044. m_scriptEvents.Add(scriptid, (scriptEvents) events);
  3045. }
  3046. }
  3047. aggregateScriptEvents();
  3048. }
  3049. /// <summary>
  3050. /// Set the text displayed for this part.
  3051. /// </summary>
  3052. /// <param name="text"></param>
  3053. public void SetText(string text)
  3054. {
  3055. Text = text;
  3056. if (ParentGroup != null)
  3057. {
  3058. ParentGroup.HasGroupChanged = true;
  3059. ScheduleFullUpdate();
  3060. }
  3061. }
  3062. public void StopLookAt()
  3063. {
  3064. m_parentGroup.stopLookAt();
  3065. m_parentGroup.ScheduleGroupForTerseUpdate();
  3066. }
  3067. /// <summary>
  3068. /// Set the text displayed for this part.
  3069. /// </summary>
  3070. /// <param name="text"></param>
  3071. /// <param name="color"></param>
  3072. /// <param name="alpha"></param>
  3073. public void SetText(string text, Vector3 color, double alpha)
  3074. {
  3075. Color = Color.FromArgb((int) (alpha*0xff),
  3076. (int) (color.X*0xff),
  3077. (int) (color.Y*0xff),
  3078. (int) (color.Z*0xff));
  3079. SetText(text);
  3080. }
  3081. public void StopMoveToTarget()
  3082. {
  3083. m_parentGroup.stopMoveToTarget();
  3084. m_parentGroup.ScheduleGroupForTerseUpdate();
  3085. //m_parentGroup.ScheduleGroupForFullUpdate();
  3086. }
  3087. public void StoreUndoState()
  3088. {
  3089. StoreUndoState(false);
  3090. }
  3091. public void StoreUndoState(bool forGroup)
  3092. {
  3093. if (!Undoing)
  3094. {
  3095. if (!IgnoreUndoUpdate)
  3096. {
  3097. if (ParentGroup != null)
  3098. {
  3099. lock (m_undo)
  3100. {
  3101. if (m_undo.Count > 0)
  3102. {
  3103. UndoState last = m_undo.Peek();
  3104. if (last != null)
  3105. {
  3106. // TODO: May need to fix for group comparison
  3107. if (last.Compare(this))
  3108. {
  3109. // m_log.DebugFormat(
  3110. // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
  3111. // Name, LocalId, m_undo.Count);
  3112. return;
  3113. }
  3114. }
  3115. }
  3116. // m_log.DebugFormat(
  3117. // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
  3118. // Name, LocalId, forGroup, m_undo.Count);
  3119. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3120. {
  3121. UndoState nUndo = new UndoState(this, forGroup);
  3122. m_undo.Push(nUndo);
  3123. if (m_redo.Count > 0)
  3124. m_redo.Clear();
  3125. // m_log.DebugFormat(
  3126. // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
  3127. // Name, LocalId, forGroup, m_undo.Count);
  3128. }
  3129. }
  3130. }
  3131. }
  3132. // else
  3133. // {
  3134. // m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
  3135. // }
  3136. }
  3137. // else
  3138. // {
  3139. // m_log.DebugFormat(
  3140. // "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
  3141. // }
  3142. }
  3143. /// <summary>
  3144. /// Return number of undos on the stack. Here temporarily pending a refactor.
  3145. /// </summary>
  3146. public int UndoCount
  3147. {
  3148. get
  3149. {
  3150. lock (m_undo)
  3151. return m_undo.Count;
  3152. }
  3153. }
  3154. public void Undo()
  3155. {
  3156. lock (m_undo)
  3157. {
  3158. // m_log.DebugFormat(
  3159. // "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
  3160. // Name, LocalId, m_undo.Count);
  3161. if (m_undo.Count > 0)
  3162. {
  3163. UndoState goback = m_undo.Pop();
  3164. if (goback != null)
  3165. {
  3166. UndoState nUndo = null;
  3167. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3168. {
  3169. nUndo = new UndoState(this, goback.ForGroup);
  3170. }
  3171. goback.PlaybackState(this);
  3172. if (nUndo != null)
  3173. m_redo.Push(nUndo);
  3174. }
  3175. }
  3176. // m_log.DebugFormat(
  3177. // "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}",
  3178. // Name, LocalId, m_undo.Count);
  3179. }
  3180. }
  3181. public void Redo()
  3182. {
  3183. lock (m_undo)
  3184. {
  3185. // m_log.DebugFormat(
  3186. // "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
  3187. // Name, LocalId, m_redo.Count);
  3188. if (m_redo.Count > 0)
  3189. {
  3190. UndoState gofwd = m_redo.Pop();
  3191. if (gofwd != null)
  3192. {
  3193. if (m_parentGroup.GetSceneMaxUndo() > 0)
  3194. {
  3195. UndoState nUndo = new UndoState(this, gofwd.ForGroup);
  3196. m_undo.Push(nUndo);
  3197. }
  3198. gofwd.PlayfwdState(this);
  3199. }
  3200. // m_log.DebugFormat(
  3201. // "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}",
  3202. // Name, LocalId, m_redo.Count);
  3203. }
  3204. }
  3205. }
  3206. public void ClearUndoState()
  3207. {
  3208. // m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId);
  3209. lock (m_undo)
  3210. {
  3211. m_undo.Clear();
  3212. m_redo.Clear();
  3213. }
  3214. }
  3215. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  3216. {
  3217. // In this case we're using a sphere with a radius of the largest dimension of the prim
  3218. // TODO: Change to take shape into account
  3219. EntityIntersection result = new EntityIntersection();
  3220. Vector3 vAbsolutePosition = AbsolutePosition;
  3221. Vector3 vScale = Scale;
  3222. Vector3 rOrigin = iray.Origin;
  3223. Vector3 rDirection = iray.Direction;
  3224. //rDirection = rDirection.Normalize();
  3225. // Buidling the first part of the Quadratic equation
  3226. Vector3 r2ndDirection = rDirection*rDirection;
  3227. float itestPart1 = r2ndDirection.X + r2ndDirection.Y + r2ndDirection.Z;
  3228. // Buidling the second part of the Quadratic equation
  3229. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  3230. Vector3 r2Direction = rDirection*2.0f;
  3231. Vector3 tmVal3 = r2Direction*tmVal2;
  3232. float itestPart2 = tmVal3.X + tmVal3.Y + tmVal3.Z;
  3233. // Buidling the third part of the Quadratic equation
  3234. Vector3 tmVal4 = rOrigin*rOrigin;
  3235. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  3236. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  3237. // Set Radius to the largest dimension of the prim
  3238. float radius = 0f;
  3239. if (vScale.X > radius)
  3240. radius = vScale.X;
  3241. if (vScale.Y > radius)
  3242. radius = vScale.Y;
  3243. if (vScale.Z > radius)
  3244. radius = vScale.Z;
  3245. // the second part of this is the default prim size
  3246. // once we factor in the aabb of the prim we're adding we can
  3247. // change this to;
  3248. // radius = (radius / 2) - 0.01f;
  3249. //
  3250. radius = (radius / 2) + (0.5f / 2) - 0.1f;
  3251. //radius = radius;
  3252. float itestPart3 = tmVal4.X + tmVal4.Y + tmVal4.Z + tmVal5.X + tmVal5.Y + tmVal5.Z -
  3253. (2.0f*(tmVal6.X + tmVal6.Y + tmVal6.Z + (radius*radius)));
  3254. // Yuk Quadradrics.. Solve first
  3255. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  3256. if (rootsqr < 0.0f)
  3257. {
  3258. // No intersection
  3259. return result;
  3260. }
  3261. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  3262. if (root < 0.0f)
  3263. {
  3264. // perform second quadratic root solution
  3265. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  3266. // is there any intersection?
  3267. if (root < 0.0f)
  3268. {
  3269. // nope, no intersection
  3270. return result;
  3271. }
  3272. }
  3273. // We got an intersection. putting together an EntityIntersection object with the
  3274. // intersection information
  3275. Vector3 ipoint =
  3276. new Vector3(iray.Origin.X + (iray.Direction.X*root), iray.Origin.Y + (iray.Direction.Y*root),
  3277. iray.Origin.Z + (iray.Direction.Z*root));
  3278. result.HitTF = true;
  3279. result.ipoint = ipoint;
  3280. // Normal is calculated by the difference and then normalizing the result
  3281. Vector3 normalpart = ipoint - vAbsolutePosition;
  3282. result.normal = normalpart / normalpart.Length();
  3283. // It's funny how the Vector3 object has a Distance function, but the Axiom.Math object doesn't.
  3284. // I can write a function to do it.. but I like the fact that this one is Static.
  3285. Vector3 distanceConvert1 = new Vector3(iray.Origin.X, iray.Origin.Y, iray.Origin.Z);
  3286. Vector3 distanceConvert2 = new Vector3(ipoint.X, ipoint.Y, ipoint.Z);
  3287. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  3288. result.distance = distance;
  3289. return result;
  3290. }
  3291. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  3292. {
  3293. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  3294. // This breaks down into the ray---> plane equation.
  3295. // TODO: Change to take shape into account
  3296. Vector3[] vertexes = new Vector3[8];
  3297. // float[] distance = new float[6];
  3298. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  3299. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  3300. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  3301. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  3302. Vector3[] normals = new Vector3[6]; // Normal for Facei
  3303. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  3304. AAfacenormals[0] = new Vector3(1, 0, 0);
  3305. AAfacenormals[1] = new Vector3(0, 1, 0);
  3306. AAfacenormals[2] = new Vector3(-1, 0, 0);
  3307. AAfacenormals[3] = new Vector3(0, -1, 0);
  3308. AAfacenormals[4] = new Vector3(0, 0, 1);
  3309. AAfacenormals[5] = new Vector3(0, 0, -1);
  3310. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  3311. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  3312. Vector3 cross = new Vector3();
  3313. Vector3 pos = GetWorldPosition();
  3314. Quaternion rot = GetWorldRotation();
  3315. // Variables prefixed with AX are Axiom.Math copies of the LL variety.
  3316. Quaternion AXrot = rot;
  3317. AXrot.Normalize();
  3318. Vector3 AXpos = pos;
  3319. // tScale is the offset to derive the vertex based on the scale.
  3320. // it's different for each vertex because we've got to rotate it
  3321. // to get the world position of the vertex to produce the Oriented Bounding Box
  3322. Vector3 tScale = Vector3.Zero;
  3323. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  3324. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  3325. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  3326. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  3327. Vector3 rScale = new Vector3();
  3328. // Get Vertexes for Faces Stick them into ABCD for each Face
  3329. // Form: Face<vertex>[face] that corresponds to the below diagram
  3330. #region ABCD Face Vertex Map Comment Diagram
  3331. // A _________ B
  3332. // | |
  3333. // | 4 top |
  3334. // |_________|
  3335. // C D
  3336. // A _________ B
  3337. // | Back |
  3338. // | 3 |
  3339. // |_________|
  3340. // C D
  3341. // A _________ B B _________ A
  3342. // | Left | | Right |
  3343. // | 0 | | 2 |
  3344. // |_________| |_________|
  3345. // C D D C
  3346. // A _________ B
  3347. // | Front |
  3348. // | 1 |
  3349. // |_________|
  3350. // C D
  3351. // C _________ D
  3352. // | |
  3353. // | 5 bot |
  3354. // |_________|
  3355. // A B
  3356. #endregion
  3357. #region Plane Decomposition of Oriented Bounding Box
  3358. tScale = new Vector3(AXscale.X, -AXscale.Y, AXscale.Z);
  3359. rScale = tScale * AXrot;
  3360. vertexes[0] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3361. // vertexes[0].X = pos.X + vertexes[0].X;
  3362. //vertexes[0].Y = pos.Y + vertexes[0].Y;
  3363. //vertexes[0].Z = pos.Z + vertexes[0].Z;
  3364. FaceA[0] = vertexes[0];
  3365. FaceB[3] = vertexes[0];
  3366. FaceA[4] = vertexes[0];
  3367. tScale = AXscale;
  3368. rScale = tScale * AXrot;
  3369. vertexes[1] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3370. // vertexes[1].X = pos.X + vertexes[1].X;
  3371. // vertexes[1].Y = pos.Y + vertexes[1].Y;
  3372. //vertexes[1].Z = pos.Z + vertexes[1].Z;
  3373. FaceB[0] = vertexes[1];
  3374. FaceA[1] = vertexes[1];
  3375. FaceC[4] = vertexes[1];
  3376. tScale = new Vector3(AXscale.X, -AXscale.Y, -AXscale.Z);
  3377. rScale = tScale * AXrot;
  3378. vertexes[2] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3379. //vertexes[2].X = pos.X + vertexes[2].X;
  3380. //vertexes[2].Y = pos.Y + vertexes[2].Y;
  3381. //vertexes[2].Z = pos.Z + vertexes[2].Z;
  3382. FaceC[0] = vertexes[2];
  3383. FaceD[3] = vertexes[2];
  3384. FaceC[5] = vertexes[2];
  3385. tScale = new Vector3(AXscale.X, AXscale.Y, -AXscale.Z);
  3386. rScale = tScale * AXrot;
  3387. vertexes[3] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3388. //vertexes[3].X = pos.X + vertexes[3].X;
  3389. // vertexes[3].Y = pos.Y + vertexes[3].Y;
  3390. // vertexes[3].Z = pos.Z + vertexes[3].Z;
  3391. FaceD[0] = vertexes[3];
  3392. FaceC[1] = vertexes[3];
  3393. FaceA[5] = vertexes[3];
  3394. tScale = new Vector3(-AXscale.X, AXscale.Y, AXscale.Z);
  3395. rScale = tScale * AXrot;
  3396. vertexes[4] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3397. // vertexes[4].X = pos.X + vertexes[4].X;
  3398. // vertexes[4].Y = pos.Y + vertexes[4].Y;
  3399. // vertexes[4].Z = pos.Z + vertexes[4].Z;
  3400. FaceB[1] = vertexes[4];
  3401. FaceA[2] = vertexes[4];
  3402. FaceD[4] = vertexes[4];
  3403. tScale = new Vector3(-AXscale.X, AXscale.Y, -AXscale.Z);
  3404. rScale = tScale * AXrot;
  3405. vertexes[5] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3406. // vertexes[5].X = pos.X + vertexes[5].X;
  3407. // vertexes[5].Y = pos.Y + vertexes[5].Y;
  3408. // vertexes[5].Z = pos.Z + vertexes[5].Z;
  3409. FaceD[1] = vertexes[5];
  3410. FaceC[2] = vertexes[5];
  3411. FaceB[5] = vertexes[5];
  3412. tScale = new Vector3(-AXscale.X, -AXscale.Y, AXscale.Z);
  3413. rScale = tScale * AXrot;
  3414. vertexes[6] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3415. // vertexes[6].X = pos.X + vertexes[6].X;
  3416. // vertexes[6].Y = pos.Y + vertexes[6].Y;
  3417. // vertexes[6].Z = pos.Z + vertexes[6].Z;
  3418. FaceB[2] = vertexes[6];
  3419. FaceA[3] = vertexes[6];
  3420. FaceB[4] = vertexes[6];
  3421. tScale = new Vector3(-AXscale.X, -AXscale.Y, -AXscale.Z);
  3422. rScale = tScale * AXrot;
  3423. vertexes[7] = (new Vector3((pos.X + rScale.X), (pos.Y + rScale.Y), (pos.Z + rScale.Z)));
  3424. // vertexes[7].X = pos.X + vertexes[7].X;
  3425. // vertexes[7].Y = pos.Y + vertexes[7].Y;
  3426. // vertexes[7].Z = pos.Z + vertexes[7].Z;
  3427. FaceD[2] = vertexes[7];
  3428. FaceC[3] = vertexes[7];
  3429. FaceD[5] = vertexes[7];
  3430. #endregion
  3431. // Get our plane normals
  3432. for (int i = 0; i < 6; i++)
  3433. {
  3434. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  3435. // Our Plane direction
  3436. AmBa = FaceA[i] - FaceB[i];
  3437. AmBb = FaceB[i] - FaceC[i];
  3438. cross = Vector3.Cross(AmBb, AmBa);
  3439. // normalize the cross product to get the normal.
  3440. normals[i] = cross / cross.Length();
  3441. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  3442. //distance[i] = (normals[i].X * AmBa.X + normals[i].Y * AmBa.Y + normals[i].Z * AmBa.Z) * -1;
  3443. }
  3444. EntityIntersection result = new EntityIntersection();
  3445. result.distance = 1024;
  3446. float c = 0;
  3447. float a = 0;
  3448. float d = 0;
  3449. Vector3 q = new Vector3();
  3450. #region OBB Version 2 Experiment
  3451. //float fmin = 999999;
  3452. //float fmax = -999999;
  3453. //float s = 0;
  3454. //for (int i=0;i<6;i++)
  3455. //{
  3456. //s = iray.Direction.Dot(normals[i]);
  3457. //d = normals[i].Dot(FaceB[i]);
  3458. //if (s == 0)
  3459. //{
  3460. //if (iray.Origin.Dot(normals[i]) > d)
  3461. //{
  3462. //return result;
  3463. //}
  3464. // else
  3465. //{
  3466. //continue;
  3467. //}
  3468. //}
  3469. //a = (d - iray.Origin.Dot(normals[i])) / s;
  3470. //if (iray.Direction.Dot(normals[i]) < 0)
  3471. //{
  3472. //if (a > fmax)
  3473. //{
  3474. //if (a > fmin)
  3475. //{
  3476. //return result;
  3477. //}
  3478. //fmax = a;
  3479. //}
  3480. //}
  3481. //else
  3482. //{
  3483. //if (a < fmin)
  3484. //{
  3485. //if (a < 0 || a < fmax)
  3486. //{
  3487. //return result;
  3488. //}
  3489. //fmin = a;
  3490. //}
  3491. //}
  3492. //}
  3493. //if (fmax > 0)
  3494. // a= fmax;
  3495. //else
  3496. // a=fmin;
  3497. //q = iray.Origin + a * iray.Direction;
  3498. #endregion
  3499. // Loop over faces (6 of them)
  3500. for (int i = 0; i < 6; i++)
  3501. {
  3502. AmBa = FaceA[i] - FaceB[i];
  3503. AmBb = FaceB[i] - FaceC[i];
  3504. d = Vector3.Dot(normals[i], FaceB[i]);
  3505. //if (faceCenters)
  3506. //{
  3507. // c = normals[i].Dot(normals[i]);
  3508. //}
  3509. //else
  3510. //{
  3511. c = Vector3.Dot(iray.Direction, normals[i]);
  3512. //}
  3513. if (c == 0)
  3514. continue;
  3515. a = (d - Vector3.Dot(iray.Origin, normals[i])) / c;
  3516. if (a < 0)
  3517. continue;
  3518. // If the normal is pointing outside the object
  3519. if (Vector3.Dot(iray.Direction, normals[i]) < 0 || !frontFacesOnly)
  3520. {
  3521. //if (faceCenters)
  3522. //{ //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  3523. // q = iray.Origin + a * normals[i];
  3524. //}
  3525. //else
  3526. //{
  3527. q = iray.Origin + iray.Direction * a;
  3528. //}
  3529. float distance2 = (float)GetDistanceTo(q, AXpos);
  3530. // Is this the closest hit to the object's origin?
  3531. //if (faceCenters)
  3532. //{
  3533. // distance2 = (float)GetDistanceTo(q, iray.Origin);
  3534. //}
  3535. if (distance2 < result.distance)
  3536. {
  3537. result.distance = distance2;
  3538. result.HitTF = true;
  3539. result.ipoint = q;
  3540. //m_log.Info("[FACE]:" + i.ToString());
  3541. //m_log.Info("[POINT]: " + q.ToString());
  3542. //m_log.Info("[DIST]: " + distance2.ToString());
  3543. if (faceCenters)
  3544. {
  3545. result.normal = AAfacenormals[i] * AXrot;
  3546. Vector3 scaleComponent = AAfacenormals[i];
  3547. float ScaleOffset = 0.5f;
  3548. if (scaleComponent.X != 0) ScaleOffset = AXscale.X;
  3549. if (scaleComponent.Y != 0) ScaleOffset = AXscale.Y;
  3550. if (scaleComponent.Z != 0) ScaleOffset = AXscale.Z;
  3551. ScaleOffset = Math.Abs(ScaleOffset);
  3552. Vector3 offset = result.normal * ScaleOffset;
  3553. result.ipoint = AXpos + offset;
  3554. ///pos = (intersectionpoint + offset);
  3555. }
  3556. else
  3557. {
  3558. result.normal = normals[i];
  3559. }
  3560. result.AAfaceNormal = AAfacenormals[i];
  3561. }
  3562. }
  3563. }
  3564. return result;
  3565. }
  3566. /// <summary>
  3567. /// Serialize this part to xml.
  3568. /// </summary>
  3569. /// <param name="xmlWriter"></param>
  3570. public void ToXml(XmlTextWriter xmlWriter)
  3571. {
  3572. SceneObjectSerializer.SOPToXml2(xmlWriter, this, new Dictionary<string, object>());
  3573. }
  3574. public void TriggerScriptChangedEvent(Changed val)
  3575. {
  3576. if (m_parentGroup != null && m_parentGroup.Scene != null)
  3577. m_parentGroup.Scene.EventManager.TriggerOnScriptChangedEvent(LocalId, (uint)val);
  3578. }
  3579. public void TrimPermissions()
  3580. {
  3581. _baseMask &= (uint)PermissionMask.All;
  3582. _ownerMask &= (uint)PermissionMask.All;
  3583. _groupMask &= (uint)PermissionMask.All;
  3584. _everyoneMask &= (uint)PermissionMask.All;
  3585. _nextOwnerMask &= (uint)PermissionMask.All;
  3586. }
  3587. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  3588. {
  3589. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  3590. if (type == 0x30)
  3591. {
  3592. if (m_shape.SculptEntry && m_shape.SculptTexture != UUID.Zero)
  3593. {
  3594. m_parentGroup.Scene.AssetService.Get(m_shape.SculptTexture.ToString(), this, AssetReceived);
  3595. }
  3596. }
  3597. if (ParentGroup != null)
  3598. {
  3599. ParentGroup.HasGroupChanged = true;
  3600. ScheduleFullUpdate();
  3601. }
  3602. }
  3603. public void UpdateGroupPosition(Vector3 pos)
  3604. {
  3605. if ((pos.X != GroupPosition.X) ||
  3606. (pos.Y != GroupPosition.Y) ||
  3607. (pos.Z != GroupPosition.Z))
  3608. {
  3609. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  3610. GroupPosition = newPos;
  3611. ScheduleTerseUpdate();
  3612. }
  3613. }
  3614. public virtual void UpdateMovement()
  3615. {
  3616. }
  3617. /// <summary>
  3618. ///
  3619. /// </summary>
  3620. /// <param name="pos"></param>
  3621. public void UpdateOffSet(Vector3 pos)
  3622. {
  3623. if ((pos.X != OffsetPosition.X) ||
  3624. (pos.Y != OffsetPosition.Y) ||
  3625. (pos.Z != OffsetPosition.Z))
  3626. {
  3627. Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z);
  3628. if (ParentGroup.RootPart.GetStatusSandbox())
  3629. {
  3630. if (Util.GetDistanceTo(ParentGroup.RootPart.StatusSandboxPos, newPos) > 10)
  3631. {
  3632. ParentGroup.RootPart.ScriptSetPhysicsStatus(false);
  3633. newPos = OffsetPosition;
  3634. ParentGroup.Scene.SimChat(Utils.StringToBytes("Hit Sandbox Limit"),
  3635. ChatTypeEnum.DebugChannel, 0x7FFFFFFF, ParentGroup.RootPart.AbsolutePosition, Name, UUID, false);
  3636. }
  3637. }
  3638. OffsetPosition = newPos;
  3639. ScheduleTerseUpdate();
  3640. }
  3641. }
  3642. public void UpdatePermissions(UUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  3643. {
  3644. bool set = addRemTF == 1;
  3645. bool god = m_parentGroup.Scene.Permissions.IsGod(AgentID);
  3646. uint baseMask = _baseMask;
  3647. if (god)
  3648. baseMask = 0x7ffffff0;
  3649. // Are we the owner?
  3650. if ((AgentID == _ownerID) || god)
  3651. {
  3652. switch (field)
  3653. {
  3654. case 1:
  3655. if (god)
  3656. {
  3657. _baseMask = ApplyMask(_baseMask, set, mask);
  3658. Inventory.ApplyGodPermissions(_baseMask);
  3659. }
  3660. break;
  3661. case 2:
  3662. _ownerMask = ApplyMask(_ownerMask, set, mask) &
  3663. baseMask;
  3664. break;
  3665. case 4:
  3666. _groupMask = ApplyMask(_groupMask, set, mask) &
  3667. baseMask;
  3668. break;
  3669. case 8:
  3670. _everyoneMask = ApplyMask(_everyoneMask, set, mask) &
  3671. baseMask;
  3672. break;
  3673. case 16:
  3674. _nextOwnerMask = ApplyMask(_nextOwnerMask, set, mask) &
  3675. baseMask;
  3676. // Prevent the client from creating no mod, no copy
  3677. // objects
  3678. if ((_nextOwnerMask & (uint)PermissionMask.Copy) == 0)
  3679. _nextOwnerMask |= (uint)PermissionMask.Transfer;
  3680. _nextOwnerMask |= (uint)PermissionMask.Move;
  3681. break;
  3682. }
  3683. SendFullUpdateToAllClients();
  3684. SendRootPartPropertiesToClient(AgentID);
  3685. }
  3686. }
  3687. public bool IsHingeJoint()
  3688. {
  3689. // For now, we use the NINJA naming scheme for identifying joints.
  3690. // In the future, we can support other joint specification schemes such as a
  3691. // custom checkbox in the viewer GUI.
  3692. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3693. {
  3694. string hingeString = "hingejoint";
  3695. return (Name.Length >= hingeString.Length && Name.Substring(0, hingeString.Length) == hingeString);
  3696. }
  3697. else
  3698. {
  3699. return false;
  3700. }
  3701. }
  3702. public bool IsBallJoint()
  3703. {
  3704. // For now, we use the NINJA naming scheme for identifying joints.
  3705. // In the future, we can support other joint specification schemes such as a
  3706. // custom checkbox in the viewer GUI.
  3707. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3708. {
  3709. string ballString = "balljoint";
  3710. return (Name.Length >= ballString.Length && Name.Substring(0, ballString.Length) == ballString);
  3711. }
  3712. else
  3713. {
  3714. return false;
  3715. }
  3716. }
  3717. public bool IsJoint()
  3718. {
  3719. // For now, we use the NINJA naming scheme for identifying joints.
  3720. // In the future, we can support other joint specification schemes such as a
  3721. // custom checkbox in the viewer GUI.
  3722. if (m_parentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
  3723. {
  3724. return IsHingeJoint() || IsBallJoint();
  3725. }
  3726. else
  3727. {
  3728. return false;
  3729. }
  3730. }
  3731. /// <summary>
  3732. /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
  3733. /// </summary>
  3734. /// <param name="UsePhysics"></param>
  3735. /// <param name="SetTemporary"></param>
  3736. /// <param name="SetPhantom"></param>
  3737. /// <param name="SetVD"></param>
  3738. public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD)
  3739. {
  3740. bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
  3741. bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
  3742. bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0);
  3743. bool wasVD = VolumeDetectActive;
  3744. if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
  3745. {
  3746. return;
  3747. }
  3748. // Special cases for VD. VD can only be called from a script
  3749. // and can't be combined with changes to other states. So we can rely
  3750. // that...
  3751. // ... if VD is changed, all others are not.
  3752. // ... if one of the others is changed, VD is not.
  3753. if (SetVD) // VD is active, special logic applies
  3754. {
  3755. // State machine logic for VolumeDetect
  3756. // More logic below
  3757. bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
  3758. if (phanReset) // Phantom changes from on to off switch VD off too
  3759. {
  3760. SetVD = false; // Switch it of for the course of this routine
  3761. VolumeDetectActive = false; // and also permanently
  3762. if (PhysActor != null)
  3763. PhysActor.SetVolumeDetect(0); // Let physics know about it too
  3764. }
  3765. else
  3766. {
  3767. // If volumedetect is active we don't want phantom to be applied.
  3768. // If this is a new call to VD out of the state "phantom"
  3769. // this will also cause the prim to be visible to physics
  3770. SetPhantom = false;
  3771. }
  3772. }
  3773. if (UsePhysics && IsJoint())
  3774. {
  3775. SetPhantom = true;
  3776. }
  3777. if (UsePhysics)
  3778. {
  3779. AddFlag(PrimFlags.Physics);
  3780. if (!wasUsingPhysics)
  3781. {
  3782. DoPhysicsPropertyUpdate(UsePhysics, false);
  3783. if (!m_parentGroup.IsDeleted)
  3784. {
  3785. if (LocalId == m_parentGroup.RootPart.LocalId)
  3786. {
  3787. m_parentGroup.CheckSculptAndLoad();
  3788. }
  3789. }
  3790. }
  3791. }
  3792. else
  3793. {
  3794. RemFlag(PrimFlags.Physics);
  3795. if (wasUsingPhysics)
  3796. {
  3797. DoPhysicsPropertyUpdate(UsePhysics, false);
  3798. }
  3799. }
  3800. if (SetPhantom
  3801. || ParentGroup.IsAttachment
  3802. || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
  3803. {
  3804. AddFlag(PrimFlags.Phantom);
  3805. if (PhysActor != null)
  3806. {
  3807. m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  3808. /// that's not wholesome. Had to make Scene public
  3809. PhysActor = null;
  3810. }
  3811. }
  3812. else // Not phantom
  3813. {
  3814. RemFlag(PrimFlags.Phantom);
  3815. if (ParentGroup.Scene == null)
  3816. return;
  3817. PhysicsActor pa = PhysActor;
  3818. if (pa == null)
  3819. {
  3820. // It's not phantom anymore. So make sure the physics engine get's knowledge of it
  3821. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  3822. string.Format("{0}/{1}", Name, UUID),
  3823. Shape,
  3824. AbsolutePosition,
  3825. Scale,
  3826. RotationOffset,
  3827. UsePhysics,
  3828. m_localId);
  3829. pa = PhysActor;
  3830. if (pa != null)
  3831. {
  3832. PhysActor.SetMaterial(Material);
  3833. DoPhysicsPropertyUpdate(UsePhysics, true);
  3834. if (!m_parentGroup.IsDeleted)
  3835. {
  3836. if (LocalId == m_parentGroup.RootPart.LocalId)
  3837. {
  3838. m_parentGroup.CheckSculptAndLoad();
  3839. }
  3840. }
  3841. if (
  3842. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  3843. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  3844. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  3845. ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
  3846. ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
  3847. ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
  3848. (CollisionSound != UUID.Zero)
  3849. )
  3850. {
  3851. PhysActor.OnCollisionUpdate += PhysicsCollision;
  3852. PhysActor.SubscribeEvents(1000);
  3853. }
  3854. }
  3855. }
  3856. else // it already has a physical representation
  3857. {
  3858. pa.IsPhysical = UsePhysics;
  3859. DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
  3860. if (!m_parentGroup.IsDeleted)
  3861. {
  3862. if (LocalId == m_parentGroup.RootPart.LocalId)
  3863. {
  3864. m_parentGroup.CheckSculptAndLoad();
  3865. }
  3866. }
  3867. }
  3868. }
  3869. if (SetVD)
  3870. {
  3871. // If the above logic worked (this is urgent candidate to unit tests!)
  3872. // we now have a physicsactor.
  3873. // Defensive programming calls for a check here.
  3874. // Better would be throwing an exception that could be catched by a unit test as the internal
  3875. // logic should make sure, this Physactor is always here.
  3876. if (this.PhysActor != null)
  3877. {
  3878. PhysActor.SetVolumeDetect(1);
  3879. AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
  3880. this.VolumeDetectActive = true;
  3881. }
  3882. }
  3883. else
  3884. {
  3885. // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
  3886. // (mumbles, well, at least if you have infinte CPU powers :-))
  3887. PhysicsActor pa = this.PhysActor;
  3888. if (pa != null)
  3889. {
  3890. PhysActor.SetVolumeDetect(0);
  3891. }
  3892. this.VolumeDetectActive = false;
  3893. }
  3894. if (SetTemporary)
  3895. {
  3896. AddFlag(PrimFlags.TemporaryOnRez);
  3897. }
  3898. else
  3899. {
  3900. RemFlag(PrimFlags.TemporaryOnRez);
  3901. }
  3902. // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  3903. if (ParentGroup != null)
  3904. {
  3905. ParentGroup.HasGroupChanged = true;
  3906. ScheduleFullUpdate();
  3907. }
  3908. // m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
  3909. }
  3910. public void UpdateRotation(Quaternion rot)
  3911. {
  3912. if ((rot.X != RotationOffset.X) ||
  3913. (rot.Y != RotationOffset.Y) ||
  3914. (rot.Z != RotationOffset.Z) ||
  3915. (rot.W != RotationOffset.W))
  3916. {
  3917. RotationOffset = rot;
  3918. if (ParentGroup != null)
  3919. {
  3920. ParentGroup.HasGroupChanged = true;
  3921. ScheduleTerseUpdate();
  3922. }
  3923. }
  3924. }
  3925. /// <summary>
  3926. /// Update the shape of this part.
  3927. /// </summary>
  3928. /// <param name="shapeBlock"></param>
  3929. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  3930. {
  3931. m_shape.PathBegin = shapeBlock.PathBegin;
  3932. m_shape.PathEnd = shapeBlock.PathEnd;
  3933. m_shape.PathScaleX = shapeBlock.PathScaleX;
  3934. m_shape.PathScaleY = shapeBlock.PathScaleY;
  3935. m_shape.PathShearX = shapeBlock.PathShearX;
  3936. m_shape.PathShearY = shapeBlock.PathShearY;
  3937. m_shape.PathSkew = shapeBlock.PathSkew;
  3938. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  3939. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  3940. m_shape.PathCurve = shapeBlock.PathCurve;
  3941. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  3942. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  3943. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  3944. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  3945. m_shape.PathTaperX = shapeBlock.PathTaperX;
  3946. m_shape.PathTaperY = shapeBlock.PathTaperY;
  3947. m_shape.PathTwist = shapeBlock.PathTwist;
  3948. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  3949. if (PhysActor != null)
  3950. {
  3951. PhysActor.Shape = m_shape;
  3952. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  3953. }
  3954. // This is what makes vehicle trailers work
  3955. // A script in a child prim re-issues
  3956. // llSetPrimitiveParams(PRIM_TYPE) every few seconds. That
  3957. // prevents autoreturn. This is not well known. It also works
  3958. // in SL.
  3959. //
  3960. if (ParentGroup.RootPart != this)
  3961. ParentGroup.RootPart.Rezzed = DateTime.UtcNow;
  3962. ParentGroup.HasGroupChanged = true;
  3963. TriggerScriptChangedEvent(Changed.SHAPE);
  3964. ScheduleFullUpdate();
  3965. }
  3966. /// <summary>
  3967. /// If the part is a sculpt/mesh, retrieve the mesh data and reinsert it into the shape so that the physics
  3968. /// engine can use it.
  3969. /// </summary>
  3970. /// <remarks>
  3971. /// When the physics engine has finished with it, the sculpt data is discarded to save memory.
  3972. /// </remarks>
  3973. public void CheckSculptAndLoad()
  3974. {
  3975. // m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
  3976. if (ParentGroup.IsDeleted)
  3977. return;
  3978. if ((ParentGroup.RootPart.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
  3979. return;
  3980. if (Shape.SculptEntry && Shape.SculptTexture != UUID.Zero)
  3981. {
  3982. // check if a previously decoded sculpt map has been cached
  3983. // We don't read the file here - the meshmerizer will do that later.
  3984. // TODO: Could we simplify the meshmerizer code by reading and setting the data here?
  3985. if (File.Exists(System.IO.Path.Combine("j2kDecodeCache", "smap_" + Shape.SculptTexture.ToString())))
  3986. {
  3987. SculptTextureCallback(null);
  3988. }
  3989. else
  3990. {
  3991. ParentGroup.Scene.AssetService.Get(Shape.SculptTexture.ToString(), this, AssetReceived);
  3992. }
  3993. }
  3994. }
  3995. /// <summary>
  3996. /// Update the textures on the part.
  3997. /// </summary>
  3998. /// <remarks>
  3999. /// Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  4000. /// not handling RGBA properly. Cycles through, and "fixes" the color
  4001. /// info
  4002. /// </remarks>
  4003. /// <param name="tex"></param>
  4004. public void UpdateTexture(Primitive.TextureEntry tex)
  4005. {
  4006. //Color4 tmpcolor;
  4007. //for (uint i = 0; i < 32; i++)
  4008. //{
  4009. // if (tex.FaceTextures[i] != null)
  4010. // {
  4011. // tmpcolor = tex.GetFace((uint) i).RGBA;
  4012. // tmpcolor.A = tmpcolor.A*255;
  4013. // tmpcolor.R = tmpcolor.R*255;
  4014. // tmpcolor.G = tmpcolor.G*255;
  4015. // tmpcolor.B = tmpcolor.B*255;
  4016. // tex.FaceTextures[i].RGBA = tmpcolor;
  4017. // }
  4018. //}
  4019. //tmpcolor = tex.DefaultTexture.RGBA;
  4020. //tmpcolor.A = tmpcolor.A*255;
  4021. //tmpcolor.R = tmpcolor.R*255;
  4022. //tmpcolor.G = tmpcolor.G*255;
  4023. //tmpcolor.B = tmpcolor.B*255;
  4024. //tex.DefaultTexture.RGBA = tmpcolor;
  4025. UpdateTextureEntry(tex.GetBytes());
  4026. }
  4027. /// <summary>
  4028. /// Update the texture entry for this part.
  4029. /// </summary>
  4030. /// <param name="textureEntry"></param>
  4031. public void UpdateTextureEntry(byte[] textureEntry)
  4032. {
  4033. m_shape.TextureEntry = textureEntry;
  4034. TriggerScriptChangedEvent(Changed.TEXTURE);
  4035. ParentGroup.HasGroupChanged = true;
  4036. //This is madness..
  4037. //ParentGroup.ScheduleGroupForFullUpdate();
  4038. //This is sparta
  4039. ScheduleFullUpdate();
  4040. }
  4041. public void aggregateScriptEvents()
  4042. {
  4043. AggregateScriptEvents = 0;
  4044. // Aggregate script events
  4045. lock (m_scriptEvents)
  4046. {
  4047. foreach (scriptEvents s in m_scriptEvents.Values)
  4048. {
  4049. AggregateScriptEvents |= s;
  4050. }
  4051. }
  4052. uint objectflagupdate = 0;
  4053. if (
  4054. ((AggregateScriptEvents & scriptEvents.touch) != 0) ||
  4055. ((AggregateScriptEvents & scriptEvents.touch_end) != 0) ||
  4056. ((AggregateScriptEvents & scriptEvents.touch_start) != 0)
  4057. )
  4058. {
  4059. objectflagupdate |= (uint) PrimFlags.Touch;
  4060. }
  4061. if ((AggregateScriptEvents & scriptEvents.money) != 0)
  4062. {
  4063. objectflagupdate |= (uint) PrimFlags.Money;
  4064. }
  4065. if (AllowedDrop)
  4066. {
  4067. objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
  4068. }
  4069. if (
  4070. ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
  4071. ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  4072. ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
  4073. ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
  4074. ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
  4075. ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
  4076. (CollisionSound != UUID.Zero)
  4077. )
  4078. {
  4079. // subscribe to physics updates.
  4080. if (PhysActor != null)
  4081. {
  4082. PhysActor.OnCollisionUpdate += PhysicsCollision;
  4083. PhysActor.SubscribeEvents(1000);
  4084. }
  4085. }
  4086. else
  4087. {
  4088. if (PhysActor != null)
  4089. {
  4090. PhysActor.UnSubscribeEvents();
  4091. PhysActor.OnCollisionUpdate -= PhysicsCollision;
  4092. }
  4093. }
  4094. //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
  4095. //{
  4096. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting;
  4097. //}
  4098. //else
  4099. //{
  4100. // m_parentGroup.Scene.EventManager.OnScriptTimerEvent -= handleTimerAccounting;
  4101. //}
  4102. LocalFlags = (PrimFlags)objectflagupdate;
  4103. if (m_parentGroup != null && m_parentGroup.RootPart == this)
  4104. {
  4105. m_parentGroup.aggregateScriptEvents();
  4106. }
  4107. else
  4108. {
  4109. // m_log.DebugFormat(
  4110. // "[SCENE OBJECT PART]: Scheduling part {0} {1} for full update in aggregateScriptEvents()", Name, LocalId);
  4111. ScheduleFullUpdate();
  4112. }
  4113. }
  4114. public void SetCameraAtOffset(Vector3 v)
  4115. {
  4116. m_cameraAtOffset = v;
  4117. }
  4118. public void SetCameraEyeOffset(Vector3 v)
  4119. {
  4120. m_cameraEyeOffset = v;
  4121. }
  4122. public void SetForceMouselook(bool force)
  4123. {
  4124. m_forceMouselook = force;
  4125. }
  4126. public Vector3 GetCameraAtOffset()
  4127. {
  4128. return m_cameraAtOffset;
  4129. }
  4130. public Vector3 GetCameraEyeOffset()
  4131. {
  4132. return m_cameraEyeOffset;
  4133. }
  4134. public bool GetForceMouselook()
  4135. {
  4136. return m_forceMouselook;
  4137. }
  4138. public override string ToString()
  4139. {
  4140. return String.Format("{0} {1} (parent {2}))", Name, UUID, ParentGroup);
  4141. }
  4142. #endregion Public Methods
  4143. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  4144. {
  4145. if (ParentGroup.IsDeleted)
  4146. return;
  4147. if (ParentGroup.IsAttachment && ParentGroup.RootPart != this)
  4148. return;
  4149. // Causes this thread to dig into the Client Thread Data.
  4150. // Remember your locking here!
  4151. remoteClient.SendPrimUpdate(this, PrimUpdateFlags.Position | PrimUpdateFlags.Rotation | PrimUpdateFlags.Velocity | PrimUpdateFlags.Acceleration | PrimUpdateFlags.AngularVelocity);
  4152. }
  4153. public void AddScriptLPS(int count)
  4154. {
  4155. m_parentGroup.AddScriptLPS(count);
  4156. }
  4157. public void ApplyNextOwnerPermissions()
  4158. {
  4159. _baseMask &= _nextOwnerMask;
  4160. _ownerMask &= _nextOwnerMask;
  4161. _everyoneMask &= _nextOwnerMask;
  4162. Inventory.ApplyNextOwnerPermissions();
  4163. }
  4164. public void UpdateLookAt()
  4165. {
  4166. try
  4167. {
  4168. if (APIDTarget != Quaternion.Identity)
  4169. {
  4170. if (Single.IsNaN(APIDTarget.W) == true)
  4171. {
  4172. APIDTarget = Quaternion.Identity;
  4173. return;
  4174. }
  4175. Quaternion rot = RotationOffset;
  4176. Quaternion dir = (rot - APIDTarget);
  4177. float speed = ((APIDStrength / APIDDamp) * (float)(Math.PI / 180.0f));
  4178. if (dir.Z > speed)
  4179. {
  4180. rot.Z -= speed;
  4181. }
  4182. if (dir.Z < -speed)
  4183. {
  4184. rot.Z += speed;
  4185. }
  4186. rot.Normalize();
  4187. UpdateRotation(rot);
  4188. }
  4189. }
  4190. catch (Exception ex)
  4191. {
  4192. m_log.Error("[Physics] " + ex);
  4193. }
  4194. }
  4195. public Color4 GetTextColor()
  4196. {
  4197. Color color = Color;
  4198. return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
  4199. }
  4200. }
  4201. }