Пример #1
0
        public static bool ShowSemanticBoundingBoxAndIconWithType(SceneUnderstandingObjectType objType, bool boxIsVisible, bool iconIsVisible)
        {
            bool found = false;

            foreach (SceneObject ssobj in ShowSceneObjects)
            {
                if (ssobj.objTypeID == objType)
                {
                    found = true;
                    foreach (GameObject obj in ssobj.BoundingBoxGameObj)
                    {
                        if (obj != null)
                        {
                            obj.SetActive(boxIsVisible);
                        }
                    }
                    foreach (GameObject obj in ssobj.IconGameObj)
                    {
                        if (obj != null)
                        {
                            obj.SetActive(iconIsVisible);
                        }
                    }
                }
            }
            return(found);
        }
Пример #2
0
 public static string SemanticTypeToString(SceneUnderstandingObjectType type)
 {
     if (type == SceneUnderstandingObjectType.FLOOR)
     {
         return("Floor");
     }
     else if (type == SceneUnderstandingObjectType.WALL)
     {
         return("Wall");
     }
     else if (type == SceneUnderstandingObjectType.CEILING)
     {
         return("Ceiling");
     }
     else if (type == SceneUnderstandingObjectType.CHAIR)
     {
         return("Chair");
     }
     else if (type == SceneUnderstandingObjectType.TABLE)
     {
         return("Table");
     }
     else if (type == SceneUnderstandingObjectType.BED)
     {
         return("Bed");
     }
     else
     {
         return("NONE");
     }
 }
Пример #3
0
        public void LoadSemanticMeshByType(SceneUnderstandingObjectType type, System.Action beforeLoad = null, System.Action done = null)
        {
            if (SemanticMeshIsLoading)
            {
                return;
            }

            if (SemanticMeshIsLoaded)
            {
                UnloadSemanticMesh();
            }

            _semanticMeshIsLoading = true;

            if (beforeLoad != null)
            {
                beforeLoad();
            }
            SemanticMeshReadyCallback = done;

            GameObject[] semanticObjs = SemanticMeshLoader.LoadSemanticColliderObjsByType(semanticObj_dirPath, type);
            foreach (GameObject go in semanticObjs)
            {
                go.SetActive(false);
                semanticList.Add(go);
            }
            StartCoroutine(waitForSemanticMeshLoad());
        }
Пример #4
0
 public static string SemanticTypeToString(SceneUnderstandingObjectType type)
 {
     if (type == SceneUnderstandingObjectType.FLOOR)
     {
         return("Floor");
     }
     else if (type == SceneUnderstandingObjectType.WALL)
     {
         return("Wall");
     }
     else if (type == SceneUnderstandingObjectType.CEILING)
     {
         return("Ceiling");
     }
     else if (type == SceneUnderstandingObjectType.CHAIR)
     {
         return("Chair");
     }
     else if (type == SceneUnderstandingObjectType.TABLE)
     {
         return("Table");
     }
     else if (type == SceneUnderstandingObjectType.BED)
     {
         return("Bed");
     }
     else if (type == SceneUnderstandingObjectType.MONITOR)
     {
         return("Monitor");
     }
     else if (type == SceneUnderstandingObjectType.WINDOW)
     {
         return("Window");
     }
     else if (type == SceneUnderstandingObjectType.FURNITURE)
     {
         return("Furniture");
     }
     else if (type == SceneUnderstandingObjectType.DOOR)
     {
         return("Door");
     }
     else if (type == SceneUnderstandingObjectType.PICTURE)
     {
         return("Picture");
     }
     else if (type == SceneUnderstandingObjectType.PERSON)
     {
         return("Person");
     }
     else
     {
         return("NONE");
     }
 }
Пример #5
0
        public SceneUnderstandingObjectType GetSemanticType()
        {
            SceneUnderstandingObjectType type = SceneUnderstandingObjectType.NONE;

            if (numClds > 0 && allColliders[0].SemanticType != type)
            {
                type = allColliders[0].SemanticType;
            }

            return(type);
        }
Пример #6
0
        public static List <Vector3> GetPlacedPositionsByType(SceneUnderstandingObjectType objType)
        {
            List <Vector3> positions = new List <Vector3>();

            foreach (SceneObject obj in ShowSceneObjects)
            {
                if (obj.objTypeID == objType)
                {
                    positions.AddRange(obj.positions);
                }
            }
            return(positions);
        }
Пример #7
0
        public static string[] GetColliderFileNamesByType(SceneUnderstandingObjectType objType)
        {
            List <string> nameList = new List <string>();

            foreach (SceneObject obj in ShowSceneObjects)
            {
                if (objType == obj.objTypeID)
                {
                    nameList.Add(obj.cldFileName);
                }
            }

            return(nameList.ToArray());
        }
Пример #8
0
            public void Clear()
            {
                objTypeID   = SceneUnderstandingObjectType.NONE;
                objID       = -1;
                objFileName = "";
                cldFileName = "";
                forward     = new Vector3();

                if (positions == null)
                {
                    positions = new List <Vector3>();
                }
                else
                {
                    positions.Clear();
                }

                if (BoundingBoxGameObj == null)
                {
                    BoundingBoxGameObj = new List <GameObject>();
                }
                else
                {
                    foreach (GameObject obj in BoundingBoxGameObj)
                    {
                        if (obj != null)
                        {
                            GameObject.Destroy(obj);
                        }
                    }
                    BoundingBoxGameObj.Clear();
                }

                if (IconGameObj == null)
                {
                    IconGameObj = new List <GameObject>();
                }
                else
                {
                    foreach (GameObject obj in IconGameObj)
                    {
                        if (obj != null)
                        {
                            GameObject.Destroy(obj);
                        }
                    }
                    IconGameObj.Clear();
                }
            }
Пример #9
0
 public void ShowSemanticColliderByType(SceneUnderstandingObjectType type)
 {
     foreach (GameObject go in semanticList)
     {
         ViveSR_StaticColliderPool pool = go.GetComponent <ViveSR_StaticColliderPool>();
         if (type != SceneUnderstandingObjectType.NONE && pool.GetSemanticType() == type)
         {
             if (pool == null)
             {
                 _WaitForSemanticCldPoolToShow(go);
             }
             else
             {
                 pool.ShowAllColliderWithPropsAndCondition(new uint[] { (uint)ColliderShapeType.MESH_SHAPE });
             }
         }
     }
 }
        public void TriggerPressUp()
        //public SceneUnderstandingObjectType TriggerPressUp()
        {
            SceneUnderstandingObjectType type = SceneUnderstandingObjectType.NONE;

            isTriggerDown        = false;
            lineRenderer.enabled = false;
            boundingBox.SetActive(false);
            //if (raycastMode == RaycastMode.ValidHit)
            //{
            //    ViveSR_StaticColliderPool cldPool = hitCldInfo.gameObject.transform.root.GetComponent<ViveSR_StaticColliderPool>();
            //    type = hitCldInfo.SemanticType;

            //    if (enablePlacer) PlaceObjects(ViveSR_SceneUnderstanding.GetPlacedPositionsByID((int)type, hitCldInfo.SceneObjectID));

            //    cldPool.ShowAllColliderWithPropsAndCondition(new uint[] { (uint)ColliderShapeType.MESH_SHAPE });
            //    ViveSR_SceneUnderstanding.ShowSemanticBoundingBoxAndIconWithId((int)type, hitCldInfo.SceneObjectID, true, true);
            //}
            //return type;
        }
Пример #11
0
        public void ShowSemanticColliderByType(SceneUnderstandingObjectType type)
        {
            if (type == SceneUnderstandingObjectType.NONE)
            {
                return;
            }

            foreach (GameObject go in semanticList)
            {
                WaitForSemanticCldPool(go, () => {
                    ViveSR_StaticColliderPool pool = go.GetComponent <ViveSR_StaticColliderPool>();
                    {
                        if (pool.GetSemanticType() == type)
                        {
                            pool.ShowAllColliderWithPropsAndCondition(new uint[] { (uint)ColliderShapeType.MESH_SHAPE });
                        }
                    }
                });
            }
        }
        public GameObject[] LoadSemanticColliderObjsByType(string dirPath, SceneUnderstandingObjectType type)
        {
            isAllColliderReady = false;

            ViveSR_SceneUnderstanding.ImportSceneObjects(dirPath); // read data from xml

            List <GameObject> outputObjs = new List <GameObject>();
            DirectoryInfo     dir        = new DirectoryInfo(dirPath);

            if (!dir.Exists)
            {
                Debug.Log(dirPath + " does not exist.");
            }
            else
            {
                string[] fileNames = ViveSR_SceneUnderstanding.GetColliderFileNamesByType(type);
                for (int i = 0; i < fileNames.Length; i++)
                {
                    FileInfo file = new FileInfo(dirPath + "/" + fileNames[i]);
                    //Debug.Log(file.FullName);
                    if (!file.Exists)
                    {
                        Debug.Log(file.FullName + " does not exist.");
                        if (i == fileNames.Length - 1)
                        {
                            isAllColliderReady = true;
                            return(outputObjs.ToArray());
                        }
                        else
                        {
                            continue;
                        }
                    }

                    GameObject go = OBJLoader.LoadOBJFile(file.FullName, LoadColliderDoneCallBack);
                    go.SetActive(false);
                    outputObjs.Add(go);
                }
            }
            return(outputObjs.ToArray());
        }
Пример #13
0
        public GameObject[] GetSemanticObjects(SceneUnderstandingObjectType type)
        {
            List <GameObject> objList = new List <GameObject>();

            if (type != SceneUnderstandingObjectType.NONE)
            {
                foreach (GameObject go in semanticList)
                {
                    ViveSR_StaticColliderPool pool = go.GetComponent <ViveSR_StaticColliderPool>();
                    if (pool == null)
                    {
                        Debug.Log("[SemanticSegmentation] Semantic object is not loaded completely.");
                        break;
                    }
                    if (pool.GetSemanticType() == type)
                    {
                        objList.Add(go);
                    }
                }
            }
            return(objList.ToArray());
        }
Пример #14
0
        public static void ShowSemanticBoundingBoxAndIconWithId(SceneUnderstandingObjectType objType, int objId, bool IsShowingBox, bool IsShowingIcon)
        {
            foreach (SceneObject ssobj in ShowSceneObjects)
            {
                if (ssobj.objTypeID == objType && ssobj.objID == objId)
                {
                    foreach (GameObject obj in ssobj.BoundingBoxGameObj)
                    {
                        if (obj != null)
                        {
                            obj.SetActive(IsShowingBox);
                        }
                    }

                    foreach (GameObject obj in ssobj.IconGameObj)
                    {
                        if (obj != null)
                        {
                            obj.SetActive(IsShowingIcon);
                        }
                    }
                }
            }
        }
Пример #15
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);
        }
Пример #16
0
        public List <SceneUnderstandingObjects.Element> GetSegmentationInfo(SceneUnderstandingObjectType type)
        {
            SceneUnderstandingObjects segObjs = new SceneUnderstandingObjects(semanticObj_dirPath);

            return(new List <SceneUnderstandingObjects.Element>(segObjs.GetElements((int)type)));
        }
Пример #17
0
        public static void ImportSceneObjectsByType(string dirPath, SceneUnderstandingObjectType objType)
        {
            SceneUnderstandingObjects SceneObj = new SceneUnderstandingObjects(dirPath);

            foreach (SceneObject ssobj in ShowSceneObjects)
            {
                if (ssobj.objTypeID == objType)
                {
                    foreach (GameObject obj in ssobj.BoundingBoxGameObj)
                    {
                        if (obj != null)
                        {
                            GameObject.Destroy(obj);
                        }
                    }
                }
            }
            if (SceneObj.GetNElement() < 1)
            {
                Debug.Log("Scene semantic [" + SceneObj.GetElementName((int)objType) + "] data is empty");
                return;
            }
            //Comment in ViveSR
            //else
            //{
            //    foreach (SceneUnderstandingObjects.Element each in SceneObj.GetElements(objType))
            //    {
            //        Debug.Log("id[" + each.id + "] tag[" + each.tag + "]");

            //        Debug.Log("objfilename = " + each.objfilename);
            //        Debug.Log("cldfilename = " + each.cldfilename);
            //        Debug.Log("pos num = " + each.position.Count);
            //        foreach (var pos in each.position)
            //        {
            //            Debug.Log("pos idx = " + each.position.IndexOf(pos));
            //            Debug.Log("pos.x = " + pos.x);
            //            Debug.Log("pos.y = " + pos.y);
            //            Debug.Log("pos.z = " + pos.z);
            //        }
            //        //Debug.Log("forward = " + each.forward);
            //        Debug.Log("bBoxMinPoint = " + each.bBoxMinPoint);
            //        Debug.Log("bBoxMaxPoint = " + each.bBoxMaxPoint);
            //    }
            //}

            #region Get Object Bounding Box
            foreach (SceneUnderstandingObjects.Element element in SceneObj.GetElements((int)objType))
            {
                SceneObject scene_obj = new SceneObject();
                scene_obj.BoundingBoxGameObj = new List <GameObject>();
                scene_obj.IconGameObj        = new List <GameObject>();
                scene_obj.objTypeID          = (SceneUnderstandingObjectType)objType;
                scene_obj.objID       = element.id;
                scene_obj.objFileName = element.objfilename;
                scene_obj.cldFileName = element.cldfilename;
                scene_obj.forward     = element.forward;
                scene_obj.positions   = element.position;
                SceneObj.GetElementsBoundingBoxMeshes((int)objType, element, ref scene_obj.BoundingBoxGameObj);
                SceneObj.GetElementsIcons((int)objType, element, ref scene_obj.IconGameObj);
                ShowSceneObjects.Add(scene_obj);
            }
            #endregion
        }
Пример #18
0
        public static void SetCustomSceneUnderstandingConfig(SceneUnderstandingObjectType objectType, int objectMaxNum, bool isOn)
        {
            SceneUnderstandingConfig config = new SceneUnderstandingConfig();

            GetSceneUnderstandingConfig(ref config);

            switch (objectType)
            {
            case SceneUnderstandingObjectType.BED:
                if (isOn)
                {
                    config.nBedMaxInst = objectMaxNum;
                }
                else
                {
                    config.nBedMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.CEILING:
                if (isOn)
                {
                    config.nCeilingMaxInst = objectMaxNum;
                }
                else
                {
                    config.nCeilingMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.CHAIR:
                if (isOn)
                {
                    config.nChairMaxInst = objectMaxNum;
                }
                else
                {
                    config.nChairMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.FLOOR:
                if (isOn)
                {
                    config.nFloorMaxInst = objectMaxNum;
                }
                else
                {
                    config.nFloorMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.TABLE:
                if (isOn)
                {
                    config.nTableMaxInst = objectMaxNum;
                }
                else
                {
                    config.nTableMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.WALL:
                if (isOn)
                {
                    config.nWallMaxInst = objectMaxNum;
                }
                else
                {
                    config.nWallMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.WINDOW:
                if (isOn)
                {
                    config.nWindowMaxInst = objectMaxNum;
                }
                else
                {
                    config.nWindowMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.MONITOR:
                if (isOn)
                {
                    config.nMonitorMaxInst = objectMaxNum;
                }
                else
                {
                    config.nMonitorMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.FURNITURE:
                if (isOn)
                {
                    config.nFurnitureMaxInst = objectMaxNum;
                }
                else
                {
                    config.nFurnitureMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.DOOR:
                if (isOn)
                {
                    config.nDoorMaxInst = objectMaxNum;
                }
                else
                {
                    config.nDoorMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.PICTURE:
                if (isOn)
                {
                    config.nPictureMaxInst = objectMaxNum;
                }
                else
                {
                    config.nPictureMaxInst = 0;
                }
                break;

            case SceneUnderstandingObjectType.PERSON:
                if (isOn)
                {
                    config.nPersonMaxInst = objectMaxNum;
                }
                else
                {
                    config.nPersonMaxInst = 0;
                }
                break;
            }
            SetSceneUnderstandingConfig(config);
        }