PrimitiveBaseShape.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 State;
  66. public byte PCode;
  67. public ushort PathBegin;
  68. public ushort PathEnd;
  69. public byte PathScaleX;
  70. public byte PathScaleY;
  71. public byte PathShearX;
  72. public byte PathShearY;
  73. public sbyte PathSkew;
  74. public ushort ProfileBegin;
  75. public ushort ProfileEnd;
  76. public LLVector3 Scale;
  77. public byte PathCurve;
  78. public byte ProfileCurve;
  79. public ushort ProfileHollow;
  80. public sbyte PathRadiusOffset;
  81. public byte PathRevolutions;
  82. public sbyte PathTaperX;
  83. public sbyte PathTaperY;
  84. public sbyte PathTwist;
  85. public sbyte PathTwistBegin;
  86. [XmlIgnore]
  87. public LLObject.TextureEntry Textures
  88. {
  89. get { return new LLObject.TextureEntry(m_textureEntry, 0, m_textureEntry.Length); }
  90. set { m_textureEntry = value.ToBytes(); }
  91. }
  92. private byte[] m_textureEntry;
  93. public byte[] TextureEntry
  94. {
  95. get { return m_textureEntry; }
  96. set { m_textureEntry = value; }
  97. }
  98. public byte[] ExtraParams;
  99. public ProfileShape ProfileShape
  100. {
  101. get { return (ProfileShape)(ProfileCurve & 0xf); }
  102. set
  103. {
  104. byte oldValueMasked = (byte)(ProfileCurve & 0xf0);
  105. ProfileCurve = (byte)(oldValueMasked | (byte)value);
  106. }
  107. }
  108. [XmlIgnore]
  109. public HollowShape HollowShape
  110. {
  111. get { return (HollowShape)(ProfileCurve & 0xf0); }
  112. set
  113. {
  114. byte oldValueMasked = (byte)(ProfileCurve & 0x0f);
  115. ProfileCurve = (byte)(oldValueMasked | (byte)value);
  116. }
  117. }
  118. public LLVector3 PrimScale
  119. {
  120. get { return Scale; }
  121. }
  122. static PrimitiveBaseShape()
  123. {
  124. m_defaultTexture =
  125. new LLObject.TextureEntry(new LLUUID("89556747-24cb-43ed-920b-47caed15465f"));
  126. }
  127. public PrimitiveBaseShape()
  128. {
  129. PCode = (byte)PCodeEnum.Primitive;
  130. ExtraParams = new byte[1];
  131. Textures = m_defaultTexture;
  132. }
  133. public static PrimitiveBaseShape Create()
  134. {
  135. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  136. return shape;
  137. }
  138. public static PrimitiveBaseShape CreateBox()
  139. {
  140. PrimitiveBaseShape shape = Create();
  141. shape.PathCurve = (byte)Extrusion.Straight;
  142. shape.ProfileShape = ProfileShape.Square;
  143. shape.PathScaleX = 100;
  144. shape.PathScaleY = 100;
  145. return shape;
  146. }
  147. public static PrimitiveBaseShape CreateCylinder()
  148. {
  149. PrimitiveBaseShape shape = Create();
  150. shape.PathCurve = (byte)Extrusion.Curve1;
  151. shape.ProfileShape = ProfileShape.Square;
  152. shape.PathScaleX = 100;
  153. shape.PathScaleY = 100;
  154. return shape;
  155. }
  156. public static PrimitiveBaseShape Default
  157. {
  158. get
  159. {
  160. PrimitiveBaseShape boxShape = CreateBox();
  161. boxShape.SetScale(0.5f);
  162. return boxShape;
  163. }
  164. }
  165. public void SetScale(float side)
  166. {
  167. Scale = new LLVector3(side, side, side);
  168. }
  169. public void SetHeigth(float heigth)
  170. {
  171. Scale.Z = heigth;
  172. }
  173. public void SetRadius(float radius)
  174. {
  175. Scale.X = Scale.Y = radius * 2f;
  176. }
  177. //void returns need to change of course
  178. public virtual void GetMesh()
  179. {
  180. }
  181. public PrimitiveBaseShape Copy()
  182. {
  183. return (PrimitiveBaseShape)MemberwiseClone();
  184. }
  185. public static PrimitiveBaseShape CreateCylinder(float radius, float heigth)
  186. {
  187. PrimitiveBaseShape shape = CreateCylinder( );
  188. shape.SetHeigth( heigth );
  189. shape.SetRadius( radius );
  190. return shape;
  191. }
  192. }
  193. }