SceneObject.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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.Collections.Generic;
  29. using System.Text;
  30. using libsecondlife;
  31. using libsecondlife.Packets;
  32. using OpenSim.Framework.Interfaces;
  33. using OpenSim.Physics.Manager;
  34. namespace OpenSim.Region.Environment.Scenes
  35. {
  36. public class SceneObject : EntityBase
  37. {
  38. private Encoding enc = Encoding.ASCII;
  39. private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>(); //list of all primitive id's that are part of this group
  40. public Primitive rootPrimitive;
  41. private new Scene m_world;
  42. protected ulong m_regionHandle;
  43. private bool physicsEnabled = false;
  44. private PhysicsScene m_PhysScene;
  45. private PhysicsActor m_PhysActor;
  46. public LLUUID rootUUID
  47. {
  48. get
  49. {
  50. this.uuid = this.rootPrimitive.uuid;
  51. return this.uuid;
  52. }
  53. }
  54. public uint rootLocalID
  55. {
  56. get
  57. {
  58. this.m_localId = this.rootPrimitive.LocalId;
  59. return this.LocalId;
  60. }
  61. }
  62. /// <summary>
  63. ///
  64. /// </summary>
  65. public SceneObject(ulong regionHandle, Scene world, ObjectAddPacket addPacket, LLUUID ownerID, uint localID)
  66. {
  67. m_regionHandle = regionHandle;
  68. m_world = world;
  69. this.Pos = addPacket.ObjectData.RayEnd;
  70. this.CreateRootFromPacket(addPacket, ownerID, localID);
  71. }
  72. /// <summary>
  73. ///
  74. /// </summary>
  75. /// <remarks>Need a null constructor for duplication</remarks>
  76. public SceneObject()
  77. {
  78. }
  79. /// <summary>
  80. ///
  81. /// </summary>
  82. /// <param name="addPacket"></param>
  83. /// <param name="agentID"></param>
  84. /// <param name="localID"></param>
  85. public void CreateRootFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
  86. {
  87. this.rootPrimitive = new Primitive( this.m_regionHandle, this.m_world, addPacket, agentID, localID, true, this, this);
  88. this.children.Add(rootPrimitive);
  89. this.ChildPrimitives.Add(this.rootUUID, this.rootPrimitive);
  90. }
  91. /// <summary>
  92. ///
  93. /// </summary>
  94. /// <param name="data"></param>
  95. public void CreateFromBytes(byte[] data)
  96. {
  97. }
  98. /// <summary>
  99. ///
  100. /// </summary>
  101. /// <returns>A complete copy of the object</returns>
  102. public SceneObject Copy()
  103. {
  104. SceneObject dupe = new SceneObject();
  105. Primitive newRoot = this.rootPrimitive.Copy((EntityBase)dupe, dupe);
  106. foreach (EntityBase child in this.children)
  107. {
  108. EntityBase newChild = child.Copy();
  109. dupe.children.Add(newChild);
  110. }
  111. return dupe;
  112. }
  113. /// <summary>
  114. ///
  115. /// </summary>
  116. public void DeleteAllChildren()
  117. {
  118. this.children.Clear();
  119. this.ChildPrimitives.Clear();
  120. this.rootPrimitive = null;
  121. }
  122. /// <summary>
  123. ///
  124. /// </summary>
  125. /// <param name="primObject"></param>
  126. public void AddNewChildPrims(SceneObject primObject)
  127. {
  128. this.rootPrimitive.AddNewChildren(primObject);
  129. }
  130. public void AddChildToList(Primitive prim)
  131. {
  132. if (!this.ChildPrimitives.ContainsKey(prim.uuid))
  133. {
  134. this.ChildPrimitives.Add(prim.uuid, prim);
  135. }
  136. }
  137. /// <summary>
  138. ///
  139. /// </summary>
  140. /// <param name="primID"></param>
  141. /// <returns></returns>
  142. public Primitive HasChildPrim(LLUUID primID)
  143. {
  144. if (this.ChildPrimitives.ContainsKey(primID))
  145. {
  146. return this.ChildPrimitives[primID];
  147. }
  148. return null;
  149. }
  150. /// <summary>
  151. ///
  152. /// </summary>
  153. /// <param name="localID"></param>
  154. /// <returns></returns>
  155. public Primitive HasChildPrim(uint localID)
  156. {
  157. Primitive returnPrim = null;
  158. foreach (Primitive prim in this.ChildPrimitives.Values)
  159. {
  160. if (prim.LocalId == localID)
  161. {
  162. returnPrim = prim;
  163. break;
  164. }
  165. }
  166. return returnPrim;
  167. }
  168. public void SendAllChildPrimsToClient(IClientAPI client)
  169. {
  170. this.rootPrimitive.SendFullUpdateForAllChildren(client);
  171. }
  172. /// <summary>
  173. ///
  174. /// </summary>
  175. public override void BackUp()
  176. {
  177. }
  178. /// <summary>
  179. ///
  180. /// </summary>
  181. /// <param name="offset"></param>
  182. /// <param name="pos"></param>
  183. /// <param name="remoteClient"></param>
  184. public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
  185. {
  186. this.rootPrimitive.Pos = pos ;
  187. this.rootPrimitive.SendTerseUpdateForAllChildren(remoteClient);
  188. }
  189. /// <summary>
  190. ///
  191. /// </summary>
  192. /// <param name="client"></param>
  193. public void GetProperites(IClientAPI client)
  194. {
  195. ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
  196. proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
  197. proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
  198. proper.ObjectData[0].ItemID = LLUUID.Zero;
  199. proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.CreationDate;
  200. proper.ObjectData[0].CreatorID = this.rootPrimitive.CreatorID;
  201. proper.ObjectData[0].FolderID = LLUUID.Zero;
  202. proper.ObjectData[0].FromTaskID = LLUUID.Zero;
  203. proper.ObjectData[0].GroupID = LLUUID.Zero;
  204. proper.ObjectData[0].InventorySerial = 0;
  205. proper.ObjectData[0].LastOwnerID = this.rootPrimitive.LastOwnerID;
  206. proper.ObjectData[0].ObjectID = this.rootUUID;
  207. proper.ObjectData[0].OwnerID = this.rootPrimitive.OwnerID;
  208. proper.ObjectData[0].TouchName = enc.GetBytes(this.rootPrimitive.TouchName + "\0");
  209. proper.ObjectData[0].TextureID = new byte[0];
  210. proper.ObjectData[0].SitName = enc.GetBytes(this.rootPrimitive.SitName +"\0") ;
  211. proper.ObjectData[0].Name = enc.GetBytes(this.rootPrimitive.Name +"\0");
  212. proper.ObjectData[0].Description = enc.GetBytes(this.rootPrimitive.Description +"\0");
  213. proper.ObjectData[0].OwnerMask = this.rootPrimitive.OwnerMask;
  214. proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.NextOwnerMask;
  215. proper.ObjectData[0].GroupMask = this.rootPrimitive.GroupMask;
  216. proper.ObjectData[0].EveryoneMask = this.rootPrimitive.EveryoneMask;
  217. proper.ObjectData[0].BaseMask = this.rootPrimitive.BaseMask;
  218. client.OutPacket(proper);
  219. }
  220. }
  221. }