It is possible to create applications with nested modes by using multiple state gates to control when and how interaction events are detected and switch between any arbitrary number of different tools. To create an application in which a user can both draw new curves and edit the control points of any existing curves, the parametric models for each of these modes are grouped (enabling efficient reuse of parametric models such as the Edit Control Points tool) and then enabled or disabled when a user clicks a corresponding button in the mixed reality experience.
Creating Buttons to Switch Modes
We create two button geometries (alternatively you could use arbitrary buttons with textures as in this example) and assign them the names Draw and Edit. These same names are used as filters to a Track Clicks component, with the name of the detected object used as the input to a state gate. The outputs of the state gate are also set to Draw and Edit. By only detecting clicks on these objects we ensure that our state gate only updates when we click on one of these buttons, enabling us to build functionality into the connected groups that only run once when we switch modes (such as saving the drawn curve when we switch back to edit mode).
To create the draw functionality, we use another Track Clicks component that detects all clicks in our experience. We create a very simple c# script that returns the current value of a global variable called pts whenever we detect a click. The pts variable is used to store all of the control points of the curve that is currently being drawn. To preview the shape of the curve when a new control point is added at the cursor position, we merge this list of points with the liveCursor point and then interpolate a new NURBS curve through this list. The pts list is updated to include this new point and the geometry of the currently drawn curve is stored in another global variable called newCrv.
This group is the same as the Edit Control Points tool with several additions that are used to reset the pts list to an empty value, and merge the current list of crvs with whatever was last drawn in Draw mode. These components run only once when the state gate updates this group.