Skip to content

Commit 2e45a50

Browse files
authored
Merge pull request #814 from aburgm/turn-off-segmentation
Allow to unset segmentation object ID
2 parents c86c341 + 389de38 commit 2e45a50

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,45 @@ void UAirBlueprintLib::InitializeObjectStencilID(T* mesh, bool ignore_existing)
167167
template<typename T>
168168
void UAirBlueprintLib::SetObjectStencilID(T* mesh, int object_id)
169169
{
170-
mesh->SetCustomDepthStencilValue(object_id);
171-
mesh->SetRenderCustomDepth(true);
170+
if (object_id < 0)
171+
{
172+
mesh->SetRenderCustomDepth(false);
173+
}
174+
else
175+
{
176+
mesh->SetCustomDepthStencilValue(object_id);
177+
mesh->SetRenderCustomDepth(true);
178+
}
172179
//mesh->SetVisibility(false);
173180
//mesh->SetVisibility(true);
174181
}
175182

176183
void UAirBlueprintLib::SetObjectStencilID(ALandscapeProxy* mesh, int object_id)
177184
{
178-
mesh->CustomDepthStencilValue = object_id;
179-
mesh->bRenderCustomDepth = true;
185+
if (object_id < 0)
186+
{
187+
mesh->bRenderCustomDepth = false;
188+
}
189+
else
190+
{
191+
mesh->CustomDepthStencilValue = object_id;
192+
mesh->bRenderCustomDepth = true;
193+
}
180194

181195
// Explicitly set the custom depth state on the components so the
182196
// render state is marked dirty and the update actually takes effect
183197
// immediately.
184198
for (ULandscapeComponent* comp : mesh->LandscapeComponents)
185199
{
186-
comp->SetCustomDepthStencilValue(object_id);
187-
comp->SetRenderCustomDepth(true);
200+
if (object_id < 0)
201+
{
202+
comp->SetRenderCustomDepth(false);
203+
}
204+
else
205+
{
206+
comp->SetCustomDepthStencilValue(object_id);
207+
comp->SetRenderCustomDepth(true);
208+
}
188209
}
189210
}
190211

docs/image_apis.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ The return value is boolean type that lets you know if the mesh was found.
209209
Notice that typical Unreal environment like Blocks usually have many other meshes that comprises of same object, for example, "Ground_2", "Ground_3" and so on. As it is tedious to set object ID for all of these meshes, AirSim also supports regular expressions. For example, below code sets all meshes which have names starting with "ground" (ignoring case) to 21 with just one line:
210210

211211
```
212-
success = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
212+
success = client.simSetSegmentationObjectID("ground[\w]*", 21, True);
213213
```
214214

215215
The return value is true if at least one mesh was found using regular expression matching.
@@ -229,6 +229,9 @@ print(np.unique(img_rgba[:,:,2], return_counts=True)) #blue
229229

230230
A complete ready-to-run example can be found in [segmentation.py](https://github.com/Microsoft/AirSim/blob/master/PythonClient/segmentation.py).
231231

232+
#### Unsetting object ID
233+
An object's ID can be set to -1 to make it not show up on the segmentation image.
234+
232235
#### How to Find Mesh Names?
233236
To get desired ground truth segmentation you will need to know names of the meshes in your Unreal environment that you are interested in. To do this, you will need to open up Unreal Environment in Unreal Editor and then inspect the names of the meshes you are interested in the World Outliner. For example, below we see the meshe names for he ground in Blocks environment in right panel in the editor:
234237

0 commit comments

Comments
 (0)