public override bool Release()
        {
            if (!ViveSR.EnableUnityReconstruction)
            {
                return(false);
            }
            ViveSR_RigidReconstruction.StopScanning();
            ViveSR_SceneUnderstanding.ResetParameter();
            IsThreadRunning = false;
            if (MeshDataThread != null)
            {
                MeshDataThread.Join();
                MeshDataThread.Abort();
                MeshDataThread = null;
            }
            if (IsCoroutineRunning == true)
            {
                StopCoroutine(MeshDataCoroutine);
                MeshDataCoroutine = null;
            }
            ViveSR_RigidReconstruction.ReleaseAllocOutputDataMemory();

            foreach (KeyValuePair <int, GameObject> data in ShowGameObjs)
            {
                int id = data.Key;

                MeshDataVertices[id].Clear();
                MeshDataIndices[id].Clear();
                MeshDataColors[id].Clear();
                MeshDataNormals[id].Clear();
            }
            OrderedList.Clear();
            MeshDataVertices.Clear();
            MeshDataIndices.Clear();
            MeshDataColors.Clear();
            MeshDataNormals.Clear();
            HideAllLiveMeshes();
            DestroyLiveMeshes();
            ResetParameter();
            return(true);
        }
Пример #2
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();
            }
        }
Пример #3
0
        // data pre-proc
        static public bool ProcessDataAndGenColliderInfo(GameObject go)
        {
            // organize and category collider type
            bool hasCollider = false;

            MeshFilter[] mFilters = go.GetComponentsInChildren <MeshFilter>();
            int          numRnds  = mFilters.Length;

            for (int id = 0; id < numRnds; ++id)
            {
                ViveSR_StaticColliderInfo    cldInfo       = mFilters[id].gameObject.AddComponent <ViveSR_StaticColliderInfo>();
                SceneUnderstandingObjectType semantic_type = ViveSR_SceneUnderstanding.GetSemanticTypeFromObjName(go.name);
                cldInfo.SemanticType = semantic_type;
                if (semantic_type != SceneUnderstandingObjectType.NONE)
                {
                    string s_idx = go.name.Replace(ViveSR_SceneUnderstanding.SemanticTypeToString(semantic_type) + "_", "").Replace("_cld", "");
                    cldInfo.SceneObjectID = int.Parse(s_idx);
                }

                string meshName  = mFilters[id].name;
                string newName   = "";
                bool   thisIsCLD = false;

                if (meshName.Contains("PlaneConvexCollider"))
                {
                    newName = "PlaneConvexCollider";
                    cldInfo.SetBit((int)ColliderShapeType.CONVEX_SHAPE);
                    thisIsCLD = true;
                }
                else if (meshName.Contains("PlaneBBCollider"))
                {
                    newName = "PlaneBBCollider";
                    cldInfo.SetBit((int)ColliderShapeType.BOUND_RECT_SHAPE);
                    thisIsCLD = true;
                }
                else if (meshName.Contains("PlaneMeshCollider"))
                {
                    newName = "PlaneMeshCollider";
                    cldInfo.SetBit((int)ColliderShapeType.MESH_SHAPE);
                    thisIsCLD = true;
                }

                if (meshName.Contains("Horizontal"))
                {
                    cldInfo.SetBit((int)PlaneOrientation.HORIZONTAL);
                }
                else if (meshName.Contains("Vertical"))
                {
                    cldInfo.SetBit((int)PlaneOrientation.VERTICAL);
                }
                else
                {
                    cldInfo.SetBit((int)PlaneOrientation.OBLIQUE);
                }

                hasCollider = (hasCollider || thisIsCLD);
                if (!thisIsCLD)
                {
                    Component.DestroyImmediate(cldInfo);
                }
                else
                {
                    // parse area
                    int areaStringStartIdx = meshName.LastIndexOf("Area_");
                    if (areaStringStartIdx != -1)
                    {
                        areaStringStartIdx = areaStringStartIdx + 5;
                        string curString        = meshName.Substring(areaStringStartIdx);
                        int    areaStringEndIdx = curString.IndexOf("_");
                        cldInfo.ApproxArea = float.Parse(curString.Substring(0, areaStringEndIdx));
                    }
                    else
                    {
                        cldInfo.SetBit((int)PlaneOrientation.FRAGMENT);
                    }

                    // parse normal
                    int normalStringStartIdx = meshName.LastIndexOf("Normal_");
                    if (normalStringStartIdx != -1)
                    {
                        normalStringStartIdx = normalStringStartIdx + 7;
                        string curString     = meshName.Substring(normalStringStartIdx);
                        int    normalXEndIdx = curString.IndexOf("_");
                        cldInfo.GroupNormal.x = float.Parse(curString.Substring(0, normalXEndIdx));

                        curString = curString.Substring(normalXEndIdx + 1);
                        int normalYEndIdx = curString.IndexOf("_");
                        cldInfo.GroupNormal.y = float.Parse(curString.Substring(0, normalYEndIdx));

                        curString = curString.Substring(normalYEndIdx + 1);
                        int normalZEndIdx = curString.IndexOf("_");
                        cldInfo.GroupNormal.z = float.Parse(curString.Substring(0, normalZEndIdx));
                    }

                    // parse right axis
                    int rightStringStartIdx = meshName.LastIndexOf("Right_");
                    if (rightStringStartIdx != -1)
                    {
                        rightStringStartIdx = rightStringStartIdx + 6;
                        string curString    = meshName.Substring(rightStringStartIdx);
                        int    rightXEndIdx = curString.IndexOf("_");
                        cldInfo.RectRightAxis.x = float.Parse(curString.Substring(0, rightXEndIdx));

                        curString = curString.Substring(rightXEndIdx + 1);
                        int rightYEndIdx = curString.IndexOf("_");
                        cldInfo.RectRightAxis.y = float.Parse(curString.Substring(0, rightYEndIdx));

                        curString = curString.Substring(rightYEndIdx + 1);
                        int rightZEndIdx = curString.IndexOf("_");
                        cldInfo.RectRightAxis.z = float.Parse(curString.Substring(0, rightZEndIdx));
                    }

                    // parse width height
                    int whStringStartIdx = meshName.LastIndexOf("WH_");
                    if (whStringStartIdx != -1)
                    {
                        whStringStartIdx = whStringStartIdx + 3;
                        string curString   = meshName.Substring(whStringStartIdx);
                        int    widthEndIdx = curString.IndexOf("_");
                        cldInfo.RectWidth = float.Parse(curString.Substring(0, widthEndIdx));

                        curString = curString.Substring(widthEndIdx + 1);
                        int heightEndIdx = curString.IndexOf("_");
                        cldInfo.RectHeight = float.Parse(curString.Substring(0, heightEndIdx));
                    }

                    // parse id
                    int idxStringStartIdx = meshName.LastIndexOf("_");
                    cldInfo.PlaneID = (int.Parse(meshName.Substring(idxStringStartIdx + 1)));
                    newName         = newName + "_" + meshName.Substring(idxStringStartIdx + 1);
                    mFilters[id].gameObject.name = newName;
                }
            }

            return(hasCollider);
        }
        private void SceneUnderstandingGUI()
        {
            GUIStyle StyleBold = new GUIStyle {
                fontStyle = FontStyle.Bold
            };

            GUILayout.Label(new GUIContent("--Scene Understanding--"), StyleBold);
            if (ViveSR_RigidReconstruction.IsScanning)
            {
                bool isSemanticEnabled = GUILayout.Toggle(ViveSR_SceneUnderstanding.IsEnabledSceneUnderstanding, "Enable Scene Understanding");
                if (isSemanticEnabled != ViveSR_SceneUnderstanding.IsEnabledSceneUnderstanding)
                {
                    ViveSR_SceneUnderstanding.EnableSceneUnderstanding(isSemanticEnabled);
                }
                bool isSemanticRefinementEnabled = GUILayout.Toggle(ViveSR_SceneUnderstanding.IsEnabledSceneUnderstandingRefinement, "Enable Scene Understanding Refinement");
                if (isSemanticRefinementEnabled != ViveSR_SceneUnderstanding.IsEnabledSceneUnderstandingRefinement)
                {
                    ViveSR_SceneUnderstanding.EnableSceneUnderstandingRefinement(isSemanticRefinementEnabled);
                }
            }
            else
            {
                GUILayout.Label(new GUIContent("Please Start Reconstruction"), StyleBold);
            }
            if (ViveSR_SceneUnderstanding.IsEnabledSceneUnderstanding && ViveSR_RigidReconstruction.IsScanning)
            {
                GUILayout.Label(new GUIContent("--Scene Understanding Live Dispaly & Export--"), StyleBold);
                bool isSemanticPreviewEnabled = GUILayout.Toggle(ViveSR_SceneUnderstanding.IsEnabledSceneUnderstandingView, "Enable Preview");
                if (isSemanticPreviewEnabled != ViveSR_SceneUnderstanding.IsEnabledSceneUnderstandingView)
                {
                    ViveSR_SceneUnderstanding.EnableSceneUnderstandingView(isSemanticPreviewEnabled);
                }
                int index = 0;
                foreach (bool toggle in SceneObjectToggle)
                {
                    bool _toggle = GUILayout.Toggle(toggle, "View/Export " + SceneObjectName[index]);
                    if (_toggle != toggle)
                    {
                        SceneObjectToggle[index] = _toggle;
                        switch (SceneObjectName[index])
                        {
                        case "Bed":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.BED, 5, _toggle);
                            break;

                        case "Ceiling":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.CEILING, 5, _toggle);
                            break;

                        case "Chair":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.CHAIR, 5, _toggle);
                            break;

                        case "Floor":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.FLOOR, 5, _toggle);
                            break;

                        case "Table":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.TABLE, 5, _toggle);
                            break;

                        case "Wall":
                            ViveSR_SceneUnderstanding.SetCustomSceneUnderstandingConfig((int)SceneUnderstandingObjectType.WALL, 5, _toggle);
                            break;
                        }
                    }
                    index++;
                }
            }

            if (ViveSR_SceneUnderstanding.IsEnabledSceneUnderstanding && ViveSR_RigidReconstruction.IsScanning)
            {
                if (GUILayout.Button("Export SceneObjects (.xml)", GUILayout.ExpandWidth(false)))
                {
                    ViveSR_SceneUnderstanding.ExportSceneUnderstandingInfo(SemanticObjDir);
                }
            }
            GUILayout.Label(new GUIContent("--SceneObjects Operation--"), StyleBold);
            if (GUILayout.Button("Load & Show SceneObjects BoundingBox", GUILayout.ExpandWidth(false)))
            {
                SemanticObjDirPath = ReconsSceneDir + SemanticObjDir;
                ViveSR_SceneUnderstanding.ImportSceneObjects(SemanticObjDirPath);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.CHAIR, true, true);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.CEILING, true, true);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.FLOOR, true, true);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.WALL, true, true);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.BED, true, true);
                ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithType((int)SceneUnderstandingObjectType.TABLE, true, true);
            }
            if (GUILayout.Button("Destroy All SceneObjects BoundingBox", GUILayout.ExpandWidth(false)))
            {
                ViveSR_SceneUnderstanding.DestroySceneObjects();
            }
        }