/
How to prepare OSM data for Twinzo

How to prepare OSM data for Twinzo

This part is associated with previous tutorial: How to create Surroundings Its essential to look at it first and then follow this tutorial


Distance field map (Photoshop file)


Required software:



Blender part 1

  1. Download Distance field map (Photoshop file)

  2. Make sure that you have Photoshop installed or get it from official website (Trial version will be fine)

  3. If you followed previous associated tutorial you should end up similar scene like that

    image-20240529-121932.png

  4. Create blank plane and scale it roughly little less than size of surroundings

    image-20240529-122004.png

  5. Make sure that plane is at 0 Z axies

  6. Center plane with your model. (Your model should be roughly centered in the plane)

    2023-07-19 14-43-40.mp4
  7. It should look like this

    image-20240529-122106.png

  8. Next step is to add camera into the scene. You can do this with shift+a and choose camera

  9. Set camera from perspective to orthographic

    image-20240529-122131.png

Make sure you have camera selected

  1. Split screens via draging left side of the viewport to the right side and then press 0 to see camera view

    2023-07-19 14-50-19.mp4
  2. Press shortcut N to bring right side panel and reset camera Position and Rotation to 0

  3. Move camera higher than any mesh in Z axis

  4. Change camera resolution to 4096 x 4096. Camera should be in square shape instead of 16:9 ratio

  5. Change orthographic scale so you roughly see little less than size of plane and center camera with plane

    2023-07-19 14-56-22.mp4
  6. Then disable plane in viewport and also in render

    image-20240529-122541.png

If you cannot see all those disable icons, you can enable them here bellow

image-20240529-122605.png
  1. Repeat process with Buildings so in the end you should see only camera and roads

    image-20240529-122649.png

  2. Select roads and go to material settings

    image-20240529-122756.png

  3. If you have more than one material, delete all of them and create new with Roads name

  4. Click on Principled BSDF and change material type to Emission

    image-20240529-122827.png

  5. Next go to Render settings - Film and enable Transparent settings

    image-20240529-122901.png

This makes background transparent so we can export only roads with transparent background in order to create OSM distance field map for later us in Unity

Also make sure to set Filter Size about 1.25 px or 1.50 px to get better result

  1. Change Render Sampling from 64 to 128 or 256

    image-20240529-123016.png

  2. Head to Color Management settings on the bottom and change View Transform from Filmic to Standard

    image-20240529-123042.png

Filmic has slight yellow color shift. That will mess up render later in Photoshop

  1. Now press F12 to render image. You should get this result

    image-20240529-123117.png

If you see more than just roads make sure you disabled in render all object instead of roads

  1. Than save image in .png format (So we have transparent background)

    image-20240529-123213.png

    image-20240529-123258.png


Processing rendered image with Photoshop

This part of the tutorial depends on if you have a Adobe Photoshop installed. If you don't have photoshop installed, then skip this part and head to the Processing rendered image with Blender Compositor

  1. Now locate downloaded Distance field map sample project and open it in Photoshop

  2. You should see this

    image-20240529-123404.png

  3. Locate your rendered image of roads from Blender and drag and drop it into the Photoshop

    image-20240529-123436.png

Make sure that image is scaled exactly same as canvas (If you selected 4096x4096 resolution in Blender it should match automatically)

  1. Hit apply

  2. In the right side panel where Layers are located move imported tutorial osm map under Render group folder

    image-20240529-123458.png

  3. Your image should change from clear image into the blurry image

    image-20240529-123526.png

  4. Don’t worry that’s exactly what we wanted because this is a Distance field map

  5. Now save it in .jpg format

In saving option you can set maximum quality or you can also use other compressing method like Baseline Optimized for a lower final size

image-20240529-123552.png

Processing rendered image with Blender Compositor

Please go through this part of the tutorial only if you don't have a Adobe Photoshop installed

  1. After you rendered .png image, you need to open Compositing workspace located at the top bar

    image-20240529-123618.png

  2. You will be greeted with similar screen like this

    image-20240529-123646.png

  3. At the top left bar, enable Use Nodes option

    image-20240529-123716.png

  4. Now you will see this 2 nodes - Render Layers and Composite

    image-20240529-123736.png

  5. Click on the Render Layers and drag it further apart from each other, just to make space for additional nodes

  6. Unplug Render Layers node from Composite node by holding CTRL or COMMAND (on MAC device) and draw a crossing line with right mouse button

    2023-10-25 11-36-23.mp4

     

  7. Now we need to add 2 nodes between them. Both of them were be Dilate/Erode. You can add them by pressing shift + A and clicking on search and type Dilate

    2023-10-26 13-05-19.mp4

     

  8. Now wee need to connect Render Layers alpha output into the Mask input of the both Dilate/Erode nodes. You can do this via click and drag from output node to the input

    2023-10-26 13-06-22.mp4

     

  9. In first Dilate/Erode node we need to switch mode from Step to Feather. Change Distance value from 0 to 40 and Falloff from Smooth to Linear

    image-20240529-123923.png

  10. In second Dilate/Erode node we do the same but we change Distance value to negative 40

    image-20240529-123948.png

  11. Now we know how to create, modify and connect nodes so we can proceed to adding additional math nodes like Add and Multiply. Make sure that you connected and changed their settings exactly like in image bellow. You can add them by pressing shift + A and clicking on search and type math. Than you need to change their type to Add and Multiply.

    image-20240529-124012.png

  12. Now everything should look like this (Image in Render Layers node bellow is different than yours. That's absolutely okay)

    image-20240529-124109.png

  13. Finally you can again press F12 button and render image again and you will see that suddenly your image is blurry and has a black background which is what we want.

  14. After image is rendered you can save it to JPG file format instead of PNG since we don't need transparent background anymore and image size will be also lower.


Blender part 2

  1. Head back to blender and enable Plane and rename it to the Base

  2. Create new material for plane called Base road map

    image-20240529-124223.png

  3. On the left side change viewport mode to Shader Editor

    image-20240529-124249.png

  4. Drag and drop saved image from Photoshop into the Shader Editor in Blender

  5. Connect Image texture color with Base color in Principled BSDF

    image-20240529-124319.png

  6. If we switch to Material view in Blender, you can see that Distance field map doesn’t match with roads

    2023-07-19 15-50-27.mp4
  7. To fix that we need to press 0 (Camera view) than select plane and go to Edit mode, than choose UV in upper setting panel and select Project from view

    2023-07-19 15-55-05.mp4
  8. Now if head back to Material view in Blender we can see that everything match perfectly

  9. Now we can move road mesh as backup into the another folder and disable it

    2023-07-19 15-57-09.mp4

To keep everything organized please make backup copies and use collection folders with namings

Tips for surroundings optimization

  • You can delete buildings which are outside of plane because in Unity they will be never visible due to Shader settings

    2023-07-19 16-01-37.mp4
  • You can use select random function to deselect and delete buildings because usually there are lots of buildings and we don’t all of them

    2023-07-19 16-02-22.mp4

     


Exporting tips

  1. We need to export only surroundings as separate file. If you also have additional models included, you need to exclude them from export.

  2. Make sure that you have selected only surroundings and nothing else

    image-20240529-124539.png

  3. Than head to File - Export and choose FBX as a output file format

    image-20240529-124616.png

  4. Choose your desired export location and make sure that you have settings bellow exactly the same

    image-20240529-124649.png

    image-20240529-124714.png

  5. Explanation to export settings:

    1. Limit to - Selected Objects (It will export only selected objects)

    2. Apply Scalings - FBX Units Scale (It will apply current scaling into the FBX)

    3. Use Space Transform (It will apply global space transform to the object rotation)

    4. Apply Modifiers (If your model has unapplied modifiers, it will automatically apply them during export)

    5. Make sure that Bake Animation is Off (Since we don't need that for surroundings

Related content

If you encounter any issues or need assistance with using this product, please do not hesitate to reach out for support. Our team is here to help you resolve any problems and answer any questions you may have.
To create a support ticket, visit our support portal at https://partner.twinzo.eu/helpdesk/customer-care-1