Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle Main Camera Mesh Tracking #1245

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading