コード例 #1
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;
        }

        MVRTools.IsEditor = Application.isEditor;

        if (MiddleVR.VRKernel != null)
        {
            MVRTools.Log(3, "[ ] VRKernel already alive, reset Unity Manager.");
            MVRTools.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
        {
            if (CustomLicense)
            {
                MVRTools.CustomLicense     = true;
                MVRTools.CustomLicenseName = CustomLicenseName;
                MVRTools.CustomLicenseCode = CustomLicenseCode;
            }

            m_isInit = MVRTools.VRInitialize(ConfigFile);
        }


        if (SimpleClusterParticles)
        {
            _SetParticlesSeeds();
        }

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

        DumpOptions();

        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 = m_Kernel.GetLogString(true);
            print(txt);
            m_GUI.text = txt;

            return;
        }

        m_Kernel     = MiddleVR.VRKernel;
        m_DeviceMgr  = MiddleVR.VRDeviceMgr;
        m_DisplayMgr = MiddleVR.VRDisplayMgr;
        m_ClusterMgr = MiddleVR.VRClusterMgr;

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

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

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

        MVRNodesCreator.Instance.CreateNodes(VRSystemCenterNode, DebugNodes, DebugScreens, GrabExistingNodes, TemplateCamera);

        MVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);

        //AttachCameraCB();

        MVRTools.Log(4, "[<] End of VR initialization script");
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //MVRTools.Log("VRManagerUpdate");

        // Initialize interactions
        if (!m_InteractionsInitialized)
        {
            _SetNavigation(Navigation);
            _SetManipulation(Manipulation);
            _SetVirtualHandMapping(VirtualHandMapping);

            m_InteractionsInitialized = true;
        }

        MVRNodesMapper nodesMapper = MVRNodesMapper.Instance;

        nodesMapper.UpdateNodesUnityToMiddleVR();

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

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

            if (m_Kernel.GetFrame() == 0)
            {
                // Set the random seed in kernel for dispatching only during start-up.
                // With clustering, a client will be set by a call to kernel.Update().
                if (!m_ClusterMgr.IsCluster() ||
                    (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsServer()))
                {
                    // The cast is safe because the seed is always positive.
                    uint seed = (uint)UnityEngine.Random.seed;
                    m_Kernel._SetRandomSeed(seed);
                }
            }

            m_Kernel.Update();

            if (m_Kernel.GetFrame() == 0)
            {
                // Set the random seed in a client only during start-up.
                if (m_ClusterMgr.IsCluster() && m_ClusterMgr.IsClient())
                {
                    // The cast is safe because the seed comes from
                    // a previous value of Unity.
                    int seed = (int)m_Kernel.GetRandomSeed();
                    UnityEngine.Random.seed = seed;
                }
            }

            UpdateInput();

            if (ShowFPS)
            {
                this.GetComponent <GUIText>().text = m_Kernel.GetFPS().ToString("f2");
            }

            nodesMapper.UpdateNodesMiddleVRToUnity(false);

            MVRTools.UpdateCameraProperties();

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

            vrKeyboard keyb = m_DeviceMgr.GetKeyboard();

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

                    if (keyb.IsKeyToggled(MiddleVR.VRK_W) || keyb.IsKeyToggled(MiddleVR.VRK_Z))
                    {
                        ShowWand = !ShowWand;
                        ShowWandGeometry(ShowWand);
                    }

                    // Toggle Fly mode on interactions
                    if (keyb.IsKeyToggled(MiddleVR.VRK_F))
                    {
                        Fly = !Fly;
                    }

                    // Navigation mode switch
                    if (keyb.IsKeyToggled(MiddleVR.VRK_N))
                    {
                        vrInteraction navigation = _GetNextInteraction("ContinuousNavigation");
                        if (navigation != null)
                        {
                            MiddleVR.VRInteractionMgr.Activate(navigation);
                        }
                    }
                }
            }

            DeltaTime = m_Kernel.GetDeltaTime();

            MVRTools.Log(4, "[<] Unity Update - End");
        }
        else
        {
            //Debug.LogWarning("[ ] If you have an error mentioning '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)
            {
                MVRTools.Log(3, "[ ] Graphic quality forced, reset Unity Manager.");
                MVRTools.VRReset();
                MVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, m_AllowRenderTargetAA);
                m_isGeometrySet             = false;
                m_NeedDelayedRenderingReset = false;
            }
            else
            {
                --m_RenderingResetDelay;
            }
        }
    }
コード例 #3
0
    // Private methods

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

        if (MiddleVR.VRKernel != null)
        {
            MVRTools.Log(3, "[ ] VRKernel already alive, reset Unity Manager.");
            MVRTools.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
        {
            if (CustomLicense)
            {
                MVRTools.CustomLicense     = true;
                MVRTools.CustomLicenseName = CustomLicenseName;
                MVRTools.CustomLicenseCode = CustomLicenseCode;
            }

            m_isInit = MVRTools.VRInitialize(ConfigFile);
        }


        if (SimpleClusterParticles)
        {
            _SetParticlesSeeds();
        }

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

        DumpOptions();

        m_Kernel     = MiddleVR.VRKernel;
        m_DeviceMgr  = MiddleVR.VRDeviceMgr;
        m_DisplayMgr = MiddleVR.VRDisplayMgr;
        m_ClusterMgr = MiddleVR.VRClusterMgr;

        if (SimpleCluster)
        {
            SetupSimpleCluster();
        }

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

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

        MVRNodesCreator.Instance.CreateNodes(
            VRSystemCenterNode,
            DebugNodes, DebugScreens,
            GrabExistingNodes, TemplateCamera);

        MVRTools.CreateViewportsAndCameras(DontChangeWindowGeometry, true);

        MVRTools.Log(4, "[<] End of VR initialization script");
    }