Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

MapMagic 2 - infinite procedural land generator

Discussion in 'Assets and Asset Store' started by Wright, Apr 24, 2020.

  1. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    941
    Hello, just started using this tool last week and so far it's quite impressive.

    However, I've been having some issues. I'm trying to create a map preview that allows the player to supply a seed and see what the results will be before committing to that map. To do this I am disabling infinite generation and manually pinning the tiles that should be visible via code and then starting the generation. This works fine as long as I am pinning only draft tiles. However it fails when I pin both the draft and main tiles for the final map generation. The first time it generates things seem fine but if the user attempts to regenerate the map after that it throws an exception.

    Here is the stack trace

    Code (CSharp):
    1.  
    2. Den.Tools.Tasks.ThreadManager.LaunchThreads () (at Assets/MapMagic/Tools/ThreadManager/ThreadManager.cs:116)
    3. Den.Tools.Tasks.ThreadManager.Enqueue (Den.Tools.Tasks.ThreadManager+Task task) (at Assets/MapMagic/Tools/ThreadManager/ThreadManager.cs:80)
    4. MapMagic.Terrains.TerrainTile.StopEnqueueTask (MapMagic.Terrains.TerrainTile+DetailLevel det, MapMagic.Nodes.Graph graph, System.Int32 priority, System.String name) (at Assets/MapMagic/Terrains/TerrainTile.cs:680)
    5. MapMagic.Terrains.TerrainTile.StartGenerate (MapMagic.Nodes.Graph graph, System.Boolean generateMain, System.Boolean generateLod) (at Assets/MapMagic/Terrains/TerrainTile.cs:618)
    6. MapMagic.Terrains.TerrainTile.Dist (System.Single newRemoteness) (at Assets/MapMagic/Terrains/TerrainTile.cs:358)
    7. MapMagic.Terrains.TerrainTile.Move (Den.Tools.Coord newCoord, System.Single newRemoteness) (at Assets/MapMagic/Terrains/TerrainTile.cs:343)
    8. MapMagic.Core.TerrainTileManager.Pin (Den.Tools.Coord coord, System.Boolean asDraft, UnityEngine.MonoBehaviour holder) (at Assets/MapMagic/Terrains/TerrainTileManager.cs:36)
    9.  
    It specifically fails on line 116 because GetMaxPriorityNum returns -1. It seems that the is a single element in queue but its priority is set to int.min which means GetMaxPriotityNum always 'fails'. My guess is that the task in the queue has actually completed but isn't getting cleared properly. This only seems to happen when I manually Unpin and Pin tiles myself via code. Any suggestions for what I may be doing wrong? I tried calling the StopGeneration() method on the map object before changing pins but that doesn't work (on a side not, StopGeneration should *really* be a public method I am thinking).
     
  2. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    My previous post was to make sure I'm starting at the right foot with using MM2.

    With basic coding, I was able to get a node, change its properties, add a new node to graph at runtime.
    I used pyramid Simple form and holes nodes to make a hole.

    As for my real questions:

    -What is the proposed method for adding multiple holes to terrain?
    Our custom class decides where to and how many holes I'll need on a terrain. But I'm not sure what is the best way to add unknown amount of holes to a terrain with MM2.
    Just add / remove nodes and maintain the graph?
    or use a Loop node somehow? (I didn't check it in code) How would I change a node' properties for each iteration?

    -How can I make a rectangle shape? Pyramid gives a square but only has one scale property.
    I'd use import node but my rectangle hole shapes are runtime generated.

    -While using splines to flatten some areas on my terrain with a shape that is across terrain tiles.
    I notice some seams at tile edge. They don't correct themselves with rendering twice.
    I can change some setting to make it less visible.
    Is this why splines module is still in beta? Any estimates on release date?


    upload_2023-8-10_20-40-10.png

    upload_2023-8-10_20-40-28.png

    upload_2023-8-10_20-40-52.png



    -Are there any nodes that I should beware while using in code?
    I don't want to mess out MM2 generation (especially timing)

    -We'll need linear interpolation between spline points. When using splines to put out a shape. What is the proposed way to get a flat, linear interpolation between points?

    Thanks for your time.
    Cheers!
     
    Last edited: Aug 11, 2023
  3. mailfromthewilds

    mailfromthewilds

    Joined:
    Jan 31, 2020
    Posts:
    217
    MICROSPLAT node works for me as if it was static. Meaning Graph1 and Graph2 wont store their own microsplat settings. When I change between graph1 and graph2 the microsplat material doesnt change. It seems these settings are stored in the Gameobject's MAPMAGIC component.

    Is that the result of a bug or of design? It would be very convenient for users if it changed along with graph.
     
  4. Bill-Leee

    Bill-Leee

    Joined:
    May 12, 2015
    Posts:
    3
    Hello, my quest to make an Open World infinite terrain brought me to The Map Magic2 Bundle and combined with VS Pro it looks pretty and with promise. It seems that they work together as long as you stick to one Biome, I'm using Unity 2019.4.1. I'd like to ask people on the forum if anyone can recommend an AI Spawning system that works with Map Magic and VS Pro. I've been trying to get Crux to be of service, which can be at times but is really flakey IMHO. I can get it to spawn but only when the Terrain property is set to Mesh. Any suggestions for an AI spawning system for MM2 or advice about it is appreciated.
     
  5. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    This is really strange. Just tried to re-create this, but it seem to be working. What about splines demo scene, is it working for you?

    Can you try this preview shader? (MapMagic/Preview/Editor)

    These kind of seams might occur for simple graphs, when tile is calculated faster then the other one started. It's editor-only issue that should not occur in playmode, and happens only on graph change. Does it happen in playmode in your case?

    Pinning in runtime is not a good idea, it was designed as editor-only tool. Instead you can use standard generate, but instead of generating around camera use one anchor object with specified tag.

    You mean cut-outs in terrain or pits on it's surface? Anyways you'll need a map for those holes, and the easies way to create it would be using objects and then applying stamp to paint. If you need specific positions for objects you can use Positions node (and specify positions with script).

    Hmm, I can see your use case. Shapes in Simple Form are really uniform, but for some cases we might need them to be rectangular or oval. I will think of how to make this for the next version.

    Exactly it's the main reason splines couldn't be called complete - and it's not about splines actually, it's mostly caused by the way MM works. There can't be a simple fix, but I'm trying to find a way.

    By enabling Debug Mode in Window-MapMagic-Settings you will have a debug menu in each of the nodes, where you will see a generate time this node takes for draft and for main terrains.

    Could you please clarify what exactly do you need? What kind of result this interpolation return? Should it be point on a spline (i.e. you want to divide spline segments), or you want to stamp it on terrain? How should lerp work?

    I see. Compatibility with other assets is mostly 'as is', but I will try to look into it, however I can't promise it will be soon.

    Unfortunately I have no experience of working with Crux, but just in case - you can spawn objects with MM. And it can be not only trees or stones, you can spawn NPC or animals the same way.
     
    Bill-Leee, gurayg and Sluggy like this.
  6. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    By enabling Debug Mode in Window-MapMagic-Settings you will have a debug menu in each of the nodes, where you will see a generate time this node takes for draft and for main terrains.
    Exactly what I needed !


    Could you please clarify what exactly do you need? What kind of result this interpolation return? Should it be point on a spline (i.e. you want to divide spline segments), or you want to stamp it on terrain? How should lerp work?


    upload_2023-8-15_11-13-12.png


    Thanks for your reply @Wright
    I tried to show my use case here. I added line renderer where the spline is, white spheres are points in "Manual" node. I added "Get by tag" and "Stamp" with "Simple Form" for putting some holes in terrain tiles.

    upload_2023-8-15_11-17-15.png

    There seems to be some problem with this setup. There are no holes in neighboring terrain tiles.
    Also there is a gap in one of the tiles (hard to see, it' near the right most green box) This screenshot is at runtime.

    upload_2023-8-15_11-40-43.png



    After your reply, I think I'll upgrade this setup to using "Positions" node but I see it only takes a single Vector3 for position.
    I took a look at your code. "Transition" class seems to have another Vector3 for scale.
    Maybe, I can copy your Position node' code and add scale to it.
    Or if you decide to add rectangle support to "Simple Form" maybe I can go from there.

    Anyways, if you decide to add Rectangle to Simple Form, would you also consider adding gradients in opposite direction? Like "Gradient -X", "Gradient +X". If that' not too much to ask.

    As for my spline use case: Our playing area is only where the spline is. I need splines to shape the terrain and be linear from point to point. No Bezier or any other spline smoothing. But if you're asking for blend range and fallout areas, those are already more than good for me.

    I don't know what is causing problems in MM' core but I do hope you find a solution.
    Cause this project is great, solid and promising.

    Cheers
     
    Last edited: Aug 15, 2023
  7. Bill-Leee

    Bill-Leee

    Joined:
    May 12, 2015
    Posts:
    3
    Thanks for your reply as well @Wright, indeed the Map Magic Objects node would be great to use here. It does spawn my AI NPC but it brings up a more general question about using the node; Is there a method to have the spawning of significant objects take place closer to the player in a more controlled yield? I'm wondering if the Rarer node is of use for this, or is there something else to look at for this?
    thanks again for making this.
     
  8. unity_Ea0raybWi2x2QA

    unity_Ea0raybWi2x2QA

    Joined:
    Sep 21, 2020
    Posts:
    4
    Hello, I am using the code below to gather an index to use for choosing which footstep sound to play:

    Code (CSharp):
    1.     //Get terrain and hit point from raycast hitting a terrain
    2.     private void CheckTextureOnTerrain(Terrain terrain, Vector3 hitPoint, Vector3 footPos)
    3.     {
    4.         Vector3 terrainPosition = hitPoint - terrain.transform.position;
    5.         Vector3 splatMapPosition =
    6.             new Vector3
    7.             (
    8.                 terrainPosition.x / terrain.terrainData.size.x,
    9.                 0,
    10.                 terrainPosition.z / terrain.terrainData.size.z
    11.             );
    12.  
    13.         int x = Mathf.FloorToInt(splatMapPosition.x * terrain.terrainData.alphamapWidth);
    14.         int z = Mathf.FloorToInt(splatMapPosition.z * terrain.terrainData.alphamapHeight);
    15.  
    16.         float[,,] alphaMap = terrain.terrainData.GetAlphamaps(x, z, 1, 1);
    17.  
    18.         //primary index mostly stays at 0,
    19.         //no matter the texture stepped on,
    20.         //on procedurally spawned terrains.
    21.         //alphaMap.Length is 5,
    22.         //which is the correct amount of texture layers,
    23.         //as found in the microsplat terrain material
    24.         int primaryIndex = 0;
    25.         for (int i = 1; i < alphaMap.Length; i++)
    26.         {
    27.             if (alphaMap[0, 0, i] > alphaMap[0, 0, primaryIndex])
    28.             {
    29.                 primaryIndex = i;
    30.             }
    31.         }
    32.        
    33.         //Use the index as FMOD parameter value, to play footstep sfx
    34.         CheckIfStepOrLand(primaryIndex, footPos);
    35.     }
    I am using microsplat with map magic 2, and this works flawlessly on manually created terrains. It gives me the correct index corresponding to the texture shown on the microsplat material editor. But it doesn't work that well with procedural terrains spawned in with map magic. Usually the index will show as 0 no matter what texture the player is stepping on, the debug logs shown in the code all give 0. The exception to this is the alphamap.length debug.log, which returns a count of 5, and in the microsplat terrain editor there are 5 textures stored, so this is expected. So it seems like it knows how many textures there are, but don't know which these textures are, or can't read them on the alphamap.

    Now, as I have understood it, you need to set apply type on the microsplat output in the map magic object to "apply both" to generate standard splat maps, as these are necessary. And if I am correct, this should make the procedurally spawned terrains data be readable the same way as any standard unity terrain data would. These are the settings on the microsplat output:



    Here's the catch; Sometimes the code will work on the terrain on which the player spawns. I don't believe it's connected to it being the spawning tile, but rather that I somehow luck out, and some of the tiles actually spawn terrains (which happens to be the tile I spawn on every now and then) that have working terrain data, that gets read correctly. When I try stepping on other terrains though in the same procedural map, they won't work as usual, returning 0 no matter the texture stepped upon. This leads me to believe there's something inconsistent about how the splatmaps are generated, and how they get the required data, but I am unsure, I haven't been able to figure out why this is happening after trying for a good while.
     
  9. DancingZombie

    DancingZombie

    Joined:
    Mar 4, 2018
    Posts:
    6
    update - I found what was causing the issue, resolution downscale was set to 0

    I am getting the following error when using the grass node, not sure if this is an issue with unity or GrassOut script.
    grass node is linked to grass texture node, I have also used grass node connected to noise node and error occurs.
    I have used mesh unlit and grass modes with this issue occurring.

    Thread failed: System.DivideByZeroException: Attempted to divide by zero.
    at MapMagic.Nodes.MatrixGenerators.GrassOutput200.CreateDetailLayer (Den.Tools.Matrices.Matrix matrix, Den.Tools.Matrices.Matrix biomeMask, System.Single density, System.Int32 randomNum, MapMagic.Products.TileData data, MapMagic.Products.StopToken stop) [0x0000d] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Generators\Matrix\Runtime\GrassOut.cs:100
    at MapMagic.Nodes.MatrixGenerators.GrassOutput200.Finalize (MapMagic.Products.TileData data, MapMagic.Products.StopToken stop) [0x00079] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Generators\Matrix\Runtime\GrassOut.cs:75
    at MapMagic.Nodes.Graph.Finalize (MapMagic.Products.TileData data, MapMagic.Products.StopToken stop) [0x0002b] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Nodes\Graph.cs:988
    at MapMagic.Terrains.TerrainTile.Generate (MapMagic.Nodes.Graph graph, MapMagic.Terrains.TerrainTile tile, MapMagic.Terrains.TerrainTile+DetailLevel det, MapMagic.Products.StopToken stop) [0x00070] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Terrains\TerrainTile.cs:725
    at MapMagic.Terrains.TerrainTile+<>c__DisplayClass50_0.<StopEnqueueTask>b__0 () [0x00000] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Terrains\TerrainTile.cs:677
    at Den.Tools.Tasks.ThreadManager.TaskThreadAction (Den.Tools.Tasks.ThreadManager+Task task) [0x00000] in E:\Unity Projects\MagicMap2\Assets\MapMagic\Tools\ThreadManager\ThreadManager.cs:138
    UnityEngine.Debug:LogError (object)
    Den.Tools.Tasks.ThreadManager:TaskThreadAction (Den.Tools.Tasks.ThreadManager/Task) (at Assets/MapMagic/Tools/ThreadManager/ThreadManager.cs:144)
    System.Threading.ThreadHelper:ThreadStart ()
     
    Last edited: Aug 18, 2023
  10. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    @Wright this error also occured on the "heights" node
     
  11. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    I get this too ... instead create an async wait state for mapmagicobject.isgenerating to go away
    StopGeneration is quite useful for me btw... :p

    edit : here i hope this helps?


    Code (CSharp):
    1.  
    2.     public static async Task<bool> WaitForActualCompletionAsync(float duration = 10000f)
    3.     {
    4.         float TimeoutDuration = duration;
    5.  
    6.         float startTime = Time.time;
    7.         bool isActuallyDone;
    8.  
    9.         while (true)
    10.         {
    11.             isActuallyDone = true;
    12.  
    13.             foreach (var item in MMWorldCustomBaseData.currentSceneMMObject.tiles.pinned)
    14.             {
    15.                 var test = !item.Value.IsGenerating;
    16.                 if (!test)
    17.                 {
    18.                     isActuallyDone = false;
    19.                     break;
    20.                 }
    21.             }
    22.  
    23.             if (isActuallyDone)
    24.                 break;
    25.  
    26.             // Add a delay to prevent excessive polling (optional).
    27.             await Task.Delay(100);
    28.  
    29.             // Check for timeout and handle it.
    30.             if (Time.time - startTime > TimeoutDuration)
    31.             {
    32.                 Debug.LogWarning("WaitForActualCompletionAsync: Timeout occurred.");
    33.                 return false;
    34.             }
    35.         }
    36.  
    37.         return true;
    38.     }
     
    Last edited: Aug 17, 2023
  12. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    hi....

    im not 100% sure, but i think that the slight variations you get in the terrains is unavoidable if you have different clients generating the terrain independantly (side note : that does not seem authorative to me?)

    anyhow.. i think @Wright explains why here :
    https://gitlab.com/denispahunov/mapmagic/-/wikis/Brush/ResolutionCompliance

    all maps have a slight variance chance because of this.
    Its really small but definately enough to cause exactly the issue i think you are explaining?
     
  13. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    Yes, unfortunately that's why splines are still in beta. There are cases they can't pass from one tile to another. I'm thinking of the way to solve this, but it's not easy.

    There are several ways to invert map. You can use Contrast node with contrast -1, or levels with inversed input values:
    upload_2023-8-20_19-46-6.png

    But isn't spline initially created this way, after Interlink or Manual?

    Rarefy node is part of a node graph, and node graphs don't know anything about player position. Instead I think it would be better to spawn dummy object with a special script that will read player position, and decide when to span and what.

    For this use case take a look at Direct Matrices output, or maybe Direct Textures if you find working with textures more convenient.

    Could you please email me your graph?

    So - this is why it's intentionally made private. It was not designed to be used this way :)

    If I understand the problem correctly it's not related with resolution. It's either accumulated floating point error or the way Unity applies heightmap to terrain. Will try to fix it in first case, or let Unity know in second.
     
    gurayg likes this.
  14. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    I see. I'll be waiting for Splines to go out of beta then. Hope it won't take long.

    Thanks. I knew that trick. What I meant was: if you decide to add a "Rectangle" shape to "Simple Form" maybe you can also consider adding those. they would only save a node but less clutter in schematic is good right :)

    They seem that way. I haven't made tests beyond what you saw. I stopped when I encountered spline + terrain tile issues. I was just trying to show my use case.

    Thanks for the answers.
    I'll be holding my breath for the next update. Good luck!
     
    Last edited: Aug 20, 2023
  15. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    941
    @Wright
    I've found a work around for not using pins by simply sticking a dummy object in the middle of the map with a tag that the MapMagicObject tracks. I didn't realize that you could have infinite generation turned off and still utilize the tag/camera tracking.

    But I am still having a ton of problems with previewing the map for users. It's a fairly small map, only about 5x5 tiles. For the preview I force the resolutions to the lowest value of 33 before generation. And then allow them to change the seed before generating a new map to preview. Once they select the map it puts the resolution back to the correct values before generating. Usually it works, but very often it also hard crashes the entire unity engine. What exactly would be the recommended way of handling this scenario that is more reliable?

    EDIT:

    By the way, here's the code I was using.
    Code (CSharp):
    1.  
    2.             Map.StopGenerate();
    3.             Map.Refresh(clearAll: true);
    4.             //Map.ApplyTileSettings();
    5.             Map.tiles.ReDeploy(new Vector3(Map.tileSize.x, 1, Map.tileSize.z), Map.tiles.pinned, Map);
    6.  
    Originally I was using ApplyTileSettings() but this seemed to cause a lot of instability, leading to editor crashing a lot. Switching to ReDeploy() helped somewhat but there are still a lot of issues. For example, if I move the mouse or touch the keyboard (even if nothing is happing gameplaywise) during the initial map generation this will often lead to crashes to the desktop.
     
    Last edited: Aug 21, 2023
  16. brenchleyderek

    brenchleyderek

    Joined:
    Sep 20, 2019
    Posts:
    4
    Hello! Really impressive product, but I am embarrassed to admit that I have an easy scripting question. I'm trying to access the nodes via script to either enable/disable them or change values within the node. I've gone onto the wiki and saw this:

    • Execute mapMagicObject.graph.GetGenerator(g => g.id==12345) will return this generator as Generator type
    • cast this generator to it's original type to get access to it's variables. I will probably add mapMagicObject.graph.GetGeneratorById(12345) to simplify this in next versions, but this call will remain as well.
    Here is what I have so far:
    Code (CSharp):
    1. MapMagicObject mapMagic = FindObjectOfType<MapMagicObject>();
    2.  
    3. Generator erosion = mapMagic.graph.GetGeneratorbyID(7204879794490572803);
    4. erosion.enabled = false;
    This doesn't work, and I'm not sure how to cast this generator to its original type or access erosion's variables (such as iterations, sediment, fluidity, etc.). Any help for a coding beginner would be very helpful!
     
    Last edited: Aug 22, 2023
  17. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    i had issues with disabling generators not making a difference too....
    I started looking into the links themselves because you can nullify a generator nodes output by having no connections, but this does not stop functions - which do whatever they want - if one is on a graph it seemingly owns that graph and you can do nothing about it... @Wright ?
     
  18. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    @Wright I am attempting to cache a matrixworld to a variable just to bring it back and upscale it on the same tile later...

    This works if i scope to mm only, giving me exactly the output i expect,

    but i am getting a very odd error if I do this and there are microsplat outputs on the graph ...
    and im not sure how to deal with this:

    upload_2023-8-25_12-50-20.png

    related : ive been working with the import / export heights functions because of this, it does not seem that there is any return types for your c++ native ran versions of these providing an efficient route to import / export with c++ leaving us to creating a slower c# custom solution for this step, or am i missing something, which im sure i am...
     
    Last edited: Aug 25, 2023
  19. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146

    heres a snippet from code in my project that grabs a function node - and casts it - and enables the inner generators


    Code (CSharp):
    1.  
    2.         Generator biomeSeedGeneratorNode = MMWorldCustomBaseData.currentSceneMMObject.graph.GetGeneratorById(18052542766872788993);
    3.  
    4.         Function210 bsgn = (Function210)biomeSeedGeneratorNode;
    5.         if (bsgn.enabled == false)
    6.         {
    7.             foreach (var item in bsgn.subGraph.generators)
    8.             {
    9.                 item.enabled = true;
    10.             }
    11.             bsgn.enabled = true;
    12.         }

    To get the cast type to cast to : .... IF its working properly for a given node you can right click any mm native node and goto generator -> GoToCode and it should take you to the point in the code where you can find out what each nodes class actually needs to be casted to fairly easily.
     
    Last edited: Aug 25, 2023
  20. jpileborg

    jpileborg

    Joined:
    Jan 5, 2013
    Posts:
    30
    I'm sure this has been asked before, but it's not easy to find among the 50 pages of messages... So apologies!

    Is there a way to blend or mix MM2 with existing terrain? Lets say I want to create some terrain with extra details, using perhaps something like MicroVerse, and then integrate it in a larger (but less detailed) world generated by MM2. Will it be possible? What kind of nodes are needed for that mix/blend/integration?

    Or should I generate the world, pin the tiles that I need to work extra on, and use the other tools (again like MicroVerse) on those specific tiles only?
     
  21. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    I think the best solution would be here is using 2 MM objects - one for low-res, one for full resolution. Only one of those objects should be enabled at a time.

    This won't have an effect unless you will re-generate all of the land. Just disabling generator will not remove erosion from already generated tiles. In case you tried to re-generate all the land - does disabling erosion not taking effect happens in build or editor? And in editor in playmode or editmode?

    Try disabling native C++ libraries (Window - MapMagic - Settings). Probably it won't fix it, but at least it will write the right error instead of empty one.

    The second way will work - you can generate big land with MM, use Lock to prevent some area on a pinned terrain from changes, and edit this area the way you want with (probably) any tool you like.
     
    jpileborg likes this.
  22. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    I been here a while fairly consistently...
    Trust me when i say : Everyones first impulse is to import from whatever other tool they were using.

    I dont wanna be the one to say thats wrong, because importing makes plenty sense in several scenarios, but usually... usually... especially when its someone who picked up MM2 as a new asset, it is most likely not the approach your looking for...
    Welcome to map magic, dig in to the depths of it for a few days and see whats actually possible.
     
  23. unity_Ea0raybWi2x2QA

    unity_Ea0raybWi2x2QA

    Joined:
    Sep 21, 2020
    Posts:
    4
    Hey, thanks for the reply. :)

    I have successfully used matrices in conjunction with the biome node, to see how much of each biome is represented at the player position. I could of course use this to change the footstep sound depending on the values, but often a biome will consist of several textures, like rock, snow and gravel, and thus this approach is a tad too generic.

    Which of course leads me to believe that I am missing a use case here. I have tried routing the directmatricesholder node to the texture/microsplat output node, then getting the matricesholder at runtime, finally calling the "ValueAtPosition". The value does correspond to what texture the player is walking on (most of the time, sometimes it's 0 for some reason), but the value is very small, not all textures work though, only main ones like rock and snow, but not gravel (used for roads). Meaning, I am probably doing this all wrong.

    I have tried digging into what function I should call, how I should route the nodes, trying different things, but it seems I just don't get how I would get the very specific texture (or blended ones) the player is standing on at the time.
     
  24. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146

    just a bit more unity and less map magic reliance...


    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TextureIdentifier : MonoBehaviour
    4. {
    5.     public LayerMask groundLayerMask;  // Assign the layer(s) that represent the ground in the Inspector
    6.  
    7.     private void Update()
    8.     {
    9.         if (Input.GetMouseButtonDown(0))  // Replace with your preferred input method
    10.         {
    11.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    12.             RaycastHit hit;
    13.  
    14.             if (Physics.Raycast(ray, out hit, Mathf.Infinity, groundLayerMask))
    15.             {
    16.                 // You've hit the ground, now get the texture information
    17.                 Texture2D texture = GetTextureFromRaycastHit(hit);
    18.                 Debug.Log("You're standing on texture: " + texture.name);
    19.             }
    20.         }
    21.     }
    22.  
    23.     private Texture2D GetTextureFromRaycastHit(RaycastHit hit)
    24.     {
    25.         Renderer renderer = hit.collider.GetComponent<Renderer>();
    26.         if (renderer == null)
    27.         {
    28.             Debug.LogError("No renderer found on the collided object.");
    29.             return null;
    30.         }
    31.  
    32.         Material material = renderer.material;
    33.         if (material == null)
    34.         {
    35.             Debug.LogError("No material found on the collided object's renderer.");
    36.             return null;
    37.         }
    38.  
    39.         // You can get the texture from the material's main texture property
    40.         Texture2D texture = material.mainTexture as Texture2D;
    41.         if (texture == null)
    42.         {
    43.             Debug.LogError("No Texture2D found in the main texture property of the material.");
    44.             return null;
    45.         }
    46.  
    47.         return texture;
    48.     }
    49. }
    50.  
     
  25. unity_Ea0raybWi2x2QA

    unity_Ea0raybWi2x2QA

    Joined:
    Sep 21, 2020
    Posts:
    4
    Thank you, I do have something very similar to this working for non-terrain. But I still can't get the texture on terrains the way I need to using alphamaps or directmatrices.
     
    Greviouss likes this.
  26. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    160
    Is Map Magic still under development?

    I am encountering an issue with URP 14, Unity 2022.3.7

    The terrains generated with map magic are invisible in build, but not in editor. Also terrains that are created without map magic do show in build.

    Would you take a look at this please?

    edit: yeah well i tried to reproduce it in a clean project and I cant. Guess I'm stuck, I can't send you my own project because it's too big. I'm gonna go for terran to mesh for now.. Maybe you get some time to investigate this remotely sometime? Cheers!
     
    Last edited: Aug 31, 2023
  27. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    I believe you've already looked Direct Matrices link. Probably the best way to find what step sounds we should have is to use AllValuesAtPosition and then iterate KVPs to find one with the biggest value. If you have problem using it - could you please paste here your code?

    If you're enabling the terrains in runtime and have no tiles pinned, the shader might get stripped by Unity. Open Project Settings > Graphics and try to put the default Terrain Shader to the "Always included shaders" list.

    For standard render pipeline the shader name is Nature/Terrain/Standard, for HDRP - HDRP/TerrainLit. It could not be assigned by drag and drop from your project, so you'll have to click the object picker circle and select it from the list. (FAQ)

    Yes. I dived deep into re-making it for cluster system :)
     
    swantonb likes this.
  28. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    feature request...
    remove inline(?)
    a second remove option that relinks a generator with 10 out links (for example) to whatever is in line before it in the graph, if something is there, if alot of things are there default to the first one in the list...

    this

    upload_2023-9-1_2-42-40.png

    to this :

    upload_2023-9-1_2-42-55.png
     
  29. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    you could also implement an add inline on any given generator connecting it inline as the next generator and gathering all the current nodes out links (the inverse of the above)
     
  30. GreaserMonkey

    GreaserMonkey

    Joined:
    Feb 10, 2019
    Posts:
    65
    Hi. From time to time it seems that Map Magic 2 does not obey the settings on the inspector Trees, Details and Grass properties. I can for example reduce the tree distance setting to zero and nothing happens. It still draws the same amount of trees and it is same with the billboard distance setting for example. Could this be a bug with Map Magic 2 or something else? I'm using Unity 2022.3.5f1.
    upload_2023-9-3_21-5-55.png
     
  31. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    160
    Well that's not it because i put the terrain/lit default material that is used by unity in their default terrains (like when i create a new unity terrain) on the map magic generated terrains, along with literally one unity terrain. The unity terrain rendered (so the shader is in build) but the map magic terrains are invisible.

    Very strange :(

    Are there any other shaders than the URP Terrain Lit that map magic needs?
     
  32. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Hi, I am on MapMagic 2.1.12 and the MapMagic editor does not show any texture when I use the node IMPORT.
    I tried all formats possible (I think) and READ/WRITE is set to on.
    upload_2023-9-6_20-12-44.png
    upload_2023-9-6_20-13-8.png
     
  33. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Oh and when I click these buttons they get selected but they do nothing.
    In particular I wanted to SAVE A COPY of the actual terrain, so to have a different one as a base to edit something else.
    upload_2023-9-6_20-14-52.png
     
  34. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    I see. Probably it might be alternative to Delete or Unlink. Will think of the way to implement it best.

    This already works when you drag and drop plus button from top-right corner on an existing link.

    Didn't you notice when exactly it stops working? Do you have any error in the console before this? I'll appreciate if you could provide any information on how this could be reproduced.

    Do you have any tile pinned? If so - are they visible?

    Import node works with Matrix Asset, not with texture directly. You've got to convert texture or raw map to this asset to make it possible for MM to read (both in editor and playmode). You can find more info here: Import node.

    When you select Pin Tile you should see a tile frame highlighted under your cursor in scene view. When you click Save as Copy you can select pinned tile to be saved with this frame.

    If you don't see the frame on Pin Tile - check that you have gizmos enabled.
     
    PolyMad likes this.
  35. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    160
    Hey! Yes of course I do have terrain pinned and they show in editor, just not in build.
     
  36. SSL7

    SSL7

    Joined:
    Mar 23, 2016
    Posts:
    347
    Hey at @Wright, I m trying to access a scatter generator and change its seed inside a biome, I tried everything the documentation says but doesnt seem to work, I came up with this code which works but only for the main graph and not inside the biome:


    Code (CSharp):
    1. using UnityEngine;
    2. using MapMagic.Core;
    3. using MapMagic.Nodes.ObjectsGenerators;
    4.  
    5. public class NewSeedMM : MonoBehaviour
    6. {
    7.     private ulong PortalsScatterGreen;
    8.     private ulong ArenasScatterGreen;
    9.     private ulong EnemiesScatterGreen;
    10.  
    11.     private void OnStart()
    12.     {
    13.      
    14.     }
    15.  
    16.     private void OnEnable()
    17.     {
    18.      
    19.         //worldManager.worldManagerClass.SeedRandomizer();
    20.         //Need to be done for the rest of the biomes
    21.         //PortalsScatterGreen = 8913579138170748931;
    22.         PortalsScatterGreen = 120697789427482625;
    23.         ArenasScatterGreen = 10411599959341137943;
    24.         EnemiesScatterGreen = 10657501336846729255;
    25.  
    26.         MapMagicObject mapMagic = FindObjectOfType<MapMagicObject>();
    27.  
    28.         int newSeed = Random.Range(1, 99999);
    29.  
    30.         if (mapMagic == null)
    31.         {
    32.             if (Debug.isDebugBuild)
    33.                 Debug.LogError("seed - MapMagicObject not found!");
    34.             return;
    35.         }    
    36.  
    37.         Scatter200 scatterPortals = mapMagic.graph.GetGeneratorById(PortalsScatterGreen) as Scatter200;
    38.  
    39.         if (scatterPortals == null)
    40.         {
    41.             if (Debug.isDebugBuild)
    42.                 Debug.LogError("seed - Scatter200: " + scatterPortals + " with ID: " + PortalsScatterGreen + " for Portals not found!");
    43.             return;
    44.         }
    45.  
    46.         scatterPortals.seed = newSeed;
    47.  
    48.         if (Debug.isDebugBuild)
    49.         {
    50.             Debug.Log("seed - Generating new seeds for Scatters on Enable of NewSeed");
    51.             Debug.Log("seed - PortalsScatterGreen id: " + PortalsScatterGreen + " New Seed: " + scatterPortals.seed);
    52.         }
    53.     }
    Can you please tell me what I need to change to access the scatter inside the biome? I only need to randomize some objects in the scene and not the whole map (I use splines and need the graph to stay persistent other than this scatter).

    Also tried this code:

    Foreach (BiomesSet200 biomesSet in mapMagicObject.graph.GeneratorsOfType()) foreach (BiomeLayer biome in biomesSet.Biomes()) { if (biome.graph == myOldGraph) biome.graph = myNewGraph; }

    Without much success, if you can make an example on my code how to change a generator inside Biome 1 and 3 would be great.

    Thank you
     
    Last edited: Sep 7, 2023
  37. GreaserMonkey

    GreaserMonkey

    Joined:
    Feb 10, 2019
    Posts:
    65
    Unfortunately no. I just noticed from stats panel that triangles count was way higher than before. No errors in the console.

    Could this be caused by the vegetation assets?
     
  38. Tarmack

    Tarmack

    Joined:
    Dec 16, 2016
    Posts:
    12

    Sorry was hellah busy lately, but the problem is way more complexe, build target is Windows For Both Client and Server, Server is set as Dedicated Server Build, so it's basically headless, but that have no impact, we have made workarounds that work on our end, the clients actually don't do the Height generation stuff, and just download height from the server, and then apply it.

    But as said we have done a lot of investigations, and problem mainly seems to come from the DLL, and random generation involved within it, from the few things we had narrow down at past.

    It's been more than a month now from that, but if you want to organize a call or whatever, so we can show you the thing, would be with pleasure.

    We are the studio doing https://store.steampowered.com/app/1442910/Reign_Of_Dwarf/ if you have an interest in looking into it.

    we have made quite a few changes to the way your asset work, to fit our requirement, and i can say so far it's doing the job quite well.

    Would love to talk with you about evolution of the tool, or maybe even some sponsored features for the futur.
     
  39. User414322

    User414322

    Joined:
    Jul 9, 2019
    Posts:
    27
    Hello! I am new to Map Magic and wanted to ask some questions (I have read the documentation).

    1. World Machine has a feature called "shapes" (prev. "layout generator") that lets you (afaik) run a separate set of nodes inside of a polygonal area of your denomination. I find this to be very useful for landmarks within tiles, like a massive volcano or a mountain range cutting through an otherwise flat plain.
      I wish to know if Map Magic has such a feature.

      I know that "locks" exist, but (afaik) it seems like a destructive workflow, as it just locks the at-the-time state of nodes in place, rather than running a separate set. I imagine that if I use locks a lot, I might end up having problems if I ever decide to re-do any of my landmarks.

      I also know that biomes exist (and boy am I excited to try them out!) but it seems like they cover a much wider area (and would be harder to fine-tune into a very specific shape without a lot of nodes) than I have in mind.
      So yeah, does Map Magic have anything that can help me accomplish my goal of a non-destructive way of having a different set of nodes in a specifically designated area within a tile? Or any valid alternative. I plan on using the map's features to help balance the game, so the placement and flow of passable and impassable terrain is very important to me.

    2. Is it possible to use materials rather than textures for terrain?
    That's all. I feel like I am forgetting some additional questions, but all I can recall is really wanting that shapes tool.
    Thank you very much for this asset. I have used a lot of terrain generators (not that I am good with any of them) and yours is by far the most user-friendly of them all. I would call it 20 years ahead of its competition in terms of UX.
     
    Wright likes this.
  40. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    Unfortunately I could not reproduce the issue, for me terrain is quite visible. Does this happen with TutorialURP scene for you? Could you please make sure that you have TerrainURP material assigned as Material Template in MM object > Terrain Properties, and it has Universal Render Pipeline/Terrain/Lit shader.

    You've got to get your biome graph from mm object first, and then change it's seed (not main graph), or search for scatter node here. Try this code:

    Code (CSharp):
    1.             BiomesSet200 biomesSetNode = mapMagic.graph.GetGeneratorById(biomesSetId) as BiomesSet200;
    2.             Graph biomeGraph = biomesSetNode.layers[biomeIndex].graph;
    3.  
    4.             //if you want to change biome global seed
    5.             biomeGraph.random = new Noise(myNewGlobalSeed);
    6.  
    7.             //if you want to change scatter node seed only
    8.             Scatter200 scatterNode = biomeGraph.GetGeneratorById(scatterNodeIdInBiomeGraph) as Scatter200;
    9.             scatterNode.seed = myNewSeed;
    It depends on vegetational assets you are using. If they require some additional parameters to change density then yes. MM can't provide asset-related information here.

    Do I understand it correctly that everything works fine when you disable C++ code, and MM generates exactly the same values for all platforms?

    Take a look into functions. It is exactly the way to execute several nodes from other graph. And you can mask the generated result with Mask nodes on output.

    MM outputs generated results to standard Unity terrains. They work with one material only.

    Thank you! I really like to hear such feedback!
     
  41. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    160
    Yeah i couldn't reproduce it neither so I could give a repo project to you to look at.

    I do have the shader included, and the template assigned + the URP shader assigned in MM settings too, i dont see what could be the issue. But i have an additional error here which may help:
    upload_2023-9-12_9-4-17.png

    this is from the player log, i guess this is the cause. Any idea why this pops?

    Edit: well, i was on an older version, i upgraded to latest asset store version and the error is gone but the terrains are still invisible :(
     
    Last edited: Sep 12, 2023
  42. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    160
    Any chance you'd come remotely to see what is going on? I cannot give you a small repo project, it only happens in my main project and its 100+ gb

    Edit: oh damn i am one dumb person. I had the instancing variants stripped entirely in graphics settings. Cheers mate I'm sorry for the trouble! And if anyone else encounters my problem now you know the second reason it could be happening.
     
    Last edited: Sep 12, 2023
    Wright likes this.
  43. User414322

    User414322

    Joined:
    Jul 9, 2019
    Posts:
    27
    Bought the whole bundle. I love it so far!

    A side question, is there a discord or similar real-time-communications platform dedicated to Map Magic? I'd like to talk to other users in other to learn from them and improve my own map generation abilities.

    Update: Found it. https://discord.com/invite/yCJEgSw
     
    Last edited: Sep 13, 2023
    Wright likes this.
  44. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    dont just regenerate - remove the existing tile first then regenerate it with your new graph...
     
  45. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    Yes that does work for 1:1 links, but the suggestion i made would allow someone to do that to all connected output nodes in 2 clicks (imagine having 6-10 receivers of a node and you want them all to have thier own new curve...) instead of repeta dragging + and digging through the list for each one (or duplicating and running the links which is faster than plus dragging and digging when you have alot of them) wabam click click theres one for each...

    and while I thought that was a nice extension idea to mention - the original suggestion there was remove inline - which would take a bunch of links and move them to the next node up in the graph links parent chain without having to do each one manually, and nothing does do that currently, i dont think.
     
  46. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    I have also used many competing terrain building platforms from across the spectrum, and i agree with this, none of them hold the power of map magic. Its light years ahead of the competition.
     
    Wright likes this.
  47. User414322

    User414322

    Joined:
    Jul 9, 2019
    Posts:
    27
    All that is left towards perfection is a built-in way of doing rivers ;)
     
  48. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    First of all I'd like to thank you for these warm words! I'm really touched! It's a strong incentive that motivates to me to improve MM!

    Phew, I'm glad you could find it out! It's always a trouble to find out the issue I can't reproduce.

    Hmm, I see. But it's not clear how exactly it should work, and how it will determine what links should be re-routed and what remained. Re-link all the outputs might be counter-intuitive and will confuse users. I don't remember anything like that in Substance Designer or Houdini.

    However re-link nodes on delete is pretty straightforward, it's in my to-do list now (possibly by shaking the node? Or menu item?)

    Working on it, but to be honest I'm a bit stuck. There's no proper way to implement clusters, all of them are hacky. But I'm constantly thinking and waiting for proper idea to come to my mind.
     
    User414322 likes this.
  49. Greviouss

    Greviouss

    Joined:
    May 27, 2016
    Posts:
    146
    I appreciate all you do, and i hate to add to your to do list, buuuttt....
    I picked up the microsplat 256 module, and mm will not recognize the shader...
    I get a series of errors.... upload_2023-9-18_1-24-16.png

    upload_2023-9-18_1-24-16.png
    please if you can add this to your fix list, that would be cool.
     
  50. Wright

    Wright

    Joined:
    Feb 26, 2013
    Posts:
    2,260
    Unfortunately I can't guarantee MM working with all the Microsplat features, and compatibility issues are not top priority, but I will look into it and see what I can do
     
    Greviouss likes this.