private async Task SearchData(string searchPano, LatLngPoint searchPoint, IProgress prog) { prog.Report(0); metadata = await gmaps.SearchMetadataAsync(searchLocation, searchPano, searchPoint, searchRadius, prog) .ConfigureAwait(false); if (metadata != null) { searchPoint = metadata.Location; searchLocation = searchPano = metadata.Pano_ID; if (lastSphere == null) { origin = metadata.Location; } if (gps != null) { gps.FakeCoord = true; gps.Coord = metadata.Location; } #if UNITY_EDITOR if (locationInput != null) { locationInput.value = searchLocation; } #endif loadingBar.Activate(); var curSphere = await GetPhotosphere(); if (lastSphere != null) { await JuniperSystem.OnMainThreadAsync(lastSphere.Deactivate); } await JuniperSystem.OnMainThreadAsync(curSphere.Activate); if (lastSphere == null) { await prog.WaitOnAsync(curSphere, "Loading photosphere"); Complete(); } await JuniperSystem.OnMainThreadAsync(() => { avatar.transform.position = GetRelativeVector3(metadata); curSphere.transform.position = avatar.Head.position; }); prog.Report(1); lastSphere = curSphere; } }
private void Photosphere_Complete(PhotosphereJig jig, bool captureCubemap) { loadingBar.Deactivate(); jig.ImageNeeded -= Photosphere_ImageNeeded; jig.Complete -= Photosphere_Complete; if (captureCubemap) { captureTask = CaptureCubemap(jig); } }
private async Task <Texture2D> Photosphere_ImageNeeded(PhotosphereJig source, int fov, int heading, int pitch) { if (gmaps == null || codec == null) { return(null); } else { return(Decode(await gmaps.GetImageAsync(source.CubemapName, fov, heading, pitch))); } }
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; } }