OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AnimationsCommandModule.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.Linq;
31 using System.Reflection;
32 using System.Text;
33 using log4net;
34 using Mono.Addins;
35 using Nini.Config;
36 using OpenMetaverse;
37 using OpenSim.Framework;
38 using OpenSim.Framework.Console;
39 using OpenSim.Framework.Monitoring;
40 using OpenSim.Region.ClientStack.LindenUDP;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
44 using OpenSim.Services.Interfaces;
46 
47 namespace OpenSim.Region.OptionalModules.Avatar.Animations
48 {
52  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")]
54  {
55 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
56 
57  private List<Scene> m_scenes = new List<Scene>();
58 
59  public string Name { get { return "Animations Command Module"; } }
60 
61  public Type ReplaceableInterface { get { return null; } }
62 
63  public void Initialise(IConfigSource source)
64  {
65 // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE");
66  }
67 
68  public void PostInitialise()
69  {
70 // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE");
71  }
72 
73  public void Close()
74  {
75 // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE");
76  }
77 
78  public void AddRegion(Scene scene)
79  {
80 // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
81  }
82 
83  public void RemoveRegion(Scene scene)
84  {
85 // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
86 
87  lock (m_scenes)
88  m_scenes.Remove(scene);
89  }
90 
91  public void RegionLoaded(Scene scene)
92  {
93 // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
94 
95  lock (m_scenes)
96  m_scenes.Add(scene);
97 
98  scene.AddCommand(
99  "Users", this, "show animations",
100  "show animations [<first-name> <last-name>]",
101  "Show animation information for avatars in this simulator.",
102  "If no name is supplied then information for all avatars is shown.\n"
103  + "Please note that for inventory animations, the animation name is the name under which the animation was originally uploaded\n"
104  + ", which is not necessarily the current inventory name.",
105  HandleShowAnimationsCommand);
106  }
107 
108  protected void HandleShowAnimationsCommand(string module, string[] cmd)
109  {
110  if (cmd.Length != 2 && cmd.Length < 4)
111  {
112  MainConsole.Instance.OutputFormat("Usage: show animations [<first-name> <last-name>]");
113  return;
114  }
115 
116  bool targetNameSupplied = false;
117  string optionalTargetFirstName = null;
118  string optionalTargetLastName = null;
119 
120  if (cmd.Length >= 4)
121  {
122  targetNameSupplied = true;
123  optionalTargetFirstName = cmd[2];
124  optionalTargetLastName = cmd[3];
125  }
126 
127  StringBuilder sb = new StringBuilder();
128 
129  lock (m_scenes)
130  {
131  foreach (Scene scene in m_scenes)
132  {
133  if (targetNameSupplied)
134  {
135  ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
136  if (sp != null && !sp.IsChildAgent)
137  GetAttachmentsReport(sp, sb);
138  }
139  else
140  {
141  scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
142  }
143  }
144  }
145 
146  MainConsole.Instance.Output(sb.ToString());
147  }
148 
149  private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
150  {
151  sb.AppendFormat("Animations for {0}\n", sp.Name);
152 
153  ConsoleDisplayList cdl = new ConsoleDisplayList() { Indent = 2 };
154  ScenePresenceAnimator spa = sp.Animator;
155  AnimationSet anims = sp.Animator.Animations;
156 
157  string cma = spa.CurrentMovementAnimation;
158  cdl.AddRow(
159  "Current movement anim",
160  string.Format("{0}, {1}", DefaultAvatarAnimations.GetDefaultAnimation(cma), cma));
161 
162  UUID defaultAnimId = anims.DefaultAnimation.AnimID;
163  cdl.AddRow(
164  "Default anim",
165  string.Format("{0}, {1}", defaultAnimId, sp.Animator.GetAnimName(defaultAnimId)));
166 
167  UUID implicitDefaultAnimId = anims.ImplicitDefaultAnimation.AnimID;
168  cdl.AddRow(
169  "Implicit default anim",
170  string.Format("{0}, {1}",
171  implicitDefaultAnimId, sp.Animator.GetAnimName(implicitDefaultAnimId)));
172 
173  cdl.AddToStringBuilder(sb);
174 
175  ConsoleDisplayTable cdt = new ConsoleDisplayTable() { Indent = 2 };
176  cdt.AddColumn("Animation ID", 36);
177  cdt.AddColumn("Name", 20);
178  cdt.AddColumn("Seq", 3);
179  cdt.AddColumn("Object ID", 36);
180 
181  UUID[] animIds;
182  int[] sequenceNumbers;
183  UUID[] objectIds;
184 
185  sp.Animator.Animations.GetArrays(out animIds, out sequenceNumbers, out objectIds);
186 
187  for (int i = 0; i < animIds.Length; i++)
188  {
189  UUID animId = animIds[i];
190  string animName = sp.Animator.GetAnimName(animId);
191  int seq = sequenceNumbers[i];
192  UUID objectId = objectIds[i];
193 
194  cdt.AddRow(animId, animName, seq, objectId);
195  }
196 
197  cdt.AddToStringBuilder(sb);
198  sb.Append("\n");
199  }
200  }
201 }
Used to generated a formatted table for the console.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Used to generated a formatted table for the console.
A module that just holds commands for inspecting avatar animations.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
Handle all animation duties for a scene presence
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
Interactive OpenSim region server
Definition: OpenSim.cs:55
OpenSim.Framework.Animation Animation
OpenSim.Region.Framework.Scenes.Animation.AnimationSet AnimationSet