Skip to content

Commit

Permalink
Merge pull request #1245 from allenai/toggleCameraMeshTracking
Browse files Browse the repository at this point in the history
Toggle Main Camera Mesh Tracking
  • Loading branch information
winthos authored Nov 6, 2024
2 parents 88fd448 + 2f3413b commit c1f52ee
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
25 changes: 24 additions & 1 deletion unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private enum serverTypes {
"UpdateThirdPartyCamera",
"ChangeResolution",
"CoordinateFromRaycastThirdPartyCamera",
"ChangeQuality"
"ChangeQuality",
"ToggleAgentMainCameraMeshTracking"
};
public HashSet<string> errorAllowedActions = new HashSet<string> { "Reset" };

Expand Down Expand Up @@ -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<SyncTransform> st = UtilityFunctions.FindAllComponentsInChildren<SyncTransform>(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(
Expand Down
9 changes: 9 additions & 0 deletions unity/Assets/Scripts/DebugInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> action = new Dictionary<string, object>();
action["action"] = "ToggleAgentMainCameraMeshTracking";
action["toggleOff"] = true;
CurrentActiveController().ProcessControlCommand(new DynamicServerAction(action), AManager);
break;
}

// put an object down with stationary false
case "putf": {
Dictionary<string, object> action = new Dictionary<string, object>();
Expand Down
21 changes: 21 additions & 0 deletions unity/Assets/Scripts/UtilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> FindAllComponentsInChildren<T>(Transform parent) where T : Component
{
List<T> components = new List<T>();

// Check if the parent itself has the component
T component = parent.GetComponent<T>();
if (component != null)
{
components.Add(component);
}

// Loop through all children and collect their components recursively
foreach (Transform child in parent)
{
components.AddRange(FindAllComponentsInChildren<T>(child));
}

return components;
}

public static List<LightParameters> GetLightPropertiesOfScene() {
Debug.Log("we are inside GetLIghtPropertiesOfScene");
var lightsInScene = UnityEngine.Object.FindObjectsOfType<Light>(true);
Expand Down

0 comments on commit c1f52ee

Please sign in to comment.