HOW TO INSTALL
Start by downloading the .py file. In Blender, go to Edit > Preferences > Add-ons. Click Install in the top bar, search for the .py file and click Install add-on from file. Then, type "Distance Map" in the search bar. Enable the addon and click Save preferences. You are now able to use the addon!
The Distance Map addon is visible in the Sidebar (hotkey N) > Distance Map. To be able to generate a distance map, select two objects with mesh data. The distance map is built onto the last selected (active) object. The first selected (inactive) object serves as the target object, i.e. the object to which the distance is calculated. NOTE: Modifiers are not applied before calculating the distance map. NOTE: Color and text maps are not updated when an object is transformed after calculating the distance map.
* Generate Distance Map
Generate a distance map of two selected mesh objects. Distance maps are saved under Properties > Object Data Properties > Vertex Colors. In the distance map name, the name of the target object, the raycast method ("Normals" or "Nearest") and maximum distance are included. Select a vertex color map name (not the camera icon) to make it active. Switch to viewport shading "Solid" and shading color "Vertex" to view the active color map in the viewport.
* Raycast Mode
There are two methods to calculate a distance map. The "Normals" mode searches for the shortest distance from the base object to the target object along the vertex normals. Whether a hit was found along the positive or negative normal direction determines the color. If no hit was found, the out of range color is used. The "Nearest" mode searches for the shortest distance to the target object in any direction. The terms "positive" and "negative" are ill-defined in this context, this method therefore only uses the positive color. In contrary to the "Normals" mode, this method yields results for every vertex, as it searches in any direction.
* Normalization Value
The normalization value determines how the colors of the color map are scaled. The distance map colors are normalized according to this value. If set to zero, the color map is normalized using the largest distance that was found and the colors are spaced evenly over the distance map. A small value will produce a color map with concentrated colors, while a larger value will stretch the colors in the color map.
* Positive Color
Color that is used for positive distances.
* Negative Color
Color that is used for negative distances (disabled in "Nearest" mode).
* Out Of Range Color
Color that is used when no raycast hit was found (disabled in "Nearest" mode).
* Show Distances
Display the distances of the active distance map in the viewport. Select the desired object and distance map (Properties > Object Data Properties > Vertex Colors) to view the distance per vertex.
* Font Size
The font size of the distances in the viewport.
The number of decimals of the distances in the viewport.
* Font Color
The font color of the distances in the viewport.
* Export Distances
Export the distances of a distance map to a text file. Select one object and the desired distance map (Properties > Object Data Properties > Vertex Colors). The values can be copied to other software for further analysis. In the text file, row index corresponds to vertex index (both starting at 0). A "nan" value indicates that there was no raycast hit for this vertex.