Skip to content

Commit

Permalink
Merge pull request #814 from allenai/tmapView
Browse files Browse the repository at this point in the history
Top-Down Image Frame Updates
  • Loading branch information
mattdeitke authored Jul 9, 2021
2 parents e8bf86e + 07ac69f commit ec298b9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 24 deletions.
92 changes: 69 additions & 23 deletions unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3154,18 +3154,16 @@ public void SetTopLevelView(bool topView = false) {
actionFinished(true);
}

[ObsoleteAttribute(message: "This action is deprecated. Use GetMapViewCameraProperties with a third party camera instead.", error: false)]
public void ToggleMapView() {
SyncTransform[] syncInChildren;

List<StructureObject> structureObjsList = new List<StructureObject>();
StructureObject[] structureObjs = FindObjectsOfType(typeof(StructureObject)) as StructureObject[];
StructureObject ceiling = null;

foreach (StructureObject structure in structureObjs) {
switch (structure.WhatIsMyStructureObjectTag) {
case StructureObjectTag.Ceiling:
ceiling = structure;
goto case StructureObjectTag.LightFixture;
case StructureObjectTag.LightFixture:
case StructureObjectTag.CeilingLight:
structureObjsList.Add(structure);
Expand Down Expand Up @@ -3201,34 +3199,82 @@ public void ToggleMapView() {
lastLocalCameraPosition = m_Camera.transform.localPosition;
lastLocalCameraRotation = m_Camera.transform.localRotation;

Bounds b;
if (ceiling != null) {
// There's a ceiling component in the room!
// Let's use it's bounds. (Likely iTHOR.)
b = ceiling.GetComponent<Renderer>().bounds;
} else {
// There's no component in the room!
// Let's use the bounds from every object. (Likely RoboTHOR.)
b = new Bounds();
b.min = agentManager.SceneBounds.min;
b.max = agentManager.SceneBounds.max;
}
float midX = (b.max.x + b.min.x) / 2.0f;
float midZ = (b.max.z + b.min.z) / 2.0f;
m_Camera.transform.rotation = Quaternion.Euler(90.0f, 0.0f, 0.0f);
m_Camera.transform.position = new Vector3(midX, b.max.y + 5, midZ);
m_Camera.orthographic = true;
var cameraProps = getMapViewCameraProperties();
m_Camera.transform.rotation = Quaternion.Euler((Vector3)cameraProps["rotation"]);
m_Camera.transform.position = (Vector3)cameraProps["position"];
m_Camera.orthographic = (bool)cameraProps["orthographic"];
m_Camera.orthographicSize = (float)cameraProps["orthographicSize"];

m_Camera.orthographicSize = Math.Max((b.max.x - b.min.x) / 2f, (b.max.z - b.min.z) / 2f);

cameraOrthSize = m_Camera.orthographicSize;
foreach (StructureObject so in structureObjsList) {
UpdateDisplayGameObject(so.gameObject, false);
}
}
actionFinished(true);
}

protected Dictionary<string, object> getMapViewCameraProperties() {
StructureObject[] structureObjs = FindObjectsOfType(typeof(StructureObject)) as StructureObject[];
StructureObject ceiling = null;

if (structureObjs != null) {
StructureObject ceilingStruct = null;
foreach (StructureObject structure in structureObjs) {
if (
structure.WhatIsMyStructureObjectTag == StructureObjectTag.Ceiling
&& structure.gameObject.name.ToLower().Contains("ceiling")
) {
ceiling = structure;
break;
} else if (structure.WhatIsMyStructureObjectTag == StructureObjectTag.Ceiling) {
ceilingStruct = structure;
}
}

if (ceiling == null) {
ceiling = ceilingStruct;
}
}

Bounds b;
float yValue;
if (ceiling != null) {
// There's a ceiling component in the room!
// Let's use it's bounds. (Likely iTHOR.)
b = ceiling.GetComponent<Renderer>().bounds;
yValue = b.min.y;
} else {
// There's no component in the room!
// Let's use the bounds from every object. (Likely RoboTHOR.)
b = new Bounds();
b.min = agentManager.SceneBounds.min;
b.max = agentManager.SceneBounds.max;
yValue = b.max.y;
}
float midX = (b.max.x + b.min.x) / 2f;
float midZ = (b.max.z + b.min.z) / 2f;

// solves an edge case where the lowest point of the ceiling
// is actually below the floor :0
var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
if (sceneName == "FloorPlan309_physics") {
yValue = 2f;
}

return new Dictionary<string, object>() {
["position"] = new Vector3(midX, yValue, midZ),
["rotation"] = new Vector3(90, 0, 0),
["orthographicSize"] = Math.Max((b.max.x - b.min.x) / 2f, (b.max.z - b.min.z) / 2f),
["orthographic"] = true
};
}

public void GetMapViewCameraProperties() {
actionFinishedEmit(
success: true,
actionReturn: getMapViewCameraProperties()
);
}

/*
Get the 2D (x, z) convex hull of a GameObject. See the Get2DSemanticHulls
function for more information.
Expand Down
11 changes: 10 additions & 1 deletion unity/Assets/Scripts/DebugInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void InitializeUserControl() {
SelectPlayerControl();

#if !UNITY_EDITOR
HideHUD();
HideHUD();
#endif
}

Expand Down Expand Up @@ -2189,6 +2189,15 @@ IEnumerator executeBatch(JArray jActions) {
break;
}

// map view props
case "mvp": {
var action = new Dictionary<string, object>() {
["action"] = "GetMapViewCameraProperties"
};
CurrentActiveController().ProcessControlCommand(action);
break;
}

case "fillwine": {
ServerAction action = new ServerAction();
action.action = "FillObjectWithLiquid";
Expand Down

0 comments on commit ec298b9

Please sign in to comment.