[Tutorial] Level Building with LIDAR

Discussion in 'Content Creation' started by Ewanc, Apr 27, 2017.

  1. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Here's my method of getting 3D map data in-game. This method is geared to rFactor's workflow, where its loaded and reoriented in a 3D modeling program first, before going into BeamED

    Ive picked through the emerging LIDAR scene and put together a clear workflow; from acquiring raw data, to importing it into a 3D editor and then into BeamED, all with very high accuracy. In this tutorial, I'll show you step by step using my new version of Road Atlanta, as I got it in-game.

    Intro:

    Light Detection and Ranging, until now has been a rarity only available to the privileged few who had the high priced hardware or strong financial backing, and up until recently there were no effective apps for even getting the data into a game. This holy grail of landscape designers is now freely available for anyone to use for a myriad of tasks, from civil engineering, to video games. Being a long time sim race track builder, I’ve been trying to learn how to get my hands of these laser scanned nuggets of gold for years. Wadda ya know, as of a few years ago a literal gold mine of (free) resources are now available, some using NOAA aircraft, and even home brewed contraptions bolted to the back of cars can render 0.6mm accuracy.

    This resource differs from topographical maps and GPS plots in that it is high fidelity and accurate; it records a point every 0.3 meters horizontally (some times more) with 10cm elevation accuracy. BeamNG terrain uses 1 meter horizontal squares for its terrain system, so you can use it as is, to quickly create terrain.

    The end result isn't a perfect solution; untouched, its not smooth enough to drive a race car on and man made features can be very jagged on places, but with the super smooth tool applied and some planning, its workable.

    The Tutorial:

    1.
    Get LIDAR files: for many US locations (thanks Obama); https://earthexplorer.usgs.gov/

    a. Search Criteria for your location and then plot 4 points surrounding it (not too big)

    b. Select Data Sets : digital elevation : LIDAR

    c. Switch to the Results tab; make sure the Date Sets drop-down menu is set to LIDAR

    d. Hit the Download options button,

    e.Registration and Login. Don't worry, its a free service and spam free.

    f. The buttons will change from light to dark blue, allowing you to Download the LAZ file.



    For aerial images that match up easily: Datasets - Aerial Imagery - NAIP GEOTIFF​

    Some alternate sources:


    Some areas aren’t available, especially if it’s far from a city, just keep in mind that it’s a limited resource.

    2. Get CloudCompare: http://www.danielgm.net/cc/ this app is free and very useful for working with all kinds of cartography.

    3. Open all of your LIDAR file(s) in 'CC’

    1ccopen.jpg

    4. Hit the apply all and yes to all to the 2 pop-ups.

    5. Select all clouds in the DB tree panel, and hit merge button.
    2dbtree-mearge.jpg

    6. In the panel below; properties: scroll down to Scalar Fields; change type to Intensity

    3properiessalar-sfdispalyparams.jpg

    7. Below Scalar fields; (SF display params); move the yellow arrow until its close to the black wave form.

    These 2 steps should clear up the map and you can have some fun in the 3d viewer. You will see details like the roads, grass, and 3D details like buildings and trees. If you left/right click-drag you can rotate/pan and see it from different angles and zoom in with the mouse wheel. Hit F4 to switch to camera centered rotation and you can sort of fly through the scene. If you zoom in too close, the dots get too small to see; in the top left of the viewer, you can increase point size so you can keep zooming in and still see the terrain up close.
    43dviewer.jpg

    Now that you are oriented with the map, click the magnifying glass icon on the left tool bar, and the orange and white cube below it to get the view straightened. Save the map as BIN which is CC’s native format and can be loaded easily.

    (Alternate path: Convert to height map):
    The cloud from step 7 can be converted to a height map that can be imported directly into Beamed using the Tools: projection: rasterize tool. Big thanks to marcus.stromson figured out the workflow for generating height maps:

    "To get a grey scale height map for import to BeamNG I did this (using Photoshop):

    1. Followed your tutorial to step 7.
    2. Then cut the map as close to 512x512, 1024x1024 or 2048x2048 etc. as possible. The reason for this is that I want the correct Z-dimension (height difference from lowest to highest point on the map) when importing it to BeamNG.
    3. Followed your tutorial at step 9.
    4. Tools > Projection > Rasterize. Click Edit grid and set width XY to equal 512, 1024 or 2048 etc. Fill empty cells with interpolation and set value to 1. Click Update grid. Then export as Image.
    5. Open the image in Photoshop.
    6. Image > Mode > Color Table, and choose Grey scale.
    7. Image > Mode > Grey scale
    8. Image > Mode > 16 bits/channel
    9. Save heightmap as a png and import to BeamNG.

    Works pretty well I think. Needs some smoothing in the editor, but maybe that is common for every heightmap?"

    8. If you are continuing to the mesh exporting phase, it's time to cut up the map. The raw cloud map displayed is undoubtedly bigger than the area you want to use for your map. Plan out a square region you will use for your level.

    a. Select the cloud from the DB tree panel

    b. Click the scissors icon on the middle of the top toolbar

    c. A small tool bar will pop-up in the 3D viewer; click the pause button, then pan/zoom to so the region you want is visible.

    d. Un-pause, click the polyline selection arrow, and switch it to square selection, drag-select the region you want to keep. You can click the polyline button’s arrow to export the square, and save it as a BIN file for later. You can do this whenever you make a polyline selection and want to reuse it.

    e. Hit the red filled-in button and the check mark to finish. Delete the ‘remaining’ section that was cut out. Save this map as a BIN file – I name it Map_All.bin​

    5polyselect.jpg

    9. Extracting the ‘Ground Points’ is vital. It removes the trees, walls and buildings; leaving you with the only bare terrain which can be paved and have quality 3D scenery added to.

    a. First, go to scalar fields again; this time use Classification. In SF display params; move the two circles until they isolate the blue line at the 1.9 / 2.1 parameters (usually).

    b. Cut the unwanted sections out: edit: scalar fields: filter by value: split button.

    c. Delete the old unchecked map piece and the one labeled outside in DB panel.

    Save as a new BIN file ie: Map_Ground.bin
    3properiessalar-sfdispalyparams2.jpg

    10. To get the raw points into real 3D, we need to convert it to a mesh. Go to Edit: Mesh: Delaunay 2.5D (XY Plane) - set Max edge length to 0: this setting will fill in any holes with a flat patch the size of the number, in this case infinite. Go to edit: Global Shift/scale and zero out the 3 shift fields, so the mesh loads close to the center of origin.


    11. Save as OBJ or STL

    12. Open in blender or 3DS Max. Assign a material to the mesh. You can also apply UV mapping and a satellite image overlay, if you want to make it easier to paint and pave in BeamED. I’ve tried using a top down screenshot of the 3d viewer in CC, and mapping it to the mesh and it’s matched pretty well to start with and was very useful for painting the initial roads.
    13max.jpg
    12. Cut the mesh into pieces no larger than 200,000 triangles, any bigger and Beamng will crash while loading the mesh. I’ve loaded over a million tri’s total, but they can’t be any bigger per mesh. You can do this in CC before export using scissors tool: polyline selection, or in your 3d editor.

    13. Save as DAE

    14. Time to move your map into BeamNG

    a. Load up a new level in BeamED,

    b. Load the DAEs,

    c. On the side panel: transform: position box; zero out the xyz values

    d. Create a new terrain, set to 2048 resolution, or the power of 2 number closest to your map width in meters;

    e. Move the terrain so its origin corner (south west) matches the corner of the mesh. Make sure its max height is more than the mesh and the minimum height is lower than the mesh to avoid spiking. You can gauge this with the set height tool and the specific mesh height by looking in CC at the mesh’s Box Dimensions: Z value. Keep in mind, the smaller the max height value is, the smoother the road surface will be. The Square Size should be 1 meter or less, to best suit the mesh density. You can change it until the terrain fits over the mesh if you like.​

    15. With the terrain in place start molding it to the LIDAR mesh. Go to the terrain edit mode and Align with mesh up/down. You will need to do this task to the whole map. I do it in steps; around the important roads first, then the outlying parts after I get it drivable. If you applied UV mapping to the mesh and added a map texture, it will be easier to paint and adding of scenery objects.

    beamed01.jpg
    Here's my semi-finished terrain. I used a USGS NAIP 1 meter image overlay on everything to bring it to life.

    done.jpg

    Tip 1: optimizing the terrain is a special step you can use for sections of terrain not normally visited, or things only seen from afar.

    You can cut these areas out using the scissors tool and polyselect type. Then use Edit: Subsample to reduce the cloud’s point’s spacing. My USGS files use feet as their measurement, so I make areas 60 feet from the track 3 foot spacing and areas 500-600 feet out 6 feet apart. This makes loading meshes quicker and reduces the poly-count. I then make meshes for the background hills and mountains for areas beyond the terrains limits using 10-20 foot spacing. The finished parts can be converted to mesh with Edit: Mesh: Delaunay 2.5D (XY Plane) - set Max edge length to 6 (higher for parts with big holes and for rougher clouds.)

    Tip2: (IMPORTANT STEP ALERT) Making a mesh with just the road polygons is vital if you want to be able to terrain paint them accurately in BeamED and to add a perfectly matched up satiate map image over the terrain.

    a. Select the map and Set scalar fields to intensity and move the right circle until the grass areas of the map start to disappear between 50-35 seem to reduce it enough to turn most non road areas white.

    b. Then use the trick from step 9: edit: scalar fields: filter by value, to remove the grass sections.

    c. This can be used as is or further trimmed using scissors: polyselect: delete.

    d. The finished mesh can also be converted to mesh same as Tip 1

    e. Once loaded into BeamED (after molding the entire terrain with align to mesh from step 15) , you can paint the road by tracing over the road mesh by setting the road’s material to mult transparency, so it’s see through, then export the terrain, and it will output a PNG image with the road shape on it. This image can be loaded into an image editor and a USGS NAIP GEOTIFF can be overlaid if you set the terrain to 1 meter square size.

    I give all grass and forest sections this map a terrain paint type with diffuseSize = "2048"; so it matches the map resolution. Some flipping or mirroring may be needed since the outputted PNG isn’t oriented right.

    For smooth roads; I build a high polygon 3d model of only the road surfaces, align the terrain to them and discard the 3d model when done smoothing. The mesh road tool in BeamED can be used in a similar way to achieve accurate banking and smoothness. For a rally/dirt map, the inherent bumpiness of the LIDAR makes a good realistic dirt surface, and only the paved sections need smoothing.
    This tutorial is based on this one I found http://assettocorsamods.net/threads/lidar-point-cloud-to-mesh-tutorial.422/ which is great, but I’ve added some important steps for getting it into BeamNG. For more detailed explanation and a fully realized theory on terrain generation, check out Map In a Month. Day 4 is especially important for completing this process


    Changelog:
    - Some small typos fixed
    - add how to save polylines.
    - Fixed step 9. It now includes the steps on how to split the cloud into 2, after excluding trees.
    - Added some tips for making optimized point clouds for exporting to mesh as backdrops.
    - A big tip for isolating the road portions of the point cloud for matching up your LIDAR generated terrain to satellite images. Also for how to make a satellite map overlay material – for terrain paint.
    -Rewrote the beginning section, and added some formatting
    -Added Marcus.stromson's steps for converting the ground points directly to a height map (big thanks)

    torsion Gave me this tip for Blender users:

    Did you consider using Blender to reduce the amount of chopping up and manual "align with mesh" work? After going through the steps you describe I think that you could simply:

    1. import the entire, uncut, mesh into blender
    2. add a "ramp" to setup min/max height if desired (eg if you're combining this LIDAR scan with other terrain)
    3. render to PNG (edit if desired)
    4. import into BeamNG
     
    #1 Ewanc, Apr 27, 2017
    Last edited: Feb 9, 2018
    • Like Like x 8
    • Informative Informative x 8
    • Staff Pick Staff Pick x 1
  2. FS16

    FS16
    Expand Collapse

    Joined:
    Feb 18, 2015
    Messages:
    992
    this is awesome for map builders. Massive thanks.
     
    • Agree Agree x 4
  3. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,031
    Awesome - thanks! :)
     
    • Like Like x 2
  4. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Updated the tutorial... I found out the hard way that you can't copy and paste text from MS Word to the forum. Lost all the indents and everything got triple spaced between paragraphs. I need to find a format friendly place to publish. It might be missing some of my edits and have formatting mess.


    Fixed some small typos, added how to save poly lines. Fixed step 9. It now includes the steps on how to split the cloud into 2, after excluding trees, Added some tips for making optimized point clouds for exporting to mesh as backdrops. A big tip for isolating the road portions of the point cloud for matching up your LIDAR generated terrain to satellite images. Also for how to make a satellite map overlay material – for terrain paint.
     
    #4 Ewanc, Apr 29, 2017
    Last edited: Apr 29, 2017
  5. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    Paste with Ctrl + Shift + V, that makes plain text paste to forum, should work with most browsers.
     
  6. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    Thanks for the tutorial, this is very interesting stuff.

    In this case I think you mean a "power of two" which is closest to your map width in meters, not a prime number. https://en.wikipedia.org/wiki/Power_of_two#Computer_science

    Did you consider using Blender to reduce the amount of chopping up and manual "align with mesh" work? After going through the steps you describe I think that you could simply:
    1. import the entire, uncut, mesh into blender
    2. add a "ramp" to setup min/max height if desired (eg if you're combining this LIDAR scan with other terrain)
    3. render to PNG (edit if desired)
    4. import into BeamNG
    https://beamng.com/threads/tutorial-adding-heightmap-roads-using-blender.16356/
     
  7. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Thanks guys. That would definetly speed up the process, importing as a hieghtmap. I've worked with hieghtmaps, but gave up on them because it was complicated to line up the terrain with my walls and other modeled 3D parts. My needs aside, Im sure it will help many. Cloud Compare has a rasterize tool which does the same thing but let's you trim the map to the exact size needed for import. I'll try to finish step 10, which i started to explain it.
     
    #7 Ewanc, May 1, 2017
    Last edited: May 1, 2017
  8. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    196
    Have you figured out how to use the rasterize tool successfully? I'm sure this could help many people.
     
  9. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    I havent worked on my real world projects this month, other than some oval concepts. Ill give it a try for my next race track and compare the end results.
     
    • Like Like x 1
  10. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    196
    Nice, I'd like to see the results of that
     
  11. Eldigan

    Eldigan
    Expand Collapse

    Joined:
    Jan 27, 2017
    Messages:
    22
    Very useful
     
  12. Gavril T85

    Gavril T85
    Expand Collapse

    Joined:
    Aug 14, 2017
    Messages:
    635
    On earthexplorer.usgs.gov it wont let me download the file without giving me all this "sign up" crap. and the other websites don't seem to follow for instructions. please help?
     
  13. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    The LIDAR files and most of the maps are all free, but (I just noticed) do require registering on the USGS site. I've been registered for a while, and its painless, so no worries about that. Your not signing your life away or anything. I've seen some pay content mixed in, but nothing required for this type of project.
     
    #13 Ewanc, Sep 18, 2017
    Last edited: Sep 23, 2017
  14. Gavril T85

    Gavril T85
    Expand Collapse

    Joined:
    Aug 14, 2017
    Messages:
    635
    ok
     
  15. NGAP NSO Shotgun Chuck

    NGAP NSO Shotgun Chuck
    Expand Collapse

    Joined:
    Mar 6, 2015
    Messages:
    1,410
    Bump, but: with the accuracy statistics you mentioned, is there a method yet for accurately replicating the bumps and cracks of a real-life road in BeamNG.Drive? Especially as with certain pass roads, the bumps and dips and cracks are part of the fun. One road near me has a section I call "Corvette Killer" as it's full of cracks, patches, and whoops, another has a corner where you can do a gutter hook without even getting close to the edge because the ground under the inside 1/8th or so of the road has sunk since the construction of said road. Getting the layout and topography right is good but there isn't really a point to putting these roads in a game if these surface imperfections can't be replicated properly.
     
    • Informative Informative x 1
  16. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    I haven't experienced much in the way of cracks and holes, since my aim is at silky smooth race tracks. Games like iRacing use LIDAR, but it's recorded from the back of a car rather than the wing of a plane. They can achieve accuracy of less than a millimeter compared to 5cm from the NOAA aerial stuff I'm using and make use of whatever details they want, with their almost infinite data. I bet they have trouble figuring out which details to include without killing the frame rate of the game. The technology is getting cheaper, and a home brewed super accurate car mounted LIDAR system is possible. That could possibly be my next hobby/experiment ;)

    BeamNG.Drive really cant get much better accuracy than what I'm working with due to the terrain grid being made of big squares. It'll register a 5cm bump, but over a 2m length. Cracks can't be replicated with this system unless the hole is 2m wide. I mean, you could maybe make a hole in the terrain grid (delete a square) and fill it in exactly with a custom mesh "crack".

    On the bright side, I just got done building out the service roads around Road Atlanta, which include a lot of crude gravel roads. There are definitely some well preserved whoops and washed out parts. Also...if you slip off the road, you launch out of a 10 foot wide ditch and go flying 4 feet in the air and land in the trees. Ive worked out quite a rally scenario from these features.
     
    #16 Ewanc, Nov 3, 2017
    Last edited: Nov 3, 2017
    • Like Like x 1
  17. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    That's a cool area to try out, very dramatic. It's too bad the USGS data isn't categorised better for separating the ground layer. There's a lot of cleaning up needed, where buildings and walls are terraced into the terrain. Most of the walls on Road Atlanta are barried in the ground on the outside for instance.

    Cloud compare is great at point clouds, but not much else. QGIS has some good plugins and its a good go-between. My main problem with terrain generated in-editor is syncing meshes like walls and other molded in features.

    Feel free write up a guide post it separately. I can just link it to this one. It sounds like you found a simpler way that would work on its own. Between your method and this one it should fit most people's needs.
     
  18. Spiicy

    Spiicy
    Expand Collapse

    Joined:
    Sep 8, 2016
    Messages:
    3,797
    umm, were is the download button? Its nowhere!
     
  19. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    This is a tutorial; what's to download? Are some of external site links not working?
     
  20. Spiicy

    Spiicy
    Expand Collapse

    Joined:
    Sep 8, 2016
    Messages:
    3,797
    on earthexplorrer.usgg or whatever its called i mapped out the area, but I cant find the download button after selecting lidar
     
  21. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Aha, that makes sense. Here's some more detailed instruction. Ive used this service so many times, I forgot how complicated it could be.

    a. Search Criteria for your location and then plot 4 points surrounding it (not too big)

    b. Select Data Sets : digital elevation : LIDAR

    c. Switch to the Results tab; make sure the Date Sets drop-down menu is set to LIDAR

    d. Hit the Download options button,

    e.Registration and Login. Don't worry, its a free service and spam free.

    f. The buttons will change from light to dark blue, allowing you to Download the LAZ file.

    lidar_DL.jpg
     
    #19 Ewanc, Dec 9, 2017
    Last edited: Dec 9, 2017
    • Informative Informative x 1
  22. marcus.stromsten

    marcus.stromsten
    Expand Collapse

    Joined:
    Nov 6, 2016
    Messages:
    1
    Thank you for a good tutorial!

    To get a grey scale height map for import to BeamNG I did this (using Photoshop):

    1. Followed your tutorial to step 7.
    2. Then cut the map as close to 512x512, 1024x1024 or 2048x2048 etc. as possible. The reason for this is that I want the correct Z-dimension (height difference from lowest to highest point on the map) when importing it to BeamNG.
    3. Followed your tutorial at step 9.
    4. Tools > Projection > Rasterize. Click Edit grid and set width XY to equal 512, 1024 or 2048 etc. Fill empty cells with interpolation and set value to 1. Click Update grid. Then export as Image.
    5. Open the image in Photoshop.
    6. Image > Mode > Color Table, and choose Grey scale.
    7. Image > Mode > Grey scale
    8. Image > Mode > 16 bits/channel
    9. Save heightmap as a png and import to BeamNG.

    Works pretty well I think. Needs some smoothing in the editor, but maybe that is common for every heightmap?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice