Document toolboxDocument toolbox

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)

  7. It should look like this

  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

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

  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

  6. Then disable plane in viewport and also in render

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

  1. Repeat process with Buildings so in the end you should see only camera and roads

  2. Select roads and go to material settings

  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

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

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

  1. Change Render Sampling from 64 to 128 or 256

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

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

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


Processing rendered image with Photoshop

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

  2. You should see this

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

  1. Hit apply

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

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

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

  5. Now save it in .jpg format


Processing rendered image with Blender Compositor

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

  2. You will be greeted with similar screen like this

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

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

  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

     

  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

     

  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

     

  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

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

  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.

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

  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

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

  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

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

  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

  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

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

  • 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

     


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

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

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

  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

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