Exemple #1
0
    // We only crudely check overlap in xz plane
    private bool Overlaps(SpatialUnderstandingDllTopology.TopologyResult result, float width)
    {
        float halfWidth = 0.5f * width;

        foreach (Tuple <Vector3, Vector3> placement in m_platformPlacements)
        {
            Vector3 position = placement.first;
            Vector3 halfSize = 0.5f * placement.second;
            if (result.position.x + halfWidth < (position.x - halfSize.x))
            {
                continue;
            }
            if (result.position.x - halfWidth > (position.x + halfSize.x))
            {
                continue;
            }
            if (result.position.x + halfWidth < (position.x - halfSize.x))
            {
                continue;
            }
            if (result.position.z - halfWidth > (position.z + halfSize.z))
            {
                continue;
            }
            if (result.position.z + halfWidth < (position.z - halfSize.z))
            {
                continue;
            }
            return(true);
        }
        return(false);
    }
Exemple #2
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_FindLargePositionsSittable(minHeight, maxHeight, 1, minWidth, 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);
    }
Exemple #3
0
    public void InstanciateObjectOnWall2()
    {
        const int QueryResultMaxCount = 512;

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

        var minWidthOfWallSpace  = 0.1f;
        var minHeightAboveFloor  = 1f;
        var minHeightOfWallSpace = 1f;
        var minFacingClearance   = 0.1f;

        var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);

        var locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnWalls(
            minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance,
            _resultsTopology.Length, resultsTopologyPtr);

        if (locationCount > 0)
        {
            Instantiate(this.FloorPrefab,
                        _resultsTopology[0].position,
                        Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up));
        }
        else
        {
            this.InstructionTextMesh.text = "I can't found the enough space to place the hologram on the Wall.";
        }
    }
Exemple #4
0
    public void InstanciateObjectOnFloor()
    {
        const int QueryResultMaxCount = 512;

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

        var minLengthFloorSpace = 0.25f;
        var minWidthFloorSpace  = 0.25f;

        var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
        var locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor(minLengthFloorSpace, minWidthFloorSpace, _resultsTopology.Length, resultsTopologyPtr);

        if (locationCount > 0)
        {
            Instantiate(this.WallPrefab,
                        _resultsTopology[0].position,
                        Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up));

            //this.InstructionTextMesh.text = "Placed the hologram on the floor";
        }
        else
        {
            this.InstructionTextMesh.text = "I can't found the enough space to place the hologram on the floor.";
        }
    }
Exemple #5
0
    void Update()
    {
        if (SpatialUnderstanding.Instance.ScanState == SpatialUnderstanding.ScanStates.Done && !done)
        {
            SpatialUnderstandingDllTopology.TopologyResult[] result = new SpatialUnderstandingDllTopology.TopologyResult[1];
            System.IntPtr intptr        = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(result);
            int           locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargePositionsOnWalls(0.1f, 0.1f, 0.0f, 0.2f, result.Length, intptr);

            if (locationCount > 0)
            {
                something.transform.position = result[0].position;
                Debug.Log(result[0].position);
                Debug.Log(result[0].length);
                Debug.Log(result[0].width);
                Debug.Log(result[0].normal);
                SpatialUnderstanding.Instance.UnderstandingDLL.UnpinAllObjects();

                done = true;
                Debug.Log("Retrieved spatial understanding position.");
            }
        }

        if (!scanDone && Time.fixedTime > 20.0f)
        {
            SpatialUnderstanding.Instance.RequestFinishScan();
            scanDone = true;
        }
    }
    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);
    }
Exemple #7
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));
        }
    }
Exemple #8
0
    private void InstanciateObjectOnWall()
    {
        const int QueryResultMaxCount = 512;

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

        var minWidthOfWallSpace  = 0.1f;
        var minHeightAboveFloor  = 1f;
        var minHeightOfWallSpace = 1f;
        var minFacingClearance   = 0.1f;

        var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
        var locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnWalls(
            minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance,
            _resultsTopology.Length, resultsTopologyPtr);

        if (locationCount > 0)
        {
            Instantiate(this.WallPrefab,
                        _resultsTopology[0].position,
                        Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up));
        }
    }
Exemple #9
0
        private void InstanciateObjectOnFloor()
        {
            const int QueryResultMaxCount = 512;

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

            var minLengthFloorSpace = 0.25f;
            var minWidthFloorSpace  = 0.25f;

            var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
            var locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor(minLengthFloorSpace, minWidthFloorSpace, _resultsTopology.Length, resultsTopologyPtr);

            if (locationCount > 0)
            {
                o.transform.position = _resultsTopology[(int)(locationCount / 2)].position;
                //o.transform.up = _resultsTopology[0].normal;

                Debug.Log("Placed the hologram");
            }
            else
            {
                Debug.Log("I can't found the enough space to place the hologram.");
            }
        }
Exemple #10
0
    private IEnumerator SetupMenu()
    {
        // Setup for queries
        SpatialUnderstandingDllTopology.TopologyResult[] resultsTopology = new SpatialUnderstandingDllTopology.TopologyResult[1];
        IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology);

#if UNITY_WSA && !UNITY_EDITOR
        // Place on a wall (do it in a thread, as it can take a little while)
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition placeOnWallDef =
            SpatialUnderstandingDllObjectPlacement.ObjectPlacementDefinition.Create_OnWall(new Vector3(MenuWidth * 0.5f, MenuHeight * 0.5f, MenuMinDepth * 0.5f), 0.5f, 3.0f);
        SpatialUnderstandingDllObjectPlacement.ObjectPlacementResult placementResult = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResult();
        System.Threading.Tasks.Task thread = System.Threading.Tasks.Task.Run(() =>
        {
            if (SpatialUnderstandingDllObjectPlacement.Solver_PlaceObject(
                    "UIPlacement",
                    SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(placeOnWallDef),
                    0,
                    IntPtr.Zero,
                    0,
                    IntPtr.Zero,
                    SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticObjectPlacementResultPtr()) == 0)
            {
                placementResult = null;
            }
        });
        while (!thread.IsCompleted)
        {
            yield return(null);
        }
        if (placementResult != null)
        {
            Debug.Log("PlaceMenu - ObjectSolver-OnWall");
            Vector3 posOnWall = placementResult.Position - placementResult.Forward * MenuMinDepth * 0.5f;
            PlaceMenu(posOnWall, -placementResult.Forward);
            yield break;
        }
#endif

        // Wait a frame
        yield return(null);

        // Fallback, place floor (add a facing, if so)
        int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor(
            resultsTopology.Length, resultsTopologyPtr);
        if (locationCount > 0)
        {
            Debug.Log("PlaceMenu - LargestPositionsOnFloor");
            SpatialUnderstandingDllTopology.TopologyResult menuLocation = resultsTopology[0];
            Vector3 menuPosition   = menuLocation.position + Vector3.up * MenuHeight;
            Vector3 menuLookVector = Camera.main.transform.position - menuPosition;
            PlaceMenu(menuPosition, (new Vector3(menuLookVector.x, 0.0f, menuLookVector.z)).normalized, true);
            yield break;
        }

        // Final fallback just in front of the user
        SpatialUnderstandingDll.Imports.QueryPlayspaceAlignment(SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceAlignmentPtr());
        SpatialUnderstandingDll.Imports.PlayspaceAlignment alignment = SpatialUnderstanding.Instance.UnderstandingDLL.GetStaticPlayspaceAlignment();
        Vector3 defaultPosition = Camera.main.transform.position + Camera.main.transform.forward * 2.0f;
        PlaceMenu(new Vector3(defaultPosition.x, Math.Max(defaultPosition.y, alignment.FloorYValue + 1.5f), defaultPosition.z), (new Vector3(Camera.main.transform.forward.x, 0.0f, Camera.main.transform.forward.z)).normalized, true);
        Debug.Log("PlaceMenu - InFrontOfUser");
    }
Exemple #11
0
    private void InstantiatePaintingsOnWalls()
    {
        // Shuffle the Tags List

        // Assign Tags to Paintings
        AssignTagsToPaintings(Keys, Tags, tagCaptions);

        //
        //  ALGORITHM FOR POSITIONING
        //
        // Add every gameobject that I want to show in a list
        GeneralLists();

        const int QueryResultMaxCount = 128;

        SpatialUnderstandingDllTopology.TopologyResult[] _resultsTopology = new SpatialUnderstandingDllTopology.TopologyResult[QueryResultMaxCount];
        var minHeightOfWallSpace = 0.5f;
        var minWidthOfWallSpace  = 0.5f;
        var minHeightAboveFloor  = 1.0f;
        var minFacingClearance   = 0.2f;

        var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology);
        var locationCount      = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnWalls(minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance, _resultsTopology.Length, resultsTopologyPtr);

        int lastIndex = 0;

        if (locationCount > 0)
        {
            //
            // Finding Position and rotation of Paintings
            //

            GlobalVariables.objPositions.Add(_resultsTopology[0].position);// first painting
            GlobalVariables.objRotations.Add(Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up));

            // last topology index is zero
            int paintCounter = 0;
            // for the rest paintings
            for (int i = 1; i < allPaintings.Count; i++)
            {
                // Checking every topology location
                for (int j = lastIndex + 1; j < locationCount; j++)
                {
                    // Check if this GameObject is too close with with the previous one
                    if (IsDistanceBetween(i, _resultsTopology[j].position))
                    {
                        // Assign positions
                        Vector3    pos = new Vector3(_resultsTopology[j].position.x, _resultsTopology[j].position.y, _resultsTopology[j].position.z);
                        Quaternion rot = Quaternion.LookRotation(_resultsTopology[j].normal, Vector3.up);

                        GlobalVariables.objPositions.Add(pos);
                        GlobalVariables.objRotations.Add(rot);// first painting

                        lastIndex = j;
                        break;
                    }
                }
            }

            for (int z = 0; z < allPaintings.Count; z++)
            {
                // Instantiate PAINTINGS
                if ((z - 1) % 3 == 0)
                {
                    paintingChildren[paintCounter].transform.position = GlobalVariables.objPositions[z];
                    paintingChildren[paintCounter].transform.rotation = GlobalVariables.objRotations[z];
                    InstantiatePaintingWithCaption(paintingChildren[paintCounter], paintingCaptions[paintCounter], Paintings[paintCounter]);

                    paintCounter++;
                }
                else
                {
                    // Position TAGS
                    if (z % 3 == 0)
                    {
                        paintingChildren[z / 3].GetComponent <ShowTags>().PositionTag(0, GlobalVariables.objPositions[z], GlobalVariables.objRotations[z]);
                    }
                    else
                    {
                        paintingChildren[z / 3].GetComponent <ShowTags>().PositionTag(1, GlobalVariables.objPositions[z], GlobalVariables.objRotations[z]);
                    }
                }
            }

            // Position the bag and its children
            bag.transform.position = new Vector3(0, 0, 1.0f);
            bag.transform.rotation = Quaternion.LookRotation(Vector3.forward);

            bag.GetComponent <TagsMenu>().PositionBag();

            // Instantiate Bars now that I have the Sizes of the painting objects (or box colliders)
            foreach (GameObject child in paintingChildren)
            {
                child.GetComponent <ShowTags>().InstantiateBars();
            }

            progressBar.SetActive(true);
            gameObject.GetComponent <GamingManager>().enabled = true;
        }
        else
        {
            this.InstructionTextMesh.text = "I can't find enough space to place the painting.";
        }
    }