1
0

AnimationsCommandModule.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Monitoring;
  39. using OpenSim.Region.ClientStack.LindenUDP;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using OpenSim.Region.Framework.Scenes.Animation;
  43. using OpenSim.Services.Interfaces;
  44. using AnimationSet = OpenSim.Region.Framework.Scenes.Animation.AnimationSet;
  45. namespace OpenSim.Region.OptionalModules.Avatar.Animations
  46. {
  47. /// <summary>
  48. /// A module that just holds commands for inspecting avatar animations.
  49. /// </summary>
  50. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")]
  51. public class AnimationsCommandModule : ISharedRegionModule
  52. {
  53. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  54. private List<Scene> m_scenes = new List<Scene>();
  55. public string Name { get { return "Animations Command Module"; } }
  56. public Type ReplaceableInterface { get { return null; } }
  57. public void Initialise(IConfigSource source)
  58. {
  59. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE");
  60. }
  61. public void PostInitialise()
  62. {
  63. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE");
  64. }
  65. public void Close()
  66. {
  67. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE");
  68. }
  69. public void AddRegion(Scene scene)
  70. {
  71. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  72. }
  73. public void RemoveRegion(Scene scene)
  74. {
  75. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  76. lock (m_scenes)
  77. m_scenes.Remove(scene);
  78. }
  79. public void RegionLoaded(Scene scene)
  80. {
  81. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  82. lock (m_scenes)
  83. m_scenes.Add(scene);
  84. scene.AddCommand(
  85. "Users", this, "show animations",
  86. "show animations [<first-name> <last-name>]",
  87. "Show animation information for avatars in this simulator.",
  88. "If no name is supplied then information for all avatars is shown.\n"
  89. + "Please note that for inventory animations, the animation name is the name under which the animation was originally uploaded\n"
  90. + ", which is not necessarily the current inventory name.",
  91. HandleShowAnimationsCommand);
  92. }
  93. protected void HandleShowAnimationsCommand(string module, string[] cmd)
  94. {
  95. if (cmd.Length != 2 && cmd.Length < 4)
  96. {
  97. MainConsole.Instance.OutputFormat("Usage: show animations [<first-name> <last-name>]");
  98. return;
  99. }
  100. bool targetNameSupplied = false;
  101. string optionalTargetFirstName = null;
  102. string optionalTargetLastName = null;
  103. if (cmd.Length >= 4)
  104. {
  105. targetNameSupplied = true;
  106. optionalTargetFirstName = cmd[2];
  107. optionalTargetLastName = cmd[3];
  108. }
  109. StringBuilder sb = new StringBuilder();
  110. lock (m_scenes)
  111. {
  112. foreach (Scene scene in m_scenes)
  113. {
  114. if (targetNameSupplied)
  115. {
  116. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  117. if (sp != null && !sp.IsChildAgent)
  118. GetAttachmentsReport(sp, sb);
  119. }
  120. else
  121. {
  122. scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
  123. }
  124. }
  125. }
  126. MainConsole.Instance.Output(sb.ToString());
  127. }
  128. private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
  129. {
  130. sb.AppendFormat("Animations for {0}\n", sp.Name);
  131. ConsoleDisplayList cdl = new ConsoleDisplayList() { Indent = 2 };
  132. ScenePresenceAnimator spa = sp.Animator;
  133. AnimationSet anims = sp.Animator.Animations;
  134. string cma = spa.CurrentMovementAnimation;
  135. cdl.AddRow(
  136. "Current movement anim",
  137. string.Format("{0}, {1}", DefaultAvatarAnimations.GetDefaultAnimation(cma), cma));
  138. UUID defaultAnimId = anims.DefaultAnimation.AnimID;
  139. cdl.AddRow(
  140. "Default anim",
  141. string.Format("{0}, {1}", defaultAnimId, sp.Animator.GetAnimName(defaultAnimId)));
  142. UUID implicitDefaultAnimId = anims.ImplicitDefaultAnimation.AnimID;
  143. cdl.AddRow(
  144. "Implicit default anim",
  145. string.Format("{0}, {1}",
  146. implicitDefaultAnimId, sp.Animator.GetAnimName(implicitDefaultAnimId)));
  147. cdl.AddToStringBuilder(sb);
  148. ConsoleDisplayTable cdt = new ConsoleDisplayTable() { Indent = 2 };
  149. cdt.AddColumn("Animation ID", 36);
  150. cdt.AddColumn("Name", 20);
  151. cdt.AddColumn("Seq", 3);
  152. cdt.AddColumn("Object ID", 36);
  153. UUID[] animIds;
  154. int[] sequenceNumbers;
  155. UUID[] objectIds;
  156. sp.Animator.Animations.GetArrays(out animIds, out sequenceNumbers, out objectIds);
  157. for (int i = 0; i < animIds.Length; i++)
  158. {
  159. UUID animId = animIds[i];
  160. string animName = sp.Animator.GetAnimName(animId);
  161. int seq = sequenceNumbers[i];
  162. UUID objectId = objectIds[i];
  163. cdt.AddRow(animId, animName, seq, objectId);
  164. }
  165. cdt.AddToStringBuilder(sb);
  166. sb.Append("\n");
  167. }
  168. }
  169. }