From 59f548cda82facef003fb7309180412254a234a1 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Mon, 1 Aug 2011 23:41:29 +0100 Subject: Get osNpcCreate appearance working with avatars that are currently in the scene. Had to stop using AvatarService for now since it doesn't store baked texture IDs (which is why this was failing). Also failing because cloning appearance was also cloning the AvatarApperance.Owner field, which we weren't then changing. Extended TestCreate() to check this. --- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 4 ++++ OpenSim/Region/Framework/Scenes/ScenePresence.cs | 9 ++++++-- .../Region/OptionalModules/World/NPC/NPCModule.cs | 25 +++++++++++++++++----- .../World/NPC/Tests/NPCModuleTests.cs | 23 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 20dff0c..e3e3452 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -151,6 +151,10 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory if (face == null) continue; +// m_log.DebugFormat( +// "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}", +// face.TextureID, idx, client.Name, client.AgentId); + // if the texture is one of the "defaults" then skip it // this should probably be more intelligent (skirt texture doesnt matter // if the avatar isnt wearing a skirt) but if any of the main baked diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 83b761c..1e121d9 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -2647,7 +2647,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendAppearanceToAgent(ScenePresence avatar) { -// m_log.WarnFormat("[SP] Send appearance from {0} to {1}",m_uuid,avatar.ControllingClient.AgentId); +// m_log.DebugFormat( +// "[SCENE PRESENCE] Send appearance from {0} {1} to {2} {3}", Name, m_uuid, avatar.Name, avatar.UUID); avatar.ControllingClient.SendAppearance( m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); @@ -2659,7 +2660,11 @@ namespace OpenSim.Region.Framework.Scenes public AvatarAppearance Appearance { get { return m_appearance; } - set { m_appearance = value; } + set + { + m_appearance = value; +// m_log.DebugFormat("[SCENE PRESENCE]: Set appearance for {0} to {1}", Name, value); + } } #endregion diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3cdd06d..64f82c9 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -59,14 +59,21 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_appearanceCache.ContainsKey(target)) return m_appearanceCache[target]; - AvatarAppearance appearance = scene.AvatarService.GetAppearance(target); - if (appearance != null) + ScenePresence originalPresence = scene.GetScenePresence(target); + + if (originalPresence != null) { - m_appearanceCache.Add(target, appearance); - return appearance; + AvatarAppearance originalAppearance = originalPresence.Appearance; + m_appearanceCache.Add(target, originalAppearance); + return originalAppearance; } + else + { + m_log.DebugFormat( + "[NPC MODULE]: Avatar {0} is not in the scene for us to grab baked textures from them. Using defaults.", target); - return new AvatarAppearance(); + return new AvatarAppearance(); + } } public UUID CreateNPC(string firstname, string lastname, Vector3 position, Scene scene, UUID cloneAppearanceFrom) @@ -86,8 +93,16 @@ namespace OpenSim.Region.OptionalModules.World.NPC AvatarAppearance originalAppearance = GetAppearance(cloneAppearanceFrom, scene); AvatarAppearance npcAppearance = new AvatarAppearance(originalAppearance, true); + npcAppearance.Owner = acd.AgentID; acd.Appearance = npcAppearance; +// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) +// { +// m_log.DebugFormat( +// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", +// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); +// } + scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); scene.AddNewClient(npcAvatar); diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 899e721..bc151ed 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs @@ -27,11 +27,13 @@ using System; using System.Reflection; +using log4net; using Nini.Config; using NUnit.Framework; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Region.CoreModules.Avatar.AvatarFactory; using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -58,14 +60,31 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests config.Configs["AvatarService"].Set("LocalServiceModule", "OpenSim.Services.AvatarService.dll:AvatarService"); config.Configs["AvatarService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); + AvatarFactoryModule afm = new AvatarFactoryModule(); TestScene scene = SceneSetupHelpers.SetupScene(); - SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule(), new LocalAvatarServicesConnector()); + SceneSetupHelpers.SetupSceneModules(scene, config, afm, new NPCModule(), new LocalAvatarServicesConnector()); + TestClient originalClient = SceneSetupHelpers.AddClient(scene, TestHelper.ParseTail(0x1)); +// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId); + + // 8 is the index of the first baked texture in AvatarAppearance + UUID originalFace8TextureId = TestHelper.ParseTail(0x10); + Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero); + Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8); + originalTef.TextureID = originalFace8TextureId; + + // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell + // ScenePresence.SendInitialData() to reset our entire appearance. + scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId)); + + afm.SetAppearance(originalClient, originalTe, null); INPCModule npcModule = scene.RequestModuleInterface(); - UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, UUID.Zero); + UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, originalClient.AgentId); ScenePresence npc = scene.GetScenePresence(npcId); + Assert.That(npc, Is.Not.Null); + Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId)); } } } \ No newline at end of file -- cgit v1.1