Skip to content

Commit

Permalink
removing visibilityScheme param from GetVisibleObjects...
Browse files Browse the repository at this point in the history
... to ensure an error is thrown because the local visibilityScheme value is set to the only valid enum at initialization now

also adding a main camera unit test in GetVisibleObjectsFromCamera as previously only the created ThirdPartyCamera was being tested for expected returns
  • Loading branch information
winthos committed Aug 21, 2024
1 parent 93a137f commit 37cce20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
15 changes: 1 addition & 14 deletions unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4562,12 +4562,6 @@ public void GetVisibleObjectsFromCamera(
camera = agentManager.thirdPartyCameras[thirdPartyCameraId.Value];
}

if (this.visibilityScheme != VisibilityScheme.Distance) {
throw new System.NotImplementedException(
$"Visibility scheme {this.visibilityScheme} is not compatible. Visibility scheme should be 'Distance'."
);
}

//only check visibility for objects with these ids otherwise check them all
List<SimObjPhysics> filterSimObjs = null;
if (filterObjectIds != null) {
Expand Down Expand Up @@ -4608,7 +4602,6 @@ public void GetVisibleObjectsFromCamera(
)]
public void GetVisibleObjects(
float? maxDistance = null,
string visibilityScheme = null,
int? thirdPartyCameraIndex = null,
List<string> objectIds = null
) {
Expand All @@ -4621,12 +4614,6 @@ public void GetVisibleObjects(
camera = m_Camera;
}

if (this.visibilityScheme != VisibilityScheme.Distance) {
throw new System.NotImplementedException(
$"Visibility scheme {this.visibilityScheme} is not compatible. Visibility scheme should be 'Distance'."
);
}

List<SimObjPhysics> filterSimObjs = null;
if (objectIds != null) {
foreach (string objectId in objectIds) {
Expand All @@ -4646,7 +4633,7 @@ public void GetVisibleObjects(

visible = GetAllVisibleSimObjPhysicsDistance(
camera: camera,
maxDistance: maxDistance.GetValueOrDefault(this.maxVisibleDistance), // lgtm [cs/dereferenced-value-may-be-null]
maxDistance: maxDistance.GetValueOrDefault(this.maxVisibleDistance),
filterSimObjs: filterSimObjs,
interactable: out interactable
);
Expand Down
26 changes: 26 additions & 0 deletions unity/Assets/UnitTests/TestThirdPartyCameraAndMainCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public IEnumerator TestGetVisibleObjectsFromCamera()

action.Clear();

//testing third party camera return
action["action"] = "GetVisibleObjectsFromCamera";
action["thirdPartyCameraId"] = 0;
yield return step(action);
Expand Down Expand Up @@ -241,7 +242,10 @@ public IEnumerator TestGetVisibleObjectsFromCamera()

visibleObjects.Clear();
visibleObjects = (List<string>)actionReturn;

#if UNITY_EDITOR
Debug.Log($"Checking Visible Objects from ThirdPartyCamera Index 0");
Debug.Log($"Total Visible Objects: {visibleObjects.Count}");
foreach (string obj in visibleObjects)
{
Debug.Log(obj);
Expand All @@ -250,6 +254,28 @@ public IEnumerator TestGetVisibleObjectsFromCamera()

Assert.AreEqual(visibleObjects.Count, 1);
Assert.AreEqual(visibleObjects[0], "Apple|-00.47|+01.15|+00.48");

//Test main camera return
action.Clear();

action["action"] = "GetVisibleObjectsFromCamera";
action["thirdPartyCameraId"] = null; //null ID queries main camera instead
yield return step(action);

visibleObjects.Clear();
visibleObjects = (List<string>)actionReturn;

#if UNITY_EDITOR
Debug.Log($"Checking Visible Objects from Main Camera");
Debug.Log($"Total Visible Objects: {visibleObjects.Count}");
foreach (string obj in visibleObjects)
{
Debug.Log(obj);
}
#endif

Assert.AreEqual(visibleObjects.Count, 4);
Assert.AreEqual(visibleObjects[0], "Cabinet|-01.85|+02.02|+00.38");
}

[UnityTest]
Expand Down

0 comments on commit 37cce20

Please sign in to comment.