Jump to content

Leadwerks Road To Terrain Snapper (With Source!)


gamecreator
 Share

Recommended Posts

Leadwerks Road To Terrain Snapper (with source code)

I decided to write this tool after seeing a few members inquiring about roads in Leadwerks.  I thought it might be easy to code and a good way to stretch my coding muscles as a break from game coding.

The tool uses the information you provide in settings.txt to locate a map file and a road file and allows you to move and rotate the road on the terrain until you find a place you like.  You can then snap the road to it so that every vertex of the road snaps to the terrain below it.  When you quit the program, the program exports an OBJ file you can import into your 3D modeling program.  Unfortunately the program doesn't keep your texturing information but since the source is included, you're welcome to add that in.  The program also keeps track of the position of the road so that when you import it back into Leadwerks, you can type it in to the position boxes to put the road right where you snapped it (you'll probably need to multiply by 100 to match the editor format).

You may be wondering why the road looks bad and the terrain is sticking through it.  This is a combination of two things:
1.  I didn't include any space between the road and the terrain.  You can place the road as high off the ground as you feel is right once you put it back into the editor or your code.
2.  The road in the screenshot is only 180 triangles.  I suggest using more depending on your scene.

The entire project with source code:
http://www.mediafire.com/file/y1743umgg0q75x9/Road_To_Terrain_Snapper_project_and_source.zip

Just the program:
http://www.mediafire.com/file/xhbfy8hn7x5nr5i/Road_To_Terrain_Snapper.zip

Enjoy!

screenshot.png

(The settings.txt file also lets you specify the resolution you would like to run your program at and fullscreen or windowed.)

Thank you to macklebee for his help with this on the forums.

  • Upvote 9
Link to comment
Share on other sites

Great Idea, I miss a lot a Road maker but I think I don't undertand how it works... That's what I obtained as export.obj, but I can't use this as road:

2017-07-20.thumb.png.23ff7520dd8abe5cc6aaaca9bfebcfea.png

 

If the result contains all the curves of the terrain, well that's the same work as it requires the terrain to be smoothed ? Maybe I did not correct use it..

 

 

Link to comment
Share on other sites

9 hours ago, reepblue said:

I'd put the source on a git so people can fork/pull request changes and fixes

I don't use it but you're absolutely welcome to.  No need to credit me in any way.

7 hours ago, Marcousik said:

If the result contains all the curves of the terrain, well that's the same work as it requires the terrain to be smoothed ?

If your terrain is flat/flattened, you won't need this tool.  But if you have roads going up and down hills, I think it may be easier to just snap the road to it instead of trying to adjust the terrain spot by spot.  But I think a combination of the two may be best.

2 hours ago, jen said:

How accurate are the exported roads? Are they 1:1 with the surface the road is patched on on the terrain?

Yes.  There are no adjustments after you snap the terrain.  Vertices are saved as they are.
Edit: correction/clarity: the road is actually lowered uniformly to 0 height so that it's at the origin and that it's not way up in the air when you import it into your modeling program.  However, the vertices will match terrain height exactly.  All you need to do is drag it back up once you import it into the editor.  If you prefer to keep the road at the terrain height during export, you can remove +lowestpoint from the below code.

//  "Subtract" lowestpoint from all vetex heights to put road closer to origin
fprintf(f, "v %f %f %f\n", vpos.x, -vpos.z+lowestpoint, vpos.y);

 

Link to comment
Share on other sites

thanks for sharing this beauty

It remembers me an old technique of making shadows.. by creating a black+alpha mesh that overlaps the terrain/buildings with a small offset, when almost all thing were made by hand!

 

  • Upvote 1

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...