// Instantiate a gameject at given location
    private GameObject InstantiateObj(Object objOri, NavObj.ObjCategory m_objCat, int m_objLocIdx)
    {
        Transform  locReceptable = GameObject.Find($"PosReceptacles/{m_objCat.ToString()}").transform.GetChild(m_objLocIdx);
        GameObject objInst       = GameObject.Instantiate(objOri, locReceptable) as GameObject;

        objInst.transform.localPosition = Vector3.zero; // Reset object location at the center

        // Change orientations of objects with category on wall
        if (m_objCat == NavObj.ObjCategory.OnWall)
        {
            if (locReceptable.position.x == 4f)
            {
                objInst.transform.localRotation = Quaternion.Euler(0, -90f, 0);
            }
            if (locReceptable.position.x == -4f)
            {
                objInst.transform.localRotation = Quaternion.Euler(0, 90f, 0);
            }
            if (locReceptable.position.z == 2.5f)
            {
                objInst.transform.localRotation = Quaternion.Euler(0, 180f, 0);
            }
            if (locReceptable.position.z == -2.5f)
            {
                objInst.transform.localRotation = Quaternion.Euler(0, 0, 0);
            }
        }
        else
        {
            // objInst.transform.localRotation = ((GameObject)objOri).transform.localRotation;
            objInst.transform.localRotation = Quaternion.Euler(0, Random.Range(-180f, 180f), 0);
        }
        return(objInst);
    }
    // Select an objet prefab with provided object category. Return a list of objects which will be randomly spawned in the scene. There can be at most 3 objects with OnFloor category,
    // including the target object.
    private NavObj[] SelectNavObj(NavObj.ObjCategory m_objCat)
    {
        // Only call this random selection function when autosettarget is true
        if (envSetup.autoSetTarget || agentController.CompletedEpisodes == 0)
        {
            // Randomly select 1-2 OnFloor Objects, 1-9 OnFurnitureTop Objects, 1-9 OnWall Objects (except for the target objects)
            // int OFObjNum = Random.Range(1,2);
            // int OFTObjNum = Random.Range(1,9);
            // int OWObjNum = Random.Range(1,9);
            objNums[0] = Random.Range(1, 2);
            objNums[1] = Random.Range(1, 9);
            objNums[2] = Random.Range(1, 9);

            // Create new object array which with be returned and contains all the objects
            selectedNavObjs = new NavObj[objNums.Sum() + 1];

            // Generate arrays with different categories
            NavObj[] OF_list  = objList.Where(obj => obj.objCat == NavObj.ObjCategory.OnFloor).ToArray();
            NavObj[] OFT_list = objList.Where(obj => obj.objCat == NavObj.ObjCategory.OnFurnitureTop).ToArray();
            NavObj[] OW_list  = objList.Where(obj => obj.objCat == NavObj.ObjCategory.OnWall).ToArray();

            // Select the target objects
            switch (m_objCat)
            {
            case NavObj.ObjCategory.OnFloor:
                selectedNavObjs[0] = OF_list[Random.Range(0, OF_list.Length)];
                break;

            case NavObj.ObjCategory.OnFurnitureTop:
                selectedNavObjs[0] = OFT_list[Random.Range(0, OFT_list.Length)];
                break;

            case NavObj.ObjCategory.OnWall:
                selectedNavObjs[0] = OW_list[Random.Range(0, OW_list.Length)];
                break;
            }

            // Set values for global object type and instance number variables
            objType        = selectedNavObjs[0].objType;
            objInstanceNum = selectedNavObjs[0].objInstanceNum;

            for (int i = 1; i < objNums.Sum() + 1; i++)
            {
                if (i < objNums[0] + 1) // Select OnFloor Objects
                {
                    selectedNavObjs[i] = OF_list[Random.Range(0, OF_list.Length)];
                }
                else if (i < objNums[0] + objNums[1] + 1)
                {
                    selectedNavObjs[i] = OFT_list[Random.Range(0, OFT_list.Length)];
                }
                else
                {
                    selectedNavObjs[i] = OW_list[Random.Range(0, OW_list.Length)];
                }
            }
            // return selectedNavObjs;
        }
        return(selectedNavObjs);
    }
Example #3
0
 public void settingTaskTarget()
 {
     // Auto set object category and location
     if (autoSetTarget)
     {
         objCatSelected = (NavObj.ObjCategory)Random.Range(0, numObjCats);
         // objCatSelected = NavObj.ObjCategory.OnWall;
         objLocationIdxSelected = Random.Range(0, 10);
     }
 }
    // Initialize selected objects in the given location. Return a list of instantiated Gameobjects
    private Transform[] InitObj(NavObj[] m_objList, NavObj.ObjCategory m_ObjCat, int m_objLocIdx)
    {
        // Instantiate other objects in the object list if needed
        if (m_objList.Length != 1 && (envSetup.autoSetTarget || agentController.CompletedEpisodes == 0))
        {
            // Create a new transform array
            _objList = new Transform[m_objList.Length];
            // Create a new object location indices
            objLocIdx = new int[_objList.Length];

            // Instantiate the target object
            _objList[0]  = InstantiateObj(m_objList[0].objInstance, m_ObjCat, m_objLocIdx).transform;
            objLocIdx[0] = m_objLocIdx;
            // _fakeTargetsLocIdx = Enumerable.Range(0,10).Where(num => num!=m_objLocIdx).OrderBy(num => Guid.NewGuid()).Take(m_objList.Length-1).ToArray();

            // Debug.Log(objLocIdx.Length);

            // Environment object location indices
            switch (m_ObjCat)
            {
            case NavObj.ObjCategory.OnFloor:
                Array.Copy(Enumerable.Range(0, 10).Where(num => num != objLocIdx[0]).OrderBy(num => Guid.NewGuid()).Take(objNums[0]).ToArray(), 0, objLocIdx, 1, objNums[0]);
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[1]).ToArray(), 0, objLocIdx, 1 + objNums[0], objNums[1]);
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[2]).ToArray(), 0, objLocIdx, 1 + objNums[0] + objNums[1], objNums[2]);
                break;

            case NavObj.ObjCategory.OnFurnitureTop:
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[0]).ToArray(), 0, objLocIdx, 1, objNums[0]);
                Array.Copy(Enumerable.Range(0, 10).Where(num => num != objLocIdx[0]).OrderBy(num => Guid.NewGuid()).Take(objNums[1]).ToArray(), 0, objLocIdx, 1 + objNums[0], objNums[1]);
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[2]).ToArray(), 0, objLocIdx, 1 + objNums[0] + objNums[1], objNums[2]);
                break;

            case NavObj.ObjCategory.OnWall:
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[0]).ToArray(), 0, objLocIdx, 1, objNums[0]);
                Array.Copy(Enumerable.Range(0, 10).OrderBy(num => Guid.NewGuid()).Take(objNums[1]).ToArray(), 0, objLocIdx, 1 + objNums[0], objNums[1]);
                Array.Copy(Enumerable.Range(0, 10).Where(num => num != objLocIdx[0]).OrderBy(num => Guid.NewGuid()).Take(objNums[2]).ToArray(), 0, objLocIdx, 1 + objNums[0] + objNums[1], objNums[2]);
                break;
            }

            for (int i = 1; i < objNums.Sum() + 1; i++)
            {
                _objList[i] = InstantiateObj(m_objList[i].objInstance, m_objList[i].objCat, objLocIdx[i]).transform;
            }
        }
        // for(int i=1;i<_objList.Length;i++)
        // {
        // _objList[i] = InstantiateObj(m_objList[i], m_ObjCat, _fakeTargetsLocIdx[i-1]).transform;
        // }

        return(_objList);
    }
    // Select Animation Clips with provided object category and location
    private void SelectAnimClips(string[] m_devices, int playerID, NavObj.ObjCategory m_objCat, int m_objLocIdx)
    {
        AnimationClip[][] qualifiedList = new AnimationClip[m_devices.Length][];
        for (int i = 0; i < m_devices.Length; i++)
        {
            qualifiedList[i] = animList.Where(anim => anim.name.Split('_')[0] == m_devices[i] &&
                                              anim.name.Split('_')[1] == playerID.ToString() &&
                                              anim.name.Split('_')[2] == m_objCat.ToString() &&
                                              anim.name.Split('_')[3] == m_objLocIdx.ToString()).ToArray();
        }
        int selectedIndex = Random.Range(0, qualifiedList[0].Length);

        for (int i = 0; i < m_devices.Length; i++)
        {
            selectedRefClip[i] = qualifiedList[i][selectedIndex];
        }
    }
    public void SetupReplay(NavObj.ObjCategory m_objCat, int m_objLocIdx)
    {
        // Play selected animation clips
        int playerID = playerIDs[!isTraining && newGestures? Random.Range(6, 10):Random.Range(0, 6)]; // select a random player ID
        // Scale Kinect avatar according to playerID
        float scale = playerID2Height[playerID] / 1.75f;

        if (envSetup.autoSetTarget || agentController.CompletedEpisodes == 0)
        {
            GameObject.Find("KinectAvatar").transform.localScale = new Vector3(scale, scale, scale);
        }

        if (envSetup.autoSetTarget || agentController.CompletedEpisodes == 0)
        {
            SelectAnimClips(deviceList, playerID, m_objCat, m_objLocIdx);
        }
        for (int i = 0; i < deviceList.Length; i++)
        {
            replayController.PlayAnimClipInCtrl(animCtrls[i], selectedRefClip[i]);
        }
    }
 // Setup replay for device using the replay controller, and return the instantiated gameobjects
 public Transform[] SetupTarget(NavObj.ObjCategory m_objCat, int m_objLocIdx)
 {
     // Instantiate all objects in the list
     return(InitObj(SelectNavObj(m_objCat), m_objCat, m_objLocIdx));
 }