From f86be5c7c1640b6686c82864bffa863cf49322a6 Mon Sep 17 00:00:00 2001 From: Extrys Date: Thu, 23 May 2024 09:43:48 +0200 Subject: [PATCH 1/4] . --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2d2995c..084b31b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -

From a6e450784701518f331c8a7a07a94aa8595207ed Mon Sep 17 00:00:00 2001 From: Extrys Date: Wed, 7 Aug 2024 18:35:17 +0200 Subject: [PATCH 2/4] Fixed Errors given when entering and exiting play mode --- Runtime/Scripts/XRMasterHandSkeletonDriver.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Runtime/Scripts/XRMasterHandSkeletonDriver.cs b/Runtime/Scripts/XRMasterHandSkeletonDriver.cs index 68ded12..a760b91 100644 --- a/Runtime/Scripts/XRMasterHandSkeletonDriver.cs +++ b/Runtime/Scripts/XRMasterHandSkeletonDriver.cs @@ -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; @@ -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() { @@ -322,7 +326,4 @@ public void InitializeFromSerializedReferences() /// /// A list of strings to list the joints that were not found. public virtual void FindJointsFromRoot(List missingJointNames) => XRMasterHandSkeletonDriverUtility.FindJointsFromRoot(this, missingJointNames); - - void ISerializationCallbackReceiver.OnBeforeSerialize() { } - void ISerializationCallbackReceiver.OnAfterDeserialize() => InitializeFromSerializedReferences(); } From ebf6b7306742999a6b77ac5a8f9f2d021f6b74ae Mon Sep 17 00:00:00 2001 From: Extrys Date: Wed, 7 Aug 2024 18:35:43 +0200 Subject: [PATCH 3/4] Added Velocity and Angular velocity to hand inputs --- .../Templates/HandProxyDevice_Template.cs.txt | 13 ++++++- Runtime/Scripts/HandVelocityStream.cs | 36 +++++++++++++++++++ Runtime/Scripts/HandVelocityStream.cs.meta | 11 ++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Runtime/Scripts/HandVelocityStream.cs create mode 100644 Runtime/Scripts/HandVelocityStream.cs.meta diff --git a/Editor/AutoGenTemplate/Templates/HandProxyDevice_Template.cs.txt b/Editor/AutoGenTemplate/Templates/HandProxyDevice_Template.cs.txt index fb0d9fd..2b6c821 100644 --- a/Editor/AutoGenTemplate/Templates/HandProxyDevice_Template.cs.txt +++ b/Editor/AutoGenTemplate/Templates/HandProxyDevice_Template.cs.txt @@ -20,6 +20,8 @@ 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 @@ -27,6 +29,8 @@ public class HandProxyDevice : InputDevice, IHandProxyDevice protected override void FinishSetup() { + velocity = GetChildControl("velocity"); + angularVelocity = GetChildControl("angularVelocity"); joystick = GetChildControl("joystick"); JoystickStarter = GetChildControl("JoystickStarter"); #region BUTTONCONTROLS_SETUP ---> AUTOGEN @@ -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; @@ -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, @@ -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; diff --git a/Runtime/Scripts/HandVelocityStream.cs b/Runtime/Scripts/HandVelocityStream.cs new file mode 100644 index 0000000..bfe1d08 --- /dev/null +++ b/Runtime/Scripts/HandVelocityStream.cs @@ -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; + } +} diff --git a/Runtime/Scripts/HandVelocityStream.cs.meta b/Runtime/Scripts/HandVelocityStream.cs.meta new file mode 100644 index 0000000..caa3438 --- /dev/null +++ b/Runtime/Scripts/HandVelocityStream.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bc0a654581703049801617a70943a3c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From afe1af32c9a9f4baa63bbff7c562a58a11412d76 Mon Sep 17 00:00:00 2001 From: Extrys Date: Wed, 7 Aug 2024 18:37:49 +0200 Subject: [PATCH 4/4] versionChange --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cdfb6f5..fff6ab5 100644 --- a/package.json +++ b/package.json @@ -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",