aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/AvatarFactory
diff options
context:
space:
mode:
authorMaster ScienceSim2010-10-20 16:17:54 -0700
committerMaster ScienceSim2010-10-20 16:17:54 -0700
commitb1c8d0588829dfa76f89460eeb8406d9c4fc479f (patch)
tree463cbb0bf2eab5c7e7f98ebdc0dc7113dea56688 /OpenSim/Region/CoreModules/Avatar/AvatarFactory
parentMerge branch 'master' of /var/git/opensim/ (diff)
downloadopensim-SC-b1c8d0588829dfa76f89460eeb8406d9c4fc479f.zip
opensim-SC-b1c8d0588829dfa76f89460eeb8406d9c4fc479f.tar.gz
opensim-SC-b1c8d0588829dfa76f89460eeb8406d9c4fc479f.tar.bz2
opensim-SC-b1c8d0588829dfa76f89460eeb8406d9c4fc479f.tar.xz
Major refactoring of appearance handling.
AvatarService -- add two new methods, GetAppearance and SetAppearance to get around the lossy encoding in AvatarData. Preseve the old functions to avoid changing the behavior for ROBUST services. AvatarAppearance -- major refactor, moved the various encoding methods used by AgentCircuitData, ClientAgentUpdate and ScenePresence into one location. Changed initialization. AvatarAttachments -- added a class specifically to handle attachments in preparation for additional functionality that will be needed for viewer 2. AvatarFactory -- removed a number of unused or methods duplicated in other locations. Moved in all appearance event handling from ScenePresence. Required a change to IClientAPI that propogated throughout all the IClientAPI implementations.
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/AvatarFactory')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs237
1 files changed, 150 insertions, 87 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index 22c8937..9f7ff7f 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -38,48 +38,20 @@ using OpenSim.Services.Interfaces;
38 38
39namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory 39namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
40{ 40{
41 public class AvatarFactoryModule : IAvatarFactory, IRegionModule 41 public class AvatarFactoryModule : IRegionModule
42 { 42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
44 private Scene m_scene = null; 45 private Scene m_scene = null;
45 private static readonly AvatarAppearance def = new AvatarAppearance();
46 46
47 public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance) 47 private bool m_startAnimationSet = false;
48 {
49 AvatarData avatar = m_scene.AvatarService.GetAvatar(avatarId);
50 //if ((profile != null) && (profile.RootFolder != null))
51 if (avatar != null)
52 {
53 appearance = avatar.ToAvatarAppearance(avatarId);
54 return true;
55 }
56
57 m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId);
58 appearance = CreateDefault(avatarId);
59 return false;
60 }
61
62 private AvatarAppearance CreateDefault(UUID avatarId)
63 {
64 AvatarAppearance appearance = null;
65 AvatarWearable[] wearables;
66 byte[] visualParams;
67 GetDefaultAvatarAppearance(out wearables, out visualParams);
68 appearance = new AvatarAppearance(avatarId, wearables, visualParams);
69
70 return appearance;
71 }
72 48
73 public void Initialise(Scene scene, IConfigSource source) 49 public void Initialise(Scene scene, IConfigSource source)
74 { 50 {
75 scene.RegisterModuleInterface<IAvatarFactory>(this);
76 scene.EventManager.OnNewClient += NewClient; 51 scene.EventManager.OnNewClient += NewClient;
77 52
78 if (m_scene == null) 53 if (m_scene == null)
79 {
80 m_scene = scene; 54 m_scene = scene;
81 }
82
83 } 55 }
84 56
85 public void PostInitialise() 57 public void PostInitialise()
@@ -102,6 +74,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
102 74
103 public void NewClient(IClientAPI client) 75 public void NewClient(IClientAPI client)
104 { 76 {
77 client.OnRequestWearables += SendWearables;
78 client.OnSetAppearance += SetAppearance;
105 client.OnAvatarNowWearing += AvatarIsWearing; 79 client.OnAvatarNowWearing += AvatarIsWearing;
106 } 80 }
107 81
@@ -110,42 +84,115 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
110 // client.OnAvatarNowWearing -= AvatarIsWearing; 84 // client.OnAvatarNowWearing -= AvatarIsWearing;
111 } 85 }
112 86
113 public void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance) 87 /// <summary>
88 /// Set appearance data (textureentry and slider settings) received from the client
89 /// </summary>
90 /// <param name="texture"></param>
91 /// <param name="visualParam"></param>
92 public void SetAppearance(IClientAPI client, Primitive.TextureEntry textureEntry, byte[] visualParams)
114 { 93 {
115 IInventoryService invService = m_scene.InventoryService; 94 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
95 if (sp == null)
96 {
97 m_log.WarnFormat("[AVFACTORY] SetAppearance unable to find presence for {0}",client.AgentId);
98 return;
99 }
100
101// DEBUG ON
102 m_log.WarnFormat("[AVFACTORY] SetAppearance for {0}",client.AgentId);
103// DEBUG OFF
116 104
117 if (invService.GetRootFolder(userID) != null) 105/*
106 if (m_physicsActor != null)
118 { 107 {
119 for (int i = 0; i < 13; i++) 108 if (!IsChildAgent)
120 { 109 {
121 if (appearance.Wearables[i].ItemID == UUID.Zero) 110 // This may seem like it's redundant, remove the avatar from the physics scene
122 { 111 // just to add it back again, but it saves us from having to update
123 appearance.Wearables[i].AssetID = UUID.Zero; 112 // 3 variables 10 times a second.
124 } 113 bool flyingTemp = m_physicsActor.Flying;
125 else 114 RemoveFromPhysicalScene();
126 { 115 //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor);
127 InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i].ItemID, userID);
128 baseItem = invService.GetItem(baseItem);
129 116
130 if (baseItem != null) 117 //PhysicsActor = null;
131 { 118
132 appearance.Wearables[i].AssetID = baseItem.AssetID; 119 AddToPhysicalScene(flyingTemp);
133 } 120 }
134 else 121 }
122*/
123 #region Bake Cache Check
124
125 bool changed = false;
126
127 // Process the texture entry
128 if (textureEntry != null)
129 {
130 for (int i = 0; i < BAKE_INDICES.Length; i++)
131 {
132 int j = BAKE_INDICES[i];
133 Primitive.TextureEntryFace face = textureEntry.FaceTextures[j];
134
135 if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE)
136 {
137 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null)
135 { 138 {
136 m_log.ErrorFormat( 139 m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,this.Name);
137 "[APPEARANCE]: Can't find inventory item {0} for {1}, setting to default", 140 client.SendRebakeAvatarTextures(face.TextureID);
138 appearance.Wearables[i].ItemID, (WearableType)i);
139
140 appearance.Wearables[i].AssetID = def.Wearables[i].AssetID;
141 } 141 }
142 } 142 }
143 } 143 }
144 changed = sp.Appearance.SetTextureEntries(textureEntry);
145
146 }
147
148 #endregion Bake Cache Check
149
150 changed = sp.Appearance.SetVisualParams(visualParams) || changed;
151
152 // If nothing changed (this happens frequently) just return
153 if (changed)
154 {
155// DEBUG ON
156 m_log.Warn("[AVFACTORY] Appearance changed");
157// DEBUG OFF
158 sp.Appearance.SetAppearance(textureEntry, visualParams);
159 if (sp.Appearance.AvatarHeight > 0)
160 sp.SetHeight(sp.Appearance.AvatarHeight);
161
162 m_scene.AvatarService.SetAppearance(client.AgentId, sp.Appearance);
144 } 163 }
164// DEBUG ON
145 else 165 else
166 m_log.Warn("[AVFACTORY] Appearance did not change");
167// DEBUG OFF
168
169 sp.SendAppearanceToAllOtherAgents();
170 if (!m_startAnimationSet)
171 {
172 sp.Animator.UpdateMovementAnimations();
173 m_startAnimationSet = true;
174 }
175
176 client.SendAvatarDataImmediate(sp);
177 client.SendAppearance(sp.Appearance.Owner,sp.Appearance.VisualParams,sp.Appearance.Texture.GetBytes());
178 }
179
180 /// <summary>
181 /// Tell the client for this scene presence what items it should be wearing now
182 /// </summary>
183 public void SendWearables(IClientAPI client)
184 {
185 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
186 if (sp == null)
146 { 187 {
147 m_log.WarnFormat("[APPEARANCE]: user {0} has no inventory, appearance isn't going to work", userID); 188 m_log.WarnFormat("[AVFACTORY] SendWearables unable to find presence for {0}",client.AgentId);
189 return;
148 } 190 }
191
192// DEBUG ON
193 m_log.WarnFormat("[AVFACTORY]: Received request for wearables of {0}", client.AgentId);
194// DEBUG OFF
195 client.SendWearables(sp.Appearance.Wearables,sp.Appearance.Serial++);
149 } 196 }
150 197
151 /// <summary> 198 /// <summary>
@@ -153,65 +200,81 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
153 /// </summary> 200 /// </summary>
154 /// <param name="sender"></param> 201 /// <param name="sender"></param>
155 /// <param name="e"></param> 202 /// <param name="e"></param>
156 public void AvatarIsWearing(Object sender, AvatarWearingArgs e) 203 public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e)
157 { 204 {
158 m_log.DebugFormat("[APPEARANCE]: AvatarIsWearing"); 205 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
159 206 if (sp == null)
160 IClientAPI clientView = (IClientAPI)sender;
161 ScenePresence sp = m_scene.GetScenePresence(clientView.AgentId);
162
163 if (sp == null)
164 { 207 {
165 m_log.Error("[APPEARANCE]: Avatar is child agent, ignoring AvatarIsWearing event"); 208 m_log.WarnFormat("[AVFACTORY] AvatarIsWearing unable to find presence for {0}",client.AgentId);
166 return; 209 return;
167 } 210 }
211
212// DEBUG ON
213 m_log.WarnFormat("[AVFACTORY]: AvatarIsWearing called for {0}",client.AgentId);
214// DEBUG OFF
215
216 AvatarAppearance avatAppearance = new AvatarAppearance(sp.Appearance);
168 217
169 AvatarAppearance avatAppearance = sp.Appearance; 218 //if (!TryGetAvatarAppearance(client.AgentId, out avatAppearance))
170 //if (!TryGetAvatarAppearance(clientView.AgentId, out avatAppearance))
171 //{ 219 //{
172 // m_log.Warn("[APPEARANCE]: We didn't seem to find the appearance, falling back to ScenePresence"); 220 // m_log.Warn("[AVFACTORY]: We didn't seem to find the appearance, falling back to ScenePresence");
173 // avatAppearance = sp.Appearance; 221 // avatAppearance = sp.Appearance;
174 //} 222 //}
175 223
176 //m_log.DebugFormat("[APPEARANCE]: Received wearables for {0}", clientView.Name); 224 //m_log.DebugFormat("[AVFACTORY]: Received wearables for {0}", client.Name);
177 225
178 foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) 226 foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
179 { 227 {
180 if (wear.Type < 13) 228 if (wear.Type < AvatarWearable.MAX_WEARABLES)
181 { 229 {
182 avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; 230 AvatarWearable newWearable = new AvatarWearable(wear.ItemID,UUID.Zero);
231 avatAppearance.SetWearable(wear.Type, newWearable);
183 } 232 }
184 } 233 }
185 234
186 SetAppearanceAssets(sp.UUID, ref avatAppearance); 235 SetAppearanceAssets(sp.UUID, ref avatAppearance);
187 AvatarData adata = new AvatarData(avatAppearance);
188 m_scene.AvatarService.SetAvatar(clientView.AgentId, adata);
189 236
237 m_scene.AvatarService.SetAppearance(client.AgentId, avatAppearance);
190 sp.Appearance = avatAppearance; 238 sp.Appearance = avatAppearance;
191 } 239 }
192 240
193 public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) 241 private void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance)
194 { 242 {
195 visualParams = GetDefaultVisualParams(); 243 IInventoryService invService = m_scene.InventoryService;
196 wearables = AvatarWearable.DefaultWearables;
197 }
198 244
199 public void UpdateDatabase(UUID user, AvatarAppearance appearance) 245 if (invService.GetRootFolder(userID) != null)
200 { 246 {
201 //m_log.DebugFormat("[APPEARANCE]: UpdateDatabase"); 247 for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++)
202 AvatarData adata = new AvatarData(appearance); 248 {
203 m_scene.AvatarService.SetAvatar(user, adata); 249 if (appearance.Wearables[i].ItemID == UUID.Zero)
204 } 250 {
251 appearance.Wearables[i].AssetID = UUID.Zero;
252 }
253 else
254 {
255 InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i].ItemID, userID);
256 baseItem = invService.GetItem(baseItem);
205 257
206 private static byte[] GetDefaultVisualParams() 258 if (baseItem != null)
207 { 259 {
208 byte[] visualParams; 260 appearance.Wearables[i].AssetID = baseItem.AssetID;
209 visualParams = new byte[218]; 261 }
210 for (int i = 0; i < 218; i++) 262 else
263 {
264 m_log.ErrorFormat(
265 "[AVFACTORY]: Can't find inventory item {0} for {1}, setting to default",
266 appearance.Wearables[i].ItemID, (WearableType)i);
267
268 appearance.Wearables[i].ItemID = UUID.Zero;
269 appearance.Wearables[i].AssetID = UUID.Zero;
270 }
271 }
272 }
273 }
274 else
211 { 275 {
212 visualParams[i] = 100; 276 m_log.WarnFormat("[AVFACTORY]: user {0} has no inventory, appearance isn't going to work", userID);
213 } 277 }
214 return visualParams;
215 } 278 }
216 } 279 }
217} 280}