2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Collections.Generic;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Imaging;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
public class DumpOutfitCommand : Command
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
List<UUID> OutfitAssets = new List<UUID>();
|
2007-07-11 09:17:46 +00:00
|
|
|
AssetManager.ImageReceivedCallback ImageReceivedHandler;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
public DumpOutfitCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "dumpoutfit";
|
|
|
|
|
Description = "Dumps all of the textures from an avatars outfit to the hard drive. Usage: dumpoutfit [avatar-uuid]";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Inventory;
|
|
|
|
|
|
2007-07-11 09:17:46 +00:00
|
|
|
ImageReceivedHandler = new AssetManager.ImageReceivedCallback(Assets_OnImageReceived);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
return "Usage: dumpoutfit [avatar-uuid]";
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
UUID target;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
if (!UUID.TryParse(args[0], out target))
|
2007-04-28 20:54:02 +00:00
|
|
|
return "Usage: dumpoutfit [avatar-uuid]";
|
|
|
|
|
|
2007-08-20 09:26:21 +00:00
|
|
|
lock (Client.Network.Simulators)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-08-20 09:26:21 +00:00
|
|
|
for (int i = 0; i < Client.Network.Simulators.Count; i++)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-08-29 08:55:53 +00:00
|
|
|
Avatar targetAv;
|
|
|
|
|
|
2008-01-03 21:55:49 +00:00
|
|
|
targetAv = Client.Network.Simulators[i].ObjectsAvatars.Find(
|
2007-08-29 08:55:53 +00:00
|
|
|
delegate(Avatar avatar)
|
|
|
|
|
{
|
|
|
|
|
return avatar.ID == target;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (targetAv != null)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-08-29 08:55:53 +00:00
|
|
|
StringBuilder output = new StringBuilder("Downloading ");
|
|
|
|
|
|
|
|
|
|
lock (OutfitAssets) OutfitAssets.Clear();
|
|
|
|
|
Client.Assets.OnImageReceived += ImageReceivedHandler;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < targetAv.Textures.FaceTextures.Length; j++)
|
2007-08-20 09:26:21 +00:00
|
|
|
{
|
2008-08-24 05:06:51 +00:00
|
|
|
Primitive.TextureEntryFace face = targetAv.Textures.FaceTextures[j];
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2007-08-29 08:55:53 +00:00
|
|
|
if (face != null)
|
|
|
|
|
{
|
|
|
|
|
ImageType type = ImageType.Normal;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2007-08-29 08:55:53 +00:00
|
|
|
switch ((AppearanceManager.TextureIndex)j)
|
2007-08-20 09:26:21 +00:00
|
|
|
{
|
2007-08-29 08:55:53 +00:00
|
|
|
case AppearanceManager.TextureIndex.HeadBaked:
|
|
|
|
|
case AppearanceManager.TextureIndex.EyesBaked:
|
|
|
|
|
case AppearanceManager.TextureIndex.UpperBaked:
|
|
|
|
|
case AppearanceManager.TextureIndex.LowerBaked:
|
|
|
|
|
case AppearanceManager.TextureIndex.SkirtBaked:
|
|
|
|
|
type = ImageType.Baked;
|
|
|
|
|
break;
|
2007-08-20 09:26:21 +00:00
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2007-08-29 08:55:53 +00:00
|
|
|
OutfitAssets.Add(face.TextureID);
|
|
|
|
|
Client.Assets.RequestImage(face.TextureID, type, 100000.0f, 0);
|
|
|
|
|
|
|
|
|
|
output.Append(((AppearanceManager.TextureIndex)j).ToString());
|
|
|
|
|
output.Append(" ");
|
2007-08-20 09:26:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-08-29 08:55:53 +00:00
|
|
|
|
|
|
|
|
return output.ToString();
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-30 13:15:31 +00:00
|
|
|
return "Couldn't find avatar " + target.ToString();
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-25 09:36:33 +00:00
|
|
|
private void Assets_OnImageReceived(ImageDownload image, AssetTexture assetTexture)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-07-11 09:17:46 +00:00
|
|
|
lock (OutfitAssets)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-07-11 09:17:46 +00:00
|
|
|
if (OutfitAssets.Contains(image.ID))
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2007-07-11 09:17:46 +00:00
|
|
|
if (image.Success)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2007-11-30 13:15:31 +00:00
|
|
|
File.WriteAllBytes(image.ID.ToString() + ".jp2", image.AssetData);
|
|
|
|
|
Console.WriteLine("Wrote JPEG2000 image " + image.ID.ToString() + ".jp2");
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-16 17:41:09 +00:00
|
|
|
ManagedImage imgData;
|
2008-07-18 10:29:16 +00:00
|
|
|
OpenJPEG.DecodeToImage(image.AssetData, out imgData);
|
|
|
|
|
byte[] tgaFile = imgData.ExportTGA();
|
2007-11-30 13:15:31 +00:00
|
|
|
File.WriteAllBytes(image.ID.ToString() + ".tga", tgaFile);
|
|
|
|
|
Console.WriteLine("Wrote TGA image " + image.ID.ToString() + ".tga");
|
2007-07-11 09:17:46 +00:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-11-30 13:15:31 +00:00
|
|
|
Console.WriteLine("Failed to download image " + image.ID.ToString());
|
2007-07-11 09:17:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutfitAssets.Remove(image.ID);
|
|
|
|
|
|
|
|
|
|
if (OutfitAssets.Count == 0)
|
2007-08-10 20:16:19 +00:00
|
|
|
Client.Assets.OnImageReceived -= ImageReceivedHandler;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|