MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Getting a Vector3 from Spatial Understanding Object Placement?

Open Caltato opened this issue 9 years ago • 5 comments

Hello! I am having a little difficulty understanding how Spatial Understanding Queries work.

What I want to do is just find a random point on the floor where the space above it is a minimum of 2.0f and spawn something there. But even from reading all the exmple codes, I dont see any Vector3's that I can get from the query structs. (Much less know which is the script actually calling the queries because of all the referencing back and forth between and within scripts.) Does the whole Spatial Understanding thing work in a different way of telling space?

Also do Object Placement Queries place an object or do they just find places that you can? And should I be using Topology or Object Placement?

Sorry just a bit lost. Thanks!

Caltato avatar Nov 07 '17 00:11 Caltato

You could add SurfaceProcessing and SurfaceMeshesToPlanes to your project and create planes from the spatial understanding mesh. If you choose to only generate floors from the mesh, you could easily get the planes using floors = SurfaceMeshesToPlanes.Instance.ActivePlanes. Then I guess using something like object.position = floors[i].transform.position - floor.transform.forward * 2.0f would spawn the object 2.0f over the center of the floor i.

eirikhollis avatar Nov 09 '17 12:11 eirikhollis

@eirikhollis Hey thanks for the reply! Hmm... Haven't got into SurfaceMeshesToPlanes yet. Something for me to check out. So it just generates multiple planes to cover the floor? Could I maybe generate planes for walls too?

Caltato avatar Nov 10 '17 00:11 Caltato

SurfaceMeshesToPlanes will generate planes for floors, walls, ceilings, and tables. Basically, anything that can be considered a plane. We cover the usage of this script (along with the SpatialMappingManager) in the MixedRealityAcademy 230 course: https://developer.microsoft.com/en-us/windows/mixed-reality/holograms_230. The SurfaceMeshesToPlanes script exposes a drop-down in Unity for selecting all of the types of planes you want to create/render.

I just wrote a game where I needed to know where the floor and walls are for object placement, but I didn't want the ceiling to interfere with the alien attackers coming from above. I was able to use the DestroyPlanes property of the SurfaceMeshesToPlanes script to remove the ceiling. I use both planes and Spatial Mapping meshes during object placement, and then disable the SpatialMappingManager's parent (which owns all of the meshes generated from Spatial Mapping) and only used the generated planes (minus the ceiling) during the battle sequence of my game. That way, projectiles bounce off of walls/floors, but I can still shoot enemies that fly above the ceiling.

Plane finding is a great alternative to using SpatialUnderstanding or the Spatial Mapping meshes directly, when you just need to find/use flat surfaces for object placement. The planefinding.dll was originally created by the team that created Robo Raid. If you need more complex understanding of the world, and a mesh that has no holes (especially good for AI navigation) then SpatialUnderstanding might be a better choice. That code was contributed by the team that made Fragments and Young Conker on the HoloLens.

I hope this is helpful, and that you find SpatialMapping/Planefinding useful :) ~Angela

angelaHillier avatar Nov 10 '17 01:11 angelaHillier

@angelaHillier Thanks Angela! That sounds really good. Hmm but I actually am considering using AI navigation later on in the project. But I'm still struggling to understand how to derive information from SpatialUnderstanding scripts. Like how can I check if there's a wall near an AI? Do I shoot a raycast at the mesh? How do I get information such as what type of surface it is and maybe how high it is?

I think it'll be really useful if SpatialUnderstanding came with Get_____() functions. E.g. GetTypeOfSurface() or GetSpaceAboveSurface() haha or maybe that's just me

Caltato avatar Nov 10 '17 01:11 Caltato

I recommend taking a look at the Mixed Reality documentation on Spatial Mapping and Spatial Understanding: https://docs.microsoft.com/en-us/windows/mixed-reality/spatial-mapping-in-unity#holotoolkit.spatialunderstanding

david-c-kline avatar May 21 '18 22:05 david-c-kline