Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

mTerrain (3dsMax mesh to Unity terrain)

Discussion in 'Made With Unity' started by mgear, May 28, 2011.

  1. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    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
    - http://www.mediafire.com/?nqp2wm9japdncaf

    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
    - mTerrain is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    http://creativecommons.org/licenses/by-sa/3.0/


    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)
     
    Last edited: May 30, 2011
  2. pixellegolas

    pixellegolas

    Joined:
    Apr 10, 2011
    Posts:
    223
    loving it!
     
  3. Pedro Afonso

    Pedro Afonso

    Joined:
    Mar 13, 2011
    Posts:
    240
    very very nice work and you are giving it for free!

    I'm your fan
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    - Export script from Max is now fixed/updated (check updated install info on 1st post)
     
  5. IndieStudio

    IndieStudio

    Joined:
    May 12, 2011
    Posts:
    60
    Is it possible to have the scene and mesh of you example?
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    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
     

    Attached Files:

  7. IndieStudio

    IndieStudio

    Joined:
    May 12, 2011
    Posts:
    60
    Thank you very much
     
  8. IndieStudio

    IndieStudio

    Joined:
    May 12, 2011
    Posts:
    60
    tested. Really COOL Stuff. Thank you again
     
  9. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    nice work!!
     
  10. makan

    makan

    Joined:
    Jan 8, 2011
    Posts:
    342
    This is awesome :D
     
  11. info@lifelike.ee

    info@lifelike.ee

    Joined:
    Jul 25, 2011
    Posts:
    3
    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?
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    Hi,

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

    skylebones

    Joined:
    Nov 21, 2009
    Posts:
    106
    Oh I like that! Very cool!
     
  14. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    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?
     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    ^ 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..
     
  16. ForceX

    ForceX

    Joined:
    Jun 22, 2010
    Posts:
    1,102
    This is amazing! After the terrain has been imported into unity will it use the adaptive resolution that unity generated terrains use?
     
  17. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    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.
     
  18. soulzero

    soulzero

    Joined:
    Dec 9, 2009
    Posts:
    8
    This is a Great Tool! Thanks for sharing it.
     
  19. info@lifelike.ee

    info@lifelike.ee

    Joined:
    Jul 25, 2011
    Posts:
    3
    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.
     
    Last edited: Aug 1, 2011
  20. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    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?
     
  21. bumd198

    bumd198

    Joined:
    Nov 11, 2010
    Posts:
    37
    I have a problem, I did all the settings correct but when I try to get noise modified terrain to unity, it comes with almost flat plane to unity. There r few mini holes in the terrain. It shows like a flat play and a few circles on it... I'm using meters in 3dsmax, and it's 2000x2000 meters, anyway it's nothing to do with it I guess.

    If screenshots may help to understand, I can post it.
     
  22. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    Or email me the file, i'll test it also. (i'll pm the address)
     
  23. bumd198

    bumd198

    Joined:
    Nov 11, 2010
    Posts:
    37
    It's funny that after I re open 3dsmax, exporter script is not responding. Tried to reinstall and tried in max 2012 and first time install, still not responding.
     
  24. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    Wow, sweet! Thanks for sharing!
     
  25. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    Someone had problems exporting from Max while Unity was running. (asset file was locked by unity?)

    Havent had the same problems and it should work while Unity is running..
    But thanks for the bug reports.
     
  26. krillmcrawl

    krillmcrawl

    Joined:
    Feb 18, 2011
    Posts:
    29
    Thank you, very handy! Are you releasing the tree exporter as well?
     
  27. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Just started using this tonight and I must say it's a very handy terrain exporting tool, great job!

    Just one little bug regarding the save folder setting. It's not a big deal but whenever I choose the save to folder, E:\Project\Terrain, for example. The exported file will save in the Project folder instead of the Terrain folder. Anyone else experiencing this as well?
     
  28. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    Yes, just havent decided what to pick for exporting different types of trees..
    - use 1 pflow for each tree type
    - or use 1 pflow for all the trees (and use particle values (like color/custom val..) to pick tree types in unity..
    ..thinking..

    Tested it now and made the same thing here..

    You can fix it by manually adding "\" after the folder name (in setup window)
    so make it, E:\Project\Terrain\
     
  29. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Cool, worked great, thanks!

    Now another thing I ran into while trying to Build Test my scene. I'm getting compiler errors which I'll copy and paste below.

    Assets/mTerrain.js(10,9): BCE0005: Unknown identifier: 'EditorUtility'.
    Assets/mTerrain.js(11,9): BCE0005: Unknown identifier: 'EditorUtility'.
    Assets/mTerrain.js(25,17): BCE0005: Unknown identifier: 'EditorUtility'.
    Assets/mTerrain.js(28,9): BCE0005: Unknown identifier: 'EditorUtility'.
    Assets/mTerrain.js(29,9): BCE0005: Unknown identifier: 'EditorUtility'.

    Any ideas as to what these errors could be?
     
    Last edited: Oct 21, 2011
  30. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
  31. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Alright, I'll try that and see if it works. Thanks!

    PS. What I did to fix it was to just remove the mterrain file and editor folder then just re-import it whenever I do need to import in my terrain from max, but I'll try the above to see if it works so I don't have to do it that way which isn't really a big deal.
     
    Last edited: Oct 21, 2011
  32. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    One bug note:
    Someone noticed that you should have your 3dsMax unit setup as: 1 unit = 1 meter
    (otherwise the terrain was too high in unity)
     
  33. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Do you take PayPal?
     
  34. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
  35. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Yes, I've been using it for a month or so now. It's the only way I can find to get real world terrain into Unity. I want the code to be able to fix the directory problem (the "\" fix works) and name the files. But I just got a new PC and now i'm having trouble with it. I notice in your 'SampleMountain1.txt' all of the values are between 0 and 1 (more or less). For some reason i'm getting much larger values, 4.47179, 7.17261, 8.55866 etc. I cant find a combination of units/terrain height that works. How can I fix this? Thanks.
     
    Last edited: Dec 17, 2012
  36. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,324
    Yeah the maxscript source is available for donors (pm me if the paypal donation button doesnt work)

    Only thing that I could think of now is, maybe your terrain height is bigger than the given "unity terrain height"..?
    Or maybe you need to have Max units (both) the same: I used Millimeters

    Or if you want to send me some max test terrain, I can try it.
     
  37. HelioZuazua

    HelioZuazua

    Joined:
    Oct 24, 2013
    Posts:
    4
    Hi:

    Superb tool , but im messing up with "ERROR 1:vertext count doesnt match".

    I trie to review all 512x512 tiles, 2000x200 plane , 600 strenght and 1M : 1Unit , but no mesh available.(or i cand find it at leat in the directori given)

    Thanks in advance
     
  38. HelioZuazua

    HelioZuazua

    Joined:
    Oct 24, 2013
    Posts:
    4
    Sorry but restrat all and "error 0".

    I review the posts and the ini file is in the given directory and setings saved.

    If I finally can export the files ill let you know.

    (test file absolutely correct the import , just that i cant export from max)