From 25b761e4a1feab9bbb6d2c11ae6a5dfaf43e90a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Sun, 17 Dec 2023 11:26:25 +0100 Subject: [PATCH 1/2] Apply idle pose if configured on awake --- .../Hands/Visualizers/RiggedHandControllerVisualizer.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Runtime/Input/Hands/Visualizers/RiggedHandControllerVisualizer.cs b/Runtime/Input/Hands/Visualizers/RiggedHandControllerVisualizer.cs index 3e0a0fa6..6c10554f 100644 --- a/Runtime/Input/Hands/Visualizers/RiggedHandControllerVisualizer.cs +++ b/Runtime/Input/Hands/Visualizers/RiggedHandControllerVisualizer.cs @@ -61,6 +61,12 @@ protected override void Awake() { base.Awake(); poseAnimator = new HandPoseAnimator(jointTransformProvider); + + // If an idle pose is configured, instantly apply it. + if (idlePose.IsNotNull()) + { + poseAnimator.Transition(idlePose, false); + } } /// From 3553fb0b8e552d8c1ca593503690401e460c19b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Sun, 17 Dec 2023 13:47:28 +0100 Subject: [PATCH 2/2] Fix issue where poke interactors would cause conflicting behaviour with the attach visualizer behaviour --- .../AttachControllerVisualizerBehaviour.cs | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Runtime/Input/InteractionBehaviours/AttachControllerVisualizerBehaviour.cs b/Runtime/Input/InteractionBehaviours/AttachControllerVisualizerBehaviour.cs index 7540e698..c9f51e58 100644 --- a/Runtime/Input/InteractionBehaviours/AttachControllerVisualizerBehaviour.cs +++ b/Runtime/Input/InteractionBehaviours/AttachControllerVisualizerBehaviour.cs @@ -11,8 +11,12 @@ namespace RealityToolkit.Input.InteractionBehaviours { /// /// Attaches the 's - /// to the pose. + /// to the pose and keeps them in sync until input is released. /// + /// + /// Only supports s. + /// Does not support s and will ignore them. + /// public class AttachControllerVisualizerBehaviour : BaseInteractionBehaviour { [SerializeField, Tooltip("Optional local offset from the object's pivot.")] @@ -21,14 +25,14 @@ public class AttachControllerVisualizerBehaviour : BaseInteractionBehaviour [SerializeField, Tooltip("Optional local offset from the object's pivot.")] private Vector3 poseLocalRotationOffset = Vector3.zero; - private readonly List interactors = new List(); + private readonly List attachedInteractors = new List(); /// protected override void Update() { - for (int i = 0; i < interactors.Count; i++) + for (int i = 0; i < attachedInteractors.Count; i++) { - var interactor = interactors[i]; + var interactor = attachedInteractors[i]; var pose = GetGrabPose(interactor); interactor.Controller.Visualizer.PoseDriver.SetPositionAndRotation(pose.position, pose.rotation); @@ -38,63 +42,64 @@ protected override void Update() /// protected override void OnSelectEntered(InteractionEventArgs eventArgs) { - if (eventArgs.Interactor is not IControllerInteractor controllerInteractor) + if (eventArgs.Interactor is not IControllerInteractor controllerInteractor || + eventArgs.Interactor is IPokeInteractor) { return; } - Attach(controllerInteractor); + AttachVisualizer(controllerInteractor); } /// protected override void OnSelectExited(InteractionExitEventArgs eventArgs) { - if (eventArgs.Interactor is not IControllerInteractor controllerInteractor) + if (eventArgs.Interactor is not IControllerInteractor controllerInteractor || + eventArgs.Interactor is IPokeInteractor) { return; } - Detach(controllerInteractor); + DetachVisualizer(controllerInteractor); } /// protected override void OnGrabEntered(InteractionEventArgs eventArgs) { - if (eventArgs.Interactor is not IControllerInteractor controllerInteractor) + if (eventArgs.Interactor is not IControllerInteractor controllerInteractor || + eventArgs.Interactor is IPokeInteractor) { return; } - Attach(controllerInteractor); + AttachVisualizer(controllerInteractor); } /// protected override void OnGrabExited(InteractionExitEventArgs eventArgs) { - if (eventArgs.Interactor is not IControllerInteractor controllerInteractor) + if (eventArgs.Interactor is not IControllerInteractor controllerInteractor || + eventArgs.Interactor is IPokeInteractor) { return; } - Detach(controllerInteractor); + DetachVisualizer(controllerInteractor); } - private void Attach(IControllerInteractor currentInteractor) + private void AttachVisualizer(IControllerInteractor currentInteractor) { - interactors.EnsureListItem(currentInteractor); + attachedInteractors.EnsureListItem(currentInteractor); currentInteractor.Controller.Visualizer.VisualizerPoseOverrideSource = transform; } - private void Detach(IControllerInteractor currentInteractor) + private void DetachVisualizer(IControllerInteractor currentInteractor) { - interactors.SafeRemoveListItem(currentInteractor); + attachedInteractors.SafeRemoveListItem(currentInteractor); currentInteractor.Controller.Visualizer.VisualizerPoseOverrideSource = null; } - private Pose GetGrabPose(IControllerInteractor controllerInteractor) - { - return new Pose(GetGrabPosition(controllerInteractor), GetGrabRotation(controllerInteractor)); - } + private Pose GetGrabPose(IControllerInteractor controllerInteractor) => new Pose(GetGrabPosition(controllerInteractor), GetGrabRotation(controllerInteractor)); private Vector3 GetGrabPosition(IControllerInteractor currentInteractor) { @@ -111,10 +116,10 @@ private Vector3 GetGrabPosition(IControllerInteractor currentInteractor) return worldAttachmentPosition; } - private Quaternion GetGrabRotation(IControllerInteractor currentInteractor) + private Quaternion GetGrabRotation(IControllerInteractor interactor) { var worldAttachmentRotation = Quaternion.Euler(poseLocalRotationOffset); - var localControllerOffset = currentInteractor.Controller.Visualizer.GripPose.localRotation; + var localControllerOffset = interactor.Controller.Visualizer.GripPose.localRotation; return transform.rotation * worldAttachmentRotation * localControllerOffset; } }