Skip to content

Commit

Permalink
merge nanna-release-api to naive-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdeitke committed Sep 29, 2022
2 parents 281b26a + 51871f8 commit c9833a5
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 110 deletions.
Binary file modified ai2thor/tests/data/procedural/proc_rgb_lit_fifo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
136 changes: 70 additions & 66 deletions ai2thor/tests/test_unity_procedural.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# import pytest
import json
import os
import pytest

import cv2
import numpy as np
from ai2thor.wsgi_server import WsgiServer
import pytest

from ai2thor.fifo_server import FifoServer
from .test_unity import build_controller, images_near, depth_images_near
import cv2
from ai2thor.wsgi_server import WsgiServer

from .test_unity import build_controller, depth_images_near, images_near

DATA_PATH = "ai2thor/tests/data/"
IMAGE_FOLDER_PATH = os.path.join(DATA_PATH, "procedural")
Expand All @@ -18,7 +22,7 @@
width=300,
height=300,
fieldOfView=45,
agentCount=1
agentCount=1,
)

_wsgi_controller = dict(server_class=WsgiServer, **shared_args)
Expand All @@ -28,12 +32,14 @@
wsgi = [_wsgi_controller]
fifo = [_fifo_controller]


def create_pixel_diff_image(img, g_truth):
dx = np.where(~np.all(g_truth == img, axis=-1))
copy = img.copy()
copy[dx] = (255, 0, 255)
return copy


house_template = {
"id": "house_0",
"layout": """
Expand All @@ -59,98 +65,92 @@ def create_pixel_diff_image(img, g_truth):
"wallTemplate": {
"material": {
"unlit": False,
"color": {
"r": 1.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
"color": {"r": 1.0, "g": 0.0, "b": 0.0, "a": 1.0},
}
},
"floorTemplate": {
"roomType": "Bedroom",
"floorMaterial": { "name": "DarkWoodFloors" },
"floorMaterial": {"name": "DarkWoodFloors"},
},
"floorYPosition": 0.0,
"wallHeight": 3.0
"wallHeight": 3.0,
},
"2": {
"wallTemplate": {
"material": {
"unlit": False,
"color": {
"r": 0.0,
"g": 0.0,
"b": 1.0,
"a": 1.0
}
"color": {"r": 0.0, "g": 0.0, "b": 1.0, "a": 1.0},
}
},
"floorTemplate": {
"roomType": "LivingRoom",
"floorMaterial": { "name": "RedBrick"}
"floorMaterial": {"name": "RedBrick"},
},
"floorYPosition": 0.0,
"wallHeight": 3.0
}
},
"holes": {
"=": {
"room0": "1",
"openness": 1.0,
"assetId": "Doorway_1"
}
},
"objects": {
"+": {
"kinematic": True,
"assetId": "Chair_007_1"
}
"wallHeight": 3.0,
},
},
"holes": {"=": {"room0": "1", "openness": 1.0, "assetId": "Doorway_1"}},
"objects": {"+": {"kinematic": True, "assetId": "Chair_007_1"}},
"proceduralParameters": {
"floorColliderThickness": 1.0,
"receptacleHeight": 0.7,
"skyboxId": "Sky1",
"ceilingMaterial": { "name": "ps_mat" }
}

"ceilingMaterial": {"name": "ps_mat"},
},
"schema": "1.0.0",
}

# TODO rendering is different for fifo and wsgi server
@pytest.mark.parametrize("controller_args", fifo)
@pytest.mark.skip(reason="blocking current work")
def test_render_lit(controller_args):
print("Args")
print(controller_args)
controller = build_controller(
**controller_args
)
controller = build_controller(**controller_args)

rgb_filename = "proc_rgb_lit_fifo.png"
ground_truth = cv2.imread(os.path.join(IMAGE_FOLDER_PATH, rgb_filename))

evt = controller.step(
action="GetHouseFromTemplate",
template=house_template
)
evt = controller.step(action="GetHouseFromTemplate", template=house_template)

print("Action success {0}, message {1}".format(evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]))
print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
house = evt.metadata["actionReturn"]

controller.step(
action="CreateHouse",
house=house
with open("test_render_lit.json", "w") as f:
print(house)
json.dump(house, f)

evt = controller.step(action="CreateHouse", house=house)

print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"]

evt = controller.step(
action="TeleportFull", x=3.0, y=0.9010001, z=1.0, rotation=dict(x=0, y=0, z=0),
horizon=0, standing=True, forceAction=True
action="TeleportFull",
x=3.0,
y=0.9010001,
z=1.0,
rotation=dict(x=0, y=0, z=0),
horizon=0,
standing=True,
forceAction=True,
)

controller.stop()

assert images_near(evt.cv2img, ground_truth, max_mean_pixel_diff=52, debug_save=True)
assert images_near(
evt.cv2img, ground_truth, max_mean_pixel_diff=52, debug_save=True
)


#
# @pytest.mark.parametrize("controller_args", wsgi)
Expand All @@ -172,36 +172,40 @@ def test_render_lit(controller_args):
# assert depth_images_near(server_image, raw_depth, epsilon=2e-1, debug_save=True)



@pytest.mark.parametrize("controller_args", fifo)
def test_depth(controller_args):
controller_args.update(
renderDepthImage=True,
)

controller = build_controller(
**controller_args
)
controller = build_controller(**controller_args)

depth_filename = "proc_depth.npy"
raw_depth = np.load(os.path.join(IMAGE_FOLDER_PATH, depth_filename))

evt = controller.step(
action="GetHouseFromTemplate",
template=house_template
)
evt = controller.step(action="GetHouseFromTemplate", template=house_template)

assert evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
house = evt.metadata["actionReturn"]

controller.step(
action="CreateHouse",
house=house
evt = controller.step(action="CreateHouse", house=house)

print(
"Action success {0}, message {1}".format(
evt.metadata["lastActionSuccess"], evt.metadata["errorMessage"]
)
)
assert evt.metadata["lastActionSuccess"]

evt = controller.step(
action="TeleportFull", x=3.0, y=0.9010001, z=1.0, rotation=dict(x=0, y=0, z=0),
horizon=0, standing=True, forceAction=True
action="TeleportFull",
x=3.0,
y=0.9010001,
z=1.0,
rotation=dict(x=0, y=0, z=0),
horizon=0,
standing=True,
forceAction=True,
)

controller.stop()
Expand Down
17 changes: 1 addition & 16 deletions unity/Assets/Scenes/Procedural/Procedural.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4975387, g: 0.5876736, b: 0.7671069, a: 1}
m_IndirectSpecularColor: {r: 0.49752694, g: 0.5876213, b: 0.76683104, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -1105,7 +1105,6 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 2102304081}
- component: {fileID: 2102304080}
- component: {fileID: 2102304082}
- component: {fileID: 2102304083}
m_Layer: 0
Expand All @@ -1115,20 +1114,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2102304080
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2102304079}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d2f52a53641cf447b8e93cd67654976c, type: 3}
m_Name:
m_EditorClassIdentifier:
floorMesh: {fileID: 0}
floorMaterial: {fileID: 2100000, guid: 9554c30067d9e4b40a657e538d755129, type: 2}
--- !u!4 &2102304081
Transform:
m_ObjectHideFlags: 0
Expand Down
3 changes: 2 additions & 1 deletion unity/Assets/Scripts/BaseFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4793,7 +4793,8 @@ public void CreateHouse(ProceduralHouse house) {
ProceduralTools.CreateHouse(house: house, materialDb: materials);
}
catch (Exception e) {
var msg = $"Exception creating house.\n'{e.Message}'\n'{e.InnerException.Message}'";
Debug.Log(e);
var msg = $"Exception creating house.\n'{e.Message}'\n'{e.InnerException}'";
Debug.Log(msg);
actionFinished(false, actionReturn: null, errorMessage: msg);
return;
Expand Down
9 changes: 4 additions & 5 deletions unity/Assets/Scripts/ProceduralData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class Door : WallRectangularHole {
public bool openable { get; set; }
public float openness { get; set; } = 0.0f;
public string assetId { get; set; }

public MaterialProperties material { get; set; }
public Vector3? scale { get; set; } = null;
public SerializableColor color { get; set; } = null;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public class PolygonWall {
public string roomId { get; set; }
public float thickness { get; set; }
public string layer { get; set; }
public MaterialProperties material;
public MaterialProperties material { get; set; }
public bool empty { get; set; } = false;
public bool unlit;
}
Expand Down Expand Up @@ -258,7 +258,7 @@ public class Window : WallRectangularHole {
public List<VectorXZ> axesXZ { get; set; }
public string type { get; set; }
public string assetId { get; set; }

public MaterialProperties material { get; set; }
public Vector3? scale { get; set; } = null;
public SerializableColor color { get; set; } = null;
}
Expand Down Expand Up @@ -359,7 +359,6 @@ public class HouseObject {
public bool? isDirty { get; set; } = null;

public bool unlit;
public SerializableColor color { get; set; } = null;
public MaterialProperties material;
}

Expand Down Expand Up @@ -427,7 +426,7 @@ public interface WallRectangularHole {
float openness { get; set; }

Vector3? scale { get; set; }
SerializableColor color { get; set; }
MaterialProperties material { get; set; }
}

[Serializable]
Expand Down
2 changes: 1 addition & 1 deletion unity/Assets/Scripts/ProceduralTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public static ProceduralHouse createHouseFromTemplate(
};

return new ProceduralHouse() {
metadata = metadata,
metadata = new HouseMetadata() { schema=houseTemplate.schema },
proceduralParameters = houseTemplate.proceduralParameters.DeepClone(),
id = !string.IsNullOrEmpty(houseTemplate.id) ? houseTemplate.id : houseId(),
rooms = roomsWithWalls.Select(p => p.room).ToList(),
Expand Down
Loading

0 comments on commit c9833a5

Please sign in to comment.