Example #1
0
 public UnityEditorProgressDialog(string title)
 {
     this.title = title;
     JuniperSystem.OnMainThread(() =>
     {
         EditorApplication.update += ShowStatus;
     });
 }
Example #2
0
 public void Close()
 {
     JuniperSystem.OnMainThread(() =>
     {
         EditorApplication.update -= ShowStatus;
         EditorUtility.ClearProgressBar();
     });
 }
        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;
            }
        }
Example #4
0
        public Texture2D Deserialize(byte[] buffer)
        {
            if (buffer is null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            var info = GetImageInfo(buffer);

            return(JuniperSystem.OnMainThread(() =>
                                              MakeTexture(info, buffer)));
        }
        private async Task <PhotosphereJig> GetPhotosphere()
        {
            var jig = await JuniperSystem.OnMainThreadAsync(() =>
                                                            photospheres.GetPhotosphere <PhotosphereJig>(metadata.Pano_ID));

            if (!imageNeededSet.Contains(metadata.Pano_ID))
            {
                imageNeededSet.Add(metadata.Pano_ID);
                jig.ImageNeeded += Photosphere_ImageNeeded;
#if UNITY_EDITOR
                jig.Complete += Photosphere_Complete;
#endif
            }
            return(jig);
        }
Example #6
0
 public void PauseZone(string zoneName)
 {
     JuniperSystem.OnMainThread(() =>
     {
         var audioSources = Find.All <AudioSource>(a => !a.CompareTag(INTERACTION_SOUND_TAG));
         foreach (var audioSource in audioSources)
         {
             if (audioSource.IsInZone(zoneName) &&
                 audioSource.isPlaying)
             {
                 audioSource.Pause();
             }
         }
     });
 }
Example #7
0
        public async Task EnableDopplerAsync(bool value)
        {
#if UNITY_MODULES_AUDIO
            await JuniperSystem.OnMainThreadAsync(() =>
            {
                var audioSources = Find.All <AudioSource>();
                var doppler      = value ? dopplerLevel : 0;
                foreach (var audioSource in audioSources)
                {
                    audioSource.dopplerLevel = doppler;
                }
            });
#endif

            // burn a frame
            await Task.Yield();
        }
Example #8
0
 public void PlayZone(string zoneName)
 {
     JuniperSystem.OnMainThread(() =>
     {
         var audioSources = Find.All <AudioSource>(a => !a.CompareTag(INTERACTION_SOUND_TAG));
         foreach (var audioSource in audioSources)
         {
             if (!audioSource.IsInZone(zoneName) &&
                 audioSource.isPlaying)
             {
                 audioSource.Stop();
             }
             else if (audioSource.playOnAwake &&
                      !audioSource.isPlaying)
             {
                 audioSource.Activate();
                 audioSource.Play();
             }
         }
     });
 }
        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;
            }
        }
Example #10
0
 public static Task ActivateAsync(this MonoBehaviour parent)
 {
     return(JuniperSystem.OnMainThreadAsync(parent.Activate));
 }
Example #11
0
        private async Task UpdatePhotosphere()
        {
            var euler = (Vector2)avatar.Head.rotation.eulerAngles;

            var numRequests = 0;

            for (var f = 0; f < mgr.FOVs.Length && numRequests < MAX_REQUESTS; ++f)
            {
                var fov        = mgr.FOVs[f];
                var overlap    = mgr.FOVs.Length - f;
                var radius     = 10 * overlap + 50;
                var overlapFOV = fov + 2f * overlap;
                var scale      = 2 * radius * Mathf.Tan(Degrees.Radians(overlapFOV / 2));

                var testAngles = mgr.fovTestAngles[f];
                for (var a = 0; a < testAngles.Length && numRequests < MAX_REQUESTS; ++a)
                {
                    var testAngle  = euler + testAngles[a];
                    var heading    = (int)Mathf.Repeat(fov * Mathf.Round(testAngle.y / fov), 360);
                    var unityPitch = (int)Mathf.Repeat(fov * Mathf.Round(testAngle.x / fov), 360);
                    var pitch      = -unityPitch;
                    if (unityPitch >= 270)
                    {
                        pitch += 360;
                    }
                    else if (unityPitch > 90)
                    {
                        pitch += 180;
                    }

                    if (90 < unityPitch && unityPitch < 270)
                    {
                        heading = (int)Mathf.Repeat(heading + 180, 360);
                    }

                    if (Mathf.Abs(pitch) == 90)
                    {
                        heading = 0;
                    }

                    var needLodLevel = !detailContainerCache.ContainsKey(fov);
                    var needSlice    = needLodLevel || !detailSliceContainerCache[fov].ContainsKey(heading);
                    var needFrame    = needSlice || !detailSliceFrameContainerCache[fov][heading].ContainsKey(pitch);
                    if (needLodLevel || needSlice || needFrame)
                    {
                        if (needLodLevel)
                        {
                            await JuniperSystem.OnMainThreadAsync(() =>
                            {
                                var detail = new GameObject(fov.ToString()).transform;
                                detail.SetParent(transform, false);
                                detailContainerCache[fov]           = detail;
                                detailSliceContainerCache[fov]      = new Dictionary <int, Transform>();
                                detailSliceFrameContainerCache[fov] = new Dictionary <int, Dictionary <int, Transform> >();
                            });
                        }

                        var detailContainer          = detailContainerCache[fov];
                        var sliceContainerCache      = detailSliceContainerCache[fov];
                        var sliceFrameContainerCache = detailSliceFrameContainerCache[fov];

                        if (needSlice)
                        {
                            await JuniperSystem.OnMainThreadAsync(() =>
                            {
                                var slice = new GameObject(heading.ToString()).transform;
                                slice.SetParent(detailContainer, false);
                                sliceContainerCache[heading]      = slice;
                                sliceFrameContainerCache[heading] = new Dictionary <int, Transform>();
                            });
                        }

                        var sliceContainer      = sliceContainerCache[heading];
                        var frameContainerCache = sliceFrameContainerCache[heading];

                        if (needFrame)
                        {
                            await JuniperSystem.OnMainThreadAsync(() =>
                            {
                                var frame      = new GameObject(pitch.ToString()).transform;
                                frame.rotation = Quaternion.Euler(-pitch, heading, 0);
                                frame.position = frame.rotation * (radius *Vector3.forward);
                                frame.SetParent(sliceContainer, false);
                                frameContainerCache[pitch] = frame;
                            });
                        }

                        if (ImageNeeded != null)
                        {
                            var image = await ImageNeeded(this, (int)overlapFOV, heading, pitch);

                            if (image != null)
                            {
                                await JuniperSystem.OnMainThreadAsync(() =>
                                {
                                    var frame      = GameObject.CreatePrimitive(PrimitiveType.Quad);
                                    var renderer   = frame.GetComponent <MeshRenderer>();
                                    var properties = new MaterialPropertyBlock();
                                    properties.SetTexture("_MainTex", image);
                                    renderer.SetMaterial(material);
                                    renderer.SetPropertyBlock(properties);
                                    frame.layer        = LayerMask.NameToLayer(PHOTOSPHERE_LAYER);
                                    var frameContainer = frameContainerCache[pitch];
                                    frame.transform.SetParent(frameContainer, false);
                                    frame.transform.localScale = scale *Vector3.one;
                                });
                            }
                        }

                        // For the lowest detail level, we fill out all of the image angles immediately.
                        // For all other detail levels, we break out of testing angles and continue to
                        // next highest detail level.
                        if (f > 0)
                        {
                            break;
                        }
                    }
                }
            }
        }
Example #12
0
 public static Task ActivateAsync(this Component parent)
 {
     return(JuniperSystem.OnMainThreadAsync(parent.Activate));
 }
Example #13
0
 public static Task SetActiveAsync(this Component parent, bool active)
 {
     return(JuniperSystem.OnMainThreadAsync(() => parent.SetActive(active)));
 }
Example #14
0
 public static Task <bool> IsActivatedAsync(this Component parent)
 {
     return(JuniperSystem.OnMainThreadAsync(parent.IsActivated));
 }