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.SurfacePrefag, _resultsTopology[0].position, Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up)); } }
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); }
public void Query_Topology_FindLargePositionsOnWalls() { // Setup float minHeightOfWallSpace = 1.0f; float minWidthOfWallSpace = 1.5f; float minHeightAboveFloor = 1.5f; float minFacingClearance = 0.5f; // Only if we're enabled if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding) { return; } // Query IntPtr resultsTopologyPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); int locationCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargePositionsOnWalls( minHeightOfWallSpace, minWidthOfWallSpace, minHeightAboveFloor, minFacingClearance, resultsTopology.Length, resultsTopologyPtr); // Output HandleResults_Topology("Find Large Positions On Walls", locationCount, new Vector3(minWidthOfWallSpace, minHeightOfWallSpace, 0.025f), Color.yellow); }
private void InstantiateObjectOnSurface() { 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(ObjectPrefab, _resultsTopology[0].position, Quaternion.LookRotation(_resultsTopology[0].normal, Vector3.up)); this.InstructionTextMesh.text = "Placed the hologram"; } else { InstructionTextMesh.text = "I can't found the enough space to place the hologram."; } }
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)); } }
// Display and measure largest wall public void Query_Topology_MeasureLargestWall() { ClearGeometry(); // Only if we're enabled if (!SpatialUnderstanding.Instance.AllowSpatialUnderstanding) { return; } // Query IntPtr wallPtr = SpatialUnderstanding.Instance.UnderstandingDLL.PinObject(resultsTopology); int wallCount = SpatialUnderstandingDllTopology.QueryTopology_FindLargestWall( wallPtr); if (wallCount == 0) { AppState.Instance.SpaceQueryDescription = "Measure Largest Wall (0)"; return; } // Add the line boxes float timeDelay = (float)lineBoxList.Count * AnimatedBox.DelayPerItem; float ourWidth = resultsTopology[0].width + 0.18f; float ourLength = resultsTopology [0].length + 0.05f; lineBoxList.Add( new AnimatedBox( timeDelay, resultsTopology[0].position, Quaternion.LookRotation(resultsTopology[0].normal, Vector3.up), Color.magenta, new Vector3(ourWidth, ourLength, 0.05f) * 0.5f) ); AppState.Instance.SpaceQueryDescription = "Width(" + ourWidth.ToString("#.00") + "m) x Height (" + ourLength.ToString("#.00") + "m) Area: (" + (ourWidth * ourLength).ToString("#.00m") + ")"; }
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."); } }
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; } } }
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"); }
//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); }
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."; } }
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(); }
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); }