SceneObjectPart.cs 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886
  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.Runtime.Serialization;
  31. using System.Security.Permissions;
  32. using System.Xml;
  33. using System.Xml.Serialization;
  34. using Axiom.Math;
  35. using libsecondlife;
  36. using libsecondlife.Packets;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Environment.Scenes.Scripting;
  39. using OpenSim.Region.Physics.Manager;
  40. namespace OpenSim.Region.Environment.Scenes
  41. {
  42. // I don't really know where to put this except here.
  43. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  44. [Flags]
  45. public enum ExtraParamType
  46. {
  47. Something1 = 1,
  48. Something2 = 2,
  49. Something3 = 4,
  50. Something4 = 8,
  51. Flexible = 16,
  52. Light = 32,
  53. Sculpt = 48,
  54. Something5 = 64,
  55. Something6 = 128
  56. }
  57. [Flags]
  58. public enum Changed : uint
  59. {
  60. INVENTORY = 1,
  61. COLOR = 2,
  62. SHAPE = 4,
  63. SCALE = 8,
  64. TEXTURE = 16,
  65. LINK = 32,
  66. ALLOWED_DROP = 64,
  67. OWNER = 128
  68. }
  69. [Flags]
  70. public enum TextureAnimFlags : byte
  71. {
  72. NONE = 0x00,
  73. ANIM_ON = 0x01,
  74. LOOP = 0x02,
  75. REVERSE = 0x04,
  76. PING_PONG = 0x08,
  77. SMOOTH = 0x10,
  78. ROTATE = 0x20,
  79. SCALE = 0x40
  80. }
  81. [Serializable]
  82. public partial class SceneObjectPart : IScriptHost, ISerializable
  83. {
  84. [XmlIgnore] public PhysicsActor PhysActor = null;
  85. public LLUUID LastOwnerID;
  86. public LLUUID OwnerID;
  87. public LLUUID GroupID;
  88. public int OwnershipCost;
  89. public byte ObjectSaleType;
  90. public int SalePrice;
  91. public uint Category;
  92. // TODO: This needs to be persisted in next XML version update!
  93. [XmlIgnore] public int[] PayPrice = {-2,-2,-2,-2,-2};
  94. [XmlIgnore] private Dictionary<LLUUID, scriptEvents> m_scriptEvents = new Dictionary<LLUUID, scriptEvents>();
  95. [XmlIgnore] public scriptEvents m_aggregateScriptEvents=0;
  96. [XmlIgnore] private LLObject.ObjectFlags LocalFlags = LLObject.ObjectFlags.None;
  97. [XmlIgnore] public bool DIE_AT_EDGE = false;
  98. [XmlIgnore] public bool m_IsAttachment = false;
  99. [XmlIgnore] public uint m_attachmentPoint = (byte)0;
  100. [XmlIgnore] public LLUUID m_attachedAvatar = LLUUID.Zero;
  101. [XmlIgnore] public LLVector3 m_attachedPos = LLVector3.Zero;
  102. [XmlIgnore] public LLUUID fromAssetID = LLUUID.Zero;
  103. [XmlIgnore] public bool m_undoing = false;
  104. public Int32 CreationDate;
  105. public uint ParentID = 0;
  106. private PhysicsVector m_lastRotationalVelocity = PhysicsVector.Zero;
  107. private Vector3 m_sitTargetPosition = new Vector3(0, 0, 0);
  108. private Quaternion m_sitTargetOrientation = new Quaternion(0, 0, 0, 1);
  109. public LLUUID m_sitTargetAvatar = LLUUID.Zero;
  110. [XmlIgnore] public PhysicsVector m_rotationAxis = new PhysicsVector(1f,1f,1f);
  111. #region Permissions
  112. public uint BaseMask = (uint)PermissionMask.All;
  113. public uint OwnerMask = (uint)PermissionMask.All;
  114. public uint GroupMask = (uint)PermissionMask.None;
  115. public uint EveryoneMask = (uint)PermissionMask.None;
  116. public uint NextOwnerMask = (uint)PermissionMask.All;
  117. private UndoStack<UndoState> m_undo = new UndoStack<UndoState>(5);
  118. public LLObject.ObjectFlags Flags = LLObject.ObjectFlags.None;
  119. public uint ObjectFlags
  120. {
  121. get { return (uint)Flags; }
  122. set { Flags = (LLObject.ObjectFlags)value; }
  123. }
  124. #endregion
  125. protected byte[] m_particleSystem = new byte[0];
  126. [XmlIgnore] public uint TimeStampFull = 0;
  127. [XmlIgnore] public uint TimeStampTerse = 0;
  128. [XmlIgnore] public uint TimeStampLastActivity = 0; // Will be used for AutoReturn
  129. /// <summary>
  130. /// Only used internally to schedule client updates.
  131. /// 0 - no update is scheduled
  132. /// 1 - terse update scheduled
  133. /// 2 - full update scheduled
  134. ///
  135. /// TODO - This should be an enumeration
  136. /// </summary>
  137. private byte m_updateFlag;
  138. #region Properties
  139. public LLUUID CreatorID;
  140. public LLUUID ObjectCreator
  141. {
  142. get { return CreatorID; }
  143. }
  144. protected LLUUID m_uuid;
  145. public LLUUID UUID
  146. {
  147. get { return m_uuid; }
  148. set { m_uuid = value; }
  149. }
  150. protected uint m_localId;
  151. public uint LocalId
  152. {
  153. get { return m_localId; }
  154. set { m_localId = value; }
  155. }
  156. protected string m_name;
  157. public virtual string Name
  158. {
  159. get { return m_name; }
  160. set { m_name = value; }
  161. }
  162. public scriptEvents ScriptEvents
  163. {
  164. get { return m_aggregateScriptEvents; }
  165. }
  166. protected LLObject.MaterialType m_material = 0;
  167. public byte Material
  168. {
  169. get { return (byte) m_material; }
  170. set { m_material = (LLObject.MaterialType) value; }
  171. }
  172. protected ulong m_regionHandle;
  173. public ulong RegionHandle
  174. {
  175. get { return m_regionHandle; }
  176. set { m_regionHandle = value; }
  177. }
  178. public uint GetEffectiveObjectFlags()
  179. {
  180. LLObject.ObjectFlags f = Flags;
  181. if (m_parentGroup == null || m_parentGroup.RootPart == this)
  182. f &= ~(LLObject.ObjectFlags.Touch | LLObject.ObjectFlags.Money);
  183. return (uint)Flags | (uint)LocalFlags;
  184. }
  185. //unkown if this will be kept, added as a way of removing the group position from the group class
  186. protected LLVector3 m_groupPosition;
  187. /// <summary>
  188. /// Method for a prim to get it's world position from the group.
  189. /// Remember, the Group Position simply gives the position of the group itself
  190. /// </summary>
  191. /// <returns>A Linked Child Prim objects position in world</returns>
  192. public LLVector3 GetWorldPosition()
  193. {
  194. Quaternion parentRot = new Quaternion(
  195. ParentGroup.RootPart.RotationOffset.W,
  196. ParentGroup.RootPart.RotationOffset.X,
  197. ParentGroup.RootPart.RotationOffset.Y,
  198. ParentGroup.RootPart.RotationOffset.Z);
  199. Vector3 axPos
  200. = new Vector3(
  201. OffsetPosition.X,
  202. OffsetPosition.Y,
  203. OffsetPosition.Z);
  204. axPos = parentRot * axPos;
  205. LLVector3 translationOffsetPosition = new LLVector3(axPos.x, axPos.y, axPos.z);
  206. return GroupPosition + translationOffsetPosition;
  207. //return (new LLVector3(axiomPos.x, axiomPos.y, axiomPos.z) + AbsolutePosition);
  208. }
  209. /// <summary>
  210. /// Gets the rotation of this prim offset by the group rotation
  211. /// </summary>
  212. /// <returns></returns>
  213. public LLQuaternion GetWorldRotation()
  214. {
  215. Quaternion newRot;
  216. if (this.LinkNum == 0)
  217. {
  218. newRot = new Quaternion(RotationOffset.W,RotationOffset.X,RotationOffset.Y,RotationOffset.Z);
  219. }
  220. else
  221. {
  222. Quaternion parentRot = new Quaternion(
  223. ParentGroup.RootPart.RotationOffset.W,
  224. ParentGroup.RootPart.RotationOffset.X,
  225. ParentGroup.RootPart.RotationOffset.Y,
  226. ParentGroup.RootPart.RotationOffset.Z);
  227. Quaternion oldRot
  228. = new Quaternion(
  229. RotationOffset.W,
  230. RotationOffset.X,
  231. RotationOffset.Y,
  232. RotationOffset.Z);
  233. newRot = parentRot * oldRot;
  234. }
  235. return new LLQuaternion(newRot.x, newRot.y, newRot.z, newRot.w);
  236. //return new LLQuaternion(axiomPartRotation.x, axiomPartRotation.y, axiomPartRotation.z, axiomPartRotation.w);
  237. }
  238. public void StoreUndoState()
  239. {
  240. if (!m_undoing)
  241. {
  242. if (m_parentGroup != null)
  243. {
  244. if (m_undo.Count > 0)
  245. {
  246. UndoState last = m_undo.Peek();
  247. if (last != null)
  248. {
  249. if (last.Compare(this))
  250. return;
  251. }
  252. }
  253. if (m_parentGroup.GetSceneMaxUndo() > 0)
  254. {
  255. UndoState nUndo = new UndoState(this);
  256. m_undo.Push(nUndo);
  257. }
  258. }
  259. }
  260. }
  261. public void ClearUndoState()
  262. {
  263. m_undo.Clear();
  264. StoreUndoState();
  265. }
  266. public LLVector3 GroupPosition
  267. {
  268. get
  269. {
  270. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  271. if (PhysActor != null && ParentID == 0)
  272. {
  273. m_groupPosition.X = PhysActor.Position.X;
  274. m_groupPosition.Y = PhysActor.Position.Y;
  275. m_groupPosition.Z = PhysActor.Position.Z;
  276. }
  277. if (m_IsAttachment)
  278. {
  279. ScenePresence sp = m_parentGroup.Scene.GetScenePresence(m_attachedAvatar);
  280. if (sp != null)
  281. {
  282. return sp.AbsolutePosition;
  283. }
  284. }
  285. return m_groupPosition;
  286. }
  287. set
  288. {
  289. StoreUndoState();
  290. m_groupPosition = value;
  291. if (PhysActor != null)
  292. {
  293. try
  294. {
  295. // Root prim actually goes at Position
  296. if (ParentID == 0)
  297. {
  298. PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  299. }
  300. else
  301. {
  302. // To move the child prim in respect to the group position and rotation we have to calculate
  303. LLVector3 resultingposition = GetWorldPosition();
  304. PhysActor.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z);
  305. LLQuaternion resultingrot = GetWorldRotation();
  306. PhysActor.Orientation = new Quaternion(resultingrot.W, resultingrot.X, resultingrot.Y, resultingrot.Z);
  307. }
  308. // Tell the physics engines that this prim changed.
  309. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  310. }
  311. catch (Exception e)
  312. {
  313. Console.WriteLine(e.Message);
  314. }
  315. }
  316. }
  317. }
  318. private byte[] m_TextureAnimation;
  319. protected LLVector3 m_offsetPosition;
  320. public LLVector3 OffsetPosition
  321. {
  322. get { return m_offsetPosition; }
  323. set
  324. {
  325. StoreUndoState();
  326. m_offsetPosition = value;
  327. try
  328. {
  329. // Hack to get the child prim to update world positions in the physics engine
  330. ParentGroup.ResetChildPrimPhysicsPositions();
  331. }
  332. catch (NullReferenceException)
  333. {
  334. // Ignore, and skip over.
  335. }
  336. //m_log.Info("[PART]: OFFSET:" + m_offsetPosition.ToString());
  337. }
  338. }
  339. public LLVector3 AbsolutePosition
  340. {
  341. get {
  342. if (m_IsAttachment)
  343. return GroupPosition;
  344. return m_offsetPosition + m_groupPosition; }
  345. }
  346. protected LLQuaternion m_rotationOffset;
  347. public LLQuaternion RotationOffset
  348. {
  349. get
  350. {
  351. // We don't want the physics engine mucking up the rotations in a linkset
  352. if (PhysActor != null && ParentID == 0)
  353. {
  354. if (PhysActor.Orientation.x != 0 || PhysActor.Orientation.y != 0
  355. || PhysActor.Orientation.z != 0 || PhysActor.Orientation.w != 0)
  356. {
  357. m_rotationOffset.X = PhysActor.Orientation.x;
  358. m_rotationOffset.Y = PhysActor.Orientation.y;
  359. m_rotationOffset.Z = PhysActor.Orientation.z;
  360. m_rotationOffset.W = PhysActor.Orientation.w;
  361. }
  362. }
  363. return m_rotationOffset;
  364. }
  365. set
  366. {
  367. StoreUndoState();
  368. m_rotationOffset = value;
  369. if (PhysActor != null)
  370. {
  371. try
  372. {
  373. // Root prim gets value directly
  374. if (ParentID == 0)
  375. {
  376. PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z);
  377. //m_log.Info("[PART]: RO1:" + PhysActor.Orientation.ToString());
  378. }
  379. else
  380. {
  381. // Child prim we have to calculate it's world rotationwel
  382. LLQuaternion resultingrotation = GetWorldRotation();
  383. PhysActor.Orientation = new Quaternion(resultingrotation.W, resultingrotation.X, resultingrotation.Y, resultingrotation.Z);
  384. //m_log.Info("[PART]: RO2:" + PhysActor.Orientation.ToString());
  385. }
  386. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  387. //}
  388. }
  389. catch (Exception ex)
  390. {
  391. Console.WriteLine(ex.Message);
  392. }
  393. }
  394. }
  395. }
  396. protected LLVector3 m_velocity;
  397. protected LLVector3 m_rotationalvelocity;
  398. /// <summary></summary>
  399. public LLVector3 Velocity
  400. {
  401. get
  402. {
  403. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  404. //|| PhysActor.Velocity.z != 0)
  405. //{
  406. if (PhysActor != null)
  407. {
  408. if (PhysActor.IsPhysical)
  409. {
  410. m_velocity.X = PhysActor.Velocity.X;
  411. m_velocity.Y = PhysActor.Velocity.Y;
  412. m_velocity.Z = PhysActor.Velocity.Z;
  413. }
  414. }
  415. return m_velocity;
  416. }
  417. set {
  418. m_velocity = value;
  419. if (PhysActor != null)
  420. {
  421. if (PhysActor.IsPhysical)
  422. {
  423. PhysActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  424. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  425. }
  426. }
  427. }
  428. }
  429. public LLVector3 RotationalVelocity
  430. {
  431. get
  432. {
  433. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  434. //|| PhysActor.Velocity.z != 0)
  435. //{
  436. if (PhysActor != null)
  437. {
  438. if (PhysActor.IsPhysical)
  439. {
  440. m_rotationalvelocity.FromBytes(PhysActor.RotationalVelocity.GetBytes(),0);
  441. }
  442. }
  443. return m_rotationalvelocity;
  444. }
  445. set { m_rotationalvelocity = value; }
  446. }
  447. protected LLVector3 m_angularVelocity;
  448. /// <summary></summary>
  449. public LLVector3 AngularVelocity
  450. {
  451. get { return m_angularVelocity; }
  452. set { m_angularVelocity = value; }
  453. }
  454. protected LLVector3 m_acceleration;
  455. /// <summary></summary>
  456. public LLVector3 Acceleration
  457. {
  458. get { return m_acceleration; }
  459. set { m_acceleration = value; }
  460. }
  461. private string m_description = String.Empty;
  462. public string Description
  463. {
  464. get { return m_description; }
  465. set { m_description = value; }
  466. }
  467. private Color m_color = Color.Black;
  468. public Color Color
  469. {
  470. get { return m_color; }
  471. set
  472. {
  473. m_color = value;
  474. TriggerScriptChangedEvent(Changed.COLOR);
  475. /* ScheduleFullUpdate() need not be called b/c after
  476. * setting the color, the text will be set, so then
  477. * ScheduleFullUpdate() will be called. */
  478. //ScheduleFullUpdate();
  479. }
  480. }
  481. private string m_text = String.Empty;
  482. public Vector3 SitTargetPosition
  483. {
  484. get { return m_sitTargetPosition; }
  485. }
  486. public Quaternion SitTargetOrientation
  487. {
  488. get { return m_sitTargetOrientation; }
  489. }
  490. public string Text
  491. {
  492. get
  493. {
  494. string returnstr = m_text;
  495. if (returnstr.Length > 255)
  496. {
  497. returnstr = returnstr.Substring(0, 254);
  498. }
  499. return returnstr;
  500. }
  501. set
  502. {
  503. m_text = value;
  504. }
  505. }
  506. //Xantor 20080528 Sound stuff:
  507. // Note: This isn't persisted in the database right now, as the fields for that aren't just there yet.
  508. // Not a big problem as long as the script that sets it remains in the prim on startup.
  509. // for SL compatibility it should be persisted though (set sound / displaytext / particlesystem, kill script)
  510. [XmlIgnore]
  511. public LLUUID Sound;
  512. [XmlIgnore]
  513. public byte SoundFlags;
  514. [XmlIgnore]
  515. public double SoundGain;
  516. [XmlIgnore]
  517. public double SoundRadius;
  518. private string m_sitName = String.Empty;
  519. public string SitName
  520. {
  521. get { return m_sitName; }
  522. set { m_sitName = value; }
  523. }
  524. private string m_touchName = String.Empty;
  525. public string TouchName
  526. {
  527. get { return m_touchName; }
  528. set { m_touchName = value; }
  529. }
  530. private int m_linkNum = 0;
  531. public int LinkNum
  532. {
  533. get { return m_linkNum; }
  534. set
  535. {
  536. m_linkNum = value;
  537. TriggerScriptChangedEvent(Changed.LINK);
  538. }
  539. }
  540. private byte m_clickAction = 0;
  541. public byte ClickAction
  542. {
  543. get { return m_clickAction; }
  544. set
  545. {
  546. m_clickAction = value;
  547. }
  548. }
  549. protected PrimitiveBaseShape m_shape;
  550. /// <summary>
  551. /// hook to the physics scene to apply impulse
  552. /// This is sent up to the group, which then finds the root prim
  553. /// and applies the force on the root prim of the group
  554. /// </summary>
  555. /// <param name="impulsei">Vector force</param>
  556. /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
  557. public void ApplyImpulse(LLVector3 impulsei, bool localGlobalTF)
  558. {
  559. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  560. if (localGlobalTF)
  561. {
  562. LLQuaternion grot = GetWorldRotation();
  563. Quaternion AXgrot = new Quaternion(grot.W,grot.X,grot.Y,grot.Z);
  564. Vector3 AXimpulsei = new Vector3(impulsei.X, impulsei.Y, impulsei.Z);
  565. Vector3 newimpulse = AXgrot * AXimpulsei;
  566. impulse = new PhysicsVector(newimpulse.x, newimpulse.y, newimpulse.z);
  567. }
  568. else
  569. {
  570. if (m_parentGroup != null)
  571. {
  572. m_parentGroup.applyImpulse(impulse);
  573. }
  574. }
  575. }
  576. public void MoveToTarget(LLVector3 target, float tau)
  577. {
  578. if (tau > 0)
  579. {
  580. m_parentGroup.moveToTarget(target, tau);
  581. }
  582. else
  583. {
  584. StopMoveToTarget();
  585. }
  586. }
  587. public void StopMoveToTarget()
  588. {
  589. m_parentGroup.stopMoveToTarget();
  590. }
  591. public void TriggerScriptChangedEvent(Changed val)
  592. {
  593. if (m_parentGroup != null)
  594. {
  595. if (m_parentGroup.Scene != null)
  596. m_parentGroup.Scene.TriggerObjectChanged(LocalId, (uint)val);
  597. }
  598. }
  599. public PrimitiveBaseShape Shape
  600. {
  601. get { return m_shape; }
  602. set
  603. {
  604. m_shape = value;
  605. TriggerScriptChangedEvent(Changed.SHAPE);
  606. }
  607. }
  608. public LLVector3 Scale
  609. {
  610. get { return m_shape.Scale; }
  611. set
  612. {
  613. StoreUndoState();
  614. m_shape.Scale = value;
  615. TriggerScriptChangedEvent(Changed.SCALE);
  616. }
  617. }
  618. public bool Stopped
  619. {
  620. get {
  621. double threshold = 0.02;
  622. return (Math.Abs(Velocity.X) < threshold &&
  623. Math.Abs(Velocity.Y) < threshold &&
  624. Math.Abs(Velocity.Z) < threshold &&
  625. Math.Abs(AngularVelocity.X) < threshold &&
  626. Math.Abs(AngularVelocity.Y) < threshold &&
  627. Math.Abs(AngularVelocity.Z) < threshold);
  628. }
  629. }
  630. #endregion
  631. public LLUUID ObjectOwner
  632. {
  633. get { return OwnerID; }
  634. }
  635. // FIXME, TODO, ERROR: 'ParentGroup' can't be in here, move it out.
  636. protected SceneObjectGroup m_parentGroup;
  637. public SceneObjectGroup ParentGroup
  638. {
  639. get { return m_parentGroup; }
  640. }
  641. public byte UpdateFlag
  642. {
  643. get { return m_updateFlag; }
  644. set { m_updateFlag = value; }
  645. }
  646. #region Constructors
  647. /// <summary>
  648. /// No arg constructor called by region restore db code
  649. /// </summary>
  650. public SceneObjectPart()
  651. {
  652. // It's not necessary to persist this
  653. m_TextureAnimation = new byte[0];
  654. }
  655. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  656. PrimitiveBaseShape shape, LLVector3 groupPosition, LLVector3 offsetPosition)
  657. : this(regionHandle, parent, ownerID, localID, shape, groupPosition, LLQuaternion.Identity, offsetPosition)
  658. {
  659. }
  660. /// <summary>
  661. /// Create a completely new SceneObjectPart (prim)
  662. /// </summary>
  663. /// <param name="regionHandle"></param>
  664. /// <param name="parent"></param>
  665. /// <param name="ownerID"></param>
  666. /// <param name="localID"></param>
  667. /// <param name="shape"></param>
  668. /// <param name="position"></param>
  669. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  670. PrimitiveBaseShape shape, LLVector3 groupPosition, LLQuaternion rotationOffset,
  671. LLVector3 offsetPosition)
  672. {
  673. m_name = "Primitive";
  674. m_regionHandle = regionHandle;
  675. m_parentGroup = parent;
  676. CreationDate = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  677. OwnerID = ownerID;
  678. CreatorID = OwnerID;
  679. LastOwnerID = LLUUID.Zero;
  680. UUID = LLUUID.Random();
  681. LocalId = (uint) (localID);
  682. Shape = shape;
  683. // Todo: Add More Object Parameter from above!
  684. OwnershipCost = 0;
  685. ObjectSaleType = (byte) 0;
  686. SalePrice = 0;
  687. Category = (uint) 0;
  688. LastOwnerID = CreatorID;
  689. // End Todo: ///
  690. GroupPosition = groupPosition;
  691. OffsetPosition = offsetPosition;
  692. RotationOffset = rotationOffset;
  693. Velocity = new LLVector3(0, 0, 0);
  694. m_rotationalvelocity = new LLVector3(0, 0, 0);
  695. AngularVelocity = new LLVector3(0, 0, 0);
  696. Acceleration = new LLVector3(0, 0, 0);
  697. m_TextureAnimation = new byte[0];
  698. // Prims currently only contain a single folder (Contents). From looking at the Second Life protocol,
  699. // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
  700. // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
  701. Flags = 0;
  702. Flags |= LLObject.ObjectFlags.CreateSelected;
  703. TrimPermissions();
  704. //m_undo = new UndoStack<UndoState>(ParentGroup.GetSceneMaxUndo());
  705. ScheduleFullUpdate();
  706. }
  707. /// <summary>
  708. /// Re/create a SceneObjectPart (prim)
  709. /// currently not used, and maybe won't be
  710. /// </summary>
  711. /// <param name="regionHandle"></param>
  712. /// <param name="parent"></param>
  713. /// <param name="ownerID"></param>
  714. /// <param name="localID"></param>
  715. /// <param name="shape"></param>
  716. /// <param name="position"></param>
  717. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, int creationDate, LLUUID ownerID,
  718. LLUUID creatorID, LLUUID lastOwnerID, uint localID, PrimitiveBaseShape shape,
  719. LLVector3 position, LLQuaternion rotation, uint flags)
  720. {
  721. m_regionHandle = regionHandle;
  722. m_parentGroup = parent;
  723. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  724. CreationDate = creationDate;
  725. OwnerID = ownerID;
  726. CreatorID = creatorID;
  727. LastOwnerID = lastOwnerID;
  728. UUID = LLUUID.Random();
  729. LocalId = (uint) (localID);
  730. Shape = shape;
  731. OwnershipCost = 0;
  732. ObjectSaleType = (byte) 0;
  733. SalePrice = 0;
  734. Category = (uint) 0;
  735. LastOwnerID = CreatorID;
  736. OffsetPosition = position;
  737. RotationOffset = rotation;
  738. ObjectFlags = flags;
  739. // Since we don't store script state, this is only a 'temporary' objectflag now
  740. // If the object is scripted, the script will get loaded and this will be set again
  741. ObjectFlags &= ~(uint)(LLObject.ObjectFlags.Scripted | LLObject.ObjectFlags.Touch);
  742. TrimPermissions();
  743. // ApplyPhysics();
  744. ScheduleFullUpdate();
  745. }
  746. #endregion
  747. /// <summary>
  748. /// Restore this part from the serialized xml representation.
  749. /// </summary>
  750. /// <param name="xmlreader"></param>
  751. /// <returns></returns>
  752. public static SceneObjectPart FromXml(XmlReader xmlReader)
  753. {
  754. // It's not necessary to persist this
  755. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  756. SceneObjectPart newobject = (SceneObjectPart) serializer.Deserialize(xmlReader);
  757. return newobject;
  758. }
  759. public void ApplyPhysics(uint rootObjectFlags, bool m_physicalPrim)
  760. {
  761. bool isPhysical = (((rootObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0) && m_physicalPrim);
  762. bool isPhantom = ((rootObjectFlags & (uint) LLObject.ObjectFlags.Phantom) != 0);
  763. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  764. bool RigidBody = isPhysical && !isPhantom;
  765. // The only time the physics scene shouldn't know about the prim is if it's phantom
  766. if (!isPhantom)
  767. {
  768. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  769. Name,
  770. Shape,
  771. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  772. AbsolutePosition.Z),
  773. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  774. new Quaternion(RotationOffset.W, RotationOffset.X,
  775. RotationOffset.Y, RotationOffset.Z), RigidBody);
  776. // Basic Physics returns null.. joy joy joy.
  777. if (PhysActor != null)
  778. {
  779. PhysActor.LocalID = LocalId;
  780. DoPhysicsPropertyUpdate(RigidBody, true);
  781. }
  782. }
  783. }
  784. public void TrimPermissions()
  785. {
  786. BaseMask &= (uint)PermissionMask.All;
  787. OwnerMask &= (uint)PermissionMask.All;
  788. GroupMask &= (uint)PermissionMask.All;
  789. EveryoneMask &= (uint)PermissionMask.All;
  790. NextOwnerMask &= (uint)PermissionMask.All;
  791. }
  792. /// <summary>
  793. /// Serialize this part to xml.
  794. /// </summary>
  795. /// <param name="xmlWriter"></param>
  796. public void ToXml(XmlWriter xmlWriter)
  797. {
  798. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  799. serializer.Serialize(xmlWriter, this);
  800. }
  801. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  802. {
  803. // In this case we're using a sphere with a radius of the largest dimention of the prim
  804. // TODO: Change to take shape into account
  805. EntityIntersection returnresult = new EntityIntersection();
  806. Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z);
  807. Vector3 vScale = new Vector3(Scale.X, Scale.Y, Scale.Z);
  808. Quaternion qRotation =
  809. new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
  810. //Quaternion worldRotation = (qRotation*parentrot);
  811. //Matrix3 worldRotM = worldRotation.ToRotationMatrix();
  812. Vector3 rOrigin = iray.Origin;
  813. Vector3 rDirection = iray.Direction;
  814. //rDirection = rDirection.Normalize();
  815. // Buidling the first part of the Quadratic equation
  816. Vector3 r2ndDirection = rDirection*rDirection;
  817. float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z;
  818. // Buidling the second part of the Quadratic equation
  819. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  820. Vector3 r2Direction = rDirection*2.0f;
  821. Vector3 tmVal3 = r2Direction*tmVal2;
  822. float itestPart2 = tmVal3.x + tmVal3.y + tmVal3.z;
  823. // Buidling the third part of the Quadratic equation
  824. Vector3 tmVal4 = rOrigin*rOrigin;
  825. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  826. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  827. // Set Radius to the largest dimention of the prim
  828. float radius = 0f;
  829. if (vScale.x > radius)
  830. radius = vScale.x;
  831. if (vScale.y > radius)
  832. radius = vScale.y;
  833. if (vScale.z > radius)
  834. radius = vScale.z;
  835. // the second part of this is the default prim size
  836. // once we factor in the aabb of the prim we're adding we can
  837. // change this to;
  838. // radius = (radius / 2) - 0.01f;
  839. //
  840. radius = (radius / 2) + (0.5f / 2) - 0.1f;
  841. //radius = radius;
  842. float itestPart3 = tmVal4.x + tmVal4.y + tmVal4.z + tmVal5.x + tmVal5.y + tmVal5.z -
  843. (2.0f*(tmVal6.x + tmVal6.y + tmVal6.z + (radius*radius)));
  844. // Yuk Quadradrics.. Solve first
  845. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  846. if (rootsqr < 0.0f)
  847. {
  848. // No intersection
  849. return returnresult;
  850. }
  851. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  852. if (root < 0.0f)
  853. {
  854. // perform second quadratic root solution
  855. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  856. // is there any intersection?
  857. if (root < 0.0f)
  858. {
  859. // nope, no intersection
  860. return returnresult;
  861. }
  862. }
  863. // We got an intersection. putting together an EntityIntersection object with the
  864. // intersection information
  865. Vector3 ipoint =
  866. new Vector3(iray.Origin.x + (iray.Direction.x*root), iray.Origin.y + (iray.Direction.y*root),
  867. iray.Origin.z + (iray.Direction.z*root));
  868. returnresult.HitTF = true;
  869. returnresult.ipoint = ipoint;
  870. // Normal is calculated by the difference and then normalizing the result
  871. Vector3 normalpart = ipoint - vAbsolutePosition;
  872. returnresult.normal = normalpart / normalpart.Length;
  873. // It's funny how the LLVector3 object has a Distance function, but the Axiom.Math object doesnt.
  874. // I can write a function to do it.. but I like the fact that this one is Static.
  875. LLVector3 distanceConvert1 = new LLVector3(iray.Origin.x, iray.Origin.y, iray.Origin.z);
  876. LLVector3 distanceConvert2 = new LLVector3(ipoint.x, ipoint.y, ipoint.z);
  877. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  878. returnresult.distance = distance;
  879. return returnresult;
  880. }
  881. public double GetDistanceTo(Vector3 a, Vector3 b)
  882. {
  883. float dx = a.x - b.x;
  884. float dy = a.y - b.y;
  885. float dz = a.z - b.z;
  886. return Math.Sqrt(dx * dx + dy * dy + dz * dz);
  887. }
  888. public EntityIntersection TestIntersectionOBB(Ray iray, Quaternion parentrot, bool frontFacesOnly, bool faceCenters)
  889. {
  890. // In this case we're using a rectangular prism, which has 6 faces and therefore 6 planes
  891. // This breaks down into the ray---> plane equation.
  892. // TODO: Change to take shape into account
  893. Vector3[] vertexes = new Vector3[8];
  894. float[] distance = new float[6];
  895. Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
  896. Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
  897. Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
  898. Vector3[] FaceD = new Vector3[6]; // vertex D for Facei
  899. Vector3[] normals = new Vector3[6]; // Normal for Facei
  900. Vector3[] AAfacenormals = new Vector3[6]; // Axis Aligned face normals
  901. AAfacenormals[0] = new Vector3(1, 0, 0);
  902. AAfacenormals[1] = new Vector3(0, 1, 0);
  903. AAfacenormals[2] = new Vector3(-1, 0, 0);
  904. AAfacenormals[3] = new Vector3(0, -1, 0);
  905. AAfacenormals[4] = new Vector3(0, 0, 1);
  906. AAfacenormals[5] = new Vector3(0, 0, -1);
  907. Vector3 AmBa = new Vector3(0, 0, 0); // Vertex A - Vertex B
  908. Vector3 AmBb = new Vector3(0, 0, 0); // Vertex B - Vertex C
  909. Vector3 cross = new Vector3();
  910. LLVector3 pos = GetWorldPosition();
  911. LLQuaternion rot = GetWorldRotation();
  912. // Variables prefixed with AX are Axiom.Math copies of the LL variety.
  913. Quaternion AXrot = new Quaternion(rot.W,rot.X,rot.Y,rot.Z);
  914. AXrot.Normalize();
  915. Vector3 AXpos = new Vector3(pos.X, pos.Y, pos.Z);
  916. // tScale is the offset to derive the vertex based on the scale.
  917. // it's different for each vertex because we've got to rotate it
  918. // to get the world position of the vertex to produce the Oriented Bounding Box
  919. Vector3 tScale = new Vector3();
  920. Vector3 AXscale = new Vector3(m_shape.Scale.X * 0.5f, m_shape.Scale.Y * 0.5f, m_shape.Scale.Z * 0.5f);
  921. //Vector3 pScale = (AXscale) - (AXrot.Inverse() * (AXscale));
  922. //Vector3 nScale = (AXscale * -1) - (AXrot.Inverse() * (AXscale * -1));
  923. // rScale is the rotated offset to find a vertex based on the scale and the world rotation.
  924. Vector3 rScale = new Vector3();
  925. // Get Vertexes for Faces Stick them into ABCD for each Face
  926. // Form: Face<vertex>[face] that corresponds to the below diagram
  927. #region ABCD Face Vertex Map Comment Diagram
  928. // A _________ B
  929. // | |
  930. // | 4 top |
  931. // |_________|
  932. // C D
  933. // A _________ B
  934. // | Back |
  935. // | 3 |
  936. // |_________|
  937. // C D
  938. // A _________ B B _________ A
  939. // | Left | | Right |
  940. // | 0 | | 2 |
  941. // |_________| |_________|
  942. // C D D C
  943. // A _________ B
  944. // | Front |
  945. // | 1 |
  946. // |_________|
  947. // C D
  948. // C _________ D
  949. // | |
  950. // | 5 bot |
  951. // |_________|
  952. // A B
  953. #endregion
  954. #region Plane Decomposition of Oriented Bounding Box
  955. tScale = new Vector3(AXscale.x, -AXscale.y, AXscale.z);
  956. rScale = ((AXrot * tScale));
  957. vertexes[0] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  958. // vertexes[0].x = pos.X + vertexes[0].x;
  959. //vertexes[0].y = pos.Y + vertexes[0].y;
  960. //vertexes[0].z = pos.Z + vertexes[0].z;
  961. FaceA[0] = vertexes[0];
  962. FaceB[3] = vertexes[0];
  963. FaceA[4] = vertexes[0];
  964. tScale = AXscale;
  965. rScale = ((AXrot * tScale));
  966. vertexes[1] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  967. // vertexes[1].x = pos.X + vertexes[1].x;
  968. // vertexes[1].y = pos.Y + vertexes[1].y;
  969. //vertexes[1].z = pos.Z + vertexes[1].z;
  970. FaceB[0] = vertexes[1];
  971. FaceA[1] = vertexes[1];
  972. FaceC[4] = vertexes[1];
  973. tScale = new Vector3(AXscale.x, -AXscale.y, -AXscale.z);
  974. rScale = ((AXrot * tScale));
  975. vertexes[2] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  976. //vertexes[2].x = pos.X + vertexes[2].x;
  977. //vertexes[2].y = pos.Y + vertexes[2].y;
  978. //vertexes[2].z = pos.Z + vertexes[2].z;
  979. FaceC[0] = vertexes[2];
  980. FaceD[3] = vertexes[2];
  981. FaceC[5] = vertexes[2];
  982. tScale = new Vector3(AXscale.x, AXscale.y, -AXscale.z);
  983. rScale = ((AXrot * tScale));
  984. vertexes[3] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  985. //vertexes[3].x = pos.X + vertexes[3].x;
  986. // vertexes[3].y = pos.Y + vertexes[3].y;
  987. // vertexes[3].z = pos.Z + vertexes[3].z;
  988. FaceD[0] = vertexes[3];
  989. FaceC[1] = vertexes[3];
  990. FaceA[5] = vertexes[3];
  991. tScale = new Vector3(-AXscale.x, AXscale.y, AXscale.z);
  992. rScale = ((AXrot * tScale));
  993. vertexes[4] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  994. // vertexes[4].x = pos.X + vertexes[4].x;
  995. // vertexes[4].y = pos.Y + vertexes[4].y;
  996. // vertexes[4].z = pos.Z + vertexes[4].z;
  997. FaceB[1] = vertexes[4];
  998. FaceA[2] = vertexes[4];
  999. FaceD[4] = vertexes[4];
  1000. tScale = new Vector3(-AXscale.x, AXscale.y, -AXscale.z);
  1001. rScale = ((AXrot * tScale));
  1002. vertexes[5] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  1003. // vertexes[5].x = pos.X + vertexes[5].x;
  1004. // vertexes[5].y = pos.Y + vertexes[5].y;
  1005. // vertexes[5].z = pos.Z + vertexes[5].z;
  1006. FaceD[1] = vertexes[5];
  1007. FaceC[2] = vertexes[5];
  1008. FaceB[5] = vertexes[5];
  1009. tScale = new Vector3(-AXscale.x, -AXscale.y, AXscale.z);
  1010. rScale = ((AXrot * tScale));
  1011. vertexes[6] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  1012. // vertexes[6].x = pos.X + vertexes[6].x;
  1013. // vertexes[6].y = pos.Y + vertexes[6].y;
  1014. // vertexes[6].z = pos.Z + vertexes[6].z;
  1015. FaceB[2] = vertexes[6];
  1016. FaceA[3] = vertexes[6];
  1017. FaceB[4] = vertexes[6];
  1018. tScale = new Vector3(-AXscale.x, -AXscale.y, -AXscale.z);
  1019. rScale = ((AXrot * tScale));
  1020. vertexes[7] = (new Vector3((pos.X + rScale.x), (pos.Y + rScale.y), (pos.Z + rScale.z)));
  1021. // vertexes[7].x = pos.X + vertexes[7].x;
  1022. // vertexes[7].y = pos.Y + vertexes[7].y;
  1023. // vertexes[7].z = pos.Z + vertexes[7].z;
  1024. FaceD[2] = vertexes[7];
  1025. FaceC[3] = vertexes[7];
  1026. FaceD[5] = vertexes[7];
  1027. #endregion
  1028. // Get our plane normals
  1029. for (int i = 0; i < 6; i++)
  1030. {
  1031. //m_log.Info("[FACECALCULATION]: FaceA[" + i + "]=" + FaceA[i] + " FaceB[" + i + "]=" + FaceB[i] + " FaceC[" + i + "]=" + FaceC[i] + " FaceD[" + i + "]=" + FaceD[i]);
  1032. // Our Plane direction
  1033. AmBa = FaceA[i] - FaceB[i];
  1034. AmBb = FaceB[i] - FaceC[i];
  1035. cross = AmBb.Cross(AmBa);
  1036. // normalize the cross product to get the normal.
  1037. normals[i] = cross / cross.Length;
  1038. //m_log.Info("[NORMALS]: normals[ " + i + "]" + normals[i].ToString());
  1039. //distance[i] = (normals[i].x * AmBa.x + normals[i].y * AmBa.y + normals[i].z * AmBa.z) * -1;
  1040. }
  1041. EntityIntersection returnresult = new EntityIntersection();
  1042. returnresult.distance = 1024;
  1043. float c = 0;
  1044. float a = 0;
  1045. float d = 0;
  1046. Vector3 q = new Vector3();
  1047. #region OBB Version 2 Experiment
  1048. //float fmin = 999999;
  1049. //float fmax = -999999;
  1050. //float s = 0;
  1051. //for (int i=0;i<6;i++)
  1052. //{
  1053. //s = iray.Direction.Dot(normals[i]);
  1054. //d = normals[i].Dot(FaceB[i]);
  1055. //if (s == 0)
  1056. //{
  1057. //if (iray.Origin.Dot(normals[i]) > d)
  1058. //{
  1059. //return returnresult;
  1060. //}
  1061. // else
  1062. //{
  1063. //continue;
  1064. //}
  1065. //}
  1066. //a = (d - iray.Origin.Dot(normals[i])) / s;
  1067. //if (iray.Direction.Dot(normals[i]) < 0)
  1068. //{
  1069. //if (a > fmax)
  1070. //{
  1071. //if (a > fmin)
  1072. //{
  1073. //return returnresult;
  1074. //}
  1075. //fmax = a;
  1076. //}
  1077. //}
  1078. //else
  1079. //{
  1080. //if (a < fmin)
  1081. //{
  1082. //if (a < 0 || a < fmax)
  1083. //{
  1084. //return returnresult;
  1085. //}
  1086. //fmin = a;
  1087. //}
  1088. //}
  1089. //}
  1090. //if (fmax > 0)
  1091. // a= fmax;
  1092. //else
  1093. // a=fmin;
  1094. //q = iray.Origin + a * iray.Direction;
  1095. #endregion
  1096. // Loop over faces (6 of them)
  1097. for (int i = 0; i < 6; i++)
  1098. {
  1099. AmBa = FaceA[i] - FaceB[i];
  1100. AmBb = FaceB[i] - FaceC[i];
  1101. d = normals[i].Dot(FaceB[i]);
  1102. if (faceCenters)
  1103. {
  1104. c = normals[i].Dot(normals[i]);
  1105. }
  1106. else
  1107. {
  1108. c = iray.Direction.Dot(normals[i]);
  1109. }
  1110. if (c == 0)
  1111. continue;
  1112. a = (d - iray.Origin.Dot(normals[i])) / c;
  1113. if (a < 0)
  1114. continue;
  1115. // If the normal is pointing outside the object
  1116. if (iray.Direction.Dot(normals[i]) < 0 || !frontFacesOnly)
  1117. {
  1118. if (faceCenters)
  1119. { //(FaceA[i] + FaceB[i] + FaceC[1] + FaceD[i]) / 4f;
  1120. q = iray.Origin + a * normals[i];
  1121. }
  1122. else
  1123. {
  1124. q = iray.Origin + a * iray.Direction;
  1125. }
  1126. float distance2 = (float)GetDistanceTo(q, AXpos);
  1127. // Is this the closest hit to the object's origin?
  1128. if (faceCenters)
  1129. {
  1130. distance2 = (float)GetDistanceTo(q, iray.Origin);
  1131. }
  1132. if (distance2 < returnresult.distance)
  1133. {
  1134. returnresult.distance = distance2;
  1135. returnresult.HitTF = true;
  1136. returnresult.ipoint = q;
  1137. m_log.Info("[FACE]:" + i.ToString());
  1138. m_log.Info("[POINT]: " + q.ToString());
  1139. m_log.Info("[DIST]: " + distance2.ToString());
  1140. returnresult.normal = normals[i];
  1141. returnresult.AAfaceNormal = AAfacenormals[i];
  1142. }
  1143. }
  1144. }
  1145. return returnresult;
  1146. }
  1147. // Use this for attachments! LocalID should be avatar's localid
  1148. public void SetParentLocalId(uint localID)
  1149. {
  1150. ParentID = localID;
  1151. }
  1152. public void SetAttachmentPoint(uint AttachmentPoint)
  1153. {
  1154. m_attachmentPoint = AttachmentPoint;
  1155. // save the attachment point.
  1156. //if (AttachmentPoint != 0)
  1157. //{
  1158. m_shape.State = (byte)AttachmentPoint;
  1159. //}
  1160. }
  1161. /// <summary>
  1162. ///
  1163. /// </summary>
  1164. public void SetParent(SceneObjectGroup parent)
  1165. {
  1166. m_parentGroup = parent;
  1167. }
  1168. public void SetSitTarget(Vector3 offset, Quaternion orientation)
  1169. {
  1170. m_sitTargetPosition = offset;
  1171. m_sitTargetOrientation = orientation;
  1172. }
  1173. public void SetBuoyancy(float fvalue)
  1174. {
  1175. if (PhysActor != null)
  1176. {
  1177. PhysActor.Buoyancy = fvalue;
  1178. }
  1179. }
  1180. public void SetAxisRotation(int axis, int rotate)
  1181. {
  1182. if (m_parentGroup != null)
  1183. {
  1184. m_parentGroup.SetAxisRotation(axis, rotate);
  1185. }
  1186. }
  1187. public void SetPhysicsAxisRotation()
  1188. {
  1189. PhysActor.LockAngularMotion(m_rotationAxis);
  1190. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1191. }
  1192. public void SetFloatOnWater(int floatYN)
  1193. {
  1194. if (PhysActor != null)
  1195. {
  1196. if (floatYN == 1)
  1197. {
  1198. PhysActor.FloatOnWater = true;
  1199. }
  1200. else
  1201. {
  1202. PhysActor.FloatOnWater = false;
  1203. }
  1204. }
  1205. }
  1206. public LLVector3 GetSitTargetPositionLL()
  1207. {
  1208. return new LLVector3(m_sitTargetPosition.x, m_sitTargetPosition.y, m_sitTargetPosition.z);
  1209. }
  1210. public LLQuaternion GetSitTargetOrientationLL()
  1211. {
  1212. return
  1213. new LLQuaternion(m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z,
  1214. m_sitTargetOrientation.w);
  1215. }
  1216. // Utility function so the databases don't have to reference axiom.math
  1217. public void SetSitTargetLL(LLVector3 offset, LLQuaternion orientation)
  1218. {
  1219. if (
  1220. !(offset.X == 0 && offset.Y == 0 && offset.Z == 0 && (orientation.W == 0 || orientation.W == 1) &&
  1221. orientation.X == 0 && orientation.Y == 0 && orientation.Z == 0))
  1222. {
  1223. m_sitTargetPosition = new Vector3(offset.X, offset.Y, offset.Z);
  1224. m_sitTargetOrientation = new Quaternion(orientation.W, orientation.X, orientation.Y, orientation.Z);
  1225. }
  1226. }
  1227. public Vector3 GetSitTargetPosition()
  1228. {
  1229. return m_sitTargetPosition;
  1230. }
  1231. public Quaternion GetSitTargetOrientation()
  1232. {
  1233. return m_sitTargetOrientation;
  1234. }
  1235. public void SetAvatarOnSitTarget(LLUUID avatarID)
  1236. {
  1237. m_sitTargetAvatar = avatarID;
  1238. TriggerScriptChangedEvent(Changed.LINK);
  1239. }
  1240. public LLUUID GetAvatarOnSitTarget()
  1241. {
  1242. return m_sitTargetAvatar;
  1243. }
  1244. public LLUUID GetRootPartUUID()
  1245. {
  1246. if (m_parentGroup != null)
  1247. {
  1248. return m_parentGroup.UUID;
  1249. }
  1250. return LLUUID.Zero;
  1251. }
  1252. public static SceneObjectPart Create()
  1253. {
  1254. SceneObjectPart part = new SceneObjectPart();
  1255. part.UUID = LLUUID.Random();
  1256. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  1257. part.Shape = shape;
  1258. part.Name = "Primitive";
  1259. part.OwnerID = LLUUID.Random();
  1260. return part;
  1261. }
  1262. #region Copying
  1263. /// <summary>
  1264. /// Duplicates this part.
  1265. /// </summary>
  1266. /// <returns></returns>
  1267. public SceneObjectPart Copy(uint localID, LLUUID AgentID, LLUUID GroupID, int linkNum, bool userExposed)
  1268. {
  1269. SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone();
  1270. dupe.m_shape = m_shape.Copy();
  1271. dupe.m_regionHandle = m_regionHandle;
  1272. if (userExposed)
  1273. dupe.UUID = LLUUID.Random();
  1274. dupe.LocalId = localID;
  1275. dupe.OwnerID = AgentID;
  1276. dupe.GroupID = GroupID;
  1277. dupe.GroupPosition = new LLVector3(GroupPosition.X, GroupPosition.Y, GroupPosition.Z);
  1278. dupe.OffsetPosition = new LLVector3(OffsetPosition.X, OffsetPosition.Y, OffsetPosition.Z);
  1279. dupe.RotationOffset =
  1280. new LLQuaternion(RotationOffset.X, RotationOffset.Y, RotationOffset.Z, RotationOffset.W);
  1281. dupe.Velocity = new LLVector3(0, 0, 0);
  1282. dupe.Acceleration = new LLVector3(0, 0, 0);
  1283. dupe.AngularVelocity = new LLVector3(0, 0, 0);
  1284. dupe.ObjectFlags = ObjectFlags;
  1285. dupe.OwnershipCost = OwnershipCost;
  1286. dupe.ObjectSaleType = ObjectSaleType;
  1287. dupe.SalePrice = SalePrice;
  1288. dupe.Category = Category;
  1289. dupe.TaskInventory = (TaskInventoryDictionary)dupe.TaskInventory.Clone();
  1290. if (userExposed)
  1291. dupe.ResetIDs(linkNum);
  1292. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  1293. dupe.LastOwnerID = ObjectOwner;
  1294. byte[] extraP = new byte[Shape.ExtraParams.Length];
  1295. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  1296. dupe.Shape.ExtraParams = extraP;
  1297. if (userExposed)
  1298. {
  1299. if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != LLUUID.Zero)
  1300. {
  1301. m_parentGroup.Scene.AssetCache.GetAsset(dupe.m_shape.SculptTexture, dupe.SculptTextureCallback, true);
  1302. }
  1303. bool UsePhysics = ((dupe.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) != 0);
  1304. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  1305. }
  1306. return dupe;
  1307. }
  1308. #endregion
  1309. /// <summary>
  1310. /// Reset LLUUIDs for this part. This involves generate this part's own LLUUID and
  1311. /// generating new LLUUIDs for all the items in the inventory.
  1312. /// </summary>
  1313. /// <param name="linkNum">Link number for the part</param>
  1314. public void ResetIDs(int linkNum)
  1315. {
  1316. UUID = LLUUID.Random();
  1317. LinkNum = linkNum;
  1318. ResetInventoryIDs();
  1319. }
  1320. #region Update Scheduling
  1321. /// <summary>
  1322. /// Clear all pending updates
  1323. /// </summary>
  1324. private void ClearUpdateSchedule()
  1325. {
  1326. m_updateFlag = 0;
  1327. }
  1328. /// <summary>
  1329. /// Schedules this prim for a full update
  1330. /// </summary>
  1331. public void ScheduleFullUpdate()
  1332. {
  1333. if (m_parentGroup != null)
  1334. {
  1335. m_parentGroup.HasGroupChanged = true;
  1336. m_parentGroup.QueueForUpdateCheck();
  1337. }
  1338. int timeNow = Util.UnixTimeSinceEpoch();
  1339. // If multiple updates are scheduled on the same second, we still need to perform all of them
  1340. // So we'll force the issue by bumping up the timestamp so that later processing sees these need
  1341. // to be performed.
  1342. if (timeNow <= TimeStampFull)
  1343. {
  1344. TimeStampFull += 1;
  1345. }
  1346. else
  1347. {
  1348. TimeStampFull = (uint)timeNow;
  1349. }
  1350. m_updateFlag = 2;
  1351. // m_log.DebugFormat(
  1352. // "[SCENE OBJECT PART]: Scheduling full update for {0}, {1} at {2}",
  1353. // UUID, Name, TimeStampFull);
  1354. }
  1355. public void AddFlag(LLObject.ObjectFlags flag)
  1356. {
  1357. LLObject.ObjectFlags prevflag = Flags;
  1358. //uint objflags = Flags;
  1359. if ((ObjectFlags & (uint) flag) == 0)
  1360. {
  1361. //Console.WriteLine("Adding flag: " + ((LLObject.ObjectFlags) flag).ToString());
  1362. Flags |= flag;
  1363. }
  1364. //uint currflag = (uint)Flags;
  1365. //System.Console.WriteLine("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1366. //ScheduleFullUpdate();
  1367. }
  1368. public void RemFlag(LLObject.ObjectFlags flag)
  1369. {
  1370. LLObject.ObjectFlags prevflag = Flags;
  1371. if ((ObjectFlags & (uint) flag) != 0)
  1372. {
  1373. //Console.WriteLine("Removing flag: " + ((LLObject.ObjectFlags)flag).ToString());
  1374. Flags &= ~flag;
  1375. }
  1376. //System.Console.WriteLine("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  1377. //ScheduleFullUpdate();
  1378. }
  1379. /// <summary>
  1380. /// Schedule a terse update for this prim. Terse updates only send position,
  1381. /// rotation, velocity, rotational velocity and shape information.
  1382. /// </summary>
  1383. public void ScheduleTerseUpdate()
  1384. {
  1385. if (m_updateFlag < 1)
  1386. {
  1387. if (m_parentGroup != null)
  1388. {
  1389. m_parentGroup.HasGroupChanged = true;
  1390. m_parentGroup.QueueForUpdateCheck();
  1391. }
  1392. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  1393. m_updateFlag = 1;
  1394. // m_log.DebugFormat(
  1395. // "[SCENE OBJECT PART]: Scheduling terse update for {0}, {1} at {2}",
  1396. // UUID, Name, TimeStampTerse);
  1397. }
  1398. }
  1399. /// <summary>
  1400. /// Tell all the prims which have had updates scheduled
  1401. /// </summary>
  1402. public void SendScheduledUpdates()
  1403. {
  1404. if (m_updateFlag == 1) //some change has been made so update the clients
  1405. {
  1406. AddTerseUpdateToAllAvatars();
  1407. ClearUpdateSchedule();
  1408. // This causes the Scene to 'poll' physical objects every couple of frames
  1409. // bad, so it's been replaced by an event driven method.
  1410. //if ((ObjectFlags & (uint)LLObject.ObjectFlags.Physics) != 0)
  1411. //{
  1412. // Only send the constant terse updates on physical objects!
  1413. //ScheduleTerseUpdate();
  1414. //}
  1415. }
  1416. else
  1417. {
  1418. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  1419. {
  1420. AddFullUpdateToAllAvatars();
  1421. ClearUpdateSchedule();
  1422. }
  1423. }
  1424. }
  1425. #endregion
  1426. #region Shape
  1427. /// <summary>
  1428. ///
  1429. /// </summary>
  1430. /// <param name="shapeBlock"></param>
  1431. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  1432. {
  1433. m_shape.PathBegin = shapeBlock.PathBegin;
  1434. m_shape.PathEnd = shapeBlock.PathEnd;
  1435. m_shape.PathScaleX = shapeBlock.PathScaleX;
  1436. m_shape.PathScaleY = shapeBlock.PathScaleY;
  1437. m_shape.PathShearX = shapeBlock.PathShearX;
  1438. m_shape.PathShearY = shapeBlock.PathShearY;
  1439. m_shape.PathSkew = shapeBlock.PathSkew;
  1440. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  1441. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  1442. m_shape.PathCurve = shapeBlock.PathCurve;
  1443. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  1444. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  1445. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  1446. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  1447. m_shape.PathTaperX = shapeBlock.PathTaperX;
  1448. m_shape.PathTaperY = shapeBlock.PathTaperY;
  1449. m_shape.PathTwist = shapeBlock.PathTwist;
  1450. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  1451. if (PhysActor != null)
  1452. {
  1453. PhysActor.Shape = m_shape;
  1454. }
  1455. ScheduleFullUpdate();
  1456. }
  1457. #endregion
  1458. #region ExtraParams
  1459. public void UpdatePrimFlags(ushort type, bool inUse, byte[] data)
  1460. {
  1461. //m_log.Info("TSomething1:" + ((type & (ushort)ExtraParamType.Something1) == (ushort)ExtraParamType.Something1));
  1462. //m_log.Info("TSomething2:" + ((type & (ushort)ExtraParamType.Something2) == (ushort)ExtraParamType.Something2));
  1463. //m_log.Info("TSomething3:" + ((type & (ushort)ExtraParamType.Something3) == (ushort)ExtraParamType.Something3));
  1464. //m_log.Info("TSomething4:" + ((type & (ushort)ExtraParamType.Something4) == (ushort)ExtraParamType.Something4));
  1465. //m_log.Info("TSomething5:" + ((type & (ushort)ExtraParamType.Something5) == (ushort)ExtraParamType.Something5));
  1466. //m_log.Info("TSomething6:" + ((type & (ushort)ExtraParamType.Something6) == (ushort)ExtraParamType.Something6));
  1467. bool usePhysics = false;
  1468. bool IsTemporary = false;
  1469. bool IsPhantom = false;
  1470. bool castsShadows = false;
  1471. bool wasUsingPhysics = ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
  1472. //bool IsLocked = false;
  1473. int i = 0;
  1474. try
  1475. {
  1476. i += 46;
  1477. //IsLocked = (data[i++] != 0) ? true : false;
  1478. usePhysics = ((data[i++] != 0) && m_parentGroup.Scene.m_physicalPrim) ? true : false;
  1479. //System.Console.WriteLine("U" + packet.ToBytes().Length.ToString());
  1480. IsTemporary = (data[i++] != 0) ? true : false;
  1481. IsPhantom = (data[i++] != 0) ? true : false;
  1482. castsShadows = (data[i++] != 0) ? true : false;
  1483. }
  1484. catch (Exception)
  1485. {
  1486. Console.WriteLine("Ignoring invalid Packet:");
  1487. //Silently ignore it - TODO: FIXME Quick
  1488. }
  1489. if (usePhysics)
  1490. {
  1491. AddFlag(LLObject.ObjectFlags.Physics);
  1492. if (!wasUsingPhysics)
  1493. {
  1494. DoPhysicsPropertyUpdate(usePhysics, false);
  1495. if (m_parentGroup != null)
  1496. {
  1497. if (m_parentGroup.RootPart != null)
  1498. {
  1499. if (LocalId == m_parentGroup.RootPart.LocalId)
  1500. {
  1501. m_parentGroup.CheckSculptAndLoad();
  1502. }
  1503. }
  1504. }
  1505. }
  1506. }
  1507. else
  1508. {
  1509. RemFlag(LLObject.ObjectFlags.Physics);
  1510. if (wasUsingPhysics)
  1511. {
  1512. DoPhysicsPropertyUpdate(usePhysics, false);
  1513. }
  1514. }
  1515. if (IsPhantom)
  1516. {
  1517. AddFlag(LLObject.ObjectFlags.Phantom);
  1518. if (PhysActor != null)
  1519. {
  1520. m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1521. /// that's not wholesome. Had to make Scene public
  1522. PhysActor = null;
  1523. }
  1524. }
  1525. else
  1526. {
  1527. RemFlag(LLObject.ObjectFlags.Phantom);
  1528. if (PhysActor == null)
  1529. {
  1530. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1531. Name,
  1532. Shape,
  1533. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1534. AbsolutePosition.Z),
  1535. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1536. new Quaternion(RotationOffset.W, RotationOffset.X,
  1537. RotationOffset.Y, RotationOffset.Z), usePhysics);
  1538. if (PhysActor != null)
  1539. {
  1540. PhysActor.LocalID = LocalId;
  1541. DoPhysicsPropertyUpdate(usePhysics, true);
  1542. if (m_parentGroup != null)
  1543. {
  1544. if (m_parentGroup.RootPart != null)
  1545. {
  1546. if (LocalId == m_parentGroup.RootPart.LocalId)
  1547. {
  1548. m_parentGroup.CheckSculptAndLoad();
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. else
  1555. {
  1556. PhysActor.IsPhysical = usePhysics;
  1557. DoPhysicsPropertyUpdate(usePhysics, false);
  1558. if (m_parentGroup != null)
  1559. {
  1560. if (m_parentGroup.RootPart != null)
  1561. {
  1562. if (LocalId == m_parentGroup.RootPart.LocalId)
  1563. {
  1564. m_parentGroup.CheckSculptAndLoad();
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. if (IsTemporary)
  1571. {
  1572. AddFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1573. }
  1574. else
  1575. {
  1576. RemFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1577. }
  1578. // System.Console.WriteLine("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  1579. ScheduleFullUpdate();
  1580. }
  1581. public void ScriptSetPhysicsStatus(bool UsePhysics)
  1582. {
  1583. if (m_parentGroup != null)
  1584. {
  1585. m_parentGroup.ScriptSetPhysicsStatus(UsePhysics);
  1586. }
  1587. }
  1588. public void ScriptSetPhantomStatus(bool Phantom)
  1589. {
  1590. if (m_parentGroup != null)
  1591. {
  1592. m_parentGroup.ScriptSetPhantomStatus(Phantom);
  1593. }
  1594. }
  1595. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1596. {
  1597. if (PhysActor != null)
  1598. {
  1599. if (UsePhysics != PhysActor.IsPhysical || isNew)
  1600. {
  1601. if (PhysActor.IsPhysical)
  1602. {
  1603. if (!isNew)
  1604. ParentGroup.Scene.RemovePhysicalPrim(1);
  1605. PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1606. PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
  1607. PhysActor.delink();
  1608. }
  1609. PhysActor.IsPhysical = UsePhysics;
  1610. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1611. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1612. /// that's not wholesome. Had to make Scene public
  1613. //PhysActor = null;
  1614. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
  1615. {
  1616. //PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1617. //Name,
  1618. //Shape,
  1619. //new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1620. //AbsolutePosition.Z),
  1621. //new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1622. //new Quaternion(RotationOffset.W, RotationOffset.X,
  1623. //RotationOffset.Y, RotationOffset.Z), UsePhysics);
  1624. if (UsePhysics)
  1625. {
  1626. ParentGroup.Scene.AddPhysicalPrim(1);
  1627. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1628. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  1629. if (ParentID != 0 && ParentID != LocalId)
  1630. {
  1631. if (ParentGroup.RootPart.PhysActor != null)
  1632. {
  1633. PhysActor.link(ParentGroup.RootPart.PhysActor);
  1634. }
  1635. }
  1636. }
  1637. }
  1638. }
  1639. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1640. }
  1641. }
  1642. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  1643. {
  1644. m_shape.ReadInUpdateExtraParam(type, inUse, data);
  1645. if (type == 0x30)
  1646. {
  1647. if (m_shape.SculptEntry && m_shape.SculptTexture != LLUUID.Zero)
  1648. {
  1649. //AssetBase tx = m_parentGroup.Scene.getase
  1650. m_parentGroup.Scene.AssetCache.GetAsset(m_shape.SculptTexture, SculptTextureCallback, true);
  1651. }
  1652. }
  1653. ScheduleFullUpdate();
  1654. }
  1655. public void SculptTextureCallback(LLUUID textureID, AssetBase texture)
  1656. {
  1657. if (m_shape.SculptEntry)
  1658. {
  1659. if (texture != null)
  1660. {
  1661. m_shape.SculptData = texture.Data;
  1662. if (PhysActor != null)
  1663. {
  1664. // Tricks physics engine into thinking we've changed the part shape.
  1665. PrimitiveBaseShape m_newshape = m_shape.Copy();
  1666. PhysActor.Shape = m_newshape;
  1667. m_shape = m_newshape;
  1668. }
  1669. }
  1670. }
  1671. }
  1672. #endregion
  1673. #region Physics
  1674. public float GetMass()
  1675. {
  1676. if (PhysActor != null)
  1677. {
  1678. return PhysActor.Mass;
  1679. }
  1680. else
  1681. {
  1682. return 0;
  1683. }
  1684. }
  1685. public LLVector3 GetGeometricCenter()
  1686. {
  1687. if (PhysActor != null)
  1688. {
  1689. return new LLVector3(PhysActor.CenterOfMass.X, PhysActor.CenterOfMass.Y, PhysActor.CenterOfMass.Z);
  1690. }
  1691. else
  1692. {
  1693. return new LLVector3(0, 0, 0);
  1694. }
  1695. }
  1696. #endregion
  1697. #region Texture
  1698. /// <summary>
  1699. ///
  1700. /// </summary>
  1701. /// <param name="textureEntry"></param>
  1702. public void UpdateTextureEntry(byte[] textureEntry)
  1703. {
  1704. m_shape.TextureEntry = textureEntry;
  1705. TriggerScriptChangedEvent(Changed.TEXTURE);
  1706. ScheduleFullUpdate();
  1707. }
  1708. // Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  1709. // not handling RGBA properly. Cycles through, and "fixes" the color
  1710. // info
  1711. public void UpdateTexture(LLObject.TextureEntry tex)
  1712. {
  1713. //LLColor tmpcolor;
  1714. //for (uint i = 0; i < 32; i++)
  1715. //{
  1716. // if (tex.FaceTextures[i] != null)
  1717. // {
  1718. // tmpcolor = tex.GetFace((uint) i).RGBA;
  1719. // tmpcolor.A = tmpcolor.A*255;
  1720. // tmpcolor.R = tmpcolor.R*255;
  1721. // tmpcolor.G = tmpcolor.G*255;
  1722. // tmpcolor.B = tmpcolor.B*255;
  1723. // tex.FaceTextures[i].RGBA = tmpcolor;
  1724. // }
  1725. //}
  1726. //tmpcolor = tex.DefaultTexture.RGBA;
  1727. //tmpcolor.A = tmpcolor.A*255;
  1728. //tmpcolor.R = tmpcolor.R*255;
  1729. //tmpcolor.G = tmpcolor.G*255;
  1730. //tmpcolor.B = tmpcolor.B*255;
  1731. //tex.DefaultTexture.RGBA = tmpcolor;
  1732. UpdateTextureEntry(tex.ToBytes());
  1733. }
  1734. public byte ConvertScriptUintToByte(uint indata)
  1735. {
  1736. byte outdata = (byte)TextureAnimFlags.NONE;
  1737. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1738. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1739. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1740. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1741. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1742. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1743. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1744. return outdata;
  1745. }
  1746. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1747. {
  1748. byte[] data = new byte[16];
  1749. int pos = 0;
  1750. // The flags don't like conversion from uint to byte, so we have to do
  1751. // it the crappy way. See the above function :(
  1752. data[pos] = ConvertScriptUintToByte(pTexAnim.Flags); pos++;
  1753. data[pos] = (byte)pTexAnim.Face; pos++;
  1754. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1755. data[pos] = (byte)pTexAnim.SizeY; pos++;
  1756. Helpers.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1757. Helpers.FloatToBytes(pTexAnim.Length).CopyTo(data, pos + 4);
  1758. Helpers.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1759. m_TextureAnimation = data;
  1760. }
  1761. #endregion
  1762. #region ParticleSystem
  1763. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1764. {
  1765. m_particleSystem = pSystem.GetBytes();
  1766. }
  1767. #endregion
  1768. #region Position
  1769. /// <summary>
  1770. ///
  1771. /// </summary>
  1772. /// <param name="pos"></param>
  1773. public void UpdateOffSet(LLVector3 pos)
  1774. {
  1775. if ((pos.X != OffsetPosition.X) ||
  1776. (pos.Y != OffsetPosition.Y) ||
  1777. (pos.Z != OffsetPosition.Z))
  1778. {
  1779. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1780. OffsetPosition = newPos;
  1781. ScheduleTerseUpdate();
  1782. }
  1783. }
  1784. public void UpdateGroupPosition(LLVector3 pos)
  1785. {
  1786. if ((pos.X != GroupPosition.X) ||
  1787. (pos.Y != GroupPosition.Y) ||
  1788. (pos.Z != GroupPosition.Z))
  1789. {
  1790. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1791. GroupPosition = newPos;
  1792. ScheduleTerseUpdate();
  1793. }
  1794. }
  1795. #endregion
  1796. #region rotation
  1797. public void UpdateRotation(LLQuaternion rot)
  1798. {
  1799. if ((rot.X != RotationOffset.X) ||
  1800. (rot.Y != RotationOffset.Y) ||
  1801. (rot.Z != RotationOffset.Z) ||
  1802. (rot.W != RotationOffset.W))
  1803. {
  1804. //StoreUndoState();
  1805. RotationOffset = new LLQuaternion(rot.X, rot.Y, rot.Z, rot.W);
  1806. ScheduleTerseUpdate();
  1807. }
  1808. }
  1809. #endregion
  1810. #region Sound
  1811. public void PreloadSound(string sound)
  1812. {
  1813. LLUUID ownerID = OwnerID;
  1814. LLUUID objectID = UUID;
  1815. LLUUID soundID = LLUUID.Zero;
  1816. if (!LLUUID.TryParse(sound, out soundID))
  1817. {
  1818. //Trys to fetch sound id from prim's inventory.
  1819. //Prim's inventory doesn't support non script items yet
  1820. SceneObjectPart op = this;
  1821. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1822. {
  1823. if (item.Value.Name == sound)
  1824. {
  1825. soundID = item.Value.ItemID;
  1826. break;
  1827. }
  1828. }
  1829. }
  1830. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1831. foreach (ScenePresence p in avatarts)
  1832. {
  1833. // TODO: some filtering by distance of avatar
  1834. p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  1835. }
  1836. }
  1837. public void AdjustSoundGain(double volume)
  1838. {
  1839. if (volume > 1)
  1840. volume = 1;
  1841. if (volume < 0)
  1842. volume = 0;
  1843. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1844. foreach (ScenePresence p in avatarts)
  1845. {
  1846. p.ControllingClient.SendAttachedSoundGainChange(UUID, (float)volume);
  1847. }
  1848. }
  1849. public void SendSound(string sound, double volume, bool triggered, byte flags)
  1850. {
  1851. if (volume > 1)
  1852. volume = 1;
  1853. if (volume < 0)
  1854. volume = 0;
  1855. LLUUID ownerID = OwnerID;
  1856. LLUUID objectID = UUID;
  1857. LLUUID parentID = GetRootPartUUID();
  1858. LLUUID soundID = LLUUID.Zero;
  1859. LLVector3 position = AbsolutePosition; // region local
  1860. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  1861. //byte flags = 0;
  1862. if (!LLUUID.TryParse(sound, out soundID))
  1863. {
  1864. // search sound file from inventory
  1865. SceneObjectPart op = this;
  1866. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1867. {
  1868. if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
  1869. {
  1870. soundID = item.Value.ItemID;
  1871. break;
  1872. }
  1873. }
  1874. }
  1875. if (soundID == LLUUID.Zero)
  1876. return;
  1877. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1878. foreach (ScenePresence p in avatarts)
  1879. {
  1880. double dis=Util.GetDistanceTo(p.AbsolutePosition, position);
  1881. if (dis > 100.0) // Max audio distance
  1882. continue;
  1883. // Scale by distance
  1884. volume*=((100.0-dis)/100.0);
  1885. if (triggered)
  1886. {
  1887. p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume);
  1888. }
  1889. else
  1890. {
  1891. p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags);
  1892. }
  1893. }
  1894. }
  1895. #endregion
  1896. #region Resizing/Scale
  1897. /// <summary>
  1898. ///
  1899. /// </summary>
  1900. /// <param name="scale"></param>
  1901. public void Resize(LLVector3 scale)
  1902. {
  1903. StoreUndoState();
  1904. m_shape.Scale = scale;
  1905. ScheduleFullUpdate();
  1906. }
  1907. #endregion
  1908. public void UpdatePermissions(LLUUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  1909. {
  1910. bool set = addRemTF == 1;
  1911. // Are we the owner?
  1912. if (AgentID == OwnerID)
  1913. {
  1914. switch (field)
  1915. {
  1916. case 2:
  1917. OwnerMask = ApplyMask(OwnerMask, set, mask);
  1918. break;
  1919. case 4:
  1920. GroupMask = ApplyMask(GroupMask, set, mask);
  1921. break;
  1922. case 8:
  1923. EveryoneMask = ApplyMask(EveryoneMask, set, mask);
  1924. break;
  1925. case 16:
  1926. NextOwnerMask = ApplyMask(NextOwnerMask, set, mask);
  1927. break;
  1928. }
  1929. SendFullUpdateToAllClients();
  1930. SendObjectPropertiesToClient(AgentID);
  1931. }
  1932. }
  1933. private void SendObjectPropertiesToClient(LLUUID AgentID)
  1934. {
  1935. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1936. for (int i = 0; i < avatars.Count; i++)
  1937. {
  1938. // Ugly reference :(
  1939. if (avatars[i].UUID == AgentID)
  1940. {
  1941. m_parentGroup.GetProperties(avatars[i].ControllingClient);
  1942. }
  1943. }
  1944. }
  1945. private uint ApplyMask(uint val, bool set, uint mask)
  1946. {
  1947. if (set)
  1948. {
  1949. return val |= mask;
  1950. }
  1951. else
  1952. {
  1953. return val &= ~mask;
  1954. }
  1955. }
  1956. #region Client Update Methods
  1957. /// <summary>
  1958. /// Tell all scene presences that they should send updates for this part to their clients
  1959. /// </summary>
  1960. public void AddFullUpdateToAllAvatars()
  1961. {
  1962. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1963. for (int i = 0; i < avatars.Count; i++)
  1964. {
  1965. avatars[i].QueuePartForUpdate(this);
  1966. }
  1967. }
  1968. public void SendFullUpdateToAllClientsExcept(LLUUID agentID)
  1969. {
  1970. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1971. for (int i = 0; i < avatars.Count; i++)
  1972. {
  1973. // Ugly reference :(
  1974. if (avatars[i].UUID != agentID)
  1975. {
  1976. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1977. avatars[i].GenerateClientFlags(UUID));
  1978. }
  1979. }
  1980. }
  1981. public void AddFullUpdateToAvatar(ScenePresence presence)
  1982. {
  1983. presence.QueuePartForUpdate(this);
  1984. }
  1985. /// <summary>
  1986. ///
  1987. /// </summary>
  1988. public void SendFullUpdateToAllClients()
  1989. {
  1990. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  1991. for (int i = 0; i < avatars.Count; i++)
  1992. {
  1993. // Ugly reference :(
  1994. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1995. avatars[i].GenerateClientFlags(UUID));
  1996. }
  1997. }
  1998. /// <summary>
  1999. ///
  2000. /// </summary>
  2001. /// <param name="remoteClient"></param>
  2002. public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  2003. {
  2004. m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
  2005. }
  2006. /// <summary>
  2007. /// Sends a full update to the client
  2008. /// </summary>
  2009. /// <param name="remoteClient"></param>
  2010. /// <param name="clientFlags"></param>
  2011. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  2012. {
  2013. LLVector3 lPos;
  2014. lPos = OffsetPosition;
  2015. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  2016. }
  2017. /// <summary>
  2018. /// Sends a full update to the client
  2019. /// </summary>
  2020. /// <param name="remoteClient"></param>
  2021. /// <param name="lPos"></param>
  2022. /// <param name="clientFlags"></param>
  2023. public void SendFullUpdateToClient(IClientAPI remoteClient, LLVector3 lPos, uint clientFlags)
  2024. {
  2025. clientFlags &= ~(uint) LLObject.ObjectFlags.CreateSelected;
  2026. if (remoteClient.AgentId == OwnerID)
  2027. {
  2028. if ((uint) (Flags & LLObject.ObjectFlags.CreateSelected) != 0)
  2029. {
  2030. clientFlags |= (uint) LLObject.ObjectFlags.CreateSelected;
  2031. Flags &= ~LLObject.ObjectFlags.CreateSelected;
  2032. }
  2033. }
  2034. byte[] color = new byte[] {m_color.R, m_color.G, m_color.B, m_color.A};
  2035. remoteClient.SendPrimitiveToClient(
  2036. m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, m_shape,
  2037. lPos, Velocity, Acceleration, RotationOffset, RotationalVelocity, clientFlags, m_uuid,
  2038. OwnerID,
  2039. m_text, color, ParentID, m_particleSystem, m_clickAction, m_TextureAnimation, m_IsAttachment, m_attachmentPoint,fromAssetID, Sound, SoundGain, SoundFlags, SoundRadius);
  2040. }
  2041. /// Terse updates
  2042. public void AddTerseUpdateToAllAvatars()
  2043. {
  2044. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  2045. for (int i = 0; i < avatars.Count; i++)
  2046. {
  2047. avatars[i].QueuePartForUpdate(this);
  2048. }
  2049. }
  2050. public void AddTerseUpdateToAvatar(ScenePresence presence)
  2051. {
  2052. presence.QueuePartForUpdate(this);
  2053. }
  2054. /// <summary>
  2055. ///
  2056. /// </summary>
  2057. public void SendTerseUpdateToAllClients()
  2058. {
  2059. List<ScenePresence> avatars = m_parentGroup.Scene.GetScenePresences();
  2060. for (int i = 0; i < avatars.Count; i++)
  2061. {
  2062. m_parentGroup.SendPartTerseUpdate(avatars[i].ControllingClient, this);
  2063. }
  2064. }
  2065. /// <summary>
  2066. /// Send a terse update to the client.
  2067. /// </summary>
  2068. /// <param name="remoteClient"></param>
  2069. public void SendTerseUpdate(IClientAPI remoteClient)
  2070. {
  2071. m_parentGroup.SendPartTerseUpdate(remoteClient, this);
  2072. }
  2073. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  2074. {
  2075. LLVector3 lPos;
  2076. lPos = OffsetPosition;
  2077. LLQuaternion mRot = RotationOffset;
  2078. // TODO: I have no idea why we are making this check. This should be sorted out
  2079. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) == 0)
  2080. {
  2081. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity, RotationalVelocity, Shape.State, fromAssetID);
  2082. }
  2083. else
  2084. {
  2085. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity,
  2086. RotationalVelocity);
  2087. //System.Console.WriteLine("LID: " + LocalID + " RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  2088. }
  2089. }
  2090. public void SendTerseUpdateToClient(IClientAPI remoteClient, LLVector3 lPos)
  2091. {
  2092. LLQuaternion mRot = RotationOffset;
  2093. if (m_IsAttachment)
  2094. {
  2095. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity, RotationalVelocity, (byte)((m_attachmentPoint % 16) * 16 + (m_attachmentPoint / 16)),fromAssetID);
  2096. }
  2097. else
  2098. {
  2099. if ((ObjectFlags & (uint)LLObject.ObjectFlags.Physics) == 0)
  2100. {
  2101. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity, RotationalVelocity, Shape.State, fromAssetID);
  2102. }
  2103. else
  2104. {
  2105. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalId, lPos, mRot, Velocity,
  2106. RotationalVelocity);
  2107. //System.Console.WriteLine("LID: " + LocalID + "RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  2108. }
  2109. }
  2110. }
  2111. #endregion
  2112. public virtual void UpdateMovement()
  2113. {
  2114. }
  2115. #region Events
  2116. public void PhysicsRequestingTerseUpdate()
  2117. {
  2118. if (PhysActor != null)
  2119. {
  2120. LLVector3 newpos = new LLVector3(PhysActor.Position.GetBytes(), 0);
  2121. if (newpos.X > 257f || newpos.X < -1f || newpos.Y > 257f || newpos.Y < -1f)
  2122. {
  2123. m_parentGroup.AbsolutePosition = newpos;
  2124. return;
  2125. }
  2126. }
  2127. ScheduleTerseUpdate();
  2128. //SendTerseUpdateToAllClients();
  2129. }
  2130. #endregion
  2131. public void PhysicsOutOfBounds(PhysicsVector pos)
  2132. {
  2133. m_log.Info("[PHYSICS]: Physical Object went out of bounds.");
  2134. RemFlag(LLObject.ObjectFlags.Physics);
  2135. DoPhysicsPropertyUpdate(false, true);
  2136. //m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  2137. }
  2138. public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient)
  2139. {
  2140. }
  2141. public void SetText(string text)
  2142. {
  2143. Text = text;
  2144. ScheduleFullUpdate();
  2145. }
  2146. public void SetText(string text, Vector3 color, double alpha)
  2147. {
  2148. Color = Color.FromArgb(0xff - (int) (alpha*0xff),
  2149. (int) (color.x*0xff),
  2150. (int) (color.y*0xff),
  2151. (int) (color.z*0xff));
  2152. SetText(text);
  2153. }
  2154. public int registerTargetWaypoint(LLVector3 target, float tolerance)
  2155. {
  2156. if (m_parentGroup != null)
  2157. {
  2158. return m_parentGroup.registerTargetWaypoint(target, tolerance);
  2159. }
  2160. return 0;
  2161. }
  2162. public void unregisterTargetWaypoint(int handle)
  2163. {
  2164. if (m_parentGroup != null)
  2165. {
  2166. m_parentGroup.unregisterTargetWaypoint(handle);
  2167. }
  2168. }
  2169. protected SceneObjectPart(SerializationInfo info, StreamingContext context)
  2170. {
  2171. //System.Console.WriteLine("SceneObjectPart Deserialize BGN");
  2172. if (info == null)
  2173. {
  2174. throw new ArgumentNullException("info");
  2175. }
  2176. /*
  2177. m_queue = (Queue<SceneObjectPart>)info.GetValue("m_queue", typeof(Queue<SceneObjectPart>));
  2178. m_ids = (List<LLUUID>)info.GetValue("m_ids", typeof(List<LLUUID>));
  2179. */
  2180. //System.Console.WriteLine("SceneObjectPart Deserialize END");
  2181. }
  2182. [SecurityPermission(SecurityAction.LinkDemand,
  2183. Flags = SecurityPermissionFlag.SerializationFormatter)]
  2184. public virtual void GetObjectData(
  2185. SerializationInfo info, StreamingContext context)
  2186. {
  2187. if (info == null)
  2188. {
  2189. throw new ArgumentNullException("info");
  2190. }
  2191. info.AddValue("m_inventoryFileName", GetInventoryFileName());
  2192. info.AddValue("m_folderID", UUID);
  2193. info.AddValue("PhysActor", PhysActor);
  2194. Dictionary<Guid, TaskInventoryItem> TaskInventory_work = new Dictionary<Guid, TaskInventoryItem>();
  2195. foreach (LLUUID id in TaskInventory.Keys)
  2196. {
  2197. TaskInventory_work.Add(id.UUID, TaskInventory[id]);
  2198. }
  2199. info.AddValue("TaskInventory", TaskInventory_work);
  2200. info.AddValue("LastOwnerID", LastOwnerID.UUID);
  2201. info.AddValue("OwnerID", OwnerID.UUID);
  2202. info.AddValue("GroupID", GroupID.UUID);
  2203. info.AddValue("OwnershipCost", OwnershipCost);
  2204. info.AddValue("ObjectSaleType", ObjectSaleType);
  2205. info.AddValue("SalePrice", SalePrice);
  2206. info.AddValue("Category", Category);
  2207. info.AddValue("CreationDate", CreationDate);
  2208. info.AddValue("ParentID", ParentID);
  2209. info.AddValue("OwnerMask", OwnerMask);
  2210. info.AddValue("NextOwnerMask", NextOwnerMask);
  2211. info.AddValue("GroupMask", GroupMask);
  2212. info.AddValue("EveryoneMask", EveryoneMask);
  2213. info.AddValue("BaseMask", BaseMask);
  2214. info.AddValue("m_particleSystem", m_particleSystem);
  2215. info.AddValue("TimeStampFull", TimeStampFull);
  2216. info.AddValue("TimeStampTerse", TimeStampTerse);
  2217. info.AddValue("TimeStampLastActivity", TimeStampLastActivity);
  2218. info.AddValue("m_updateFlag", m_updateFlag);
  2219. info.AddValue("CreatorID", CreatorID.UUID);
  2220. info.AddValue("m_inventorySerial", m_inventorySerial);
  2221. info.AddValue("m_uuid", m_uuid.UUID);
  2222. info.AddValue("m_localID", m_localId);
  2223. info.AddValue("m_name", m_name);
  2224. info.AddValue("m_flags", Flags);
  2225. info.AddValue("m_material", m_material);
  2226. info.AddValue("m_regionHandle", m_regionHandle);
  2227. info.AddValue("m_groupPosition.X", m_groupPosition.X);
  2228. info.AddValue("m_groupPosition.Y", m_groupPosition.Y);
  2229. info.AddValue("m_groupPosition.Z", m_groupPosition.Z);
  2230. info.AddValue("m_offsetPosition.X", m_offsetPosition.X);
  2231. info.AddValue("m_offsetPosition.Y", m_offsetPosition.Y);
  2232. info.AddValue("m_offsetPosition.Z", m_offsetPosition.Z);
  2233. info.AddValue("m_rotationOffset.W", m_rotationOffset.W);
  2234. info.AddValue("m_rotationOffset.X", m_rotationOffset.X);
  2235. info.AddValue("m_rotationOffset.Y", m_rotationOffset.Y);
  2236. info.AddValue("m_rotationOffset.Z", m_rotationOffset.Z);
  2237. info.AddValue("m_velocity.X", m_velocity.X);
  2238. info.AddValue("m_velocity.Y", m_velocity.Y);
  2239. info.AddValue("m_velocity.Z", m_velocity.Z);
  2240. info.AddValue("m_rotationalvelocity.X", m_rotationalvelocity.X);
  2241. info.AddValue("m_rotationalvelocity.Y", m_rotationalvelocity.Y);
  2242. info.AddValue("m_rotationalvelocity.Z", m_rotationalvelocity.Z);
  2243. info.AddValue("m_angularVelocity.X", m_angularVelocity.X);
  2244. info.AddValue("m_angularVelocity.Y", m_angularVelocity.Y);
  2245. info.AddValue("m_angularVelocity.Z", m_angularVelocity.Z);
  2246. info.AddValue("m_acceleration.X", m_acceleration.X);
  2247. info.AddValue("m_acceleration.Y", m_acceleration.Y);
  2248. info.AddValue("m_acceleration.Z", m_acceleration.Z);
  2249. info.AddValue("m_description", m_description);
  2250. info.AddValue("m_color", m_color);
  2251. info.AddValue("m_text", m_text);
  2252. info.AddValue("m_sitName", m_sitName);
  2253. info.AddValue("m_touchName", m_touchName);
  2254. info.AddValue("m_clickAction", m_clickAction);
  2255. info.AddValue("m_shape", m_shape);
  2256. info.AddValue("m_parentGroup", m_parentGroup);
  2257. info.AddValue("PayPrice", PayPrice);
  2258. }
  2259. public void Undo()
  2260. {
  2261. if (m_undo.Count > 0)
  2262. {
  2263. UndoState goback = m_undo.Pop();
  2264. if (goback != null)
  2265. goback.PlaybackState(this);
  2266. }
  2267. }
  2268. public void SetScriptEvents(LLUUID scriptid, int events)
  2269. {
  2270. scriptEvents oldparts;
  2271. lock (m_scriptEvents)
  2272. {
  2273. if (m_scriptEvents.ContainsKey(scriptid))
  2274. {
  2275. oldparts = m_scriptEvents[scriptid];
  2276. // remove values from aggregated script events
  2277. m_scriptEvents[scriptid] = (scriptEvents) events;
  2278. }
  2279. else
  2280. {
  2281. m_scriptEvents.Add(scriptid, (scriptEvents) events);
  2282. }
  2283. }
  2284. aggregateScriptEvents();
  2285. }
  2286. public void RemoveScriptEvents(LLUUID scriptid)
  2287. {
  2288. lock (m_scriptEvents)
  2289. {
  2290. if (m_scriptEvents.ContainsKey(scriptid))
  2291. {
  2292. scriptEvents oldparts = scriptEvents.None;
  2293. oldparts = (scriptEvents) m_scriptEvents[scriptid];
  2294. // remove values from aggregated script events
  2295. m_aggregateScriptEvents &= ~oldparts;
  2296. m_scriptEvents.Remove(scriptid);
  2297. }
  2298. }
  2299. aggregateScriptEvents();
  2300. }
  2301. public void aggregateScriptEvents()
  2302. {
  2303. // Aggregate script events
  2304. lock (m_scriptEvents)
  2305. {
  2306. foreach (scriptEvents s in m_scriptEvents.Values)
  2307. {
  2308. m_aggregateScriptEvents |= s;
  2309. }
  2310. }
  2311. uint objectflagupdate = 0;
  2312. if (
  2313. ((m_aggregateScriptEvents & scriptEvents.touch) != 0) ||
  2314. ((m_aggregateScriptEvents & scriptEvents.touch_end) != 0) ||
  2315. ((m_aggregateScriptEvents & scriptEvents.touch_start) != 0)
  2316. )
  2317. {
  2318. objectflagupdate |= (uint) LLObject.ObjectFlags.Touch;
  2319. }
  2320. if ((m_aggregateScriptEvents & scriptEvents.money) != 0)
  2321. {
  2322. objectflagupdate |= (uint) LLObject.ObjectFlags.Money;
  2323. }
  2324. if (
  2325. ((m_aggregateScriptEvents & scriptEvents.collision) != 0) ||
  2326. ((m_aggregateScriptEvents & scriptEvents.collision_end) != 0) ||
  2327. ((m_aggregateScriptEvents & scriptEvents.collision_start) != 0)
  2328. )
  2329. {
  2330. // subscribe to physics updates.
  2331. if (PhysActor != null)
  2332. {
  2333. PhysActor.OnCollisionUpdate += PhysicsCollision;
  2334. PhysActor.SubscribeEvents(1000);
  2335. }
  2336. }
  2337. else
  2338. {
  2339. if (PhysActor != null)
  2340. {
  2341. PhysActor.UnSubscribeEvents();
  2342. PhysActor.OnCollisionUpdate -= PhysicsCollision;
  2343. }
  2344. }
  2345. if ((GetEffectiveObjectFlags() & (uint)LLObject.ObjectFlags.Scripted) != 0)
  2346. {
  2347. m_parentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting;
  2348. }
  2349. else
  2350. {
  2351. m_parentGroup.Scene.EventManager.OnScriptTimerEvent -= handleTimerAccounting;
  2352. }
  2353. LocalFlags=(LLObject.ObjectFlags)objectflagupdate;
  2354. if (m_parentGroup != null && m_parentGroup.RootPart == this)
  2355. m_parentGroup.aggregateScriptEvents();
  2356. else
  2357. ScheduleFullUpdate();
  2358. }
  2359. public void PhysicsCollision(EventArgs e)
  2360. {
  2361. return;
  2362. //
  2363. //if (e == null)
  2364. //{
  2365. // return;
  2366. //}
  2367. //CollisionEventUpdate a = (CollisionEventUpdate)e;
  2368. //Dictionary<uint, float> collissionswith = a.m_objCollisionList;
  2369. //foreach (uint localid in collissionswith.Keys)
  2370. //{
  2371. // m_log.Debug("[OBJECT]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
  2372. //}
  2373. }
  2374. public void SetDieAtEdge(bool p)
  2375. {
  2376. if (m_parentGroup == null)
  2377. return;
  2378. if (m_parentGroup.RootPart == null)
  2379. return;
  2380. m_parentGroup.RootPart.DIE_AT_EDGE = p;
  2381. }
  2382. public bool GetDieAtEdge()
  2383. {
  2384. if (m_parentGroup == null)
  2385. return false;
  2386. if (m_parentGroup.RootPart == null)
  2387. return false;
  2388. return m_parentGroup.RootPart.DIE_AT_EDGE;
  2389. }
  2390. public void GetProperties(IClientAPI client)
  2391. {
  2392. client.SendObjectPropertiesReply(LLUUID.Zero, (ulong)CreationDate, CreatorID, LLUUID.Zero, LLUUID.Zero,
  2393. GroupID, (short)InventorySerial, LastOwnerID, UUID, OwnerID,
  2394. ParentGroup.RootPart.TouchName, new byte[0], ParentGroup.RootPart.SitName, Name, Description,
  2395. ParentGroup.RootPart.OwnerMask, ParentGroup.RootPart.NextOwnerMask, ParentGroup.RootPart.GroupMask, ParentGroup.RootPart.EveryoneMask,
  2396. ParentGroup.RootPart.BaseMask);
  2397. }
  2398. public void SetGroup(LLUUID groupID, IClientAPI client)
  2399. {
  2400. GroupID = groupID;
  2401. GetProperties(client);
  2402. m_updateFlag = 2;
  2403. }
  2404. private void handleTimerAccounting(uint localID, double interval)
  2405. {
  2406. if (localID == LocalId)
  2407. {
  2408. float sec = (float)interval;
  2409. if (m_parentGroup != null)
  2410. {
  2411. if (sec == 0)
  2412. {
  2413. if (m_parentGroup.scriptScore + 0.001f >= float.MaxValue - 0.001)
  2414. m_parentGroup.scriptScore = 0;
  2415. m_parentGroup.scriptScore += 0.001f;
  2416. return;
  2417. }
  2418. if (m_parentGroup.scriptScore + (0.001f / sec) >= float.MaxValue - (0.001f / sec))
  2419. m_parentGroup.scriptScore = 0;
  2420. m_parentGroup.scriptScore += (0.001f / sec);
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }