1
0

PrimitiveBaseShape.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.Xml.Serialization;
  30. using libsecondlife;
  31. namespace OpenSim.Framework
  32. {
  33. public enum ProfileShape : byte
  34. {
  35. Circle = 0,
  36. Square = 1,
  37. IsometricTriangle = 2,
  38. EquilateralTriangle = 3,
  39. RightTriangle = 4,
  40. HalfCircle = 5
  41. }
  42. public enum HollowShape : byte
  43. {
  44. Same = 0,
  45. Circle = 16,
  46. Square = 32,
  47. Triangle = 48
  48. }
  49. public enum PCodeEnum : byte
  50. {
  51. Primitive = 9,
  52. Avatar = 47
  53. }
  54. public enum Extrusion : byte
  55. {
  56. Straight = 16,
  57. Curve1 = 32,
  58. Curve2 = 48,
  59. Flexible = 128
  60. }
  61. [Serializable]
  62. public class PrimitiveBaseShape
  63. {
  64. private static readonly LLObject.TextureEntry m_defaultTexture;
  65. public byte[] ExtraParams;
  66. private byte[] m_textureEntry;
  67. public ushort PathBegin;
  68. public byte PathCurve;
  69. public ushort PathEnd;
  70. public sbyte PathRadiusOffset;
  71. public byte PathRevolutions;
  72. public byte PathScaleX;
  73. public byte PathScaleY;
  74. public byte PathShearX;
  75. public byte PathShearY;
  76. public sbyte PathSkew;
  77. public sbyte PathTaperX;
  78. public sbyte PathTaperY;
  79. public sbyte PathTwist;
  80. public sbyte PathTwistBegin;
  81. public byte PCode;
  82. public ushort ProfileBegin;
  83. public byte ProfileCurve;
  84. public ushort ProfileEnd;
  85. public ushort ProfileHollow;
  86. public LLVector3 Scale;
  87. public byte State;
  88. static PrimitiveBaseShape()
  89. {
  90. m_defaultTexture =
  91. new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
  92. }
  93. public PrimitiveBaseShape()
  94. {
  95. PCode = (byte) PCodeEnum.Primitive;
  96. ExtraParams = new byte[1];
  97. Textures = m_defaultTexture;
  98. }
  99. [XmlIgnore]
  100. public LLObject.TextureEntry Textures
  101. {
  102. get { return new LLObject.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); }
  103. set { m_textureEntry = value.ToBytes(); }
  104. }
  105. public byte[] TextureEntry
  106. {
  107. get { return m_textureEntry; }
  108. set { m_textureEntry = value; }
  109. }
  110. public ProfileShape ProfileShape
  111. {
  112. get { return (ProfileShape) (ProfileCurve & 0xf); }
  113. set
  114. {
  115. byte oldValueMasked = (byte) (ProfileCurve & 0xf0);
  116. ProfileCurve = (byte) (oldValueMasked | (byte) value);
  117. }
  118. }
  119. public HollowShape HollowShape
  120. {
  121. get { return (HollowShape) (ProfileCurve & 0xf0); }
  122. set
  123. {
  124. byte oldValueMasked = (byte) (ProfileCurve & 0x0f);
  125. ProfileCurve = (byte) (oldValueMasked | (byte) value);
  126. }
  127. }
  128. public static PrimitiveBaseShape Default
  129. {
  130. get
  131. {
  132. PrimitiveBaseShape boxShape = CreateBox();
  133. boxShape.SetScale(0.5f);
  134. return boxShape;
  135. }
  136. }
  137. public static PrimitiveBaseShape Create()
  138. {
  139. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  140. return shape;
  141. }
  142. public static PrimitiveBaseShape CreateBox()
  143. {
  144. PrimitiveBaseShape shape = Create();
  145. shape.PathCurve = (byte) Extrusion.Straight;
  146. shape.ProfileShape = ProfileShape.Square;
  147. shape.PathScaleX = 100;
  148. shape.PathScaleY = 100;
  149. return shape;
  150. }
  151. public static PrimitiveBaseShape CreateCylinder()
  152. {
  153. PrimitiveBaseShape shape = Create();
  154. shape.PathCurve = (byte) Extrusion.Curve1;
  155. shape.ProfileShape = ProfileShape.Square;
  156. shape.PathScaleX = 100;
  157. shape.PathScaleY = 100;
  158. return shape;
  159. }
  160. public void SetScale(float side)
  161. {
  162. Scale = new LLVector3(side, side, side);
  163. }
  164. public void SetHeigth(float heigth)
  165. {
  166. Scale.Z = heigth;
  167. }
  168. public void SetRadius(float radius)
  169. {
  170. Scale.X = Scale.Y = radius*2f;
  171. }
  172. //void returns need to change of course
  173. public virtual void GetMesh()
  174. {
  175. }
  176. public PrimitiveBaseShape Copy()
  177. {
  178. return (PrimitiveBaseShape) MemberwiseClone();
  179. }
  180. public static PrimitiveBaseShape CreateCylinder(float radius, float heigth)
  181. {
  182. PrimitiveBaseShape shape = CreateCylinder();
  183. shape.SetHeigth(heigth);
  184. shape.SetRadius(radius);
  185. return shape;
  186. }
  187. public void SetPathRange(LLVector3 pathRange)
  188. {
  189. PathBegin = LLObject.PackBeginCut(pathRange.X);
  190. PathEnd = LLObject.PackEndCut(pathRange.Y);
  191. }
  192. public void SetProfileRange(LLVector3 profileRange)
  193. {
  194. ProfileBegin = LLObject.PackBeginCut(profileRange.X);
  195. ProfileEnd = LLObject.PackEndCut(profileRange.Y);
  196. }
  197. }
  198. }