Create Top-Down Map of Unreal Engine Scene
3-D scenes developed for the Unreal Engine® simulation environment can be large and complex. Using the Unreal® Editor, you can create a 2-D, top-down map of the scene to get a big-picture view of your scene. You can also use this map to select waypoints of vehicles traveling along a path in your scene.
To create your 2-D map, first capture a high-resolution screenshot of your 3-D scene from a top-down perspective.
Open the Unreal Editor from a Simulink® model that is configured to co-simulate with the Unreal Editor. For more details, see Customize Scenes Using Simulink and Unreal Editor.
Open your scene in the Unreal Editor.
Switch to a top-down view of the scene. In the top-left corner of the editing window, click Perspective, and then click Top.
Verify that the scene is lit by the standard lighting. In the top-left corner of the editing window, click Lit.
Open the control panel for taking high-resolution screenshots of the scene. The screenshot acts as a 2-D scene map. In the top-left corner of the editing window, click the down arrow and select High Resolution Screenshot.
In the left corner of the control panel, click Specify the region which will be captured by the screenshot.
Manually select a region of the scene, and then click Take a screenshot.
The Unreal Editor displays a message that the screenshot is saved to a folder in your project. Click the folder location to access the image file. The folder containing screenshots is a path similar to this path:
Convert Screenshot to Map
After you create your high-resolution screenshot, you can convert it to a map by
creating a 2-D spatial referencing object,
imref2d. This object describes the
relationship between the pixels in the image and the world coordinates of the scene. To
use this object to create a map, you must know the X-axis and
Y-axis limits of the scene in world coordinates. For example, in
this code, the scene captured by image
X-coordinates of –80 to 60 meters and
Y-coordinates of –75 to 65 meters.
sceneImage = imread('myScene.png'); imageSize = size(sceneImage); xlims = [-80 60]; % in meters ylims = [-75 65]; % in meters sceneRef = imref2d(imageSize,xlims,ylims);
You can use the scene image and spatial referencing object to select waypoints for vehicles to follow in your scene. For details on this process, see the Select Waypoints for Unreal Engine Simulation example. This code shows helper function calls in that example. These function calls enable you to display your scene and interactively specify waypoints for vehicles to follow. The image shows a sample map and drawn waypoints in blue that are from the example.
helperShowSceneImage(sceneImage, sceneRef); hFig = helperSelectSceneWaypoints(sceneImage, sceneRef);