0

I'm trying to get the closest point on the spatial mesh obtained from MS Hololens. I could get the SpatialAwarenessMeshObject collider and gameObject easily with this reference (https://learn.microsoft.com/en-us/windows/mixed-reality/mrtk-unity/features/spatial-awareness/usage-guide?view=mrtkunity-2021-01)

It is running but not what I expected. The calculated closest point is not correct. Did I do it right? And please let me know differences between OnObservationAdded and OnObservationUpdated method.

enter image description here LineManager.cs script : I want to draw a line from a certain point to the closest point on the spatial mesh. This script tries to get the Collider of the SpatialAwarenessMeshObject and find the closest point on it.

enter image description here MeshManager.cs : This script implements the virtual method from the SpatialAwarenessHandler. I don't really know about what each virtual methods means.

Thanks.

BINN
  • 1

1 Answers1

0

It is pretty expensive trying to render a line for the distance property. We can try the following steps to accomplish this task: First, gets the position of your main camera with Camera.mainCamera.gameObject.transform.position and the vertex position of the mesh with Mesh.vertices. And then, transforms vertex position from local space to world space with Mesh.Transform.TransformPoint. Finally, invoke Vector3.Distance to obtain the distance between them.

And please let me know differences between OnObservationAdded and OnObservationUpdated method.

OnObservationAdded raises whenever a mesh is created by the observer and OnObservationUpdated raises whenever a mesh is updated. Please take a look at this source code to learn how it works: BaseSpatialMeshObserver.

Hernando - MSFT
  • 2,895
  • 1
  • 5
  • 11
  • Thank you so much for letting me know about the virtual methods of SpatialAwarenesshandler. But what I really want to know is "how can I get the right spatial mesh collider", not the distance to the vertices of the mesh. Once I get the right spatial mesh collider, then I will get the closest point with the method "Physics.ClosestPoint()". If my given information is not easy to understand and make you confuse, Sorry for that. This is my first question. Thanks for your answer. – BINN Dec 31 '21 at 01:33
  • To get the collider spatial mesh, just using [meshObject.Collider](https://learn.microsoft.com/en-us/dotnet/api/microsoft.mixedreality.toolkit.spatialawareness.spatialawarenessmeshobject.collider?view=mixed-reality-toolkit-unity-2019-dotnet-2.7.0). However, from your code, you assigned different value of dictionary to the same variable repeatedly in the loop, this caused part of the data to be missing. – Hernando - MSFT Dec 31 '21 at 06:55