That said, here it is for posterity:
/// Blocking method to create and upload baked textures for all of the
/// missing bakes
///
///
private bool CreateBakes()
{
bool success = true;
List
// Check each bake layer in the Textures array for missing bakes
for (int bakedIndex = 0; bakedIndex < BAKED_TEXTURE_COUNT; bakedIndex++) { AvatarTextureIndex textureIndex = 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 && !Wearables.ContainsKey(WearableType.Skirt)) continue; pendingBakes.Add((BakeType)bakedIndex); } } if (pendingBakes.Count > 0)
{
DownloadTextures(pendingBakes);
Parallel.ForEach
delegate(BakeType bakeType)
{
if (!CreateBake(bakeType))
success = false;
}
);
}
// Free up all the textures we're holding on to
for (int i = 0; i < Textures.Length; i++) { Textures[i].Texture = null; } // We just allocated and freed a ridiculous amount of memory while // baking. Signal to the GC to clean up GC.Collect(); return success; } ///
/// Blocking method to create and upload a baked texture for a single
/// bake layer
///
/// Layer to bake ///
private bool CreateBake(BakeType bakeType)
{
List
Baker oven = new Baker(bakeType);
for (int i = 0; i < textureIndices.Count; i++) { AvatarTextureIndex textureIndex = textureIndices[i]; TextureData texture = Textures[(int)textureIndex]; texture.TextureIndex = textureIndex; oven.AddTexture(texture); } int start = Environment.TickCount; oven.Bake(); Logger.DebugLog("Baking " + bakeType + " took " + (Environment.TickCount - start) + "ms"); UUID newAssetID = UUID.Zero; int retries = UPLOAD_RETRIES; while (newAssetID == UUID.Zero && retries > 0)
{
newAssetID = UploadBake(oven.BakedTexture.AssetData);
--retries;
}
Textures[(int)BakeTypeToAgentTextureIndex(bakeType)].TextureID = newAssetID;
if (newAssetID == UUID.Zero)
{
Logger.Log("Failed uploading bake " + bakeType, Helpers.LogLevel.Warning);
return false;
}
return true;
}
///
/// Blocking method to upload a baked texture
///
/// Five channel JPEG2000 texture data to upload ///
private UUID UploadBake(byte[] textureData)
{
UUID bakeID = UUID.Zero;
AutoResetEvent uploadEvent = new AutoResetEvent(false);
Client.Assets.RequestUploadBakedTexture(textureData,
delegate(UUID newAssetID)
{
bakeID = newAssetID;
uploadEvent.Set();
}
);
// FIXME: evalute the need for timeout here, RequestUploadBakedTexture() will
// timout either on Client.Settings.TRANSFER_TIMEOUT or Client.Settings.CAPS_TIMEOUT
// depending on which upload method is used.
uploadEvent.WaitOne(UPLOAD_TIMEOUT, false);
return bakeID;
}
No comments:
Post a Comment