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

[RELEASED] Dynamic Terrain Objects - Run time deformation of terrain using any GameObject

Discussion in 'Assets and Asset Store' started by Jrodz, Jul 18, 2016.

  1. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    Use game objects of any size and shape to raise, lower, smooth, texture, and even animate your terrains at run time! If you have ever wanted to do run time manipulation of your Unity heightmap based terrains then this is the asset for you!

    Here is a run down of the library's API:

    Add the volume of your GameObject to your terrain:



    You can also subtract using the game object:



    Game objects with a sphere collider are the most efficient, but you can also use an object that has a box or even a mesh collider. Mesh collider objects are the most expensive performance wise, but once the object has been loaded in the relative values (what I refer to within the library as a "LocalHeightMap") used to deform the terrain area cached on the object making it very performant!




    You can smooth the terrain. Note the boundary of the smoothing's initial area. This is the end of the local "terrain area". By limiting the terrain manipulation to as small an area as possible you see big gains in performance. The size of the terrain area can be adjusted via the "area padding" variable exposed in script attached to the game object and for which you see some UI on the left sidebar.



    You can also update textures on the terrain. The only limitation here is that the texture must be added to the terrain object already via the built in interface. The size of the area around the object for which texture updates will occur can be modified via "alpha padding" on the game object script.




    The possibilities for this are endless, but here are a few quick runtime terrain animations I put together for the demo:



    Thanks for your time!

    - Jarrod
     
    Last edited: Nov 20, 2017
  2. montyfi

    montyfi

    Joined:
    Aug 3, 2012
    Posts:
    548
    Looks pretty interesting, it would be nice to see some fps counter during runtime transformations.
     
    Teila likes this.
  3. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    Hey thanks! Good idea on the FPS counter... I have a small batch of changes/improvements already cooking so I will add that to the next update.
     
    Teila likes this.
  4. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    334
    Hi can this tool also work in the editor and be used to paint and save changes in the editor as well as a runtime or is it only designed to be used at runtime ?
     
  5. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    For now it is primarily intended for use at runtime for doing realtime effects such as impact craters, simulating digging, raising/lowering terrain in response to some user input, etc. I could modify the demo scene a bit to allow it to be a more free form terrain editor, but even that would still technically be "runtime". If enough people think it would be useful I can do the work needed to make it more non-runtime friendly, but for now I had planned on focusing on adding more features to its use as a runtime tool.
     
    montyfi and Teila like this.
  6. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    335
    Hello,

    in your first sample: Add (1).

    After adding one time, i add another time but the ball dont raise up and stay on initial floor.

    +++
     
  7. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    Hey thanks... really appreciate that. As for multiple terrain tiles: I haven't tested it thoroughly, but you should be able to reference which terrain object you want the deformer to affect via the terrain attribute. Currently you would have to swap out that terrain object in code, but I can probably come up with a system for efficiently auto detecting the nearest terrain object in a future update.
     
  8. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    This was intentional for for the demo - in a real use you would be controlling the deformer object via scripting or some type of player input. Use the mouse wheel to set the deformer's height, hold shift + mouse wheel to scale.
     
  9. mercurysama

    mercurysama

    Joined:
    Jul 20, 2016
    Posts:
    2
    hey; great asset...
    can I use it in mobile devices???
     
  10. IanStanbridge

    IanStanbridge

    Joined:
    Aug 26, 2013
    Posts:
    334
    I would suggest at least adding the ability to save changes to the terrain as even if people only want to use this at runtime in most games they would want to be able to create a save game that preserved the changes. If you did that then it would also be able to make this tool useful for a large amount of use cases. For example I could use Gaia in the unity edior to produce a procedural terrain. Then I could use this tool to make any minor changes I needed to that terrain in play mode and then save it in play mode in the editor.
     
  11. mercurysama

    mercurysama

    Joined:
    Jul 20, 2016
    Posts:
    2
    great.
     
  12. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    For sure you will be a bit more limited in how much you can deform the terrain at once for performance reasons, but there are definitely no dependencies that prevent it from being used on mobile. The library leverages Unity's SetHeights and SetAlphas terrain functions which definitely work on mobile. I am going to be adding an update which allows you to use the deferred LOD version of SetHeights which will allow further performance optimization.

    I will do some further mobile testing and see if there are any performance limitations on your typical mobile device
     
  13. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    It actually already does this - all you have to do is make sure none of your Deformer objects have "restoreTerrainOnExit" unchecked and any changes done during runtime will be persisted to the terrainData object thus making the changes permanent. The current downside to this is that I do not inject runtime changes into the editor undo stack so ctrl + z would not allow you to rollback the runtime changes. I may try to add this in the near future if more people want to use the tool as a pseudo editor.
     
  14. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    Yeah I had not considered this use case. I haven't used multiple terrains before in the way you are, but I know you are not alone in this approach so I am glad you brought this up. I will see if I can duplicate and come up with a fix in the near future.
     
    ftejada likes this.
  15. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    573
    hello kevin, how big is the terrain you are testing with, how is the impact on the framerate relating to the amount of morphing
     
  16. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    I am aggressively looking for ways to improve the alphamap updates (texture painting) as the performance there is also important for the game I am developing which uses this tool. I am starting to fear that the problem lie within Unity itself, but any improvements I can make within the library to negate that I certainly will.
     
  17. tequyla

    tequyla

    Joined:
    Jul 22, 2012
    Posts:
    335
    hello,

    is possible to use library object like house, pillar or something more and put them on the world ?

    ++
     
  18. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    I am assuming you mean creating a flat place for a house to be spawned in and sit naturally on top of. Yes, you could use a combination of adding or subtracting terrain height and smoothing while using the objects transform to script appropriate positioning. Several people have asked about this, so I will put it on my todo list to add it as a built in function of the library.
     
  19. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi! I care a lot buy their asset and in a few weeks. Long waited something

    I also join the call for the asset in the work inspector but as a medium-term future because I prefer to focus on improving performance as much as possible and add more features at runtime.

    Now I would like to know something about your asset before buying ...

    I basically what I want is for my game the character can dig hidden treasures in the world, etc ...
    I use TerrainComposer2 and RTP to build procedural terrains,

    1º Is there any problems or incompatibility?

    2º When the texture is changed at runtime, I can use two features at a time with your asset? For example, do subtract and change the texture of the hole at the same time?

    3º What quality, (difuse, normalmap, specular ...), I can put in the textures his asset changes?

    I quite concerned about the impact on performance when changing textures at runtime ...
    4º What you plan to do about it?

    regards
     
  20. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    1. As long as the terrain is a Unity terrain object it will work fine. I believe TerrainComposer2 and RTP both just modify standard unity terrain objects.

    2. Yes, per frame you can combine the calls using the deferred versions of each function (Subtract() instead of SubtractNow()) and then call SetHeights() or SetAlphas() when you are ready to commit the changes to the terrain.

    3. The library just adjusts the textures already added to the terrain object. Things like difuse, normalmap, specular are all configured at the time you add the texture to the terrain. When you select the terrain in the inspector and click on the texture tab you will see a small list of thumbnails for each texture you have added. Dynamic Terrain Objects works with these via their respective index: 0 is the first texture on the left, 1 is the second, etc, etc. In the future I would like to display the thumbnails within the Deformer script to make it even more intuitive, but for now you just specify which you want to update via index (can also update this run time via code)

    4. Real time texturing is still quite usable in my opinion, its only when you are writing textures to the terrain every single frame that I see a bit of FPS drop. I am working hard to profile the code and determine what improvements can be made on my end.
     
  21. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Thanks for answering
     
  22. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    Version 1.1 was just accepted to the Asset store which fixes the problem with deforming terrain along the edges.

    Here is the full change log:

    • Added new Deformer command: Flatten... raises or lowers terrain to specified height between the top and bottom of the deformer. Can choose to raise just points where the deformer intersects with the terrain or the entire area of deformer + area padding
    • Added option to use delayed LOD version of SetHeights which increases performance considerably
    • Added terrain edge detection. Prevents errors when trying to use a deformer near the edge of a terrain or off of the active terrain.
    • Improved smoothing algorithm to allow a greater amount of smoothing per operation.
    • Renamed "Displace()" to "Embrace()" and improved its functionality. Use for creating volcano like shapes or simply perching an object on a hill. A true Displace that will make accurate crater like shapes will be added in the next update.
    • Made Columns not lookup their terrain height unless explicitly told to - improves performance.
    • Remove some unused constructors and general code cleanup
    • Misc bugfixes and performance improvements
     
    ftejada likes this.
  23. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    Hi !!
    To will be completed when all documentation (Area, Local HeightMap, LocalAlphaMap, Vertex, Column, etc)?

    regards
     
  24. orvedal

    orvedal

    Joined:
    Nov 10, 2015
    Posts:
    47
    Works fine in the demo, but after following the setup to the letter for my own project i walk around hammering the deform button and it will only work like 3% of the time, like hardly ever... either i'm doing something wrong or this is not very good. i either need help or a refund. Also, when it does work, the deformation is just rough triangulation of the objects location, there is no shape to the deform....
     
  25. orvedal

    orvedal

    Joined:
    Nov 10, 2015
    Posts:
    47
    Please tell me more about the relationship between Terrain width and length and your algorithms. You do not explain in your documentation that the either the heightmap resolution or the texture resolutions need to be the same as these. after playing around with these numbers I have achieved a more desirable result but i need to adjust an existing terrain accordingly without wiping out the existing data.
     
  26. orvedal

    orvedal

    Joined:
    Nov 10, 2015
    Posts:
    47
    at a terrain width and length of 2048 you need 4097 height map, now i can finally deform everywhere i want... is this how I should be doing it or am i missing something still?
     
  27. zmaxz

    zmaxz

    Joined:
    Sep 26, 2012
    Posts:
    143
    I get a error in unity 5.5 .
    Assets/DynamicTerrainObjects/Deformer.cs(102,9): error CS0103: The name `Profiler' does not exist in the current context
     
  28. ftejada

    ftejada

    Joined:
    Jul 1, 2015
    Posts:
    695
    It seems that the author has not answered since 6 august. A pity! I was interested in this asset but I no longer believe that I buy it because of what seems like a bad support.

    regards
     
  29. SuperNewbee

    SuperNewbee

    Joined:
    Jun 2, 2012
    Posts:
    195
    Can anybody confirm if this is working in 2017 and with RTP?
     
  30. VizII

    VizII

    Joined:
    Mar 22, 2013
    Posts:
    5
    No matter what the status of restore on exit is all changes are preserved. I am using the plugin with Oculus Touch, Deformer.cs is attached to a sphere.
     
  31. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577
    Hi i have couple of problems.
    First is that when you edit terrain, then you recompile while app is running, it will reload the assembly and leave the terrain in the state it was on runtime, tada - data corruption. I would like to tear off any ability of your asset to do data corruption, i dont need the changes to persist in edit time.

    Next is a very weird lag the more you edit the terrain, which i havent found source yet, but it appears your asset can generate tremendous amounts of garbage per frame.
    Ok this lag comes from when you have `Keep updated` due to lod not recalculating (or something)

    However it doesnt work at all if keep updated is disabled.

    What i forgot to SetHeights() ??
    nope, i didn't

    Code (CSharp):
    1. internal override void OrderedUpdate() {
    2.  
    3.         base.OrderedUpdate();
    4.  
    5.         if (ActiveTool != null) {
    6.  
    7.             if (Input.GetKey(KeyCode.Escape)) {
    8.                 ActiveTool = null;
    9.                 SetBrushActive(false);
    10.                 return;
    11.             }
    12.  
    13.             ActiveTool.UpdatePosition(ActiveBrush.transform, GetGroundMousePosition());
    14.  
    15.             ActiveTool.Negate = false;
    16.  
    17.             if (Input.GetKey(KeyCode.LeftAlt)) {
    18.                 ActiveTool.Negate = true;
    19.             }
    20.  
    21.             if (Input.GetKeyDown(KeyCode.Mouse0)) {
    22.                 ActiveTool.Use(ActiveDeformer);
    23.             }
    24.  
    25.             ActiveDeformer.SetHeights();
    26.         }
    27.  
    28.     }
    Ok it seems its how it was meant to be, i assumed you dont need to keep it updated, because that is what documentation says, but well.

    Man...


    What is this -
    1. Drop the deformer in scene - doesnt work , produces some crap on the terrain like a small dot that is offset far from deformer
    2. Literally SELECT it in hierarchy, nothing more, just select
    Works.

    ????????????????

    Kek it seems its purely random. Sometimes it wokrs, sometimes it doesn't.
    Why cant it just work...
    It somehow manages to fix itself if i manually enable Convex on mesh collider, then disable,
    in code - nope.
    Wtf? What exactly in the mesh collider may possibly force your asset to work?

    OOh i get it now.
    After each change of collider geometry, scale in my case, you need to call `Init()` on it
     
    Last edited: Aug 10, 2017
  32. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    577
  33. TonanBora

    TonanBora

    Joined:
    Feb 4, 2013
    Posts:
    493
    Works in 2017, not sure about RTP though.

    @Jrodz
    How hard do you think it would be to integrate this with uNet?
     
    Last edited: Nov 20, 2017
  34. TonanBora

    TonanBora

    Joined:
    Feb 4, 2013
    Posts:
    493
    Well, yah, of course you're going to get data corruption if you modify scripts while they are running... :p
    If you don't want this to happen, then don't modify scripts while they are being executed. I think it is rather unfair to blame the developer for this, as it is generally a bad idea to modify scripts during run time anyway (precisely because it can lead to data corruption), unless you are using an Engine that supports that (which Unity obviously does not) .
     
    Last edited: Nov 20, 2017
  35. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    I haven't done any multiplayer stuffs with the library, but I would imagine you could just have an entity with the Deformer script on each client and then have it send the same messages to each to keep the terrain modifications in sync.
     
  36. magicbananna

    magicbananna

    Joined:
    May 9, 2013
    Posts:
    22
    When you get an error like this Highlight the error and click resolve. It will tell you what is wrong.. In this case
    make sure you have a using statement:

    using UnityEngine.Profiling;
     
  37. magicbananna

    magicbananna

    Joined:
    May 9, 2013
    Posts:
    22

    It is a bastard to integrate with unet. I gave up after about 10 hrs lol.
     
  38. TeemuMV

    TeemuMV

    Joined:
    Nov 10, 2017
    Posts:
    19
    @Jrodz When terrain transform Y position is set to negatives, the deformers seem to act weird, to me at least.

    Repro steps:
    * Create terrain with height 10, flatten it to 5, set its Y position to -5.
    (This is necessary so the terrain can be both lowered and raised beyond the default level, while maintaining a clean zero Y as the default ground level.)

    * When a deformer GO is placed at the terrain level, it modifies the terrain weirdly. Tested with Add() (pictured,) Subtract(), and Embrace().



    Additional info:
    * The operations work fine if the terrain's Y position is positive.
    * Using an empty GO as the parent of the terrain/deformer and offsetting that way doesn't change the behaviour.
     
    Last edited: Dec 21, 2017
  39. Jrodz

    Jrodz

    Joined:
    Apr 8, 2014
    Posts:
    29
    @TeemuMV thanks for pointing this out... I will take a look as soon as I can and see about getting a fix out
     
  40. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    hey,

    the demo is not working. do you have another link?

    thanks in a advance
     
  41. visualjump3d

    visualjump3d

    Joined:
    Jun 6, 2014
    Posts:
    14
    How i can activate the second terrain ? ( runtime )
    Thank You
     
  42. magicbananna

    magicbananna

    Joined:
    May 9, 2013
    Posts:
    22
    I have a function on my character that keeps track of what terrain it is on using raycast, Then in the deformer.cs Awake() function I use this. I use it that way because the deformer object is instatiated when needed.

    Code (CSharp):
    1. if (this.terrain == null)
    2. {
    3.  this.terrain = GameObject.FindGameObjectWithTag ("Player").GetComponent<CharacterInteraction> ().tez;
    This will only work when using instatiated deformers though.
     
  43. GamePyro-com

    GamePyro-com

    Joined:
    Jul 28, 2018
    Posts:
    197
    Hello

    is there a way use this also in editor moder or set object to shape / flatten terrain when at the script to the object.

    need something like your asset for houses / buildings at mountains / hills and roads and so on.

    for this problem for example :
    https://i.gyazo.com/41de42fb53c8c05ecd60d2222511d861.png

    or know you or anybody here an other asset or good way to tat in editor automatic at every object road building etc where a script with a function us added to automatic shape / flatten.?

    also can player save changes and next time he play changes are loaded ?

    last update long ago are you still here ?

    regards
     
    Last edited: Sep 2, 2018
  44. GamePyro-com

    GamePyro-com

    Joined:
    Jul 28, 2018
    Posts:
    197
  45. roimil

    roimil

    Joined:
    Nov 17, 2017
    Posts:
    7
    hi i see that the sphere deform the terrain only if it's with a large scale (X20) in your test scene.
    is it possible to use it on a X1 scale ?
     
  46. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    it's can be nice tool