本文整理汇总了C#中IAssetService.GetCached方法的典型用法代码示例。如果您正苦于以下问题:C# IAssetService.GetCached方法的具体用法?C# IAssetService.GetCached怎么用?C# IAssetService.GetCached使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAssetService
的用法示例。
在下文中一共展示了IAssetService.GetCached方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Splat
/// <summary>
/// Builds a composited terrain texture given the region texture
/// and heightmap settings
/// </summary>
/// <param name="heightmap">Terrain heightmap</param>
/// <param name="regionInfo">Region information including terrain texture parameters</param>
/// <returns>A composited 256x256 RGB texture ready for rendering</returns>
/// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting
/// </remarks>
public static Bitmap Splat(float[] heightmap, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain)
{
Debug.Assert(heightmap.Length == 256 * 256);
Debug.Assert(textureIDs.Length == 4);
Debug.Assert(startHeights.Length == 4);
Debug.Assert(heightRanges.Length == 4);
Bitmap[] detailTexture = new Bitmap[4];
if (textureTerrain)
{
// Swap empty terrain textureIDs with default IDs
for (int i = 0; i < textureIDs.Length; i++)
{
if (textureIDs[i] == UUID.Zero)
textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
}
#region Texture Fetching
if (assetService != null)
{
for (int i = 0; i < 4; i++)
{
AssetBase asset;
UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
// Try to fetch a cached copy of the decoded/resized version of this texture
asset = assetService.GetCached(cacheID.ToString());
if (asset != null)
{
try
{
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
detailTexture[i] = (Bitmap)Image.FromStream(stream);
}
catch (Exception ex)
{
m_log.Warn("Failed to decode cached terrain texture " + cacheID +
" (textureID: " + textureIDs[i] + "): " + ex.Message);
}
}
if (detailTexture[i] == null)
{
// Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
asset = assetService.Get(textureIDs[i].ToString());
if (asset != null)
{
try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
catch (Exception ex)
{
m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
}
}
if (detailTexture[i] != null)
{
Bitmap bitmap = detailTexture[i];
// Make sure this texture is the correct size, otherwise resize
if (bitmap.Width != 256 || bitmap.Height != 256)
bitmap = ImageUtils.ResizeImage(bitmap, 256, 256);
// Save the decoded and resized texture to the cache
byte[] data;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
{
bitmap.Save(stream, ImageFormat.Png);
data = stream.ToArray();
}
// Cache a PNG copy of this terrain texture
AssetBase newAsset = new AssetBase
{
Data = data,
Description = "PNG",
Flags = AssetFlags.Collectable,
FullID = cacheID,
ID = cacheID.ToString(),
Local = true,
Name = String.Empty,
Temporary = true,
Type = (sbyte)AssetType.Unknown
};
newAsset.Metadata.ContentType = "image/png";
assetService.Store(newAsset);
}
}
}
}
//.........这里部分代码省略.........