aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-09 03:51:34 +0100
committerJustin Clark-Casey (justincc)2011-08-09 03:51:34 +0100
commite869eeb0bfc48c769f680970f99e4c67dd5a1a70 (patch)
tree749440ee4ba12140b708e2fe68e98419710d6ea0 /OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
parentfactor out common notecard caching code from 3 methods. (diff)
downloadopensim-SC_OLD-e869eeb0bfc48c769f680970f99e4c67dd5a1a70.zip
opensim-SC_OLD-e869eeb0bfc48c769f680970f99e4c67dd5a1a70.tar.gz
opensim-SC_OLD-e869eeb0bfc48c769f680970f99e4c67dd5a1a70.tar.bz2
opensim-SC_OLD-e869eeb0bfc48c769f680970f99e4c67dd5a1a70.tar.xz
Implement first draft functions for saving and loading NPC appearance from storage.
This works by serializing and deserializing NPC AvatarAppearance to a notecard in the prim inventory and making the required baked textures permanent. By using notecards, we avoid lots of awkward, technical and user-unfriendly issues concerning retaining asset references and creating a new asset type. Notecards also allow different appearances to be swapped and manipulated easily. This also allows stored NPC appearances to work transparently with OARs/IARs since the UUID scan will pick up and store the necessary references from the notecard text. This works in my basic test but is not at all ready for user use or bug reporting yet.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs87
1 files changed, 64 insertions, 23 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index e3e3452..75d8143 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -104,7 +104,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
104 public void NewClient(IClientAPI client) 104 public void NewClient(IClientAPI client)
105 { 105 {
106 client.OnRequestWearables += SendWearables; 106 client.OnRequestWearables += SendWearables;
107 client.OnSetAppearance += SetAppearance; 107 client.OnSetAppearance += SetAppearanceFromClient;
108 client.OnAvatarNowWearing += AvatarIsWearing; 108 client.OnAvatarNowWearing += AvatarIsWearing;
109 } 109 }
110 110
@@ -189,7 +189,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
189 /// <param name="client"></param> 189 /// <param name="client"></param>
190 /// <param name="texture"></param> 190 /// <param name="texture"></param>
191 /// <param name="visualParam"></param> 191 /// <param name="visualParam"></param>
192 public void SetAppearance(IClientAPI client, Primitive.TextureEntry textureEntry, byte[] visualParams) 192 public void SetAppearanceFromClient(IClientAPI client, Primitive.TextureEntry textureEntry, byte[] visualParams)
193 { 193 {
194 ScenePresence sp = m_scene.GetScenePresence(client.AgentId); 194 ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
195 if (sp == null) 195 if (sp == null)
@@ -257,6 +257,47 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
257 return true; 257 return true;
258 } 258 }
259 259
260 public bool SaveBakedTextures(UUID agentId)
261 {
262 ScenePresence sp = m_scene.GetScenePresence(agentId);
263
264 if (sp == null || sp.IsChildAgent)
265 return false;
266
267 AvatarAppearance appearance = sp.Appearance;
268 Primitive.TextureEntryFace[] faceTextures = appearance.Texture.FaceTextures;
269
270 m_log.DebugFormat(
271 "[AV FACTORY]: Permanently saving baked textures for {0} in {1}",
272 sp.Name, m_scene.RegionInfo.RegionName);
273
274 for (int i = 0; i < faceTextures.Length; i++)
275 {
276// m_log.DebugFormat(
277// "[AVFACTORY]: NPC avatar {0} has texture id {1} : {2}",
278// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]);
279
280 if (faceTextures[i] == null)
281 continue;
282
283 AssetBase asset = m_scene.AssetService.Get(faceTextures[i].TextureID.ToString());
284
285 if (asset != null)
286 {
287 asset.Temporary = false;
288 m_scene.AssetService.Store(asset);
289 }
290 else
291 {
292 m_log.WarnFormat(
293 "[AV FACTORY]: Baked texture {0} for {1} in {2} unexpectedly not found when trying to save permanently",
294 faceTextures[i].TextureID, sp.Name, m_scene.RegionInfo.RegionName);
295 }
296 }
297
298 return true;
299 }
300
260 #region UpdateAppearanceTimer 301 #region UpdateAppearanceTimer
261 302
262 /// <summary> 303 /// <summary>
@@ -289,25 +330,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
289 } 330 }
290 } 331 }
291 332
292 private void HandleAppearanceSend(UUID agentid) 333 private void SaveAppearance(UUID agentid)
293 {
294 ScenePresence sp = m_scene.GetScenePresence(agentid);
295 if (sp == null)
296 {
297 m_log.WarnFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentid);
298 return;
299 }
300
301 // m_log.WarnFormat("[AVFACTORY]: Handle appearance send for {0}", agentid);
302
303 // Send the appearance to everyone in the scene
304 sp.SendAppearanceToAllOtherAgents();
305
306 // Send animations back to the avatar as well
307 sp.Animator.SendAnimPack();
308 }
309
310 private void HandleAppearanceSave(UUID agentid)
311 { 334 {
312 // We must set appearance parameters in the en_US culture in order to avoid issues where values are saved 335 // We must set appearance parameters in the en_US culture in order to avoid issues where values are saved
313 // in a culture where decimal points are commas and then reloaded in a culture which just treats them as 336 // in a culture where decimal points are commas and then reloaded in a culture which just treats them as
@@ -337,7 +360,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
337 { 360 {
338 if (kvp.Value < now) 361 if (kvp.Value < now)
339 { 362 {
340 Util.FireAndForget(delegate(object o) { HandleAppearanceSend(kvp.Key); }); 363 Util.FireAndForget(delegate(object o) { SendAppearance(kvp.Key); });
341 m_sendqueue.Remove(kvp.Key); 364 m_sendqueue.Remove(kvp.Key);
342 } 365 }
343 } 366 }
@@ -350,7 +373,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
350 { 373 {
351 if (kvp.Value < now) 374 if (kvp.Value < now)
352 { 375 {
353 Util.FireAndForget(delegate(object o) { HandleAppearanceSave(kvp.Key); }); 376 Util.FireAndForget(delegate(object o) { SaveAppearance(kvp.Key); });
354 m_savequeue.Remove(kvp.Key); 377 m_savequeue.Remove(kvp.Key);
355 } 378 }
356 } 379 }
@@ -427,6 +450,24 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
427 } 450 }
428 } 451 }
429 452
453 public bool SendAppearance(UUID agentId)
454 {
455 ScenePresence sp = m_scene.GetScenePresence(agentId);
456 if (sp == null)
457 {
458 m_log.WarnFormat("[AVFACTORY]: Agent {0} no longer in the scene", agentId);
459 return false;
460 }
461
462 // Send the appearance to everyone in the scene
463 sp.SendAppearanceToAllOtherAgents();
464
465 // Send animations back to the avatar as well
466 sp.Animator.SendAnimPack();
467
468 return true;
469 }
470
430 private void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance) 471 private void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance)
431 { 472 {
432 IInventoryService invService = m_scene.InventoryService; 473 IInventoryService invService = m_scene.InventoryService;