コード例 #1
0
        private void TestPlacment()
        {
            if (Time.time < nextRefresh)
            {
                return;
            }
            nextRefresh = Time.time + refreshRate;

            IntPtr test = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(testRes);

            testRes.normal   = rayCastResult.IntersectNormal;
            testRes.position = rayCastResult.IntersectPoint;
            testRes.length   = 0.2f;
            testRes.width    = 0.2f;

            Quaternion quat = Quaternion.LookRotation(CameraCache.Main.transform.forward, testRes.normal);


            switch ((int)rayCastResult.SurfaceType)
            {
            case 0:    //invalid
                break;

            case 1:    //other
                break;

            case 2:    //floor
            case 3:    //floorlike
            case 4:    //platform
                quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)), testRes.normal);
                break;

            case 5:    //ceiling
                quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (-Vector3.one - testRes.normal)), testRes.normal);
                break;

            case 6:    //wallexternal
            case 7:    //walllike
                quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)), testRes.normal);
                break;

            default:
                break;
            }

            //if (rayCastResult.SurfaceType != SpatialUnderstandingDll.Imports.RaycastResult.SurfaceTypes.Floor)
            {
                Debug.Log(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)));
                //return;
            }

            Vector3 topLeft     = testRes.position + quat * new Vector3(-0.2f, 0f, -0.2f);
            Vector3 topRight    = testRes.position + quat * new Vector3(-0.2f, 0f, 0.2f);
            Vector3 bottomLeft  = testRes.position + quat * new Vector3(0.2f, 0f, -0.2f);
            Vector3 bottomRight = testRes.position + quat * new Vector3(0.2f, 0f, 0.2f);

            Debug.Log("ray:" + testRes.position + "\nnorm" + testRes.normal + "\nTL:" + topLeft + "\nTR:" + topRight + "\nBR:" + bottomRight + "\nBL:" + bottomLeft);

            bool isValidRect = SpatialUnderstandingDllTopology.QueryTopology_IsValidRect(topLeft, topRight, bottomLeft, bottomRight, requestType, (int)rayCastResult.SurfaceType, test);

            if (isValidRect)
            {
                cubePosition.transform.SetPositionAndRotation(testRes.position, quat);
                cube.SetActive(true);
            }
            else
            {
                cube.SetActive(false);
            }
            CursorText.text = rayCastResult.SurfaceType.ToString();
        }
コード例 #2
0
    public bool CheckPlacement(SpatialUnderstandingDll.Imports.RaycastResult rayCastResult)
    {
        while (Time.time < nextRefresh)
        {
            //yield null;
        }
        nextRefresh = Time.time + refreshRate;

        IntPtr test = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(testRes);

        testRes.normal   = rayCastResult.IntersectNormal;
        testRes.position = rayCastResult.IntersectPoint;
        testRes.length   = curretObject.halfLength;
        testRes.width    = curretObject.halfWidth;

        Quaternion quat = Quaternion.LookRotation(CameraCache.Main.transform.forward, testRes.normal);


        switch ((int)rayCastResult.SurfaceType)
        {
        case 0:    //invalid
            break;

        case 1:    //other
            break;

        case 2:    //floor
        case 3:    //floorlike
        case 4:    //platform
            quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)), testRes.normal);
            break;

        case 5:    //ceiling
            quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (-Vector3.one - testRes.normal)), testRes.normal);
            break;

        case 6:    //wallexternal
        case 7:    //walllike
            quat = Quaternion.LookRotation(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)), testRes.normal);
            break;

        default:
            break;
        }

        //if (rayCastResult.SurfaceType != SpatialUnderstandingDll.Imports.RaycastResult.SurfaceTypes.Floor)
        {
            Debug.Log(Vector3.Scale(CameraCache.Main.transform.forward, (Vector3.one - testRes.normal)));
            //return;
        }

        Vector3 topLeft     = testRes.position + quat * new Vector3(-curretObject.halfLength, 0f, -curretObject.halfWidth);
        Vector3 topRight    = testRes.position + quat * new Vector3(-curretObject.halfLength, 0f, curretObject.halfWidth);
        Vector3 bottomLeft  = testRes.position + quat * new Vector3(curretObject.halfLength, 0f, -curretObject.halfWidth);
        Vector3 bottomRight = testRes.position + quat * new Vector3(curretObject.halfLength, 0f, curretObject.halfWidth);

        //Debug.Log("ray:" + testRes.position + "\nnorm" + testRes.normal + "\nTL:" + topLeft + "\nTR:" + topRight + "\nBR:" + bottomRight + "\nBL:" + bottomLeft);

        bool isValidRect = SpatialUnderstandingDllTopology.QueryTopology_IsValidRect(topLeft, topRight, bottomLeft, bottomRight, requestType, (int)rayCastResult.SurfaceType, test);

        if (isValidRect)
        {
            objectToPlace.transform.SetPositionAndRotation(testRes.position, quat);
            objectToPlace.SetActive(true);
            isValidLocation = true;
        }
        else
        {
            objectToPlace.SetActive(false);
            isValidLocation = false;
        }

        return(false);
    }