From e100f410e7db6c6af5319e88884cb2b0ddf6ab16 Mon Sep 17 00:00:00 2001 From: Winson Han Date: Thu, 5 Sep 2024 16:39:53 -0700 Subject: [PATCH 1/8] first few changes --- unity/Assets/Scripts/AgentManager.cs | 54 ++++++++++--------- .../Assets/Scripts/BaseFPSAgentController.cs | 2 + 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 9e0efc8904..1fc2508dca 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1297,29 +1297,25 @@ bool shouldRenderImageSynthesis cMetadata.position = camera.gameObject.transform.position; cMetadata.rotation = camera.gameObject.transform.eulerAngles; + cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.position; + cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.rotation; - //agent relative third party camera metadata here - //if the camera is a child of the base agent, then return local space values - if (camera.GetComponentInParent()) { - cMetadata.agentPositionRelativeThirdPartyCameraPosition = camera - .gameObject - .transform - .localPosition; - cMetadata.agentPositionRelativeThirdPartyCameraRotation = camera - .gameObject - .transform - .localEulerAngles; + if(camera.transform.parent != null) { + cMetadata.parentObjectName = camera.transform.parent.name; + cMetadata.parentPositionRelativeThirdPartyCameraPosition = camera.transform.parent.InverseTransformPoint(camera.transform.position); + } else { + cMetadata.parentObjectName = ""; + } + + if (camera.GetComponentInParent() != null) { + GameObject agent = camera.GetComponentInParent().gameObject; + cMetadata.agentPositionRelativeThirdPartyCameraPosition = agent.transform.InverseTransformPoint(camera.gameObject.transform.position); + cMetadata.agentPositionRelativeThirdPartyCameraRotation = agent.transform.InverseTransformDirection(camera.gameObject.transform.forward); } else { //if this third party camera is not a child of the agent, then the agent relative coordinates //are the same as the world coordinates so - cMetadata.agentPositionRelativeThirdPartyCameraPosition = camera - .gameObject - .transform - .position; - cMetadata.agentPositionRelativeThirdPartyCameraRotation = camera - .gameObject - .transform - .eulerAngles; + cMetadata.agentPositionRelativeThirdPartyCameraPosition = null; + cMetadata.agentPositionRelativeThirdPartyCameraRotation = null; } cMetadata.fieldOfView = camera.fieldOfView; @@ -1846,14 +1842,20 @@ public class MultiAgentMetadata { [MessagePackObject(keyAsPropertyName: true)] public class ThirdPartyCameraMetadata { public int thirdPartyCameraId; - public Vector3 position; - public Vector3 rotation; + public Vector3 position; //to be deprecated + public Vector3 rotation; //to be deprecated + public Vector3 worldRelativeThirdPartyCameraPosition; + public Vector3 worldRelativeThirdPartyCameraRotation; public float fieldOfView; //note these should only be returned with values //if the third party camera is a child of the agent - public Vector3 agentPositionRelativeThirdPartyCameraPosition; - public Vector3 agentPositionRelativeThirdPartyCameraRotation; + public Vector3? agentPositionRelativeThirdPartyCameraPosition; + public Vector3? agentPositionRelativeThirdPartyCameraRotation; + //return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented + public Vector3? parentPositionRelativeThirdPartyCameraPosition; + public Vector3? parentPositionRelativeThirdPartyCameraRotation; + public string parentObjectName; //if this third party camera is in a heirarchy, return the name of the parent object } [Serializable] @@ -2280,8 +2282,10 @@ public struct MetadataWrapper { public ArmMetadata arm; public ArticulationArmMetadata articulationArm; public float fov; - public Vector3 cameraPosition; - public Vector3 cameraRotation; + public Vector3 cameraPosition; //to be deprecated + public Vector3 cameraRotation; //to be deprecated + public Vector3 worldRelativeCameraPosition; + public Vector3 worldRelativeCameraRotation; public Vector3 agentPositionRelativeCameraPosition; public Vector3 agentPositionRelativeCameraRotation; public float cameraOrthSize; diff --git a/unity/Assets/Scripts/BaseFPSAgentController.cs b/unity/Assets/Scripts/BaseFPSAgentController.cs index a2ef43c4fc..42b8a09439 100644 --- a/unity/Assets/Scripts/BaseFPSAgentController.cs +++ b/unity/Assets/Scripts/BaseFPSAgentController.cs @@ -2629,6 +2629,8 @@ public virtual MetadataWrapper generateMetadataWrapper() { metaMessage.cameraPosition = m_Camera.transform.position; metaMessage.cameraRotation = m_Camera.transform.eulerAngles; + metaMessage.worldRelativeCameraPosition = metaMessage.cameraPosition; + metaMessage.worldRelativeCameraRotation = metaMessage.cameraRotation; //we need to transform these relative to the agent position //main camera's local space coordinates need to be translated to world space first From 892da28a4919914f0550684678aa0a17338d9c93 Mon Sep 17 00:00:00 2001 From: Winson Han Date: Fri, 6 Sep 2024 13:13:07 -0700 Subject: [PATCH 2/8] getting parent and agent relative thirdpartycamera returns setup --- unity/Assets/Scripts/AgentManager.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 1fc2508dca..e5f4ca63e7 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1295,25 +1295,45 @@ bool shouldRenderImageSynthesis Camera camera = thirdPartyCameras.ToArray()[i]; cMetadata.thirdPartyCameraId = i; + //to be depracated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera.... cMetadata.position = camera.gameObject.transform.position; cMetadata.rotation = camera.gameObject.transform.eulerAngles; + //currently redundant data as it is the same as metadata.position/rotation, but more descriptive naming convention cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.position; cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.rotation; + //grab this for parent or agent relative stuff + var worldSpaceCameraRotationAsQuaternion = camera.transform.rotation; + + //this may be the same info as the agentPositionRelative values since ThirdPartyCameras often are children of the agent + //but in cases where a third party camera is attached to an arm joint or the like, this can be useful if(camera.transform.parent != null) { cMetadata.parentObjectName = camera.transform.parent.name; + cMetadata.parentPositionRelativeThirdPartyCameraPosition = camera.transform.parent.InverseTransformPoint(camera.transform.position); + + //get third party camera rotation as quaternion in world space + var parentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(camera.transform.parent.rotation) * worldSpaceCameraRotationAsQuaternion; + cMetadata.parentPositionRelativeThirdPartyCameraRotation = parentSpaceCameraRotationAsQuaternion.eulerAngles; + } else { cMetadata.parentObjectName = ""; + cMetadata.parentPositionRelativeThirdPartyCameraPosition = null; + cMetadata.parentPositionRelativeThirdPartyCameraRotation = null; } + //if this camera is part of the agent's heirarchy at all, get agent relative info if (camera.GetComponentInParent() != null) { GameObject agent = camera.GetComponentInParent().gameObject; + cMetadata.agentPositionRelativeThirdPartyCameraPosition = agent.transform.InverseTransformPoint(camera.gameObject.transform.position); - cMetadata.agentPositionRelativeThirdPartyCameraRotation = agent.transform.InverseTransformDirection(camera.gameObject.transform.forward); + + //get third party camera rotation as quaternion in world space + var agentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(agent.transform.rotation) * worldSpaceCameraRotationAsQuaternion; + cMetadata.agentPositionRelativeThirdPartyCameraRotation = agentSpaceCameraRotationAsQuaternion.eulerAngles; + } else { - //if this third party camera is not a child of the agent, then the agent relative coordinates - //are the same as the world coordinates so + //if this third party camera is not a child of the agent, we don't need agent-relative coordinates cMetadata.agentPositionRelativeThirdPartyCameraPosition = null; cMetadata.agentPositionRelativeThirdPartyCameraRotation = null; } From af301bda69002e926cb50c24a45396a007e6c9af Mon Sep 17 00:00:00 2001 From: Winson Han Date: Fri, 6 Sep 2024 14:37:34 -0700 Subject: [PATCH 3/8] adding unit tests for updated metadata returns --- unity/Assets/Scripts/AgentManager.cs | 10 +- .../Assets/Scripts/BaseFPSAgentController.cs | 14 +- .../TestThirdPartyCameraAndMainCamera.cs | 180 ++++++++++++++++++ 3 files changed, 190 insertions(+), 14 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index e5f4ca63e7..e351749812 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1296,15 +1296,15 @@ bool shouldRenderImageSynthesis cMetadata.thirdPartyCameraId = i; //to be depracated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera.... - cMetadata.position = camera.gameObject.transform.position; - cMetadata.rotation = camera.gameObject.transform.eulerAngles; + cMetadata.position = camera.transform.position; + cMetadata.rotation = camera.transform.eulerAngles; //currently redundant data as it is the same as metadata.position/rotation, but more descriptive naming convention - cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.position; - cMetadata.worldRelativeThirdPartyCameraPosition = cMetadata.rotation; + cMetadata.worldRelativeThirdPartyCameraPosition = camera.transform.position; + cMetadata.worldRelativeThirdPartyCameraRotation = camera.transform.eulerAngles; //grab this for parent or agent relative stuff var worldSpaceCameraRotationAsQuaternion = camera.transform.rotation; - + //this may be the same info as the agentPositionRelative values since ThirdPartyCameras often are children of the agent //but in cases where a third party camera is attached to an arm joint or the like, this can be useful if(camera.transform.parent != null) { diff --git a/unity/Assets/Scripts/BaseFPSAgentController.cs b/unity/Assets/Scripts/BaseFPSAgentController.cs index 42b8a09439..7af3eac1fe 100644 --- a/unity/Assets/Scripts/BaseFPSAgentController.cs +++ b/unity/Assets/Scripts/BaseFPSAgentController.cs @@ -2629,24 +2629,20 @@ public virtual MetadataWrapper generateMetadataWrapper() { metaMessage.cameraPosition = m_Camera.transform.position; metaMessage.cameraRotation = m_Camera.transform.eulerAngles; - metaMessage.worldRelativeCameraPosition = metaMessage.cameraPosition; - metaMessage.worldRelativeCameraRotation = metaMessage.cameraRotation; + metaMessage.worldRelativeCameraPosition = m_Camera.transform.position; + metaMessage.worldRelativeCameraRotation = m_Camera.transform.eulerAngles; //we need to transform these relative to the agent position //main camera's local space coordinates need to be translated to world space first var worldSpaceCameraPosition = m_Camera.transform.position; //now convert camera position to agent relative local space - metaMessage.agentPositionRelativeCameraPosition = transform.InverseTransformPoint( - worldSpaceCameraPosition - ); + metaMessage.agentPositionRelativeCameraPosition = transform.InverseTransformPoint(worldSpaceCameraPosition); //Debug.Log($"agentRelativeCameraPosition: {metaMessage.agentPositionRelativeCameraPosition}"); //ok to get local euler angles we need to do... some shenanigans lets go var worldSpaceCameraRotationAsQuaternion = m_Camera.transform.rotation; - var localSpaceCameraRotationAsQuaternion = - Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion; - metaMessage.agentPositionRelativeCameraRotation = - localSpaceCameraRotationAsQuaternion.eulerAngles; + var localSpaceCameraRotationAsQuaternion = Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion; + metaMessage.agentPositionRelativeCameraRotation = localSpaceCameraRotationAsQuaternion.eulerAngles; //Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentPositionRelativeCameraRotation}"); metaMessage.cameraOrthSize = cameraOrthSize; diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index 38a70f6897..d9ce5890db 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -312,5 +312,185 @@ public IEnumerator TestUpdateMainCamera() result = Mathf.Approximately(camera.transform.localEulerAngles.z, 0.0f); Assert.AreEqual(result, true); } + + //test main camera metadata + [UnityTest] + public IEnumerator TestMainCameraMetadataReturn() + { + bool result = false; + Dictionary action = new Dictionary(); + + action["action"] = "Initialize"; + action["fieldOfView"] = 90f; + action["snapToGrid"] = true; + yield return step(action); + + action.Clear(); + + MetadataWrapper metadata = getLastActionMetadata(); + + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.x, -1.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.y, 1.5759990000f); + Assert.AreEqual(result, true); + result= Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.x, 0.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.y, 270.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.z, 0.0000000000f); + Assert.AreEqual(result, true); + + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.x, 0.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.y, 0.6750000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.z, 0.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.x, 0.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.y, 0.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.z, 0.0000000000f); + Assert.AreEqual(result, true); + + action["action"] = "UpdateMainCamera"; + action["position"] = new Vector3(0.5f, 0.5f, 0.5f); + action["rotation"] = new Vector3(30f, 10f, 12f); + yield return step(action); + + metadata = getLastActionMetadata(); + + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.x, -1.5000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.y, 1.4009990000f); + Assert.AreEqual(result, true); + result= Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.5000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.x, 30.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.y, 280.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.worldRelativeCameraRotation.z, 12.0000000000f); + Assert.AreEqual(result, true); + + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.x, 0.5000001000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.y, 0.4999999000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.z, 0.5000002000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.x, 30.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.y, 10.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.z, 12.0000000000f); + Assert.AreEqual(result, true); + } + + //test third party camera metadata + [UnityTest] + public IEnumerator TestThirdPartyCameraMetadataReturn() + { + bool result = false; + + Dictionary action = new Dictionary(); + + action["action"] = "Initialize"; + action["fieldOfView"] = 90f; + action["snapToGrid"] = true; + yield return step(action); + + action.Clear(); + + action["action"] = "AddThirdPartyCamera"; + action["position"] = new Vector3(3, 2, 1); + action["rotation"] = new Vector3(10, 20, 30); + action["parent"] = "world"; + yield return step(action); + + MetadataWrapper metadata = getLastActionMetadata(); + + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, 3.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, 2.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, 1.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, 10.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, 30.0000000000f); + Assert.AreEqual(result, true); + Assert.AreEqual(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition, null); + Assert.AreEqual(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation, null); + Assert.AreEqual(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition, null); + Assert.AreEqual(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation, null); + Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, ""); + + action.Clear(); + + //use update third party camera to change camera to be attached to agent + action["action"] = "UpdateThirdPartyCamera"; + action["thirdPartyCameraId"] = 0; + action["position"] = new Vector3(1, 2, 3); + action["rotation"] = new Vector3(20, 20, 20); + action["parent"] = "agent"; + action["agentPositionRelativeCoordinates"] = true; + yield return step(action); + + metadata = getLastActionMetadata(); + + // //world relative + // Debug.Log($"world relative camera pos: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition:F10}"); + // Debug.Log($"world relative camera rot: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation:F10}"); + // //agent relative + // Debug.Log($"agent relative camera pos: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition:F10}"); + // Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation:F10}"); + // //parent relative + // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition:F10}"); + // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation:F10}"); + // Debug.Log($"parent object name: {metadata.thirdPartyCameras[0].parentObjectName}"); + + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, -4.0000010000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, 2.9009990000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, 2.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, 290.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.x, 1.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.y, 2.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.z, 3.0000020000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.x, 1.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.y, 2.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.z, 3.0000020000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f); + Assert.AreEqual(result, true); + result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f); + Assert.AreEqual(result, true); + Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, "FPSController"); + } } } From c7c3afff3fb94d41e97f004fdaeeafdd6dd2001e Mon Sep 17 00:00:00 2001 From: Winson Han Date: Fri, 6 Sep 2024 16:40:39 -0700 Subject: [PATCH 4/8] ran formatting --- unity/Assets/Scripts/AgentManager.cs | 27 +- .../Assets/Scripts/BaseFPSAgentController.cs | 10 +- .../Assets/Scripts/StretchAgentController.cs | 4 +- .../TestThirdPartyCameraAndMainCamera.cs | 232 ++++++++++++++---- 4 files changed, 213 insertions(+), 60 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index e351749812..fb9b815af5 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1307,15 +1307,18 @@ bool shouldRenderImageSynthesis //this may be the same info as the agentPositionRelative values since ThirdPartyCameras often are children of the agent //but in cases where a third party camera is attached to an arm joint or the like, this can be useful - if(camera.transform.parent != null) { + if (camera.transform.parent != null) { cMetadata.parentObjectName = camera.transform.parent.name; - cMetadata.parentPositionRelativeThirdPartyCameraPosition = camera.transform.parent.InverseTransformPoint(camera.transform.position); - - //get third party camera rotation as quaternion in world space - var parentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(camera.transform.parent.rotation) * worldSpaceCameraRotationAsQuaternion; - cMetadata.parentPositionRelativeThirdPartyCameraRotation = parentSpaceCameraRotationAsQuaternion.eulerAngles; + cMetadata.parentPositionRelativeThirdPartyCameraPosition = + camera.transform.parent.InverseTransformPoint(camera.transform.position); + //get third party camera rotation as quaternion in world space + var parentSpaceCameraRotationAsQuaternion = + Quaternion.Inverse(camera.transform.parent.rotation) + * worldSpaceCameraRotationAsQuaternion; + cMetadata.parentPositionRelativeThirdPartyCameraRotation = + parentSpaceCameraRotationAsQuaternion.eulerAngles; } else { cMetadata.parentObjectName = ""; cMetadata.parentPositionRelativeThirdPartyCameraPosition = null; @@ -1326,12 +1329,15 @@ bool shouldRenderImageSynthesis if (camera.GetComponentInParent() != null) { GameObject agent = camera.GetComponentInParent().gameObject; - cMetadata.agentPositionRelativeThirdPartyCameraPosition = agent.transform.InverseTransformPoint(camera.gameObject.transform.position); + cMetadata.agentPositionRelativeThirdPartyCameraPosition = + agent.transform.InverseTransformPoint(camera.gameObject.transform.position); //get third party camera rotation as quaternion in world space - var agentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(agent.transform.rotation) * worldSpaceCameraRotationAsQuaternion; - cMetadata.agentPositionRelativeThirdPartyCameraRotation = agentSpaceCameraRotationAsQuaternion.eulerAngles; - + var agentSpaceCameraRotationAsQuaternion = + Quaternion.Inverse(agent.transform.rotation) + * worldSpaceCameraRotationAsQuaternion; + cMetadata.agentPositionRelativeThirdPartyCameraRotation = + agentSpaceCameraRotationAsQuaternion.eulerAngles; } else { //if this third party camera is not a child of the agent, we don't need agent-relative coordinates cMetadata.agentPositionRelativeThirdPartyCameraPosition = null; @@ -1872,6 +1878,7 @@ public class ThirdPartyCameraMetadata { //if the third party camera is a child of the agent public Vector3? agentPositionRelativeThirdPartyCameraPosition; public Vector3? agentPositionRelativeThirdPartyCameraRotation; + //return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented public Vector3? parentPositionRelativeThirdPartyCameraPosition; public Vector3? parentPositionRelativeThirdPartyCameraRotation; diff --git a/unity/Assets/Scripts/BaseFPSAgentController.cs b/unity/Assets/Scripts/BaseFPSAgentController.cs index 7af3eac1fe..b04ff1f848 100644 --- a/unity/Assets/Scripts/BaseFPSAgentController.cs +++ b/unity/Assets/Scripts/BaseFPSAgentController.cs @@ -2636,13 +2636,17 @@ public virtual MetadataWrapper generateMetadataWrapper() { //main camera's local space coordinates need to be translated to world space first var worldSpaceCameraPosition = m_Camera.transform.position; //now convert camera position to agent relative local space - metaMessage.agentPositionRelativeCameraPosition = transform.InverseTransformPoint(worldSpaceCameraPosition); + metaMessage.agentPositionRelativeCameraPosition = transform.InverseTransformPoint( + worldSpaceCameraPosition + ); //Debug.Log($"agentRelativeCameraPosition: {metaMessage.agentPositionRelativeCameraPosition}"); //ok to get local euler angles we need to do... some shenanigans lets go var worldSpaceCameraRotationAsQuaternion = m_Camera.transform.rotation; - var localSpaceCameraRotationAsQuaternion = Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion; - metaMessage.agentPositionRelativeCameraRotation = localSpaceCameraRotationAsQuaternion.eulerAngles; + var localSpaceCameraRotationAsQuaternion = + Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion; + metaMessage.agentPositionRelativeCameraRotation = + localSpaceCameraRotationAsQuaternion.eulerAngles; //Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentPositionRelativeCameraRotation}"); metaMessage.cameraOrthSize = cameraOrthSize; diff --git a/unity/Assets/Scripts/StretchAgentController.cs b/unity/Assets/Scripts/StretchAgentController.cs index ba7967f92f..0c9f8e4fe8 100644 --- a/unity/Assets/Scripts/StretchAgentController.cs +++ b/unity/Assets/Scripts/StretchAgentController.cs @@ -739,9 +739,7 @@ public void PlaceObjectIntoGripper(string objectId, bool grasp = true) { Physics.SyncTransforms(); - Collider c = UtilityFunctions.firstColliderObjectCollidingWith( - go: sop.gameObject - ); + Collider c = UtilityFunctions.firstColliderObjectCollidingWith(go: sop.gameObject); if (c != null) { SimObjPhysics collisionSop = ancestorSimObjPhysics(c.gameObject); errorMessage = diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index d9ce5890db..7fd08f9c14 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -315,7 +315,7 @@ public IEnumerator TestUpdateMainCamera() //test main camera metadata [UnityTest] - public IEnumerator TestMainCameraMetadataReturn() + public IEnumerator TestMainCameraMetadataReturn() { bool result = false; Dictionary action = new Dictionary(); @@ -333,7 +333,7 @@ public IEnumerator TestMainCameraMetadataReturn() Assert.AreEqual(result, true); result = Mathf.Approximately(metadata.worldRelativeCameraPosition.y, 1.5759990000f); Assert.AreEqual(result, true); - result= Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.0000000000f); + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.0000000000f); Assert.AreEqual(result, true); result = Mathf.Approximately(metadata.worldRelativeCameraRotation.x, 0.0000000000f); Assert.AreEqual(result, true); @@ -342,17 +342,35 @@ public IEnumerator TestMainCameraMetadataReturn() result = Mathf.Approximately(metadata.worldRelativeCameraRotation.z, 0.0000000000f); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.x, 0.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.x, + 0.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.y, 0.6750000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.y, + 0.6750000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.z, 0.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.z, + 0.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.x, 0.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.x, + 0.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.y, 0.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.y, + 0.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.z, 0.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.z, + 0.0000000000f + ); Assert.AreEqual(result, true); action["action"] = "UpdateMainCamera"; @@ -366,7 +384,7 @@ public IEnumerator TestMainCameraMetadataReturn() Assert.AreEqual(result, true); result = Mathf.Approximately(metadata.worldRelativeCameraPosition.y, 1.4009990000f); Assert.AreEqual(result, true); - result= Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.5000000000f); + result = Mathf.Approximately(metadata.worldRelativeCameraPosition.z, 1.5000000000f); Assert.AreEqual(result, true); result = Mathf.Approximately(metadata.worldRelativeCameraRotation.x, 30.0000000000f); Assert.AreEqual(result, true); @@ -375,23 +393,41 @@ public IEnumerator TestMainCameraMetadataReturn() result = Mathf.Approximately(metadata.worldRelativeCameraRotation.z, 12.0000000000f); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.x, 0.5000001000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.x, + 0.5000001000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.y, 0.4999999000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.y, + 0.4999999000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraPosition.z, 0.5000002000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraPosition.z, + 0.5000002000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.x, 30.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.x, + 30.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.y, 10.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.y, + 10.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.agentPositionRelativeCameraRotation.z, 12.0000000000f); + result = Mathf.Approximately( + metadata.agentPositionRelativeCameraRotation.z, + 12.0000000000f + ); Assert.AreEqual(result, true); } //test third party camera metadata [UnityTest] - public IEnumerator TestThirdPartyCameraMetadataReturn() + public IEnumerator TestThirdPartyCameraMetadataReturn() { bool result = false; @@ -412,22 +448,52 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() MetadataWrapper metadata = getLastActionMetadata(); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, 3.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, + 3.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, 2.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, + 2.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, 1.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, + 1.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, 10.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, + 10.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, 30.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, + 30.0000000000f + ); Assert.AreEqual(result, true); - Assert.AreEqual(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition, null); - Assert.AreEqual(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation, null); - Assert.AreEqual(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition, null); - Assert.AreEqual(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation, null); + Assert.AreEqual( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition, + null + ); + Assert.AreEqual( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation, + null + ); + Assert.AreEqual( + metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition, + null + ); + Assert.AreEqual( + metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation, + null + ); Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, ""); action.Clear(); @@ -454,41 +520,119 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation:F10}"); // Debug.Log($"parent object name: {metadata.thirdPartyCameras[0].parentObjectName}"); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, -4.0000010000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, + -4.0000010000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, 2.9009990000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.y, + 2.9009990000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, 2.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.z, + 2.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, 290.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.y, + 290.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.z, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.x, 1.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.x, + 1.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.y, 2.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.y, + 2.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.z, 3.0000020000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.z, + 3.0000020000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.x, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.y, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.z, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.x, 1.0000000000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraPosition + .Value + .x, + 1.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.y, 2.0000000000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraPosition + .Value + .y, + 2.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition.Value.z, 3.0000020000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraPosition + .Value + .z, + 3.0000020000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraRotation + .Value + .x, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraRotation + .Value + .y, + 20.0000000000f + ); Assert.AreEqual(result, true); - result = Mathf.Approximately(metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f); + result = Mathf.Approximately( + metadata + .thirdPartyCameras[0] + .parentPositionRelativeThirdPartyCameraRotation + .Value + .z, + 20.0000000000f + ); Assert.AreEqual(result, true); Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, "FPSController"); } From ef3bfb20c08ec9a7a991b23d7e9008af3c72d132 Mon Sep 17 00:00:00 2001 From: Winson Han Date: Tue, 10 Sep 2024 12:18:09 -0700 Subject: [PATCH 5/8] cleaning up comments, rename one variable cleaning up some comments and spelling, changing the following nomenclature: //for third party camera agentPositionRelativeThirdPartyCameraRotation -> agentRotationRelativeThirdPartyCameraRotation //for main camera agentPositionRelativeCameraRotation -> agentRotationRelativeCameraRotation as rotation relative to the agent position doesn't mean anything. --- unity/Assets/Scripts/AgentManager.cs | 17 +++++++------- .../Assets/Scripts/BaseFPSAgentController.cs | 8 +++---- .../TestThirdPartyCameraAndMainCamera.cs | 22 +++++++++---------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index fb9b815af5..79f7f69588 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1295,7 +1295,7 @@ bool shouldRenderImageSynthesis Camera camera = thirdPartyCameras.ToArray()[i]; cMetadata.thirdPartyCameraId = i; - //to be depracated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera.... + //to be deprecated at some point, will be replaced by more descriptive worldRelativeThirdPartyCamera.... cMetadata.position = camera.transform.position; cMetadata.rotation = camera.transform.eulerAngles; //currently redundant data as it is the same as metadata.position/rotation, but more descriptive naming convention @@ -1313,7 +1313,7 @@ bool shouldRenderImageSynthesis cMetadata.parentPositionRelativeThirdPartyCameraPosition = camera.transform.parent.InverseTransformPoint(camera.transform.position); - //get third party camera rotation as quaternion in world space + //get third party camera rotation as quaternion in parent space var parentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(camera.transform.parent.rotation) * worldSpaceCameraRotationAsQuaternion; @@ -1325,23 +1325,22 @@ bool shouldRenderImageSynthesis cMetadata.parentPositionRelativeThirdPartyCameraRotation = null; } - //if this camera is part of the agent's heirarchy at all, get agent relative info + //if this camera is part of the agent's hierarchy at all, get agent relative info if (camera.GetComponentInParent() != null) { GameObject agent = camera.GetComponentInParent().gameObject; cMetadata.agentPositionRelativeThirdPartyCameraPosition = agent.transform.InverseTransformPoint(camera.gameObject.transform.position); - //get third party camera rotation as quaternion in world space var agentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(agent.transform.rotation) * worldSpaceCameraRotationAsQuaternion; - cMetadata.agentPositionRelativeThirdPartyCameraRotation = + cMetadata.agentRotationRelativeThirdPartyCameraRotation = agentSpaceCameraRotationAsQuaternion.eulerAngles; } else { //if this third party camera is not a child of the agent, we don't need agent-relative coordinates cMetadata.agentPositionRelativeThirdPartyCameraPosition = null; - cMetadata.agentPositionRelativeThirdPartyCameraRotation = null; + cMetadata.agentRotationRelativeThirdPartyCameraRotation = null; } cMetadata.fieldOfView = camera.fieldOfView; @@ -1877,12 +1876,12 @@ public class ThirdPartyCameraMetadata { //note these should only be returned with values //if the third party camera is a child of the agent public Vector3? agentPositionRelativeThirdPartyCameraPosition; - public Vector3? agentPositionRelativeThirdPartyCameraRotation; + public Vector3? agentRotationRelativeThirdPartyCameraRotation; //return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented public Vector3? parentPositionRelativeThirdPartyCameraPosition; public Vector3? parentPositionRelativeThirdPartyCameraRotation; - public string parentObjectName; //if this third party camera is in a heirarchy, return the name of the parent object + public string parentObjectName; //if this third party camera is in a hierarchy, return the name of the parent object } [Serializable] @@ -2314,7 +2313,7 @@ public struct MetadataWrapper { public Vector3 worldRelativeCameraPosition; public Vector3 worldRelativeCameraRotation; public Vector3 agentPositionRelativeCameraPosition; - public Vector3 agentPositionRelativeCameraRotation; + public Vector3 agentRotationRelativeCameraRotation; public float cameraOrthSize; public ThirdPartyCameraMetadata[] thirdPartyCameras; public bool collided; diff --git a/unity/Assets/Scripts/BaseFPSAgentController.cs b/unity/Assets/Scripts/BaseFPSAgentController.cs index b04ff1f848..1ad6e89011 100644 --- a/unity/Assets/Scripts/BaseFPSAgentController.cs +++ b/unity/Assets/Scripts/BaseFPSAgentController.cs @@ -2627,8 +2627,8 @@ public virtual MetadataWrapper generateMetadataWrapper() { metaMessage.screenWidth = Screen.width; metaMessage.screenHeight = Screen.height; - metaMessage.cameraPosition = m_Camera.transform.position; - metaMessage.cameraRotation = m_Camera.transform.eulerAngles; + metaMessage.cameraPosition = m_Camera.transform.position; //to be deprecated + metaMessage.cameraRotation = m_Camera.transform.eulerAngles; //to be deprecated metaMessage.worldRelativeCameraPosition = m_Camera.transform.position; metaMessage.worldRelativeCameraRotation = m_Camera.transform.eulerAngles; @@ -2645,9 +2645,9 @@ public virtual MetadataWrapper generateMetadataWrapper() { var worldSpaceCameraRotationAsQuaternion = m_Camera.transform.rotation; var localSpaceCameraRotationAsQuaternion = Quaternion.Inverse(transform.rotation) * worldSpaceCameraRotationAsQuaternion; - metaMessage.agentPositionRelativeCameraRotation = + metaMessage.agentRotationRelativeCameraRotation = localSpaceCameraRotationAsQuaternion.eulerAngles; - //Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentPositionRelativeCameraRotation}"); + //Debug.Log($"agentRelativeCameraRotation: {metaMessage.agentRotationRelativeCameraRotation}"); metaMessage.cameraOrthSize = cameraOrthSize; cameraOrthSize = -1f; diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index 7fd08f9c14..dc47ced39a 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -358,17 +358,17 @@ public IEnumerator TestMainCameraMetadataReturn() ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.x, + metadata.agentRotationRelativeCameraRotation.x, 0.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.y, + metadata.agentRotationRelativeCameraRotation.y, 0.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.z, + metadata.agentRotationRelativeCameraRotation.z, 0.0000000000f ); Assert.AreEqual(result, true); @@ -409,17 +409,17 @@ public IEnumerator TestMainCameraMetadataReturn() ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.x, + metadata.agentRotationRelativeCameraRotation.x, 30.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.y, + metadata.agentRotationRelativeCameraRotation.y, 10.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.agentPositionRelativeCameraRotation.z, + metadata.agentRotationRelativeCameraRotation.z, 12.0000000000f ); Assert.AreEqual(result, true); @@ -483,7 +483,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() null ); Assert.AreEqual( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation, + metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation, null ); Assert.AreEqual( @@ -514,7 +514,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() // Debug.Log($"world relative camera rot: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation:F10}"); // //agent relative // Debug.Log($"agent relative camera pos: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition:F10}"); - // Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation:F10}"); + // Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation:F10}"); // //parent relative // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition:F10}"); // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation:F10}"); @@ -566,17 +566,17 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.x, + metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.y, + metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraRotation.Value.z, + metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f ); Assert.AreEqual(result, true); From b86121869dbce2765a70b4893b4cca5072f5262e Mon Sep 17 00:00:00 2001 From: Winson Han Date: Fri, 13 Sep 2024 13:19:26 -0700 Subject: [PATCH 6/8] addressing comments - removing extra inverse matrix operations --- unity/Assets/Scripts/AgentManager.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 79f7f69588..712c9497de 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -624,10 +624,10 @@ private void updateCameraProperties( camera.transform.localScale = Vector3.one; } else { if (position.HasValue) { - camera.gameObject.transform.position = position.Value; + camera.transform.position = position.Value; } if (rotation.HasValue) { - camera.gameObject.transform.eulerAngles = rotation.Value; + camera.transform.eulerAngles = rotation.Value; } } @@ -1311,14 +1311,11 @@ bool shouldRenderImageSynthesis cMetadata.parentObjectName = camera.transform.parent.name; cMetadata.parentPositionRelativeThirdPartyCameraPosition = - camera.transform.parent.InverseTransformPoint(camera.transform.position); + camera.transform.localPosition; //get third party camera rotation as quaternion in parent space - var parentSpaceCameraRotationAsQuaternion = - Quaternion.Inverse(camera.transform.parent.rotation) - * worldSpaceCameraRotationAsQuaternion; cMetadata.parentPositionRelativeThirdPartyCameraRotation = - parentSpaceCameraRotationAsQuaternion.eulerAngles; + camera.transform.localEulerAngles; } else { cMetadata.parentObjectName = ""; cMetadata.parentPositionRelativeThirdPartyCameraPosition = null; @@ -1330,7 +1327,7 @@ bool shouldRenderImageSynthesis GameObject agent = camera.GetComponentInParent().gameObject; cMetadata.agentPositionRelativeThirdPartyCameraPosition = - agent.transform.InverseTransformPoint(camera.gameObject.transform.position); + agent.transform.InverseTransformPoint(camera.transform.position); var agentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(agent.transform.rotation) From 12d8e0548244938bb119e08703dfb722101b6f64 Mon Sep 17 00:00:00 2001 From: Winson Han Date: Mon, 16 Sep 2024 09:57:37 -0700 Subject: [PATCH 7/8] shortening variable names shortening the following: - agentPositionRelativeThirdPartyCameraPosition -> agentRelativeThirdPartyCameraPosition - agentRotationRelativeThirdPartyCameraRotation -> agentRelativeThirdPartyCameraRotation - parentPositionRelativeThirdPartyCameraPosition -> parentRelativeThirdPartyCameraPosition - parentRotationRelativeThirdPartyCameraRotation -> parentRelativeThirdPartyCameraRotation --- unity/Assets/Scripts/AgentManager.cs | 24 +++++------ .../TestThirdPartyCameraAndMainCamera.cs | 40 +++++++++---------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 712c9497de..3f54a0749f 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1310,34 +1310,34 @@ bool shouldRenderImageSynthesis if (camera.transform.parent != null) { cMetadata.parentObjectName = camera.transform.parent.name; - cMetadata.parentPositionRelativeThirdPartyCameraPosition = + cMetadata.parentRelativeThirdPartyCameraPosition = camera.transform.localPosition; //get third party camera rotation as quaternion in parent space - cMetadata.parentPositionRelativeThirdPartyCameraRotation = + cMetadata.parentRelativeThirdPartyCameraRotation = camera.transform.localEulerAngles; } else { cMetadata.parentObjectName = ""; - cMetadata.parentPositionRelativeThirdPartyCameraPosition = null; - cMetadata.parentPositionRelativeThirdPartyCameraRotation = null; + cMetadata.parentRelativeThirdPartyCameraPosition = null; + cMetadata.parentRelativeThirdPartyCameraRotation = null; } //if this camera is part of the agent's hierarchy at all, get agent relative info if (camera.GetComponentInParent() != null) { GameObject agent = camera.GetComponentInParent().gameObject; - cMetadata.agentPositionRelativeThirdPartyCameraPosition = + cMetadata.agentRelativeThirdPartyCameraPosition = agent.transform.InverseTransformPoint(camera.transform.position); var agentSpaceCameraRotationAsQuaternion = Quaternion.Inverse(agent.transform.rotation) * worldSpaceCameraRotationAsQuaternion; - cMetadata.agentRotationRelativeThirdPartyCameraRotation = + cMetadata.agentRelativeThirdPartyCameraRotation = agentSpaceCameraRotationAsQuaternion.eulerAngles; } else { //if this third party camera is not a child of the agent, we don't need agent-relative coordinates - cMetadata.agentPositionRelativeThirdPartyCameraPosition = null; - cMetadata.agentRotationRelativeThirdPartyCameraRotation = null; + cMetadata.agentRelativeThirdPartyCameraPosition = null; + cMetadata.agentRelativeThirdPartyCameraRotation = null; } cMetadata.fieldOfView = camera.fieldOfView; @@ -1872,12 +1872,12 @@ public class ThirdPartyCameraMetadata { //note these should only be returned with values //if the third party camera is a child of the agent - public Vector3? agentPositionRelativeThirdPartyCameraPosition; - public Vector3? agentRotationRelativeThirdPartyCameraRotation; + public Vector3? agentRelativeThirdPartyCameraPosition; + public Vector3? agentRelativeThirdPartyCameraRotation; //return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented - public Vector3? parentPositionRelativeThirdPartyCameraPosition; - public Vector3? parentPositionRelativeThirdPartyCameraRotation; + public Vector3? parentRelativeThirdPartyCameraPosition; + public Vector3? parentRelativeThirdPartyCameraRotation; public string parentObjectName; //if this third party camera is in a hierarchy, return the name of the parent object } diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index dc47ced39a..f6f6b9522e 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -479,19 +479,19 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() ); Assert.AreEqual(result, true); Assert.AreEqual( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition, null ); Assert.AreEqual( - metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation, null ); Assert.AreEqual( - metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition, + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition, null ); Assert.AreEqual( - metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation, + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation, null ); Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, ""); @@ -513,11 +513,11 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() // Debug.Log($"world relative camera pos: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition:F10}"); // Debug.Log($"world relative camera rot: {metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation:F10}"); // //agent relative - // Debug.Log($"agent relative camera pos: {metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition:F10}"); - // Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation:F10}"); + // Debug.Log($"agent relative camera pos: {metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition:F10}"); + // Debug.Log($"agent relative camera rot: {metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation:F10}"); // //parent relative - // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraPosition:F10}"); - // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentPositionRelativeThirdPartyCameraRotation:F10}"); + // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition:F10}"); + // Debug.Log($"parent relative camera rot: {metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation:F10}"); // Debug.Log($"parent object name: {metadata.thirdPartyCameras[0].parentObjectName}"); result = Mathf.Approximately( @@ -551,39 +551,39 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.x, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition.Value.x, 1.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.y, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition.Value.y, 2.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentPositionRelativeThirdPartyCameraPosition.Value.z, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition.Value.z, 3.0000020000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.x, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation.Value.x, 20.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.y, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation.Value.y, 20.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( - metadata.thirdPartyCameras[0].agentRotationRelativeThirdPartyCameraRotation.Value.z, + metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation.Value.z, 20.0000000000f ); Assert.AreEqual(result, true); result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraPosition + .parentRelativeThirdPartyCameraPosition .Value .x, 1.0000000000f @@ -592,7 +592,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraPosition + .parentRelativeThirdPartyCameraPosition .Value .y, 2.0000000000f @@ -601,7 +601,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraPosition + .parentRelativeThirdPartyCameraPosition .Value .z, 3.0000020000f @@ -610,7 +610,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraRotation + .parentRelativeThirdPartyCameraRotation .Value .x, 20.0000000000f @@ -619,7 +619,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraRotation + .parentRelativeThirdPartyCameraRotation .Value .y, 20.0000000000f @@ -628,7 +628,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() result = Mathf.Approximately( metadata .thirdPartyCameras[0] - .parentPositionRelativeThirdPartyCameraRotation + .parentRelativeThirdPartyCameraRotation .Value .z, 20.0000000000f From b93fc060ab3eb1255c578bc589e6811f90373756 Mon Sep 17 00:00:00 2001 From: Winson Han Date: Thu, 19 Sep 2024 15:49:06 -0700 Subject: [PATCH 8/8] change parentRelativeThirdpartyCameraPosition/Rotation to default to world coords if null parent rather than returning null if no parent object, the parentRelativeThirdPartyCameraPosition and parentRelativeThirdPartyCameraRotation now default to world coordinates since za warudo is the parent now --- unity/Assets/Scripts/AgentManager.cs | 11 +++-- .../TestThirdPartyCameraAndMainCamera.cs | 46 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index 3f54a0749f..1b869c9fad 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -1317,9 +1317,10 @@ bool shouldRenderImageSynthesis cMetadata.parentRelativeThirdPartyCameraRotation = camera.transform.localEulerAngles; } else { + //if not parented, default position and rotation to world coordinate space cMetadata.parentObjectName = ""; - cMetadata.parentRelativeThirdPartyCameraPosition = null; - cMetadata.parentRelativeThirdPartyCameraRotation = null; + cMetadata.parentRelativeThirdPartyCameraPosition = camera.transform.position; + cMetadata.parentRelativeThirdPartyCameraRotation = camera.transform.rotation.eulerAngles; } //if this camera is part of the agent's hierarchy at all, get agent relative info @@ -1336,6 +1337,8 @@ bool shouldRenderImageSynthesis agentSpaceCameraRotationAsQuaternion.eulerAngles; } else { //if this third party camera is not a child of the agent, we don't need agent-relative coordinates + //Note: We don't default this to world space because in the case of a multi-agent scenario, the agent + //to be relative to is ambiguous and UHHHHH cMetadata.agentRelativeThirdPartyCameraPosition = null; cMetadata.agentRelativeThirdPartyCameraRotation = null; } @@ -1876,8 +1879,8 @@ public class ThirdPartyCameraMetadata { public Vector3? agentRelativeThirdPartyCameraRotation; //return the local space coordinates if this third party camera has a parent object, this may be the same as agentPositionRelative depending on how things are parented - public Vector3? parentRelativeThirdPartyCameraPosition; - public Vector3? parentRelativeThirdPartyCameraRotation; + public Vector3 parentRelativeThirdPartyCameraPosition; + public Vector3 parentRelativeThirdPartyCameraRotation; public string parentObjectName; //if this third party camera is in a hierarchy, return the name of the parent object } diff --git a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs index f6f6b9522e..cd20598ace 100644 --- a/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs +++ b/unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs @@ -448,6 +448,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() MetadataWrapper metadata = getLastActionMetadata(); + // World Relative Position result = Mathf.Approximately( metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraPosition.x, 3.0000000000f @@ -463,6 +464,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() 1.0000000000f ); Assert.AreEqual(result, true); + // World Relative Rotation result = Mathf.Approximately( metadata.thirdPartyCameras[0].worldRelativeThirdPartyCameraRotation.x, 10.0000000000f @@ -478,6 +480,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() 30.0000000000f ); Assert.AreEqual(result, true); + //Agent Relative Position Assert.AreEqual( metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraPosition, null @@ -486,16 +489,39 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata.thirdPartyCameras[0].agentRelativeThirdPartyCameraRotation, null ); - Assert.AreEqual( - metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition, - null + //Parent Relative Position + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.x, + 3.0000000000f ); - Assert.AreEqual( - metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation, - null + Assert.AreEqual(result, true); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.y, + 2.0000000000f + ); + Assert.AreEqual(result, true); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.z, + 1.0000000000f ); + Assert.AreEqual(result, true); + //Parent Relative Rotation + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.x, + 10.0000000000f + ); + Assert.AreEqual(result, true); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.y, + 20.0000000000f + ); + Assert.AreEqual(result, true); + result = Mathf.Approximately( + metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.z, + 30.0000000000f + ); + Assert.AreEqual(result, true); Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, ""); - action.Clear(); //use update third party camera to change camera to be attached to agent @@ -584,7 +610,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraPosition - .Value .x, 1.0000000000f ); @@ -593,7 +618,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraPosition - .Value .y, 2.0000000000f ); @@ -602,7 +626,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraPosition - .Value .z, 3.0000020000f ); @@ -611,7 +634,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraRotation - .Value .x, 20.0000000000f ); @@ -620,7 +642,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraRotation - .Value .y, 20.0000000000f ); @@ -629,7 +650,6 @@ public IEnumerator TestThirdPartyCameraMetadataReturn() metadata .thirdPartyCameras[0] .parentRelativeThirdPartyCameraRotation - .Value .z, 20.0000000000f );