public IEnumerator AddImageJob(Texture2D texture2D) { yield return(null); debugLog.text = string.Empty; debugLog.text += "Adding image\n"; jobLog.text = "Job Starting..."; var firstGuid = new SerializableGuid(0, 0); var secondGuid = new SerializableGuid(0, 0); XRReferenceImage newImage = new XRReferenceImage(firstGuid, secondGuid, new Vector2(0.1f, 0.1f), Guid.NewGuid().ToString(), texture2D); try { MutableRuntimeReferenceImageLibrary mutableRuntimeReferenceImageLibrary = trackImageManager.referenceLibrary as MutableRuntimeReferenceImageLibrary; debugLog.text += $"TextureFormat.RGBA32 supported: {mutableRuntimeReferenceImageLibrary.IsTextureFormatSupported(TextureFormat.RGBA32)}\n"; debugLog.text += $"TextureFormat size: {texture2D.width}px width {texture2D.height}px height\n"; var jobHandle = mutableRuntimeReferenceImageLibrary.ScheduleAddImageJob(texture2D, Guid.NewGuid().ToString(), 0.1f); while (!jobHandle.IsCompleted) { jobLog.text = "Job Running..."; } jobLog.text = "Job Completed..."; debugLog.text += $"Job Completed ({mutableRuntimeReferenceImageLibrary.count})\n"; debugLog.text += $"Supported Texture Count ({mutableRuntimeReferenceImageLibrary.supportedTextureFormatCount})\n"; debugLog.text += $"trackImageManager.trackables.count ({trackImageManager.trackables.count})\n"; debugLog.text += $"trackImageManager.trackedImagePrefab.name ({trackImageManager.trackedImagePrefab.name})\n"; debugLog.text += $"trackImageManager.maxNumberOfMovingImages ({trackImageManager.maxNumberOfMovingImages})\n"; debugLog.text += $"trackImageManager.supportsMutableLibrary ({trackImageManager.subsystem.SubsystemDescriptor.supportsMutableLibrary})\n"; debugLog.text += $"trackImageManager.requiresPhysicalImageDimensions ({trackImageManager.subsystem.SubsystemDescriptor.requiresPhysicalImageDimensions})\n"; } catch (Exception e) { if (texture2D == null) { debugLog.text += "texture2D is null"; } debugLog.text += $"Error: {e.ToString()}"; } }
// Descarga los targets utilizando las urls de entrada y los // añade a la colleccion/libreria de targets para que AR Foundation // pueda detectarlas. El nombre de cada target es el id al que esta // vinculado. private IEnumerator DownloadAndAddTargetsFromUrl(List <string> links, List <string> ids) { // Empareja el id con su textura. // image.item1 es el id // image.item2 es la textura2D List <Tuple <string, Texture2D> > allImages = new List <Tuple <string, Texture2D> >(); // Descarga de imagenes for (int h = 0; h < links.Count; h++) { UnityWebRequest request = UnityWebRequestTexture.GetTexture(links[h]); yield return(request.SendWebRequest()); Texture2D texture2D; if (request.isNetworkError || request.isHttpError) { Debug.Log(request.error); } else { debugLog.text += "Descarga de Imagen exitosa.\n"; texture2D = ((DownloadHandlerTexture)request.downloadHandler).texture; allImages.Add(new Tuple <string, Texture2D>(ids[h], texture2D)); } } // Creacion de coleccion/libreria de targets para AR foundation. try { trackImageManager.referenceLibrary = trackImageManager.CreateRuntimeLibrary(runtimeImageLibrary); trackImageManager.maxNumberOfMovingImages = 3; trackImageManager.trackedImagePrefab = prefabOnTrack; trackImageManager.enabled = true; MutableRuntimeReferenceImageLibrary mutableRuntimeReferenceImageLibrary = trackImageManager.referenceLibrary as MutableRuntimeReferenceImageLibrary; debugLog.text += $"TextureFormat.RGBA32 supported: {mutableRuntimeReferenceImageLibrary.IsTextureFormatSupported(TextureFormat.RGBA32)} \n"; // Recorre la lista de pares para añadir la textura2D/Target // a la mutableRuntimeReferenceImageLibrary con el id como nombre. // image.item1 es el id // image.item2 es la textura2D foreach (var image in allImages) { Texture2D texture2D = image.Item2; debugLog.text += $"TextureFormat size: {texture2D.width}px width {texture2D.height}px height \n"; var jobHandle = mutableRuntimeReferenceImageLibrary.ScheduleAddImageJob(texture2D, image.Item1, 0.1f); while (!jobHandle.IsCompleted) { debugLog.text += "Job Running... \n"; Task.Delay(100).Wait(); } } } catch (Exception e) { debugLog.text += e.ToString() + "\n"; } }