SceneObjectPart.cs 153 KB

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