PrimData.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using libsecondlife;
  5. namespace OpenSim.Framework.Assets
  6. {
  7. public class PrimData
  8. {
  9. private const uint FULL_MASK_PERMISSIONS = 2147483647;
  10. public LLUUID OwnerID;
  11. public byte PCode;
  12. public byte PathBegin;
  13. public byte PathEnd;
  14. public byte PathScaleX;
  15. public byte PathScaleY;
  16. public byte PathShearX;
  17. public byte PathShearY;
  18. public sbyte PathSkew;
  19. public byte ProfileBegin;
  20. public byte ProfileEnd;
  21. public LLVector3 Scale;
  22. public byte PathCurve;
  23. public byte ProfileCurve;
  24. public uint ParentID = 0;
  25. public byte ProfileHollow;
  26. public sbyte PathRadiusOffset;
  27. public byte PathRevolutions;
  28. public sbyte PathTaperX;
  29. public sbyte PathTaperY;
  30. public sbyte PathTwist;
  31. public sbyte PathTwistBegin;
  32. public byte[] Texture;
  33. public Int32 CreationDate;
  34. public uint OwnerMask = FULL_MASK_PERMISSIONS;
  35. public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
  36. public uint GroupMask = FULL_MASK_PERMISSIONS;
  37. public uint EveryoneMask = FULL_MASK_PERMISSIONS;
  38. public uint BaseMask = FULL_MASK_PERMISSIONS;
  39. //following only used during prim storage
  40. public LLVector3 Position;
  41. public LLQuaternion Rotation = new LLQuaternion(0,1,0,0);
  42. public uint LocalID;
  43. public LLUUID FullID;
  44. public PrimData()
  45. {
  46. }
  47. public PrimData(byte[] data)
  48. {
  49. int i =0;
  50. this.OwnerID = new LLUUID(data, i); i += 16;
  51. this.PCode = data[i++];
  52. this.PathBegin = data[i++];
  53. this.PathEnd = data[i++];
  54. this.PathScaleX = data[i++];
  55. this.PathScaleY = data[i++];
  56. this.PathShearX = data[i++];
  57. this.PathShearY = data[i++];
  58. this.PathSkew = (sbyte)data[i++];
  59. this.ProfileBegin = data[i++];
  60. this.ProfileEnd = data[i++];
  61. this.Scale = new LLVector3(data, i); i += 12;
  62. this.PathCurve = data[i++];
  63. this.ProfileCurve = data[i++];
  64. this.ParentID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  65. this.ProfileHollow = data[i++];
  66. this.PathRadiusOffset = (sbyte)data[i++];
  67. this.PathRevolutions = data[i++];
  68. this.PathTaperX = (sbyte)data[i++];
  69. this.PathTaperY =(sbyte) data[i++];
  70. this.PathTwist = (sbyte) data[i++];
  71. this.PathTwistBegin = (sbyte) data[i++];
  72. ushort length = (ushort)(data[i++] + (data[i++] << 8));
  73. this.Texture = new byte[length];
  74. Array.Copy(data, i, Texture, 0, length); i += length;
  75. this.CreationDate = (Int32)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  76. this.OwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  77. this.NextOwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  78. this.GroupMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  79. this.EveryoneMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  80. this.BaseMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  81. this.Position = new LLVector3(data, i); i += 12;
  82. this.Rotation = new LLQuaternion(data,i, true); i += 12;
  83. this.LocalID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
  84. this.FullID = new LLUUID(data, i); i += 16;
  85. }
  86. public byte[] ToBytes()
  87. {
  88. int i = 0;
  89. byte[] bytes = new byte[121 + Texture.Length];
  90. Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16;
  91. bytes[i++] = this.PCode;
  92. bytes[i++] = this.PathBegin;
  93. bytes[i++] = this.PathEnd;
  94. bytes[i++] = this.PathScaleX;
  95. bytes[i++] = this.PathScaleY;
  96. bytes[i++] = this.PathShearX;
  97. bytes[i++] = this.PathShearY;
  98. bytes[i++] = (byte)this.PathSkew;
  99. bytes[i++] = this.ProfileBegin;
  100. bytes[i++] = this.ProfileEnd;
  101. Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12;
  102. bytes[i++] = this.PathCurve;
  103. bytes[i++] = this.ProfileCurve;
  104. bytes[i++] = (byte)(ParentID % 256);
  105. bytes[i++] = (byte)((ParentID >> 8) % 256);
  106. bytes[i++] = (byte)((ParentID >> 16) % 256);
  107. bytes[i++] = (byte)((ParentID >> 24) % 256);
  108. bytes[i++] = this.ProfileHollow;
  109. bytes[i++] = ((byte)this.PathRadiusOffset);
  110. bytes[i++] = this.PathRevolutions;
  111. bytes[i++] = ((byte) this.PathTaperX);
  112. bytes[i++] = ((byte) this.PathTaperY);
  113. bytes[i++] = ((byte) this.PathTwist);
  114. bytes[i++] = ((byte) this.PathTwistBegin);
  115. bytes[i++] = (byte)(Texture.Length % 256);
  116. bytes[i++] = (byte)((Texture.Length >> 8) % 256);
  117. Array.Copy(Texture, 0, bytes, i, Texture.Length); i += Texture.Length;
  118. bytes[i++] = (byte)(this.CreationDate % 256);
  119. bytes[i++] = (byte)((this.CreationDate >> 8) % 256);
  120. bytes[i++] = (byte)((this.CreationDate >> 16) % 256);
  121. bytes[i++] = (byte)((this.CreationDate >> 24) % 256);
  122. bytes[i++] = (byte)(this.OwnerMask % 256);
  123. bytes[i++] = (byte)((this.OwnerMask >> 8) % 256);
  124. bytes[i++] = (byte)((this.OwnerMask >> 16) % 256);
  125. bytes[i++] = (byte)((this.OwnerMask >> 24) % 256);
  126. bytes[i++] = (byte)(this.NextOwnerMask % 256);
  127. bytes[i++] = (byte)((this.NextOwnerMask >> 8) % 256);
  128. bytes[i++] = (byte)((this.NextOwnerMask >> 16) % 256);
  129. bytes[i++] = (byte)((this.NextOwnerMask >> 24) % 256);
  130. bytes[i++] = (byte)(this.GroupMask % 256);
  131. bytes[i++] = (byte)((this.GroupMask >> 8) % 256);
  132. bytes[i++] = (byte)((this.GroupMask >> 16) % 256);
  133. bytes[i++] = (byte)((this.GroupMask >> 24) % 256);
  134. bytes[i++] = (byte)(this.EveryoneMask % 256);
  135. bytes[i++] = (byte)((this.EveryoneMask >> 8) % 256);
  136. bytes[i++] = (byte)((this.EveryoneMask >> 16) % 256);
  137. bytes[i++] = (byte)((this.EveryoneMask >> 24) % 256);
  138. bytes[i++] = (byte)(this.BaseMask % 256);
  139. bytes[i++] = (byte)((this.BaseMask >> 8) % 256);
  140. bytes[i++] = (byte)((this.BaseMask >> 16) % 256);
  141. bytes[i++] = (byte)((this.BaseMask >> 24) % 256);
  142. Array.Copy(this.Position.GetBytes(), 0, bytes, i, 12); i += 12;
  143. if (this.Rotation == new LLQuaternion(0,0,0,0))
  144. {
  145. this.Rotation = new LLQuaternion(0, 1, 0, 0);
  146. }
  147. Array.Copy(this.Rotation.GetBytes(), 0, bytes, i, 12); i += 12;
  148. bytes[i++] = (byte)(this.LocalID % 256);
  149. bytes[i++] = (byte)((this.LocalID >> 8) % 256);
  150. bytes[i++] = (byte)((this.LocalID >> 16) % 256);
  151. bytes[i++] = (byte)((this.LocalID >> 24) % 256);
  152. Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16;
  153. return bytes;
  154. }
  155. }
  156. }