Skip to content

Instantly share code, notes, and snippets.

@KzoNag
Created December 14, 2022 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KzoNag/a85b124ae9af8135ec29445a39961952 to your computer and use it in GitHub Desktop.
Save KzoNag/a85b124ae9af8135ec29445a39961952 to your computer and use it in GitHub Desktop.
ブログ用 - ハンドトラッキングデータの発行
[SerializeField]
private PXR_Hand _rightHand, _leftHand;
private const int ValidTrackingState = (int)(InputTrackingState.Position | InputTrackingState.Rotation);
private const int InvalidTrackingState = (int)InputTrackingState.None;
private const float GripThreshold = 0.5f;
private void Update()
{
if(_rightDevice != null && _rightDevice.added)
{
UpdateHand(_rightDevice, _rightHand);
}
if(_leftDevice != null && _leftDevice.added)
{
UpdateHand(_leftDevice, _leftHand);
}
}
private void UpdateHand(InputDevice device, PXR_Hand hand)
{
if(device == null || hand == null)
{
return;
}
var state = new HandDeviceState()
{
isTracked = hand.RayValid,
trackingState = hand.RayValid ? ValidTrackingState : InvalidTrackingState,
devicePosition = hand.RayPose.Position.ToVector3(),
deviceRotation = hand.RayPose.Orientation.ToQuat(),
grip = hand.TouchStrengthRay,
gripButton = (hand.TouchStrengthRay > GripThreshold)
};
InputSystem.QueueStateEvent(device, state);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment