TerraRoad v0.1

Started by aknight0, August 22, 2021, 08:42:29 pm

Previous topic - Next topic

aknight0

Introducing TerraRoad - Terragen roads where you want them!

https://github.com/abe-mart/TerraRoad

I got tired of not being able to control road placement in Terragen, so I cooked up a Python script to help.  TerraRoad combines a heightfield exported from Terragen with an SVG vector path, and produces a new heightfield with the road surface smoothed.  It also exports masks that can be used for shading the road, border, and markings, as well as cut and fill areas.  

The link above has the Python source code, and install instructions.  I believe this should be cross-platform, but I've only tested it on Windows.  

There are some limitations.  This is heightfield and image based, so you're limited in area and resolution unless you want gigantic files.  This is particularly noticeable for closeups of the road lines.  They look decent from far away though.  The script assumes a single road for now, and no crossroads.  

This is early in development, so feedback is welcome and needed.  Don't expect a finished product, bugs are expected at this point!  A good first test would be to see if I've missed any important steps in the install instructions linked above.  I'm open to ideas on how this could be improved as well.  

RoadSampleSmall.jpg RoadFinal_close_small.jpg 4.jpg Lakeside.jpg

WAS

This looks interesting, and probably very useful. I feel like this is the sort of modern functionality Terragen should have in it's package. These little features will add up to really comprehensive world building.

I do have one request: Allow PNG/BMP/TIFF support for images. Though, if I know Python right, that may require then converting the formats to SVG anyway. I know I have SVG support in CS5 but not my older Photoshop.

PS; May I add this resource to the Terragen resource listing on NWDA?

aknight0

Sure, feel free to add to your list, though like I said before, active development is in progress, so no guarantee of functionality at this point.

I'm using the Imageio library for image import and export, so any of these formats should be possible.  The road shape is a little trickier.  It's important that it's in a vector format rather than a bitmap, because I'm using the svgpathtools library to load in the road path and calculate the normals and offsets that define the road and shoulder.  My intention is that people would use the pen tool in Photoshop or similar to draw a spline over the terrain where the road should go.  

On a side-note if you haven't checked out Affinity Photo yet I'd highly recommend it.  I switched over a while back and have rarely missed Photoshop at all, which is awesome considering the price.  I've been using it to make my .svgs.

Dune

Good that you take it off the alpha part. You'll get a lot more feedback I guess. I still didn't have time to try it, sorry.

WAS

I tried to install it, but I got a few warnings and error with the prerequisites which I don't understand, though It's late here.

PS I do have Affinity Photo, but always forget. Lol I also, am embarrassed to say, I still have yet to fully grasp the pen tool. Lol Like people always use the pen tool to cut out things. I painstakingly use the polygon lasso tool with the pixel ruler. Lol

Quote from: pip outputWARNING: The script f2py.exe is installed in 'C:\Users\WAS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts lsm2bin.exe, tiff2fsspec.exe, tiffcomment.exe and tifffile.exe are installed in 'C:\Users\WAS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts imageio_download_bin.exe and imageio_remove_bin.exe are installed in 'C:\Users\WAS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\WAS\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\sklearn\\datasets\\tests\\data\\openml\\292\\api-v1-json-data-list-data_name-australian-limit-2-data_version-1-status-deactivated.json.gz'

WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the 'C:\Users\WAS\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe -m pip install --upgrade pip' command.

aknight0

August 23, 2021, 11:32:59 am #5 Last Edit: August 23, 2021, 12:00:16 pm by aknight0
Thanks for testing.  The warnings aren't a problem, it should still run fine, and you can suppress them with the suggestions it gives if desired.

The scikit-learn error is a problem.  It looks like the package hits Window's default 260 character path limit.  https://github.com/scikit-learn/scikit-learn/issues/19306.  You can remove the limit in Windows 10: https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/.  That's an annoying extra step for everyone to do though, so I'll probably try to remove the dependence on scikit-learn.  I think I only use it once in the code, because I was too lazy to write my own function to scale numbers between 0-1 Lol.  Should be pretty easy to swap out.

I haven't used the pen much before this either, but the pen skill level required for road drawing isn't too bad.  I found in Affinity at least you can select the pen, then click the little 'Smart Mode' button towards the top, then click a few times.  It auto creates a curve through your points, and you can hold Ctrl to edit.  Then save as svg, and the script uses your curve as the center of the road.  I'll try to make a little getting started video at some point here.

UPDATE:
Just pushed a new version of the code with the scikit-learn dependency removed.

mhaze

Windows 10, python 3.9 installed. Won't start, no error messages.

aknight0

Thanks for testing mhaze.  No error message, and no pop-up window?  And that's from running 'python TerraRoad.py'?  Strange.  I've tested it successfully on a couple of computers, but I'll try it on my wife's laptop later to increase my chances of finding the problem.  I'll try to put up a video tonight as well to show the expected behavior.  

We'll get this ironed out eventually.

WAS

August 23, 2021, 02:21:53 pm #8 Last Edit: August 23, 2021, 02:25:56 pm by WAS
I got the latest version to work, though I needed to install 3 of the dependencies that already were installed. Lol No clue.


To run the software (from my desktop) I just did the following (first step is unnecessary for pretty much any other Windows OS; I have CMD customized):
C:
cd Users\WAS\Desktop\TerraRoad-main
python TerraRoad.py

which through the traceback let me know any problems I needed to fix.

WAS

Ok. I guess I need more help... do you have a tutorial for creating paths that are equal in width? I have no clue what I'm doing, and the pen tool just acts as a lasso tool when you go to fill it or mask with it.

aknight0

Quote from: WAS on August 23, 2021, 02:21:53 pmI got the latest version to work, though I needed to install 3 of the dependencies that already were installed. Lol No clue.


To run the software (from my desktop) I just did the following (first step is unnecessary for pretty much any other Windows OS; I have CMD customized):
C:
cd Users\WAS\Desktop\TerraRoad-main
python TerraRoad.py

which through the traceback let me know any problems I needed to fix.
And we have a winner!   ;D  First successful launch is a good first step!

Quote from: WAS on August 23, 2021, 02:59:06 pmOk. I guess I need more help... do you have a tutorial for creating paths that are equal in width? I have no clue what I'm doing, and the pen tool just acts as a lasso tool when you go to fill it or mask with it.
So actually all you need is the line in your first picture.  The .svg defines where the road should go, and then TerraRoad basically applies a 'stroke' to it to give it width.  You should be able to just take what you had in your first picture and export it as an svg.  I've been disabling the background first, but I don't know if that's necessary, I'll have to test. 

I think it will work with the road extending outside the terrain boundary, but I haven't tested that yet, so if it gives trouble try bringing the whole path inside the borders.

WAS

Thanks for the quick response! All making sense to me now. Will hopefully return with an example image.

PS I added this tool to the resources' page on NWDA under Terragen: https://nwdagroup.com/resources/

mhaze

WAS tried your method but was told that python is not recognised as a command!

aknight0

I recorded a quick video walkthrough that I'll try to upload today.  

In the meantime try running just 'python' from the command line.  If it doesn't print out something about Python, your Python install either isn't set up right, or is set up differently than we're expecting.  

WAS and I have been working through some separate issues trying to export .svg files from Photoshop.  It seems that Photoshop just saves a .png and calls it a .svg, which doesn't work because it isn't actually a vector.  I've had good luck in Affinity so far, but I'll explore some alternatives for creating the spline path as well.

mhaze

Interseting - python is recognised by the system. If it's any help when I run the program a box flashes up and immediately disapears.