SceneObjectPart.cs 159 KB

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