From b1c8d0588829dfa76f89460eeb8406d9c4fc479f Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Wed, 20 Oct 2010 16:17:54 -0700 Subject: 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. --- OpenSim/Framework/AgentCircuitData.cs | 61 +- OpenSim/Framework/AvatarAppearance.cs | 839 ++++++++++++------------ OpenSim/Framework/AvatarAttachment.cs | 78 +++ OpenSim/Framework/AvatarWearable.cs | 46 +- OpenSim/Framework/Capabilities/Caps.cs | 4 +- OpenSim/Framework/ChildAgentDataUpdate.cs | 70 +- OpenSim/Framework/IClientAPI.cs | 6 +- OpenSim/Framework/Tests/AgentCircuitDataTest.cs | 2 - 8 files changed, 602 insertions(+), 504 deletions(-) create mode 100644 OpenSim/Framework/AvatarAttachment.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs index 4f89d78..be98380 100644 --- a/OpenSim/Framework/AgentCircuitData.cs +++ b/OpenSim/Framework/AgentCircuitData.cs @@ -26,7 +26,9 @@ */ using System; +using System.Reflection; using System.Collections.Generic; +using log4net; using OpenMetaverse; using OpenMetaverse.StructuredData; @@ -38,6 +40,12 @@ namespace OpenSim.Framework /// public class AgentCircuitData { +// DEBUG ON + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); +// DEBUG OFF + /// /// Avatar Unique Agent Identifier /// @@ -205,6 +213,7 @@ namespace OpenSim.Framework args["mac"] = OSD.FromString(Mac); args["id0"] = OSD.FromString(Id0); +/* if (Appearance != null) { //System.Console.WriteLine("XXX Before packing Wearables"); @@ -221,20 +230,26 @@ namespace OpenSim.Framework } //System.Console.WriteLine("XXX Before packing Attachments"); - Dictionary attachments = Appearance.GetAttachmentDictionary(); + Dictionary attachments = Appearance.Attachments; if ((attachments != null) && (attachments.Count > 0)) { OSDArray attachs = new OSDArray(attachments.Count); - foreach (KeyValuePair kvp in attachments) + foreach (KeyValuePair kvp in attachments) { - AttachmentData adata = new AttachmentData(kvp.Key, kvp.Value[0], kvp.Value[1]); - attachs.Add(adata.PackUpdateMessage()); + AvatarAttachment adata = new AvatarAttachment(kvp.Value); + attachs.Add(adata.Pack()); //System.Console.WriteLine("XXX att.pt=" + kvp.Key + "; itemID=" + kvp.Value[0] + "; assetID=" + kvp.Value[1]); } args["attachments"] = attachs; } } - +*/ + if (Appearance != null) + { + OSDMap appmap = Appearance.Pack(); + args["packed_appearance"] = appmap; + } + if (ServiceURLs != null && ServiceURLs.Count > 0) { OSDArray urls = new OSDArray(ServiceURLs.Count * 2); @@ -317,9 +332,37 @@ namespace OpenSim.Framework if (args["start_pos"] != null) Vector3.TryParse(args["start_pos"].AsString(), out startpos); +// DEBUG ON + m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString()); +// DEBUG OFF + + try { + // Unpack various appearance elements Appearance = new AvatarAppearance(AgentID); + if (args["packed_appearance"] != null) + { + if (args["packed_appearance"].Type == OSDType.Map) + { + Appearance.Unpack((OSDMap)args["packed_appearance"]); + m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); + } + else + m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString()); + } +// DEBUG ON + else + m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance"); +// DEBUG OFF + } catch (Exception e) + { + m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message); + } + + +/* if (args["appearance_serial"] != null) Appearance.Serial = args["appearance_serial"].AsInteger(); + if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array) { OSDArray wears = (OSDArray)(args["wearables"]); @@ -328,23 +371,23 @@ namespace OpenSim.Framework Appearance.Wearables[i].ItemID = wears[i*2].AsUUID(); Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID(); } - } + } if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); - AttachmentData[] attachments = new AttachmentData[attachs.Count]; + AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count]; int i = 0; foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { - attachments[i++] = new AttachmentData((OSDMap)o); + attachments[i++] = new AvatarAttachment((OSDMap)o); } } Appearance.SetAttachments(attachments); } - +*/ ServiceURLs = new Dictionary(); if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array) { diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index 5da8ba1..55646dd 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -26,9 +26,12 @@ */ using System; +using System.Reflection; using System.Collections; using System.Collections.Generic; using OpenMetaverse; +using OpenMetaverse.StructuredData; +using log4net; namespace OpenSim.Framework { @@ -37,48 +40,26 @@ namespace OpenSim.Framework /// public class AvatarAppearance { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - // these are guessed at by the list here - - // http://wiki.secondlife.com/wiki/Avatar_Appearance. We'll - // correct them over time for when were are wrong. - public readonly static int BODY = 0; - public readonly static int SKIN = 1; - public readonly static int HAIR = 2; - public readonly static int EYES = 3; - public readonly static int SHIRT = 4; - public readonly static int PANTS = 5; - public readonly static int SHOES = 6; - public readonly static int SOCKS = 7; - public readonly static int JACKET = 8; - public readonly static int GLOVES = 9; - public readonly static int UNDERSHIRT = 10; - public readonly static int UNDERPANTS = 11; - public readonly static int SKIRT = 12; - - private readonly static int MAX_WEARABLES = 13; - - private static UUID BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73"); - private static UUID BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9"); - private static UUID SKIN_ASSET = new UUID("77c41e39-38f9-f75a-024e-585989bbabbb"); - private static UUID SKIN_ITEM = new UUID("77c41e39-38f9-f75a-024e-585989bfabc9"); - private static UUID SHIRT_ASSET = new UUID("00000000-38f9-1111-024e-222222111110"); - private static UUID SHIRT_ITEM = new UUID("77c41e39-38f9-f75a-0000-585989bf0000"); - private static UUID PANTS_ASSET = new UUID("00000000-38f9-1111-024e-222222111120"); - private static UUID PANTS_ITEM = new UUID("77c41e39-38f9-f75a-0000-5859892f1111"); - private static UUID HAIR_ASSET = new UUID("d342e6c0-b9d2-11dc-95ff-0800200c9a66"); - private static UUID HAIR_ITEM = new UUID("d342e6c1-b9d2-11dc-95ff-0800200c9a66"); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public readonly static int VISUALPARAM_COUNT = 218; + public readonly static int TEXTURE_COUNT = 21; + protected UUID m_owner; + protected int m_serial = 1; + protected byte[] m_visualparams; + protected Primitive.TextureEntry m_texture; + protected AvatarWearable[] m_wearables; + protected Dictionary m_attachments; + protected float m_avatarHeight = 0; + protected float m_hipOffset = 0; public virtual UUID Owner { get { return m_owner; } set { m_owner = value; } } - protected int m_serial = 1; public virtual int Serial { @@ -86,15 +67,17 @@ namespace OpenSim.Framework set { m_serial = value; } } - protected byte[] m_visualparams; - public virtual byte[] VisualParams { get { return m_visualparams; } set { m_visualparams = value; } } - protected AvatarWearable[] m_wearables; + public virtual Primitive.TextureEntry Texture + { + get { return m_texture; } + set { m_texture = value; } + } public virtual AvatarWearable[] Wearables { @@ -102,287 +85,363 @@ namespace OpenSim.Framework set { m_wearables = value; } } + public virtual Dictionary Attachments + { + get { return m_attachments; } + } + public virtual UUID BodyItem { - get { return m_wearables[BODY].ItemID; } - set { m_wearables[BODY].ItemID = value; } + get { return m_wearables[AvatarWearable.BODY].ItemID; } + set { m_wearables[AvatarWearable.BODY].ItemID = value; } } public virtual UUID BodyAsset { - get { return m_wearables[BODY].AssetID; } - set { m_wearables[BODY].AssetID = value; } + get { return m_wearables[AvatarWearable.BODY].AssetID; } + set { m_wearables[AvatarWearable.BODY].AssetID = value; } } public virtual UUID SkinItem { - get { return m_wearables[SKIN].ItemID; } - set { m_wearables[SKIN].ItemID = value; } + get { return m_wearables[AvatarWearable.SKIN].ItemID; } + set { m_wearables[AvatarWearable.SKIN].ItemID = value; } } public virtual UUID SkinAsset { - get { return m_wearables[SKIN].AssetID; } - set { m_wearables[SKIN].AssetID = value; } + get { return m_wearables[AvatarWearable.SKIN].AssetID; } + set { m_wearables[AvatarWearable.SKIN].AssetID = value; } } public virtual UUID HairItem { - get { return m_wearables[HAIR].ItemID; } - set { m_wearables[HAIR].ItemID = value; } + get { return m_wearables[AvatarWearable.HAIR].ItemID; } + set { m_wearables[AvatarWearable.HAIR].ItemID = value; } } public virtual UUID HairAsset { - get { return m_wearables[HAIR].AssetID; } - set { m_wearables[HAIR].AssetID = value; } + get { return m_wearables[AvatarWearable.HAIR].AssetID; } + set { m_wearables[AvatarWearable.HAIR].AssetID = value; } } public virtual UUID EyesItem { - get { return m_wearables[EYES].ItemID; } - set { m_wearables[EYES].ItemID = value; } + get { return m_wearables[AvatarWearable.EYES].ItemID; } + set { m_wearables[AvatarWearable.EYES].ItemID = value; } } public virtual UUID EyesAsset { - get { return m_wearables[EYES].AssetID; } - set { m_wearables[EYES].AssetID = value; } + get { return m_wearables[AvatarWearable.EYES].AssetID; } + set { m_wearables[AvatarWearable.EYES].AssetID = value; } } public virtual UUID ShirtItem { - get { return m_wearables[SHIRT].ItemID; } - set { m_wearables[SHIRT].ItemID = value; } + get { return m_wearables[AvatarWearable.SHIRT].ItemID; } + set { m_wearables[AvatarWearable.SHIRT].ItemID = value; } } public virtual UUID ShirtAsset { - get { return m_wearables[SHIRT].AssetID; } - set { m_wearables[SHIRT].AssetID = value; } + get { return m_wearables[AvatarWearable.SHIRT].AssetID; } + set { m_wearables[AvatarWearable.SHIRT].AssetID = value; } } public virtual UUID PantsItem { - get { return m_wearables[PANTS].ItemID; } - set { m_wearables[PANTS].ItemID = value; } + get { return m_wearables[AvatarWearable.PANTS].ItemID; } + set { m_wearables[AvatarWearable.PANTS].ItemID = value; } } public virtual UUID PantsAsset { - get { return m_wearables[PANTS].AssetID; } - set { m_wearables[PANTS].AssetID = value; } + get { return m_wearables[AvatarWearable.PANTS].AssetID; } + set { m_wearables[AvatarWearable.PANTS].AssetID = value; } } public virtual UUID ShoesItem { - get { return m_wearables[SHOES].ItemID; } - set { m_wearables[SHOES].ItemID = value; } + get { return m_wearables[AvatarWearable.SHOES].ItemID; } + set { m_wearables[AvatarWearable.SHOES].ItemID = value; } } public virtual UUID ShoesAsset { - get { return m_wearables[SHOES].AssetID; } - set { m_wearables[SHOES].AssetID = value; } + get { return m_wearables[AvatarWearable.SHOES].AssetID; } + set { m_wearables[AvatarWearable.SHOES].AssetID = value; } } public virtual UUID SocksItem { - get { return m_wearables[SOCKS].ItemID; } - set { m_wearables[SOCKS].ItemID = value; } + get { return m_wearables[AvatarWearable.SOCKS].ItemID; } + set { m_wearables[AvatarWearable.SOCKS].ItemID = value; } } public virtual UUID SocksAsset { - get { return m_wearables[SOCKS].AssetID; } - set { m_wearables[SOCKS].AssetID = value; } + get { return m_wearables[AvatarWearable.SOCKS].AssetID; } + set { m_wearables[AvatarWearable.SOCKS].AssetID = value; } } public virtual UUID JacketItem { - get { return m_wearables[JACKET].ItemID; } - set { m_wearables[JACKET].ItemID = value; } + get { return m_wearables[AvatarWearable.JACKET].ItemID; } + set { m_wearables[AvatarWearable.JACKET].ItemID = value; } } public virtual UUID JacketAsset { - get { return m_wearables[JACKET].AssetID; } - set { m_wearables[JACKET].AssetID = value; } + get { return m_wearables[AvatarWearable.JACKET].AssetID; } + set { m_wearables[AvatarWearable.JACKET].AssetID = value; } } public virtual UUID GlovesItem { - get { return m_wearables[GLOVES].ItemID; } - set { m_wearables[GLOVES].ItemID = value; } + get { return m_wearables[AvatarWearable.GLOVES].ItemID; } + set { m_wearables[AvatarWearable.GLOVES].ItemID = value; } } public virtual UUID GlovesAsset { - get { return m_wearables[GLOVES].AssetID; } - set { m_wearables[GLOVES].AssetID = value; } + get { return m_wearables[AvatarWearable.GLOVES].AssetID; } + set { m_wearables[AvatarWearable.GLOVES].AssetID = value; } } public virtual UUID UnderShirtItem { - get { return m_wearables[UNDERSHIRT].ItemID; } - set { m_wearables[UNDERSHIRT].ItemID = value; } + get { return m_wearables[AvatarWearable.UNDERSHIRT].ItemID; } + set { m_wearables[AvatarWearable.UNDERSHIRT].ItemID = value; } } public virtual UUID UnderShirtAsset { - get { return m_wearables[UNDERSHIRT].AssetID; } - set { m_wearables[UNDERSHIRT].AssetID = value; } + get { return m_wearables[AvatarWearable.UNDERSHIRT].AssetID; } + set { m_wearables[AvatarWearable.UNDERSHIRT].AssetID = value; } } public virtual UUID UnderPantsItem { - get { return m_wearables[UNDERPANTS].ItemID; } - set { m_wearables[UNDERPANTS].ItemID = value; } + get { return m_wearables[AvatarWearable.UNDERPANTS].ItemID; } + set { m_wearables[AvatarWearable.UNDERPANTS].ItemID = value; } } public virtual UUID UnderPantsAsset { - get { return m_wearables[UNDERPANTS].AssetID; } - set { m_wearables[UNDERPANTS].AssetID = value; } + get { return m_wearables[AvatarWearable.UNDERPANTS].AssetID; } + set { m_wearables[AvatarWearable.UNDERPANTS].AssetID = value; } } public virtual UUID SkirtItem { - get { return m_wearables[SKIRT].ItemID; } - set { m_wearables[SKIRT].ItemID = value; } + get { return m_wearables[AvatarWearable.SKIRT].ItemID; } + set { m_wearables[AvatarWearable.SKIRT].ItemID = value; } } public virtual UUID SkirtAsset { - get { return m_wearables[SKIRT].AssetID; } - set { m_wearables[SKIRT].AssetID = value; } + get { return m_wearables[AvatarWearable.SKIRT].AssetID; } + set { m_wearables[AvatarWearable.SKIRT].AssetID = value; } } - public virtual void SetDefaultWearables() + public virtual float AvatarHeight { - m_wearables[BODY].AssetID = BODY_ASSET; - m_wearables[BODY].ItemID = BODY_ITEM; - m_wearables[SKIN].AssetID = SKIN_ASSET; - m_wearables[SKIN].ItemID = SKIN_ITEM; - m_wearables[HAIR].AssetID = HAIR_ASSET; - m_wearables[HAIR].ItemID = HAIR_ITEM; - m_wearables[SHIRT].AssetID = SHIRT_ASSET; - m_wearables[SHIRT].ItemID = SHIRT_ITEM; - m_wearables[PANTS].AssetID = PANTS_ASSET; - m_wearables[PANTS].ItemID = PANTS_ITEM; + get { return m_avatarHeight; } + set { m_avatarHeight = value; } } - public virtual void ClearWearables() + public virtual float HipOffset { - for (int i = 0; i < 13; i++) - { - m_wearables[i].AssetID = UUID.Zero; - m_wearables[i].ItemID = UUID.Zero; - } + get { return m_hipOffset; } } - public virtual void SetDefaultParams(byte[] vparams) + public AvatarAppearance() : this(UUID.Zero) {} + + public AvatarAppearance(UUID owner) { - // TODO: Figure out better values then 'fat scientist 150' or 'alien 0' - for (int i = 0; i < VISUALPARAM_COUNT; i++) - { - vparams[i] = 150; - } +// DEBUG ON + m_log.WarnFormat("[AVATAR APPEARANCE] create empty appearance for {0}",owner); +// DEBUG OFF + m_serial = 0; + m_owner = owner; + + SetDefaultWearables(); + SetDefaultTexture(); + SetDefaultParams(); + SetHeight(); + + m_attachments = new Dictionary(); } + + public AvatarAppearance(UUID avatarID, OSDMap map) + { +// DEBUG ON + m_log.WarnFormat("[AVATAR APPEARANCE] create appearance for {0} from OSDMap",avatarID); +// DEBUG OFF + m_owner = avatarID; + Unpack(map); + SetHeight(); + } + + public AvatarAppearance(UUID avatarID, AvatarWearable[] wearables, Primitive.TextureEntry textureEntry, byte[] visualParams) + { +// DEBUG ON + m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance for {0}",avatarID); +// DEBUG OFF + m_serial = 1; + m_owner = avatarID; - protected Primitive.TextureEntry m_texture; + if (wearables != null) + m_wearables = wearables; + else + SetDefaultWearables(); + + if (textureEntry != null) + m_texture = textureEntry; + else + SetDefaultTexture(); - public virtual Primitive.TextureEntry Texture - { - get { return m_texture; } - set { m_texture = value; } + if (visualParams != null) + m_visualparams = visualParams; + else + SetDefaultParams(); + + SetHeight(); + + m_attachments = new Dictionary(); } - protected float m_avatarHeight = 0; - protected float m_hipOffset = 0; + public AvatarAppearance(AvatarAppearance appearance) + { +// DEBUG ON + m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance"); +// DEBUG OFF + if (appearance == null) + { + m_serial = 0; + m_owner = UUID.Zero; - public virtual float AvatarHeight + SetDefaultWearables(); + SetDefaultTexture(); + SetDefaultParams(); + SetHeight(); + + m_attachments = new Dictionary(); + + return; + } + + m_serial = appearance.Serial; + m_owner = appearance.Owner; + + m_wearables = null; + if (appearance.Wearables != null) + { + m_wearables = new AvatarWearable[AvatarWearable.MAX_WEARABLES]; //should be 13 of these + for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) + SetWearable(i,appearance.Wearables[i]); + } + + m_texture = null; + if (appearance.Texture != null) + { + byte[] tbytes = appearance.Texture.GetBytes(); + m_texture = new Primitive.TextureEntry(tbytes,0,tbytes.Length); + } + + m_visualparams = null; + if (appearance.VisualParams != null) + m_visualparams = (byte[])appearance.VisualParams.Clone(); + + m_attachments = new Dictionary(); + foreach (KeyValuePair kvp in appearance.Attachments) + m_attachments[kvp.Key] = new AvatarAttachment(kvp.Value); + } + + protected virtual void SetDefaultWearables() { - get { return m_avatarHeight; } - set { m_avatarHeight = value; } + m_wearables = AvatarWearable.DefaultWearables; } - public virtual float HipOffset + protected virtual void SetDefaultParams() { - get { return m_hipOffset; } + m_visualparams = new byte[VISUALPARAM_COUNT]; + for (int i = 0; i < VISUALPARAM_COUNT; i++) + { + m_visualparams[i] = 150; + } } - //Builds the VisualParam Enum using LIBOMV's Visual Param NameValues - /* - public void BuildVisualParamEnum() + protected virtual void SetDefaultTexture() { - Dictionary IndexedParams = new Dictionary(); - int vpIndex = 0; - IndexedParams = new Dictionary(); - - System.Text.StringBuilder sb = new System.Text.StringBuilder(); + m_texture = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97")); + // The initialization of these seems to force a rebake regardless of whether it is needed + // m_textures.CreateFace(0).TextureID = new UUID("00000000-0000-1111-9999-000000000012"); + // m_textures.CreateFace(1).TextureID = Util.BLANK_TEXTURE_UUID; + // m_textures.CreateFace(2).TextureID = Util.BLANK_TEXTURE_UUID; + // m_textures.CreateFace(3).TextureID = new UUID("6522E74D-1660-4E7F-B601-6F48C1659A77"); + // m_textures.CreateFace(4).TextureID = new UUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B"); + // m_textures.CreateFace(5).TextureID = new UUID("00000000-0000-1111-9999-000000000010"); + // m_textures.CreateFace(6).TextureID = new UUID("00000000-0000-1111-9999-000000000011"); + } - sb.Append("public enum VPElement: int\n"); - sb.Append("{\n"); - foreach (KeyValuePair kvp in OpenMetaverse.VisualParams.Params) + /// + /// Set up appearance textures. + /// Returns boolean that indicates whether the new entries actually change the + /// existing values. + /// + public virtual bool SetTextureEntries(Primitive.TextureEntry textureEntry) + { + if (textureEntry == null) + return false; + + // There are much simpler versions of this copy that could be + // made. We determine if any of the textures actually + // changed to know if the appearance should be saved later + bool changed = false; + for (int i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { - VisualParam vp = kvp.Value; - - // Only Group-0 parameters are sent in AgentSetAppearance packets - if (kvp.Value.Group == 0) - { + Primitive.TextureEntryFace newface = textureEntry.FaceTextures[i]; + Primitive.TextureEntryFace oldface = m_texture.FaceTextures[i]; - if (!IndexedParams.ContainsKey(vp.Name)) - { - - if (vp.Label.Length > 0 || vp.LabelMin.Length > 0 || vp.LabelMax.Length > 0) - { - - sb.Append("/// \n"); - if (vp.LabelMin.Length > 0 && vp.LabelMax.Length > 0) - sb.Append(string.Format("/// {0} - {1} 0--+255 {2}\n", vp.Label, vp.LabelMin, - vp.LabelMax)); - - else - sb.Append(string.Format("/// {0}\n", vp.Label)); - - sb.Append("/// \n"); - } - sb.Append(string.Format(" {0}_{1} = {2}", vp.Wearable.ToUpper(), vp.Name.ToUpper().Replace(" ", "_"),vpIndex)); - - IndexedParams.Add(vp.Name, vpIndex++); - } - else - { - sb.Append(string.Format(" {0}_{1}_{2} = {2}", vp.Wearable.ToUpper(), vp.Name.ToUpper().Replace(" ", "_"), vpIndex)); - vpIndex++; - //int i = 0; - } + if (newface == null) + { + if (oldface == null) continue; } - if (vpIndex < 217) - sb.Append(",\n"); else - sb.Append("\n"); + { + if (oldface != null && oldface.TextureID == newface.TextureID) continue; + } + m_texture.FaceTextures[i] = (newface != null) ? new Primitive.TextureEntryFace(newface) : null; + changed = true; +// DEBUG ON + if (newface != null) + m_log.WarnFormat("[SCENEPRESENCE] index {0}, new texture id {1}",i,newface.TextureID); +// DEBUG OFF } - sb.Append("}\n"); + return changed; } - */ - - public AvatarAppearance() : this(UUID.Zero) {} - - public AvatarAppearance(UUID owner) + + /// + /// Set up visual parameters for the avatar and refresh the avatar height + /// Returns boolean that indicates whether the new entries actually change the + /// existing values. + /// + public virtual bool SetVisualParams(byte[] visualParams) { - m_wearables = new AvatarWearable[MAX_WEARABLES]; - for (int i = 0; i < MAX_WEARABLES; i++) + if (visualParams == null) + return false; + + // There are much simpler versions of this copy that could be + // made. We determine if any of the visual parameters actually + // changed to know if the appearance should be saved later + bool changed = false; + for (int i = 0; i < AvatarAppearance.VISUALPARAM_COUNT; i++) { - // this makes them all null - m_wearables[i] = new AvatarWearable(); + if (visualParams[i] != m_visualparams[i]) + { +// DEBUG ON + m_log.WarnFormat("[AVATARAPPEARANCE] vparams changed [{0}] {1} ==> {2}", + i,m_visualparams[i],visualParams[i]); +// DEBUG OFF + m_visualparams[i] = visualParams[i]; + changed = true; + } } - m_serial = 0; - m_owner = owner; - //BuildVisualParamEnum() - m_visualparams = new byte[VISUALPARAM_COUNT]; - // This sets Visual Params with *less* weirder values then default. Instead of a ugly alien, it looks like a fat scientist - SetDefaultParams(m_visualparams); - SetDefaultWearables(); - m_texture = GetDefaultTexture(); + + // Reset the height if the visual parameters actually changed + if (changed) + SetHeight(); + + return changed; } - - public AvatarAppearance(UUID avatarID, AvatarWearable[] wearables, byte[] visualParams) + + public virtual void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) { - m_owner = avatarID; - m_serial = 1; - m_wearables = wearables; - m_visualparams = visualParams; - m_texture = GetDefaultTexture(); + SetTextureEntries(textureEntry); + SetVisualParams(visualParams); } - - /// - /// Set up appearance textures and avatar parameters, including a height calculation - /// - public virtual void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) + + public virtual void SetHeight() { - if (textureEntry != null) - m_texture = textureEntry; - if (visualParams != null) - m_visualparams = visualParams; - m_avatarHeight = 1.23077f // Shortest possible avatar height + 0.516945f * (float)m_visualparams[(int)VPElement.SHAPE_HEIGHT] / 255.0f // Body height + 0.072514f * (float)m_visualparams[(int)VPElement.SHAPE_HEAD_SIZE] / 255.0f // Head size @@ -390,217 +449,63 @@ namespace OpenSim.Framework + 0.08f * (float)m_visualparams[(int)VPElement.SHOES_PLATFORM_HEIGHT] / 255.0f // Shoe platform height + 0.07f * (float)m_visualparams[(int)VPElement.SHOES_HEEL_HEIGHT] / 255.0f // Shoe heel height + 0.076f * (float)m_visualparams[(int)VPElement.SHAPE_NECK_LENGTH] / 255.0f; // Neck length + m_hipOffset = (((1.23077f // Half of avatar + 0.516945f * (float)m_visualparams[(int)VPElement.SHAPE_HEIGHT] / 255.0f // Body height + 0.3836f * (float)m_visualparams[(int)VPElement.SHAPE_LEG_LENGTH] / 255.0f // Leg length + 0.08f * (float)m_visualparams[(int)VPElement.SHOES_PLATFORM_HEIGHT] / 255.0f // Shoe platform height + 0.07f * (float)m_visualparams[(int)VPElement.SHOES_HEEL_HEIGHT] / 255.0f // Shoe heel height ) / 2) - m_avatarHeight / 2) * 0.31f - 0.0425f; - - - - //System.Console.WriteLine(">>>>>>> [APPEARANCE]: Height {0} Hip offset {1}" + m_avatarHeight + " " + m_hipOffset); - //m_log.Debug("------------- Set Appearance Texture ---------------"); - //Primitive.TextureEntryFace[] faces = Texture.FaceTextures; - //foreach (Primitive.TextureEntryFace face in faces) - //{ - // if (face != null) - // m_log.Debug(" ++ " + face.TextureID); - // else - // m_log.Debug(" ++ NULL "); - //} - //m_log.Debug("----------------------------"); - } public virtual void SetWearable(int wearableId, AvatarWearable wearable) { - m_wearables[wearableId] = wearable; +// DEBUG ON +// m_log.WarnFormat("[AVATARAPPEARANCE] set wearable {0} --> {1}:{2}",wearableId,wearable.ItemID,wearable.AssetID); +// DEBUG OFF + m_wearables[wearableId] = new AvatarWearable(wearable.ItemID,wearable.AssetID); } - public static Primitive.TextureEntry GetDefaultTexture() - { - Primitive.TextureEntry textu = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97")); - textu.CreateFace(0).TextureID = new UUID("00000000-0000-1111-9999-000000000012"); - textu.CreateFace(1).TextureID = Util.BLANK_TEXTURE_UUID; - textu.CreateFace(2).TextureID = Util.BLANK_TEXTURE_UUID; - textu.CreateFace(3).TextureID = new UUID("6522E74D-1660-4E7F-B601-6F48C1659A77"); - textu.CreateFace(4).TextureID = new UUID("7CA39B4C-BD19-4699-AFF7-F93FD03D3E7B"); - textu.CreateFace(5).TextureID = new UUID("00000000-0000-1111-9999-000000000010"); - textu.CreateFace(6).TextureID = new UUID("00000000-0000-1111-9999-000000000011"); - return textu; - } - - public static byte[] GetDefaultVisualParams() - { - byte[] visualParams; - visualParams = new byte[VISUALPARAM_COUNT]; - for (int i = 0; i < VISUALPARAM_COUNT; i++) - { - visualParams[i] = 100; - } - return visualParams; - } +// DEBUG ON public override String ToString() { - String s = "[Wearables] =>"; - s += " Body Item: " + BodyItem.ToString() + ";"; - s += " Skin Item: " + SkinItem.ToString() + ";"; - s += " Shirt Item: " + ShirtItem.ToString() + ";"; - s += " Pants Item: " + PantsItem.ToString() + ";"; - return s; - } - - // this is used for OGS1 - public virtual Hashtable ToHashTable() - { - Hashtable h = new Hashtable(); - h["owner"] = Owner.ToString(); - h["serial"] = Serial.ToString(); - h["visual_params"] = VisualParams; - h["texture"] = Texture.GetBytes(); - h["avatar_height"] = AvatarHeight.ToString(); - h["body_item"] = BodyItem.ToString(); - h["body_asset"] = BodyAsset.ToString(); - h["skin_item"] = SkinItem.ToString(); - h["skin_asset"] = SkinAsset.ToString(); - h["hair_item"] = HairItem.ToString(); - h["hair_asset"] = HairAsset.ToString(); - h["eyes_item"] = EyesItem.ToString(); - h["eyes_asset"] = EyesAsset.ToString(); - h["shirt_item"] = ShirtItem.ToString(); - h["shirt_asset"] = ShirtAsset.ToString(); - h["pants_item"] = PantsItem.ToString(); - h["pants_asset"] = PantsAsset.ToString(); - h["shoes_item"] = ShoesItem.ToString(); - h["shoes_asset"] = ShoesAsset.ToString(); - h["socks_item"] = SocksItem.ToString(); - h["socks_asset"] = SocksAsset.ToString(); - h["jacket_item"] = JacketItem.ToString(); - h["jacket_asset"] = JacketAsset.ToString(); - h["gloves_item"] = GlovesItem.ToString(); - h["gloves_asset"] = GlovesAsset.ToString(); - h["undershirt_item"] = UnderShirtItem.ToString(); - h["undershirt_asset"] = UnderShirtAsset.ToString(); - h["underpants_item"] = UnderPantsItem.ToString(); - h["underpants_asset"] = UnderPantsAsset.ToString(); - h["skirt_item"] = SkirtItem.ToString(); - h["skirt_asset"] = SkirtAsset.ToString(); - - string attachments = GetAttachmentsString(); - if (attachments != String.Empty) - h["attachments"] = attachments; - - return h; - } - - public AvatarAppearance(Hashtable h) - { - Owner = new UUID((string)h["owner"]); - Serial = Convert.ToInt32((string)h["serial"]); - VisualParams = (byte[])h["visual_params"]; - - if (h.Contains("texture")) - { - byte[] te = h["texture"] as byte[]; - if (te != null && te.Length > 0) - Texture = new Primitive.TextureEntry(te, 0, te.Length); - } - else - { - // We shouldn't be receiving appearance hashtables without a TextureEntry, - // but in case we do this will prevent a failure when saving to the database - Texture = GetDefaultTexture(); - } - + String s = ""; + for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) + if (m_texture.FaceTextures[i] != null) + s += String.Format("Texture: {0} --> {1}\n",i,m_texture.FaceTextures[i].TextureID); + + foreach (AvatarWearable awear in m_wearables) + s += String.Format("Wearable: item={0}, asset={1}\n",awear.ItemID,awear.AssetID); + + s += "Visual Params: "; + for (uint j = 0; j < AvatarAppearance.VISUALPARAM_COUNT; j++) + s += String.Format("{0},",m_visualparams[j]); + s += "\n"; - AvatarHeight = (float)Convert.ToDouble((string)h["avatar_height"]); - - m_wearables = new AvatarWearable[MAX_WEARABLES]; - for (int i = 0; i < MAX_WEARABLES; i++) - { - // this makes them all null - m_wearables[i] = new AvatarWearable(); - } - - BodyItem = new UUID((string)h["body_item"]); - BodyAsset = new UUID((string)h["body_asset"]); - SkinItem = new UUID((string)h["skin_item"]); - SkinAsset = new UUID((string)h["skin_asset"]); - HairItem = new UUID((string)h["hair_item"]); - HairAsset = new UUID((string)h["hair_asset"]); - EyesItem = new UUID((string)h["eyes_item"]); - EyesAsset = new UUID((string)h["eyes_asset"]); - ShirtItem = new UUID((string)h["shirt_item"]); - ShirtAsset = new UUID((string)h["shirt_asset"]); - PantsItem = new UUID((string)h["pants_item"]); - PantsAsset = new UUID((string)h["pants_asset"]); - ShoesItem = new UUID((string)h["shoes_item"]); - ShoesAsset = new UUID((string)h["shoes_asset"]); - SocksItem = new UUID((string)h["socks_item"]); - SocksAsset = new UUID((string)h["socks_asset"]); - JacketItem = new UUID((string)h["jacket_item"]); - JacketAsset = new UUID((string)h["jacket_asset"]); - GlovesItem = new UUID((string)h["gloves_item"]); - GlovesAsset = new UUID((string)h["gloves_asset"]); - UnderShirtItem = new UUID((string)h["undershirt_item"]); - UnderShirtAsset = new UUID((string)h["undershirt_asset"]); - UnderPantsItem = new UUID((string)h["underpants_item"]); - UnderPantsAsset = new UUID((string)h["underpants_asset"]); - SkirtItem = new UUID((string)h["skirt_item"]); - SkirtAsset = new UUID((string)h["skirt_asset"]); - - if (h.ContainsKey("attachments")) - { - SetAttachmentsString(h["attachments"].ToString()); - } + return s; } +// DEBUG OFF - private Dictionary m_attachments = new Dictionary(); - - public void SetAttachments(AttachmentData[] data) + public void SetAttachments(AvatarAttachment[] data) { - foreach (AttachmentData a in data) - { - m_attachments[a.AttachPoint] = new UUID[2]; - m_attachments[a.AttachPoint][0] = a.ItemID; - m_attachments[a.AttachPoint][1] = a.AssetID; - } + foreach (AvatarAttachment attach in data) + m_attachments[attach.AttachPoint] = new AvatarAttachment(attach); } - public void SetAttachments(Hashtable data) + public void SetAttachment(int attachpoint, UUID item, UUID asset) { - m_attachments.Clear(); - - if (data == null) + if (attachpoint == 0) return; - foreach (DictionaryEntry e in data) + if (item == UUID.Zero) { - int attachpoint = Convert.ToInt32(e.Key); - if (m_attachments.ContainsKey(attachpoint)) - continue; - - UUID item; - UUID asset; - - Hashtable uuids = (Hashtable) e.Value; - UUID.TryParse(uuids["item"].ToString(), out item); - UUID.TryParse(uuids["asset"].ToString(), out asset); - - UUID[] attachment = new UUID[2]; - attachment[0] = item; - attachment[1] = asset; - - m_attachments[attachpoint] = attachment; + m_attachments.Remove(attachpoint); + return; } - } - public Dictionary GetAttachmentDictionary() - { - return m_attachments; + m_attachments[attachpoint] = new AvatarAttachment(attachpoint,item,asset); } public Hashtable GetAttachments() @@ -610,16 +515,13 @@ namespace OpenSim.Framework Hashtable ret = new Hashtable(); - foreach (KeyValuePair kvp in m_attachments) + foreach (KeyValuePair kvp in m_attachments) { - int attachpoint = kvp.Key; - UUID[] uuids = kvp.Value; - Hashtable data = new Hashtable(); - data["item"] = uuids[0].ToString(); - data["asset"] = uuids[1].ToString(); + data["item"] = kvp.Value.ItemID.ToString(); + data["asset"] = kvp.Value.AssetID.ToString(); - ret[attachpoint] = data; + ret[kvp.Key] = data; } return ret; @@ -635,7 +537,7 @@ namespace OpenSim.Framework if (!m_attachments.ContainsKey(attachpoint)) return UUID.Zero; - return m_attachments[attachpoint][0]; + return m_attachments[attachpoint].ItemID; } public UUID GetAttachedAsset(int attachpoint) @@ -643,33 +545,14 @@ namespace OpenSim.Framework if (!m_attachments.ContainsKey(attachpoint)) return UUID.Zero; - return m_attachments[attachpoint][1]; - } - - public void SetAttachment(int attachpoint, UUID item, UUID asset) - { - if (attachpoint == 0) - return; - - if (item == UUID.Zero) - { - if (m_attachments.ContainsKey(attachpoint)) - m_attachments.Remove(attachpoint); - return; - } - - if (!m_attachments.ContainsKey(attachpoint)) - m_attachments[attachpoint] = new UUID[2]; - - m_attachments[attachpoint][0] = item; - m_attachments[attachpoint][1] = asset; + return m_attachments[attachpoint].AssetID; } public int GetAttachpoint(UUID itemID) { - foreach (KeyValuePair kvp in m_attachments) + foreach (KeyValuePair kvp in m_attachments) { - if (kvp.Value[0] == itemID) + if (kvp.Value.ItemID == itemID) { return kvp.Key; } @@ -690,42 +573,126 @@ namespace OpenSim.Framework m_attachments.Clear(); } - string GetAttachmentsString() + /// + /// Create an OSDMap from the appearance data + /// + public OSDMap Pack() { - List strings = new List(); + OSDMap data = new OSDMap(); - foreach (KeyValuePair e in m_attachments) + data["serial"] = OSD.FromInteger(m_serial); + data["height"] = OSD.FromReal(m_avatarHeight); + data["hipoffset"] = OSD.FromReal(m_hipOffset); + + // Wearables + OSDArray wears = new OSDArray(AvatarWearable.MAX_WEARABLES); + for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) + wears.Add(m_wearables[i].Pack()); + data["wearables"] = wears; + + // Avatar Textures + OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); + for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { - strings.Add(e.Key.ToString()); - strings.Add(e.Value[0].ToString()); - strings.Add(e.Value[1].ToString()); + if (m_texture.FaceTextures[i] != null) + textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); + else + textures.Add(OSD.FromUUID(UUID.Zero)); } + data["textures"] = textures; - return String.Join(",", strings.ToArray()); + // Visual Parameters + OSDBinary visualparams = new OSDBinary(m_visualparams); + data["visualparams"] = visualparams; + + // Attachments + OSDArray attachs = new OSDArray(m_attachments.Count); + foreach (KeyValuePair kvp in m_attachments) + attachs.Add(kvp.Value.Pack()); + data["attachments"] = attachs; + + return data; } - void SetAttachmentsString(string data) + /// + /// Unpack and OSDMap and initialize the appearance + /// from it + /// + public void Unpack(OSDMap data) { - string[] strings = data.Split(new char[] {','}); - int i = 0; + if ((data != null) && (data["appearance_serial"] != null)) + m_serial = data["appearance_serial"].AsInteger(); + if ((data != null) && (data["height"] != null)) + m_avatarHeight = (float)data["height"].AsReal(); + if ((data != null) && (data["hipoffset"] != null)) + m_hipOffset = (float)data["hipoffset"].AsReal(); + + try + { + // Wearables + SetDefaultWearables(); + if ((data != null) && (data["wearables"] != null) && (data["wearables"]).Type == OSDType.Array) + { + OSDArray wears = (OSDArray)(data["wearables"]); + for (int i = 0; i < wears.Count; i++) + m_wearables[i] = new AvatarWearable((OSDMap)wears[i]); + } + else + { + m_log.Warn("[AVATARAPPEARANCE] failed to unpack wearables"); + } - m_attachments.Clear(); + // Avatar Textures + SetDefaultTexture(); + if ((data != null) && (data["textures"] != null) && (data["textures"]).Type == OSDType.Array) + { + OSDArray textures = (OSDArray)(data["textures"]); + for (int i = 0; i < AvatarAppearance.TEXTURE_COUNT && i < textures.Count; i++) + { + if (textures[i] != null) + { + UUID textureID = textures[i].AsUUID(); + if (textureID != UUID.Zero) + m_texture.CreateFace((uint)i).TextureID = textureID; + } + } + } + else + { + m_log.Warn("[AVATARAPPEARANCE] failed to unpack textures"); + } - while (strings.Length - i > 2) - { - int attachpoint = Int32.Parse(strings[i]); - UUID item = new UUID(strings[i+1]); - UUID asset = new UUID(strings[i+2]); - i += 3; + // Visual Parameters + SetDefaultParams(); + if ((data != null) && (data["visualparams"] != null)) + { + if ((data["visualparams"].Type == OSDType.Binary) || (data["visualparams"].Type == OSDType.Array)) + m_visualparams = data["visualparams"].AsBinary(); + } + else + { + m_log.Warn("[AVATARAPPEARANCE] failed to unpack visual parameters"); + } - if (!m_attachments.ContainsKey(attachpoint)) + // Attachments + m_attachments = new Dictionary(); + if ((data != null) && (data["attachments"] != null) && (data["attachments"]).Type == OSDType.Array) { - m_attachments[attachpoint] = new UUID[2]; - m_attachments[attachpoint][0] = item; - m_attachments[attachpoint][1] = asset; + OSDArray attachs = (OSDArray)(data["attachments"]); + for (int i = 0; i < attachs.Count; i++) + { + AvatarAttachment attach = new AvatarAttachment((OSDMap)attachs[i]); + m_attachments[attach.AttachPoint] = attach; + } } } + catch (Exception e) + { + m_log.ErrorFormat("[AVATARAPPEARANCE] unpack failed badly: {0}",e.Message); + } } + + /// /// Viewer Params Array Element for AgentSetAppearance /// Generated from LibOMV's Visual Params list diff --git a/OpenSim/Framework/AvatarAttachment.cs b/OpenSim/Framework/AvatarAttachment.cs new file mode 100644 index 0000000..c68d78d --- /dev/null +++ b/OpenSim/Framework/AvatarAttachment.cs @@ -0,0 +1,78 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Framework +{ + public class AvatarAttachment + { + public int AttachPoint; + public UUID ItemID; + public UUID AssetID; + + public AvatarAttachment(AvatarAttachment attach) + { + AttachPoint = attach.AttachPoint; + ItemID = attach.ItemID; + AssetID = attach.AssetID; + } + + public AvatarAttachment(int point, UUID item, UUID asset) + { + AttachPoint = point; + ItemID = item; + AssetID = asset; + } + + public AvatarAttachment(OSDMap args) + { + Unpack(args); + } + + public OSDMap Pack() + { + OSDMap attachdata = new OSDMap(); + attachdata["point"] = OSD.FromInteger(AttachPoint); + attachdata["item"] = OSD.FromUUID(ItemID); + attachdata["asset"] = OSD.FromUUID(AssetID); + + return attachdata; + } + + + public void Unpack(OSDMap args) + { + if (args["point"] != null) + AttachPoint = args["point"].AsInteger(); + ItemID = (args["item"] != null) ? args["item"].AsUUID() : UUID.Zero; + AssetID = (args["asset"] != null) ? args["asset"].AsUUID() : UUID.Zero; + } + } +} diff --git a/OpenSim/Framework/AvatarWearable.cs b/OpenSim/Framework/AvatarWearable.cs index 30c5172..87098bf 100644 --- a/OpenSim/Framework/AvatarWearable.cs +++ b/OpenSim/Framework/AvatarWearable.cs @@ -26,14 +26,32 @@ */ using System; -using System.Runtime.Serialization; -using System.Security.Permissions; using OpenMetaverse; +using OpenMetaverse.StructuredData; namespace OpenSim.Framework { public class AvatarWearable { + // these are guessed at by the list here - + // http://wiki.secondlife.com/wiki/Avatar_Appearance. We'll + // correct them over time for when were are wrong. + public static readonly int BODY = 0; + public static readonly int SKIN = 1; + public static readonly int HAIR = 2; + public static readonly int EYES = 3; + public static readonly int SHIRT = 4; + public static readonly int PANTS = 5; + public static readonly int SHOES = 6; + public static readonly int SOCKS = 7; + public static readonly int JACKET = 8; + public static readonly int GLOVES = 9; + public static readonly int UNDERSHIRT = 10; + public static readonly int UNDERPANTS = 11; + public static readonly int SKIRT = 12; + + public static readonly int MAX_WEARABLES = 13; + public static readonly UUID DEFAULT_BODY_ITEM = new UUID("66c41e39-38f9-f75a-024e-585989bfaba9"); public static readonly UUID DEFAULT_BODY_ASSET = new UUID("66c41e39-38f9-f75a-024e-585989bfab73"); @@ -62,12 +80,32 @@ namespace OpenSim.Framework ItemID = itemId; } + public AvatarWearable(OSDMap args) + { + Unpack(args); + } + + public OSDMap Pack() + { + OSDMap weardata = new OSDMap(); + weardata["item"] = OSD.FromUUID(ItemID); + weardata["asset"] = OSD.FromUUID(AssetID); + + return weardata; + } + + public void Unpack(OSDMap args) + { + ItemID = (args["item"] != null) ? args["item"].AsUUID() : UUID.Zero; + AssetID = (args["asset"] != null) ? args["asset"].AsUUID() : UUID.Zero; + } + public static AvatarWearable[] DefaultWearables { get { - AvatarWearable[] defaultWearables = new AvatarWearable[13]; //should be 13 of these - for (int i = 0; i < 13; i++) + AvatarWearable[] defaultWearables = new AvatarWearable[MAX_WEARABLES]; //should be 13 of these + for (int i = 0; i < MAX_WEARABLES; i++) { defaultWearables[i] = new AvatarWearable(); } diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs index 72283de..6b64e12 100644 --- a/OpenSim/Framework/Capabilities/Caps.cs +++ b/OpenSim/Framework/Capabilities/Caps.cs @@ -976,7 +976,9 @@ namespace OpenSim.Framework.Capabilities public void BakedTextureUploaded(UUID assetID, byte[] data) { - m_log.DebugFormat("[CAPS]: Received baked texture {0}", assetID.ToString()); +// DEBUG ON + m_log.WarnFormat("[CAPS]: Received baked texture {0}", assetID.ToString()); +// DEBUG OFF AssetBase asset; asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString()); asset.Data = data; diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs index 0dc5dbc..fdebba3 100644 --- a/OpenSim/Framework/ChildAgentDataUpdate.cs +++ b/OpenSim/Framework/ChildAgentDataUpdate.cs @@ -225,46 +225,6 @@ namespace OpenSim.Framework } } - public class AttachmentData - { - public int AttachPoint; - public UUID ItemID; - public UUID AssetID; - - public AttachmentData(int point, UUID item, UUID asset) - { - AttachPoint = point; - ItemID = item; - AssetID = asset; - } - - public AttachmentData(OSDMap args) - { - UnpackUpdateMessage(args); - } - - public OSDMap PackUpdateMessage() - { - OSDMap attachdata = new OSDMap(); - attachdata["point"] = OSD.FromInteger(AttachPoint); - attachdata["item"] = OSD.FromUUID(ItemID); - attachdata["asset"] = OSD.FromUUID(AssetID); - - return attachdata; - } - - - public void UnpackUpdateMessage(OSDMap args) - { - if (args["point"] != null) - AttachPoint = args["point"].AsInteger(); - if (args["item"] != null) - ItemID = args["item"].AsUUID(); - if (args["asset"] != null) - AssetID = args["asset"].AsUUID(); - } - } - public class ControllerData { public UUID ItemID; @@ -348,11 +308,14 @@ namespace OpenSim.Framework public UUID GranterID; // Appearance + public AvatarAppearance Appearance; + +/* public byte[] AgentTextures; public byte[] VisualParams; public UUID[] Wearables; - public AttachmentData[] Attachments; - + public AvatarAttachment[] Attachments; +*/ // Scripted public ControllerData[] Controllers; @@ -413,6 +376,9 @@ namespace OpenSim.Framework args["animations"] = anims; } + if (Appearance != null) + args["packed_appearance"] = Appearance.Pack(); + //if ((AgentTextures != null) && (AgentTextures.Length > 0)) //{ // OSDArray textures = new OSDArray(AgentTextures.Length); @@ -421,7 +387,7 @@ namespace OpenSim.Framework // args["agent_textures"] = textures; //} - +/* if ((AgentTextures != null) && (AgentTextures.Length > 0)) args["texture_entry"] = OSD.FromBinary(AgentTextures); @@ -441,11 +407,11 @@ namespace OpenSim.Framework if ((Attachments != null) && (Attachments.Length > 0)) { OSDArray attachs = new OSDArray(Attachments.Length); - foreach (AttachmentData att in Attachments) - attachs.Add(att.PackUpdateMessage()); + foreach (AvatarAttachment att in Attachments) + attachs.Add(att.Pack()); args["attachments"] = attachs; } - +*/ if ((Controllers != null) && (Controllers.Length > 0)) { OSDArray controls = new OSDArray(Controllers.Length); @@ -581,6 +547,12 @@ namespace OpenSim.Framework // AgentTextures[i++] = o.AsUUID(); //} + if (args["packed_appearance"] != null) + Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); + else + Appearance = new AvatarAppearance(AgentID); + +/* if (args["texture_entry"] != null) AgentTextures = args["texture_entry"].AsBinary(); @@ -599,17 +571,17 @@ namespace OpenSim.Framework if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); - Attachments = new AttachmentData[attachs.Count]; + Attachments = new AvatarAttachment[attachs.Count]; int i = 0; foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { - Attachments[i++] = new AttachmentData((OSDMap)o); + Attachments[i++] = new AvatarAttachment((OSDMap)o); } } } - +*/ if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { OSDArray controls = (OSDArray)(args["controllers"]); diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 94815cd..027f9c5 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -43,7 +43,7 @@ namespace OpenSim.Framework public delegate void TextureRequest(Object sender, TextureRequestArgs e); - public delegate void AvatarNowWearing(Object sender, AvatarWearingArgs e); + public delegate void AvatarNowWearing(IClientAPI sender, AvatarWearingArgs e); public delegate void ImprovedInstantMessage(IClientAPI remoteclient, GridInstantMessage im); @@ -65,7 +65,7 @@ namespace OpenSim.Framework public delegate void NetworkStats(int inPackets, int outPackets, int unAckedBytes); - public delegate void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams); + public delegate void SetAppearance(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams); public delegate void StartAnim(IClientAPI remoteClient, UUID animID); @@ -711,7 +711,7 @@ namespace OpenSim.Framework event TeleportLandmarkRequest OnTeleportLandmarkRequest; event DeRezObject OnDeRezObject; event Action OnRegionHandShakeReply; - event GenericCall2 OnRequestWearables; + event GenericCall1 OnRequestWearables; event GenericCall1 OnCompleteMovementToRegion; event UpdateAgent OnPreAgentUpdate; event UpdateAgent OnAgentUpdate; diff --git a/OpenSim/Framework/Tests/AgentCircuitDataTest.cs b/OpenSim/Framework/Tests/AgentCircuitDataTest.cs index 2fda6f3..05d8469 100644 --- a/OpenSim/Framework/Tests/AgentCircuitDataTest.cs +++ b/OpenSim/Framework/Tests/AgentCircuitDataTest.cs @@ -65,9 +65,7 @@ namespace OpenSim.Framework.Tests SessionId = UUID.Random(); AvAppearance = new AvatarAppearance(AgentId); - AvAppearance.SetDefaultWearables(); VisualParams = new byte[218]; - AvAppearance.SetDefaultParams(VisualParams); //body VisualParams[(int)AvatarAppearance.VPElement.SHAPE_HEIGHT] = 155; -- cgit v1.1 From 267f18925d06ca05e2a5ffbfbb63582783762439 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Thu, 21 Oct 2010 16:48:58 -0700 Subject: First attempt to get multiple attachments working to support viewer2. The attachment code appears to work correctly for 1.23 viewers so, in spite of some big changes in the internal representation, there don't appear to be regressions. That being said, I still can't get a viewer2 avatar to show correctly. --- OpenSim/Framework/AvatarAppearance.cs | 138 +++++++++++++++++----------------- 1 file changed, 70 insertions(+), 68 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index 55646dd..ba0cad2 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -51,7 +51,7 @@ namespace OpenSim.Framework protected byte[] m_visualparams; protected Primitive.TextureEntry m_texture; protected AvatarWearable[] m_wearables; - protected Dictionary m_attachments; + protected Dictionary> m_attachments; protected float m_avatarHeight = 0; protected float m_hipOffset = 0; @@ -85,11 +85,6 @@ namespace OpenSim.Framework set { m_wearables = value; } } - public virtual Dictionary Attachments - { - get { return m_attachments; } - } - public virtual UUID BodyItem { get { return m_wearables[AvatarWearable.BODY].ItemID; } set { m_wearables[AvatarWearable.BODY].ItemID = value; } @@ -246,7 +241,7 @@ namespace OpenSim.Framework SetDefaultParams(); SetHeight(); - m_attachments = new Dictionary(); + m_attachments = new Dictionary>(); } public AvatarAppearance(UUID avatarID, OSDMap map) @@ -284,7 +279,7 @@ namespace OpenSim.Framework SetHeight(); - m_attachments = new Dictionary(); + m_attachments = new Dictionary>(); } public AvatarAppearance(AvatarAppearance appearance) @@ -302,7 +297,7 @@ namespace OpenSim.Framework SetDefaultParams(); SetHeight(); - m_attachments = new Dictionary(); + m_attachments = new Dictionary>(); return; } @@ -329,9 +324,10 @@ namespace OpenSim.Framework if (appearance.VisualParams != null) m_visualparams = (byte[])appearance.VisualParams.Clone(); - m_attachments = new Dictionary(); - foreach (KeyValuePair kvp in appearance.Attachments) - m_attachments[kvp.Key] = new AvatarAttachment(kvp.Value); + // Copy the attachment, force append mode since that ensures consistency + m_attachments = new Dictionary>(); + foreach (AvatarAttachment attachment in appearance.GetAttachments()) + AppendAttachment(new AvatarAttachment(attachment)); } protected virtual void SetDefaultWearables() @@ -487,12 +483,41 @@ namespace OpenSim.Framework } // DEBUG OFF - public void SetAttachments(AvatarAttachment[] data) + /// + /// Get a list of the attachments, note that there may be + /// duplicate attachpoints + /// + public List GetAttachments() + { + List alist = new List(); + foreach (KeyValuePair> kvp in m_attachments) + { + foreach (AvatarAttachment attach in kvp.Value) + alist.Add(new AvatarAttachment(attach)); + } + + return alist; + } + + internal void AppendAttachment(AvatarAttachment attach) { - foreach (AvatarAttachment attach in data) - m_attachments[attach.AttachPoint] = new AvatarAttachment(attach); + if (! m_attachments.ContainsKey(attach.AttachPoint)) + m_attachments[attach.AttachPoint] = new List(); + m_attachments[attach.AttachPoint].Add(attach); } + internal void ReplaceAttachment(AvatarAttachment attach) + { + m_attachments[attach.AttachPoint] = new List(); + m_attachments[attach.AttachPoint].Add(attach); + } + + /// + /// Add an attachment, if the attachpoint has the + /// 0x80 bit set then we assume this is an append + /// operation otherwise we replace whatever is + /// currently attached at the attachpoint + /// public void SetAttachment(int attachpoint, UUID item, UUID asset) { if (attachpoint == 0) @@ -505,67 +530,47 @@ namespace OpenSim.Framework return; } - m_attachments[attachpoint] = new AvatarAttachment(attachpoint,item,asset); - } - - public Hashtable GetAttachments() - { - if (m_attachments.Count == 0) - return null; - - Hashtable ret = new Hashtable(); - - foreach (KeyValuePair kvp in m_attachments) + // check if this is an append or a replace, 0x80 marks it as an append + if ((attachpoint & 0x80) > 0) { - Hashtable data = new Hashtable(); - data["item"] = kvp.Value.ItemID.ToString(); - data["asset"] = kvp.Value.AssetID.ToString(); - - ret[kvp.Key] = data; + // strip the append bit + int point = attachpoint & 0x7F; + AppendAttachment(new AvatarAttachment(point, item, asset)); + } + else + { + ReplaceAttachment(new AvatarAttachment(attachpoint,item,asset)); } - - return ret; - } - - public List GetAttachedPoints() - { - return new List(m_attachments.Keys); - } - - public UUID GetAttachedItem(int attachpoint) - { - if (!m_attachments.ContainsKey(attachpoint)) - return UUID.Zero; - - return m_attachments[attachpoint].ItemID; - } - - public UUID GetAttachedAsset(int attachpoint) - { - if (!m_attachments.ContainsKey(attachpoint)) - return UUID.Zero; - - return m_attachments[attachpoint].AssetID; } public int GetAttachpoint(UUID itemID) { - foreach (KeyValuePair kvp in m_attachments) + foreach (KeyValuePair> kvp in m_attachments) { - if (kvp.Value.ItemID == itemID) - { + int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; }); + if (index >= 0) return kvp.Key; - } } + return 0; } public void DetachAttachment(UUID itemID) { - int attachpoint = GetAttachpoint(itemID); + foreach (KeyValuePair> kvp in m_attachments) + { + int index = kvp.Value.FindIndex(delegate(AvatarAttachment a) { return a.ItemID == itemID; }); + if (index >= 0) + { + // Remove it from the list of attachments at that attach point + m_attachments[kvp.Key].RemoveAt(index); - if (attachpoint > 0) - m_attachments.Remove(attachpoint); + // And remove the list if there are no more attachments here + if (m_attachments[kvp.Key].Count == 0) + m_attachments.Remove(kvp.Key); + return; + } + } } public void ClearAttachments() @@ -607,8 +612,8 @@ namespace OpenSim.Framework // Attachments OSDArray attachs = new OSDArray(m_attachments.Count); - foreach (KeyValuePair kvp in m_attachments) - attachs.Add(kvp.Value.Pack()); + foreach (AvatarAttachment attach in GetAttachments()) + attachs.Add(attach.Pack()); data["attachments"] = attachs; return data; @@ -675,15 +680,12 @@ namespace OpenSim.Framework } // Attachments - m_attachments = new Dictionary(); + m_attachments = new Dictionary>(); if ((data != null) && (data["attachments"] != null) && (data["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(data["attachments"]); for (int i = 0; i < attachs.Count; i++) - { - AvatarAttachment attach = new AvatarAttachment((OSDMap)attachs[i]); - m_attachments[attach.AttachPoint] = attach; - } + AppendAttachment(new AvatarAttachment((OSDMap)attachs[i])); } } catch (Exception e) -- cgit v1.1 From 657cceb8847f94a9af0c8b2358124105d778486c Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Mon, 25 Oct 2010 09:41:08 -0700 Subject: Intermediate commit for backward compatability; does not compile yet --- OpenSim/Framework/AgentCircuitData.cs | 65 ++++++++++++++-------------- OpenSim/Framework/ChildAgentDataUpdate.cs | 70 ++++++++++++++++++------------- 2 files changed, 73 insertions(+), 62 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs index be98380..30a9548 100644 --- a/OpenSim/Framework/AgentCircuitData.cs +++ b/OpenSim/Framework/AgentCircuitData.cs @@ -206,16 +206,18 @@ namespace OpenSim.Framework args["service_session_id"] = OSD.FromString(ServiceSessionID); args["start_pos"] = OSD.FromString(startpos.ToString()); - args["appearance_serial"] = OSD.FromInteger(Appearance.Serial); args["client_ip"] = OSD.FromString(IPAddress); args["viewer"] = OSD.FromString(Viewer); args["channel"] = OSD.FromString(Channel); args["mac"] = OSD.FromString(Mac); args["id0"] = OSD.FromString(Id0); -/* + // Eventually this code should be deprecated, use full appearance + // packing in packed_appearance if (Appearance != null) { + args["appearance_serial"] = OSD.FromInteger(Appearance.Serial); + //System.Console.WriteLine("XXX Before packing Wearables"); if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0)) { @@ -230,20 +232,19 @@ namespace OpenSim.Framework } //System.Console.WriteLine("XXX Before packing Attachments"); - Dictionary attachments = Appearance.Attachments; + List attachments = Appearance.GetAttachments(); if ((attachments != null) && (attachments.Count > 0)) { OSDArray attachs = new OSDArray(attachments.Count); - foreach (KeyValuePair kvp in attachments) + foreach (AvatarAttachment attach in attachments) { - AvatarAttachment adata = new AvatarAttachment(kvp.Value); - attachs.Add(adata.Pack()); + attachs.Add(attach.Pack()); //System.Console.WriteLine("XXX att.pt=" + kvp.Key + "; itemID=" + kvp.Value[0] + "; assetID=" + kvp.Value[1]); } args["attachments"] = attachs; } } -*/ + if (Appearance != null) { OSDMap appmap = Appearance.Pack(); @@ -339,27 +340,9 @@ namespace OpenSim.Framework try { // Unpack various appearance elements Appearance = new AvatarAppearance(AgentID); - if (args["packed_appearance"] != null) - { - if (args["packed_appearance"].Type == OSDType.Map) - { - Appearance.Unpack((OSDMap)args["packed_appearance"]); - m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); - } - else - m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString()); - } -// DEBUG ON - else - m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance"); -// DEBUG OFF - } catch (Exception e) - { - m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message); - } - - -/* + + // Eventually this code should be deprecated, use full appearance + // packing in packed_appearance if (args["appearance_serial"] != null) Appearance.Serial = args["appearance_serial"].AsInteger(); @@ -376,18 +359,34 @@ namespace OpenSim.Framework if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); - AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count]; - int i = 0; foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { - attachments[i++] = new AvatarAttachment((OSDMap)o); + Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o)); } } - Appearance.SetAttachments(attachments); } -*/ + + if (args["packed_appearance"] != null) + { + if (args["packed_appearance"].Type == OSDType.Map) + { + Appearance.Unpack((OSDMap)args["packed_appearance"]); + m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); + } + else + m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString()); + } +// DEBUG ON + else + m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance"); +// DEBUG OFF + } catch (Exception e) + { + m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message); + } + ServiceURLs = new Dictionary(); if (args.ContainsKey("service_urls") && args["service_urls"] != null && (args["service_urls"]).Type == OSDType.Array) { diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs index fdebba3..d7a7d1e 100644 --- a/OpenSim/Framework/ChildAgentDataUpdate.cs +++ b/OpenSim/Framework/ChildAgentDataUpdate.cs @@ -387,31 +387,37 @@ namespace OpenSim.Framework // args["agent_textures"] = textures; //} -/* - if ((AgentTextures != null) && (AgentTextures.Length > 0)) - args["texture_entry"] = OSD.FromBinary(AgentTextures); + // The code to pack textures, visuals, wearables and attachments + // should be removed; packed appearance contains the full appearance + // This is retained for backward compatibility only + if ((Appearance.Texture != null) && (Appearance.Texture.Length > 0)) + args["texture_entry"] = OSD.FromBinary(Appearance.Texture); - if ((VisualParams != null) && (VisualParams.Length > 0)) - args["visual_params"] = OSD.FromBinary(VisualParams); + if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0)) + args["visual_params"] = OSD.FromBinary(Appearance.VisualParams); // We might not pass this in all cases... - if ((Wearables != null) && (Wearables.Length > 0)) + if ((Appearance.Wearables != null) && (Appearance.Wearables.Length > 0)) { - OSDArray wears = new OSDArray(Wearables.Length); - foreach (UUID uuid in Wearables) - wears.Add(OSD.FromUUID(uuid)); + OSDArray wears = new OSDArray(Appearance.Wearables.Length * 2); + foreach (AvatarWearable awear in Appearance.Wearables) + { + wears.Add(OSD.FromUUID(awear.ItemID)); + wears.Add(OSD.FromUUID(awear.AssetID)); + } args["wearables"] = wears; } - - if ((Attachments != null) && (Attachments.Length > 0)) + List attachments = Appearance.GetAttachments(); + if ((attachments != null) && (attachments.Length > 0)) { - OSDArray attachs = new OSDArray(Attachments.Length); - foreach (AvatarAttachment att in Attachments) + OSDArray attachs = new OSDArray(attachments.Length); + foreach (AvatarAttachment att in attachments) attachs.Add(att.Pack()); args["attachments"] = attachs; } -*/ + // End of code to remove + if ((Controllers != null) && (Controllers.Length > 0)) { OSDArray controls = new OSDArray(Controllers.Length); @@ -547,41 +553,47 @@ namespace OpenSim.Framework // AgentTextures[i++] = o.AsUUID(); //} - if (args["packed_appearance"] != null) - Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); - else - Appearance = new AvatarAppearance(AgentID); - -/* + + Appearance = new AvatarAppearance(AgentID); + + // The code to pack textures, visuals, wearables and attachments + // should be removed; packed appearance contains the full appearance + // This is retained for backward compatibility only if (args["texture_entry"] != null) - AgentTextures = args["texture_entry"].AsBinary(); + Appearance.SetTextureEntries(args["texture_entry"].AsBinary()); if (args["visual_params"] != null) - VisualParams = args["visual_params"].AsBinary(); + Appearance.SetVisualParams(args["visual_params"].AsBinary()); if ((args["wearables"] != null) && (args["wearables"]).Type == OSDType.Array) { OSDArray wears = (OSDArray)(args["wearables"]); - Wearables = new UUID[wears.Count]; - int i = 0; - foreach (OSD o in wears) - Wearables[i++] = o.AsUUID(); + for (int i = 0; i < wears.Count / 2; i++) + { + Appearance.Wearables[i].ItemID = wears[i*2].AsUUID(); + Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID(); + } } if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); - Attachments = new AvatarAttachment[attachs.Count]; + AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count]; int i = 0; foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { - Attachments[i++] = new AvatarAttachment((OSDMap)o); + attachments[i++] = new AvatarAttachment((OSDMap)o); } } + Appearance.SetAttachments(attachments); } -*/ + // end of code to remove + + if (args["packed_appearance"] != null) + Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); + if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { OSDArray controls = (OSDArray)(args["controllers"]); -- cgit v1.1 From 6e58c3d563b50c5797d1cfffbaec3fe82f18c2ea Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Mon, 25 Oct 2010 14:11:47 -0700 Subject: Half of the compatibility is working. Login into a new region with old data works. Teleport out of a new region with old data works. Teleport into a new region with old data does not trigger the necessary rebake. --- OpenSim/Framework/AgentCircuitData.cs | 13 +++++------- OpenSim/Framework/AvatarAppearance.cs | 2 +- OpenSim/Framework/ChildAgentDataUpdate.cs | 33 ++++++++++++++++++++----------- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs index 30a9548..098b33c 100644 --- a/OpenSim/Framework/AgentCircuitData.cs +++ b/OpenSim/Framework/AgentCircuitData.cs @@ -368,15 +368,12 @@ namespace OpenSim.Framework } } - if (args["packed_appearance"] != null) + if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map)) { - if (args["packed_appearance"].Type == OSDType.Map) - { - Appearance.Unpack((OSDMap)args["packed_appearance"]); - m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); - } - else - m_log.WarnFormat("[AGENTCIRCUITDATA] packed_appearance is not a map:\n{0}",args["packed_appearance"].ToString()); + Appearance.Unpack((OSDMap)args["packed_appearance"]); +// DEBUG ON + m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance"); +// DEBUG OFF } // DEBUG ON else diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index ba0cad2..05330c7 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -389,7 +389,7 @@ namespace OpenSim.Framework changed = true; // DEBUG ON if (newface != null) - m_log.WarnFormat("[SCENEPRESENCE] index {0}, new texture id {1}",i,newface.TextureID); + m_log.WarnFormat("[AVATAR APPEARANCE] index {0}, new texture id {1}",i,newface.TextureID); // DEBUG OFF } diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs index d7a7d1e..215682f 100644 --- a/OpenSim/Framework/ChildAgentDataUpdate.cs +++ b/OpenSim/Framework/ChildAgentDataUpdate.cs @@ -390,8 +390,11 @@ namespace OpenSim.Framework // The code to pack textures, visuals, wearables and attachments // should be removed; packed appearance contains the full appearance // This is retained for backward compatibility only - if ((Appearance.Texture != null) && (Appearance.Texture.Length > 0)) - args["texture_entry"] = OSD.FromBinary(Appearance.Texture); + if (Appearance.Texture != null) + { + byte[] rawtextures = Appearance.Texture.GetBytes(); + args["texture_entry"] = OSD.FromBinary(rawtextures); + } if ((Appearance.VisualParams != null) && (Appearance.VisualParams.Length > 0)) args["visual_params"] = OSD.FromBinary(Appearance.VisualParams); @@ -408,10 +411,10 @@ namespace OpenSim.Framework args["wearables"] = wears; } - List attachments = Appearance.GetAttachments(); - if ((attachments != null) && (attachments.Length > 0)) + List attachments = Appearance.GetAttachments(); + if ((attachments != null) && (attachments.Count > 0)) { - OSDArray attachs = new OSDArray(attachments.Length); + OSDArray attachs = new OSDArray(attachments.Count); foreach (AvatarAttachment att in attachments) attachs.Add(att.Pack()); args["attachments"] = attachs; @@ -560,7 +563,11 @@ namespace OpenSim.Framework // should be removed; packed appearance contains the full appearance // This is retained for backward compatibility only if (args["texture_entry"] != null) - Appearance.SetTextureEntries(args["texture_entry"].AsBinary()); + { + byte[] rawtextures = args["texture_entry"].AsBinary(); + Primitive.TextureEntry textures = new Primitive.TextureEntry(rawtextures,0,rawtextures.Length); + Appearance.SetTextureEntries(textures); + } if (args["visual_params"] != null) Appearance.SetVisualParams(args["visual_params"].AsBinary()); @@ -578,21 +585,25 @@ namespace OpenSim.Framework if ((args["attachments"] != null) && (args["attachments"]).Type == OSDType.Array) { OSDArray attachs = (OSDArray)(args["attachments"]); - AvatarAttachment[] attachments = new AvatarAttachment[attachs.Count]; - int i = 0; foreach (OSD o in attachs) { if (o.Type == OSDType.Map) { - attachments[i++] = new AvatarAttachment((OSDMap)o); + // We know all of these must end up as attachments so we + // append rather than replace to ensure multiple attachments + // per point continues to work + Appearance.AppendAttachment(new AvatarAttachment((OSDMap)o)); } } - Appearance.SetAttachments(attachments); } // end of code to remove - if (args["packed_appearance"] != null) + if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map) Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); +// DEBUG ON + else + System.Console.WriteLine("No packed appearance in AgentUpdate"); +// DEBUG OFF if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { -- cgit v1.1 From 9cfd3e1d5ac8383087fb09cf076e9ec199808fd7 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Tue, 26 Oct 2010 12:54:28 -0700 Subject: Small cleanup and add more debugging information --- OpenSim/Framework/AgentCircuitData.cs | 4 ++-- OpenSim/Framework/ChildAgentDataUpdate.cs | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AgentCircuitData.cs b/OpenSim/Framework/AgentCircuitData.cs index 098b33c..640a646 100644 --- a/OpenSim/Framework/AgentCircuitData.cs +++ b/OpenSim/Framework/AgentCircuitData.cs @@ -351,8 +351,8 @@ namespace OpenSim.Framework OSDArray wears = (OSDArray)(args["wearables"]); for (int i = 0; i < wears.Count / 2; i++) { - Appearance.Wearables[i].ItemID = wears[i*2].AsUUID(); - Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID(); + AvatarWearable awear = new AvatarWearable(wears[i*2].AsUUID(),wears[(i*2)+1].AsUUID()); + Appearance.SetWearable(i,awear); } } diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs index 215682f..66487f7 100644 --- a/OpenSim/Framework/ChildAgentDataUpdate.cs +++ b/OpenSim/Framework/ChildAgentDataUpdate.cs @@ -28,6 +28,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection; +using log4net; using OpenMetaverse; using OpenMetaverse.StructuredData; @@ -310,6 +312,12 @@ namespace OpenSim.Framework // Appearance public AvatarAppearance Appearance; +// DEBUG ON + private static readonly ILog m_log = + LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); +// DEBUG OFF + /* public byte[] AgentTextures; public byte[] VisualParams; @@ -323,6 +331,10 @@ namespace OpenSim.Framework public virtual OSDMap Pack() { +// DEBUG ON + m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Pack data"); +// DEBUG OFF + OSDMap args = new OSDMap(); args["message_type"] = OSD.FromString("AgentData"); @@ -444,6 +456,10 @@ namespace OpenSim.Framework /// public virtual void Unpack(OSDMap args) { +// DEBUG ON + m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data"); +// DEBUG OFF + if (args.ContainsKey("region_id")) UUID.TryParse(args["region_id"].AsString(), out RegionID); @@ -556,10 +572,9 @@ namespace OpenSim.Framework // AgentTextures[i++] = o.AsUUID(); //} - Appearance = new AvatarAppearance(AgentID); - // The code to pack textures, visuals, wearables and attachments + // The code to unpack textures, visuals, wearables and attachments // should be removed; packed appearance contains the full appearance // This is retained for backward compatibility only if (args["texture_entry"] != null) @@ -577,8 +592,8 @@ namespace OpenSim.Framework OSDArray wears = (OSDArray)(args["wearables"]); for (int i = 0; i < wears.Count / 2; i++) { - Appearance.Wearables[i].ItemID = wears[i*2].AsUUID(); - Appearance.Wearables[i].AssetID = wears[(i*2)+1].AsUUID(); + AvatarWearable awear = new AvatarWearable(wears[i*2].AsUUID(),wears[(i*2)+1].AsUUID()); + Appearance.SetWearable(i,awear); } } @@ -602,8 +617,8 @@ namespace OpenSim.Framework Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]); // DEBUG ON else - System.Console.WriteLine("No packed appearance in AgentUpdate"); -// DEBUG OFF + m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance"); +// DEBUG OFF if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array) { -- cgit v1.1 From 0f28fa400d1f853cc3c3ebd2707b08ed06d2f127 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Thu, 28 Oct 2010 09:00:39 -0700 Subject: Added background thread to handle delayed send and save of appearance to accommodate batching of the many updates that happen on login and teleport. Fixed handling of the serial property in appearance. --- OpenSim/Framework/AvatarAppearance.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index 05330c7..e66a1e7 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -233,7 +233,7 @@ namespace OpenSim.Framework // DEBUG ON m_log.WarnFormat("[AVATAR APPEARANCE] create empty appearance for {0}",owner); // DEBUG OFF - m_serial = 0; + m_serial = 1; m_owner = owner; SetDefaultWearables(); @@ -289,7 +289,7 @@ namespace OpenSim.Framework // DEBUG OFF if (appearance == null) { - m_serial = 0; + m_serial = 1; m_owner = UUID.Zero; SetDefaultWearables(); @@ -467,6 +467,9 @@ namespace OpenSim.Framework public override String ToString() { String s = ""; + + s += String.Format("Serial: {0}\n",m_serial); + for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) if (m_texture.FaceTextures[i] != null) s += String.Format("Texture: {0} --> {1}\n",i,m_texture.FaceTextures[i].TextureID); @@ -625,8 +628,8 @@ namespace OpenSim.Framework /// public void Unpack(OSDMap data) { - if ((data != null) && (data["appearance_serial"] != null)) - m_serial = data["appearance_serial"].AsInteger(); + if ((data != null) && (data["serial"] != null)) + m_serial = data["serial"].AsInteger(); if ((data != null) && (data["height"] != null)) m_avatarHeight = (float)data["height"].AsReal(); if ((data != null) && (data["hipoffset"] != null)) -- cgit v1.1 From 68666efd25f4d094949f31eae08ee17fd821b7e4 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Thu, 28 Oct 2010 12:00:04 -0700 Subject: Configuration of persistent baked textures and save/send delays. --- OpenSim/Framework/Capabilities/Caps.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Capabilities/Caps.cs b/OpenSim/Framework/Capabilities/Caps.cs index 6b64e12..872de9a 100644 --- a/OpenSim/Framework/Capabilities/Caps.cs +++ b/OpenSim/Framework/Capabilities/Caps.cs @@ -31,6 +31,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using log4net; +using Nini.Config; using OpenMetaverse; using OpenSim.Framework.Servers; using OpenSim.Framework.Servers.HttpServer; @@ -112,6 +113,8 @@ namespace OpenSim.Framework.Capabilities private string m_regionName; private object m_fetchLock = new Object(); + private bool m_persistBakedTextures = false; + public bool SSLCaps { get { return m_httpListener.UseSSL; } @@ -145,6 +148,15 @@ namespace OpenSim.Framework.Capabilities m_httpListenPort = httpPort; + m_persistBakedTextures = false; + IConfigSource config = m_Scene.Config; + if (config != null) + { + IConfig sconfig = config.Configs["Startup"]; + if (sconfig != null) + m_persistBakedTextures = sconfig.GetBoolean("PersistBakedTextures",m_persistBakedTextures); + } + if (httpServer != null && httpServer.UseSSL) { m_httpListenPort = httpServer.SSLPort; @@ -983,7 +995,7 @@ namespace OpenSim.Framework.Capabilities asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString()); asset.Data = data; asset.Temporary = true; - asset.Local = true; + asset.Local = ! m_persistBakedTextures; // Local assets aren't persisted, non-local are m_assetCache.Store(asset); } -- cgit v1.1