My First “Real” Magic Leap Project: Part 2

We implement a number of application states to build the mesh.

John Tucker
Coinmonks
Published in
3 min readAug 3, 2018

--

This article is part of a multi-part series starting with My First “Real” Magic Leap Project: Part 1.

Building the Mesh

When utilizing MLSpatialMapper, one will observe that its Transform component defines the volume in which the mesh objects will be built and retained. With this in mind, the first step in the application will be for the user to define this volume.

The application starts with the MLSpatialMapper disabled and in a positioning state where the user uses a controller (in left hand) to position a semi-transparent blue cube.

By giving an Ok hand pose with the right hand, the user changes the state to scaling where the user a controller (in left hand) to scale the cube.

By giving an Ok hand pose with the right hand, the user changes the state to meshing; hides the cube and enables the MLSpatialMapper. At this point, the MLSpatialMapper will begin to build mesh object in the volume.

note: In the simulator, the mesh objects are built regardless of them being in view of the user; with the hardware, I am assume that they are only built when they are.

Implementing this functionality amounts to creating a semi-transparent blue cube (MeshingZone) in the scene, removing the unnecessary Box Collider component, and adding the following component.

Assets/Table/MeshingZone.cs

Observations:

  • There is certain simplicity in having all the implementation in a single file
  • The number of concerns (application state, input, hands, the cube, and the MLSpatialMapper) in this single file is already getting a bit overwhelming
  • As we add additional game components to the mix; continuing this approach will not scale well

State Management

At this point it is immediately clear that it will be critically important to implement a state management strategy before moving forward.

Through a bit of research (Google) and looking at Magic Leap’s Dodge example, one popular state management strategy is to use a finite state machine. The challenge here is that it seems that everyone seems to have their own implementation.

In the same vein, I have implemented a similar pattern using concepts borrowed from web development (Redux) and will continue with this approach.

Next Steps

In the next article, My First “Real” Magic Leap Project: Part 3, we refactor the current implementation using a Redux-like state management strategy.

--

--

John Tucker
Coinmonks

Broad infrastructure, development, and soft-skill background