Esempio n. 1
0
        void AddInternal(SteamVR_Camera vrcam)
        {
            var camera = vrcam.GetComponent <Camera>();
            var length = cameras.Length;
            var sorted = new SteamVR_Camera[length + 1];
            int insert = 0;

            for (int i = 0; i < length; i++)
            {
                var c = cameras[i].GetComponent <Camera>();
                if (i == insert && c.depth > camera.depth)
                {
                    sorted[insert++] = vrcam;
                }

                sorted[insert++] = cameras[i];
            }

            if (insert == length)
            {
                sorted[insert] = vrcam;
            }

            cameras = sorted;
        }
Esempio n. 2
0
        void RemoveInternal(SteamVR_Camera vrcam)
        {
            var length = cameras.Length;
            int count  = 0;

            for (int i = 0; i < length; i++)
            {
                var c = cameras[i];
                if (c == vrcam)
                {
                    ++count;
                }
            }

            if (count == 0)
            {
                return;
            }

            var sorted = new SteamVR_Camera[length - count];
            int insert = 0;

            for (int i = 0; i < length; i++)
            {
                var c = cameras[i];
                if (c != vrcam)
                {
                    sorted[insert++] = c;
                }
            }

            cameras = sorted;
        }
Esempio n. 3
0
 static public void Add(SteamVR_Camera vrcam)
 {
     if (!isQuitting)
     {
         instance.AddInternal(vrcam);
     }
 }
Esempio n. 4
0
 static public void Remove(SteamVR_Camera vrcam)
 {
     if (!isQuitting && instance != null)
     {
         instance.RemoveInternal(vrcam);
     }
 }
Esempio n. 5
0
 public static void Remove(SteamVR_Camera vrcam)
 {
     if (!SteamVR_Render.isQuitting && SteamVR_Render.instance != null)
     {
         SteamVR_Render.instance.RemoveInternal(vrcam);
     }
 }
Esempio n. 6
0
        private void RemoveInternal(SteamVR_Camera vrcam)
        {
            int num  = this.cameras.Length;
            int num2 = 0;

            for (int i = 0; i < num; i++)
            {
                if (this.cameras[i] == vrcam)
                {
                    num2++;
                }
            }
            if (num2 == 0)
            {
                return;
            }
            SteamVR_Camera[] array = new SteamVR_Camera[num - num2];
            int num3 = 0;

            for (int j = 0; j < num; j++)
            {
                SteamVR_Camera steamVR_Camera = this.cameras[j];
                if (steamVR_Camera != vrcam)
                {
                    array[num3++] = steamVR_Camera;
                }
            }
            this.cameras = array;
        }
Esempio n. 7
0
 private void RenderEye(SteamVR vr, EVREye eye)
 {
     SteamVR_Render.eye = eye;
     if (this.cameraMask != null)
     {
         this.cameraMask.Set(vr, eye);
     }
     foreach (SteamVR_Camera steamVR_Camera in this.cameras)
     {
         steamVR_Camera.transform.localPosition = vr.eyes[(int)eye].pos;
         steamVR_Camera.transform.localRotation = vr.eyes[(int)eye].rot;
         this.cameraMask.transform.position     = steamVR_Camera.transform.position;
         Camera camera = steamVR_Camera.camera;
         camera.targetTexture = SteamVR_Camera.GetSceneTexture(false);
         int cullingMask = camera.cullingMask;
         if (eye == EVREye.Eye_Left)
         {
             camera.cullingMask &= ~this.rightMask;
             camera.cullingMask |= this.leftMask;
         }
         else
         {
             camera.cullingMask &= ~this.leftMask;
             camera.cullingMask |= this.rightMask;
         }
         camera.Render();
         camera.cullingMask = cullingMask;
     }
 }
Esempio n. 8
0
 public static void Add(SteamVR_Camera vrcam)
 {
     if (!SteamVR_Render.isQuitting)
     {
         SteamVR_Render.instance.AddInternal(vrcam);
     }
 }
        private void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            Graphics.Blit(src, dest, blitMaterial);
            if (SteamVR_Camera.doomp)
            {
                SteamVR_Camera.DumpRenderTexture(src, Application.streamingAssetsPath + "/CameraFlip_OnRenderImage_src.png");
            }

            if (SteamVR_Camera.doomp)
            {
                Debug.Log(Time.frameCount.ToString() + "/CameraFlip_OnRenderImage");
                SteamVR_Camera.DumpRenderTexture(dest, Application.streamingAssetsPath + "/CameraFlip_OnRenderImage_dst.png");
            }
        }
Esempio n. 10
0
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(this.waitForEndOfFrame);

                if (!SteamVR_Render.pauseRendering)
                {
                    CVRCompositor compositor = OpenVR.Compositor;
                    if (compositor != null)
                    {
                        if (!compositor.CanRenderScene() || cameras.Length < 1)
                        {
                            continue;
                        }
                        compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                        SteamVR_Utils.QueueEventOnRenderThread(201510020);
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                        SteamVR_Camera.GetSceneTexture(this.cameras[0].GetComponent <Camera>()).GetNativeTexturePtr();
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - End");
                        compositor.GetLastPoses(this.poses, this.gamePoses);
                        SteamVR_Events.NewPoses.Send(this.poses);
                        SteamVR_Events.NewPosesApplied.Send();
                    }
                    SteamVR_Overlay instance = SteamVR_Overlay.instance;
                    if (instance != null)
                    {
                        instance.UpdateOverlay();
                    }
                    if (this.CheckExternalCamera())
                    {
                        this.RenderExternalCamera();
                    }
                    SteamVR instance2 = SteamVR.instance;
                    this.RenderEye(instance2, EVREye.Eye_Left);
                    this.RenderEye(instance2, EVREye.Eye_Right);
                    foreach (SteamVR_Camera steamVR_Camera in this.cameras)
                    {
                        steamVR_Camera.transform.localPosition = Vector3.zero;
                        steamVR_Camera.transform.localRotation = Quaternion.identity;
                    }
                    if (this.cameraMask != null)
                    {
                        this.cameraMask.Clear();
                    }
                }
            }
            yield break;
        }
 public void ForceLast()
 {
     if (SteamVR_Camera.values != null)
     {
         foreach (object obj in SteamVR_Camera.values)
         {
             DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
             (dictionaryEntry.Key as FieldInfo).SetValue(this, dictionaryEntry.Value);
         }
         SteamVR_Camera.values = null;
         return;
     }
     Component[] components = base.GetComponents <Component>();
     for (int i = 0; i < components.Length; i++)
     {
         SteamVR_Camera steamVR_Camera = components[i] as SteamVR_Camera;
         if (steamVR_Camera != null && steamVR_Camera != this)
         {
             if (steamVR_Camera.flip != null)
             {
                 UnityEngine.Object.DestroyImmediate(steamVR_Camera.flip);
             }
             UnityEngine.Object.DestroyImmediate(steamVR_Camera);
         }
     }
     components = base.GetComponents <Component>();
     if (this != components[components.Length - 1] || this.flip == null)
     {
         if (this.flip == null)
         {
             this.flip = base.gameObject.AddComponent <SteamVR_CameraFlip>();
         }
         SteamVR_Camera.values = new Hashtable();
         foreach (FieldInfo fieldInfo in base.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
         {
             if (fieldInfo.IsPublic || fieldInfo.IsDefined(typeof(SerializeField), true))
             {
                 SteamVR_Camera.values[fieldInfo] = fieldInfo.GetValue(this);
             }
         }
         GameObject gameObject = base.gameObject;
         UnityEngine.Object.DestroyImmediate(this);
         gameObject.AddComponent <SteamVR_Camera>().ForceLast();
     }
 }
        void RenderEye(SteamVR vr, EVREye eye)
        {
            eyePreRenderCallback?.Invoke(eye);

            int i = (int)eye;

            SteamVR_Render.eye = eye;

            if (cameraMask != null)
            {
                cameraMask.Set(vr, eye);
            }

            foreach (var c in cameras)
            {
                c.transform.localPosition = vr.eyes[i].pos;
                c.transform.localRotation = vr.eyes[i].rot;

                // Update position to keep from getting culled
                cameraMask.transform.position = c.transform.position;

                var camera = c.camera;
                camera.targetTexture = SteamVR_Camera.GetSceneTexture(camera.allowHDR);
                int cullingMask = camera.cullingMask;
                if (eye == EVREye.Eye_Left)
                {
                    camera.cullingMask &= ~rightMask;
                    camera.cullingMask |= leftMask;
                }
                else
                {
                    camera.cullingMask &= ~leftMask;
                    camera.cullingMask |= rightMask;
                }
                camera.Render();

                if (SteamVR_Camera.doomp)
                {
                    Debug.Log(Time.frameCount.ToString() + $"/Render{eye}_OnRenderImage_src.png");
                    SteamVR_Camera.DumpRenderTexture(camera.targetTexture, Application.streamingAssetsPath + $"/Render{eye}_OnRenderImage_src.png");
                }
                camera.cullingMask = cullingMask;
            }
            eyePostRenderCallback?.Invoke(eye);
        }
Esempio n. 13
0
        private void AddInternal(SteamVR_Camera vrcam)
        {
            Camera component = vrcam.GetComponent <Camera>();
            int    num       = this.cameras.Length;

            SteamVR_Camera[] array = new SteamVR_Camera[num + 1];
            int num2 = 0;

            for (int i = 0; i < num; i++)
            {
                Camera component2 = this.cameras[i].GetComponent <Camera>();
                if (i == num2 && component2.depth > component.depth)
                {
                    array[num2++] = vrcam;
                }
                array[num2++] = this.cameras[i];
            }
            if (num2 == num)
            {
                array[num2] = vrcam;
            }
            this.cameras = array;
            base.enabled = true;
        }
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(waitForEndOfFrame);

                if (cameras.Length == 0)
                {
                    continue;
                }

                if (pauseRendering)
                {
                    continue;
                }

                var compositor = OpenVR.Compositor;
                if (compositor != null)
                {
                    if (!compositor.CanRenderScene())
                    {
                        continue;
                    }

                    compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                    SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_WaitGetPoses);

                    // Hack to flush render event that was queued in Update (this ensures WaitGetPoses has returned before we grab the new values).
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                    SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().allowHDR).GetNativeTexturePtr();
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - End");

                    compositor.GetLastPoses(poses, gamePoses);
                    SteamVR_Events.NewPoses.Send(poses);
                    SteamVR_Events.NewPosesApplied.Send();
                }

                var overlay = SteamVR_Overlay.instance;
                if (overlay != null)
                {
                    overlay.UpdateOverlay();
                }

                RenderExternalCamera();


                var vr = SteamVR.instance;
                RenderEye(vr, EVREye.Eye_Left);
                RenderEye(vr, EVREye.Eye_Right);

                // Move cameras back to head position so they can be tracked reliably
                foreach (var c in cameras)
                {
                    c.transform.localPosition = Vector3.zero;
                    c.transform.localRotation = Quaternion.identity;
                }

                if (cameraMask != null)
                {
                    cameraMask.Clear();
                }
            }
        }