SceneObjectPart.cs 134 KB

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