Skip to content

Heightfields with World Machine

Michael Horvath edited this page Jan 30, 2021 · 13 revisions

Steps I use to create heightmaps using World Machine (free or demo version is okay) and MeshLab (free and open source) and import them into LDraw (freeware). The tools currently only work under MS Windows.

For regular "smooth" terrain

  1. By "smooth" I mean that the vertical vertex coordinates can be any number, including floating point numbers; as opposed to "stepped" terrain, whose coordinates are rounded to integer multiples. (See next section.)
  2. Open "ldraw_terrace.tmd" in World Machine or create a new project.
  3. In World Machine select "World Commands" > "Project World Parameters...".
  4. In the "Render Extents and Normal Build Resolution" tab make sure that the "Resolution" setting is set to 128x128 and that the "+1" box is checked. Checking the "+1" box will change the resolution to 129x129. This is OK.
  5. Also make sure that the "Lower Left Coordinate" setting is set to 0m and 0m and that the "Upper Right Coordinate" setting is set to 8km and 8km.
  6. In the "General Setup" tab I set the "Maximum Elevation" setting to 3000m and the "Base Elevation" setting to 0m. You can change these to whatever you feel comfortable with or looks the best.
  7. Also make sure that the "Dimensionality" setting is set to "Kilometers".
  8. Continue to tweak the other heightfield parameters if you want to, before opening the mesh properties dialog.
  9. In the mesh properties dialog, make sure "Y is up" is selected in the "Coordinate System" field.
  10. Make sure that "Units" is set to "Export using meters".
  11. Make sure "Always export at origin" is checked.
  12. Specify the output file name to "mesh.obj".
  13. Set the file format to "Wavefront Object".
  14. We don't need UV coordinates, so you can uncheck those options.
  15. Make sure the "Allow common-edge flip" setting is checked.
  16. Press the "Write output to disk!" button to export the model.
  17. Import "mesh.obj" into MeshLab.
  18. The mesh currently is 8000 by 8000 units large. It needs to be 81920 by 81920 units large (128 by 128 baseplates), so we need to scale the mesh upward by 10.24.
  19. In MeshLab select "Filters" > "Normals, Curvatures and Orientation" > "Transform: Scale". Make sure the "Uniform Scaling" box is checked. Then set the scaling factor to 10.24 for all three axes. Click "Apply" then "Close". This dialog is a bit buggy so you may have difficulty entering the scaling values.
  20. In MeshLab select "File" > "Export Mesh As..." to open the export dialog. Uncheck "Binary encoding" and "Materialize color encoding". Export the file as "mesh_nosteps.stl".
  21. Using the command prompt or a batch file convert the STL file to LDR using "stl2dat.exe". An example of the command line looks like this: stl2dat mesh_nosteps.stl -ldr -raw
  22. Open the LDR model in MLCAD. The model may be upside-down, so rotate the model by 180 degrees around the x-axis if needed.

For "terraced" terrain

  1. By "terraced" I mean that I used the "terrace" filter in World Machine to give the terrain a stair-step or terrace-like appearance.
  2. The goal here is to give each terrace level a height of some integer multiple of 24 LDU (the height of an LDraw brick) after all is said and done.
  3. The "Maximum Elevation" in our World Machine scene is set to 3000.
  4. This value gets scaled by 10.24 in MeshLab, resulting in a final height of 30720 LDU.
  5. Divide 30720 by 24 LDU (the height of an LDraw brick) and you get 1280. 128 happens to be the maximum number of terraces you can give a mesh in World Machine, so if you set it to that amount then you get terraces exactly 10 bricks high.
  6. For some reason, when using this method, there are several non-integer coordinates in the result. For that reason, I recommend reading the "For stepped terrain" section, below, and using that method instead. (The two methods are very similar and try to do basically the same thing.)

For "stepped" terrain

  1. By "stepped" I mean that mesh vertex coordinates are rounded to some multiple of some integer. This makes the mesh look less smooth, but makes it align and fit better within the LEGO system.
  2. Run the LDR file through my program "terrain_stepper.js". An example of the command line looks like this: cscript terrain_stepper.js meshlab_output_stepped.ldr -n 24
  3. Note that "terrain_stepper.js" only modifies the vertical coordinates. Horizontal coordinates will remain unchanged.
  4. All vertical mesh coordinates should be integer multiples of 24 at this stage. If you see decimal values for the horizontal mesh coordinates, then you may need to round the numbers further using LDDP, or report a bug to me.

For a "stand-in" version of the terrain

  1. By "stand-in" I mean a version that is easier to work with as opposed to looking pretty. E.g. not the final version.
  2. Use "terrain_splitter.js" to split the mesh into 16 pieces. It is located in the "helper_scripts" folder. There should be some batch files in the same folder or in the parent folder that can be modified to do this job.
  3. Use "terrain_colorer.js" on the sixteen pieces to alternately color each triangle. It is located in the "helper_scripts" folder. There should be some batch files in the same folder or in the parent folder that can be modified to do this job.
  4. Use "Edger2.exe" to add edge lines around contiguous areas. There should be some batch files in the "helper_scripts" folder or in the parent folder that can be modified to do this job.

Clamps and masks

  1. To do.