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 - Download — blender.org
Blender part 1
Download Distance field map (Photoshop file)
Make sure that you have Photoshop installed or get it from official website (Trial version will be fine)
If you followed previous associated tutorial you should end up similar scene like that
Create blank plane and scale it roughly little less than size of surroundings
Make sure that plane is at 0 Z axies
Center plane with your model. (Your model should be roughly centered in the plane)
It should look like this
Next step is to add camera into the scene. You can do this with shift+a and choose camera
Set camera from perspective to orthographic
Make sure you have camera selected
Split screens via draging left side of the viewport to the right side and then press 0 to see camera view
Press shortcut N to bring right side panel and reset camera Position and Rotation to 0
Move camera higher than any mesh in Z axis
Change camera resolution to 4096 x 4096. Camera should be in square shape instead of 16:9 ratio
Change orthographic scale so you roughly see little less than size of plane and center camera with plane
Then disable plane in viewport and also in render
If you cannot see all those disable icons, you can enable them here bellow
Repeat process with Buildings so in the end you should see only camera and roads
Select roads and go to material settings
If you have more than one material, delete all of them and create new with Roads name
Click on Principled BSDF and change material type to Emission
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
Change Render Sampling from 64 to 128 or 256
Head to Color Management settings on the bottom and change View Transform from Filmic to Standard
Now press F12 to render image. You should get this result
Than save image in .png format (So we have transparent background)
Processing rendered image with Photoshop
Now locate downloaded Distance field map sample project and open it in Photoshop
You should see this
Locate your rendered image of roads from Blender and drag and drop it into the Photoshop
Hit apply
In the right side panel where Layers are located move imported tutorial osm map under Render group folder
Your image should change from clear image into the blurry image
Don’t worry that’s exactly what we wanted because this is a Distance field map
Now save it in .jpg format
Processing rendered image with Blender Compositor
After you rendered .png image, you need to open Compositing workspace located at the top bar
You will be greeted with similar screen like this
At the top left bar, enable Use Nodes option
Now you will see this 2 nodes - Render Layers and Composite
Click on the Render Layers and drag it further apart from each other, just to make space for additional nodes
Unplug Render Layers node from Composite node by holding CTRL or COMMAND (on MAC device) and draw a crossing line with right mouse button
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
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
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
In second Dilate/Erode node we do the same but we change Distance value to negative 40
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.
Now everything should look like this (Image in Render Layers node bellow is different than yours. That's absolutely okay)
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.
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
Head back to blender and enable Plane and rename it to the Base
Create new material for plane called Base road map
On the left side change viewport mode to Shader Editor
Drag and drop saved image from Photoshop into the Shader Editor in Blender
Connect Image texture color with Base color in Principled BSDF
If we switch to Material view in Blender, you can see that Distance field map doesn’t match with roads
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
Now if head back to Material view in Blender we can see that everything match perfectly
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
We need to export only surroundings as separate file. If you also have additional models included, you need to exclude them from export.
Make sure that you have selected only surroundings and nothing else
Than head to File - Export and choose FBX as a output file format
Choose your desired export location and make sure that you have settings bellow exactly the same
Explanation to export settings:
Limit to - Selected Objects (It will export only selected objects)
Apply Scalings - FBX Units Scale (It will apply current scaling into the FBX)
Use Space Transform (It will apply global space transform to the object rotation)
Apply Modifiers (If your model has unapplied modifiers, it will automatically apply them during export)
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