Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
winthos committed Sep 25, 2024
1 parent 33ef2df commit 1b9a986
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 57 deletions.
17 changes: 11 additions & 6 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1310,17 +1310,22 @@ bool shouldRenderImageSynthesis
if (camera.transform.parent != null) {
cMetadata.parentObjectName = camera.transform.parent.name;

cMetadata.parentRelativeThirdPartyCameraPosition =
camera.transform.localPosition;
cMetadata.parentRelativeThirdPartyCameraPosition = camera
.transform
.localPosition;

//get third party camera rotation as quaternion in parent space
cMetadata.parentRelativeThirdPartyCameraRotation =
camera.transform.localEulerAngles;
cMetadata.parentRelativeThirdPartyCameraRotation = camera
.transform
.localEulerAngles;
} else {
//if not parented, default position and rotation to world coordinate space
cMetadata.parentObjectName = "";
cMetadata.parentRelativeThirdPartyCameraPosition = camera.transform.position;
cMetadata.parentRelativeThirdPartyCameraRotation = camera.transform.rotation.eulerAngles;
cMetadata.parentRelativeThirdPartyCameraRotation = camera
.transform
.rotation
.eulerAngles;
}

//if this camera is part of the agent's hierarchy at all, get agent relative info
Expand All @@ -1337,7 +1342,7 @@ 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
//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;
Expand Down
21 changes: 10 additions & 11 deletions unity/Assets/Scripts/ArmAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ public override void Teleport(
bool forceAction = false
) {
//non-high level agents cannot set standing
if(standing != null) {
if (standing != null) {
errorMessage = "Cannot set standing for arm/stretch agent";
actionFinishedEmit(success:false, actionReturn:null, errorMessage:errorMessage);
actionFinishedEmit(success: false, actionReturn: null, errorMessage: errorMessage);
return;
}

Expand All @@ -290,19 +290,19 @@ public override void Teleport(
}

public override void TeleportFull(
Vector3? position = null,
Vector3? rotation = null,
float? horizon = null,
bool? standing = null,
Vector3? position = null,
Vector3? rotation = null,
float? horizon = null,
bool? standing = null,
bool forceAction = false
) {
//non-high level agents cannot set standing
if(standing != null) {
if (standing != null) {
errorMessage = "Cannot set standing for arm/stretch agent";
actionFinishedEmit(success:false, actionReturn:null, errorMessage:errorMessage);
actionFinishedEmit(success: false, actionReturn: null, errorMessage: errorMessage);
return;
}

//cache old values in case there is a failure
Vector3 oldPosition = transform.position;
Quaternion oldRotation = transform.rotation;
Expand All @@ -315,7 +315,7 @@ public override void TeleportFull(
horizon: horizon,
forceAction: forceAction
);

// add arm value cases
if (!forceAction) {
if (Arm != null && Arm.IsArmColliding()) {
Expand All @@ -329,7 +329,6 @@ public override void TeleportFull(
}
base.assertTeleportedNearGround(targetPosition: position);
}

} catch (InvalidOperationException e) {
transform.position = oldPosition;
transform.rotation = oldRotation;
Expand Down
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/DiscreteHidenSeekAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void Update() {
if (wasStanding == true) {
action.action = "Crouch";
PhysicsController.ProcessControlCommand(action);
} else if(wasStanding == false) {
} else if (wasStanding == false) {
action.action = "Stand";
PhysicsController.ProcessControlCommand(action);
}
Expand Down
31 changes: 17 additions & 14 deletions unity/Assets/Scripts/PhysicsRemoteFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,27 +174,30 @@ public void SetMassProperties(string objectId, float mass, float drag, float ang
}

public bool? isStanding() {

//default to not standing if this isn't literally the PhysicsRemoteFPSAgentController
//this means the metadat for isStanding should always be false for all derived classes
if (this.GetType() != typeof(PhysicsRemoteFPSAgentController))
{
if (this.GetType() != typeof(PhysicsRemoteFPSAgentController)) {
return null;
}

//if camera is in neither the standing or crouching predetermined locations, return null
if(UtilityFunctions.ArePositionsApproximatelyEqual(m_Camera.transform.localPosition, standingLocalCameraPosition) == true) {
if (
UtilityFunctions.ArePositionsApproximatelyEqual(
m_Camera.transform.localPosition,
standingLocalCameraPosition
) == true
) {
return true;
}

else if(UtilityFunctions.ArePositionsApproximatelyEqual(m_Camera.transform.localPosition, crouchingLocalCameraPosition) == true) {
} else if (
UtilityFunctions.ArePositionsApproximatelyEqual(
m_Camera.transform.localPosition,
crouchingLocalCameraPosition
) == true
) {
return false;
}

else {
} else {
return null;
}

}

public override MetadataWrapper generateMetadataWrapper() {
Expand Down Expand Up @@ -2343,7 +2346,7 @@ public bool CheckIfItemBlocksAgentStandOrCrouch() {
bool? standState = isStanding();
if (standState == true) {
dir = new Vector3(0.0f, -1f, 0.0f);
} else if (standState == false){
} else if (standState == false) {
dir = new Vector3(0.0f, 1f, 0.0f);
}

Expand Down Expand Up @@ -6374,7 +6377,7 @@ SimObjPhysics sop in GetAllVisibleSimObjPhysics(

if (wasStanding == true) {
stand();
} else if(wasStanding == false){
} else if (wasStanding == false) {
crouch();
}
transform.position = oldPosition;
Expand Down Expand Up @@ -6638,7 +6641,7 @@ public virtual List<Dictionary<string, object>> getInteractablePoses(
// restore old agent pose
if (wasStanding == true) {
stand();
} else if(wasStanding == false) {
} else if (wasStanding == false) {
crouch();
}
SetTransform(
Expand Down
32 changes: 7 additions & 25 deletions unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public IEnumerator TestThirdPartyCameraMetadataReturn()
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.z,
30.0000000000f
);
Assert.AreEqual(result, true);
Assert.AreEqual(result, true);
Assert.AreEqual(metadata.thirdPartyCameras[0].parentObjectName, "");
action.Clear();

Expand Down Expand Up @@ -611,50 +611,32 @@ public IEnumerator TestThirdPartyCameraMetadataReturn()
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraPosition
.x,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.x,
1.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraPosition
.y,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.y,
2.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraPosition
.z,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraPosition.z,
3.0000020000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraRotation
.x,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.x,
20.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraRotation
.y,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.y,
20.0000000000f
);
Assert.AreEqual(result, true);
result = Mathf.Approximately(
metadata
.thirdPartyCameras[0]
.parentRelativeThirdPartyCameraRotation
.z,
metadata.thirdPartyCameras[0].parentRelativeThirdPartyCameraRotation.z,
20.0000000000f
);
Assert.AreEqual(result, true);
Expand Down

0 comments on commit 1b9a986

Please sign in to comment.