コード例 #1
0
ファイル: IAvatarService.cs プロジェクト: CassieEllen/opensim
        public AvatarAppearance ToAvatarAppearance()
        {
            AvatarAppearance appearance = new AvatarAppearance();

            if (Data.Count == 0)
                return appearance;

            appearance.ClearWearables();
            try
            {
                if (Data.ContainsKey("Serial"))
                    appearance.Serial = Int32.Parse(Data["Serial"]);

                if (Data.ContainsKey("AvatarHeight"))
                {
                    float h = float.Parse(Data["AvatarHeight"]);
                    if( h == 0f)
                        h = 1.9f;
                    appearance.SetSize(new Vector3(0.45f, 0.6f, h ));
//                    appearance.AvatarHeight = float.Parse(Data["AvatarHeight"]);
                }

                // Legacy Wearables
                if (Data.ContainsKey("BodyItem"))
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                            UUID.Parse(Data["BodyItem"]),
                            UUID.Parse(Data["BodyAsset"]));

                if (Data.ContainsKey("SkinItem"))
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                            UUID.Parse(Data["SkinItem"]),
                            UUID.Parse(Data["SkinAsset"]));

                if (Data.ContainsKey("HairItem"))
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                            UUID.Parse(Data["HairItem"]),
                            UUID.Parse(Data["HairAsset"]));

                if (Data.ContainsKey("EyesItem"))
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                            UUID.Parse(Data["EyesItem"]),
                            UUID.Parse(Data["EyesAsset"]));

                if (Data.ContainsKey("ShirtItem"))
                    appearance.Wearables[AvatarWearable.SHIRT].Wear(
                            UUID.Parse(Data["ShirtItem"]),
                            UUID.Parse(Data["ShirtAsset"]));

                if (Data.ContainsKey("PantsItem"))
                    appearance.Wearables[AvatarWearable.PANTS].Wear(
                            UUID.Parse(Data["PantsItem"]),
                            UUID.Parse(Data["PantsAsset"]));

                if (Data.ContainsKey("ShoesItem"))
                    appearance.Wearables[AvatarWearable.SHOES].Wear(
                            UUID.Parse(Data["ShoesItem"]),
                            UUID.Parse(Data["ShoesAsset"]));

                if (Data.ContainsKey("SocksItem"))
                    appearance.Wearables[AvatarWearable.SOCKS].Wear(
                            UUID.Parse(Data["SocksItem"]),
                            UUID.Parse(Data["SocksAsset"]));

                if (Data.ContainsKey("JacketItem"))
                    appearance.Wearables[AvatarWearable.JACKET].Wear(
                            UUID.Parse(Data["JacketItem"]),
                            UUID.Parse(Data["JacketAsset"]));

                if (Data.ContainsKey("GlovesItem"))
                    appearance.Wearables[AvatarWearable.GLOVES].Wear(
                            UUID.Parse(Data["GlovesItem"]),
                            UUID.Parse(Data["GlovesAsset"]));

                if (Data.ContainsKey("UnderShirtItem"))
                    appearance.Wearables[AvatarWearable.UNDERSHIRT].Wear(
                            UUID.Parse(Data["UnderShirtItem"]),
                            UUID.Parse(Data["UnderShirtAsset"]));

                if (Data.ContainsKey("UnderPantsItem"))
                    appearance.Wearables[AvatarWearable.UNDERPANTS].Wear(
                            UUID.Parse(Data["UnderPantsItem"]),
                            UUID.Parse(Data["UnderPantsAsset"]));

                if (Data.ContainsKey("SkirtItem"))
                    appearance.Wearables[AvatarWearable.SKIRT].Wear(
                            UUID.Parse(Data["SkirtItem"]),
                            UUID.Parse(Data["SkirtAsset"]));

                if (Data.ContainsKey("VisualParams"))
                {
                    string[] vps = Data["VisualParams"].Split(new char[] {','});
                    //byte[] binary = new byte[AvatarAppearance.VISUALPARAM_COUNT];

                    //for (int i = 0 ; i < vps.Length && i < binary.Length ; i++)
                    byte[] binary = new byte[vps.Length];

                    for (int i = 0; i < vps.Length; i++)
                    	binary[i] = (byte)Convert.ToInt32(vps[i]);
                    
                    appearance.VisualParams = binary;
                }

                // New style wearables
                foreach (KeyValuePair<string, string> _kvp in Data)
                {
                    if (_kvp.Key.StartsWith("Wearable "))
                    {
                        string wearIndex = _kvp.Key.Substring(9);
                        string[] wearIndices = wearIndex.Split(new char[] {':'});
                        int index = Convert.ToInt32(wearIndices[0]);

                        string[] ids = _kvp.Value.Split(new char[] {':'});
                        UUID itemID = new UUID(ids[0]);
                        UUID assetID = new UUID(ids[1]);

                        appearance.Wearables[index].Add(itemID, assetID);
                    }
                }

                // Attachments
                Dictionary<string, string> attchs = new Dictionary<string, string>();
                foreach (KeyValuePair<string, string> _kvp in Data)
                    if (_kvp.Key.StartsWith("_ap_"))
                        attchs[_kvp.Key] = _kvp.Value;

                foreach (KeyValuePair<string, string> _kvp in attchs)
                {
                    string pointStr = _kvp.Key.Substring(4);
                    int point = 0;
                    if (!Int32.TryParse(pointStr, out point))
                        continue;

                    List<string> idList = new List<string>(_kvp.Value.Split(new char[] {','}));

                    appearance.SetAttachment(point, UUID.Zero, UUID.Zero);
                    foreach (string id in idList)
                    {
                        UUID uuid = UUID.Zero;
                        UUID.TryParse(id, out uuid);

                        appearance.SetAttachment(point | 0x80, uuid, UUID.Zero);
                    }
                }

                if (appearance.Wearables[AvatarWearable.BODY].Count == 0)
                    appearance.Wearables[AvatarWearable.BODY].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.BODY][0]);

                if (appearance.Wearables[AvatarWearable.SKIN].Count == 0)
                    appearance.Wearables[AvatarWearable.SKIN].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.SKIN][0]);

                if (appearance.Wearables[AvatarWearable.HAIR].Count == 0)
                    appearance.Wearables[AvatarWearable.HAIR].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.HAIR][0]);

                if (appearance.Wearables[AvatarWearable.EYES].Count == 0)
                    appearance.Wearables[AvatarWearable.EYES].Wear(
                            AvatarWearable.DefaultWearables[
                            AvatarWearable.EYES][0]);

            }
            catch
            {
                // We really should report something here, returning null
                // will at least break the wrapper
                return null;
            }

            return appearance;
        }