1
0

PrimitiveBaseShape.cs 6.8 KB

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