Exemple #1
0
        private async Task <Voice[]> GetVoicesAsync()
        {
            var voiceListRequest = new VoiceListRequest(region);

            if (!cache.IsCached(voiceListRequest))
            {
                voiceListRequest.AuthToken = await GetTokenAsync().ConfigureAwait(false);
            }

            return(await cache
                   .LoadAsync(voiceListDecoder, voiceListRequest)
                   .ConfigureAwait(false));
        }
Exemple #2
0
        public GoogleMapsClient(string apiKey, string signingKey, IJsonFactory <MetadataTypeT> metadataDecoder, IJsonFactory <GeocodingResponse> geocodingDecoder, CachingStrategy cache)
        {
            this.apiKey           = apiKey ?? throw new ArgumentNullException(nameof(apiKey));
            this.signingKey       = signingKey ?? throw new ArgumentNullException(nameof(signingKey));
            this.metadataDecoder  = metadataDecoder ?? throw new ArgumentNullException(nameof(metadataDecoder));
            this.geocodingDecoder = geocodingDecoder ?? throw new ArgumentNullException(nameof(geocodingDecoder));
            this.cache            = cache ?? throw new ArgumentNullException(nameof(cache));


            foreach (var(fileRef, metadata) in cache.Get(metadataDecoder))
            {
                if (metadata.Location != null)
                {
                    _ = Cache(metadata);
                    var imageRef = metadata.Pano_ID + MediaType.Image.Jpeg;
                    if (cache.IsCached(imageRef))
                    {
                        knownImages.Add(metadata.Pano_ID);
                    }
                }
                else
                {
                    _ = cache.Delete(fileRef);
                }
            }

            foreach (var fileRef in cache.GetContentReferences(MediaType.Image.Jpeg))
            {
                knownImages.Add(fileRef.CacheID);
            }

            knownImages.Sort();
        }
        private async Task CaptureCubemap(PhotosphereJig photosphere)
        {
            try
            {
                var fileRef = photosphere.name + codec.ContentType;
                if (cache.IsCached(fileRef))
                {
                    Debug.Log("Cubemap already cached");
                }
                else
                {
                    loadingBar.Activate();

                    const int dim     = 2048;
                    Cubemap   cubemap = null;
                    Texture2D img     = null;

                    await loadingBar.RunAsync(
                        ("Rendering cubemap", async(prog) =>
                    {
                        cubemap = await JuniperSystem.OnMainThreadAsync(() =>
                        {
                            prog.Report(0);
                            var cb = new Cubemap(dim, TextureFormat.RGB24, false);
                            cb.Apply();

                            var curMask = DisplayManager.MainCamera.cullingMask;
                            DisplayManager.MainCamera.cullingMask = LayerMask.GetMask(Photosphere.PHOTOSPHERE_LAYER_ARR);

                            var curRotation = DisplayManager.MainCamera.transform.rotation;
                            DisplayManager.MainCamera.transform.rotation = Quaternion.identity;

                            DisplayManager.MainCamera.RenderToCubemap(cb, 63);

                            DisplayManager.MainCamera.cullingMask = curMask;
                            DisplayManager.MainCamera.transform.rotation = curRotation;
                            prog.Report(1);

                            return(cb);
                        });
                    }
                        ),
                        ("Copying cubemap faces", async(prog) =>
                    {
                        for (var f = 0; f < CAPTURE_CUBEMAP_FACES.Length; ++f)
                        {
                            await JuniperSystem.OnMainThreadAsync(() =>
                            {
                                prog.Report(f, CAPTURE_CUBEMAP_FACES.Length, CAPTURE_CUBEMAP_FACES[f].ToString());
                                var pixels = cubemap.GetPixels(CAPTURE_CUBEMAP_FACES[f]);
                                var texture = new Texture2D(cubemap.width, cubemap.height);
                                texture.SetPixels(pixels);
                                texture.Apply();
                                CAPTURE_CUBEMAP_SUB_IMAGES[f] = texture;
                                prog.Report(f + 1, CAPTURE_CUBEMAP_FACES.Length);
                            });
                        }
                    }
                        ),
                        ("Concatenating faces", async(prog) =>
                    {
                        img = await JuniperSystem.OnMainThreadAsync(() =>
                                                                    processor.Concatenate(ImageData.CubeCross(CAPTURE_CUBEMAP_SUB_IMAGES), prog));
                    }
                        ),
                        ("Saving image", (prog) =>
                         JuniperSystem.OnMainThreadAsync(() => cache.Save(codec, fileRef, img))));

                    loadingBar.Deactivate();
                }

                await JuniperSystem.OnMainThreadAsync(photosphere.DestroyJig);

                var anyDestroyed = await JuniperSystem.OnMainThreadAsync(() =>
                {
                    var any = false;
                    foreach (var texture in CAPTURE_CUBEMAP_SUB_IMAGES)
                    {
                        if (texture != null)
                        {
                            any = true;
                            Destroy(texture);
                        }
                    }

                    return(any);
                });

                if (anyDestroyed)
                {
                    Resources.UnloadUnusedAssets();
                    GC.Collect();
                }

                photosphere.enabled = false;
                await Task.Yield();

                photosphere.enabled = true;
            }
            catch (Exception exp)
            {
                Debug.LogError("Cubemap capture error");
                Debug.LogException(exp, this);
                throw;
            }
        }
 private bool Photo_CheckIsCubemapAvailable(Photosphere source)
 {
     return(cache.IsCached(source.CubemapName + codec.ContentType));
 }