public static void ExportModel(string filename)
        {
            ExportStage      = 0;
            ExportPercentage = 0;
            ExportError      = (int)Error.WORK;
            IsExportingMesh  = true;
            IsScannedMeshPreviewCompleted = false;

            SRWorkModule_API.SetReconstructionParameterBool((int)ReconstructionParam.EXPORT_ADAPTIVE_MODEL, ExportAdaptiveMesh);
            if (ExportAdaptiveMesh)
            {
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MAX_GRID, ExportAdaptiveMaxGridSize * 0.01f);   // cm to m
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MIN_GRID, ExportAdaptiveMinGridSize * 0.01f);
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_ERROR_THRES, ExportAdaptiveErrorThres);
            }

            //if ((int)Error.WORK != SRWorkModule_API.RegisterReconstructionCallback(Marshal.GetFunctionPointerForDelegate((ExportProgressCallback)UpdateExportProgress)))
            //    Debug.Log("[ViveSR] [ExportModel] Progress listener failed to register");
            //ViveSR_Framework.RegisterCallback(ViveSR_Framework.MODULE_ID_RIGID_RECONSTRUCTION, (int)ReconstructionCallback.EXPORT_PROGRESS, Marshal.GetFunctionPointerForDelegate((ExportProgressCallback)UpdateExportProgress));

            byte[] bytearray = System.Text.Encoding.ASCII.GetBytes(filename);
            IntPtr parameter = Marshal.AllocCoTaskMem(filename.Length);

            Marshal.Copy(bytearray, 0, parameter, filename.Length);

            SRWorkModule_API.SetReconstructionOutputFileName(parameter, filename.Length);
        }
示例#2
0
        public static void EnableSceneUnderstandingView(bool enable)
        {
            int result = 0;

            if (!ViveSR_RigidReconstruction.IsScanning)
            {
                return;
            }

            result = SRWorkModule_API.SetReconstructionParameterBool((int)ReconstructionParam.SCENE_UNDERSTANDING_MACHINE_VISION, enable);
            if (result == (int)Error.WORK)
            {
                IsEnabledSceneUnderstandingView = enable;
                Debug.Log("[ViveSR] [Scene Understanding] Preview " + (enable ? "enabled" : "disabled"));

                if (IsEnabledSceneUnderstandingView)
                {
                    ViveSR_RigidReconstructionRenderer.EnableSector       = false;
                    ViveSR_RigidReconstructionRenderer.SetWireFrameOpaque = false;
                }
                else
                {
                    // ViveSR_RigidReconstructionRenderer.EnableSector = true;
                    ViveSR_RigidReconstructionRenderer.SetWireFrameOpaque = true;

                    ResetSceneUnderstandingProgress();
                }
            }
        }
示例#3
0
        public static void EnableSceneUnderstanding(bool enable)
        {
            int result = SRWorkModule_API.SetReconstructionParameterBool((int)ReconstructionParam.SCENE_UNDERSTANDING_ENABLE, enable);

            if (result == (int)Error.WORK)
            {
                IsEnabledSceneUnderstanding = enable;
            }
            else
            {
                Debug.Log("[ViveSR] [Scene Understanding] Activation/Deactivation failed");
                return;
            }

            if (IsEnabledSceneUnderstanding)
            {
                //result = ViveSR_Framework.RegisterCallback(ViveSR_Framework.MODULE_ID_RIGID_RECONSTRUCTION, (int)ReconstructionCallback.SCENE_UNDERSTANDING_PROGRESS, Marshal.GetFunctionPointerForDelegate((ExportProgressCallback)UpdateSceneUnderstandingProgress));
                if (result != (int)Error.WORK)
                {
                    Debug.Log("[ViveSR] [Scene Understanding] Progress listener failed to register");
                }
            }
            else if (IsEnabledSceneUnderstandingView)
            {
                EnableSceneUnderstandingView(false);
            }
        }
 public static void StopScanning()
 {
     if (ReconstructionProcessing)
     {
         IsScanning = false;
         SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.STOP), true);
         Debug.Log("stop");
     }
     ViveSR_RigidReconstruction.EnableReconstructionProcess(false);
 }
 public static void StartScanning()
 {
     ViveSR_RigidReconstruction.EnableReconstructionProcess(true);
     if (ReconstructionProcessing)
     {
         SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.START), true);
         IsScanning = true;
         IsScannedMeshPreviewCompleted = false;
         Debug.Log("start");
     }
 }
        private bool UpdateRuntimeParameter()
        {
            bool result = true;
            int  ret    = (int)Error.FAILED;

            // check live mesh display mode
            if (ViveSR_SceneUnderstanding.IsEnabledSceneUnderstandingView || ViveSR_RigidReconstruction.IsDuringScannedMeshPreview)
            {
                LiveMeshDisplayMode = ReconstructionDisplayMode.ADAPTIVE_MESH; //support only in this mode
            }
            // update live mesh display mode
            if ((int)LiveMeshDisplayMode != LastLiveMeshDisplayMode)
            {
                HideAllLiveMeshes();
                result = SetMeshDisplayMode(LiveMeshDisplayMode) && result;
                LastLiveMeshDisplayMode = (int)LiveMeshDisplayMode;
                // refresh rate
                SRWorkModule_API.SetReconstructionParameterInt((int)ReconstructionParam.MESH_REFRESH_INTERVAL, RefreshIntervalMS);

                // full scene quality
                if (LiveMeshDisplayMode == ReconstructionDisplayMode.FULL_SCENE)
                {
                    ret = SRWorkModule_API.SetReconstructionParameterInt((int)(ReconstructionParam.CONFIG_QUALITY), (int)FullSceneQuality);
                    LiveMeshMaterial.SetFloat("_PointSizeScaler", (FullSceneQuality == ReconstructionQuality.LOW) ? 1.2f : 0.8f);
                    result = result && (ret == (int)Error.WORK);
                }
                // update live adaptive param
                if (LiveMeshDisplayMode == ReconstructionDisplayMode.ADAPTIVE_MESH)
                {
                    ret    = SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MAX_GRID, ViveSR_RigidReconstruction.LiveAdaptiveMaxGridSize * 0.01f); // cm to m
                    result = result && (ret == (int)Error.WORK);
                    ret    = SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MIN_GRID, ViveSR_RigidReconstruction.LiveAdaptiveMinGridSize * 0.01f);
                    result = result && (ret == (int)Error.WORK);
                    ret    = SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_ERROR_THRES, ViveSR_RigidReconstruction.LiveAdaptiveErrorThres);
                    result = result && (ret == (int)Error.WORK);
                }
            }

            if (EnableSector != LastEnableSector)
            {
                HideAllLiveMeshes();
                SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.ENABLE_FRUSTUM_CULLING), EnableSector);
                SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.ENABLE_SECTOR_GROUPER), EnableSector);
                SRWorkModule_API.SetReconstructionParameterFloat((int)(ReconstructionParam.SECTOR_SIZE), SectorSizeInMeter);
                LastEnableSector = EnableSector;
            }

            if (SetWireFrameOpaque != LastSetWireFrameOpaque)
            {
                WireframeMaterial.SetFloat("_Opaque", SetWireFrameOpaque ? 1.0f : 0.0f);
                LastSetWireFrameOpaque = SetWireFrameOpaque;
            }
            return(result);
        }
        public bool SetMeshDisplayMode(ReconstructionDisplayMode displayMode)
        {
            ResetData();

            int result = (int)Error.FAILED;

            if (displayMode == ReconstructionDisplayMode.FIELD_OF_VIEW)
            {
                SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.ENABLE_FRUSTUM_CULLING), false);
                SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.ENABLE_SECTOR_GROUPER), false);
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LITE_POINT_CLOUD_MODE), true);
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.FULL_POINT_CLOUD_MODE), false);
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LIVE_ADAPTIVE_MODE), false);
                LiveMeshMaterial.SetFloat("_PointSizeScaler", 1.2f);
                UsingMaterial     = LiveMeshMaterial;
                ThreadPeriod      = 15;
                BackupSectorValue = EnableSector;
                EnableSector      = false;
            }
            else if (displayMode == ReconstructionDisplayMode.FULL_SCENE)
            {
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LITE_POINT_CLOUD_MODE), false);
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.FULL_POINT_CLOUD_MODE), true);
                result = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LIVE_ADAPTIVE_MODE), false);
                LiveMeshMaterial.SetFloat("_PointSizeScaler", (FullSceneQuality == ReconstructionQuality.LOW) ? 1.3f : 0.8f);
                UsingMaterial = LiveMeshMaterial;
                ThreadPeriod  = 300;
                EnableSector  = BackupSectorValue;
            }
            else if (displayMode == ReconstructionDisplayMode.ADAPTIVE_MESH)
            {
                result        = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LITE_POINT_CLOUD_MODE), false);
                result        = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.FULL_POINT_CLOUD_MODE), false);
                result        = SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionParam.LIVE_ADAPTIVE_MODE), true);
                UsingMaterial = WireframeMaterial;
                ThreadPeriod  = 300;
                EnableSector  = BackupSectorValue;
            }
            foreach (KeyValuePair <int, GameObject> go in ShowGameObjs)
            {
                go.Value.GetComponent <MeshRenderer>().sharedMaterial = UsingMaterial;
            }

            if (result == (int)Error.WORK)
            {
                LiveMeshDisplayMode = displayMode;
            }

            return(result == (int)Error.WORK);
        }
示例#8
0
        public static void EnableSceneUnderstandingRefinement(bool enable)
        {
            int result;

            result = SRWorkModule_API.SetReconstructionParameterBool((int)ReconstructionParam.SCENE_UNDERSTANDING_REFINEMENT, enable);
            if (result == (int)Error.WORK)
            {
                IsEnabledSceneUnderstandingRefinement = enable;
                //Debug.Log("[ViveSR] [Scene Understanding] Refinement " + (enable ? "enabled" : "disabled"));
            }
            else
            {
                Debug.Log("[ViveSR] [Scene Understanding] Setting Refinement failed");
            }
        }
        public static void ExtractModelPreviewData()
        {
            ExportStage                = 0;
            ScannedMeshPreview         = 0;
            IsDuringScannedMeshPreview = true;

            SRWorkModule_API.SetReconstructionParameterBool((int)ReconstructionParam.EXPORT_ADAPTIVE_MODEL, ExportAdaptiveMesh);
            if (ExportAdaptiveMesh)
            {
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MAX_GRID, ExportAdaptiveMaxGridSize * 0.01f);   // cm to m
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_MIN_GRID, ExportAdaptiveMinGridSize * 0.01f);
                SRWorkModule_API.SetReconstructionParameterFloat((int)ReconstructionParam.ADAPTIVE_ERROR_THRES, ExportAdaptiveErrorThres);
            }
            SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.MODEL_PREVIEW_START_FOR_UNITY), true);
        }
 public static void EnableLiveMeshExtraction(bool enable)
 {
     SRWorkModule_API.SetReconstructionParameterBool((int)(ReconstructionCmd.EXTRACT_POINT_CLOUD), enable);
 }
        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
            }
        }