allenai / ai2thor

An open-source platform for Visual AI.
http://ai2thor.allenai.org
Apache License 2.0
1.12k stars 215 forks source link

Questions about editing the scene in Unity. #1014

Open zhaoliangzhang opened 2 years ago

zhaoliangzhang commented 2 years ago

Hi, I tried editing scenes in Unity, and I copied a new object(a tomato) then place it on the table. I had the GameMenu/SettlePhysics done, and added the new object to the lists of PhysicsSceneManager. After built, I am able to pick up the copied object, and the isPickedUp attribute is also set to 'True', seems everything goes well. However, if I set the renderInstanceSegmentation as 'True' at the initialization of controller, then the simulator would crash, the error messages as follows:

Traceback (most recent call last): File "iThorTest.py", line 13, in controller = Controller( File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/controller.py", line 557, in init event = self.reset(scene) File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/controller.py", line 693, in reset self.last_event = self.step( File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/controller.py", line 938, in step self.last_event = self.server.receive() File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/fifo_server.py", line 184, in receive return self.create_event(metadata, files) File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/server.py", line 543, in create_event image_mappingkey File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/server.py", line 434, in add_image_ids self.process_colors_ids() File "/home/zzl/.local/lib/python3.8/site-packages/ai2thor/server.py", line 276, in process_colors_ids unique_inverse = unique_inverse.reshape( ValueError: cannot reshape array of size 120000 into shape (300,300)

Did I miss something in Unity settings?

mattdeitke commented 2 years ago

Hi @zhaoliangzhang,

Can you try installing AI2-THOR with:

pip install --extra-index-url https://ai2thor-pypi.allenai.org ai2thor==0+49e43435d7bd8ced304dbb6bc24e8485ef3e3f43

This upgrades to the latest commit on main (which is currently unreleased), and should fix the issue :)

zhaoliangzhang commented 2 years ago

Hi @mattdeitke, I install the recommended version and the simulator runs well, thanks a lot!

And I also want a larger scene in AI2-THOR, so I tried extending them. The very first step I take is removing the door of the room because I notice that the rooms are all closed. After removing the door and I test the modified scene in python. I found that the event.metadata["actionReturn"] turns to None, and I cannot get the navigable points in the scene. I also copied the floor of the room and place it next to the origin one(in this scene, the door is not removed), but I am just able to get the navigable points on the origin floor instead on the newly added one.

How can I fix that?

mattdeitke commented 2 years ago

Hmm, can you share the error message you're obtaining?

Try printing:

print(controller.step(action="GetReachablePositions")
zhaoliangzhang commented 2 years ago

The messages:

<ai2thor.server.Event at 0x7fcae9b82400 .metadata["lastAction"] = GetReachablePositions .metadata["lastActionSuccess"] = False .metadata["errorMessage"] = "InvalidOperationException: In FloorPlan10_physics, position (-3.0, 0.9, 3.3) can be reached via capsule cast but is beyond the scene bounds. .metadata["actionReturn"] = None

Traceback (most recent call last): File "get_navigable_points.py", line 44, in for point in p1: TypeError: 'NoneType' object is not iterable

Line42-44:

p1 = controller.step(action="GetReachablePositions").metadata["actionReturn"]
for point in p1:
    plt.scatter(x=point["x"], y=point["z"], marker='o')
winthos commented 2 years ago

This error message is due to the GetReachablePositions check as part of initialization being unbounded by the room. When the door is removed, the raycasts used for this check "escape" the bounds of the room and give this error.

It is not enough to copy the floor of the room so that there is space for an agent to stand once it has gone through the door, it also needs enclosed walls so that it can't fall out of bounds and so this reachable positions check doesn't fail.

zhaoliangzhang commented 2 years ago

Yes, it appears to be the issue of opening environment, the reachable points appear after fixing it. Thanks for help!

But I am still meet two problems: The first is trying to add objects in the scene, it seems that there is no source materials in assets of the project, I have to copy an object which is not in current scene from other scenes. Is there a convenient way to add objects? The second problem is trying to combine two scenes together. For example, I copied FloorPlan15 to the scene of FloorPlan11, and tried putting them together. But after doing that, I could only get the reachable points of FloorPlan11 without FloorPlan15. I wonder that if there some way I can put the materials like floor, window, ceiling from assets resources.

winthos commented 2 years ago

The first is trying to add objects in the scene, it seems that there is no source materials in assets of the project, I have to copy an object which is not in current scene from other scenes. Is there a convenient way to add objects?

The first thing to know is that there are sort of two broad categories of "objects" that you can put into a scene. Some are structural objects. These are objects that have a renderer and collision within a scene, but do not report back metadata like a Sim Object. These are always to be put in the Structure game object found in the Hierarchy of a scene.

The other type of object are Sim Objects, which can usually be found as a Unity Prefab in the Asset directory. These objects report back metadata as detailed in our documentation here.

Sim object prefabs can be found in the Assets/Physics/SimObjsPhysics directory. This directory is further split into room categories, for example Bedroom Objects contain objects that are likely to be found in bedrooms, but can be placed in any other scene if desired. You want to go into these directories until you find the Prefab folder, for example something like Assets/Physics/SimObjsPhysics/BedroomObjects/AlarmClock/Prefabs which will then show you all the .prefab files that are the game objects to be placed in a scene.

There are a small subset of sim objects that are not currently prefabs, and only exist as a fully set up object within the scene that they exist in. Some examples of this are the window objects that are custom fit to be placed in specific scenes. These cannot be found in the asset directory, and must be copied and pasted from their origin scene if you wanted to duplicate them into another scene.

The second problem is trying to combine two scenes together. For example, I copied FloorPlan15 to the scene of FloorPlan11, and tried putting them together.

If you were to just copy one scene into another, it will likely not work immediately without some further setup. The first thing you should do is ensure that when copying a scene, you do not copy the FPSController, DebugCanvasPhysics, and the PhysicsSceneManager game objects in the object heirarchy of a scene to the new scene. ONLY the Objects the Lighting, and the Structure should be copied over to the new scene. This is because the controller, canvas, and scene manager objects require only a single instance of them to exist within a scene, otherwise it will likely not work.

Screenshot 2022-04-25 150109

Additionally, there should only be one instance of the Structure, Objects, and Lighting in a scene, so after copying them over to a new scene, you will need to move all child objects under each of the Structure, Objects and Lighting objects into the original Structure, Obects, and Lighting of the scene so all child objects are contained only under a single instance of each of those three. Delete the extra copied over parent objects as well once this is done.

You will also need to make sure that you remove an appropriate doorway between the first and second rooms, as there is nothing linking the two rooms together by default. You will need to line up the rooms such that an open doorway, clear of the door object, can connect the two rooms so the agent can move between them. You may even need to add some extra primitive colliders or geometry to make sure there are no gaps on the floor and the agent doesn't fall through the opening where the two doors meet.

Finally, you will need to setup the PhysicsSceneManager to reference all sim objects in the scene correctly, so make sure any added sim objects are included in the RequiredObjects and the SpawnedObjects arrays on that component.