PrimData.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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;
  29. using libsecondlife;
  30. namespace OpenSim.Framework.Types
  31. {
  32. public class PrimData
  33. {
  34. private const uint FULL_MASK_PERMISSIONS = 2147483647;
  35. public LLUUID OwnerID;
  36. public byte PCode;
  37. public ushort PathBegin;
  38. public ushort PathEnd;
  39. public byte PathScaleX;
  40. public byte PathScaleY;
  41. public byte PathShearX;
  42. public byte PathShearY;
  43. public sbyte PathSkew;
  44. public ushort ProfileBegin;
  45. public ushort ProfileEnd;
  46. public LLVector3 Scale;
  47. public byte PathCurve;
  48. public byte ProfileCurve;
  49. public uint ParentID = 0;
  50. public ushort ProfileHollow;
  51. public sbyte PathRadiusOffset;
  52. public byte PathRevolutions;
  53. public sbyte PathTaperX;
  54. public sbyte PathTaperY;
  55. public sbyte PathTwist;
  56. public sbyte PathTwistBegin;
  57. public byte[] TextureEntry; // a LL textureEntry in byte[] format
  58. public Int32 CreationDate;
  59. public uint OwnerMask = FULL_MASK_PERMISSIONS;
  60. public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
  61. public uint GroupMask = FULL_MASK_PERMISSIONS;
  62. public uint EveryoneMask = FULL_MASK_PERMISSIONS;
  63. public uint BaseMask = FULL_MASK_PERMISSIONS;
  64. //following only used during prim storage
  65. public LLVector3 Position;
  66. public LLQuaternion Rotation = new LLQuaternion(0, 1, 0, 0);
  67. public uint LocalID;
  68. public LLUUID FullID;
  69. public PrimData()
  70. {
  71. }
  72. public PrimData(byte[] data)
  73. {
  74. int i = 0;
  75. this.OwnerID = new LLUUID(data, i); i += 16;
  76. this.PCode = data[i++];
  77. this.PathBegin = (ushort)(data[i++] + (data[i++] << 8));
  78. this.PathEnd = (ushort)(data[i++] + (data[i++] << 8));
  79. this.PathScaleX = data[i++];
  80. this.PathScaleY = data[i++];
  81. this.PathShearX = data[i++];
  82. this.PathShearY = data[i++];
  83. this.PathSkew = (sbyte)data[i++];
  84. this.ProfileBegin = (ushort)(data[i++] + (data[i++] << 8));
  85. this.ProfileEnd = (ushort)(data[i++] + (data[i++] << 8));
  86. this.Scale = new LLVector3(data, i); i += 12;
  87. this.PathCurve = data[i++];
  88. this.ProfileCurve = data[i++];
  89. this.ParentID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  90. this.ProfileHollow = (ushort)(data[i++] + (data[i++] << 8));
  91. this.PathRadiusOffset = (sbyte)data[i++];
  92. this.PathRevolutions = data[i++];
  93. this.PathTaperX = (sbyte)data[i++];
  94. this.PathTaperY = (sbyte)data[i++];
  95. this.PathTwist = (sbyte)data[i++];
  96. this.PathTwistBegin = (sbyte)data[i++];
  97. ushort length = (ushort)(data[i++] + (data[i++] << 8));
  98. this.TextureEntry = new byte[length];
  99. Array.Copy(data, i, TextureEntry, 0, length); i += length;
  100. this.CreationDate = (Int32)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  101. this.OwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  102. this.NextOwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  103. this.GroupMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  104. this.EveryoneMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  105. this.BaseMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  106. this.Position = new LLVector3(data, i); i += 12;
  107. this.Rotation = new LLQuaternion(data, i, true); i += 12;
  108. this.LocalID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  109. this.FullID = new LLUUID(data, i); i += 16;
  110. }
  111. public byte[] ToBytes()
  112. {
  113. int i = 0;
  114. byte[] bytes = new byte[126 + TextureEntry.Length];
  115. Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16;
  116. bytes[i++] = this.PCode;
  117. bytes[i++] = (byte)(this.PathBegin % 256);
  118. bytes[i++] = (byte)((this.PathBegin >> 8) % 256);
  119. bytes[i++] = (byte)(this.PathEnd % 256);
  120. bytes[i++] = (byte)((this.PathEnd >> 8) % 256);
  121. bytes[i++] = this.PathScaleX;
  122. bytes[i++] = this.PathScaleY;
  123. bytes[i++] = this.PathShearX;
  124. bytes[i++] = this.PathShearY;
  125. bytes[i++] = (byte)this.PathSkew;
  126. bytes[i++] = (byte)(this.ProfileBegin % 256);
  127. bytes[i++] = (byte)((this.ProfileBegin >> 8) % 256);
  128. bytes[i++] = (byte)(this.ProfileEnd % 256);
  129. bytes[i++] = (byte)((this.ProfileEnd >> 8) % 256);
  130. Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12;
  131. bytes[i++] = this.PathCurve;
  132. bytes[i++] = this.ProfileCurve;
  133. bytes[i++] = (byte)(ParentID % 256);
  134. bytes[i++] = (byte)((ParentID >> 8) % 256);
  135. bytes[i++] = (byte)((ParentID >> 16) % 256);
  136. bytes[i++] = (byte)((ParentID >> 24) % 256);
  137. bytes[i++] = (byte)(this.ProfileHollow % 256);
  138. bytes[i++] = (byte)((this.ProfileHollow >> 8) % 256);
  139. bytes[i++] = ((byte)this.PathRadiusOffset);
  140. bytes[i++] = this.PathRevolutions;
  141. bytes[i++] = ((byte)this.PathTaperX);
  142. bytes[i++] = ((byte)this.PathTaperY);
  143. bytes[i++] = ((byte)this.PathTwist);
  144. bytes[i++] = ((byte)this.PathTwistBegin);
  145. bytes[i++] = (byte)(TextureEntry.Length % 256);
  146. bytes[i++] = (byte)((TextureEntry.Length >> 8) % 256);
  147. Array.Copy(TextureEntry, 0, bytes, i, TextureEntry.Length); i += TextureEntry.Length;
  148. bytes[i++] = (byte)(this.CreationDate % 256);
  149. bytes[i++] = (byte)((this.CreationDate >> 8) % 256);
  150. bytes[i++] = (byte)((this.CreationDate >> 16) % 256);
  151. bytes[i++] = (byte)((this.CreationDate >> 24) % 256);
  152. bytes[i++] = (byte)(this.OwnerMask % 256);
  153. bytes[i++] = (byte)((this.OwnerMask >> 8) % 256);
  154. bytes[i++] = (byte)((this.OwnerMask >> 16) % 256);
  155. bytes[i++] = (byte)((this.OwnerMask >> 24) % 256);
  156. bytes[i++] = (byte)(this.NextOwnerMask % 256);
  157. bytes[i++] = (byte)((this.NextOwnerMask >> 8) % 256);
  158. bytes[i++] = (byte)((this.NextOwnerMask >> 16) % 256);
  159. bytes[i++] = (byte)((this.NextOwnerMask >> 24) % 256);
  160. bytes[i++] = (byte)(this.GroupMask % 256);
  161. bytes[i++] = (byte)((this.GroupMask >> 8) % 256);
  162. bytes[i++] = (byte)((this.GroupMask >> 16) % 256);
  163. bytes[i++] = (byte)((this.GroupMask >> 24) % 256);
  164. bytes[i++] = (byte)(this.EveryoneMask % 256);
  165. bytes[i++] = (byte)((this.EveryoneMask >> 8) % 256);
  166. bytes[i++] = (byte)((this.EveryoneMask >> 16) % 256);
  167. bytes[i++] = (byte)((this.EveryoneMask >> 24) % 256);
  168. bytes[i++] = (byte)(this.BaseMask % 256);
  169. bytes[i++] = (byte)((this.BaseMask >> 8) % 256);
  170. bytes[i++] = (byte)((this.BaseMask >> 16) % 256);
  171. bytes[i++] = (byte)((this.BaseMask >> 24) % 256);
  172. Array.Copy(this.Position.GetBytes(), 0, bytes, i, 12); i += 12;
  173. if (this.Rotation == new LLQuaternion(0, 0, 0, 0))
  174. {
  175. this.Rotation = new LLQuaternion(0, 1, 0, 0);
  176. }
  177. Array.Copy(this.Rotation.GetBytes(), 0, bytes, i, 12); i += 12;
  178. bytes[i++] = (byte)(this.LocalID % 256);
  179. bytes[i++] = (byte)((this.LocalID >> 8) % 256);
  180. bytes[i++] = (byte)((this.LocalID >> 16) % 256);
  181. bytes[i++] = (byte)((this.LocalID >> 24) % 256);
  182. Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16;
  183. return bytes;
  184. }
  185. public static PrimData DefaultCube()
  186. {
  187. PrimData primData = new PrimData();
  188. primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
  189. primData.FullID = LLUUID.Random();
  190. primData.Scale = new LLVector3(0.5f, 0.5f, 0.5f);
  191. primData.Rotation = new LLQuaternion(0, 0, 0, 1);
  192. primData.PCode = 9;
  193. primData.ParentID = 0;
  194. primData.PathBegin = 0;
  195. primData.PathEnd = 0;
  196. primData.PathScaleX = 0;
  197. primData.PathScaleY = 0;
  198. primData.PathShearX = 0;
  199. primData.PathShearY = 0;
  200. primData.PathSkew = 0;
  201. primData.ProfileBegin = 0;
  202. primData.ProfileEnd = 0;
  203. primData.PathCurve = 16;
  204. primData.ProfileCurve = 1;
  205. primData.ProfileHollow = 0;
  206. primData.PathRadiusOffset = 0;
  207. primData.PathRevolutions = 0;
  208. primData.PathTaperX = 0;
  209. primData.PathTaperY = 0;
  210. primData.PathTwist = 0;
  211. primData.PathTwistBegin = 0;
  212. return primData;
  213. }
  214. }
  215. }