Skip to content

Commit

Permalink
Remove unnecessary transformation in JointFollower
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 15, 2024
1 parent 8cccccd commit a708064
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions Runtime/Tracking/JointFollower.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using ubco.ovilab.HPUI.Utils;
using Unity.XR.CoreUtils;
using UnityEngine;
using UnityEngine.XR.Hands;

Expand Down Expand Up @@ -35,12 +33,8 @@ public class JointFollower: MonoBehaviour
[SerializeField]
public float longitudinalOffset = 0f;

[Tooltip("(optional) The XR Origin. If not set, will be automatically set.")][SerializeField]
private XROrigin xrOrigin;

private float cachedRadius = 0f;
private XRHandSubsystem handSubsystem;
private bool initialized;

/// <inheritdoc />
protected void Update()
Expand Down Expand Up @@ -76,11 +70,6 @@ protected void Update()
/// <inheritdoc />
protected void OnEnable()
{
if (!initialized)
{
Initialize();
}

if (targetTransform == null)
{
targetTransform = transform;
Expand Down Expand Up @@ -144,21 +133,6 @@ public void SetParams(Handedness handedness, XRHandJointID jointID, float offset
this.longitudinalOffset = longitudinalOffset;
}

private void Initialize()
{
if (xrOrigin == null)
{
XROrigin[] objs = FindObjectsOfType<XROrigin>();
if (objs.Length != 1)
{
throw new InvalidOperationException($"Got {objs.Length} `XROrigin`s. Expected only 1. Perhaps assign it in inspector.");
}
xrOrigin = objs[0];
}

initialized = true;
}

private void OnUpdatedHands(XRHandSubsystem subsystem,
XRHandSubsystem.UpdateSuccessFlags updateSuccessFlags,
XRHandSubsystem.UpdateType updateType)
Expand Down Expand Up @@ -190,22 +164,13 @@ private void ProcessJointData(XRHand hand)
bool mainPoseSuccess = mainJoint.TryGetPose(out Pose mainJointPose);
bool mainRadiusSuccess = mainJoint.TryGetRadius(out float mainRadius);

if (mainPoseSuccess)
{
mainJointPose = mainJointPose.GetTransformedBy(xrOrigin.transform);
}

XRHandJoint secondJoint;
bool secondPoseSuccess = false;
Pose secondJointPose = default;
if (useSecondJointID)
{
secondJoint = hand.GetJoint(secondJointID);
secondPoseSuccess = secondJoint.TryGetPose(out secondJointPose);
if (secondPoseSuccess)
{
secondJointPose = secondJointPose.GetTransformedBy(xrOrigin.transform);
}
}

if (mainRadiusSuccess)
Expand Down

0 comments on commit a708064

Please sign in to comment.