Consuming FXRMotionControllerData in Blueprint
Before continuing this section, please ensure you've studied the Consuming FXRMotionControllerData section, first.
Drawing and Animating Virtual Hands
-
Create a new Virtual Reality project based the Unreal VR Template.
-
Make sure the SenseGlove UnrealEngine plugin is installed and enabled inside your new project.
-
You could use either hand-tracking or a SenseGlove device as the input data, or both of the inside the same project. Whether you would like to use hand-tracking or a SenseGlove device, please make sure the required steps are taken for each of those first.
-
You could add the required Blueprint code for drawing virtual hands to either your Level Buleprint or the VRPawn Blueprint Class located at
/Content/VRTemplate/Blueprints/VRPawn
. In this guide we are going to add the code to our VRPawn. -
Add a new function named
Draw Hand
with an input parameter of typeEController Hand
namedHand
.
- Inside this function's event graph add a
Get Motion Controller Data
node fromSenseGlove > Tracking > XR Tracker > Get Motion Controller Data
.
- Then connect the functions
Hand
input parameter to theGet Motion Controller Data
'sHand
input and right-click on theOutMotionControllerData
parameter and use theBreak XRMotionControllerData
node to break the struct to it's fields.
- After this, we need to perform data validation by checking the return status of the
Get Motion Controller Data
function andFXRMotionControllerData
'sValid
field. Then, we check if the motion controller device is being tracked and indeed coming from a hand-tracking source. And, finally, we check whether we have the positions and rotations for exactly26
joints or not.
- OK, now it's time to draw the joints! If we check out the SenseGlove Debug module's draw option, we notice there are various ways to draw the debug virtual hand. Drawing a cube or a gizmo per joint, or draw the whole hand all at once by passing the retrieved
FXRMotionControllerData
to theDebugVirtualHand::Draw
function! But, since the point of this tutorial is to learn how to consume theFXRMotionControllerData
we ignore the last option. Between the debug cubes or gizmos, we are going to choose the gizmos since they better represent the rotations than the cubes.
- In the last step inside the
Draw Hand
function, in order to draw a virtual hand with26
joints, we have to first iterate through either of theHand Key Positions
orHand Key Rotations
arrays from theFXRMotionControllerData
struct. Since we made sure both arrays have26
elements before we reached this step, it's safe to just iterate over one and use theArray Index
inside aFor Each Loop
or aFor Loop
to access the position and rotation of every joint. Then we use each arrayGet (a ref)
method to access the position and rotation data inside the loop and call theDraw
function fromSenseGlove > Debug > Gizmo
per every joint. Please note that there are twoDraw
functions and the only difference between the two is that one accepts anFQuat
and the other aFRotator
for itsRotation
input parameter. In this case, we use theFQuat
variant to avoid an extra conversion toFRotator
. Also, please adjust theThickness
option for theSettings
parameter from1.0
to0.2
, as the default value might be too thick for drawing a joint gizmo.
- Well, now the full implementation for the
Draw Hand
function insde theVRPawn
should look something like this:
- Finally, go back to
VRPawn
's event graph and the following code to theTick
event. Basically what we do here is call our newly implementedDraw Hand
twice, once for each hand.
- Now, go back to the
VRTemplateMap
and use the VR Preview button to run the game. If everything's done correctly, you should be able to see the virtual hands inside your VR simulation.