public IEnumerator GetProductTexture(string sku, TextureDownloadCallback callback) { Debug.Log("Icons GetProductTexture"); bool toEnd = false; yield return(null); foreach (Category cat in catList) { foreach (CategoryProduct cp in cat.Products) { if (cp.sku == sku) { Texture2D ta = Resources.Load("ProductIcons/" + cat.name + "/" + cp.sku, typeof(Texture2D)) as Texture2D; callback(ta); toEnd = true; break; } } if (toEnd) { break; } } }
public IEnumerator GetCategoryTexture(long categoryId, TextureDownloadCallback callback) { WWW cases = new WWW(baseUrl + "/magento/categories/" + categoryId + "/icon"); yield return(cases); callback(cases.texture); }
public IEnumerator GetProductTexture(string sku, TextureDownloadCallback callback) { WWW cases = new WWW(baseUrl + "/product-img/" + EncodeUriComponent(sku)); yield return(cases); callback(cases.texture); }
public void DownloadTexture(UUID textureID) { //return; if (!textures.ContainsKey(textureID) && !bitmaps.ContainsKey(textureID)) { if (Client.Assets.Cache.HasAsset(textureID)) { //Debug.Log("Cache hits!"); byte[] jpg = Client.Assets.Cache.GetCachedAssetBytes(textureID); Bitmap img = Jpgbytes2Bitmap(jpg); if (img == null) { return; } bitmaps[textureID] = img; //fixme: there may be access violation } else { TextureDownloadCallback handler = (state, asset) => { //Debug.Log("state is " + state.ToString()); try{ switch (state) { case TextureRequestState.Finished: { Bitmap img = Jpgbytes2Bitmap(asset.AssetData); if (img == null) { return; } bitmaps[textureID] = img; //fixme: there may be access violation break; } case TextureRequestState.Aborted: case TextureRequestState.NotFound: case TextureRequestState.Timeout: break; } } catch (Exception ex) { Debug.Log("what happened?:" + ex.Message); } }; Client.Assets.RequestImage(textureID, ImageType.Normal, handler); } } }
public IEnumerator GetCategoryTexture(long categoryId, TextureDownloadCallback callback) { Debug.Log("Icons GetCategoryTexture"); yield return(null); foreach (Category cat in catList) { if (cat.id == categoryId) { Texture2D ta = Resources.Load("ProductIcons/" + cat.name, typeof(Texture2D)) as Texture2D; callback(ta); break; } } }
/// <summary> /// Overload: Request a texture asset from the simulator using the <see cref="TexturePipeline"/> system to /// manage the requests and re-assemble the image from the packets received from the simulator /// </summary> /// <param name="textureID">The <see cref="UUID"/> of the texture asset to download</param> /// <param name="imageType">The <see cref="ImageType"/> of the texture asset. /// Use <see cref="ImageType.Normal"/> for most textures, or <see cref="ImageType.Baked"/> for baked layer texture assets</param> /// <param name="callback">The <see cref="TextureDownloadCallback"/> callback to fire when the image is retrieved. The callback /// will contain the result of the request and the texture asset data</param> public void RequestImage(UUID textureID, ImageType imageType, TextureDownloadCallback callback) { RequestImage(textureID, imageType, 101300.0f, 0, 0, callback, false); }
/// <summary> /// Fetach avatar texture on a grid capable of server side baking /// </summary> /// <param name="avatarID">ID of the avatar</param> /// <param name="textureID">ID of the texture</param> /// <param name="bakeName">Name of the part of the avatar texture applies to</param> /// <param name="callback">Callback invoked on operation completion</param> public void RequestServerBakedImage(UUID avatarID, UUID textureID, string bakeName, TextureDownloadCallback callback) { if (avatarID == UUID.Zero || textureID == UUID.Zero || callback == null) return; if (string.IsNullOrEmpty(Client.Network.AgentAppearanceServiceURL)) { callback(TextureRequestState.NotFound, null); return; } byte[] assetData; // Do we have this image in the cache? if (Client.Assets.Cache.HasAsset(textureID) && (assetData = Client.Assets.Cache.GetCachedAssetBytes(textureID)) != null) { ImageDownload image = new ImageDownload(); image.ID = textureID; image.AssetData = assetData; image.Size = image.AssetData.Length; image.Transferred = image.AssetData.Length; image.ImageType = ImageType.ServerBaked; image.AssetType = AssetType.Texture; image.Success = true; callback(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)); FireImageProgressEvent(image.ID, image.Transferred, image.Size); return; } CapsBase.DownloadProgressEventHandler progressHandler = null; Uri url = new Uri(string.Format("{0}texture/{1}/{2}/{3}", Client.Network.AgentAppearanceServiceURL, avatarID, bakeName, textureID)); DownloadRequest req = new DownloadRequest( url, Client.Settings.CAPS_TIMEOUT, "image/x-j2c", progressHandler, (HttpWebRequest request, HttpWebResponse response, byte[] responseData, Exception error) => { if (error == null && responseData != null) // success { ImageDownload image = new ImageDownload(); image.ID = textureID; image.AssetData = responseData; image.Size = image.AssetData.Length; image.Transferred = image.AssetData.Length; image.ImageType = ImageType.ServerBaked; image.AssetType = AssetType.Texture; image.Success = true; callback(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)); Client.Assets.Cache.SaveAssetToCache(textureID, responseData); } else // download failed { Logger.Log( string.Format("Failed to fetch server bake {0}: {1}", textureID, (error == null) ? "" : error.Message ), Helpers.LogLevel.Warning, Client); callback(TextureRequestState.Timeout, null); } } ); HttpDownloads.QueueDownload(req); }
/// <summary> /// Request a texture asset from the simulator using the <see cref="TexturePipeline"/> system to /// manage the requests and re-assemble the image from the packets received from the simulator /// </summary> /// <param name="textureID">The <see cref="UUID"/> of the texture asset to download</param> /// <param name="imageType">The <see cref="ImageType"/> of the texture asset. /// Use <see cref="ImageType.Normal"/> for most textures, or <see cref="ImageType.Baked"/> for baked layer texture assets</param> /// <param name="priority">A float indicating the requested priority for the transfer. Higher priority values tell the simulator /// to prioritize the request before lower valued requests. An image already being transferred using the <see cref="TexturePipeline"/> can have /// its priority changed by resending the request with the new priority value</param> /// <param name="discardLevel">Number of quality layers to discard. /// This controls the end marker of the data sent. Sending with value -1 combined with priority of 0 cancels an in-progress /// transfer.</param> /// <remarks>A bug exists in the Linden Simulator where a -1 will occasionally be sent with a non-zero priority /// indicating an off-by-one error.</remarks> /// <param name="packetStart">The packet number to begin the request at. A value of 0 begins the request /// from the start of the asset texture</param> /// <param name="callback">The <see cref="TextureDownloadCallback"/> callback to fire when the image is retrieved. The callback /// will contain the result of the request and the texture asset data</param> /// <param name="progress">If true, the callback will be fired for each chunk of the downloaded image. /// The callback asset parameter will contain all previously received chunks of the texture asset starting /// from the beginning of the request</param> /// <example> /// Request an image and fire a callback when the request is complete /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); /// /// private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", /// asset.AssetID, /// asset.AssetData.Length); /// } /// } /// </code> /// Request an image and use an inline anonymous method to handle the downloaded texture data /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, delegate(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", /// asset.AssetID, /// asset.AssetData.Length); /// } /// } /// ); /// </code> /// Request a texture, decode the texture to a bitmap image and apply it to a imagebox /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); /// /// private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// ManagedImage imgData; /// Image bitmap; /// /// if (state == TextureRequestState.Finished) /// { /// OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgData, out bitmap); /// picInsignia.Image = bitmap; /// } /// } /// } /// </code> /// </example> public void RequestImage(UUID textureID, ImageType imageType, float priority, int discardLevel, uint packetStart, TextureDownloadCallback callback, bool progress) { if (Client.Settings.USE_HTTP_TEXTURES && Client.Network.CurrentSim.Caps != null && Client.Network.CurrentSim.Caps.CapabilityURI("GetTexture") != null) { HttpRequestTexture(textureID, imageType, priority, discardLevel, packetStart, callback, progress); } else { Texture.RequestTexture(textureID, imageType, priority, discardLevel, packetStart, callback, progress); } }
// Helper method for downloading textures via GetTexture cap // Same signature as the UDP variant since we need all the params to // pass to the UDP TexturePipeline in case we need to fall back to it // (Linden servers currently (1.42) don't support bakes downloads via HTTP) private void HttpRequestTexture(UUID textureID, ImageType imageType, float priority, int discardLevel, uint packetStart, TextureDownloadCallback callback, bool progress) { if (textureID == UUID.Zero || callback == null) return; byte[] assetData; // Do we have this image in the cache? if (Client.Assets.Cache.HasAsset(textureID) && (assetData = Client.Assets.Cache.GetCachedAssetBytes(textureID)) != null) { ImageDownload image = new ImageDownload(); image.ID = textureID; image.AssetData = assetData; image.Size = image.AssetData.Length; image.Transferred = image.AssetData.Length; image.ImageType = imageType; image.AssetType = AssetType.Texture; image.Success = true; callback(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)); FireImageProgressEvent(image.ID, image.Transferred, image.Size); return; } CapsBase.DownloadProgressEventHandler progressHandler = null; if (progress) { progressHandler = (HttpWebRequest request, HttpWebResponse response, int bytesReceived, int totalBytesToReceive) => { FireImageProgressEvent(textureID, bytesReceived, totalBytesToReceive); }; } Uri url = Client.Network.CurrentSim.Caps.CapabilityURI("GetTexture"); DownloadRequest req = new DownloadRequest( new Uri(string.Format("{0}/?texture_id={1}", url.ToString(), textureID.ToString())), Client.Settings.CAPS_TIMEOUT, "image/x-j2c", progressHandler, (HttpWebRequest request, HttpWebResponse response, byte[] responseData, Exception error) => { if (error == null && responseData != null) // success { ImageDownload image = new ImageDownload(); image.ID = textureID; image.AssetData = responseData; image.Size = image.AssetData.Length; image.Transferred = image.AssetData.Length; image.ImageType = imageType; image.AssetType = AssetType.Texture; image.Success = true; callback(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)); FireImageProgressEvent(image.ID, image.Transferred, image.Size); Client.Assets.Cache.SaveAssetToCache(textureID, responseData); } else // download failed { Logger.Log( string.Format("Failed to fetch texture {0} over HTTP, falling back to UDP: {1}", textureID, (error == null) ? "" : error.Message ), Helpers.LogLevel.Warning, Client); Texture.RequestTexture(textureID, imageType, priority, discardLevel, packetStart, callback, progress); } } ); HttpDownloads.QueueDownload(req); }
/// <summary> /// Request a texture asset from the simulator using the <see cref="TexturePipeline"/> system to /// manage the requests and re-assemble the image from the packets received from the simulator /// </summary> /// <param name="textureID">The <see cref="UUID"/> of the texture asset to download</param> /// <param name="imageType">The <see cref="ImageType"/> of the texture asset. /// Use <see cref="ImageType.Normal"/> for most textures, or <see cref="ImageType.Baked"/> for baked layer texture assets</param> /// <param name="priority">A float indicating the requested priority for the transfer. Higher priority values tell the simulator /// to prioritize the request before lower valued requests. An image already being transferred using the <see cref="TexturePipeline"/> can have /// its priority changed by resending the request with the new priority value</param> /// <param name="discardLevel">Number of quality layers to discard. /// This controls the end marker of the data sent</param> /// <param name="packetStart">The packet number to begin the request at. A value of 0 begins the request /// from the start of the asset texture</param> /// <param name="callback">The <see cref="TextureDownloadCallback"/> callback to fire when the image is retrieved. The callback /// will contain the result of the request and the texture asset data</param> /// <param name="progressive">If true, the callback will be fired for each chunk of the downloaded image. /// The callback asset parameter will contain all previously received chunks of the texture asset starting /// from the beginning of the request</param> public void RequestTexture(UUID textureID, ImageType imageType, float priority, int discardLevel, uint packetStart, TextureDownloadCallback callback, bool progressive) { if (textureID == UUID.Zero) return; if (callback != null) { if (_Client.Assets.Cache.HasAsset(textureID)) { ImageDownload image = new ImageDownload(); image.ID = textureID; image.AssetData = _Client.Assets.Cache.GetCachedAssetBytes(textureID); image.Size = image.AssetData.Length; image.Transferred = image.AssetData.Length; image.ImageType = imageType; image.AssetType = AssetType.Texture; image.Success = true; callback(TextureRequestState.Finished, new AssetTexture(image.ID, image.AssetData)); _Client.Assets.FireImageProgressEvent(image.ID, image.Transferred, image.Size); } else { lock (_Transfers) { TaskInfo request; if (_Transfers.TryGetValue(textureID, out request)) { request.Callbacks.Add(callback); } else { request = new TaskInfo(); request.State = TextureRequestState.Pending; request.RequestID = textureID; request.ReportProgress = progressive; request.RequestSlot = -1; request.Type = imageType; request.Callbacks = new List<TextureDownloadCallback>(); request.Callbacks.Add(callback); ImageDownload downloadParams = new ImageDownload(); downloadParams.ID = textureID; downloadParams.Priority = priority; downloadParams.ImageType = imageType; downloadParams.DiscardLevel = discardLevel; request.Transfer = downloadParams; #if DEBUG_TIMING request.StartTime = DateTime.UtcNow; #endif _Transfers.Add(textureID, request); } } } } }
//test !!!!need to rewrite in the future public IEnumerator GetSubCategoryTexture(long subCategoryId, string subCategoryName, TextureDownloadCallback callback) { string sku = "abc"; WWW cases = new WWW(baseUrl + "/product-img/" + EncodeUriComponent(sku)); yield return(cases); callback(cases.texture); }
public IEnumerator GetSubCategoryTexture(long subCategoryId, string subCategoryName, TextureDownloadCallback callback) { Debug.Log("Icons GetSubCategoryTexture"); bool toEnd = false; yield return(null); foreach (Category cat in catList) { foreach (SubCategory sc in cat.SubCategorys) { if (sc.sub_id == subCategoryId) { Debug.Log("ProductIcons/" + cat.name + "/" + sc.sub_name); Texture2D ta = Resources.Load("ProductIcons/" + cat.name + "/" + sc.sub_name, typeof(Texture2D)) as Texture2D; callback(ta); toEnd = true; break; } } if (toEnd) { break; } } }
public IEnumerator GetSubCategoryProductTexture(long subCategoryId, string sku, TextureDownloadCallback callback) { Debug.Log("Icons GetSubCategoryProductTexture"); bool toEnd = false; yield return(null); int parentID = (int)(subCategoryId / 100); SubCategory scat = catList[parentID].SubCategorys[(int)(subCategoryId - parentID * 100)]; Debug.Log("GetSubCategoryProductTexture scat.Products.Count = " + scat.Products.Count); Debug.Log("sku = " + sku); Texture2D ta = Resources.Load("ProductIcons/" + scat.parent_name + "/" + scat.sub_name + "/" + sku, typeof(Texture2D)) as Texture2D; callback(ta); }
public void GetCategoryTexture(long categoryId, TextureDownloadCallback callback) { StartCoroutine(collector.GetCategoryTexture(categoryId, callback)); }
public void GetProductTexture(string sku, TextureDownloadCallback callback) { StartCoroutine(collector.GetProductTexture(sku, callback)); }
/// <summary> /// Overload: Request a texture asset from the simulator using the <see cref="TexturePipeline"/> system to /// manage the requests and re-assemble the image from the packets received from the simulator /// </summary> /// <param name="textureID">The <see cref="UUID"/> of the texture asset to download</param> /// <param name="imageType">The <see cref="ImageType"/> of the texture asset. /// Use <see cref="ImageType.Normal"/> for most textures, or <see cref="ImageType.Baked"/> for baked layer texture assets</param> /// <param name="callback">The <see cref="TextureDownloadCallback"/> callback to fire when the image is retrieved. The callback /// will contain the result of the request and the texture asset data</param> /// <param name="progress">If true, the callback will be fired for each chunk of the downloaded image. /// The callback asset parameter will contain all previously received chunks of the texture asset starting /// from the beginning of the request</param> public void RequestImage(UUID textureID, ImageType imageType, TextureDownloadCallback callback, bool progress) { RequestImage(textureID, imageType, 101300.0f, 0, 0, callback, progress); }
/// <summary> /// Request a texture asset from the simulator using the <see cref="TexturePipeline"/> system to /// manage the requests and re-assemble the image from the packets received from the simulator /// </summary> /// <param name="textureID">The <see cref="UUID"/> of the texture asset to download</param> /// <param name="imageType">The <see cref="ImageType"/> of the texture asset. /// Use <see cref="ImageType.Normal"/> for most textures, or <see cref="ImageType.Baked"/> for baked layer texture assets</param> /// <param name="priority">A float indicating the requested priority for the transfer. Higher priority values tell the simulator /// to prioritize the request before lower valued requests. An image already being transferred using the <see cref="TexturePipeline"/> can have /// its priority changed by resending the request with the new priority value</param> /// <param name="discardLevel">Number of quality layers to discard. /// This controls the end marker of the data sent. Sending with value -1 combined with priority of 0 cancels an in-progress /// transfer.</param> /// <remarks>A bug exists in the Linden Simulator where a -1 will occasionally be sent with a non-zero priority /// indicating an off-by-one error.</remarks> /// <param name="packetStart">The packet number to begin the request at. A value of 0 begins the request /// from the start of the asset texture</param> /// <param name="callback">The <see cref="TextureDownloadCallback"/> callback to fire when the image is retrieved. The callback /// will contain the result of the request and the texture asset data</param> /// <param name="progress">If true, the callback will be fired for each chunk of the downloaded image. /// The callback asset parameter will contain all previously received chunks of the texture asset starting /// from the beginning of the request</param> /// <example> /// Request an image and fire a callback when the request is complete /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); /// /// private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", /// asset.AssetID, /// asset.AssetData.Length); /// } /// } /// </code> /// Request an image and use an inline anonymous method to handle the downloaded texture data /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, delegate(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// Console.WriteLine("Texture {0} ({1} bytes) has been successfully downloaded", /// asset.AssetID, /// asset.AssetData.Length); /// } /// } /// ); /// </code> /// Request a texture, decode the texture to a bitmap image and apply it to a imagebox /// <code> /// Client.Assets.RequestImage(UUID.Parse("c307629f-e3a1-4487-5e88-0d96ac9d4965"), ImageType.Normal, TextureDownloader_OnDownloadFinished); /// /// private void TextureDownloader_OnDownloadFinished(TextureRequestState state, AssetTexture asset) /// { /// if(state == TextureRequestState.Finished) /// { /// ManagedImage imgData; /// Image bitmap; /// /// if (state == TextureRequestState.Finished) /// { /// OpenJPEG.DecodeToImage(assetTexture.AssetData, out imgData, out bitmap); /// picInsignia.Image = bitmap; /// } /// } /// } /// </code> /// </example> public void RequestImage(UUID textureID, ImageType imageType, float priority, int discardLevel, uint packetStart, TextureDownloadCallback callback, bool progress) { Texture.RequestTexture(textureID, imageType, priority, discardLevel, packetStart, callback, progress); }
void DownloadTexture(UUID textureID) { if (!textures.ContainsKey(textureID)) { if (Client.Assets.Cache.HasAsset(textureID)) { Debug.Log("Cache hits!"); byte[] jpg = Client.Assets.Cache.GetCachedAssetBytes(textureID); ManagedImage mi; if (!OpenJPEG.DecodeToImage(jpg, out mi)) { return; } byte[] imageBytes = mi.ExportTGA(); Bitmap img; using (MemoryStream byteData = new MemoryStream(imageBytes)) { img = LoadTGAClass.LoadTGA(byteData); } bitmaps[textureID] = img; } else { TextureDownloadCallback handler = (state, asset) => { Debug.Log("state is " + state.ToString()); try{ switch (state) { case TextureRequestState.Finished: { ManagedImage mi; if (!OpenJPEG.DecodeToImage(asset.AssetData, out mi)) { break; } byte[] imageBytes = mi.ExportTGA(); Bitmap img; using (MemoryStream byteData = new MemoryStream(imageBytes)) { img = LoadTGAClass.LoadTGA(byteData); } bitmaps[textureID] = img; break; } case TextureRequestState.Aborted: case TextureRequestState.NotFound: case TextureRequestState.Timeout: break; } } catch (Exception ex) { Debug.Log("what happened?:" + ex.Message); } }; Client.Assets.RequestImage(textureID, ImageType.Normal, handler); } } }