SceneObjectPart.cs 173 KB

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