1
0

SceneObjectPart.cs 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015
  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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Drawing;
  31. using System.Xml;
  32. using System.Xml.Serialization;
  33. using Axiom.Math;
  34. using libsecondlife;
  35. using libsecondlife.Packets;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Region.Environment.Interfaces;
  39. using OpenSim.Region.Environment.Scenes.Scripting;
  40. using OpenSim.Region.Physics.Manager;
  41. namespace OpenSim.Region.Environment.Scenes
  42. {
  43. // I don't really know where to put this except here.
  44. // Can't access the OpenSim.Region.ScriptEngine.Common.LSL_BaseClass.Changed constants
  45. [Flags]
  46. public enum ExtraParamType
  47. {
  48. Something1 = 1,
  49. Something2 = 2,
  50. Something3 = 4,
  51. Something4 = 8,
  52. Flexible = 16,
  53. Light = 32,
  54. Sculpt = 48,
  55. Something5 = 64,
  56. Something6 = 128
  57. }
  58. [Flags]
  59. public enum Changed : uint
  60. {
  61. INVENTORY = 1,
  62. COLOR = 2,
  63. SHAPE = 4,
  64. SCALE = 8,
  65. TEXTURE = 16,
  66. LINK = 32,
  67. ALLOWED_DROP = 64,
  68. OWNER = 128
  69. }
  70. [Flags]
  71. public enum TextureAnimFlags : byte
  72. {
  73. NONE = 0x00,
  74. ANIM_ON = 0x01,
  75. LOOP = 0x02,
  76. REVERSE = 0x04,
  77. PING_PONG = 0x08,
  78. SMOOTH = 0x10,
  79. ROTATE = 0x20,
  80. SCALE = 0x40
  81. }
  82. public partial class SceneObjectPart : IScriptHost
  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. public Int32 CreationDate;
  93. public uint ParentID = 0;
  94. private PhysicsVector m_lastRotationalVelocity = PhysicsVector.Zero;
  95. private Vector3 m_sitTargetPosition = new Vector3(0, 0, 0);
  96. private Quaternion m_sitTargetOrientation = new Quaternion(0, 0, 0, 1);
  97. private LLUUID m_sitTargetAvatar = LLUUID.Zero;
  98. #region Permissions
  99. public uint BaseMask = (uint)PermissionMask.All;
  100. public uint OwnerMask = (uint)PermissionMask.All;
  101. public uint GroupMask = (uint)PermissionMask.None;
  102. public uint EveryoneMask = (uint)PermissionMask.None;
  103. public uint NextOwnerMask = (uint)PermissionMask.All;
  104. public LLObject.ObjectFlags Flags = LLObject.ObjectFlags.None;
  105. public uint ObjectFlags
  106. {
  107. get { return (uint)Flags; }
  108. set { Flags = (LLObject.ObjectFlags)value; }
  109. }
  110. #endregion
  111. protected byte[] m_particleSystem = new byte[0];
  112. [XmlIgnore] public uint TimeStampFull = 0;
  113. [XmlIgnore] public uint TimeStampTerse = 0;
  114. [XmlIgnore] public uint TimeStampLastActivity = 0; // Will be used for AutoReturn
  115. /// <summary>
  116. /// Only used internally to schedule client updates
  117. /// </summary>
  118. private byte m_updateFlag;
  119. #region realXtend
  120. // Attachment parameters
  121. private ScenePresence m_attachPresence = null;
  122. private byte m_attachPt;
  123. private LLQuaternion m_attachRot;
  124. private RegionInfo m_attachRegInfo;
  125. private LLUUID m_attachAgentId;
  126. #endregion realXtend
  127. #region Properties
  128. public LLUUID CreatorID;
  129. public LLUUID ObjectCreator
  130. {
  131. get { return CreatorID; }
  132. }
  133. protected LLUUID m_uuid;
  134. public LLUUID UUID
  135. {
  136. get { return m_uuid; }
  137. set { m_uuid = value; }
  138. }
  139. protected uint m_localID;
  140. public uint LocalID
  141. {
  142. get { return m_localID; }
  143. set { m_localID = value; }
  144. }
  145. protected string m_name;
  146. public virtual string Name
  147. {
  148. get { return m_name; }
  149. set { m_name = value; }
  150. }
  151. protected LLObject.MaterialType m_material = 0;
  152. public byte Material
  153. {
  154. get { return (byte) m_material; }
  155. set { m_material = (LLObject.MaterialType) value; }
  156. }
  157. protected ulong m_regionHandle;
  158. public ulong RegionHandle
  159. {
  160. get { return m_regionHandle; }
  161. set { m_regionHandle = value; }
  162. }
  163. //unkown if this will be kept, added as a way of removing the group position from the group class
  164. protected LLVector3 m_groupPosition;
  165. /// <summary>
  166. /// Method for a prim to get it's world position from the group.
  167. /// Remember, the Group Position simply gives the position of the group itself
  168. /// </summary>
  169. /// <returns>A Linked Child Prim objects position in world</returns>
  170. public LLVector3 GetWorldPosition()
  171. {
  172. Quaternion parentRot = new Quaternion(
  173. ParentGroup.RootPart.RotationOffset.W,
  174. ParentGroup.RootPart.RotationOffset.X,
  175. ParentGroup.RootPart.RotationOffset.Y,
  176. ParentGroup.RootPart.RotationOffset.Z);
  177. Vector3 axPos
  178. = new Vector3(
  179. OffsetPosition.X,
  180. OffsetPosition.Y,
  181. OffsetPosition.Z);
  182. axPos = parentRot * axPos;
  183. LLVector3 translationOffsetPosition = new LLVector3(axPos.x, axPos.y, axPos.z);
  184. return GroupPosition + translationOffsetPosition;
  185. //return (new LLVector3(axiomPos.x, axiomPos.y, axiomPos.z) + AbsolutePosition);
  186. }
  187. /// <summary>
  188. /// Gets the rotation of this prim offset by the group rotation
  189. /// </summary>
  190. /// <returns></returns>
  191. public LLQuaternion GetWorldRotation()
  192. {
  193. Quaternion newRot;
  194. if (this.LinkNum == 0)
  195. {
  196. newRot = new Quaternion(RotationOffset.W,RotationOffset.X,RotationOffset.Y,RotationOffset.Z);
  197. }
  198. else
  199. {
  200. Quaternion parentRot = new Quaternion(
  201. ParentGroup.RootPart.RotationOffset.W,
  202. ParentGroup.RootPart.RotationOffset.X,
  203. ParentGroup.RootPart.RotationOffset.Y,
  204. ParentGroup.RootPart.RotationOffset.Z);
  205. Quaternion oldRot
  206. = new Quaternion(
  207. RotationOffset.W,
  208. RotationOffset.X,
  209. RotationOffset.Y,
  210. RotationOffset.Z);
  211. newRot = parentRot * oldRot;
  212. }
  213. return new LLQuaternion(newRot.x, newRot.y, newRot.z, newRot.w);
  214. //return new LLQuaternion(axiomPartRotation.x, axiomPartRotation.y, axiomPartRotation.z, axiomPartRotation.w);
  215. }
  216. public LLVector3 GroupPosition
  217. {
  218. get
  219. {
  220. // If this is a linkset, we don't want the physics engine mucking up our group position here.
  221. if (PhysActor != null && ParentID == 0)
  222. {
  223. m_groupPosition.X = PhysActor.Position.X;
  224. m_groupPosition.Y = PhysActor.Position.Y;
  225. m_groupPosition.Z = PhysActor.Position.Z;
  226. }
  227. return m_groupPosition;
  228. }
  229. set
  230. {
  231. m_groupPosition = value;
  232. if (PhysActor != null)
  233. {
  234. try
  235. {
  236. // Root prim actually goes at Position
  237. if (ParentID == 0)
  238. {
  239. PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  240. }
  241. else
  242. {
  243. // To move the child prim in respect to the group position and rotation we have to calculate
  244. LLVector3 resultingposition = GetWorldPosition();
  245. PhysActor.Position = new PhysicsVector(resultingposition.X, resultingposition.Y, resultingposition.Z);
  246. LLQuaternion resultingrot = GetWorldRotation();
  247. PhysActor.Orientation = new Quaternion(resultingrot.W, resultingrot.X, resultingrot.Y, resultingrot.Z);
  248. }
  249. // Tell the physics engines that this prim changed.
  250. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  251. }
  252. catch (Exception e)
  253. {
  254. Console.WriteLine(e.Message);
  255. }
  256. }
  257. }
  258. }
  259. private byte[] m_TextureAnimation;
  260. protected LLVector3 m_offsetPosition;
  261. public LLVector3 OffsetPosition
  262. {
  263. get { return m_offsetPosition; }
  264. set { m_offsetPosition = value;
  265. try
  266. {
  267. // Hack to get the child prim to update world positions in the physics engine
  268. ParentGroup.ResetChildPrimPhysicsPositions();
  269. }
  270. catch (System.NullReferenceException)
  271. {
  272. // Ignore, and skip over.
  273. }
  274. //m_log.Info("[PART]: OFFSET:" + m_offsetPosition.ToString());
  275. }
  276. }
  277. public LLVector3 AbsolutePosition
  278. {
  279. get { return m_offsetPosition + m_groupPosition; }
  280. }
  281. protected LLQuaternion m_rotationOffset;
  282. public LLQuaternion RotationOffset
  283. {
  284. get
  285. {
  286. // We don't want the physics engine mucking up the rotations in a linkset
  287. if (PhysActor != null && ParentID == 0)
  288. {
  289. if (PhysActor.Orientation.x != 0 || PhysActor.Orientation.y != 0
  290. || PhysActor.Orientation.z != 0 || PhysActor.Orientation.w != 0)
  291. {
  292. m_rotationOffset.X = PhysActor.Orientation.x;
  293. m_rotationOffset.Y = PhysActor.Orientation.y;
  294. m_rotationOffset.Z = PhysActor.Orientation.z;
  295. m_rotationOffset.W = PhysActor.Orientation.w;
  296. }
  297. }
  298. return m_rotationOffset;
  299. }
  300. set
  301. {
  302. m_rotationOffset = value;
  303. if (PhysActor != null)
  304. {
  305. try
  306. {
  307. // Root prim gets value directly
  308. if (ParentID == 0)
  309. {
  310. PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z);
  311. //m_log.Info("[PART]: RO1:" + PhysActor.Orientation.ToString());
  312. }
  313. else
  314. {
  315. // Child prim we have to calculate it's world rotationwel
  316. LLQuaternion resultingrotation = GetWorldRotation();
  317. PhysActor.Orientation = new Quaternion(resultingrotation.W, resultingrotation.X, resultingrotation.Y, resultingrotation.Z);
  318. //m_log.Info("[PART]: RO2:" + PhysActor.Orientation.ToString());
  319. }
  320. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  321. //}
  322. }
  323. catch (Exception ex)
  324. {
  325. Console.WriteLine(ex.Message);
  326. }
  327. }
  328. }
  329. }
  330. protected LLVector3 m_velocity;
  331. protected LLVector3 m_rotationalvelocity;
  332. /// <summary></summary>
  333. public LLVector3 Velocity
  334. {
  335. get
  336. {
  337. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  338. //|| PhysActor.Velocity.z != 0)
  339. //{
  340. if (PhysActor != null)
  341. {
  342. if (PhysActor.IsPhysical)
  343. {
  344. m_velocity.X = PhysActor.Velocity.X;
  345. m_velocity.Y = PhysActor.Velocity.Y;
  346. m_velocity.Z = PhysActor.Velocity.Z;
  347. }
  348. }
  349. return m_velocity;
  350. }
  351. set {
  352. m_velocity = value;
  353. if (PhysActor != null)
  354. {
  355. if (PhysActor.IsPhysical)
  356. {
  357. PhysActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
  358. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  359. }
  360. }
  361. }
  362. }
  363. public LLVector3 RotationalVelocity
  364. {
  365. get
  366. {
  367. //if (PhysActor.Velocity.x != 0 || PhysActor.Velocity.y != 0
  368. //|| PhysActor.Velocity.z != 0)
  369. //{
  370. if (PhysActor != null)
  371. {
  372. if (PhysActor.IsPhysical)
  373. {
  374. m_rotationalvelocity.FromBytes(PhysActor.RotationalVelocity.GetBytes(),0);
  375. }
  376. }
  377. return m_rotationalvelocity;
  378. }
  379. set { m_rotationalvelocity = value; }
  380. }
  381. protected LLVector3 m_angularVelocity;
  382. /// <summary></summary>
  383. public LLVector3 AngularVelocity
  384. {
  385. get { return m_angularVelocity; }
  386. set { m_angularVelocity = value; }
  387. }
  388. protected LLVector3 m_acceleration;
  389. /// <summary></summary>
  390. public LLVector3 Acceleration
  391. {
  392. get { return m_acceleration; }
  393. set { m_acceleration = value; }
  394. }
  395. private string m_description = String.Empty;
  396. public string Description
  397. {
  398. get { return m_description; }
  399. set { m_description = value; }
  400. }
  401. private Color m_color = Color.Black;
  402. public Color Color
  403. {
  404. get { return m_color; }
  405. set
  406. {
  407. m_color = value;
  408. TriggerScriptChangedEvent(Changed.COLOR);
  409. /* ScheduleFullUpdate() need not be called b/c after
  410. * setting the color, the text will be set, so then
  411. * ScheduleFullUpdate() will be called. */
  412. //ScheduleFullUpdate();
  413. }
  414. }
  415. private string m_text = String.Empty;
  416. public Vector3 SitTargetPosition
  417. {
  418. get { return m_sitTargetPosition; }
  419. }
  420. public Quaternion SitTargetOrientation
  421. {
  422. get { return m_sitTargetOrientation; }
  423. }
  424. public string Text
  425. {
  426. get { return m_text; }
  427. set
  428. {
  429. m_text = value;
  430. ScheduleFullUpdate();
  431. }
  432. }
  433. private string m_sitName = String.Empty;
  434. public string SitName
  435. {
  436. get { return m_sitName; }
  437. set { m_sitName = value; }
  438. }
  439. private string m_touchName = String.Empty;
  440. public string TouchName
  441. {
  442. get { return m_touchName; }
  443. set { m_touchName = value; }
  444. }
  445. private int m_linkNum = 0;
  446. public int LinkNum
  447. {
  448. get { return m_linkNum; }
  449. set
  450. {
  451. m_linkNum = value;
  452. TriggerScriptChangedEvent(Changed.LINK);
  453. }
  454. }
  455. private byte m_clickAction = 0;
  456. public byte ClickAction
  457. {
  458. get { return m_clickAction; }
  459. set
  460. {
  461. m_clickAction = value;
  462. ScheduleFullUpdate();
  463. }
  464. }
  465. protected PrimitiveBaseShape m_shape;
  466. /// <summary>
  467. /// hook to the physics scene to apply impulse
  468. /// This is sent up to the group, which then finds the root prim
  469. /// and applies the force on the root prim of the group
  470. /// </summary>
  471. /// <param name="impulse">Vector force</param>
  472. public void ApplyImpulse(LLVector3 impulsei)
  473. {
  474. PhysicsVector impulse = new PhysicsVector(impulsei.X, impulsei.Y, impulsei.Z);
  475. if (m_parentGroup != null)
  476. {
  477. m_parentGroup.applyImpulse(impulse);
  478. }
  479. }
  480. public void TriggerScriptChangedEvent(Changed val)
  481. {
  482. if (m_parentGroup != null)
  483. {
  484. if (m_parentGroup.Scene != null)
  485. m_parentGroup.Scene.TriggerObjectChanged(LocalID, (uint)val);
  486. }
  487. }
  488. public PrimitiveBaseShape Shape
  489. {
  490. get { return m_shape; }
  491. set
  492. {
  493. m_shape = value;
  494. TriggerScriptChangedEvent(Changed.SHAPE);
  495. }
  496. }
  497. public LLVector3 Scale
  498. {
  499. get { return m_shape.Scale; }
  500. set
  501. {
  502. m_shape.Scale = value;
  503. TriggerScriptChangedEvent(Changed.SCALE);
  504. }
  505. }
  506. public bool Stopped
  507. {
  508. get {
  509. double threshold = 0.02;
  510. return (Math.Abs(Velocity.X) < threshold &&
  511. Math.Abs(Velocity.Y) < threshold &&
  512. Math.Abs(Velocity.Z) < threshold &&
  513. Math.Abs(AngularVelocity.X) < threshold &&
  514. Math.Abs(AngularVelocity.Y) < threshold &&
  515. Math.Abs(AngularVelocity.Z) < threshold);
  516. }
  517. }
  518. #endregion
  519. public LLUUID ObjectOwner
  520. {
  521. get { return OwnerID; }
  522. }
  523. // FIXME, TODO, ERROR: 'ParentGroup' can't be in here, move it out.
  524. protected SceneObjectGroup m_parentGroup;
  525. public SceneObjectGroup ParentGroup
  526. {
  527. get { return m_parentGroup; }
  528. }
  529. public byte UpdateFlag
  530. {
  531. get { return m_updateFlag; }
  532. set { m_updateFlag = value; }
  533. }
  534. #region Constructors
  535. /// <summary>
  536. /// No arg constructor called by region restore db code
  537. /// </summary>
  538. public SceneObjectPart()
  539. {
  540. // It's not necessary to persist this
  541. m_inventoryFileName = "taskinventory" + LLUUID.Random().ToString();
  542. m_TextureAnimation = new byte[0];
  543. }
  544. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  545. PrimitiveBaseShape shape, LLVector3 groupPosition, LLVector3 offsetPosition)
  546. : this(regionHandle, parent, ownerID, localID, shape, groupPosition, LLQuaternion.Identity, offsetPosition)
  547. {
  548. }
  549. /// <summary>
  550. /// Create a completely new SceneObjectPart (prim)
  551. /// </summary>
  552. /// <param name="regionHandle"></param>
  553. /// <param name="parent"></param>
  554. /// <param name="ownerID"></param>
  555. /// <param name="localID"></param>
  556. /// <param name="shape"></param>
  557. /// <param name="position"></param>
  558. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
  559. PrimitiveBaseShape shape, LLVector3 groupPosition, LLQuaternion rotationOffset,
  560. LLVector3 offsetPosition)
  561. {
  562. m_name = "Primitive";
  563. m_regionHandle = regionHandle;
  564. m_parentGroup = parent;
  565. CreationDate = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  566. OwnerID = ownerID;
  567. CreatorID = OwnerID;
  568. LastOwnerID = LLUUID.Zero;
  569. UUID = LLUUID.Random();
  570. LocalID = (uint) (localID);
  571. Shape = shape;
  572. // Todo: Add More Object Parameter from above!
  573. OwnershipCost = 0;
  574. ObjectSaleType = (byte) 0;
  575. SalePrice = 0;
  576. Category = (uint) 0;
  577. LastOwnerID = CreatorID;
  578. // End Todo: ///
  579. GroupPosition = groupPosition;
  580. OffsetPosition = offsetPosition;
  581. RotationOffset = rotationOffset;
  582. Velocity = new LLVector3(0, 0, 0);
  583. m_rotationalvelocity = new LLVector3(0, 0, 0);
  584. AngularVelocity = new LLVector3(0, 0, 0);
  585. Acceleration = new LLVector3(0, 0, 0);
  586. m_TextureAnimation = new byte[0];
  587. m_inventoryFileName = "taskinventory" + LLUUID.Random().ToString();
  588. m_folderID = LLUUID.Random();
  589. Flags = 0;
  590. Flags |= LLObject.ObjectFlags.Touch |
  591. LLObject.ObjectFlags.AllowInventoryDrop |
  592. LLObject.ObjectFlags.CreateSelected;
  593. TrimPermissions();
  594. ScheduleFullUpdate();
  595. }
  596. /// <summary>
  597. /// Re/create a SceneObjectPart (prim)
  598. /// currently not used, and maybe won't be
  599. /// </summary>
  600. /// <param name="regionHandle"></param>
  601. /// <param name="parent"></param>
  602. /// <param name="ownerID"></param>
  603. /// <param name="localID"></param>
  604. /// <param name="shape"></param>
  605. /// <param name="position"></param>
  606. public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, int creationDate, LLUUID ownerID,
  607. LLUUID creatorID, LLUUID lastOwnerID, uint localID, PrimitiveBaseShape shape,
  608. LLVector3 position, LLQuaternion rotation, uint flags)
  609. {
  610. m_regionHandle = regionHandle;
  611. m_parentGroup = parent;
  612. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  613. CreationDate = creationDate;
  614. OwnerID = ownerID;
  615. CreatorID = creatorID;
  616. LastOwnerID = lastOwnerID;
  617. UUID = LLUUID.Random();
  618. LocalID = (uint) (localID);
  619. Shape = shape;
  620. OwnershipCost = 0;
  621. ObjectSaleType = (byte) 0;
  622. SalePrice = 0;
  623. Category = (uint) 0;
  624. LastOwnerID = CreatorID;
  625. OffsetPosition = position;
  626. RotationOffset = rotation;
  627. ObjectFlags = flags;
  628. // Since we don't store script state, this is only a 'temporary' objectflag now
  629. // If the object is scripted, the script will get loaded and this will be set again
  630. ObjectFlags &= ~(uint)LLObject.ObjectFlags.Scripted;
  631. TrimPermissions();
  632. // ApplyPhysics();
  633. ScheduleFullUpdate();
  634. }
  635. #endregion
  636. /// <summary>
  637. ///
  638. /// </summary>
  639. /// <param name="xmlreader"></param>
  640. /// <returns></returns>
  641. public static SceneObjectPart FromXml(XmlReader xmlReader)
  642. {
  643. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  644. SceneObjectPart newobject = (SceneObjectPart) serializer.Deserialize(xmlReader);
  645. return newobject;
  646. }
  647. public void ApplyPhysics(uint rootObjectFlags, bool m_physicalPrim)
  648. {
  649. bool isPhysical = (((rootObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0) && m_physicalPrim);
  650. bool isPhantom = ((rootObjectFlags & (uint) LLObject.ObjectFlags.Phantom) != 0);
  651. // Added clarification.. since A rigid body is an object that you can kick around, etc.
  652. bool RigidBody = isPhysical && !isPhantom;
  653. // The only time the physics scene shouldn't know about the prim is if it's phantom
  654. if (!isPhantom)
  655. {
  656. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  657. Name,
  658. Shape,
  659. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  660. AbsolutePosition.Z),
  661. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  662. new Quaternion(RotationOffset.W, RotationOffset.X,
  663. RotationOffset.Y, RotationOffset.Z), RigidBody);
  664. DoPhysicsPropertyUpdate(RigidBody, true);
  665. }
  666. }
  667. public void ApplyNextOwnerPermissions()
  668. {
  669. BaseMask = NextOwnerMask;
  670. OwnerMask = NextOwnerMask;
  671. TriggerScriptChangedEvent(Changed.OWNER);
  672. }
  673. public void TrimPermissions()
  674. {
  675. BaseMask &= (uint)PermissionMask.All;
  676. OwnerMask &= (uint)PermissionMask.All;
  677. GroupMask &= (uint)PermissionMask.All;
  678. EveryoneMask &= (uint)PermissionMask.All;
  679. NextOwnerMask &= (uint)PermissionMask.All;
  680. }
  681. /// <summary>
  682. ///
  683. /// </summary>
  684. /// <param name="xmlWriter"></param>
  685. public void ToXml(XmlWriter xmlWriter)
  686. {
  687. XmlSerializer serializer = new XmlSerializer(typeof (SceneObjectPart));
  688. serializer.Serialize(xmlWriter, this);
  689. }
  690. public EntityIntersection TestIntersection(Ray iray, Quaternion parentrot)
  691. {
  692. // In this case we're using a sphere with a radius of the largest dimention of the prim
  693. // TODO: Change to take shape into account
  694. EntityIntersection returnresult = new EntityIntersection();
  695. Vector3 vAbsolutePosition = new Vector3(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z);
  696. Vector3 vScale = new Vector3(Scale.X, Scale.Y, Scale.Z);
  697. Quaternion qRotation =
  698. new Quaternion(RotationOffset.W, RotationOffset.X, RotationOffset.Y, RotationOffset.Z);
  699. //Quaternion worldRotation = (qRotation*parentrot);
  700. //Matrix3 worldRotM = worldRotation.ToRotationMatrix();
  701. Vector3 rOrigin = iray.Origin;
  702. Vector3 rDirection = iray.Direction;
  703. //rDirection = rDirection.Normalize();
  704. // Buidling the first part of the Quadratic equation
  705. Vector3 r2ndDirection = rDirection*rDirection;
  706. float itestPart1 = r2ndDirection.x + r2ndDirection.y + r2ndDirection.z;
  707. // Buidling the second part of the Quadratic equation
  708. Vector3 tmVal2 = rOrigin - vAbsolutePosition;
  709. Vector3 r2Direction = rDirection*2.0f;
  710. Vector3 tmVal3 = r2Direction*tmVal2;
  711. float itestPart2 = tmVal3.x + tmVal3.y + tmVal3.z;
  712. // Buidling the third part of the Quadratic equation
  713. Vector3 tmVal4 = rOrigin*rOrigin;
  714. Vector3 tmVal5 = vAbsolutePosition*vAbsolutePosition;
  715. Vector3 tmVal6 = vAbsolutePosition*rOrigin;
  716. // Set Radius to the largest dimention of the prim
  717. float radius = 0f;
  718. if (vScale.x > radius)
  719. radius = vScale.x;
  720. if (vScale.y > radius)
  721. radius = vScale.y;
  722. if (vScale.z > radius)
  723. radius = vScale.z;
  724. //radius = radius;
  725. float itestPart3 = tmVal4.x + tmVal4.y + tmVal4.z + tmVal5.x + tmVal5.y + tmVal5.z -
  726. (2.0f*(tmVal6.x + tmVal6.y + tmVal6.z + (radius*radius)));
  727. // Yuk Quadradrics.. Solve first
  728. float rootsqr = (itestPart2*itestPart2) - (4.0f*itestPart1*itestPart3);
  729. if (rootsqr < 0.0f)
  730. {
  731. // No intersection
  732. return returnresult;
  733. }
  734. float root = ((-itestPart2) - (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  735. if (root < 0.0f)
  736. {
  737. // perform second quadratic root solution
  738. root = ((-itestPart2) + (float) Math.Sqrt((double) rootsqr))/(itestPart1*2.0f);
  739. // is there any intersection?
  740. if (root < 0.0f)
  741. {
  742. // nope, no intersection
  743. return returnresult;
  744. }
  745. }
  746. // We got an intersection. putting together an EntityIntersection object with the
  747. // intersection information
  748. Vector3 ipoint =
  749. new Vector3(iray.Origin.x + (iray.Direction.x*root), iray.Origin.y + (iray.Direction.y*root),
  750. iray.Origin.z + (iray.Direction.z*root));
  751. returnresult.HitTF = true;
  752. returnresult.ipoint = ipoint;
  753. // Normal is calculated by the difference and then normalizing the result
  754. Vector3 normalpart = ipoint - vAbsolutePosition;
  755. returnresult.normal = normalpart.Normalize();
  756. // It's funny how the LLVector3 object has a Distance function, but the Axiom.Math object doesnt.
  757. // I can write a function to do it.. but I like the fact that this one is Static.
  758. LLVector3 distanceConvert1 = new LLVector3(iray.Origin.x, iray.Origin.y, iray.Origin.z);
  759. LLVector3 distanceConvert2 = new LLVector3(ipoint.x, ipoint.y, ipoint.z);
  760. float distance = (float) Util.GetDistanceTo(distanceConvert1, distanceConvert2);
  761. returnresult.distance = distance;
  762. return returnresult;
  763. }
  764. /// <summary>
  765. ///
  766. /// </summary>
  767. public void SetParent(SceneObjectGroup parent)
  768. {
  769. m_parentGroup = parent;
  770. }
  771. public void SetSitTarget(Vector3 offset, Quaternion orientation)
  772. {
  773. m_sitTargetPosition = offset;
  774. m_sitTargetOrientation = orientation;
  775. }
  776. public LLVector3 GetSitTargetPositionLL()
  777. {
  778. return new LLVector3(m_sitTargetPosition.x, m_sitTargetPosition.y, m_sitTargetPosition.z);
  779. }
  780. public LLQuaternion GetSitTargetOrientationLL()
  781. {
  782. return
  783. new LLQuaternion(m_sitTargetOrientation.x, m_sitTargetOrientation.y, m_sitTargetOrientation.z,
  784. m_sitTargetOrientation.w);
  785. }
  786. // Utility function so the databases don't have to reference axiom.math
  787. public void SetSitTargetLL(LLVector3 offset, LLQuaternion orientation)
  788. {
  789. if (
  790. !(offset.X == 0 && offset.Y == 0 && offset.Z == 0 && (orientation.W == 0 || orientation.W == 1) &&
  791. orientation.X == 0 && orientation.Y == 0 && orientation.Z == 0))
  792. {
  793. m_sitTargetPosition = new Vector3(offset.X, offset.Y, offset.Z);
  794. m_sitTargetOrientation = new Quaternion(orientation.W, orientation.X, orientation.Y, orientation.Z);
  795. }
  796. }
  797. public Vector3 GetSitTargetPosition()
  798. {
  799. return m_sitTargetPosition;
  800. }
  801. public Quaternion GetSitTargetOrientation()
  802. {
  803. return m_sitTargetOrientation;
  804. }
  805. public void SetAvatarOnSitTarget(LLUUID avatarID)
  806. {
  807. m_sitTargetAvatar = avatarID;
  808. TriggerScriptChangedEvent(Changed.LINK);
  809. }
  810. public LLUUID GetAvatarOnSitTarget()
  811. {
  812. return m_sitTargetAvatar;
  813. }
  814. public LLUUID GetRootPartUUID()
  815. {
  816. if (m_parentGroup != null)
  817. {
  818. return m_parentGroup.UUID;
  819. }
  820. return LLUUID.Zero;
  821. }
  822. public static SceneObjectPart Create()
  823. {
  824. SceneObjectPart part = new SceneObjectPart();
  825. part.UUID = LLUUID.Random();
  826. PrimitiveBaseShape shape = PrimitiveBaseShape.Create();
  827. part.Shape = shape;
  828. part.Name = "Primitive";
  829. part.OwnerID = LLUUID.Random();
  830. return part;
  831. }
  832. #region Copying
  833. /// <summary>
  834. /// Duplicates this part.
  835. /// </summary>
  836. /// <returns></returns>
  837. public SceneObjectPart Copy(uint localID, LLUUID AgentID, LLUUID GroupID, int linkNum)
  838. {
  839. SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone();
  840. dupe.m_shape = m_shape.Copy();
  841. dupe.m_regionHandle = m_regionHandle;
  842. dupe.UUID = LLUUID.Random();
  843. dupe.LocalID = localID;
  844. dupe.OwnerID = AgentID;
  845. dupe.GroupID = GroupID;
  846. dupe.GroupPosition = new LLVector3(GroupPosition.X, GroupPosition.Y, GroupPosition.Z);
  847. dupe.OffsetPosition = new LLVector3(OffsetPosition.X, OffsetPosition.Y, OffsetPosition.Z);
  848. dupe.RotationOffset =
  849. new LLQuaternion(RotationOffset.X, RotationOffset.Y, RotationOffset.Z, RotationOffset.W);
  850. dupe.Velocity = new LLVector3(0, 0, 0);
  851. dupe.Acceleration = new LLVector3(0, 0, 0);
  852. dupe.AngularVelocity = new LLVector3(0, 0, 0);
  853. dupe.ObjectFlags = ObjectFlags;
  854. dupe.OwnershipCost = OwnershipCost;
  855. dupe.ObjectSaleType = ObjectSaleType;
  856. dupe.SalePrice = SalePrice;
  857. dupe.Category = Category;
  858. dupe.TaskInventory = (TaskInventoryDictionary)dupe.TaskInventory.Clone();
  859. dupe.ResetIDs(linkNum);
  860. // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
  861. dupe.LastOwnerID = ObjectOwner;
  862. byte[] extraP = new byte[Shape.ExtraParams.Length];
  863. Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
  864. dupe.Shape.ExtraParams = extraP;
  865. bool UsePhysics = ((dupe.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
  866. dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
  867. return dupe;
  868. }
  869. #endregion
  870. /// <summary>
  871. /// Reset LLUUIDs for this part. This involves generate this part's own LLUUID and
  872. /// generating new LLUUIDs for all the items in the inventory.
  873. /// </summary>
  874. /// <param name="linkNum'>Link number for the part</param>
  875. public void ResetIDs(int linkNum)
  876. {
  877. UUID = LLUUID.Random();
  878. LinkNum = linkNum;
  879. ResetInventoryIDs();
  880. }
  881. #region Update Scheduling
  882. /// <summary>
  883. ///
  884. /// </summary>
  885. private void ClearUpdateSchedule()
  886. {
  887. m_updateFlag = 0;
  888. }
  889. /// <summary>
  890. ///
  891. /// </summary>
  892. public void ScheduleFullUpdate()
  893. {
  894. if (m_parentGroup != null)
  895. {
  896. m_parentGroup.HasGroupChanged = true;
  897. }
  898. TimeStampFull = (uint) Util.UnixTimeSinceEpoch();
  899. m_updateFlag = 2;
  900. }
  901. public void AddFlag(LLObject.ObjectFlags flag)
  902. {
  903. LLObject.ObjectFlags prevflag = Flags;
  904. //uint objflags = Flags;
  905. if ((ObjectFlags & (uint) flag) == 0)
  906. {
  907. //Console.WriteLine("Adding flag: " + ((LLObject.ObjectFlags) flag).ToString());
  908. Flags |= flag;
  909. }
  910. //uint currflag = (uint)Flags;
  911. //System.Console.WriteLine("Aprev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  912. //ScheduleFullUpdate();
  913. }
  914. public void RemFlag(LLObject.ObjectFlags flag)
  915. {
  916. LLObject.ObjectFlags prevflag = Flags;
  917. if ((ObjectFlags & (uint) flag) != 0)
  918. {
  919. //Console.WriteLine("Removing flag: " + ((LLObject.ObjectFlags)flag).ToString());
  920. Flags &= ~flag;
  921. }
  922. //System.Console.WriteLine("prev: " + prevflag.ToString() + " curr: " + Flags.ToString());
  923. //ScheduleFullUpdate();
  924. }
  925. /// <summary>
  926. ///
  927. /// </summary>
  928. public void ScheduleTerseUpdate()
  929. {
  930. if (m_updateFlag < 1)
  931. {
  932. if (m_parentGroup != null)
  933. {
  934. m_parentGroup.HasGroupChanged = true;
  935. }
  936. TimeStampTerse = (uint) Util.UnixTimeSinceEpoch();
  937. m_updateFlag = 1;
  938. }
  939. }
  940. /// <summary>
  941. ///
  942. /// </summary>
  943. public void SendScheduledUpdates()
  944. {
  945. if (m_updateFlag == 1) //some change has been made so update the clients
  946. {
  947. AddTerseUpdateToAllAvatars();
  948. ClearUpdateSchedule();
  949. // This causes the Scene to 'poll' physical objects every couple of frames
  950. // bad, so it's been replaced by an event driven method.
  951. //if ((ObjectFlags & (uint)LLObject.ObjectFlags.Physics) != 0)
  952. //{
  953. // Only send the constant terse updates on physical objects!
  954. //ScheduleTerseUpdate();
  955. //}
  956. }
  957. else
  958. {
  959. if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes
  960. {
  961. AddFullUpdateToAllAvatars();
  962. ClearUpdateSchedule();
  963. }
  964. }
  965. }
  966. #endregion
  967. #region Shape
  968. /// <summary>
  969. ///
  970. /// </summary>
  971. /// <param name="shapeBlock"></param>
  972. public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
  973. {
  974. m_shape.PathBegin = shapeBlock.PathBegin;
  975. m_shape.PathEnd = shapeBlock.PathEnd;
  976. m_shape.PathScaleX = shapeBlock.PathScaleX;
  977. m_shape.PathScaleY = shapeBlock.PathScaleY;
  978. m_shape.PathShearX = shapeBlock.PathShearX;
  979. m_shape.PathShearY = shapeBlock.PathShearY;
  980. m_shape.PathSkew = shapeBlock.PathSkew;
  981. m_shape.ProfileBegin = shapeBlock.ProfileBegin;
  982. m_shape.ProfileEnd = shapeBlock.ProfileEnd;
  983. m_shape.PathCurve = shapeBlock.PathCurve;
  984. m_shape.ProfileCurve = shapeBlock.ProfileCurve;
  985. m_shape.ProfileHollow = shapeBlock.ProfileHollow;
  986. m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
  987. m_shape.PathRevolutions = shapeBlock.PathRevolutions;
  988. m_shape.PathTaperX = shapeBlock.PathTaperX;
  989. m_shape.PathTaperY = shapeBlock.PathTaperY;
  990. m_shape.PathTwist = shapeBlock.PathTwist;
  991. m_shape.PathTwistBegin = shapeBlock.PathTwistBegin;
  992. if (PhysActor != null)
  993. {
  994. PhysActor.Shape = m_shape;
  995. }
  996. ScheduleFullUpdate();
  997. }
  998. #endregion
  999. #region ExtraParams
  1000. public void UpdatePrimFlags(ushort type, bool inUse, byte[] data)
  1001. {
  1002. //m_log.Info("TSomething1:" + ((type & (ushort)ExtraParamType.Something1) == (ushort)ExtraParamType.Something1));
  1003. //m_log.Info("TSomething2:" + ((type & (ushort)ExtraParamType.Something2) == (ushort)ExtraParamType.Something2));
  1004. //m_log.Info("TSomething3:" + ((type & (ushort)ExtraParamType.Something3) == (ushort)ExtraParamType.Something3));
  1005. //m_log.Info("TSomething4:" + ((type & (ushort)ExtraParamType.Something4) == (ushort)ExtraParamType.Something4));
  1006. //m_log.Info("TSomething5:" + ((type & (ushort)ExtraParamType.Something5) == (ushort)ExtraParamType.Something5));
  1007. //m_log.Info("TSomething6:" + ((type & (ushort)ExtraParamType.Something6) == (ushort)ExtraParamType.Something6));
  1008. bool usePhysics = false;
  1009. bool IsTemporary = false;
  1010. bool IsPhantom = false;
  1011. bool castsShadows = false;
  1012. bool wasUsingPhysics = ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
  1013. //bool IsLocked = false;
  1014. int i = 0;
  1015. try
  1016. {
  1017. i += 46;
  1018. //IsLocked = (data[i++] != 0) ? true : false;
  1019. usePhysics = ((data[i++] != 0) && m_parentGroup.Scene.m_physicalPrim) ? true : false;
  1020. //System.Console.WriteLine("U" + packet.ToBytes().Length.ToString());
  1021. IsTemporary = (data[i++] != 0) ? true : false;
  1022. IsPhantom = (data[i++] != 0) ? true : false;
  1023. castsShadows = (data[i++] != 0) ? true : false;
  1024. }
  1025. catch (Exception)
  1026. {
  1027. Console.WriteLine("Ignoring invalid Packet:");
  1028. //Silently ignore it - TODO: FIXME Quick
  1029. }
  1030. if (usePhysics)
  1031. {
  1032. AddFlag(LLObject.ObjectFlags.Physics);
  1033. if (!wasUsingPhysics)
  1034. {
  1035. DoPhysicsPropertyUpdate(usePhysics, false);
  1036. }
  1037. }
  1038. else
  1039. {
  1040. RemFlag(LLObject.ObjectFlags.Physics);
  1041. if (wasUsingPhysics)
  1042. {
  1043. DoPhysicsPropertyUpdate(usePhysics, false);
  1044. }
  1045. }
  1046. if (IsPhantom)
  1047. {
  1048. AddFlag(LLObject.ObjectFlags.Phantom);
  1049. if (PhysActor != null)
  1050. {
  1051. m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1052. /// that's not wholesome. Had to make Scene public
  1053. PhysActor = null;
  1054. }
  1055. }
  1056. else
  1057. {
  1058. RemFlag(LLObject.ObjectFlags.Phantom);
  1059. if (PhysActor == null)
  1060. {
  1061. PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1062. Name,
  1063. Shape,
  1064. new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1065. AbsolutePosition.Z),
  1066. new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1067. new Quaternion(RotationOffset.W, RotationOffset.X,
  1068. RotationOffset.Y, RotationOffset.Z), usePhysics);
  1069. DoPhysicsPropertyUpdate(usePhysics, true);
  1070. }
  1071. else
  1072. {
  1073. PhysActor.IsPhysical = usePhysics;
  1074. DoPhysicsPropertyUpdate(usePhysics, false);
  1075. }
  1076. }
  1077. if (IsTemporary)
  1078. {
  1079. AddFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1080. }
  1081. else
  1082. {
  1083. RemFlag(LLObject.ObjectFlags.TemporaryOnRez);
  1084. }
  1085. // System.Console.WriteLine("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
  1086. ScheduleFullUpdate();
  1087. }
  1088. public void DoPhysicsPropertyUpdate(bool UsePhysics, bool isNew)
  1089. {
  1090. if (PhysActor != null)
  1091. {
  1092. if (UsePhysics != PhysActor.IsPhysical || isNew)
  1093. {
  1094. if (PhysActor.IsPhysical)
  1095. {
  1096. if (!isNew)
  1097. ParentGroup.Scene.RemovePhysicalPrim(1);
  1098. PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
  1099. PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
  1100. }
  1101. PhysActor.IsPhysical = UsePhysics;
  1102. // If we're not what we're supposed to be in the physics scene, recreate ourselves.
  1103. //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
  1104. /// that's not wholesome. Had to make Scene public
  1105. //PhysActor = null;
  1106. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
  1107. {
  1108. //PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape(
  1109. //Name,
  1110. //Shape,
  1111. //new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y,
  1112. //AbsolutePosition.Z),
  1113. //new PhysicsVector(Scale.X, Scale.Y, Scale.Z),
  1114. //new Quaternion(RotationOffset.W, RotationOffset.X,
  1115. //RotationOffset.Y, RotationOffset.Z), UsePhysics);
  1116. if (UsePhysics)
  1117. {
  1118. ParentGroup.Scene.AddPhysicalPrim(1);
  1119. PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
  1120. PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
  1121. }
  1122. }
  1123. }
  1124. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1125. }
  1126. }
  1127. public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
  1128. {
  1129. m_shape.ExtraParams = new byte[data.Length + 7];
  1130. int i = 0;
  1131. uint length = (uint) data.Length;
  1132. m_shape.ExtraParams[i++] = 1;
  1133. m_shape.ExtraParams[i++] = (byte) (type%256);
  1134. m_shape.ExtraParams[i++] = (byte) ((type >> 8)%256);
  1135. m_shape.ExtraParams[i++] = (byte) (length%256);
  1136. m_shape.ExtraParams[i++] = (byte) ((length >> 8)%256);
  1137. m_shape.ExtraParams[i++] = (byte) ((length >> 16)%256);
  1138. m_shape.ExtraParams[i++] = (byte) ((length >> 24)%256);
  1139. Array.Copy(data, 0, m_shape.ExtraParams, i, data.Length);
  1140. ScheduleFullUpdate();
  1141. }
  1142. #endregion
  1143. #region Physics
  1144. public float GetMass()
  1145. {
  1146. if (PhysActor != null)
  1147. {
  1148. return PhysActor.Mass;
  1149. }
  1150. else
  1151. {
  1152. return 0;
  1153. }
  1154. }
  1155. public LLVector3 GetGeometricCenter()
  1156. {
  1157. if (PhysActor != null)
  1158. {
  1159. return new LLVector3(PhysActor.CenterOfMass.X, PhysActor.CenterOfMass.Y, PhysActor.CenterOfMass.Z);
  1160. }
  1161. else
  1162. {
  1163. return new LLVector3(0, 0, 0);
  1164. }
  1165. }
  1166. #endregion
  1167. #region Texture
  1168. /// <summary>
  1169. ///
  1170. /// </summary>
  1171. /// <param name="textureEntry"></param>
  1172. public void UpdateTextureEntry(byte[] textureEntry)
  1173. {
  1174. m_shape.TextureEntry = textureEntry;
  1175. TriggerScriptChangedEvent(Changed.TEXTURE);
  1176. ScheduleFullUpdate();
  1177. }
  1178. // Added to handle bug in libsecondlife's TextureEntry.ToBytes()
  1179. // not handling RGBA properly. Cycles through, and "fixes" the color
  1180. // info
  1181. public void UpdateTexture(LLObject.TextureEntry tex)
  1182. {
  1183. //LLColor tmpcolor;
  1184. //for (uint i = 0; i < 32; i++)
  1185. //{
  1186. // if (tex.FaceTextures[i] != null)
  1187. // {
  1188. // tmpcolor = tex.GetFace((uint) i).RGBA;
  1189. // tmpcolor.A = tmpcolor.A*255;
  1190. // tmpcolor.R = tmpcolor.R*255;
  1191. // tmpcolor.G = tmpcolor.G*255;
  1192. // tmpcolor.B = tmpcolor.B*255;
  1193. // tex.FaceTextures[i].RGBA = tmpcolor;
  1194. // }
  1195. //}
  1196. //tmpcolor = tex.DefaultTexture.RGBA;
  1197. //tmpcolor.A = tmpcolor.A*255;
  1198. //tmpcolor.R = tmpcolor.R*255;
  1199. //tmpcolor.G = tmpcolor.G*255;
  1200. //tmpcolor.B = tmpcolor.B*255;
  1201. //tex.DefaultTexture.RGBA = tmpcolor;
  1202. UpdateTextureEntry(tex.ToBytes());
  1203. }
  1204. public byte ConvertScriptUintToByte(uint indata)
  1205. {
  1206. byte outdata = (byte)TextureAnimFlags.NONE;
  1207. if ((indata & 1) != 0) outdata |= (byte)TextureAnimFlags.ANIM_ON;
  1208. if ((indata & 2) != 0) outdata |= (byte)TextureAnimFlags.LOOP;
  1209. if ((indata & 4) != 0) outdata |= (byte)TextureAnimFlags.REVERSE;
  1210. if ((indata & 8) != 0) outdata |= (byte)TextureAnimFlags.PING_PONG;
  1211. if ((indata & 16) != 0) outdata |= (byte)TextureAnimFlags.SMOOTH;
  1212. if ((indata & 32) != 0) outdata |= (byte)TextureAnimFlags.ROTATE;
  1213. if ((indata & 64) != 0) outdata |= (byte)TextureAnimFlags.SCALE;
  1214. return outdata;
  1215. }
  1216. public void AddTextureAnimation(Primitive.TextureAnimation pTexAnim)
  1217. {
  1218. byte[] data = new byte[16];
  1219. int pos = 0;
  1220. // The flags don't like conversion from uint to byte, so we have to do
  1221. // it the crappy way. See the above function :(
  1222. data[pos] = ConvertScriptUintToByte(pTexAnim.Flags); pos++;
  1223. data[pos] = (byte)pTexAnim.Face; pos++;
  1224. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1225. data[pos] = (byte)pTexAnim.SizeX; pos++;
  1226. Helpers.FloatToBytes(pTexAnim.Start).CopyTo(data, pos);
  1227. Helpers.FloatToBytes(pTexAnim.Length ).CopyTo(data, pos + 4);
  1228. Helpers.FloatToBytes(pTexAnim.Rate).CopyTo(data, pos + 8);
  1229. m_TextureAnimation = data;
  1230. }
  1231. #endregion
  1232. #region ParticleSystem
  1233. public void AddNewParticleSystem(Primitive.ParticleSystem pSystem)
  1234. {
  1235. m_particleSystem = pSystem.GetBytes();
  1236. }
  1237. #endregion
  1238. #region Position
  1239. public void AttachToAvatar(LLUUID agentId, ScenePresence presence, byte attachPt, LLQuaternion rotation, RegionInfo regionInfo)
  1240. {
  1241. m_attachAgentId = agentId;
  1242. m_attachPresence = presence;
  1243. m_attachPt = attachPt;
  1244. m_attachRot = rotation;
  1245. m_attachRegInfo = regionInfo;
  1246. RotationOffset = new LLQuaternion(0, 0, 0, 1);
  1247. ScheduleFullUpdate();
  1248. }
  1249. public void Detach()
  1250. {
  1251. m_attachPresence = null;
  1252. ScheduleFullUpdate();
  1253. }
  1254. /// <summary>
  1255. ///
  1256. /// </summary>
  1257. /// <param name="pos"></param>
  1258. public void UpdateOffSet(LLVector3 pos)
  1259. {
  1260. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1261. OffsetPosition = newPos;
  1262. ScheduleTerseUpdate();
  1263. }
  1264. public void UpdateGroupPosition(LLVector3 pos)
  1265. {
  1266. LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
  1267. GroupPosition = newPos;
  1268. ScheduleTerseUpdate();
  1269. }
  1270. #endregion
  1271. #region rotation
  1272. public void UpdateRotation(LLQuaternion rot)
  1273. {
  1274. RotationOffset = new LLQuaternion(rot.X, rot.Y, rot.Z, rot.W);
  1275. ScheduleTerseUpdate();
  1276. }
  1277. #endregion
  1278. #region Sound
  1279. public void PreloadSound(string sound)
  1280. {
  1281. LLUUID ownerID = OwnerID;
  1282. LLUUID objectID = UUID;
  1283. LLUUID soundID = LLUUID.Zero;
  1284. if (!LLUUID.TryParse(sound, out soundID))
  1285. {
  1286. //Trys to fetch sound id from prim's inventory.
  1287. //Prim's inventory doesn't support non script items yet
  1288. SceneObjectPart op = this;
  1289. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1290. {
  1291. if (item.Value.Name == sound)
  1292. {
  1293. soundID = item.Value.ItemID;
  1294. break;
  1295. }
  1296. }
  1297. }
  1298. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1299. foreach (ScenePresence p in avatarts)
  1300. {
  1301. // TODO: some filtering by distance of avatar
  1302. p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
  1303. }
  1304. }
  1305. public void SendSound(string sound, double volume, bool triggered)
  1306. {
  1307. if (volume > 1)
  1308. volume = 1;
  1309. if (volume < 0)
  1310. volume = 0;
  1311. LLUUID ownerID = OwnerID;
  1312. LLUUID objectID = UUID;
  1313. LLUUID parentID = GetRootPartUUID();
  1314. LLUUID soundID = LLUUID.Zero;
  1315. LLVector3 position = AbsolutePosition; // region local
  1316. ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
  1317. byte flags = 0;
  1318. if (!LLUUID.TryParse(sound, out soundID))
  1319. {
  1320. // search sound file from inventory
  1321. SceneObjectPart op = this;
  1322. foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
  1323. {
  1324. if (item.Value.Name == sound)
  1325. {
  1326. soundID = item.Value.ItemID;
  1327. break;
  1328. }
  1329. }
  1330. }
  1331. List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
  1332. foreach (ScenePresence p in avatarts)
  1333. {
  1334. // TODO: some filtering by distance of avatar
  1335. if (triggered)
  1336. {
  1337. p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume);
  1338. }
  1339. else
  1340. {
  1341. p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags);
  1342. }
  1343. }
  1344. }
  1345. #endregion
  1346. #region Resizing/Scale
  1347. /// <summary>
  1348. ///
  1349. /// </summary>
  1350. /// <param name="scale"></param>
  1351. public void Resize(LLVector3 scale)
  1352. {
  1353. m_shape.Scale = scale;
  1354. ScheduleFullUpdate();
  1355. }
  1356. #endregion
  1357. public void UpdatePermissions(LLUUID AgentID, byte field, uint localID, uint mask, byte addRemTF)
  1358. {
  1359. bool set = addRemTF == 1;
  1360. // Are we the owner?
  1361. if (AgentID == OwnerID)
  1362. {
  1363. switch (field)
  1364. {
  1365. case 2:
  1366. OwnerMask = ApplyMask(OwnerMask, set, mask);
  1367. break;
  1368. case 4:
  1369. GroupMask = ApplyMask(GroupMask, set, mask);
  1370. break;
  1371. case 8:
  1372. EveryoneMask = ApplyMask(EveryoneMask, set, mask);
  1373. break;
  1374. case 16:
  1375. NextOwnerMask = ApplyMask(NextOwnerMask, set, mask);
  1376. break;
  1377. }
  1378. SendFullUpdateToAllClients();
  1379. SendObjectPropertiesToClient(AgentID);
  1380. }
  1381. }
  1382. private void SendObjectPropertiesToClient(LLUUID AgentID)
  1383. {
  1384. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1385. for (int i = 0; i < avatars.Count; i++)
  1386. {
  1387. // Ugly reference :(
  1388. if (avatars[i].UUID == AgentID)
  1389. {
  1390. m_parentGroup.GetProperties(avatars[i].ControllingClient);
  1391. }
  1392. }
  1393. }
  1394. private uint ApplyMask(uint val, bool set, uint mask)
  1395. {
  1396. if (set)
  1397. {
  1398. return val |= mask;
  1399. }
  1400. else
  1401. {
  1402. return val &= ~mask;
  1403. }
  1404. }
  1405. #region Client Update Methods
  1406. public void AddFullUpdateToAllAvatars()
  1407. {
  1408. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1409. for (int i = 0; i < avatars.Count; i++)
  1410. {
  1411. avatars[i].QueuePartForUpdate(this);
  1412. }
  1413. }
  1414. public void SendFullUpdateToAllClientsExcept(LLUUID agentID)
  1415. {
  1416. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1417. for (int i = 0; i < avatars.Count; i++)
  1418. {
  1419. // Ugly reference :(
  1420. if (avatars[i].UUID != agentID)
  1421. {
  1422. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1423. avatars[i].GenerateClientFlags(UUID));
  1424. }
  1425. }
  1426. }
  1427. public void AddFullUpdateToAvatar(ScenePresence presence)
  1428. {
  1429. presence.QueuePartForUpdate(this);
  1430. }
  1431. /// <summary>
  1432. ///
  1433. /// </summary>
  1434. public void SendFullUpdateToAllClients()
  1435. {
  1436. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1437. for (int i = 0; i < avatars.Count; i++)
  1438. {
  1439. // Ugly reference :(
  1440. m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this,
  1441. avatars[i].GenerateClientFlags(UUID));
  1442. }
  1443. }
  1444. /// <summary>
  1445. ///
  1446. /// </summary>
  1447. /// <param name="remoteClient"></param>
  1448. public void SendFullUpdate(IClientAPI remoteClient, uint clientFlags)
  1449. {
  1450. m_parentGroup.SendPartFullUpdate(remoteClient, this, clientFlags);
  1451. }
  1452. /// <summary>
  1453. ///
  1454. /// </summary>
  1455. /// <param name="remoteClient"></param>
  1456. public void SendFullUpdateToClient(IClientAPI remoteClient, uint clientflags)
  1457. {
  1458. LLVector3 lPos;
  1459. lPos = OffsetPosition;
  1460. SendFullUpdateToClient(remoteClient, lPos, clientflags);
  1461. }
  1462. public void SendAttachedUpdateToClient(IClientAPI remoteClient, LLVector3 lPos, uint clientFlags)
  1463. {
  1464. ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
  1465. objupdate.RegionData.RegionHandle = m_attachRegInfo.RegionHandle;
  1466. objupdate.RegionData.TimeDilation = 64096;
  1467. objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[2];
  1468. // avatar stuff - horrible group copypaste
  1469. objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
  1470. objupdate.ObjectData[0].PSBlock = new byte[0];
  1471. objupdate.ObjectData[0].ExtraParams = new byte[1];
  1472. objupdate.ObjectData[0].MediaURL = new byte[0];
  1473. objupdate.ObjectData[0].NameValue = new byte[0];
  1474. objupdate.ObjectData[0].Text = new byte[0];
  1475. objupdate.ObjectData[0].TextColor = new byte[4];
  1476. objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
  1477. objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
  1478. objupdate.ObjectData[0].Material = 4;
  1479. objupdate.ObjectData[0].TextureAnim = new byte[0];
  1480. objupdate.ObjectData[0].Sound = LLUUID.Zero;
  1481. objupdate.ObjectData[0].State = 0;
  1482. objupdate.ObjectData[0].Data = new byte[0];
  1483. objupdate.ObjectData[0].ObjectData = new byte[76];
  1484. objupdate.ObjectData[0].ObjectData[15] = 128;
  1485. objupdate.ObjectData[0].ObjectData[16] = 63;
  1486. objupdate.ObjectData[0].ObjectData[56] = 128;
  1487. objupdate.ObjectData[0].ObjectData[61] = 102;
  1488. objupdate.ObjectData[0].ObjectData[62] = 40;
  1489. objupdate.ObjectData[0].ObjectData[63] = 61;
  1490. objupdate.ObjectData[0].ObjectData[64] = 189;
  1491. objupdate.ObjectData[0].UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24);
  1492. objupdate.ObjectData[0].PathCurve = 16;
  1493. objupdate.ObjectData[0].ProfileCurve = 1;
  1494. objupdate.ObjectData[0].PathScaleX = 100;
  1495. objupdate.ObjectData[0].PathScaleY = 100;
  1496. objupdate.ObjectData[0].ParentID = 0;
  1497. objupdate.ObjectData[0].OwnerID = LLUUID.Zero;
  1498. objupdate.ObjectData[0].Scale = new LLVector3(1, 1, 1);
  1499. objupdate.ObjectData[0].PCode = 47;
  1500. objupdate.ObjectData[0].TextureEntry = ScenePresence.DefaultTexture;
  1501. objupdate.ObjectData[0].ID = m_attachPresence.LocalId;
  1502. objupdate.ObjectData[0].FullID = m_attachAgentId;
  1503. objupdate.ObjectData[0].ParentID = 0;
  1504. objupdate.ObjectData[0].NameValue =
  1505. Helpers.StringToField("FirstName STRING RW SV " + m_attachPresence.Firstname + "\nLastName STRING RW SV " + m_attachPresence.Lastname);
  1506. LLVector3 pos2 = m_attachPresence.AbsolutePosition;
  1507. // new LLVector3((float) Pos.X, (float) Pos.Y, (float) Pos.Z);
  1508. byte[] pb = pos2.GetBytes();
  1509. Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length);
  1510. // primitive part
  1511. objupdate.ObjectData[1] = new ObjectUpdatePacket.ObjectDataBlock();
  1512. // SetDefaultPrimPacketValues
  1513. objupdate.ObjectData[1].PSBlock = new byte[0];
  1514. objupdate.ObjectData[1].ExtraParams = new byte[1];
  1515. objupdate.ObjectData[1].MediaURL = new byte[0];
  1516. objupdate.ObjectData[1].NameValue = new byte[0];
  1517. objupdate.ObjectData[1].Text = new byte[0];
  1518. objupdate.ObjectData[1].TextColor = new byte[4];
  1519. objupdate.ObjectData[1].JointAxisOrAnchor = new LLVector3(0, 0, 0);
  1520. objupdate.ObjectData[1].JointPivot = new LLVector3(0, 0, 0);
  1521. objupdate.ObjectData[1].Material = 3;
  1522. objupdate.ObjectData[1].TextureAnim = new byte[0];
  1523. objupdate.ObjectData[1].Sound = LLUUID.Zero;
  1524. objupdate.ObjectData[1].State = 0;
  1525. objupdate.ObjectData[1].Data = new byte[0];
  1526. objupdate.ObjectData[1].ObjectData = new byte[60];
  1527. objupdate.ObjectData[1].ObjectData[46] = 128;
  1528. objupdate.ObjectData[1].ObjectData[47] = 63;
  1529. // SetPrimPacketShapeData
  1530. PrimitiveBaseShape primData = Shape;
  1531. objupdate.ObjectData[1].TextureEntry = primData.TextureEntry;
  1532. objupdate.ObjectData[1].PCode = primData.PCode;
  1533. objupdate.ObjectData[1].State = (byte)(((byte)m_attachPt) << 4);
  1534. objupdate.ObjectData[1].PathBegin = primData.PathBegin;
  1535. objupdate.ObjectData[1].PathEnd = primData.PathEnd;
  1536. objupdate.ObjectData[1].PathScaleX = primData.PathScaleX;
  1537. objupdate.ObjectData[1].PathScaleY = primData.PathScaleY;
  1538. objupdate.ObjectData[1].PathShearX = primData.PathShearX;
  1539. objupdate.ObjectData[1].PathShearY = primData.PathShearY;
  1540. objupdate.ObjectData[1].PathSkew = primData.PathSkew;
  1541. objupdate.ObjectData[1].ProfileBegin = primData.ProfileBegin;
  1542. objupdate.ObjectData[1].ProfileEnd = primData.ProfileEnd;
  1543. objupdate.ObjectData[1].Scale = primData.Scale;
  1544. objupdate.ObjectData[1].PathCurve = primData.PathCurve;
  1545. objupdate.ObjectData[1].ProfileCurve = primData.ProfileCurve;
  1546. objupdate.ObjectData[1].ProfileHollow = primData.ProfileHollow;
  1547. objupdate.ObjectData[1].PathRadiusOffset = primData.PathRadiusOffset;
  1548. objupdate.ObjectData[1].PathRevolutions = primData.PathRevolutions;
  1549. objupdate.ObjectData[1].PathTaperX = primData.PathTaperX;
  1550. objupdate.ObjectData[1].PathTaperY = primData.PathTaperY;
  1551. objupdate.ObjectData[1].PathTwist = primData.PathTwist;
  1552. objupdate.ObjectData[1].PathTwistBegin = primData.PathTwistBegin;
  1553. objupdate.ObjectData[1].ExtraParams = primData.ExtraParams;
  1554. objupdate.ObjectData[1].UpdateFlags = 276957500; // flags; // ??
  1555. objupdate.ObjectData[1].ID = LocalID;
  1556. objupdate.ObjectData[1].FullID = UUID;
  1557. objupdate.ObjectData[1].OwnerID = OwnerID;
  1558. objupdate.ObjectData[1].Text = Helpers.StringToField(Text);
  1559. objupdate.ObjectData[1].TextColor[0] = 255;
  1560. objupdate.ObjectData[1].TextColor[1] = 255;
  1561. objupdate.ObjectData[1].TextColor[2] = 255;
  1562. objupdate.ObjectData[1].TextColor[3] = 128;
  1563. objupdate.ObjectData[1].ParentID = objupdate.ObjectData[0].ID;
  1564. //objupdate.ObjectData[1].PSBlock = particleSystem;
  1565. //objupdate.ObjectData[1].ClickAction = clickAction;
  1566. objupdate.ObjectData[1].Radius = 20;
  1567. objupdate.ObjectData[1].NameValue =
  1568. Helpers.StringToField("AttachItemID STRING RW SV " + UUID);
  1569. LLVector3 pos = new LLVector3((float)0.0, (float)0.0, (float)0.0);
  1570. pb = pos.GetBytes();
  1571. Array.Copy(pb, 0, objupdate.ObjectData[1].ObjectData, 0, pb.Length);
  1572. byte[] brot = m_attachRot.GetBytes();
  1573. Array.Copy(brot, 0, objupdate.ObjectData[1].ObjectData, 36, brot.Length);
  1574. remoteClient.OutPacket(objupdate, ThrottleOutPacketType.Task);
  1575. }
  1576. public void SendFullUpdateToClient(IClientAPI remoteClient, LLVector3 lPos, uint clientFlags)
  1577. {
  1578. if (m_attachPresence != null)
  1579. {
  1580. SendAttachedUpdateToClient(remoteClient, lPos, clientFlags);
  1581. return;
  1582. }
  1583. LLQuaternion lRot;
  1584. lRot = RotationOffset;
  1585. clientFlags &= ~(uint) LLObject.ObjectFlags.CreateSelected;
  1586. if (remoteClient.AgentId == OwnerID)
  1587. {
  1588. if ((uint) (Flags & LLObject.ObjectFlags.CreateSelected) != 0)
  1589. {
  1590. clientFlags |= (uint) LLObject.ObjectFlags.CreateSelected;
  1591. Flags &= ~LLObject.ObjectFlags.CreateSelected;
  1592. }
  1593. }
  1594. byte[] color = new byte[] {m_color.R, m_color.G, m_color.B, m_color.A};
  1595. remoteClient.SendPrimitiveToClient(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalID, m_shape, lPos, clientFlags, m_uuid,
  1596. OwnerID,
  1597. m_text, color, ParentID, m_particleSystem, lRot, m_clickAction, m_TextureAnimation);
  1598. }
  1599. /// Terse updates
  1600. public void AddTerseUpdateToAllAvatars()
  1601. {
  1602. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1603. for (int i = 0; i < avatars.Count; i++)
  1604. {
  1605. avatars[i].QueuePartForUpdate(this);
  1606. }
  1607. }
  1608. public void AddTerseUpdateToAvatar(ScenePresence presence)
  1609. {
  1610. presence.QueuePartForUpdate(this);
  1611. }
  1612. /// <summary>
  1613. ///
  1614. /// </summary>
  1615. public void SendTerseUpdateToAllClients()
  1616. {
  1617. List<ScenePresence> avatars = m_parentGroup.GetScenePresences();
  1618. for (int i = 0; i < avatars.Count; i++)
  1619. {
  1620. m_parentGroup.SendPartTerseUpdate(avatars[i].ControllingClient, this);
  1621. }
  1622. }
  1623. /// <summary>
  1624. ///
  1625. /// </summary>
  1626. /// <param name="remoteClient"></param>
  1627. public void SendTerseUpdate(IClientAPI remoteClient)
  1628. {
  1629. m_parentGroup.SendPartTerseUpdate(remoteClient, this);
  1630. }
  1631. public void SendTerseUpdateToClient(IClientAPI remoteClient)
  1632. {
  1633. LLVector3 lPos;
  1634. lPos = OffsetPosition;
  1635. LLQuaternion mRot = RotationOffset;
  1636. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) == 0)
  1637. {
  1638. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalID, lPos, mRot);
  1639. }
  1640. else
  1641. {
  1642. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalID, lPos, mRot, Velocity,
  1643. RotationalVelocity);
  1644. //System.Console.WriteLine("LID: " + LocalID + " RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  1645. }
  1646. }
  1647. public void SendTerseUpdateToClient(IClientAPI remoteClient, LLVector3 lPos)
  1648. {
  1649. LLQuaternion mRot = RotationOffset;
  1650. if ((ObjectFlags & (uint) LLObject.ObjectFlags.Physics) == 0)
  1651. {
  1652. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalID, lPos, mRot);
  1653. }
  1654. else
  1655. {
  1656. remoteClient.SendPrimTerseUpdate(m_regionHandle, (ushort)(m_parentGroup.GetTimeDilation() * (float)ushort.MaxValue), LocalID, lPos, mRot, Velocity,
  1657. RotationalVelocity);
  1658. //System.Console.WriteLine("LID: " + LocalID + "RVel:" + RotationalVelocity.ToString() + " TD: " + ((ushort)(m_parentGroup.Scene.TimeDilation * 500000f)).ToString() + ":" + m_parentGroup.Scene.TimeDilation.ToString());
  1659. }
  1660. }
  1661. #endregion
  1662. public virtual void UpdateMovement()
  1663. {
  1664. }
  1665. #region Events
  1666. public void PhysicsRequestingTerseUpdate()
  1667. {
  1668. if (PhysActor != null)
  1669. {
  1670. LLVector3 newpos = new LLVector3(PhysActor.Position.GetBytes(), 0);
  1671. if (newpos.X > 257f || newpos.X < -1f || newpos.Y > 257f || newpos.Y < -1f)
  1672. {
  1673. m_parentGroup.AbsolutePosition = newpos;
  1674. return;
  1675. }
  1676. }
  1677. ScheduleTerseUpdate();
  1678. //SendTerseUpdateToAllClients();
  1679. }
  1680. #endregion
  1681. public void PhysicsOutOfBounds(PhysicsVector pos)
  1682. {
  1683. m_log.Info("[PHYSICS]: Physical Object went out of bounds.");
  1684. RemFlag(LLObject.ObjectFlags.Physics);
  1685. DoPhysicsPropertyUpdate(false, true);
  1686. m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor);
  1687. }
  1688. public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient)
  1689. {
  1690. }
  1691. public void SetText(string text, Vector3 color, double alpha)
  1692. {
  1693. Color = Color.FromArgb(0xff - (int) (alpha*0xff),
  1694. (int) (color.x*0xff),
  1695. (int) (color.y*0xff),
  1696. (int) (color.z*0xff));
  1697. Text = text;
  1698. }
  1699. }
  1700. }