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."; } }
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); }
public void OnInputClicked(InputClickedEventData eventData) { if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding) { return; } _searching = true; var minWidthOfWallSpace = 1f; var minHeightAboveFloor = 1f; // Query var resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(_resultsTopology); var locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor( minWidthOfWallSpace, minHeightAboveFloor, _resultsTopology.Length, resultsTopologyPtr); var visDesc = "Find Positions On Floor"; var boxFullDims = new Vector3(minWidthOfWallSpace, 0.025f, minHeightAboveFloor); var color = Color.red; ClearGeometry(); // Add the line boxes (we may have more results than boxes - pick evenly across the results in that case) var lineInc = Mathf.CeilToInt((float)locationCount / (float)DisplayResultMaxCount); var boxesDisplayed = 0; for (var i = 0; i < locationCount; i += lineInc) { var timeDelay = (float)_lineBoxList.Count * AnimatedBox.DelayPerItem; _lineBoxList.Add( new AnimatedBox( timeDelay, _resultsTopology[i].position, Quaternion.LookRotation(_resultsTopology[i].normal, Vector3.up), color, boxFullDims * 0.5f) ); ++boxesDisplayed; } // Vis description if (locationCount == boxesDisplayed) { _spaceQueryDescription = string.Format("{0} ({1})", visDesc, locationCount); } else { _spaceQueryDescription = string.Format("{0} (found={1}, displayed={2})", visDesc, locationCount, boxesDisplayed); } _searching = false; }
private void QueryFloorPositions() { float minWidth = 1f; float minLength = 1f; int numPositions = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor(minLength, minWidth, m_queryResults.Length, m_queryResultsPtr); Debug.Log("Found " + numPositions + " positions"); for (int i = 0; i < numPositions; i++) { var result = m_queryResults[i]; Debug.Log(" Position " + i + ": pos=" + result.position.ToString("F5") + ", length=" + result.length.ToString("F3") + ", width=" + result.width.ToString("F3") + ", normal=" + result.normal.ToString("F3")); MakeCube(result.position, result.normal); } }
public void Query_Topology_FindPositionsOnFloor() { // Setup float minWidthOfWallSpace = 1.0f; float minHeightAboveFloor = 1.0f; // Only if we're enabled if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding) { return; } // Query IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor( minWidthOfWallSpace, minHeightAboveFloor, resultsTopology.Length, resultsTopologyPtr); // Output HandleResults_Topology("Find Positions On Floor", locationCount, new Vector3(minWidthOfWallSpace, 0.025f, minHeightAboveFloor), Color.red); }
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."); } }
//Examples of ways to et locations and store them in location list. private IEnumerator GetSpawnLocations() { yield return(new WaitForSeconds(3)); //IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); //int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor( // resultsTopology.Length, resultsTopologyPtr); //Debug.Log(locationCount); //Debug.Log(resultsTopology[0].position); //END OF TEST EXAMPLES.. FINDING LOCATIONS FOR THE FLOOR NOW. SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects(); SpaceVisualizer.Instance.ClearGeometry(); IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsOnFloor( GameManager.Instance.shipManager.shipMaxHeight, GameManager.Instance.shipManager.shipMinHeight, resultsTopology.Length, resultsTopologyPtr); foreach (SpatialUnderstandingDllTopology.TopologyResult potentialShipFloor in resultsTopology) { SpatialLocation shipFloor = new SpatialLocation(); shipFloor.position = potentialShipFloor.position; shipFloor.normal = potentialShipFloor.normal; shipFloor.name = "shipFloor"; // this sould be a descriptive name of what positin is. spatialLocationList.Add(shipFloor); } // GETTING SPAWN LOCATION FOR GRID // SpaceVisualizer.Instance.ClearGeometry(); // resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); // locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestPositionsOnFloor( //resultsTopology.Length, resultsTopologyPtr); // SpatialLocation gridSittingLoc = new SpatialLocation(); // gridSittingLoc.position = resultsTopology[0].position; // gridSittingLoc.normal = resultsTopology[0].normal; // gridSittingLoc.name = "gridSittingLoc"; // this sould be a descriptive name of what positin is. // spatialLocationList.Add(gridSittingLoc); //SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects(); //SpaceVisualizer.Instance.ClearGeometry(); //float sitMinHeight = 0f; //float sitMaxHeight = 1.2f; //float sitMinFacingClearance = 2f; //SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects(); //resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); //int locationCount3 = SpatialUnderstandingDllTopology.QueryTopology_FindPositionsSittable( // sitMinHeight, sitMaxHeight, sitMinFacingClearance, // resultsTopology.Length, resultsTopologyPtr); //SpatialLocation gridSittingLoc = new SpatialLocation(); //gridSittingLoc.position = resultsTopology[0].position; //gridSittingLoc.normal = resultsTopology[0].normal; //gridSittingLoc.name = "gridSittingLoc"; // this sould be a descriptive name of what positin is. //spatialLocationList.Add(gridSittingLoc); SpatialUnderstandingDllObjectPlacement.Solver_RemoveAllObjects(); SpaceVisualizer.Instance.ClearGeometry(); IntPtr resultsShapePtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsShape); int shapeCount = SpatialUnderstandingDllShapes.QueryShape_FindShapeHalfDims( "Grid", resultsShape.Length, resultsShapePtr); Debug.Log(resultsShape[0].position); Debug.Log(resultsShape[0].halfDims); SpatialLocation gridSittingLoc = new SpatialLocation(); gridSittingLoc.position = resultsShape[0].position; gridSittingLoc.normal = resultsShape[0].halfDims; gridSittingLoc.name = "gridSittingLoc"; // this sould be a descriptive name of what positin is. spatialLocationList.Add(gridSittingLoc); yield return(null); }