Beispiel #1
0
        void Update()
        {
            UpdateWhileWorking();

            if (EnableUnitySeeThrough)
            {
                SeeThrough.SRWork_SeeThrough.UpdateData();
            }

            // UpdateData will be called in ExtractMeshDataThread
            // Also we don't need to get depth data
            if (ViveSR_DualCameraImageRenderer.UpdateDepthMaterial)
            {
                Depth.SRWork_Depth.UpdateData();
            }
            if (EnableUnityDepthMesh)
            {
                if (DepthMesh.SRWork_Depth_Mesh.UpdateData())
                {
                    ((ViveSR_DualCameraDepthCollider)Modules[1]).ExtractMeshData();
                }
            }
            if (EnableUnityReconstruction &&
                !ViveSR_SceneUnderstanding.IsExportingSceneUnderstandingInfo &&
                !ViveSR_RigidReconstruction.IsExportingMesh)
            {
                if (RigidReconstruction.SRWork_Rigid_Reconstruciton.UpdateData())
                {
                    ((ViveSR_RigidReconstructionRenderer)Modules[2]).ExtractMeshData();
                }
            }
            if (ViveSR_RigidReconstruction.IsExportingMesh)
            {
                ViveSR_RigidReconstruction.UpdateExportProgress();
            }
            if (ViveSR_SceneUnderstanding.IsExportingSceneUnderstandingInfo)
            {
                ViveSR_SceneUnderstanding.UpdateSceneUnderstandingProgress();
            }
        }
        private void ReconstructionGUI()
        {
            GUIStyle StyleBold = new GUIStyle {
                fontStyle = FontStyle.Bold
            };

            GUILayout.Label(new GUIContent("[Runtime Command]"), StyleBold);        // start / stop
            GUILayout.Label(new GUIContent("--Start/Stop--"), StyleBold);
            if (!ViveSR_RigidReconstruction.IsScanning && !ViveSR_RigidReconstruction.IsExportingMesh)
            {
                if (GUILayout.Button("Start Reconstruction", GUILayout.ExpandWidth(false)))
                {
                    ViveSR_RigidReconstruction.StartScanning();
                }
            }
            if (ViveSR_RigidReconstruction.IsScanning && !ViveSR_RigidReconstruction.IsExportingMesh)
            {
                if (GUILayout.Button("Stop Reconstruction", GUILayout.ExpandWidth(false)))
                {
                    ViveSR_RigidReconstruction.StopScanning();
                }

                GUILayout.Label(new GUIContent("--Live Extraction--"), StyleBold);
                int curMode = (int)ViveSR_RigidReconstructionRenderer.LiveMeshDisplayMode;

                if (curMode != (int)ViveSR_RigidReconstructionRenderer.LiveMeshDisplayMode)
                {
                    ViveSR_RigidReconstructionRenderer.LiveMeshDisplayMode = (ReconstructionDisplayMode)curMode;
                }
                // adaptive tunning
                if (curMode == (int)ReconstructionDisplayMode.ADAPTIVE_MESH)
                {
                    GUILayout.Label(new GUIContent("--Live Adaptive Mesh Tuning--"), StyleBold);
                    DrawAdaptiveParamUI(ViveSR_RigidReconstruction.LiveAdaptiveMaxGridSize, ViveSR_RigidReconstruction.LiveAdaptiveMinGridSize, ViveSR_RigidReconstruction.LiveAdaptiveErrorThres);
                    ViveSR_RigidReconstruction.LiveAdaptiveMaxGridSize = adaptiveLevel[maxSelectID];
                    ViveSR_RigidReconstruction.LiveAdaptiveMinGridSize = adaptiveLevel[minSelectID];
                    ViveSR_RigidReconstruction.LiveAdaptiveErrorThres  = errorThres;
                }
            }

            // export
            if (ViveSR_RigidReconstruction.IsScanning && !ViveSR_RigidReconstruction.IsExportingMesh)
            {
                GUILayout.Label(new GUIContent("--Export--"), StyleBold);
                bool exportAdaptive = ViveSR_RigidReconstruction.ExportAdaptiveMesh;
                ViveSR_RigidReconstruction.ExportAdaptiveMesh = GUILayout.Toggle(exportAdaptive, "Export Adaptive Model");

                if (ViveSR_RigidReconstruction.ExportAdaptiveMesh)
                {
                    // live extraction mode
                    GUILayout.Label(new GUIContent("--Export Adaptive Mesh Tuning--"), StyleBold);
                    DrawAdaptiveParamUI(ViveSR_RigidReconstruction.ExportAdaptiveMaxGridSize, ViveSR_RigidReconstruction.ExportAdaptiveMinGridSize, ViveSR_RigidReconstruction.ExportAdaptiveErrorThres);
                    ViveSR_RigidReconstruction.ExportAdaptiveMaxGridSize = adaptiveLevel[maxSelectID];
                    ViveSR_RigidReconstruction.ExportAdaptiveMinGridSize = adaptiveLevel[minSelectID];
                    ViveSR_RigidReconstruction.ExportAdaptiveErrorThres  = errorThres;
                }

                if (GUILayout.Button("Start Export Model", GUILayout.ExpandWidth(false)))
                {
                    ViveSR_RigidReconstruction.ExportModel("Model");
                }
            }
        }
        private void ExtractMeshDataThread()
        {
            while (IsThreadRunning == true)
            {
                try
                {
                    if (IsMeshUpdate == false && ViveSR_RigidReconstruction.IsDuringScannedMeshPreview)
                    {
                        if (RigidReconstruction.SRWork_Rigid_Reconstruciton.UpdateData())
                        {
                            bool result = ViveSR_RigidReconstruction.GetScannedModelPreviewData(
                                ref ModelChunkNum, ref ModelChunkIdx, ref VertexNum, out VertexData, ref IndexNum, out IndexData);

                            if (result)
                            {
                                lock (MeshLock) {
                                    if (VertexNum > 0)
                                    {
                                        UpdateMeshesDataList();
                                    }

                                    if (ModelPreviewIsCompleted())
                                    {
                                        SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.MODEL_PREVIEW_FINISH), true); // to stop getting data from SRWorks
                                        ModelChunkNum = 0;
                                    }
                                    else
                                    {
                                        SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.MODEL_PREVIEW_NEXT_CHUNK), true);
                                    }
                                }
                            }
                        }
                    }
                    else if (IsMeshUpdate == false && ViveSR_RigidReconstruction.IsScanning == true)
                    {
                        if (RigidReconstruction.SRWork_Rigid_Reconstruciton.UpdateData())
                        {
                            bool result = ViveSR_RigidReconstruction.GetRigidReconstructionFrame(ref ProcessedFrame);
                            if (ProcessedFrame != LastProcessedFrame && result == true)
                            {
                                LastProcessedFrame = ProcessedFrame;
                                float[] _camPose;

                                result = ViveSR_RigidReconstruction.GetRigidReconstructionData(
                                    ref ProcessedFrame, out _camPose, ref VertexNum, out VertexData, ref VertStrideInFloat,
                                    out SectorIDList, ref SectorNum, out SectorVertNum, out SectorMeshIdNum, ref IndexNum, out IndexData);

                                if (result == true)
                                {
                                    lock (MeshLock) {
                                        NumSubMeshes       = 0;
                                        LastProcessedFrame = ProcessedFrame;

                                        if (LiveMeshDisplayMode != ReconstructionDisplayMode.ADAPTIVE_MESH)
                                        {
                                            UpdatePointCloudDataList();
                                        }
                                        else if (IndexNum > 0)
                                        {
                                            UpdateMeshesDataList();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (System.Exception e)
                {
                    NumSubMeshes = 0;
                    Debug.LogWarning(e.Message);
                }

                Thread.Sleep(ThreadPeriod); //Avoid too fast get data from SR SDK DLL
            }
        }