Пример #1
0
        /// <summary>
        /// Unpack and OSDMap and initialize the appearance
        /// from it
        /// </summary>
        public void Unpack(OSDMap data)
        {
            if ((data != null) && (data["serial"] != null))
                m_serial = data["serial"].AsInteger();
            if ((data != null) && (data["height"] != null))
//                m_avatarHeight = (float)data["height"].AsReal();
                SetSize(new Vector3(0.45f,0.6f, (float)data["height"].AsReal()));

            try
            {
                // Wearables
                SetDefaultWearables();
                if ((data != null) && (data["wearables"] != null) && (data["wearables"]).Type == OSDType.Array)
                {
                    OSDArray wears = (OSDArray)(data["wearables"]);

                    int count = wears.Count;

                    m_wearables = new AvatarWearable[count];

                    for (int i = 0; i < count; i++)
                        m_wearables[i] = new AvatarWearable((OSDArray)wears[i]);
                }
                else
                {
                    m_log.Warn("[AVATAR APPEARANCE]: failed to unpack wearables");
                }

                // 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++)
                    {
                        UUID textureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE;
                        if (textures[i] != null)
                            textureID = textures[i].AsUUID();
                        m_texture.CreateFace((uint)i).TextureID = new UUID(textureID);
                    }
                }
                else
                {
                    m_log.Warn("[AVATAR APPEARANCE]: failed to unpack textures");
                }

                if ((data != null) && (data["bakedcache"] != null) && (data["bakedcache"]).Type == OSDType.Array)
                {
                    OSDArray bakedOSDArray = (OSDArray)(data["bakedcache"]);
                    m_cacheitems = WearableCacheItem.BakedFromOSD(bakedOSDArray);
                }

                // 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("[AVATAR APPEARANCE]: failed to unpack visual parameters");
                }

                // Attachments
                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 att = new AvatarAttachment((OSDMap)attachs[i]);
                        AppendAttachment(att);
                        
//                        m_log.DebugFormat(
//                            "[AVATAR APPEARANCE]: Unpacked attachment itemID {0}, assetID {1}, point {2}",
//                            att.ItemID, att.AssetID, att.AttachPoint);
                    }
                }
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[AVATAR APPEARANCE]: unpack failed badly: {0}{1}", e.Message, e.StackTrace);
            }
        }
Пример #2
0
        public AvatarAppearance(AvatarAppearance appearance, bool copyWearables, bool copyBaked)
        {
//            m_log.WarnFormat("[AVATAR APPEARANCE] create from an existing appearance");

            if (appearance == null)
            {
                m_serial = 0;
                SetDefaultWearables();
                SetDefaultTexture();
                SetDefaultParams();
//                SetHeight();
                SetSize(new Vector3(0.45f, 0.6f, 1.9f));
                m_attachments = new Dictionary<int, List<AvatarAttachment>>();

                return;
            }

            m_serial = appearance.Serial;

            if (copyWearables && (appearance.Wearables != null))
            {
                m_wearables = new AvatarWearable[appearance.Wearables.Length];
                for (int i = 0; i < appearance.Wearables.Length; i++)
                {
                    m_wearables[i] = new AvatarWearable();
                    AvatarWearable wearable = appearance.Wearables[i];
                    for (int j = 0; j < wearable.Count; j++)
                            m_wearables[i].Add(wearable[j].ItemID, wearable[j].AssetID);                       
                 }
            }
            else
                ClearWearables();

            m_texture = null;
            if (appearance.Texture != null)
            {
                byte[] tbytes = appearance.Texture.GetBytes();
                m_texture = new Primitive.TextureEntry(tbytes,0,tbytes.Length);
                if (copyBaked && appearance.m_cacheitems != null)
                    m_cacheitems = (WearableCacheItem[])appearance.m_cacheitems.Clone();
                else
                    m_cacheitems = null;
            }

            m_visualparams = null;
            if (appearance.VisualParams != null)
                m_visualparams = (byte[])appearance.VisualParams.Clone();

//            m_avatarHeight = appearance.m_avatarHeight;
            SetSize(appearance.AvatarSize);

            // 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));
        }