diff --git a/unity/Assets/Scripts/AgentManager.cs b/unity/Assets/Scripts/AgentManager.cs index b3dc6c1a97..3d8721be27 100644 --- a/unity/Assets/Scripts/AgentManager.cs +++ b/unity/Assets/Scripts/AgentManager.cs @@ -88,7 +88,8 @@ private enum serverTypes { "UpdateThirdPartyCamera", "ChangeResolution", "CoordinateFromRaycastThirdPartyCamera", - "ChangeQuality" + "ChangeQuality", + "ToggleAgentMainCameraMeshTracking" }; public HashSet errorAllowedActions = new HashSet { "Reset" }; @@ -826,6 +827,28 @@ public OptionalVector3(float? x = null, float? y = null, float? z = null) { } } + //toggles off any meshes on the agent that are tracking the position/rotation of the main camera + //this allows us to call things like UpdateMainCamera without parts of the agent body mesh moving + public void ToggleAgentMainCameraMeshTracking(bool toggleOff = true, int agentId = 0) { + //which agent are we talking about? + //default to agent 0 + var agent = this.agents[agentId]; + + List st = UtilityFunctions.FindAllComponentsInChildren(agent.transform); + + if(st.Count > 0) { + foreach (SyncTransform s in st) { + s.enabled = !toggleOff; + } + } else { + throw new InvalidOperationException( + $"Agent {agentId} does not have any SyncTransform components to toggle." + ); + } + + agent.actionFinishedEmit(success:true); + } + //allows repositioning and changing of values of agent's primary camera //note this does not support changing the main camera of multiple agents beyond the primary for now public void UpdateMainCamera( diff --git a/unity/Assets/Scripts/DebugInputField.cs b/unity/Assets/Scripts/DebugInputField.cs index 549cae6413..aeac2ef6be 100644 --- a/unity/Assets/Scripts/DebugInputField.cs +++ b/unity/Assets/Scripts/DebugInputField.cs @@ -2801,6 +2801,15 @@ IEnumerator executeBatch(JArray jActions) { break; } + //allows us to toggle of any meshes tracking the positiong and rotation of the main camera + case "tamcmt": { + Dictionary action = new Dictionary(); + action["action"] = "ToggleAgentMainCameraMeshTracking"; + action["toggleOff"] = true; + CurrentActiveController().ProcessControlCommand(new DynamicServerAction(action), AManager); + break; + } + // put an object down with stationary false case "putf": { Dictionary action = new Dictionary(); diff --git a/unity/Assets/Scripts/UtilityFunctions.cs b/unity/Assets/Scripts/UtilityFunctions.cs index c9c0157a62..490cc46ce0 100644 --- a/unity/Assets/Scripts/UtilityFunctions.cs +++ b/unity/Assets/Scripts/UtilityFunctions.cs @@ -398,6 +398,27 @@ public static Vector3[] CornerCoordinatesOfBoxColliderToWorld(BoxCollider b) { return corners; } + // Recursive method to find and return all instances of the component in the hierarchy + public static List FindAllComponentsInChildren(Transform parent) where T : Component + { + List components = new List(); + + // Check if the parent itself has the component + T component = parent.GetComponent(); + if (component != null) + { + components.Add(component); + } + + // Loop through all children and collect their components recursively + foreach (Transform child in parent) + { + components.AddRange(FindAllComponentsInChildren(child)); + } + + return components; + } + public static List GetLightPropertiesOfScene() { Debug.Log("we are inside GetLIghtPropertiesOfScene"); var lightsInScene = UnityEngine.Object.FindObjectsOfType(true);