/// <summary> /// Converts avatar texture index (face) to Bake type /// </summary> /// <param name="index">Face number (AvatarTextureIndex)</param> /// <returns>BakeType, layer to which this texture belongs to</returns> public static BakeType BakeTypeFor(AvatarTextureIndex index) { switch (index) { case AvatarTextureIndex.HeadBodypaint: return(BakeType.Head); case AvatarTextureIndex.UpperBodypaint: case AvatarTextureIndex.UpperGloves: case AvatarTextureIndex.UpperUndershirt: case AvatarTextureIndex.UpperShirt: case AvatarTextureIndex.UpperJacket: return(BakeType.UpperBody); case AvatarTextureIndex.LowerBodypaint: case AvatarTextureIndex.LowerUnderpants: case AvatarTextureIndex.LowerSocks: case AvatarTextureIndex.LowerShoes: case AvatarTextureIndex.LowerPants: case AvatarTextureIndex.LowerJacket: return(BakeType.LowerBody); case AvatarTextureIndex.EyesIris: return(BakeType.Eyes); case AvatarTextureIndex.Skirt: return(BakeType.Skirt); case AvatarTextureIndex.Hair: return(BakeType.Hair); default: return(BakeType.Unknown); } }
public override CmdResult ExecuteRequest(CmdRequest args) { ICollection PS; if (args.Length == 0) { PS = WorldObjects.SimAvatars; } else { int argsUsed; PS = WorldSystem.GetPrimitives(args.GetProperty("targets"), out argsUsed); if (IsEmpty(PS)) { return(Failure("Cannot find objects from " + args.str)); } } AppendList("list", PS); SetResult("count", PS.Count); if (args.IsFFI) { return(SuccessOrFailure()); } foreach (SimObject O in PS) { Primitive foundAv = O.Prim; StringBuilder output = new StringBuilder(); output.AppendLine(); if (foundAv.Textures == null) { output.AppendLine("No textures yet"); } else { for (int i = 0; i < foundAv.Textures.FaceTextures.Length; i++) { if (foundAv.Textures.FaceTextures[i] != null) { Primitive.TextureEntryFace face = foundAv.Textures.FaceTextures[i]; AvatarTextureIndex type = (AvatarTextureIndex)i; output.AppendFormat("{0}: {1}", type, face.TextureID); output.AppendLine(); } } } AddSuccess(output.ToString()); } return(SuccessOrFailure()); }
public override string Execute(string[] args, UUID fromAgentID) { if (args.Length != 2) { return("Usage: avatarinfo [firstname] [lastname]"); } string targetName = String.Format("{0} {1}", args[0], args[1]); Avatar foundAv = Client.Network.CurrentSim.ObjectsAvatars.Find( delegate(Avatar avatar) { return(avatar.Name == targetName); } ); if (foundAv != null) { StringBuilder output = new StringBuilder(); output.AppendFormat("{0} ({1})", targetName, foundAv.ID); output.AppendLine(); for (int i = 0; i < foundAv.Textures.FaceTextures.Length; i++) { if (foundAv.Textures.FaceTextures[i] != null) { Primitive.TextureEntryFace face = foundAv.Textures.FaceTextures[i]; AvatarTextureIndex type = (AvatarTextureIndex)i; output.AppendFormat("{0}: {1}", type, face.TextureID); output.AppendLine(); } } return(output.ToString()); } else { return("No nearby avatar with the name " + targetName); } }
void Objects_OnNewAvatar(object sender, AvatarUpdateEventArgs e) { Avatar avatar = e.Avatar; if (enabled) { // Search this avatar for textures for (int i = 0; i < avatar.Textures.FaceTextures.Length; i++) { Primitive.TextureEntryFace face = avatar.Textures.FaceTextures[i]; if (face != null) { if (!alreadyRequested.ContainsKey(face.TextureID)) { alreadyRequested[face.TextureID] = face.TextureID; // Determine if this is a baked outfit texture or a normal texture ImageType type = ImageType.Normal; AvatarTextureIndex index = (AvatarTextureIndex)i; switch (index) { case AvatarTextureIndex.EyesBaked: case AvatarTextureIndex.HeadBaked: case AvatarTextureIndex.LowerBaked: case AvatarTextureIndex.SkirtBaked: case AvatarTextureIndex.UpperBaked: type = ImageType.Baked; break; } Client.Assets.RequestImage(face.TextureID, type, Assets_OnImageReceived); } } } } }
/// <summary> /// Helper method to lookup the TextureID for a single layer and add it /// to a list if it is not already present /// </summary> /// <param name="index"></param> /// <param name="textures"></param> private void AddTextureDownload(AvatarTextureIndex index, List<UUID> textures) { TextureData textureData = Textures[(int)index]; // Add the textureID to the list if this layer has a valid textureID set, it has not already // been downloaded, and it is not already in the download list if (textureData.TextureID != UUID.Zero && textureData.Texture == null && !textures.Contains(textureData.TextureID)) textures.Add(textureData.TextureID); }
/// <summary> /// Converts avatar texture index (face) to Bake type /// </summary> /// <param name="index">Face number (AvatarTextureIndex)</param> /// <returns>BakeType, layer to which this texture belongs to</returns> public static BakeType BakeTypeFor(AvatarTextureIndex index) { switch (index) { case AvatarTextureIndex.HeadBodypaint: return BakeType.Head; case AvatarTextureIndex.UpperBodypaint: case AvatarTextureIndex.UpperGloves: case AvatarTextureIndex.UpperUndershirt: case AvatarTextureIndex.UpperShirt: case AvatarTextureIndex.UpperJacket: return BakeType.UpperBody; case AvatarTextureIndex.LowerBodypaint: case AvatarTextureIndex.LowerUnderpants: case AvatarTextureIndex.LowerSocks: case AvatarTextureIndex.LowerShoes: case AvatarTextureIndex.LowerPants: case AvatarTextureIndex.LowerJacket: return BakeType.LowerBody; case AvatarTextureIndex.EyesIris: return BakeType.Eyes; case AvatarTextureIndex.Skirt: return BakeType.Skirt; case AvatarTextureIndex.Hair: return BakeType.Hair; default: return BakeType.Unknown; } }
// List<UUID> m_lastInventoryItemIDs = new List<UUID>(); public AvatarAppearance BakeAppearance(UUID agentID, int cof_version) { AvatarAppearance appearance = m_avatarService.GetAppearance(agentID); if (appearance == null) { MainConsole.Instance.Error("[ServerSide appearance]: Unable to retrieve avatar appearance for bake!"); return(new AvatarAppearance()); } List <BakeType> pendingBakes = new List <BakeType> (); InventoryFolderBase cof = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit); if (cof.Version < cof_version) { int i = 0; while (i < 10) { cof = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit); System.Threading.Thread.Sleep(100); if (cof.Version >= cof_version) { break; } i++; } } List <InventoryItemBase> items = m_inventoryService.GetFolderItems(agentID, cof.ID); foreach (InventoryItemBase itm in items) { MainConsole.Instance.Info("[ServerSide appearance]: Baking " + itm.Name); } for (int i = 0; i < Textures.Length; i++) { Textures [i] = new TextureData(); } WearableData alphaWearable = null; List <UUID> currentItemIDs = new List <UUID> (); foreach (InventoryItemBase itm in items) { if (itm.AssetType == (int)AssetType.Link) { UUID assetID = m_inventoryService.GetItemAssetID(agentID, itm.AssetID); if (appearance.Wearables.Any((w) => w.GetItem(assetID) != UUID.Zero)) { currentItemIDs.Add(assetID); //if (m_lastInventoryItemIDs.Contains(assetID)) // continue; WearableData wearable = new WearableData(); AssetBase asset = m_assetService.Get(assetID.ToString()); if (asset != null && asset.TypeAsset != AssetType.Object) { var assetData = new byte [asset.Data.Length]; asset.Data.CopyTo(assetData, 0); asset.Dispose(); wearable.Asset = new AssetClothing(assetID, assetData); if (wearable.Asset.Decode()) { wearable.AssetID = assetID; wearable.AssetType = wearable.Asset.AssetType; wearable.WearableType = wearable.Asset.WearableType; wearable.ItemID = itm.AssetID; if (wearable.WearableType == WearableType.Alpha) { alphaWearable = wearable; continue; } AppearanceManager.DecodeWearableParams(wearable, ref Textures); } } if (asset != null) // have asset but not an object { asset.Dispose(); } } } } /*foreach (UUID id in m_lastInventoryItemIDs) * { * if (!currentItemIDs.Contains(id)) * { * OpenMetaverse.AppearanceManager.WearableData wearable = new OpenMetaverse.AppearanceManager.WearableData(); * AssetBase asset = m_assetService.Get(id.ToString()); * if (asset != null && asset.TypeAsset != AssetType.Object) * { * wearable.Asset = new AssetClothing(id, asset.Data); * if (wearable.Asset.Decode()) * { * foreach (KeyValuePair<AvatarTextureIndex, UUID> entry in wearable.Asset.Textures) * { * int i = (int)entry.Key; * * Textures[i].Texture = null; * Textures[i].TextureID = UUID.Zero; * } * } * } * } * }*/ //m_lastInventoryItemIDs = currentItemIDs; for (int i = 0; i < Textures.Length; i++) { /*if (Textures[i].TextureID == UUID.Zero) * continue; * if (Textures[i].Texture != null) * continue;*/ AssetBase asset = m_assetService.Get(Textures [i].TextureID.ToString()); if (asset != null) { var assetData = new byte [asset.Data.Length]; asset.Data.CopyTo(assetData, 0); asset.Dispose(); Textures [i].Texture = new AssetTexture(Textures [i].TextureID, assetData); Textures [i].Texture.Decode(); } } for (int bakedIndex = 0; bakedIndex < AppearanceManager.BAKED_TEXTURE_COUNT; bakedIndex++) { AvatarTextureIndex textureIndex = AppearanceManager.BakeTypeToAgentTextureIndex((BakeType)bakedIndex); if (Textures [(int)textureIndex].TextureID == UUID.Zero) { // If this is the skirt layer and we're not wearing a skirt then skip it if (bakedIndex == (int)BakeType.Skirt && appearance.Wearables [(int)WearableType.Skirt].Count == 0) { continue; } pendingBakes.Add((BakeType)bakedIndex); } } int start = Environment.TickCount; List <UUID> newBakeIDs = new List <UUID> (); foreach (BakeType bakeType in pendingBakes) { UUID assetID = UUID.Zero; List <AvatarTextureIndex> textureIndices = AppearanceManager.BakeTypeToTextures(bakeType); Baker oven = new Baker(bakeType); for (int i = 0; i < textureIndices.Count; i++) { int textureIndex = (int)textureIndices [i]; TextureData texture = Textures [textureIndex]; texture.TextureIndex = (AvatarTextureIndex)textureIndex; if (alphaWearable != null) { if (alphaWearable.Asset.Textures.ContainsKey(texture.TextureIndex) && alphaWearable.Asset.Textures [texture.TextureIndex] != UUID.Parse("5748decc-f629-461c-9a36-a35a221fe21f")) { assetID = alphaWearable.Asset.Textures [texture.TextureIndex]; goto bake_complete; } } oven.AddTexture(texture); } oven.Bake(); byte [] assetData = oven.BakedTexture.AssetData; AssetBase newBakedAsset = new AssetBase(UUID.Random()); newBakedAsset.Data = assetData; newBakedAsset.TypeAsset = AssetType.Texture; newBakedAsset.Name = "ServerSideAppearance Texture"; newBakedAsset.Flags = AssetFlags.Deletable | AssetFlags.Collectable | AssetFlags.Rewritable | AssetFlags.Temporary; var faceTextureID = appearance.Texture.FaceTextures [(int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType)].TextureID; if (faceTextureID != UUID.Zero) { try { m_assetService.Delete(faceTextureID); } catch { MainConsole.Instance.ErrorFormat("[Serverside apperance]: Unable to delete asset {0} during bake", faceTextureID); } } assetID = m_assetService.Store(newBakedAsset); bake_complete: newBakeIDs.Add(assetID); MainConsole.Instance.WarnFormat("[ServerSide appearance]: Baked {0}", assetID); int place = (int)AppearanceManager.BakeTypeToAgentTextureIndex(bakeType); appearance.Texture.FaceTextures [place].TextureID = assetID; } MainConsole.Instance.ErrorFormat("[ServerSide appearance]: Baking took {0} ms", (Environment.TickCount - start)); appearance.Serial = cof_version + 1; cof = m_inventoryService.GetFolderForType(agentID, InventoryType.Unknown, FolderType.CurrentOutfit); if (cof.Version > cof_version) { //it changed during the baking... kill it with fire! return(null); } m_avatarService.SetAppearance(agentID, appearance); return(appearance); }
/// <summary> /// //settexture 5 8dcd4a48-2d37-4909-9f78-f7a9eb4ef903 /// </summary> /// <param name="args"></param> /// <param name="fromAgentID"></param> /// <param name="WriteLine"></param> /// <returns></returns> public override CmdResult ExecuteRequest(CmdRequest args) { UUID asset = UUID.Zero; AvatarTextureIndex index = AvatarTextureIndex.Unknown; if (args.Length > 1) { Object val; int argsUsed; if (TryEnumParse(typeof(AvatarTextureIndex), args, 0, out argsUsed, out val)) { index = (AvatarTextureIndex)val; } string targetName = args[argsUsed]; if (!UUID.TryParse(targetName, out asset)) { asset = WorldSystem.SimAssetSystem.GetAssetUUID(targetName, AssetType.Texture); } } // Get our current appearance UUID target = Client.Self.AgentID; #if COGBOT_LIBOMV AgentSetAppearancePacket set = Client.Appearance.MakeAppearancePacket(); Primitive.TextureEntry te; if (!Client.Appearances.ContainsKey(target)) { te = new Primitive.TextureEntry(set.ObjectData.TextureEntry, 0, set.ObjectData.TextureEntry.Length); } else { #region AvatarAppearance to AgentSetAppearance AvatarAppearancePacket appearance = TheBotClient.Appearances[target]; set.AgentData.AgentID = Client.Self.AgentID; set.AgentData.SessionID = Client.Self.SessionID; set.AgentData.SerialNum = SerialNum++; set.AgentData.Size = new Vector3(2f, 2f, 2f); // HACK set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[0]; set.VisualParam = new AgentSetAppearancePacket.VisualParamBlock[appearance.VisualParam.Length]; for (int i = 0; i < appearance.VisualParam.Length; i++) { set.VisualParam[i] = new AgentSetAppearancePacket.VisualParamBlock(); set.VisualParam[i].ParamValue = appearance.VisualParam[i].ParamValue; } set.ObjectData.TextureEntry = appearance.ObjectData.TextureEntry; te = new Primitive.TextureEntry(appearance.ObjectData.TextureEntry, 0, appearance.ObjectData.TextureEntry.Length); #endregion AvatarAppearance to AgentSetAppearance } #region TextureEntry if (index != AvatarTextureIndex.Unknown) { Primitive.TextureEntryFace face = te.CreateFace((uint)index); face.TextureID = asset; } set.ObjectData.TextureEntry = te.GetBytes(); #endregion TextureEntry // Send the new appearance packet Client.Network.SendPacket(set); #endif return(Success("Setting texture entry for " + (AvatarTextureIndex)index + " to " + asset)); }
/// <summary> /// Decode an assets byte encoded data to a string /// </summary> /// <returns>true if the asset data was decoded successfully</returns> public override bool Decode() { if (AssetData == null || AssetData.Length == 0) { return(false); } int version = -1; Permissions = new Permissions(); try { string data = Utils.BytesToString(AssetData); data = data.Replace("\r", String.Empty); string[] lines = data.Split('\n'); for (int stri = 0; stri < lines.Length; stri++) { if (stri == 0) { string versionstring = lines[stri]; if (versionstring.Split(' ').Length == 1) { version = Int32.Parse(versionstring); } else { version = Int32.Parse(versionstring.Split(' ')[2]); } if (version != 22 && version != 18 && version != 16 && version != 15) { return(false); } } else if (stri == 1) { Name = lines[stri]; } else if (stri == 2) { Description = lines[stri]; } else { string line = lines[stri].Trim(); string[] fields = line.Split('\t'); if (fields.Length == 1) { fields = line.Split(' '); if (fields[0] == "parameters") { int count = Int32.Parse(fields[1]) + stri; for (; stri < count;) { stri++; line = lines[stri].Trim(); fields = line.Split(' '); int id = 0; // Special handling for -0 edge case if (fields[0] != "-0") { id = Int32.Parse(fields[0]); } if (fields[1] == ",") { fields[1] = "0"; } else { fields[1] = fields[1].Replace(',', '.'); } float weight = float.Parse(fields[1], System.Globalization.NumberStyles.Float, Utils.EnUsCulture.NumberFormat); Params[id] = weight; } } else if (fields[0] == "textures") { int count = Int32.Parse(fields[1]) + stri; for (; stri < count;) { stri++; line = lines[stri].Trim(); fields = line.Split(' '); AvatarTextureIndex id = (AvatarTextureIndex)Int32.Parse(fields[0]); UUID texture = new UUID(fields[1]); Textures[id] = texture; } } else if (fields[0] == "type") { WearableType = (WearableType)Int32.Parse(fields[1]); } } else if (fields.Length == 2) { switch (fields[0]) { case "creator_mask": // Deprecated, apply this as the base mask Permissions.BaseMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "base_mask": Permissions.BaseMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "owner_mask": Permissions.OwnerMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "group_mask": Permissions.GroupMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "everyone_mask": Permissions.EveryoneMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "next_owner_mask": Permissions.NextOwnerMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; case "creator_id": Creator = new UUID(fields[1]); break; case "owner_id": Owner = new UUID(fields[1]); break; case "last_owner_id": LastOwner = new UUID(fields[1]); break; case "group_id": Group = new UUID(fields[1]); break; case "group_owned": GroupOwned = (Int32.Parse(fields[1]) != 0); break; case "sale_type": ForSale = Utils.StringToSaleType(fields[1]); break; case "sale_price": SalePrice = Int32.Parse(fields[1]); break; case "sale_info": // Container for sale_type and sale_price, ignore break; case "perm_mask": // Deprecated, apply this as the next owner mask Permissions.NextOwnerMask = (PermissionMask)UInt32.Parse(fields[1], System.Globalization.NumberStyles.HexNumber); break; default: return(false); } } } } } catch (Exception ex) { Logger.Log("Failed decoding wearable asset " + this.AssetID + ": " + ex.Message, Helpers.LogLevel.Warning); return(false); } return(true); }