예제 #1
0
        private void Awake()
        {
            string fViewJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FViewTool", "FView.json");

            if (!File.Exists(fViewJsonPath))
            {
                UnityEngine.Debug.LogError("FView.Awake():先使用工具软件进行罗技摄像头的标定!");
                return;
            }

            if (FARDll.fmFViewReadJson() == 0)//读取json成功
            {
                //读坐标viewPosition
                int    size      = Marshal.SizeOf(viewPosition);
                IntPtr structPtr = Marshal.AllocHGlobal(size);
                FARDll.fmFViewGetPosition(structPtr);
                viewPosition = (Vector3)Marshal.PtrToStructure(structPtr, typeof(Vector3));
                Marshal.FreeHGlobal(structPtr);

                //读旋转viewRotation
                size      = Marshal.SizeOf(viewRotation);
                structPtr = Marshal.AllocHGlobal(size);
                FARDll.fmFViewGetRotation(structPtr);
                viewRotation = (Quaternion)Marshal.PtrToStructure(structPtr, typeof(Quaternion));
                Marshal.FreeHGlobal(structPtr);
            }
            //使用标定结果设置CamRoot的坐标(注意坐标需要缩放)
            transform.localPosition = viewPosition * FCore.ViewerScale;
            transform.localRotation = viewRotation;
        }
예제 #2
0
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.V))
            {
                //启动投屏窗口
                FARStartRenderingView(WorkMode._DoubleTexture);
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                //关闭投屏窗口
                FARDll.CloseDown();
            }
            if (_lastWorkingType != workingMode)
            {
                //切换到2D画面
                FARStartRenderingView(workingMode);
                _lastWorkingType = workingMode;
            }

            ///切换投影方式
            if (Input.GetKeyDown(KeyCode.K))
            {
                FARDll.SwitchProjector(FARDll.ProjectorType._2D);
            }
            if (Input.GetKeyDown(KeyCode.J))
            {
                FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
            }
        }
예제 #3
0
        private void OnGUI()
        {
            if (SceneManager.GetActiveScene().name == "VRSample" || SceneManager.GetActiveScene().name == "All")
            {
                if (GUI.Button(new Rect(20, 20, 160, 60), "2D"))
                {
                    FARStartRenderingView(WorkMode._DoubleTexture);
                    FARDll.SwitchProjector(FARDll.ProjectorType._2D);
                }

                if (GUI.Button(new Rect(200, 20, 160, 60), "3D"))
                {
                    FARStartRenderingView(WorkMode._DoubleTexture);
                    FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
                }
            }

            if (SceneManager.GetActiveScene().name == "F-ARSample" || SceneManager.GetActiveScene().name == "All")
            {
                if (GUI.Button(new Rect(20, 100, 160, 60), "AR"))
                {
                    FARStartRenderingView(WorkMode._SingleTexture);
                    //FARDll.SwitchProjector(FARDll.ProjectorType.LeftRight);
                }
            }

            if (SceneManager.GetActiveScene().name == "UIInter_Switch23D")
            {
                return;
            }
            if (GUI.Button(new Rect(200, 100, 160, 60), "关闭"))
            {
                FARDll.CloseDown();
            }
        }
예제 #4
0
        private void SetupArCamTransform()
        {
            _camPoseMatrixInDisplaySpace = Matrix4x4.identity;

            string fViewJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FViewTool", "FView.json");

            if (!File.Exists(fViewJsonPath))
            {
                UnityEngine.Debug.LogError("FView.Awake():先使用工具软件进行罗技摄像头的标定!");
                return;
            }

            if (FARDll.fmFViewReadJson() == 0)
            {
                _viewPosition = Vector3.zero;
                int    size      = Marshal.SizeOf(_viewPosition);
                IntPtr structPtr = Marshal.AllocHGlobal(size);
                FARDll.fmFViewGetPosition(structPtr);
                _viewPosition = (Vector3)Marshal.PtrToStructure(structPtr, typeof(Vector3));
                Marshal.FreeHGlobal(structPtr);

                _viewRotation = Quaternion.identity;
                size          = Marshal.SizeOf(_viewRotation);
                structPtr     = Marshal.AllocHGlobal(size);
                FARDll.fmFViewGetRotation(structPtr);
                _viewRotation = (Quaternion)Marshal.PtrToStructure(structPtr, typeof(Quaternion));
                Marshal.FreeHGlobal(structPtr);

                _camPoseMatrixInDisplaySpace.SetTRS(_viewPosition * mrSystem.ViewerScale, _viewRotation, Vector3.one);
            }
            // transform.position = mrSystem.transform.localToWorldMatrix.MultiplyPoint(_viewPosition * mrSystem.ViewerScale);
            // transform.rotation = Quaternion.Euler(FCore.slantAngle, 0f, 0f) * mrSystem.transform.rotation * _viewRotation;
        }
예제 #5
0
        private IEnumerator CallPluginAtEndOfFrames()
        {
            while (curMode != ScreenManger.DualScreenMode.None)
            {
                yield return(new WaitForEndOfFrame());

                GL.IssuePluginEvent(FARDll.GetRenderEventFunc(), 1);
            }
        }
예제 #6
0
 ///<summary>
 ///通过f-ar接口读取屏幕信息后设置窗口位置
 ///</summary>
 ///<param name="farwin">投屏窗口句柄</param>
 ///<param name="preview">是否为3D预览窗口</param>
 public void UpdateWindowPos(IntPtr farwin)
 {
     F3Device.Screen.Monitor monitor = F3Device.DeviceManager.Instance.FindProjectionMonitor(Global.Instance.Data.MainWindowHandle);
     if (monitor != null)
     {
         F3Device.Screen.RECT rect = monitor.m_MonitorInfo.rcMonitor;
         FARDll.MoveWindow(farwin, rect.Left, rect.Top, rect.Width, rect.Height, true);
     }
     else
     {
         UnityEngine.Debug.LogError("没有找到投屏目标显示器");
     }
 }
예제 #7
0
        ///<summary>
        ///通过f-ar接口读取屏幕信息后设置窗口位置
        ///</summary>
        ///<param name="farwin">投屏窗口句柄</param>
        public void UpdateWindowPos(IntPtr farwin)
        {
            //可先切换到扩展模式
            //SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, (SDC_APPLY | SDC_TOPOLOGY_EXTEND));
            //更新物理显示器列表
            int temp_MonitorCount = FARDll.fmARGetMonitorCount();

            if (temp_MonitorCount < 0)
            {
                UnityEngine.Debug.LogError("Direct3DWin.UpdateWindowsPos() failed with error : fmARGetMonitorCount " + temp_MonitorCount);
            }

            if (temp_MonitorCount != 2)
            {
                UnityEngine.Debug.LogError("Direct3DWin.UpdateWindows() PosCurrent monitor count : " + temp_MonitorCount);
            }

            for (int k = 0; k < temp_MonitorCount; k++)
            {
                FARDll.GCinfo gcinfo = new FARDll.GCinfo();
                int           result = FARDll.fmARGetMonitorInfoByIndex(ref gcinfo, k);
                if (result >= 0)
                {
                    if (targetMonitorName != string.Empty)
                    {
                        if (gcinfo.DeviceName.Contains(targetMonitorName))
                        {
                            UnityEngine.Debug.Log("Direct3DWin.UpdateWindows():投屏显示器:" + gcinfo.DeviceName);
                            FARDll.MoveWindow(farwin, gcinfo.RCleft, gcinfo.RCtop, gcinfo.RCright - gcinfo.RCleft, gcinfo.RCbottom - gcinfo.RCtop, true);
                            return;
                        }
                    }
                    else
                    {
                        //获取一个非GC显示器
                        if (!gcinfo.isGCmonitor)
                        {
                            UnityEngine.Debug.Log("Direct3DWin.UpdateWindows():投屏显示器:" + gcinfo.DeviceName);
                            FARDll.MoveWindow(farwin, gcinfo.RCleft, gcinfo.RCtop, gcinfo.RCright - gcinfo.RCleft, gcinfo.RCbottom - gcinfo.RCtop, true);
                            return;
                        }
                    }
                }
                else
                {
                    UnityEngine.Debug.LogError("Direct3DWin.UpdateWindows() failed with error : fmARGetMonitorInfoByIndex" + result);
                }
            }
            UnityEngine.Debug.LogError("Direct3DWin.UpdateWindows() failed with error : 没有寻找到对应的显示器");
        }
예제 #8
0
 private void OnApplicationQuit()
 {
     //安全关闭投屏窗口,可根据需求调用
     FARDll.CloseDown();
 }
예제 #9
0
        ///启动投屏窗口进程
        private IEnumerator CreateFARWindow(WorkMode _workmode)
        {
            int temp_MonitorCount = FARDll.fmARUpdatePhysicalMonitor();

            if (temp_MonitorCount < 2)
            {
                UnityEngine.Debug.LogError("Direct3DWin.CreateFARWindow() failed with error : Monitor count less than 2");
            }
            //为了与主渲染进程不产生冲突,等待下一帧结束
            yield return(new WaitForEndOfFrame());

            if (FARDll.FindWindow(null, "ClientWinCpp") == IntPtr.Zero)
            {
                string           _path     = Path.Combine(Application.streamingAssetsPath, "ClientWin.exe");
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName    = _path;
                viewProcess           = new Process();
                viewProcess.StartInfo = startInfo;
                viewProcess.Start();
                _hViewClient = IntPtr.Zero;
            }
            while (true)
            {
                _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                if (_hViewClient != IntPtr.Zero)
                {
                    UnityEngine.Debug.Log("FAR.CreateFARWindow():找到了窗口句柄!");
                    //全屏到非GC显示器
                    UpdateWindowPos(_hViewClient);
                    int pid = 0;
                    FARDll.GetWindowThreadProcessId(_hViewClient, out pid);
                    if (pid == viewProcess.Id)
                    {
                        //设置当前的色彩空间,u3d默认是Gama空间
                        FARDll.SetColorSpace(FARDll.U3DColorSpace.Gama);
                        //开始绘制同屏窗口,如目标纹理指针变更可随时调用
                        switch (_workmode)
                        {
                        case WorkMode._SingleTexture:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTexture.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case WorkMode._DoubleTexture:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTextureL.GetNativeTexturePtr(), renderTextureR.GetNativeTexturePtr());
                            break;

                        default:
                            status = (FAR_Status)FARDll.StartView(_hViewClient, renderTexture.GetNativeTexturePtr(), IntPtr.Zero);
                            break;
                        }
                    }
                    break;
                }
            }
            if (status < 0)
            {
                UnityEngine.Debug.LogError("FAR.CreateFARWindow():投屏启动失败" + status);
                FARDll.CloseDown();
            }
            else
            {
                UnityEngine.Debug.Log("FAR.CreateFARWindow():开始绘图!");
            }
        }
예제 #10
0
        ///启动投屏窗口进程
        private IEnumerator CreateFARWindow()
        {
            //为了与主渲染进程不产生冲突,等待下一帧结束
            yield return(new WaitForEndOfFrame());

            try
            {
                _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                status       = FARDll.FAR_Status.FAR_NotInitialized;
                if (_hViewClient == IntPtr.Zero)
                {
                    string           _path     = System.IO.Path.Combine(Application.streamingAssetsPath, "ClientWin.exe");
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName           = _path;
                    FARDll.viewProcess           = new Process();
                    FARDll.viewProcess.StartInfo = startInfo;
                    FARDll.viewProcess.Start();
                    FARDll.viewProcess.WaitForInputIdle();
                    _hViewClient = FARDll.FindWindow(null, "ClientWinCpp");
                }
                if (FARDll.viewProcess != null)
                {
                    if (_hViewClient != IntPtr.Zero)
                    {
                        //全屏到非GC显示器
                        UpdateWindowPos(_hViewClient);
                        //开始绘制同屏窗口,如目标纹理指针变更可随时调用
                        switch (_curMode)
                        {
                        case ScreenManger.DualScreenMode.VR:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTexture3DLeft.GetNativeTexturePtr(), renderTexture3DRight.GetNativeTexturePtr());
                            break;

                        case ScreenManger.DualScreenMode.VR_2D:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTexture3DLeft.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case ScreenManger.DualScreenMode.AR_2D:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTextureAR.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        case ScreenManger.DualScreenMode.AR:
                            status = (FARDll.FAR_Status)FARDll.StartView(_hViewClient, renderTextureAR.GetNativeTexturePtr(), IntPtr.Zero);
                            break;

                        default:
                            FARDll.CloseDown();
                            break;
                        }
                    }
                }
                else
                {
                    status = FARDll.FAR_Status.FAR_GraphicsCardUnsupported;
                }

                if (status <= 0)
                {
                    UnityEngine.Debug.LogError("投屏启动失败" + status);
                    FARDll.CloseDown();
                }

                if (_hViewClient != IntPtr.Zero)
                {
                    if (Global.Instance.Event.CreateProjectionWindowEvent != null)
                    {
                        Global.Instance.Event.CreateProjectionWindowEvent(_hViewClient);
                    }
                }

                if (_GLIssueHandle != null)
                {
                    this.StopCoroutine(_GLIssueHandle);
                }
                _GLIssueHandle = this.StartCoroutine(CallPluginAtEndOfFrames());
            }
            catch (Exception e)
            {
                FARDll.CloseDown();
                UnityEngine.Debug.LogError("投屏启动失败" + e);
            }
        }