SceneObjectPart.cs 162 KB

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