Animation.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 OpenSimulator 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 OpenMetaverse;
  29. using OpenMetaverse.StructuredData;
  30. namespace OpenSim.Framework
  31. {
  32. /// <summary>
  33. /// Information about an Animation
  34. /// </summary>
  35. [Serializable]
  36. public class Animation
  37. {
  38. private UUID animID;
  39. /// <summary>
  40. /// ID of Animation
  41. /// </summary>
  42. public UUID AnimID
  43. {
  44. get { return animID; }
  45. set { animID = value; }
  46. }
  47. private int sequenceNum;
  48. public int SequenceNum
  49. {
  50. get { return sequenceNum; }
  51. set { sequenceNum = value; }
  52. }
  53. private UUID objectID;
  54. /// <summary>
  55. /// Unique ID of object that is being animated
  56. /// </summary>
  57. public UUID ObjectID
  58. {
  59. get { return objectID; }
  60. set { objectID = value; }
  61. }
  62. public Animation()
  63. {
  64. }
  65. /// <summary>
  66. /// Creates an Animation based on the data
  67. /// </summary>
  68. /// <param name="animID">UUID ID of animation</param>
  69. /// <param name="sequenceNum"></param>
  70. /// <param name="objectID">ID of object to be animated</param>
  71. public Animation(UUID animID, int sequenceNum, UUID objectID)
  72. {
  73. this.animID = animID;
  74. this.sequenceNum = sequenceNum;
  75. this.objectID = objectID;
  76. }
  77. /// <summary>
  78. /// Animation from OSDMap from LLSD XML or LLSD json
  79. /// </summary>
  80. /// <param name="args"></param>
  81. public Animation(OSDMap args)
  82. {
  83. UnpackUpdateMessage(args);
  84. }
  85. /// <summary>
  86. /// Pack this object up as an OSDMap for transferring via LLSD XML or LLSD json
  87. /// </summary>
  88. /// <returns></returns>
  89. public OSDMap PackUpdateMessage()
  90. {
  91. OSDMap anim = new OSDMap();
  92. anim["animation"] = OSD.FromUUID(animID);
  93. anim["object_id"] = OSD.FromUUID(objectID);
  94. anim["seq_num"] = OSD.FromInteger(sequenceNum);
  95. return anim;
  96. }
  97. /// <summary>
  98. /// Fill object with data from OSDMap
  99. /// </summary>
  100. /// <param name="args"></param>
  101. public void UnpackUpdateMessage(OSDMap args)
  102. {
  103. if (args["animation"] != null)
  104. animID = args["animation"].AsUUID();
  105. if (args["object_id"] != null)
  106. objectID = args["object_id"].AsUUID();
  107. if (args["seq_num"] != null)
  108. sequenceNum = args["seq_num"].AsInteger();
  109. }
  110. public override bool Equals(object obj)
  111. {
  112. Animation other = obj as Animation;
  113. if (other != null)
  114. {
  115. return (other.AnimID.Equals(this.AnimID)
  116. && other.SequenceNum == this.SequenceNum
  117. && other.ObjectID.Equals(this.ObjectID) );
  118. }
  119. return base.Equals(obj);
  120. }
  121. public override string ToString()
  122. {
  123. return "AnimID=" + AnimID.ToString()
  124. + "/seq=" + SequenceNum.ToString()
  125. + "/objID=" + ObjectID.ToString();
  126. }
  127. }
  128. }