Spatial mapping components

In the preceding section, we learned how to scan and visualize the environment using the low-level API. In this section, we will do it all again, but this time using the prebuilt components.

We will continue using the same scene, but will disable our SpatialMappingManager script. Do this by selecting SpatialMapping in the Hierarchy panel and unchecking the attached SpatialMappingManager (Script).

With SpatialMapping selected, add the Spatial Mapping component via the Component | AR | Spatial Mapping Collider (Script) menu.

Spatial Mapping Collider (Script) takes care of most code we wrote in the preceding section. It periodically manages polling for surface changes and manages the creation, updation, and deletion for each surface with respect to the change observed. When new surfaces are observed, the details of the surface are baked into the MeshFilter of the associated GameObjects and a MeshCollider is attached, essentially making the real world tangible in our virtual world. Update the Spatial Mapping Collider component properties with the following values:

  • Set Mesh Layer to SpatialSurface; this assigns our SpatialSurface layer to the instantiated GameObject.
  • Select and drag the SpatialMapping GameObject from the Hierarchy panel onto the Surface Parent field of the Spatial Mapping Collider component in the Inspector panel. Newly created GameObjects will be a child of this.
  • Update Time Between Updates to 3; this is the duration the environment will be scanned for before reconstructing the surfaces.
  • Set the Bounding Volume Type to Sphere and set Radius In Meters to 2; similar to the preceding section, this describes the bounding volume for this instance of Spatial Mapping.

The following is a screenshot of the SpatialMapping component:

At this stage, we have an interactive environment, but it is invisible. Even though we are not required to visualize the surfaces in our application, visualizing is helpful in understanding how HoloLens sees the world and useful when debugging. So, let's go ahead and add the ability to visualize the surfaces.

Similar to the Spatial Mapping Collider, this is simply a matter of adding a component to our scene. With SpatialMapping selected, select the Component | AR | Spatial Mapping Renderer menu item. This will add the component directly to your SpatialMapping GameObject. On first glance, the properties look similar to those of the Spatial Mapping Collider component; that is because they are. Spatial Mapping Collider and Spatial Mapping Renderer work independently; you can use them together or separately. Let's go ahead and configure Spatial Mapping Renderer to match our Spatial Mapping Collider component; in the Inspector panel, update the properties with the following values:

  • Set the Custom Rendering Setting to Custom Material; this will default to the SpatialMappingWireframe, the default material used in the previous section.
  • Select and drag the SpatialMapping GameObject from the project's Hierarchy panel to the Surface Parent property. This is, again, the parent GameObject that surfaces will be nested under.
  • Set the Time between Updates to 3.
  • Finally, set the Bounding Volume Type to Sphere and Radius In Meters to 2.

Your Inspector panel for SpatialMapping should look similar to the following screenshot:

Well done, you managed to achieve everything we did in the last section without writing a single line of code. Now go ahead and build and deploy to see whether you can spot any difference between the two approaches:

With access to the physical world, our next task is to place the bin on the ground, which is the topic of the next section.

Essentially, the approach you use to scan the environment is up to you, but the following chapters will be using which approach for reference.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.252.201