From 3e321a9776ebc43390441021db66bf349573c63f Mon Sep 17 00:00:00 2001 From: Scott Haynie Date: Tue, 25 Jul 2023 15:23:00 -0700 Subject: [PATCH] MRTK3 change to make the cursor visuals very steady in editor and on device (#11739) * Revert PR 11575 and fix merge conflicts * Add sample hand menu to DwellExample (fix #11727) * Revert "Add sample hand menu to DwellExample (fix #11727)" This reverts commit d73af8f101f9417f32fb0a9b227b764637ed05ba. * Update MixedRealityGraphicsTools to 0.5.14 to pick up the render order change * Debug bounds control test * Try longer wait for cursor move * Disable scalehandle cursor rotation tests until they are debugged * Disable other cursor rotation tests * Fix programmer stupidity * Trying fix for failing unit tests * Batch mode test * Remove failed test changes * Test if OnBeforeRender gets called in tests * Verified that OnBeforeRender event doesn't fire in batch mode, so add the call to UpdateReticle in LateUpdate if we're in batch mode. --- UnityProjects/MRTKDevTemplate/Packages/manifest.json | 2 +- .../MRTKDevTemplate/Packages/packages-lock.json | 4 ++-- .../InteractorVisuals/MRTKRayReticleVisual.cs | 12 ++++++++++-- .../Tests/Runtime/BoundsControlTests.cs | 7 ++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/UnityProjects/MRTKDevTemplate/Packages/manifest.json b/UnityProjects/MRTKDevTemplate/Packages/manifest.json index 9fffc420a03..9439200c4ac 100644 --- a/UnityProjects/MRTKDevTemplate/Packages/manifest.json +++ b/UnityProjects/MRTKDevTemplate/Packages/manifest.json @@ -10,7 +10,7 @@ "com.microsoft.mrtk.data": "file:../../../com.microsoft.mrtk.data", "com.microsoft.mrtk.diagnostics": "file:../../../com.microsoft.mrtk.diagnostics", "com.microsoft.mrtk.extendedassets": "file:../../../com.microsoft.mrtk.extendedassets", - "com.microsoft.mrtk.graphicstools.unity": "https://github.com/microsoft/MixedReality-GraphicsTools-Unity.git?path=/com.microsoft.mrtk.graphicstools.unity#v0.5.12", + "com.microsoft.mrtk.graphicstools.unity": "https://github.com/microsoft/MixedReality-GraphicsTools-Unity.git?path=/com.microsoft.mrtk.graphicstools.unity#v0.5.14", "com.microsoft.mrtk.input": "file:../../../com.microsoft.mrtk.input", "com.microsoft.mrtk.spatialmanipulation": "file:../../../com.microsoft.mrtk.spatialmanipulation", "com.microsoft.mrtk.standardassets": "file:../../../com.microsoft.mrtk.standardassets", diff --git a/UnityProjects/MRTKDevTemplate/Packages/packages-lock.json b/UnityProjects/MRTKDevTemplate/Packages/packages-lock.json index 374f7d1207a..b6b708887bb 100644 --- a/UnityProjects/MRTKDevTemplate/Packages/packages-lock.json +++ b/UnityProjects/MRTKDevTemplate/Packages/packages-lock.json @@ -96,11 +96,11 @@ } }, "com.microsoft.mrtk.graphicstools.unity": { - "version": "https://github.com/microsoft/MixedReality-GraphicsTools-Unity.git?path=/com.microsoft.mrtk.graphicstools.unity#v0.5.12", + "version": "https://github.com/microsoft/MixedReality-GraphicsTools-Unity.git?path=/com.microsoft.mrtk.graphicstools.unity#v0.5.14", "depth": 0, "source": "git", "dependencies": {}, - "hash": "3361204314b43c83990b9148ebfcfb913ae657f4" + "hash": "96743038a313c93322c935d99d2deb18e831aa2d" }, "com.microsoft.mrtk.input": { "version": "file:../../../com.microsoft.mrtk.input", diff --git a/com.microsoft.mrtk.input/Interactors/InteractorVisuals/MRTKRayReticleVisual.cs b/com.microsoft.mrtk.input/Interactors/InteractorVisuals/MRTKRayReticleVisual.cs index 8c64a88b38e..a9eab2a6f70 100644 --- a/com.microsoft.mrtk.input/Interactors/InteractorVisuals/MRTKRayReticleVisual.cs +++ b/com.microsoft.mrtk.input/Interactors/InteractorVisuals/MRTKRayReticleVisual.cs @@ -51,6 +51,7 @@ public ReticleVisibilitySettings VisibilitySettings private void OnEnable() { rayInteractor.selectEntered.AddListener(LocateTargetHitPoint); + Application.onBeforeRender += UpdateReticle; // If no custom reticle root is specified, just use the interactor's transform. if (reticleRoot == null) @@ -66,6 +67,7 @@ private void OnEnable() private void OnDisable() { rayInteractor.selectEntered.RemoveListener(LocateTargetHitPoint); + Application.onBeforeRender -= UpdateReticle; ReticleSetActive(false); } @@ -73,13 +75,19 @@ private void OnDisable() /// /// A Unity event function that is called every frame, if this object is enabled. /// - private void Update() + private void LateUpdate() { - UpdateReticle(); + // if running in batch mode the onBeforeRender event doesn't fire so + // we need to update the reticle here + if (Application.isBatchMode) + { + UpdateReticle(); + } } private static readonly ProfilerMarker UpdateReticlePerfMarker = new ProfilerMarker("[MRTK] MRTKRayReticleVisual.UpdateReticle"); + [BeforeRenderOrder(XRInteractionUpdateOrder.k_BeforeRenderLineVisual)] private void UpdateReticle() { using (UpdateReticlePerfMarker.Auto()) diff --git a/com.microsoft.mrtk.spatialmanipulation/Tests/Runtime/BoundsControlTests.cs b/com.microsoft.mrtk.spatialmanipulation/Tests/Runtime/BoundsControlTests.cs index 6c78851d516..b3b65ee1d4d 100644 --- a/com.microsoft.mrtk.spatialmanipulation/Tests/Runtime/BoundsControlTests.cs +++ b/com.microsoft.mrtk.spatialmanipulation/Tests/Runtime/BoundsControlTests.cs @@ -331,7 +331,8 @@ private bool ApproximatelyEquals(Quaternion a, Quaternion b, float tolerance = 0 { return Mathf.Abs(a.x - b.x) <= tolerance && Mathf.Abs(a.y - b.y) <= tolerance - && Mathf.Abs(a.z - b.z) <= tolerance; + && Mathf.Abs(a.z - b.z) <= tolerance + && Mathf.Abs(a.w - b.w) <= tolerance; } private IEnumerator HoverCursorRotation(string handleName, Vector3 expectedRotation, string visualsPath) @@ -376,7 +377,7 @@ private IEnumerator HoverCursorRotation(string handleName, Vector3 expectedRotat SpatialManipulationReticle[] reticles = Object.FindObjectsOfType(); Assert.AreEqual(reticles.Length, 1, "Cursor should appear."); GameObject cursor = reticles[0].gameObject; - Assert.IsTrue(ApproximatelyEquals(cursor.transform.eulerAngles, expectedRotation), $"Cursor should be rotated for {handleName}."); + Assert.IsTrue(ApproximatelyEquals(cursor.transform.eulerAngles, expectedRotation), $"Cursor should be rotated for {handleName}. Expected euler angles: {expectedRotation}. Actual: {cursor.transform.eulerAngles}"); Quaternion worldRotation = cursor.transform.rotation; // Select the handle @@ -410,4 +411,4 @@ private IEnumerator HoverCursorRotation(string handleName, Vector3 expectedRotat } } } -#pragma warning restore CS1591 \ No newline at end of file +#pragma warning restore CS1591