The pick and place mechanic is one of the most intuitive ways of interacting with digital models in mixed reality. Building this functionality is as simple as toggling between a 'pick' mode which finds and stores the index of the closest point to a users cursor, and a 'place' mode that replaces this point with the cursor position.
Initialization of the Points
An initial list of points is provided to interact with. These points can represent the control points of a curve, anchor points in a physics simulation, vertices in a mesh, center points of objects to move or simply point geometry. We store the location of the points in a global variable called pts that we will move around over time while interactive with our application.
To view the position of the points we create a mesh sphere at each point and send these to all connected mixed reality devices. To efficiently display the movement of these points of time (especially while previewing the point position in 'place' mode), we create a list of vectors between the initial position of the points and the current position stored in the pts global variable and use these vectors to create a transform that we can stream to the mixed reality device.
Interaction and switching modes
We toggle between picking and placing using the Flip Flip toggle connected to a State Gate with default outputs. This enables us to alternate between components in our definition that find the closest point to our cursor (picking) and those that update the position of our pts global.
We create the pick mode by finding the closest point to our cursor position. We use the dynamic update function of the Get Global Variable component to ensure that we are using the current position of our cursor (and not the position returned by the global variable when we first enter 'pick' mode). We only need to store the index of the closest point using another global variable called closest. These components are grouped and connected to the True output of the state gate.
We create the place mode by using the Replace Index component to replace the point at the closest index with the current position of our cursor. We allow this to take place each time we update our cursor position by enabling dynamic update on our liveCursor global variable. This in turn will update the components that render the current positions of our points.