Exemple #1
0
    public void Query_Shape_FindPositionsOnShape(string shapeName)
    {
        // Setup
        float minRadius = 0.1f;

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

        // Query
        IntPtr resultsShapePtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsShape);
        int    shapeCount      = SpatialUnderstandingDllShapes.QueryShape_FindPositionsOnShape(
            shapeName, minRadius,
            resultsShape.Length, resultsShapePtr);

        // Output
        HandleResults_Shape("Find Positions on Shape '" + shapeName + "'", shapeCount, Color.cyan, new Vector3(0.1f, 0.025f, 0.1f));
    }
Exemple #2
0
    public int RunQuery()
    {
        Results = new SpatialUnderstandingDllShapes.ShapeResult[_queryMaxResultCount];

        IntPtr resultsShapePtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(Results);

        int shapeCount = 0;

        if (String.IsNullOrEmpty(ShapeName))
        {
            Debug.LogError("Empty shape name, cannot run query.");
            return(0);
        }

        switch (Type)
        {
        case STShapeQueryType.ShapeBounds:
            shapeCount = SpatialUnderstandingDllShapes.QueryShape_FindShapeHalfDims(ShapeName, Results.Length, resultsShapePtr);
            break;

        case STShapeQueryType.PositionsOnShape:
            shapeCount = SpatialUnderstandingDllShapes.QueryShape_FindPositionsOnShape(ShapeName, _minRadius, Results.Length, resultsShapePtr);
            break;
        }

        List <SpatialUnderstandingDllShapes.ShapeResult> resultTemp = new List <SpatialUnderstandingDllShapes.ShapeResult>();

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

        Results = resultTemp.ToArray();

        _hasRun = true;

        return(shapeCount);
    }
    private void InstantiateObjectOnTable()
    {
        const int MaxResultCount = 512;
        var       shapeResults   = new SpatialUnderstandingDllShapes.ShapeResult[MaxResultCount];

        var resultsShapePtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(shapeResults);
        var locationCount   = SpatialUnderstandingDllShapes.QueryShape_FindPositionsOnShape("ElectricBox", 0.1f, shapeResults.Length, resultsShapePtr);

        if (locationCount > 0)
        {
            Instantiate(_object,
                        shapeResults[0].position,
                        Quaternion.LookRotation(shapeResults[0].position.normalized, Vector3.up));
            // For some reason the halfDims of the shape result are always 0,0,0 so we can't scale
            // to the size of the surface. This may be a bug in the HoloToolkit?

            SpatialText.text = "Placed Hologram";
        }
        else
        {
            SpatialText.text = "Hologram not placed";
        }
    }
Exemple #4
0
    //if any problems arises (i.e. fps spikes when placing), this function will need to be split in multiple stages.
    //Then, rest must be given to Unity between the stages. I.e. call the stages one at a time in the Update() part. Don't call multiple stages in the same Update() call.
    //placePlat handles the placement for the Platform type of placement.
    //it relies on the SpatialUnderstandingDllShapes API. To add other Shape Definitions, see the ShapeDefinition script from HoloToolkit-Example/SpatialUnderstanding scripts
    private void placePlat()
    {
        List <Vector3>[] lPositions = new List <Vector3> [mPlatformLeftToPlace.Count];
        SpatialUnderstandingDllShapes.ShapeResult[] lPlatPos = new SpatialUnderstandingDllShapes.ShapeResult[mMaxPlatLoc];
        System.IntPtr lPlatPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(lPlatPos);

        for (int i = 0; i < mPlatformLeftToPlace.Count; i++) //prepare to find all positions for each clue
        {
            lPositions[i] = new List <Vector3>();
        }

        for (int lIt = 0; lIt < mPlatformLeftToPlace.Count; lIt++) //here we find all Platform positions for each clue
        {
            int      i          = mPlatformLeftToPlace[lIt];
            Collider lColl      = mToPlace[i].GetComponent <Collider>();
            float    lMax       = Mathf.Max(lColl.bounds.extents.x, Mathf.Max(lColl.bounds.extents.y, lColl.bounds.extents.z));
            int      lPlatCount = SpatialUnderstandingDllShapes.QueryShape_FindPositionsOnShape(
                "Platform", 1.1f * lMax,
                lPlatPos.Length, lPlatPtr);

            for (int lPlatIt = 0; lPlatIt < lPlatCount; lPlatIt++)
            {
                lPositions[lIt].Add(lPlatPos[lPlatIt].position);
            }

            if (lPositions[lIt].Count == 0) //if there is no position for an object, just exit. The placement failed.
            {
                lIt = mPlatformLeftToPlace.Count + 2;
            }
        }

        int lItObj;

        //here we choose a random position from all our positions for each clue.
        //since there might be multiple clues of the same size on platforms, those will have exactly the same positions.
        //So it would be faster to try to select a position at random than collide for a while on the first positions
        for (lItObj = 0; lItObj < mPlatformLeftToPlace.Count; lItObj++)
        {
            int  iObj    = mPlatformLeftToPlace[lItObj];
            int  lItPos  = 2;
            bool lPlaced = false;
            while ((lPositions[lItObj].Count != 0) && (!lPlaced)) //choose positions at random until we run out of positions
            {
                lItPos = Random.Range(0, lPositions[lItObj].Count - 1);

                //put object correctly on position. Without placing it upper than the position returned, we would have the center of the object at the position on the Platform
                //which essentially means the lower half will go through the Platform
                mToPlace[iObj].transform.localPosition = lPositions[lItObj][lItPos] + mToPlace[iObj].GetComponent <Collider>().bounds.extents.y *Vector3.up;

                if (canPlace(iObj)) //can place the object at this position
                {
                    mPlaced.Add(iObj);
                    lPlaced = true;
                }
                else
                {
                    lPositions[lItObj].RemoveAt(lItPos); //position unusable
                }
            }
            if (!lPlaced) //couldn't place the object, so just exit this for loop. The placement failed.
            {
                lItObj = mPlatformLeftToPlace.Count + 2;
                mToPlace[iObj].transform.localPosition = new Vector3(0, -1000, 0);
            }
        }

        if (lItObj == mPlatformLeftToPlace.Count) //successfully placed all the objects
        {
            mPlacePComplete = true;
        }
        else //could not place the objects
        {
            mPlacePComplete = false;
            mSuccessful     = false;
            mComplete       = true;
        }
    }