Mesh terrain to heightmap in 3DS Max? (Solved)

Discussion in 'Content Creation' started by Ewanc, Jan 29, 2018.

  1. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Is there a tool/editor script for converting mesh to height map? While aligning a 8192x8192 terrain to mesh, it got me thinking how nice it would be to have an "align all meshes to terrain" button. I noticed that Hirochi uses mesh walls that are aligned perfectly with the terrain; how it this possible? I have a way, but my workflow is inefficient and requires hours of align to mesh work, using a mesh version of terrain imported from my 3D editor (usually LIDAR generated) then importing the wall geometry, so geometry aligns perfect.

    My only attempts to render a height map in 3DS Max have been hampered by its inability to line the terrain square with the viewer. For example, it cant render a 2048m plane as a 2048x2048 image; the closest is "zoom extends selected" but its not zoomed in far enough to frame the object; zooming in further will only get close but not perfectly framed. Once rendered, cropped and resized, its not a perfect image.

    Importing the (3ds max rendered) height map into the editor results in another problem; the terrain isn't centered with the world (even at 0,0,0) so there's no reference to where the terrain would match with geometry. I made a special object attached to the terrain mesh which has 3 flat planes at the extreme high and low points of the terrain and the at 0 elevation. This should solve the issue with not getting accurate heights for the terrain file.

    If this was a simpler process, there would be much more quality maps.
     
  2. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Importing to Blender is a simple enough. I had skimmed over that part of B25Mitch's tutorial because I don't use Blender, but it looks like I could limp my way through it. It looks to be exactly the setup I need. Thanks!
     
  3. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    I figured out the setup for 3DS Max to frame the camera perfectly over a plane. It just requires a Orthographic free camera, pointed down and in the settings: below Multi-pass affect, set Target Distance very high and adjust it down until it only renders the plane. FOV: 39.598 and Target Distance: 11378.0m are the winning combination for a 8192m plane.

    Setting up the scene is pretty easy, just apply a gradient ramp material, and UV map it from the side or back, making sure it fits perfect from top to bottom. I also add a big white plane under the terrain plane, to make it easier to center.

    I ran into an annoying problem with the 3DS Max render engine; there's no way to turn off shading normals, (shadows and shading are handled separately) so the output will have hill shading, and in turn render a distorted hightmap. Ill give the Blender route a try, or ultimately go back to the align to mesh drudgery.
     
    #2 Ewanc, Jan 31, 2018
    Last edited: Jan 31, 2018
  4. Ewanc

    Ewanc
    Expand Collapse

    Joined:
    Oct 25, 2015
    Messages:
    254
    Finally got a breakthrough with a push in the right direction from the CGTalk's 3DS Max experts. They recommended using render to texture, rather than standard rendering. This method skips the trouble of lining up a camera. I went to the Autodesk site and brushed up on that specific tool and found it has special functions for baking heighmaps, normal maps, as well as rendering matching terrain painting masks.

    Here's a write-up on the entire process:

    Terrain generation with 3DS Max!


    This tutorial can be used in conjunction with the Map in a month guide to complete the mapping process, substituting part of the Day 4 section. The mash modeling parts can be done in 3DS Max too, but is out of the scope of this subject.

    The setup:

    1. Make a copy of your scene with all of the parts of the terrain to be included, this should include the LIDAR mesh if that's the base terrain, as well as any ground surface meshes you have modeled. Be sure to not include overlapping features; like foot bridges and underpass tunnels. when in doubt; be keep the top most surface driven on by the AI and remove the lower one.
    2. Create a plane that's the size of the map ie; 2048x2048 meters and center it over the base terrain so its even with all the boundaries of the desired driving sections. name it something like heightmap_frame.
    3. Cut off the edges of the base terrain; use vertex 3d snap and quickslice at the edge of the new plane and then delete the excess polygons.
    4. Make a multi-sub material with all the terrain types you want pre-painted onto the terrain when its imported. Set them to diffuse color black and 100% self illuminated
    5. Detach off all the parts into their terrain types, then assign all of them the new terrain material. I use the schematic view to keep the parts organized how ever needed. The objects can be arranged into groups in this window by selecting and moving them around.
    6. Reattach all the objects back together by their terrain type. Not just one big mesh, yet.
    7. for each of the new objects; assign its MatID by the one from the new Terrain material.
    8. Now attach them all together into one mesh
    Render to texture (RTT) Heightmap process:
    1. Go to Rendering>Render setup (F10) and select Renderer: Defalt scanline renderer
    2. Select heightmap_frame and go to Render> Render to texture
    3. In this window go down to Projection mapping; check Enabled
    4. Hit the pick... button and select the merged terrain, next hit options... and write down the number in the button right, this is the max height that will be used when importing the terrain. I add a few meters to this to give some flexibility: for example, from 0, 466 to -3, 469 and the max height is then 472 meters
    5. Go down to Output: add... Heighmap
    6. In file name and type: set a file name and PNG as type, hit the render button at the bottom of the RTT dialog, and go back in and select the outputted file;
    7. In settings use: Grayscale 16bit
    8. Now set the target map slot; Bump
    9. set height and width to your map's size (ie: 2048,2048)
    10. In the bottom right of the RTT window: set the views and render to Baked, now hit the Render button and it will output the heightmap to your selected location. You can now import it with the editor with its "Imoprt terrain" function, or continue on to the next section and generate the extra terrain paint types.
    RTT terrain type mask

    For big maps, its a huge time saver to use the modeled roads and sand dirt patches as the template for terrain painting. It also makes cleaner product and requires little or no touch-up. This part was a necessity for me, because with extra big 8192px maps, the in-editor brush lags too much to even use. This process is similar to baking heightmaps.

    Setup is simple, but requires some special materials every to render the black and white terrain mask. Start with the most used material; Forest in my case, I set the material colors to black, accept for Forest which will be black. I suggest double checking the type-in numbers to make sure the colors are 100% black or white.
    1. be sure Defalt scanline renderer is selected
    2. First, select the heightmap_frame pply a UVW map modifier: make sure it fits perfectly over the terrain; go to top view and zoom in to check the corners. If its offset by so much as a cm, use the mapping transform gizmo to move the mapping exactly over it.
    3. With the terrain selected, go to Render> Render to texture
    4. Skip the Projection section, but in the Mapping Coordinate section, set it to Use Existing Channel: 1
    5. In Output: chose Diffuse
    6. File type is the same: PNG: Grayscale 16bit
    7. change the file name (mak e sue to make a new one for each new baked image)
    8. target map slot; Diffuse
    9. Hit Render
    10. To repeat the process with a different terrain type; set the material colors again; to all black accept the one to be baked, which you set as white.
    Well, this isn't the full story, I also had some anomalies with the raw images not painting correctly. I ended up with a map that's all one terrain type, and a bunch of tiled patterns along the western edge. I suspect this is because the anti-aliased edges of the masks don't match each other perfect, like they do when you export a terrain. I loaded the forest mask into Paint Shop Pro; converted it to black and white (decrease colors to 2) converted it back to grayscale (mirrored it horizontally, if not already) saved it and did the same with the sand and road masks. I then made a negative of the forest road and sand; added the new sand and road to forest as layers and used darken blending on both layers. I then save it as a PNG. This made a perfectly matching mask of the grass.
     
    #3 Ewanc, Feb 6, 2018
    Last edited: Feb 20, 2018
  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