From ba319119381b1d766352660a464045345b7ee80b Mon Sep 17 00:00:00 2001 From: winthos Date: Mon, 10 Jan 2022 13:59:58 -0800 Subject: [PATCH] fix to cached object oriented bounds rotation assignment -fixing bug where the cached object oriented bounds for pickupable and moveable sim objects was not assigning the rotation of the bounds correctly. -the boundingBox child object's `rotation` was being set, where the `localRotation` should have been being set -This should fix all sim objects having more accurate placement in all actions requiring the cached bounding box values (PutObject, InitialRandomSpawn, etc) --- unity/Assets/Scripts/SimObjPhysics.cs | 2 +- .../TestCachedObjectOrientedBoundsRotation.cs | 42 +++++++++++++++++++ ...CachedObjectOrientedBoundsRotation.cs.meta | 11 +++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs create mode 100644 unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs.meta diff --git a/unity/Assets/Scripts/SimObjPhysics.cs b/unity/Assets/Scripts/SimObjPhysics.cs index 48f96e3ccc..21eea4abbc 100644 --- a/unity/Assets/Scripts/SimObjPhysics.cs +++ b/unity/Assets/Scripts/SimObjPhysics.cs @@ -338,7 +338,7 @@ private ObjectOrientedBoundingBox objectOrientedBoundingBox() { // Update SimObject's BoundingBox collider to match new bounds this.BoundingBox.transform.localPosition = Vector3.zero; - this.BoundingBox.transform.rotation = Quaternion.identity; + this.BoundingBox.transform.localRotation = Quaternion.identity; this.BoundingBox.GetComponent().center = newBB.center; this.BoundingBox.GetComponent().size = newBB.extents * 2.0f; diff --git a/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs b/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs new file mode 100644 index 0000000000..5352358e27 --- /dev/null +++ b/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs @@ -0,0 +1,42 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using System; +using UnityEngine; +using UnityEngine.TestTools; +using UnityStandardAssets.Characters.FirstPerson; + +namespace Tests { + public class TestCachedObjectOrientedBoundsRotation : TestBase + { + + //check to make sure the automatic caching of the object oriented bounds is assigning + //the localRotation of the BoundingBox child object of any given SimObject is set to + //(0,0,0) or Quaternion.identity, correctly + [UnityTest] + public IEnumerator TestCachedBoundsRotation() { + Dictionary action = new Dictionary(); + + action["action"] = "Initialize"; + action["fieldOfView"] = 90f; + action["snapToGrid"] = true; + yield return step(action); + + GameObject book = GameObject.Find("Book_3d15d052"); + + bool result = false; + GameObject boundingBox = book.transform.Find("BoundingBox").gameObject; + + result = Mathf.Approximately(boundingBox.transform.localRotation.x, 0.0f); + Assert.AreEqual(result, true); + + result = Mathf.Approximately(boundingBox.transform.localRotation.y, 0.0f); + Assert.AreEqual(result, true); + + result = Mathf.Approximately(boundingBox.transform.localRotation.z, 0.0f); + Assert.AreEqual(result, true); + } + } +} + + diff --git a/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs.meta b/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs.meta new file mode 100644 index 0000000000..71ebfa9dd8 --- /dev/null +++ b/unity/Assets/UnitTests/TestCachedObjectOrientedBoundsRotation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b88863794da67054db3f05bff76de873 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: