mTerrain (3dsMax mesh to Unity terrain)

Hi,

Small free tool, for my own testing actually,
so it takes a bit of work to install setup…
If you get it to work, let me know any ideas/suggestions for extra stuff.
(There is not much error checking done, so dont try anything funny…)

mTerrain

Intro

  • 3DS Maxscript, that exports mesh to Unity “terrain heights”
  • Whats nice, you a have full control of the terrain mesh in 3DS Max
    ie. edit as much as you like, stack modifiers, precisely edit few/single vertices etc…then easy export to Unity
  • This plugin doesnt create any terrains, use 3DS Max or external software to do that (this is for export/import only)
  • Good way to start, create plane, add displacement modifier, add some maps or bitmaps as displacement…

Requirements

  • 3ds Max 2008+
  • Unity 3.x

Download

Donation

  • Feel free to donate : )

    (bonus. Those who donate any amount, get the MaxScript source : )…which is nothing special, it just exports vertices to a file…)

Licence

Installation

3ds Max Script Installation

  • Copy “mTerrainFunctions.mse” to your 3ds Max scripts-folder (usually c:/program files/autodesk/3ds max 20xx/scripts/)
  • Copy “mTerrainv10.ms” to your 3ds Max scripts-folder (usually c:/program files/autodesk/3ds max 20xx/scripts/)
  • Run the script from 3DSMax menu: Maxscript / Run script… browse for the script, select “mTerrainv10.ms” and run it
  • Now go to menu:
  • Customize / Customise user interface
  • Go to “Toolbars” tab
  • Group: Main UI, Category: mTerrain
  • Drag the script from the cction list named “mTerrain” to your toolbar (existing or create new)

3ds Max Script Setup - First Run

  • Click the mTerrain button without any objects selected
  • This will open mTerrain Setup Window, fill in the values (You can see the values in Unity, from menu: Terrain / Set resolution )
  • Unity Heightmap resolution: ___
  • Unity Terrain height: ___
  • Unity project asset folder: ____ (this is the folder where your mterrain-textdata-asset will be saved)
  • Click “Save settings”
  • Done

Unity Script Installation

  • Import mTerrainV10.package
  • Inside the package you get 2 scripts (+1 sample terrain data asset)
  • mTerrainObject.js (can be anywhere in the project tree)
  • mTerrainEditor.js (its in editor/ folder)

Usage / Tutorial #1

Unity

  • Start new project or use your old one
  • Add unity terrain to your scene
  • Check Terrain / Set resolution… settings (they must match the values you have used in 3DS Max)
  • Add mTerrainObject.js script to your terrain (drag drop the script to terrain)

3ds Max : Creating terrain

  • Create plane
  • 2000x2000 (same size as your Unity terrain)
  • 512x512 segs (Important. 512 in Max is 513 in Unity, so its minus 1, if you use different resolutions)
  • Modify your plane to make terrain (for example, add a wave modifier)
  • Or use any displacement map with displacement modifier
  • Select the plane
  • Press “mTerrain” button
  • Wait…(progressbar is shown)
  • Done, go to Unity…

Unity : Getting 3DS Max terrain

  • Select your terrain (which has “mTerrain.js” attached)
  • Drag mTerrainAsset to mTerrainAsset in inspector window (under mTerrain script, its the terrain height values)
  • Note. You can rename “mTerrainAsset” to keep it, new imports are saved again as “mTerrainAsset”
  • Press “Update mTerrain”
  • Wait…
  • Done (your terrain should look like the one in 3DS Max)

After that you can keep modifying the 3ds Max plane and update it in Unity when needed

Go back to 3ds Max

  • Modify your plane
  • For example: add noise modifier
  • Press “mTerrain” button (1 object must be selected when exporting, if nothing is selected, setup window is shown)

Go back to Unity

  • Select your terrain
  • Press “Update mTerrain” in the inspector
  • Note. You need to click “apply materials” in TerrainTools, to get the correct textures in slopes etc.

Screenshots
Setup screen

Mesh in Max

Terrain in Unity (Terraintools used for texturing)

loving it!

very very nice work and you are giving it for free!

I’m your fan

  • Export script from Max is now fixed/updated (check updated install info on 1st post)

Is it possible to have the scene and mesh of you example?

Attached sample scene for unity + png heightmap for 3DS Max

Unity

  • import package to unity
  • open “mTerra_testscene”
  • select terrain
  • click “update mterrain” in inspector

Max

  • create plane 2000x2000 units, 512x512 segs
  • add modifier “displace”, bitmap: (browse for the .png in the zip), strength: 600

590941–21004–$scene_hmap.zip (1.08 MB)

Thank you very much

tested. Really COOL Stuff. Thank you again

nice work!!

This is awesome :smile:

Hello!

I can’t get in working. When I try to generate the map in max 2010 I get this error:

Error 0: Too many or not enough objects selected…going to setup!

What could be the problem?

Hi,

Select just the terrain (1 object), does it work then?

Oh I like that! Very cool!

Does this do anything that you couldn’t do by exporting your terrain from max as a .obj, and importing it to unity with Object2Terrain?

^ Havent tried the “Object2Terrain” yet…

This one has 1 click export 1 click import,
you can have multiple terrain datafiles in the project (could use scripts to pick one) etc…

Also the latest version (not released yet) has tree locations export from 3dsMax
and some other ideas coming up later…

This is amazing! After the terrain has been imported into unity will it use the adaptive resolution that unity generated terrains use?

It uses what ever settings you have set for the terrain,
as currently all it does, it adjusts the terrain heights to match Max mesh.

This is a Great Tool! Thanks for sharing it.

When I select only one object (a modified plane) and there is only one object in the scene I get this error. I think I should use object to terrain or try another version of 3dsmax to see if it happens again.

Ok, if you have time to check,

the problem most likely is,

  • It cannot create or read “mTerrain.ini” file
  • You can see the folder where it should be, by opening Maxscript listener window (F11) and typing: getDir #userScripts [press enter]

Check if the ini file is there, and that your settings are saved on it?