//======= Copyright (c) Valve Corporation, All rights reserved. ===============
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
namespace Valve.VR
{
[Serializable]
///
/// Skeleton Actions are our best approximation of where your hands are while holding vr controllers and pressing buttons. We give you 31 bones to help you animate hand models.
/// For more information check out this blog post: https://steamcommunity.com/games/250820/announcements/detail/1690421280625220068
///
public class SteamVR_Action_Skeleton : SteamVR_Action_Pose_Base, ISteamVR_Action_Skeleton_Source, ISerializationCallbackReceiver
{
public const int numBones = 31;
public delegate void ActiveChangeHandler(SteamVR_Action_Skeleton fromAction, bool active);
public delegate void ChangeHandler(SteamVR_Action_Skeleton fromAction);
public delegate void UpdateHandler(SteamVR_Action_Skeleton fromAction);
public delegate void TrackingChangeHandler(SteamVR_Action_Skeleton fromAction, ETrackingResult trackingState);
public delegate void ValidPoseChangeHandler(SteamVR_Action_Skeleton fromAction, bool validPose);
public delegate void DeviceConnectedChangeHandler(SteamVR_Action_Skeleton fromAction, bool deviceConnected);
/// Event fires when the active state (ActionSet active and binding active) changes
public event ActiveChangeHandler onActiveChange
{ add { sourceMap[SteamVR_Input_Sources.Any].onActiveChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onActiveChange -= value; } }
/// Event fires when the active state of the binding changes
public event ActiveChangeHandler onActiveBindingChange
{ add { sourceMap[SteamVR_Input_Sources.Any].onActiveBindingChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onActiveBindingChange -= value; } }
/// Event fires when the state of the pose or bones moves more than the changeTolerance
public event ChangeHandler onChange
{ add { sourceMap[SteamVR_Input_Sources.Any].onChange += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onChange -= value; } }
/// Event fires when the action is updated
public event UpdateHandler onUpdate
{ add { sourceMap[SteamVR_Input_Sources.Any].onUpdate += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onUpdate -= value; } }
/// Event fires when the state of the tracking system that is used to create pose data (position, rotation, etc) changes
public event TrackingChangeHandler onTrackingChanged
{ add { sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged -= value; } }
/// Event fires when the state of the pose data retrieved for this action changes validity (good/bad data from the tracking source)
public event ValidPoseChangeHandler onValidPoseChanged
{ add { sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged -= value; } }
/// Event fires when the device bound to this action is connected or disconnected
public event DeviceConnectedChangeHandler onDeviceConnectedChanged
{ add { sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged += value; } remove { sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged -= value; } }
public SteamVR_Action_Skeleton() { }
///
/// [Should not be called by user code]
/// Updates the skeleton action data
///
public virtual void UpdateValue(bool skipStateAndEventUpdates)
{
sourceMap[SteamVR_Input_Sources.Any].UpdateValue(skipStateAndEventUpdates);
}
///
/// [Should not be called by user code]
/// Updates the skeleton action data without firing events
///
public void UpdateValueWithoutEvents()
{
sourceMap[SteamVR_Input_Sources.Any].UpdateValue(true);
}
///
/// Update a transform's local position and local roation to match the pose from the most recent update
///
/// The transform of the object to be updated
public void UpdateTransform(Transform transformToUpdate)
{
base.UpdateTransform(SteamVR_Input_Sources.Any, transformToUpdate);
}
#region skeleton source properties
/// An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Vector3[] bonePositions { get { return sourceMap[SteamVR_Input_Sources.Any].bonePositions; } }
/// An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Quaternion[] boneRotations { get { return sourceMap[SteamVR_Input_Sources.Any].boneRotations; } }
/// From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Vector3[] lastBonePositions { get { return sourceMap[SteamVR_Input_Sources.Any].lastBonePositions; } }
/// From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Quaternion[] lastBoneRotations { get { return sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations; } }
/// The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.
public EVRSkeletalMotionRange rangeOfMotion
{
get { return sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion; }
set { sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion = value; }
}
/// The space to get bone data in. Parent space by default
public EVRSkeletalTransformSpace skeletalTransformSpace
{
get { return sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace; }
set { sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace = value; }
}
/// The type of summary data that will be retrieved by default. FromAnimation is smoothed data to based on the skeletal animation system. FromDevice is as recent from the device as we can get - may be different data from smoothed.
public EVRSummaryType summaryDataType
{
get { return sourceMap[SteamVR_Input_Sources.Any].summaryDataType; }
set { sourceMap[SteamVR_Input_Sources.Any].summaryDataType = value; }
}
///
/// Get the accuracy level of the skeletal tracking data.
/// * Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
/// * Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
/// * Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
///
public EVRSkeletalTrackingLevel skeletalTrackingLevel
{
get { return sourceMap[SteamVR_Input_Sources.Any].skeletalTrackingLevel; }
}
/// A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
public float thumbCurl { get { return sourceMap[SteamVR_Input_Sources.Any].thumbCurl; } }
/// A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
public float indexCurl { get { return sourceMap[SteamVR_Input_Sources.Any].indexCurl; } }
/// A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
public float middleCurl { get { return sourceMap[SteamVR_Input_Sources.Any].middleCurl; } }
/// A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
public float ringCurl { get { return sourceMap[SteamVR_Input_Sources.Any].ringCurl; } }
/// A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
public float pinkyCurl { get { return sourceMap[SteamVR_Input_Sources.Any].pinkyCurl; } }
/// A 0-1 value representing the size of the gap between the thumb and index fingers
public float thumbIndexSplay { get { return sourceMap[SteamVR_Input_Sources.Any].thumbIndexSplay; } }
/// A 0-1 value representing the size of the gap between the index and middle fingers
public float indexMiddleSplay { get { return sourceMap[SteamVR_Input_Sources.Any].indexMiddleSplay; } }
/// A 0-1 value representing the size of the gap between the middle and ring fingers
public float middleRingSplay { get { return sourceMap[SteamVR_Input_Sources.Any].middleRingSplay; } }
/// A 0-1 value representing the size of the gap between the ring and pinky fingers
public float ringPinkySplay { get { return sourceMap[SteamVR_Input_Sources.Any].ringPinkySplay; } }
/// [Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
public float lastThumbCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastThumbCurl; } }
/// [Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
public float lastIndexCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastIndexCurl; } }
/// [Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
public float lastMiddleCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastMiddleCurl; } }
/// [Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
public float lastRingCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastRingCurl; } }
/// [Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
public float lastPinkyCurl { get { return sourceMap[SteamVR_Input_Sources.Any].lastPinkyCurl; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers
public float lastThumbIndexSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastThumbIndexSplay; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers
public float lastIndexMiddleSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastIndexMiddleSplay; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers
public float lastMiddleRingSplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastMiddleRingSplay; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers
public float lastRingPinkySplay { get { return sourceMap[SteamVR_Input_Sources.Any].lastRingPinkySplay; } }
/// 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] fingerCurls { get { return sourceMap[SteamVR_Input_Sources.Any].fingerCurls; } }
/// 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] fingerSplays { get { return sourceMap[SteamVR_Input_Sources.Any].fingerSplays; } }
/// [Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] lastFingerCurls { get { return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls; } }
/// [Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] lastFingerSplays { get { return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays; } }
/// Separate from "changed". If the pose for this skeleton action has changed (root position/rotation)
public bool poseChanged { get { return sourceMap[SteamVR_Input_Sources.Any].poseChanged; } }
/// Skips processing the full per bone data and only does the summary data
public bool onlyUpdateSummaryData { get { return sourceMap[SteamVR_Input_Sources.Any].onlyUpdateSummaryData; } set { sourceMap[SteamVR_Input_Sources.Any].onlyUpdateSummaryData = value; } }
#endregion
#region pose functions with SteamVR_Input_Sources.Any
/// True if this action is bound and the ActionSet is active
public bool GetActive()
{
return sourceMap[SteamVR_Input_Sources.Any].active;
}
/// True if the ActionSet that contains this action is active
public bool GetSetActive()
{
return actionSet.IsActive(SteamVR_Input_Sources.Any);
}
///
/// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive.
///
/// The time offset in the future (estimated) or in the past (previously recorded) you want to get data from
/// true if we successfully returned a pose
public bool GetVelocitiesAtTimeOffset(float secondsFromNow, out Vector3 velocity, out Vector3 angularVelocity)
{
return sourceMap[SteamVR_Input_Sources.Any].GetVelocitiesAtTimeOffset(secondsFromNow, out velocity, out angularVelocity);
}
///
/// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive.
///
/// The time offset in the future (estimated) or in the past (previously recorded) you want to get data from
/// true if we successfully returned a pose
public bool GetPoseAtTimeOffset(float secondsFromNow, out Vector3 position, out Quaternion rotation, out Vector3 velocity, out Vector3 angularVelocity)
{
return sourceMap[SteamVR_Input_Sources.Any].GetPoseAtTimeOffset(secondsFromNow, out position, out rotation, out velocity, out angularVelocity);
}
/// The local position of the pose relative to the universe origin
public Vector3 GetLocalPosition()
{
return sourceMap[SteamVR_Input_Sources.Any].localPosition;
}
/// The local rotation of the pose relative to the universe origin
public Quaternion GetLocalRotation()
{
return sourceMap[SteamVR_Input_Sources.Any].localRotation;
}
/// The local velocity of the pose relative to the universe origin
public Vector3 GetVelocity()
{
return sourceMap[SteamVR_Input_Sources.Any].velocity;
}
/// The local angular velocity of the pose relative to the universe origin
public Vector3 GetAngularVelocity()
{
return sourceMap[SteamVR_Input_Sources.Any].angularVelocity;
}
/// True if the device bound to this action is connected
public bool GetDeviceIsConnected()
{
return sourceMap[SteamVR_Input_Sources.Any].deviceIsConnected;
}
/// True if the pose retrieved for this action is valid (good data from the tracking source)
public bool GetPoseIsValid()
{
return sourceMap[SteamVR_Input_Sources.Any].poseIsValid;
}
/// The state of the tracking system that is used to create pose data (position, rotation, etc)
public ETrackingResult GetTrackingResult()
{
return sourceMap[SteamVR_Input_Sources.Any].trackingState;
}
/// The last local position of the pose relative to the universe origin
public Vector3 GetLastLocalPosition()
{
return sourceMap[SteamVR_Input_Sources.Any].lastLocalPosition;
}
/// The last local rotation of the pose relative to the universe origin
public Quaternion GetLastLocalRotation()
{
return sourceMap[SteamVR_Input_Sources.Any].lastLocalRotation;
}
/// The last local velocity of the pose relative to the universe origin
public Vector3 GetLastVelocity()
{
return sourceMap[SteamVR_Input_Sources.Any].lastVelocity;
}
/// The last local angular velocity of the pose relative to the universe origin
public Vector3 GetLastAngularVelocity()
{
return sourceMap[SteamVR_Input_Sources.Any].lastAngularVelocity;
}
/// True if the device bound to this action was connected during the previous update
public bool GetLastDeviceIsConnected()
{
return sourceMap[SteamVR_Input_Sources.Any].lastDeviceIsConnected;
}
/// True if the pose was valid during the previous update
public bool GetLastPoseIsValid()
{
return sourceMap[SteamVR_Input_Sources.Any].lastPoseIsValid;
}
/// The tracking state for this pose during the previous update
public ETrackingResult GetLastTrackingResult()
{
return sourceMap[SteamVR_Input_Sources.Any].lastTrackingState;
}
#endregion
///
/// The number of bones in the skeleton for this action
///
public int boneCount { get { return (int)GetBoneCount(); } }
///
/// Gets the bone positions in local space. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public Vector3[] GetBonePositions(bool copy = false)
{
if (copy)
return (Vector3[])sourceMap[SteamVR_Input_Sources.Any].bonePositions.Clone();
return sourceMap[SteamVR_Input_Sources.Any].bonePositions;
}
///
/// Gets the bone rotations in local space. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public Quaternion[] GetBoneRotations(bool copy = false)
{
if (copy)
return (Quaternion[])sourceMap[SteamVR_Input_Sources.Any].boneRotations.Clone();
return sourceMap[SteamVR_Input_Sources.Any].boneRotations;
}
///
/// Gets the bone positions in local space from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public Vector3[] GetLastBonePositions(bool copy = false)
{
if (copy)
return (Vector3[])sourceMap[SteamVR_Input_Sources.Any].lastBonePositions.Clone();
return sourceMap[SteamVR_Input_Sources.Any].lastBonePositions;
}
///
/// Gets the bone rotations in local space from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public Quaternion[] GetLastBoneRotations(bool copy = false)
{
if (copy)
return (Quaternion[])sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations.Clone();
return sourceMap[SteamVR_Input_Sources.Any].lastBoneRotations;
}
///
/// Set the range of the motion of the bones in this skeleton. Options are "With Controller" as if your hand is holding your VR controller.
/// Or "Without Controller" as if your hand is empty. This will set the range for the following update.
///
public void SetRangeOfMotion(EVRSkeletalMotionRange range)
{
sourceMap[SteamVR_Input_Sources.Any].rangeOfMotion = range;
}
///
/// Sets the space that you'll get bone data back in. Options are relative to the Model and relative to the Parent bone
///
/// the space that you'll get bone data back in. Options are relative to the Model and relative to the Parent bone.
public void SetSkeletalTransformSpace(EVRSkeletalTransformSpace space)
{
sourceMap[SteamVR_Input_Sources.Any].skeletalTransformSpace = space;
}
///
/// Returns the total number of bones in the skeleton
///
public uint GetBoneCount()
{
return sourceMap[SteamVR_Input_Sources.Any].GetBoneCount();
}
///
/// Returns the order of bones in the hierarchy
///
public int[] GetBoneHierarchy()
{
return sourceMap[SteamVR_Input_Sources.Any].GetBoneHierarchy();
}
///
/// Returns the name of the bone
///
public string GetBoneName(int boneIndex)
{
return sourceMap[SteamVR_Input_Sources.Any].GetBoneName(boneIndex);
}
///
/// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
///
/// What to get the position/rotation data relative to, the model, or the bone's parent
/// Which reference pose to return
///
public SteamVR_Utils.RigidTransform[] GetReferenceTransforms(EVRSkeletalTransformSpace transformSpace, EVRSkeletalReferencePose referencePose)
{
return sourceMap[SteamVR_Input_Sources.Any].GetReferenceTransforms(transformSpace, referencePose);
}
///
/// Get the accuracy level of the skeletal tracking data.
///
///
///
/// - Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
/// - Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
/// - Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
///
///
public EVRSkeletalTrackingLevel GetSkeletalTrackingLevel()
{
return sourceMap[SteamVR_Input_Sources.Any].GetSkeletalTrackingLevel();
}
///
/// Returns the finger curl data that we calculate each update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public float[] GetFingerCurls(bool copy = false)
{
if (copy)
return (float[])sourceMap[SteamVR_Input_Sources.Any].fingerCurls.Clone();
else
return sourceMap[SteamVR_Input_Sources.Any].fingerCurls;
}
///
/// Returns the finger curl data from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public float[] GetLastFingerCurls(bool copy = false)
{
if (copy)
return (float[])sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls.Clone();
else
return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls;
}
///
/// Returns the finger splay data that we calculate each update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public float[] GetFingerSplays(bool copy = false)
{
if (copy)
return (float[])sourceMap[SteamVR_Input_Sources.Any].fingerSplays.Clone();
else
return sourceMap[SteamVR_Input_Sources.Any].fingerSplays;
}
///
/// Returns the finger splay data from the previous update. This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
///
/// This array may be modified later so if you want to hold this data then pass true to get a copy of the data instead of the actual array
public float[] GetLastFingerSplays(bool copy = false)
{
if (copy)
return (float[])sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays.Clone();
else
return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays;
}
///
/// Returns a value indicating how much the passed in finger is currently curled.
///
/// The index of the finger to return a curl value for. 0-4. thumb, index, middle, ring, pinky
/// 0-1 value. 0 being straight, 1 being fully curled.
public float GetFingerCurl(int finger)
{
return sourceMap[SteamVR_Input_Sources.Any].fingerCurls[finger];
}
///
/// Returns a value indicating how the size of the gap between fingers.
///
/// The index of the finger gap to return a splay value for. 0 being the gap between thumb and index, 1 being the gap between index and middle, 2 being the gap between middle and ring, and 3 being the gap between ring and pinky.
/// 0-1 value. 0 being no gap, 1 being "full" gap
public float GetSplay(int fingerGapIndex)
{
return sourceMap[SteamVR_Input_Sources.Any].fingerSplays[fingerGapIndex];
}
///
/// Returns a value indicating how much the passed in finger is currently curled.
///
/// The finger to return a curl value for
/// 0-1 value. 0 being straight, 1 being fully curled.
public float GetFingerCurl(SteamVR_Skeleton_FingerIndexEnum finger)
{
return GetFingerCurl((int)finger);
}
///
/// Returns a value indicating how the size of the gap between fingers.
///
/// The finger gap to return a splay value for.
/// 0-1 value. 0 being no gap, 1 being "full" gap
public float GetSplay(SteamVR_Skeleton_FingerSplayIndexEnum fingerSplay)
{
return GetSplay((int)fingerSplay);
}
///
/// Returns a value indicating how much the passed in finger was curled during the previous update
///
/// The index of the finger to return a curl value for. 0-4. thumb, index, middle, ring, pinky
/// 0-1 value. 0 being straight, 1 being fully curled.
public float GetLastFingerCurl(int finger)
{
return sourceMap[SteamVR_Input_Sources.Any].lastFingerCurls[finger];
}
///
/// Returns a value indicating the size of the gap between fingers during the previous update
///
/// The index of the finger gap to return a splay value for. 0 being the gap between thumb and index, 1 being the gap between index and middle, 2 being the gap between middle and ring, and 3 being the gap between ring and pinky.
/// 0-1 value. 0 being no gap, 1 being "full" gap
public float GetLastSplay(int fingerGapIndex)
{
return sourceMap[SteamVR_Input_Sources.Any].lastFingerSplays[fingerGapIndex];
}
///
/// Returns a value indicating how much the passed in finger was curled during the previous update
///
/// The finger to return a curl value for
/// 0-1 value. 0 being straight, 1 being fully curled.
public float GetLastFingerCurl(SteamVR_Skeleton_FingerIndexEnum finger)
{
return GetLastFingerCurl((int)finger);
}
///
/// Returns a value indicating the size of the gap between fingers during the previous update
///
/// The finger gap to return a splay value for.
/// 0-1 value. 0 being no gap, 1 being "full" gap
public float GetLastSplay(SteamVR_Skeleton_FingerSplayIndexEnum fingerSplay)
{
return GetLastSplay((int)fingerSplay);
}
///
/// Gets the localized name of the device that the action corresponds to. Include as many EVRInputStringBits as you want to add to the localized string
///
///
///
/// - VRInputString_Hand - Which hand the origin is in. ex: "Left Hand".
/// - VRInputString_ControllerType - What kind of controller the user has in that hand. ex: "Vive Controller".
/// - VRInputString_InputSource - What part of that controller is the origin. ex: "Trackpad".
/// - VRInputString_All - All of the above. ex: "Left Hand Vive Controller Trackpad".
///
///
public string GetLocalizedName(params EVRInputStringBits[] localizedParts)
{
return sourceMap[SteamVR_Input_Sources.Any].GetLocalizedOriginPart(localizedParts);
}
///
/// Removes all listeners, useful for dispose pattern
///
public void RemoveAllListeners(SteamVR_Input_Sources input_Sources)
{
sourceMap[input_Sources].RemoveAllListeners();
}
/// Fires an event when a device is connected or disconnected.
/// The method you would like to be called when a device is connected. Should take a SteamVR_Action_Pose as a param
public void AddOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The method you would like to stop calling when a device is connected. Should take a SteamVR_Action_Pose as a param
public void RemoveOnDeviceConnectedChanged(DeviceConnectedChangeHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onDeviceConnectedChanged -= functionToStopCalling;
}
/// Fires an event when the tracking of the device has changed
/// The method you would like to be called when tracking has changed. Should take a SteamVR_Action_Pose as a param
public void AddOnTrackingChanged(TrackingChangeHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The method you would like to stop calling when tracking has changed. Should take a SteamVR_Action_Pose as a param
public void RemoveOnTrackingChanged(TrackingChangeHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onTrackingChanged -= functionToStopCalling;
}
/// Fires an event when the device now has a valid pose or no longer has a valid pose
/// The method you would like to be called when the pose has become valid or invalid. Should take a SteamVR_Action_Pose as a param
public void AddOnValidPoseChanged(ValidPoseChangeHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The method you would like to stop calling when the pose has become valid or invalid. Should take a SteamVR_Action_Pose as a param
public void RemoveOnValidPoseChanged(ValidPoseChangeHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onValidPoseChanged -= functionToStopCalling;
}
/// Executes a function when this action's bound state changes
public void AddOnActiveChangeListener(ActiveChangeHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onActiveChange += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The local function that you've setup to receive update events
public void RemoveOnActiveChangeListener(ActiveChangeHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onActiveChange -= functionToStopCalling;
}
/// Executes a function when the state of this action changes
/// A local function that receives the boolean action who's state has changed, the corresponding input source, and the new value
public void AddOnChangeListener(ChangeHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onChange += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The local function that you've setup to receive on change events
public void RemoveOnChangeListener(ChangeHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onChange -= functionToStopCalling;
}
/// Executes a function when the state of this action is updated.
/// A local function that receives the boolean action who's state has changed, the corresponding input source, and the new value
public void AddOnUpdateListener(UpdateHandler functionToCall)
{
sourceMap[SteamVR_Input_Sources.Any].onUpdate += functionToCall;
}
/// Stops executing the function setup by the corresponding AddListener
/// The local function that you've setup to receive update events
public void RemoveOnUpdateListener(UpdateHandler functionToStopCalling)
{
sourceMap[SteamVR_Input_Sources.Any].onUpdate -= functionToStopCalling;
}
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
InitAfterDeserialize();
}
public static Quaternion steamVRFixUpRotation = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
}
public class SteamVR_Action_Skeleton_Source_Map : SteamVR_Action_Pose_Source_Map
{
protected override SteamVR_Action_Skeleton_Source GetSourceElementForIndexer(SteamVR_Input_Sources inputSource)
{
return sources[0]; //just in case somebody tries to access a different element, redirect them to the correct one.
}
}
///
/// Skeleton Actions are our best approximation of where your hands are while holding vr controllers and pressing buttons. We give you 31 bones to help you animate hand models.
/// For more information check out this blog post: https://steamcommunity.com/games/250820/announcements/detail/1690421280625220068
///
public class SteamVR_Action_Skeleton_Source : SteamVR_Action_Pose_Source, ISteamVR_Action_Skeleton_Source
{
protected static uint skeletonActionData_size = 0;
/// Event fires when the active state (ActionSet active and binding active) changes
public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveChange;
/// Event fires when the active state of the binding changes
public new event SteamVR_Action_Skeleton.ActiveChangeHandler onActiveBindingChange;
/// Event fires when the orientation of the pose or bones changes more than the changeTolerance
public new event SteamVR_Action_Skeleton.ChangeHandler onChange;
/// Event fires when the action is updated
public new event SteamVR_Action_Skeleton.UpdateHandler onUpdate;
/// Event fires when the state of the tracking system that is used to create pose data (position, rotation, etc) changes
public new event SteamVR_Action_Skeleton.TrackingChangeHandler onTrackingChanged;
/// Event fires when the state of the pose data retrieved for this action changes validity (good/bad data from the tracking source)
public new event SteamVR_Action_Skeleton.ValidPoseChangeHandler onValidPoseChanged;
/// Event fires when the device bound to this action is connected or disconnected
public new event SteamVR_Action_Skeleton.DeviceConnectedChangeHandler onDeviceConnectedChanged;
/// True if the action is bound
public override bool activeBinding { get { return skeletonActionData.bActive; } }
/// True if the action's binding was active during the previous update
public override bool lastActiveBinding { get { return lastSkeletonActionData.bActive; } }
/// An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Vector3[] bonePositions { get; protected set; }
/// An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Quaternion[] boneRotations { get; protected set; }
/// From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Vector3[] lastBonePositions { get; protected set; }
/// From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
public Quaternion[] lastBoneRotations { get; protected set; }
/// The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.
public EVRSkeletalMotionRange rangeOfMotion { get; set; }
/// The space to get bone data in. Parent space by default
public EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
/// The type of summary data that will be retrieved by default. FromAnimation is smoothed data to based on the skeletal animation system. FromDevice is as recent from the device as we can get - may be different data from smoothed.
public EVRSummaryType summaryDataType { get; set; }
/// A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
public float thumbCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
/// A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
public float indexCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
/// A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
public float middleCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
/// A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
public float ringCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
/// A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
public float pinkyCurl { get { return fingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
/// A 0-1 value representing the size of the gap between the thumb and index fingers
public float thumbIndexSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
/// A 0-1 value representing the size of the gap between the index and middle fingers
public float indexMiddleSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
/// A 0-1 value representing the size of the gap between the middle and ring fingers
public float middleRingSplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
/// A 0-1 value representing the size of the gap between the ring and pinky fingers
public float ringPinkySplay { get { return fingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
/// [Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
public float lastThumbCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.thumb]; } }
/// [Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
public float lastIndexCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.index]; } }
/// [Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
public float lastMiddleCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.middle]; } }
/// [Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
public float lastRingCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.ring]; } }
/// [Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
public float lastPinkyCurl { get { return lastFingerCurls[SteamVR_Skeleton_FingerIndexes.pinky]; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers
public float lastThumbIndexSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.thumbIndex]; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers
public float lastIndexMiddleSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.indexMiddle]; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers
public float lastMiddleRingSplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.middleRing]; } }
/// [Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers
public float lastRingPinkySplay { get { return lastFingerSplays[SteamVR_Skeleton_FingerSplayIndexes.ringPinky]; } }
/// 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] fingerCurls { get; protected set; }
/// 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] fingerSplays { get; protected set; }
/// [Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] lastFingerCurls { get; protected set; }
/// [Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
public float[] lastFingerSplays { get; protected set; }
/// Separate from "changed". If the pose for this skeleton action has changed (root position/rotation)
public bool poseChanged { get; protected set; }
/// Skips processing the full per bone data and only does the summary data
public bool onlyUpdateSummaryData { get; set; }
protected VRSkeletalSummaryData_t skeletalSummaryData = new VRSkeletalSummaryData_t();
protected VRSkeletalSummaryData_t lastSkeletalSummaryData = new VRSkeletalSummaryData_t();
protected SteamVR_Action_Skeleton skeletonAction;
protected VRBoneTransform_t[] tempBoneTransforms = new VRBoneTransform_t[SteamVR_Action_Skeleton.numBones];
protected InputSkeletalActionData_t skeletonActionData = new InputSkeletalActionData_t();
protected InputSkeletalActionData_t lastSkeletonActionData = new InputSkeletalActionData_t();
protected InputSkeletalActionData_t tempSkeletonActionData = new InputSkeletalActionData_t();
public override void Preinitialize(SteamVR_Action wrappingAction, SteamVR_Input_Sources forInputSource)
{
base.Preinitialize(wrappingAction, forInputSource);
skeletonAction = (SteamVR_Action_Skeleton)wrappingAction;
bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
lastBonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
lastBoneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
rangeOfMotion = EVRSkeletalMotionRange.WithController;
skeletalTransformSpace = EVRSkeletalTransformSpace.Parent;
fingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
fingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
lastFingerCurls = new float[SteamVR_Skeleton_FingerIndexes.enumArray.Length];
lastFingerSplays = new float[SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length];
}
///
/// [Should not be called by user code]
/// Initializes the handle for the inputSource, the skeletal action data size, and any other related SteamVR data.
///
public override void Initialize()
{
base.Initialize();
if (skeletonActionData_size == 0)
skeletonActionData_size = (uint)Marshal.SizeOf(typeof(InputSkeletalActionData_t));
}
///
/// Removes all listeners, useful for dispose pattern
///
public override void RemoveAllListeners()
{
base.RemoveAllListeners();
Delegate[] delegates;
if (onActiveChange != null)
{
delegates = onActiveChange.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onActiveChange -= (SteamVR_Action_Skeleton.ActiveChangeHandler)existingDelegate;
}
if (onActiveBindingChange != null)
{
delegates = onActiveBindingChange.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onActiveBindingChange -= (SteamVR_Action_Skeleton.ActiveChangeHandler)existingDelegate;
}
if (onChange != null)
{
delegates = onChange.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onChange -= (SteamVR_Action_Skeleton.ChangeHandler)existingDelegate;
}
if (onUpdate != null)
{
delegates = onUpdate.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onUpdate -= (SteamVR_Action_Skeleton.UpdateHandler)existingDelegate;
}
if (onTrackingChanged != null)
{
delegates = onTrackingChanged.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onTrackingChanged -= (SteamVR_Action_Skeleton.TrackingChangeHandler)existingDelegate;
}
if (onValidPoseChanged != null)
{
delegates = onValidPoseChanged.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onValidPoseChanged -= (SteamVR_Action_Skeleton.ValidPoseChangeHandler)existingDelegate;
}
if (onDeviceConnectedChanged != null)
{
delegates = onDeviceConnectedChanged.GetInvocationList();
if (delegates != null)
foreach (Delegate existingDelegate in delegates)
onDeviceConnectedChanged -= (SteamVR_Action_Skeleton.DeviceConnectedChangeHandler)existingDelegate;
}
}
/// [Should not be called by user code]
/// Updates the data for this action and this input source. Sends related events.
///
public override void UpdateValue()
{
UpdateValue(false);
}
/// [Should not be called by user code]
/// Updates the data for this action and this input source. Sends related events.
///
public override void UpdateValue(bool skipStateAndEventUpdates)
{
lastActive = active;
lastSkeletonActionData = skeletonActionData;
lastSkeletalSummaryData = skeletalSummaryData;
if (onlyUpdateSummaryData == false)
{
for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
{
lastBonePositions[boneIndex] = bonePositions[boneIndex];
lastBoneRotations[boneIndex] = boneRotations[boneIndex];
}
}
for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerIndexes.enumArray.Length; fingerIndex++)
{
lastFingerCurls[fingerIndex] = fingerCurls[fingerIndex];
}
for (int fingerIndex = 0; fingerIndex < SteamVR_Skeleton_FingerSplayIndexes.enumArray.Length; fingerIndex++)
{
lastFingerSplays[fingerIndex] = fingerSplays[fingerIndex];
}
base.UpdateValue(true);
poseChanged = changed;
EVRInputError error = OpenVR.Input.GetSkeletalActionData(handle, ref skeletonActionData, skeletonActionData_size);
if (error != EVRInputError.None)
{
Debug.LogError("[SteamVR] GetSkeletalActionData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
return;
}
if (active)
{
if (onlyUpdateSummaryData == false)
{
error = OpenVR.Input.GetSkeletalBoneData(handle, skeletalTransformSpace, rangeOfMotion, tempBoneTransforms);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetSkeletalBoneData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
{
// SteamVR's coordinate system is right handed, and Unity's is left handed. The FBX data has its
// X axis flipped when Unity imports it, so here we need to flip the X axis as well
bonePositions[boneIndex].x = -tempBoneTransforms[boneIndex].position.v0;
bonePositions[boneIndex].y = tempBoneTransforms[boneIndex].position.v1;
bonePositions[boneIndex].z = tempBoneTransforms[boneIndex].position.v2;
boneRotations[boneIndex].x = tempBoneTransforms[boneIndex].orientation.x;
boneRotations[boneIndex].y = -tempBoneTransforms[boneIndex].orientation.y;
boneRotations[boneIndex].z = -tempBoneTransforms[boneIndex].orientation.z;
boneRotations[boneIndex].w = tempBoneTransforms[boneIndex].orientation.w;
}
// Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
// so that forward is facing down +Z
boneRotations[0] = SteamVR_Action_Skeleton.steamVRFixUpRotation * boneRotations[0];
}
UpdateSkeletalSummaryData(summaryDataType, true);
}
if (changed == false)
{
for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++)
{
if (Vector3.Distance(lastBonePositions[boneIndex], bonePositions[boneIndex]) > changeTolerance)
{
changed = true;
break;
}
if (Mathf.Abs(Quaternion.Angle(lastBoneRotations[boneIndex], boneRotations[boneIndex])) > changeTolerance)
{
changed = true;
break;
}
}
}
if (changed)
changedTime = Time.realtimeSinceStartup;
if (skipStateAndEventUpdates == false)
CheckAndSendEvents();
}
///
/// The number of bones in the skeleton for this action
///
public int boneCount { get { return (int)GetBoneCount(); } }
///
/// Gets the number of bones in the skeleton for this action
///
public uint GetBoneCount()
{
uint boneCount = 0;
EVRInputError error = OpenVR.Input.GetBoneCount(handle, ref boneCount);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetBoneCount error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
return boneCount;
}
///
/// Gets the ordering of the bone hierarchy
///
public int[] boneHierarchy { get { return GetBoneHierarchy(); } }
///
/// Gets the ordering of the bone hierarchy
///
public int[] GetBoneHierarchy()
{
int boneCount = (int)GetBoneCount();
int[] parentIndicies = new int[boneCount];
EVRInputError error = OpenVR.Input.GetBoneHierarchy(handle, parentIndicies);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetBoneHierarchy error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
return parentIndicies;
}
///
/// Gets the name for a bone at the specified index
///
public string GetBoneName(int boneIndex)
{
StringBuilder stringBuilder = new StringBuilder(255);
EVRInputError error = OpenVR.Input.GetBoneName(handle, boneIndex, stringBuilder, 255);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetBoneName error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
return stringBuilder.ToString();
}
///
/// Returns an array of positions/rotations that represent the state of each bone in a reference pose.
///
/// What to get the position/rotation data relative to, the model, or the bone's parent
/// Which reference pose to return
///
public SteamVR_Utils.RigidTransform[] GetReferenceTransforms(EVRSkeletalTransformSpace transformSpace, EVRSkeletalReferencePose referencePose)
{
SteamVR_Utils.RigidTransform[] transforms = new SteamVR_Utils.RigidTransform[GetBoneCount()];
VRBoneTransform_t[] boneTransforms = new VRBoneTransform_t[transforms.Length];
EVRInputError error = OpenVR.Input.GetSkeletalReferenceTransforms(handle, transformSpace, referencePose, boneTransforms);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetSkeletalReferenceTransforms error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
for (int transformIndex = 0; transformIndex < boneTransforms.Length; transformIndex++)
{
Vector3 position = new Vector3(-boneTransforms[transformIndex].position.v0, boneTransforms[transformIndex].position.v1, boneTransforms[transformIndex].position.v2);
Quaternion rotation = new Quaternion(boneTransforms[transformIndex].orientation.x, -boneTransforms[transformIndex].orientation.y, -boneTransforms[transformIndex].orientation.z, boneTransforms[transformIndex].orientation.w);
transforms[transformIndex] = new SteamVR_Utils.RigidTransform(position, rotation);
}
if (transforms.Length > 0)
{
// Now that we're in the same handedness as Unity, rotate the root bone around the Y axis
// so that forward is facing down +Z
Quaternion qFixUpRot = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up);
transforms[0].rot = qFixUpRot * transforms[0].rot;
}
return transforms;
}
///
/// Get the accuracy level of the skeletal tracking data.
/// * Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
/// * Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
/// * Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
///
public EVRSkeletalTrackingLevel skeletalTrackingLevel { get { return GetSkeletalTrackingLevel(); } }
///
/// Get the accuracy level of the skeletal tracking data.
/// * Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
/// * Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
/// * Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
///
public EVRSkeletalTrackingLevel GetSkeletalTrackingLevel()
{
EVRSkeletalTrackingLevel skeletalTrackingLevel = EVRSkeletalTrackingLevel.VRSkeletalTracking_Estimated;
EVRInputError error = OpenVR.Input.GetSkeletalTrackingLevel(handle, ref skeletalTrackingLevel);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetSkeletalTrackingLevel error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
return skeletalTrackingLevel;
}
///
/// Get the skeletal summary data structure from OpenVR.
/// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
/// Easier access at named members: indexCurl, ringSplay, etc.
///
protected VRSkeletalSummaryData_t GetSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
{
UpdateSkeletalSummaryData(summaryType, force);
return skeletalSummaryData;
}
///
/// Updates the skeletal summary data structure from OpenVR.
/// Contains curl and splay data in finger order: thumb, index, middlg, ring, pinky.
/// Easier access at named members: indexCurl, ringSplay, etc.
///
protected void UpdateSkeletalSummaryData(EVRSummaryType summaryType = EVRSummaryType.FromAnimation, bool force = false)
{
if (force || this.summaryDataType != summaryDataType && active)
{
EVRInputError error = OpenVR.Input.GetSkeletalSummaryData(handle, summaryType, ref skeletalSummaryData);
if (error != EVRInputError.None)
Debug.LogError("[SteamVR] GetSkeletalSummaryData error (" + fullPath + "): " + error.ToString() + " handle: " + handle.ToString());
fingerCurls[0] = skeletalSummaryData.flFingerCurl0;
fingerCurls[1] = skeletalSummaryData.flFingerCurl1;
fingerCurls[2] = skeletalSummaryData.flFingerCurl2;
fingerCurls[3] = skeletalSummaryData.flFingerCurl3;
fingerCurls[4] = skeletalSummaryData.flFingerCurl4;
//no splay data for thumb
fingerSplays[0] = skeletalSummaryData.flFingerSplay0;
fingerSplays[1] = skeletalSummaryData.flFingerSplay1;
fingerSplays[2] = skeletalSummaryData.flFingerSplay2;
fingerSplays[3] = skeletalSummaryData.flFingerSplay3;
}
}
protected override void CheckAndSendEvents()
{
if (trackingState != lastTrackingState && onTrackingChanged != null)
onTrackingChanged.Invoke(skeletonAction, trackingState);
if (poseIsValid != lastPoseIsValid && onValidPoseChanged != null)
onValidPoseChanged.Invoke(skeletonAction, poseIsValid);
if (deviceIsConnected != lastDeviceIsConnected && onDeviceConnectedChanged != null)
onDeviceConnectedChanged.Invoke(skeletonAction, deviceIsConnected);
if (changed && onChange != null)
onChange.Invoke(skeletonAction);
if (active != lastActive && onActiveChange != null)
onActiveChange.Invoke(skeletonAction, active);
if (activeBinding != lastActiveBinding && onActiveBindingChange != null)
onActiveBindingChange.Invoke(skeletonAction, activeBinding);
if (onUpdate != null)
onUpdate.Invoke(skeletonAction);
}
}
public interface ISteamVR_Action_Skeleton_Source
{
///
/// Get the accuracy level of the skeletal tracking data.
/// * Estimated: Body part location can’t be directly determined by the device. Any skeletal pose provided by the device is estimated based on the active buttons, triggers, joysticks, or other input sensors. Examples include the Vive Controller and gamepads.
/// * Partial: Body part location can be measured directly but with fewer degrees of freedom than the actual body part.Certain body part positions may be unmeasured by the device and estimated from other input data.Examples include Knuckles or gloves that only measure finger curl
/// * Full: Body part location can be measured directly throughout the entire range of motion of the body part.Examples include hi-end mocap systems, or gloves that measure the rotation of each finger segment.
///
EVRSkeletalTrackingLevel skeletalTrackingLevel { get; }
/// An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
Vector3[] bonePositions { get; }
/// An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
Quaternion[] boneRotations { get; }
/// From the previous update: An array of the positions of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
Vector3[] lastBonePositions { get; }
/// From the previous update: An array of the rotations of the bones from the most recent update. Relative to skeletalTransformSpace. See SteamVR_Skeleton_JointIndexes for bone indexes.
Quaternion[] lastBoneRotations { get; }
/// The range of motion the we're using to get bone data from. With Controller being your hand while holding the controller.
EVRSkeletalMotionRange rangeOfMotion { get; set; }
/// The space to get bone data in. Parent space by default
EVRSkeletalTransformSpace skeletalTransformSpace { get; set; }
/// Skips processing the full per bone data and only does the summary data
bool onlyUpdateSummaryData { get; set; }
/// A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
float thumbCurl { get; }
/// A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
float indexCurl { get; }
/// A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
float middleCurl { get; }
/// A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
float ringCurl { get; }
/// A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
float pinkyCurl { get; }
/// A 0-1 value representing the size of the gap between the thumb and index fingers
float thumbIndexSplay { get; }
/// A 0-1 value representing the size of the gap between the index and middle fingers
float indexMiddleSplay { get; }
/// A 0-1 value representing the size of the gap between the middle and ring fingers
float middleRingSplay { get; }
/// A 0-1 value representing the size of the gap between the ring and pinky fingers
float ringPinkySplay { get; }
/// [Previous Update] A 0-1 value representing how curled the thumb is. 0 being straight, 1 being fully curled.
float lastThumbCurl { get; }
/// [Previous Update] A 0-1 value representing how curled the index finger is. 0 being straight, 1 being fully curled.
float lastIndexCurl { get; }
/// [Previous Update] A 0-1 value representing how curled the middle finger is. 0 being straight, 1 being fully curled.
float lastMiddleCurl { get; }
/// [Previous Update] A 0-1 value representing how curled the ring finger is. 0 being straight, 1 being fully curled.
float lastRingCurl { get; }
/// [Previous Update] A 0-1 value representing how curled the pinky finger is. 0 being straight, 1 being fully curled.
float lastPinkyCurl { get; }
/// [Previous Update] A 0-1 value representing the size of the gap between the thumb and index fingers
float lastThumbIndexSplay { get; }
/// [Previous Update] A 0-1 value representing the size of the gap between the index and middle fingers
float lastIndexMiddleSplay { get; }
/// [Previous Update] A 0-1 value representing the size of the gap between the middle and ring fingers
float lastMiddleRingSplay { get; }
/// [Previous Update] A 0-1 value representing the size of the gap between the ring and pinky fingers
float lastRingPinkySplay { get; }
/// 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
float[] fingerCurls { get; }
/// 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
float[] fingerSplays { get; }
/// [Previous Update] 0-1 values representing how curled the specified finger is. 0 being straight, 1 being fully curled. For indexes see: SteamVR_Skeleton_FingerIndexes
float[] lastFingerCurls { get; }
/// [Previous Update] 0-1 values representing how splayed the specified finger and it's next index'd finger is. For indexes see: SteamVR_Skeleton_FingerIndexes
float[] lastFingerSplays { get; }
}
///
/// The change in range of the motion of the bones in the skeleton. Options are "With Controller" as if your hand is holding your VR controller.
/// Or "Without Controller" as if your hand is empty.
///
public enum SkeletalMotionRangeChange
{
None = -1,
/// Estimation of bones in hand while holding a controller
WithController = 0,
/// Estimation of bones in hand while hand is empty (allowing full fist)
WithoutController = 1,
}
/// The order of the joints that SteamVR Skeleton Input is expecting.
public static class SteamVR_Skeleton_JointIndexes
{
public const int root = 0;
public const int wrist = 1;
public const int thumbMetacarpal = 2;
public const int thumbProximal = 2;
public const int thumbMiddle = 3;
public const int thumbDistal = 4;
public const int thumbTip = 5;
public const int indexMetacarpal = 6;
public const int indexProximal = 7;
public const int indexMiddle = 8;
public const int indexDistal = 9;
public const int indexTip = 10;
public const int middleMetacarpal = 11;
public const int middleProximal = 12;
public const int middleMiddle = 13;
public const int middleDistal = 14;
public const int middleTip = 15;
public const int ringMetacarpal = 16;
public const int ringProximal = 17;
public const int ringMiddle = 18;
public const int ringDistal = 19;
public const int ringTip = 20;
public const int pinkyMetacarpal = 21;
public const int pinkyProximal = 22;
public const int pinkyMiddle = 23;
public const int pinkyDistal = 24;
public const int pinkyTip = 25;
public const int thumbAux = 26;
public const int indexAux = 27;
public const int middleAux = 28;
public const int ringAux = 29;
public const int pinkyAux = 30;
public static int GetFingerForBone(int boneIndex)
{
switch (boneIndex)
{
case root:
case wrist:
return -1;
case thumbMetacarpal:
case thumbMiddle:
case thumbDistal:
case thumbTip:
case thumbAux:
return 0;
case indexMetacarpal:
case indexProximal:
case indexMiddle:
case indexDistal:
case indexTip:
case indexAux:
return 1;
case middleMetacarpal:
case middleProximal:
case middleMiddle:
case middleDistal:
case middleTip:
case middleAux:
return 2;
case ringMetacarpal:
case ringProximal:
case ringMiddle:
case ringDistal:
case ringTip:
case ringAux:
return 3;
case pinkyMetacarpal:
case pinkyProximal:
case pinkyMiddle:
case pinkyDistal:
case pinkyTip:
case pinkyAux:
return 4;
default:
return -1;
}
}
public static int GetBoneForFingerTip(int fingerIndex)
{
switch (fingerIndex)
{
case SteamVR_Skeleton_FingerIndexes.thumb:
return thumbTip;
case SteamVR_Skeleton_FingerIndexes.index:
return indexTip;
case SteamVR_Skeleton_FingerIndexes.middle:
return middleTip;
case SteamVR_Skeleton_FingerIndexes.ring:
return ringTip;
case SteamVR_Skeleton_FingerIndexes.pinky:
return pinkyTip;
default:
return indexTip;
}
}
}
public enum SteamVR_Skeleton_JointIndexEnum
{
root = SteamVR_Skeleton_JointIndexes.root,
wrist = SteamVR_Skeleton_JointIndexes.wrist,
thumbMetacarpal = SteamVR_Skeleton_JointIndexes.thumbMetacarpal,
thumbProximal = SteamVR_Skeleton_JointIndexes.thumbProximal,
thumbMiddle = SteamVR_Skeleton_JointIndexes.thumbMiddle,
thumbDistal = SteamVR_Skeleton_JointIndexes.thumbDistal,
thumbTip = SteamVR_Skeleton_JointIndexes.thumbTip,
indexMetacarpal = SteamVR_Skeleton_JointIndexes.indexMetacarpal,
indexProximal = SteamVR_Skeleton_JointIndexes.indexProximal,
indexMiddle = SteamVR_Skeleton_JointIndexes.indexMiddle,
indexDistal = SteamVR_Skeleton_JointIndexes.indexDistal,
indexTip = SteamVR_Skeleton_JointIndexes.indexTip,
middleMetacarpal = SteamVR_Skeleton_JointIndexes.middleMetacarpal,
middleProximal = SteamVR_Skeleton_JointIndexes.middleProximal,
middleMiddle = SteamVR_Skeleton_JointIndexes.middleMiddle,
middleDistal = SteamVR_Skeleton_JointIndexes.middleDistal,
middleTip = SteamVR_Skeleton_JointIndexes.middleTip,
ringMetacarpal = SteamVR_Skeleton_JointIndexes.ringMetacarpal,
ringProximal = SteamVR_Skeleton_JointIndexes.ringProximal,
ringMiddle = SteamVR_Skeleton_JointIndexes.ringMiddle,
ringDistal = SteamVR_Skeleton_JointIndexes.ringDistal,
ringTip = SteamVR_Skeleton_JointIndexes.ringTip,
pinkyMetacarpal = SteamVR_Skeleton_JointIndexes.pinkyMetacarpal,
pinkyProximal = SteamVR_Skeleton_JointIndexes.pinkyProximal,
pinkyMiddle = SteamVR_Skeleton_JointIndexes.pinkyMiddle,
pinkyDistal = SteamVR_Skeleton_JointIndexes.pinkyDistal,
pinkyTip = SteamVR_Skeleton_JointIndexes.pinkyTip,
thumbAux = SteamVR_Skeleton_JointIndexes.thumbAux,
indexAux = SteamVR_Skeleton_JointIndexes.indexAux,
middleAux = SteamVR_Skeleton_JointIndexes.middleAux,
ringAux = SteamVR_Skeleton_JointIndexes.ringAux,
pinkyAux = SteamVR_Skeleton_JointIndexes.pinkyAux,
}
/// The order of the fingers that SteamVR Skeleton Input outputs
public class SteamVR_Skeleton_FingerIndexes
{
public const int thumb = 0;
public const int index = 1;
public const int middle = 2;
public const int ring = 3;
public const int pinky = 4;
public static SteamVR_Skeleton_FingerIndexEnum[] enumArray = (SteamVR_Skeleton_FingerIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerIndexEnum));
}
/// The order of the fingerSplays that SteamVR Skeleton Input outputs
public class SteamVR_Skeleton_FingerSplayIndexes
{
public const int thumbIndex = 0;
public const int indexMiddle = 1;
public const int middleRing = 2;
public const int ringPinky = 3;
public static SteamVR_Skeleton_FingerSplayIndexEnum[] enumArray = (SteamVR_Skeleton_FingerSplayIndexEnum[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerSplayIndexEnum));
}
public enum SteamVR_Skeleton_FingerSplayIndexEnum
{
thumbIndex = SteamVR_Skeleton_FingerSplayIndexes.thumbIndex,
indexMiddle = SteamVR_Skeleton_FingerSplayIndexes.indexMiddle,
middleRing = SteamVR_Skeleton_FingerSplayIndexes.middleRing,
ringPinky = SteamVR_Skeleton_FingerSplayIndexes.ringPinky,
}
public enum SteamVR_Skeleton_FingerIndexEnum
{
thumb = SteamVR_Skeleton_FingerIndexes.thumb,
index = SteamVR_Skeleton_FingerIndexes.index,
middle = SteamVR_Skeleton_FingerIndexes.middle,
ring = SteamVR_Skeleton_FingerIndexes.ring,
pinky = SteamVR_Skeleton_FingerIndexes.pinky,
}
}