Exemplo n.º 1
0
    public bool TryPlaceOnPlatform(out Vector3 position, float minHeight, float maxHeight, float minWidth)
    {
        position = Vector3.zero;
        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(m_topologyResults);
        int    numResults         = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(minHeight, maxHeight, 1.0f, m_topologyResults.Length, resultsTopologyPtr);

        if (numResults == 0)
        {
            return(false);
        }

        // Pick randomly by shuffling indices
        int[] placementIdxs = new int[numResults];
        for (int i = 0; i < placementIdxs.Length; i++)
        {
            placementIdxs[i] = i;
        }
        Shuffle(placementIdxs);

        // We have to keep track of our own placements
        foreach (int idx in placementIdxs)
        {
            SpatialUnderstandingDllTopology.TopologyResult result = m_topologyResults[idx];
            if (!Overlaps(result, minWidth))
            {
                position = result.position;
                Vector3 size = new Vector3(minWidth, 0, minWidth);  // we ignore height for now
                m_platformPlacements.Add(new Tuple <Vector3, Vector3>(position, size));
                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 2
0
        public void PlaceOnSittable()
        {
            System.IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
            int           locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(.4f, 1.5f, 1f, resultsTopology.Length, resultsTopologyPtr);

            for (int i = 0; i < locationCount; i++)
            {
                Debug.Log(resultsTopology[i].position);
            }
        }
Exemplo n.º 3
0
    public int RunQuery()
    {
        Results = new SpatialUnderstandingDllTopology.TopologyResult[_queryMaxResultCount];
        SpatialUnderstandingDllTopology.TopologyResult SingleResult = new SpatialUnderstandingDllTopology.TopologyResult();


        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(Results);
        IntPtr singleResultPtr    = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(SingleResult);

        int resultCount = 0;

        switch (Type)
        {
        case STTopologyQueryType.LargePositionsOnWalls:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargePositionsOnWalls(MinHeight, MinWidth, Wall_MinHeightAboveFloor, MinFacingClearance, Results.Length, resultsTopologyPtr);
            break;

        case STTopologyQueryType.LargestPositionsOnFloor:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor(Results.Length, resultsTopologyPtr);
            break;

        case STTopologyQueryType.LargestWall:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestWall(singleResultPtr);
            Results     = new SpatialUnderstandingDllTopology.TopologyResult[] { SingleResult };
            break;

        case STTopologyQueryType.PositionsOnFloor:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor(Floor_MinLength, MinWidth, Results.Length, resultsTopologyPtr);
            break;

        case STTopologyQueryType.PositionsOnWalls:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnWalls(MinHeight, MinWidth, Wall_MinHeightAboveFloor, MinFacingClearance, Results.Length, resultsTopologyPtr);
            break;

        case STTopologyQueryType.PositionsSittable:
            resultCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(MinHeight, Sittable_MaxHeight, MinFacingClearance, Results.Length, resultsTopologyPtr);
            break;
        }

        List <SpatialUnderstandingDllTopology.TopologyResult> resultTemp = new List <SpatialUnderstandingDllTopology.TopologyResult>();

        for (int i = 0; i < resultCount; i++)
        {
            resultTemp.Add(Results[i]);
        }

        Results = resultTemp.ToArray();

        _hasRun = true;

        return(resultCount);
    }
Exemplo n.º 4
0
    private void InstanciateObjectOnSurface()
    {
        const int QueryResultMaxCount = 512;

        SpatialUnderstandingDllTopology.TopologyResult[] _resultsTopology = new SpatialUnderstandingDllTopology.TopologyResult[QueryResultMaxCount];

        var minHeight          = 0.02f;
        var maxHeight          = 1f;
        var minFacingClearance = 0.02f;

        var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
        var locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(minHeight, maxHeight, minFacingClearance, _resultsTopology.Length, resultsTopologyPtr);

        if (locationCount > 0)
        {
            Instantiate(this.SurfacePrefab, _resultsTopology[0].position, Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up));
        }
    }
Exemplo n.º 5
0
    public void Query_Topology_FindPositionsPlaceable()
    {
        // Setup
        float minHeight          = 0.125f;
        float maxHeight          = 1.0f;
        float minFacingClearance = 1.0f;

        // Only if we're enabled
        if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding)
        {
            return;
        }

        // Query
        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);
        int    locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(
            minHeight, maxHeight, minFacingClearance,
            resultsTopology.Length, resultsTopologyPtr);

        // Output
        HandleResults_Topology("Find Placeable Positions", locationCount, new Vector3(0.25f, 0.025f, 0.25f), Color.cyan);
    }
Exemplo n.º 6
0
    private void ShowCupcakes()
    {
        /*** Place ***/
        if (repeats == 0)
        {
            _resultsTopology = new SpatialUnderstandingDllTopology.TopologyResult[512];
            IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
            locationsNumber = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable(0.7f, 2.4f, 0.4f, _resultsTopology.Length, resultsTopologyPtr);
        }

        previousPosition = UnityEngine.Random.Range(0, locationsNumber);

        if (locationsNumber > 0)
        {
            if (usedPositions.Count == locationsNumber)
            {
                end = true;
            }

            for (int i = 0; i < locationsNumber; i++)
            {
                if (end)
                {
                    break;
                }

                //set radius for each cupcake
                if (!usedPositions.Contains(i) &&
                    ((_resultsTopology[i].position.x > _resultsTopology[previousPosition].position.x + radius) || (_resultsTopology[i].position.x < _resultsTopology[previousPosition].position.x - radius)) &&
                    ((_resultsTopology[i].position.z > _resultsTopology[previousPosition].position.z + radius) || (_resultsTopology[i].position.z < _resultsTopology[previousPosition].position.z - radius)))
                {
                    cupcakeManager.cupcakeList[placedCupcakes].transform.position = _resultsTopology[i].position;
                    usedPositions.Add(i);
                    previousPosition = i;
                    placedCupcakes++;
                }

                if (placedCupcakes == 5)
                {
                    break;
                }
            }

            collidedCupcakes = 0;
            noCups           = false;
            repeats++;
        }
        else
        {
            //no place for cupcakes
            noCups = true;
        }


        /*** Show ***/
        for (int i = 0; i < placedCupcakes; i++)
        {
            GameObject c = cupcakeManager.cupcakeList[i];
            c.GetComponent <CollisionManager>().enabled = true;
            Transform t = c.transform;
            foreach (Transform tr in t)
            {
                if (tr.CompareTag("Part"))
                {
                    tr.GetComponent <MeshRenderer>().enabled = true;
                }
            }
            c.GetComponent <Target>().placed             = true;
            c.GetComponent <Target>().needArrowIndicator = true;
            c.tag = "Target";
        }

        foreach (GameObject c in cupcakeManager.cupcakeList)
        {
            if (c.GetComponent <Target>().placed)
            {
                c.GetComponent <CollisionManager>().collisionAvailable = true;
            }
        }
    }