Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MiddleVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MiddleVRTools.VRReset();
                MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }
Пример #2
0
    // Private methods

    void InitializeVR()
    {
        mouseButtons[0] = mouseButtons[1] = mouseButtons[2] = false;

        if (m_displayLog)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.5f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(15, 0);
            m_GUI.anchor = TextAnchor.LowerCenter;
        }

        MiddleVRTools.IsEditor = Application.isEditor;

        m_isInit = MiddleVRTools.VRInitialize(ConfigFile);

        DumpOptions();

        kernel     = MiddleVR.VRKernel;
        displayMgr = MiddleVR.VRDisplayMgr;

        if (!m_isInit)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.2f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(0, 0);
            m_GUI.anchor = TextAnchor.LowerLeft;

            string txt = kernel.GetLogString(true);
            print(txt);
            m_GUI.text = txt;

            return;
        }

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

        if (ChangeWorldScale)
        {
            displayMgr.SetChangeWorldScale(true);
            displayMgr.SetWorldScale(WorldScale);
        }

        if (DisableExistingCameras)
        {
            Camera[] cameras = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[];

            foreach (Camera cam in cameras)
            {
                if (cam.targetTexture == null)
                {
                    cam.enabled = false;
                }
            }
        }

        MiddleVRTools.CreateNodes(RootNode, DebugNodes, DebugScreens, GrabExistingNodes, TemplateCamera);
        MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry);

        //AttachCameraCB();

        MiddleVRTools.Log(4, "[<] End of VR initialization script");
    }
Пример #3
0
    // Private methods

    void InitializeVR()
    {
        mouseButtons[0] = mouseButtons[1] = mouseButtons[2] = false;

        if (m_displayLog)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.5f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(15, 0);
            m_GUI.anchor = TextAnchor.LowerCenter;
        }

        MiddleVRTools.IsEditor = Application.isEditor;

        if (MiddleVR.VRKernel != null)
        {
            MiddleVRTools.Log(3, "[ ] VRKernel already alive, reset Unity Manager.");
            MiddleVRTools.VRReset();
            m_isInit = true;
            // Not needed because this is the first execution of this script instance
            // m_isGeometrySet = false;
            m_FirstFrameAfterReset = MiddleVR.VRKernel.GetFrame();
        }
        else
        {
            m_isInit = MiddleVRTools.VRInitialize(ConfigFile);
        }

        // Get AA from vrx configuration file
        //m_AntiAliasingLevel = (int)MiddleVR.VRDisplayMgr.GetAntiAliasing();

        DumpOptions();

        kernel     = MiddleVR.VRKernel;
        displayMgr = MiddleVR.VRDisplayMgr;

        if (!m_isInit)
        {
            GameObject gui = new GameObject();
            m_GUI = gui.AddComponent("GUIText") as GUIText;
            gui.transform.localPosition = new UnityEngine.Vector3(0.2f, 0.0f, 0.0f);
            m_GUI.pixelOffset           = new UnityEngine.Vector2(0, 0);
            m_GUI.anchor = TextAnchor.LowerLeft;

            string txt = kernel.GetLogString(true);
            print(txt);
            m_GUI.text = txt;

            return;
        }

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

        if (ChangeWorldScale)
        {
            displayMgr.SetChangeWorldScale(true);
            displayMgr.SetWorldScale(WorldScale);
        }

        if (DisableExistingCameras)
        {
            Camera[] cameras = GameObject.FindObjectsOfType(typeof(Camera)) as Camera[];

            foreach (Camera cam in cameras)
            {
                if (cam.targetTexture == null)
                {
                    cam.enabled = false;
                }
            }
        }

        MiddleVRTools.CreateNodes(RootNode, DebugNodes, DebugScreens, GrabExistingNodes, TemplateCamera);
        MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);

        //AttachCameraCB();

        MiddleVRTools.Log(4, "[<] End of VR initialization script");
    }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        //MiddleVRTools.Log("VRManagerUpdate");

        if (m_isInit)
        {
            MiddleVRTools.Log(4, "[>] Unity Update - Start");

            if (kernel.GetFrame() >= m_FirstFrameAfterReset + 1 && !m_isGeometrySet && !Application.isEditor)
            {
                if (!DontChangeWindowGeometry)
                {
                    displayMgr.SetUnityWindowGeometry();
                }
                m_isGeometrySet = true;
            }

            kernel.Update();
            UpdateInput();

            if (ShowFPS)
            {
                guiText.text = kernel.GetFPS().ToString("f2");
            }

            MiddleVRTools.UpdateNodes();

            if (m_displayLog)
            {
                string txt = kernel.GetLogString(true);
                print(txt);
                m_GUI.text = txt;
            }

            vrKeyboard keyb = MiddleVR.VRDeviceMgr.GetKeyboard();

            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_D) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowFPS         = !ShowFPS;
                guiText.enabled = ShowFPS;
            }

            if (keyb != null && (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z)) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                ShowWand = !ShowWand;
                ShowWandGeometry(ShowWand);
            }

            // Toggle Fly mode on interactions
            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_F) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                vrInteractionManager interMan = vrInteractionManager.GetInstance();
                uint interactionNb            = interMan.GetInteractionsNb();
                for (uint i = 0; i < interactionNb; ++i)
                {
                    vrProperty flyProp = interMan.GetInteractionByIndex(i).GetProperty("Fly");
                    if (flyProp != null)
                    {
                        flyProp.SetBool(!flyProp.GetBool());
                    }
                }
            }

            // Navigation mode switch
            if (keyb != null && keyb.IsKeyToggled(MiddleVR.VRK_N) && (keyb.IsKeyPressed(MiddleVR.VRK_LSHIFT) || keyb.IsKeyPressed(MiddleVR.VRK_RSHIFT)))
            {
                // Disable current nav
                MonoBehaviour currentNavigation = (MonoBehaviour)m_Wand.GetComponent((string)m_NavigationScipts[m_CurrentNavigationNb]);
                if (currentNavigation != null)
                {
                    currentNavigation.enabled = false;
                }

                // Enable next nav
                m_CurrentNavigationNb = (m_CurrentNavigationNb + 1) % m_NavigationScipts.Count;

                currentNavigation = (MonoBehaviour)m_Wand.GetComponent((string)m_NavigationScipts[m_CurrentNavigationNb]);
                if (currentNavigation != null)
                {
                    currentNavigation.enabled = true;
                }
            }

            DeltaTime = kernel.GetDeltaTime();

            MiddleVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentionning 'DLLNotFoundException: MiddleVR_CSharp', please restart Unity. If this does not fix the problem, please make sure MiddleVR is in the PATH environment variable.");
        }

        // If QualityLevel changed, we have to reset the Unity Manager
        if (m_NeedDelayedRenderingReset)
        {
            if (m_RenderingResetDelay == 0)
            {
                MiddleVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MiddleVRTools.VRReset();
                MiddleVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }