-
-
Save KzoNag/a85b124ae9af8135ec29445a39961952 to your computer and use it in GitHub Desktop.
ブログ用 - ハンドトラッキングデータの発行
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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