Skip to content

Commit

Permalink
Merge branch 'TestReadmeChange'
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrys committed Aug 7, 2024
2 parents 349ba7d + afe1af3 commit 8fbc1bb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
13 changes: 12 additions & 1 deletion Editor/AutoGenTemplate/Templates/HandProxyDevice_Template.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public class HandProxyDevice : InputDevice, IHandProxyDevice
public Handedness Handeness { get; private set; }

IJoystickSimulator joystickSimulator = new NullJoystickSimulator();
[InputControl] public Vector3Control velocity { get; private set; }
[InputControl] public Vector3Control angularVelocity { get; private set; }
[InputControl] public Vector2Control joystick { get; private set; }
[InputControl] public ButtonControl JoystickStarter { get; private set; }
#region PROXIED_BUTTONCONTROLS ---> AUTOGEN
#endregion

protected override void FinishSetup()
{
velocity = GetChildControl<Vector3Control>("velocity");
angularVelocity = GetChildControl<Vector3Control>("angularVelocity");
joystick = GetChildControl<Vector2Control>("joystick");
JoystickStarter = GetChildControl<ButtonControl>("JoystickStarter");
#region BUTTONCONTROLS_SETUP ---> AUTOGEN
Expand All @@ -37,11 +41,13 @@ public class HandProxyDevice : InputDevice, IHandProxyDevice
public void SetJoystickSimulator(IJoystickSimulator joystickSimulator) => this.joystickSimulator = joystickSimulator;
public void SetStreams(HandProxyGestureDescription desc, XRMasterHand xrMasterHand)
{
velocityStream = new HandVelocityStream(xrMasterHand);
joystickStarterStream = desc.GenerateJoystickStarterStream(xrMasterHand);
streams = desc.GenerateStreams(xrMasterHand);
SetJoystickSimulator(desc.GenerateJoystickSimulator(joystickStarterStream, xrMasterHand.handJointsUpdatedEventArgs));
}

HandVelocityStream velocityStream;
HandGestureStream joystickStarterStream;
HandGestureStream[] streams;

Expand All @@ -50,6 +56,8 @@ public class HandProxyDevice : InputDevice, IHandProxyDevice
{
state = new State
{
velocity = velocityStream.velocity,
angularVelocity = velocityStream.angularVelocity,
joystickX = joystickSimulator.X,
joystickY = joystickSimulator.Y,
joystickStarter = joystickStarterStream.performState,
Expand All @@ -62,7 +70,10 @@ public class HandProxyDevice : InputDevice, IHandProxyDevice
[StructLayout(LayoutKind.Sequential)]
public struct State : IInputStateTypeInfo
{
public FourCC format => new FourCC('H', 'T', 'P', 'C');
public FourCC format => new FourCC('X', 'R', 'M', 'H');
// velocities Definition
[InputControl(name = "velocity", layout = "Vector3", format = "VC3B", noisy = true)] public Vector3 velocity;
[InputControl(name = "angularVelocity", layout = "Vector3", format = "VC3B", noisy = true)] public Vector3 angularVelocity;
//Joystick Definition
[InputControl(name = "joystick", layout = "Vector2", format = "VC2B")]
[InputControl(name = "joystick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=0.996078431372549,normalizeZero=0.5")] public byte joystickX;
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


<p align="center">
<img src="https://github.com/Extrys/XRMasterHands/assets/38926085/8f0f3ed4-f6ad-4ee5-9c91-ebf21cfc4553">
</p>
Expand Down
36 changes: 36 additions & 0 deletions Runtime/Scripts/HandVelocityStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using UnityEngine;
using UnityEngine.XR.Hands;

[Serializable]
public class HandVelocityStream : IDisposable
{
public Vector3 velocity;
public Vector3 angularVelocity;
XRMasterHand masterHand;
public HandVelocityStream() { }
public HandVelocityStream(XRMasterHand masterHand)
{
this.masterHand = masterHand;
this.masterHand.OnJointsUpdated += OnJointsUpdated;
}

Vector3 lastPos;
Quaternion lastRot;
void OnJointsUpdated(XRHandJointsUpdatedEventArgs eventArgs)
{
Vector3 position = eventArgs.hand.rootPose.position;
velocity = (position - lastPos) / Time.deltaTime;
lastPos = eventArgs.hand.rootPose.position;
Quaternion orientation = eventArgs.hand.rootPose.rotation;
(orientation * Quaternion.Inverse(lastRot)).ToAngleAxis(out float angle, out Vector3 axis);
angularVelocity = axis * (angle * Mathf.Deg2Rad / Time.deltaTime);
lastRot = orientation;
}

public void Dispose()
{
masterHand.OnJointsUpdated -= OnJointsUpdated;
masterHand = null;
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/HandVelocityStream.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Runtime/Scripts/XRMasterHandSkeletonDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//using Unity.Burst;
//[BurstCompile] not suported yet for XRMasterHands package
#endif
public class XRMasterHandSkeletonDriver : MonoBehaviour, ISerializationCallbackReceiver
public class XRMasterHandSkeletonDriver : MonoBehaviour
{
[SerializeField] Handedness handedness;
XRMasterHand xrMasterHand;
Expand Down Expand Up @@ -92,6 +92,10 @@ public Transform rootTransform
}
}

private void Awake()
{
InitializeFromSerializedReferences();
}
//subscribes to hand tracking events and allocates the joint local poses array.
protected virtual void OnEnable()
{
Expand Down Expand Up @@ -322,7 +326,4 @@ public void InitializeFromSerializedReferences()
/// </remarks>
/// <param name="missingJointNames">A list of strings to list the joints that were not found.</param>
public virtual void FindJointsFromRoot(List<string> missingJointNames) => XRMasterHandSkeletonDriverUtility.FindJointsFromRoot(this, missingJointNames);

void ISerializationCallbackReceiver.OnBeforeSerialize() { }
void ISerializationCallbackReceiver.OnAfterDeserialize() => InitializeFromSerializedReferences();
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.squirrelbytes.xrmasterhands",
"version": "0.1.5",
"version": "0.1.6",
"displayName": "XR Master Hands",
"description": "Framework for simplifying the usage of XR Hands by automagically creating a special XR Device which implements designed hand poses as buttons for using with the unity's Input System Package",
"unity": "2022.3",
Expand Down

0 comments on commit 8fbc1bb

Please sign in to comment.