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.
viewer-2-initial-appearance
Master ScienceSim 2010-10-21 16:48:58 -07:00
parent b1c8d05888
commit 267f18925d
6 changed files with 100 additions and 111 deletions

View File

@ -1614,12 +1614,12 @@ namespace OpenSim.ApplicationPlugins.RemoteController
}
// Attachments
Dictionary<int, AvatarAttachment> attachments = avatarAppearance.Attachments;
List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();
foreach (KeyValuePair<int, AvatarAttachment> attachment in attachments)
foreach (AvatarAttachment attachment in attachments)
{
int attachpoint = attachment.Value.AttachPoint;
UUID itemID = attachment.Value.ItemID;
int attachpoint = attachment.AttachPoint;
UUID itemID = attachment.ItemID;
if (itemID != UUID.Zero)
{

View File

@ -27,6 +27,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using OpenMetaverse;
using OpenSim.Framework;
@ -765,25 +766,19 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory
FormatPart(rdata, "UnderShirt", rdata.userAppearance.UnderShirtItem, rdata.userAppearance.UnderShirtAsset);
FormatPart(rdata, "UnderPants", rdata.userAppearance.UnderPantsItem, rdata.userAppearance.UnderPantsAsset);
Hashtable attachments = rdata.userAppearance.GetAttachments();
Rest.Log.DebugFormat("{0} FormatUserAppearance: Formatting attachments", MsgId);
if (attachments != null)
rdata.writer.WriteStartElement("Attachments");
List<AvatarAttachment> attachments = rdata.userAppearance.GetAttachments();
foreach (AvatarAttachment attach in attachments)
{
Rest.Log.DebugFormat("{0} FormatUserAppearance: Formatting attachments", MsgId);
rdata.writer.WriteStartElement("Attachments");
for (int i = 0; i < attachments.Count; i++)
{
Hashtable attachment = attachments[i] as Hashtable;
rdata.writer.WriteStartElement("Attachment");
rdata.writer.WriteAttributeString("AtPoint", i.ToString());
rdata.writer.WriteAttributeString("Item", (string) attachment["item"]);
rdata.writer.WriteAttributeString("Asset", (string) attachment["asset"]);
rdata.writer.WriteEndElement();
}
rdata.writer.WriteStartElement("Attachment");
rdata.writer.WriteAttributeString("AtPoint", attach.AttachPoint.ToString());
rdata.writer.WriteAttributeString("Item", attach.ItemID.ToString());
rdata.writer.WriteAttributeString("Asset", attach.AssetID.ToString());
rdata.writer.WriteEndElement();
}
rdata.writer.WriteEndElement();
Primitive.TextureEntry texture = rdata.userAppearance.Texture;

View File

@ -51,7 +51,7 @@ namespace OpenSim.Framework
protected byte[] m_visualparams;
protected Primitive.TextureEntry m_texture;
protected AvatarWearable[] m_wearables;
protected Dictionary<int, AvatarAttachment> m_attachments;
protected Dictionary<int, List<AvatarAttachment>> 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<int, AvatarAttachment> 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<int, AvatarAttachment>();
m_attachments = new Dictionary<int, List<AvatarAttachment>>();
}
public AvatarAppearance(UUID avatarID, OSDMap map)
@ -284,7 +279,7 @@ namespace OpenSim.Framework
SetHeight();
m_attachments = new Dictionary<int, AvatarAttachment>();
m_attachments = new Dictionary<int, List<AvatarAttachment>>();
}
public AvatarAppearance(AvatarAppearance appearance)
@ -302,7 +297,7 @@ namespace OpenSim.Framework
SetDefaultParams();
SetHeight();
m_attachments = new Dictionary<int, AvatarAttachment>();
m_attachments = new Dictionary<int, List<AvatarAttachment>>();
return;
}
@ -329,9 +324,10 @@ namespace OpenSim.Framework
if (appearance.VisualParams != null)
m_visualparams = (byte[])appearance.VisualParams.Clone();
m_attachments = new Dictionary<int, AvatarAttachment>();
foreach (KeyValuePair<int, AvatarAttachment> 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<int, List<AvatarAttachment>>();
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)
/// <summary>
/// Get a list of the attachments, note that there may be
/// duplicate attachpoints
/// </summary>
public List<AvatarAttachment> GetAttachments()
{
foreach (AvatarAttachment attach in data)
m_attachments[attach.AttachPoint] = new AvatarAttachment(attach);
List<AvatarAttachment> alist = new List<AvatarAttachment>();
foreach (KeyValuePair<int, List<AvatarAttachment>> kvp in m_attachments)
{
foreach (AvatarAttachment attach in kvp.Value)
alist.Add(new AvatarAttachment(attach));
}
return alist;
}
internal void AppendAttachment(AvatarAttachment attach)
{
if (! m_attachments.ContainsKey(attach.AttachPoint))
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
}
internal void ReplaceAttachment(AvatarAttachment attach)
{
m_attachments[attach.AttachPoint] = new List<AvatarAttachment>();
m_attachments[attach.AttachPoint].Add(attach);
}
/// <summary>
/// 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
/// </summary>
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<int, AvatarAttachment> 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<int> GetAttachedPoints()
{
return new List<int>(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<int, AvatarAttachment> kvp in m_attachments)
foreach (KeyValuePair<int, List<AvatarAttachment>> 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<int, List<AvatarAttachment>> 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<int, AvatarAttachment> 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<int, AvatarAttachment>();
m_attachments = new Dictionary<int, List<AvatarAttachment>>();
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)

View File

@ -3657,15 +3657,16 @@ namespace OpenSim.Region.Framework.Scenes
return;
}
List<int> attPoints = m_appearance.GetAttachedPoints();
foreach (int p in attPoints)
List<AvatarAttachment> attachments = m_appearance.GetAttachments();
foreach (AvatarAttachment attach in attachments)
{
if (m_isDeleted)
return;
UUID itemID = m_appearance.GetAttachedItem(p);
int p = attach.AttachPoint;
UUID itemID = attach.ItemID;
//UUID assetID = m_appearance.GetAttachedAsset(p);
//UUID assetID = attach.AssetID;
// For some reason assetIDs are being written as Zero's in the DB -- need to track tat down
// But they're not used anyway, the item is being looked up for now, so let's proceed.
//if (UUID.Zero == assetID)

View File

@ -29,6 +29,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Security;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Interfaces;
@ -81,16 +82,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
get {
List<IAvatarAttachment> attachments = new List<IAvatarAttachment>();
Hashtable internalAttachments = GetSP().Appearance.GetAttachments();
if (internalAttachments != null)
List<AvatarAttachment> internalAttachments = GetSP().Appearance.GetAttachments();
foreach (AvatarAttachment attach in internalAttachments)
{
foreach (DictionaryEntry element in internalAttachments)
{
Hashtable attachInfo = (Hashtable)element.Value;
attachments.Add(new SPAvatarAttachment(m_rootScene, this, (int) element.Key,
new UUID((string) attachInfo["item"]),
new UUID((string) attachInfo["asset"]), m_security));
}
attachments.Add(new SPAvatarAttachment(m_rootScene, this, attach.AttachPoint,
new UUID(attach.ItemID),
new UUID(attach.AssetID), m_security));
}
return attachments.ToArray();

View File

@ -178,17 +178,11 @@ namespace OpenSim.Services.Interfaces
Data["UnderShirtAsset"] = appearance.UnderShirtAsset.ToString();
// Attachments
Hashtable attachs = appearance.GetAttachments();
if (attachs != null)
foreach (DictionaryEntry dentry in attachs)
{
if (dentry.Value != null)
{
Hashtable tab = (Hashtable)dentry.Value;
if (tab.ContainsKey("item") && tab["item"] != null)
Data["_ap_" + dentry.Key] = tab["item"].ToString();
}
}
List<AvatarAttachment> attachments = appearance.GetAttachments();
foreach (AvatarAttachment attach in attachments)
{
Data["_ap_" + attach.AttachPoint] = attach.ItemID.ToString();
}
}
public AvatarAppearance ToAvatarAppearance(UUID owner)