Skip to content

Commit

Permalink
Working controllers + improved pinch
Browse files Browse the repository at this point in the history
  • Loading branch information
provencher committed Dec 31, 2019
1 parent 94b0e08 commit c4a08af
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,24 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 2343937678421358193}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2348353478739872649 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4593680705043960, guid: 126d619cf4daa52469682f85c1378b4a,
type: 3}
m_PrefabInstance: {fileID: 2343937678421358193}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2343937678421137703 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 487254, guid: 126d619cf4daa52469682f85c1378b4a,
type: 3}
m_PrefabInstance: {fileID: 2343937678421358193}
m_PrefabAsset: {fileID: 0}
--- !u!4 &2344326260083813425 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4484591312116288, guid: 126d619cf4daa52469682f85c1378b4a,
type: 3}
m_PrefabInstance: {fileID: 2343937678421358193}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2388160055802378586
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -141,6 +153,128 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 835e735ca71bf78459fb2cababd74112, type: 3}
--- !u!1001 &2801243777050976572
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 2344326260083813425}
m_Modifications:
- target: {fileID: 112276, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_Name
value: OVRControllerPrefab
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11479374, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_controller
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
--- !u!1001 &6177999372221570643
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 2348353478739872649}
m_Modifications:
- target: {fileID: 112276, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_Name
value: OVRControllerPrefab
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 488160, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 11479374, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
propertyPath: m_controller
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d9809c5e8418bb047bf2c8ba1d1a2cec, type: 3}
--- !u!1001 &8492194200696547008
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ MonoBehaviour:
runtimePlatform: 208
deviceManagerProfile: {fileID: 0}
- componentType:
reference: prvncher.MixedReality.Toolkit.OculusQuestInput.OculusQuestHandInputManager,
reference: prvncher.MixedReality.Toolkit.OculusQuestInput.OculusQuestInputManager,
prvncher.MixedReality.Toolkit.OculusQuestInput
componentName: Oculus Quest Hand Input Manager
componentName: Oculus Quest Input Manager
priority: 0
runtimePlatform: 240
deviceManagerProfile: {fileID: 0}
Expand All @@ -109,12 +109,10 @@ MonoBehaviour:
type: 2}
pointerProfile: {fileID: 11400000, guid: 48aa63a9725047b28d4137fd0834bc31, type: 2}
gesturesProfile: {fileID: 11400000, guid: bd7829a9b29409045a745b5a18299291, type: 2}
speechCommandsProfile: {fileID: 11400000, guid: e8d0393e66374dae9646851a57dc6bc1,
type: 2}
speechCommandsProfile: {fileID: 0}
enableControllerMapping: 1
controllerMappingProfile: {fileID: 11400000, guid: 39ded1fd0711a0c448413d0e1ec4f7f3,
type: 2}
controllerVisualizationProfile: {fileID: 11400000, guid: 345c06fdf3732db46b96299bd3cba653,
type: 2}
controllerVisualizationProfile: {fileID: 0}
handTrackingProfile: {fileID: 11400000, guid: e445e6fda57508c46935bb141b7673a7,
type: 2}
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@

namespace prvncher.MixedReality.Toolkit.OculusQuestInput
{
[MixedRealityController(SupportedControllerType.OculusTouch, new[] { Handedness.Left, Handedness.Right })]
public class OculusQuestController : BaseController
[MixedRealityController(SupportedControllerType.ArticulatedHand, new[] { Handedness.Left, Handedness.Right })]
public class OculusQuestController : BaseController, IMixedRealityHand
{
private MixedRealityPose currentPointerPose = MixedRealityPose.ZeroIdentity;


private MixedRealityPose currentIndexPose = MixedRealityPose.ZeroIdentity;
private MixedRealityPose currentGripPose = MixedRealityPose.ZeroIdentity;

private const float cTriggerDeadZone = 0.1f;
protected readonly Dictionary<TrackedHandJoint, MixedRealityPose> jointPoses = new Dictionary<TrackedHandJoint, MixedRealityPose>();

// TODO: Hand mesh
// private int[] handMeshTriangleIndices = null;
// private Vector2[] handMeshUVs;
private const float cTriggerDeadZone = 0.1f;

public OculusQuestController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
Expand All @@ -32,18 +29,11 @@ public OculusQuestController(TrackingState trackingState, Handedness controllerH
/// <remarks>A single interaction mapping works for both left and right controllers.</remarks>
public override MixedRealityInteractionMapping[] DefaultInteractions => new[]
{
new MixedRealityInteractionMapping(0, "Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer),
new MixedRealityInteractionMapping(1, "Spatial Grip", AxisType.SixDof, DeviceInputType.SpatialGrip),
new MixedRealityInteractionMapping(2, "Grip Press", AxisType.SingleAxis, DeviceInputType.TriggerPress),
new MixedRealityInteractionMapping(3, "Trigger Position", AxisType.SingleAxis, DeviceInputType.Trigger),
new MixedRealityInteractionMapping(4, "Trigger Touch", AxisType.Digital, DeviceInputType.TriggerTouch),
new MixedRealityInteractionMapping(5, "Trigger Press (Select)", AxisType.Digital, DeviceInputType.Select),
new MixedRealityInteractionMapping(6, "Touchpad Position", AxisType.DualAxis, DeviceInputType.Touchpad),
new MixedRealityInteractionMapping(7, "Touchpad Touch", AxisType.Digital, DeviceInputType.TouchpadTouch),
new MixedRealityInteractionMapping(8, "Touchpad Press", AxisType.Digital, DeviceInputType.TouchpadPress),
new MixedRealityInteractionMapping(9, "Menu Press", AxisType.Digital, DeviceInputType.Menu),
new MixedRealityInteractionMapping(10, "Thumbstick Position", AxisType.DualAxis, DeviceInputType.ThumbStick),
new MixedRealityInteractionMapping(11, "Thumbstick Press", AxisType.Digital, DeviceInputType.ThumbStickPress),
new MixedRealityInteractionMapping(0, "Spatial Pointer", AxisType.SixDof, DeviceInputType.SpatialPointer, new MixedRealityInputAction(4, "Pointer Pose", AxisType.SixDof)),
new MixedRealityInteractionMapping(1, "Spatial Grip", AxisType.SixDof, DeviceInputType.SpatialGrip, new MixedRealityInputAction(3, "Grip Pose", AxisType.SixDof)),
new MixedRealityInteractionMapping(2, "Select", AxisType.Digital, DeviceInputType.Select, new MixedRealityInputAction(1, "Select", AxisType.Digital)),
new MixedRealityInteractionMapping(3, "Grab", AxisType.SingleAxis, DeviceInputType.TriggerPress, new MixedRealityInputAction(7, "Grip Press", AxisType.SingleAxis)),
new MixedRealityInteractionMapping(4, "Index Finger Pose", AxisType.SixDof, DeviceInputType.IndexFinger, new MixedRealityInputAction(13, "Index Finger Pose", AxisType.SixDof)),
};

public override void SetupDefaultInteractions(Handedness controllerHandedness)
Expand All @@ -62,8 +52,8 @@ public void UpdateController(OVRCameraRig ovrRigRoot, OVRInput.Controller ovrCon
return;
}

IsPositionAvailable = OVRInput.GetControllerPositionTracked(ovrController);
IsRotationAvailable = OVRInput.GetControllerPositionTracked(ovrController);
IsPositionAvailable = OVRInput.GetControllerPositionValid(ovrController);
IsRotationAvailable = OVRInput.GetControllerOrientationValid(ovrController);

Transform playSpaceTransform = ovrRigRoot.transform;

Expand Down Expand Up @@ -104,6 +94,8 @@ public void UpdateController(OVRCameraRig ovrRigRoot, OVRInput.Controller ovrCon
isTriggerPressed = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > cTriggerDeadZone;
}

UpdateJointPoses();

for (int i = 0; i < Interactions?.Length; i++)
{
switch (Interactions[i].InputType)
Expand Down Expand Up @@ -152,8 +144,89 @@ public void UpdateController(OVRCameraRig ovrRigRoot, OVRInput.Controller ovrCon
}
}
break;
case DeviceInputType.IndexFinger:
UpdateIndexFingerData(Interactions[i]);
break;
}
}
}

private void UpdateJointPoses()
{
// While we can get pretty much everything done with just the grip pose, we simulate hand sizes for bounds calculations

// Index
Vector3 fingerTipPos = currentGripPose.Position + currentGripPose.Rotation * Vector3.forward * 0.1f;
UpdateJointPose(TrackedHandJoint.IndexTip, fingerTipPos, currentGripPose.Rotation);

// Handed directional offsets
Vector3 inWardVector;
if (ControllerHandedness == Handedness.Left)
{
inWardVector = currentGripPose.Rotation * Vector3.right;
}
else
{
inWardVector = currentGripPose.Rotation * -Vector3.right;
}

// Thumb
Vector3 thumbPose = currentGripPose.Position + inWardVector * 0.04f;
UpdateJointPose(TrackedHandJoint.ThumbTip, thumbPose, currentGripPose.Rotation);
UpdateJointPose(TrackedHandJoint.ThumbMetacarpalJoint, thumbPose, currentGripPose.Rotation);
UpdateJointPose(TrackedHandJoint.ThumbDistalJoint, thumbPose, currentGripPose.Rotation);

// Pinky
Vector3 pinkyPose = currentGripPose.Position - inWardVector * 0.03f;
UpdateJointPose(TrackedHandJoint.PinkyKnuckle, pinkyPose, currentGripPose.Rotation);

// Palm
UpdateJointPose(TrackedHandJoint.Palm, currentGripPose.Position, currentGripPose.Rotation);

// Wrist
Vector3 wristPose = currentGripPose.Position - currentGripPose.Rotation * Vector3.forward * 0.05f;
UpdateJointPose(TrackedHandJoint.Palm, wristPose, currentGripPose.Rotation);
}

protected void UpdateJointPose(TrackedHandJoint joint, Vector3 position, Quaternion rotation)
{
MixedRealityPose pose = new MixedRealityPose(position, rotation);
if (!jointPoses.ContainsKey(joint))
{
jointPoses.Add(joint, pose);
}
else
{
jointPoses[joint] = pose;
}
}

private void UpdateIndexFingerData(MixedRealityInteractionMapping interactionMapping)
{
if (jointPoses.TryGetValue(TrackedHandJoint.IndexTip, out var pose))
{
currentIndexPose.Rotation = pose.Rotation;
currentIndexPose.Position = pose.Position;
}

interactionMapping.PoseData = currentIndexPose;

// If our value changed raise it.
if (interactionMapping.Changed)
{
// Raise input system Event if it enabled
CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentIndexPose);
}
}

public bool TryGetJoint(TrackedHandJoint joint, out MixedRealityPose pose)
{
if (jointPoses.TryGetValue(joint, out pose))
{
return true;
}
pose = currentGripPose;
return true;
}
}
}
Loading

0 comments on commit c4a08af

Please sign in to comment.