Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

[RELEASED] CityGen3D - Procedural Scene Generation From Real World Map Data

Discussion in 'Assets and Asset Store' started by CityGen3D, Jul 8, 2020.

  1. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Hi,

    CityGen3D uses SRTM heightmap data, which unfortunately doesn't have water depth information.

    It uses Unity Terrain objects, so if you have an alternative data source for water depth you could generate your terrains in CityGen3D and apply this data to the terrains separately.
     
  2. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    615
    Hello,

    I have an interesting use case. I'm interested in recreating the city of Stalingrad as it existed in 1942 right before the Nazis invaded.
    I've been searching for different tools and approaches to implement what i need and i think CityGen3D may be the best.

    My thinking of going about this is the following, i can use CityGen3D + OpenStreetMap + whatever dataset you use for height? to create the initial terrain/water/heightmap topography stuff by simply using the present day Volgograd location.

    Then i can use this historical map of Stalingrad before invasion to lay out streets, buildings, all the manmade structures and layouts
    http://www.etomesto.com/map-volgograd_1942-stalingrad/
    or better yet this one for serious detail http://www.etomesto.com/map-volgograd_1942-aerofoto/

    My question is, is there a way to sort of use the 2D historical map to overlay over the generated terrain from Open streetmap so i can generate stuff faster?

    I understand if i have to manually specify the placement of everything, i guess my question is can i somehow "draw" on top of the generated terrain to specify all the placements based on the historical map?

    I personally figured since a historical map doesn't have height data obviously, then beginning with terrain generation using the real location as it exists today is a good start.

    Is there maybe a better way to go about this i'm not aware of?
    Thanks.

    EDIT:
    I looked into it a bit more, seems like before generating the 3D terrain we can make any changes we want to a 2D map.
    Is it possible to quickly delete large swaths of preset stuff? Or even avoid creating certain things in import of the map data?
    Like can i just have it create the terrain and heightmap and the rest is blank, and i can manually begin recreating the map based on the historical map that i have?

    Although i wonder if there is some way i can make it as easy as possible to precisely draw things based on the map.
    LIke maybe i can use the historical map as a satellite image and draw on top of it somehow to accurately recreate the roads and stuff?
    I'm not sure how to best approach this.
     
    Last edited: Mar 22, 2024
  3. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Hi,

    Thanks for your interest in the asset.

    I did something similar once and just imported my third-party 2D map image as a texture and assigned it to a material with some transparency.
    Then attached the material to a quad or plane mesh and positioned and scaled it appropriately in 2D Map View to line up with the active terrain area, allowing me to use this as a reference image when adding in my own 2D objects with the CityGen Map Editor.

    You'll want to assign this mesh to one of the CityGen "Map" layers (such as MapSurface) so it is visible in 2D Map view.
    Then just delete/hide the mesh when not actively in use to avoid CityGen from interpreting it as a real MapSurface when generating.

    As you suggested, it's also possible to skip the processing of certain objects such as buildings, or very easy to delete them after generation.
     
  4. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    615
    Ok thank you.
     
  5. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    850
    I would like to have one city with a road that connects to another city, but the two cities are not close to each other in real life.
    Is there a way to end one city and have a landscape terrain with roads or highways leading to another terrain with a different city?

    Like linking London to Paris with just a long stretch of road.

    The asset looks great but I need to know if this will work for our project before I purchase.
     
  6. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Hi,

    Thanks for your interest in CityGen3D.
    Once your environments have been created, you could place two far away locations near each other and manually create separate Unity Terrains to join them up.

    I think the main complexity would arise if you wanted to use the LandscapeManager for scene streaming.
    You would have to configure all your Landscapes so they are part of the same location after generation.
    Renaming the scenes and setting the grid references appropriately in the Landscape component should be enough to convince the system they are part of the same location.

    But if you intend to load and unload terrains with custom code anyway, you can just use CityGen3D to generate the actual content and manage the joins between areas however you want to.
     
    dsilverthorn likes this.
  7. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    850
    That sounds promising.

    Can you mix the city streets created with open maps with manually created street systems?

    In other words, can a downloaded area be removed and replaced with hand drawn streets to make the connections. So that I don't have an area just stop, but can make an end to streets and extend others to highways, etc. Then renaming terrains accordingly, so the system matches.

    I am building a very large terrain and need cities at a large distance from each other. But the trouble I see might be the landscape of the terrains not matching. Is it possible to only pull map data for streets, building, etc. and have it added to existing terrain elevations?
     
  8. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Yes, you can draw your own roads in the CityGen3D map and join those up to existing OSM roads.
    In this video I make a map from scratch, but you can edit processed OSM maps in the same way.


    You can also modify CityGen generated heightmaps using Unity Terrain tools, so if you are combining two regions together that in real life don't join up, you can manually fix that so they seamlessly blend together.
     
    dsilverthorn and hopeful like this.
  9. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    850
    Thanks.
    I went ahead and purchased and I am playing around with it, so I have more questions. :)

    I am generating an area in the US Southwestern mountains, but the heightmap is either not downloading or being applied.
    It worked when I tried an area in Scotland, but not in the United States. So I may have missed a step, but this time I tried using the Run Generator button in the Data tab. For Scotland I generated each part, one at a time inside the generator.

    I'll keep going through the manual and videos and see if I can find what I'm doing wrong. But if you have an idea, please let me know.
     
  10. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    The Unity console should give an indication of whether the heightmap was download ok. The raw data is saved into your Resource/Data/HGT folder, so if unsure worth checking that something is there other than the default one. (n51w001.hgt is part of the CityGen install, any others would have been downloaded on demand).

    Any download failure would most like be temporary and just work on next attempt, but the most likely cause of flat terrains is the Peak setting on Generator->Heightmap tab being too low for your location, which will artificially cap the terrain height.
    You should ensure Peak is high enough to accommodate your highest point of the terrain (in metres).
    Nadir should be low enough to accommodate the lowest point on the terrain, but keep the range as small as possible for best results. (We can't just have a really low Nadir and really high Peak by default because the range would be too big for the finite resolution of Unity Terrains).
    Also keep these values the same across all Landscapes you want connected to each other to avoid seams at terrain tile boundaries.
     
    dsilverthorn likes this.
  11. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    850
    Thanks
    I’ll give that a try. I appreciate it!
     
  12. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    125
    Since Unity 6 has now reached preview I gave it a shot with CityGen3D. Do you recognize the errors below and do you have an estimate for Unity 6 support. It is tricky because I need the features of Unity 6, but many assets have not added Unity 6 support. Undoubtable Asset authors are waiting for stability, which is the intention of the "Preview" level releases.
    upload_2024-5-29_18-51-43.png
     
  13. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Hi,
    Despite these errors triggering, this test environment was generated within Unity 6, so its holding up fairly well.
    Next months update (v1.14) will have some fixes for issues showing up in Unity 6 though, so I recommend waiting for those before trying again - hopefully just a week or two away.
    But as always, LTS versions are recommended by Unity for serious production to ensure greater stability, because they will occasionally break important stuff, especially at this relatively early stage.

    unity_6.png
     
    Edy likes this.
  14. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    125
    Terrain questions:
    • Selecting all surfaces in my 2D map image shows a few areas labeled correctly with Residential, Playground, and Water (See orange outlines). Clicking instance MapSurfaces->“(Grass) Land” places orange box on everything, which then translate to "Nothing" surface in Generator->SplatMap? Should I add all the missing residential surfaces in Toolbar (Seems impractical), edit OSM data directly, or continue mapping “Nothing” to grass/houses?

      upload_2024-6-4_23-38-22.png
    • I would like to use high quality terrain elements (i.e. Grass/Plants) from the asset store (Forest Environment or Gaia). How can this be done in a very automated fashion. Alternatively, I think you mentioned someone tried using Gaia terrain directly first, but I think you lose the placement/building magic of CityGen3D?

    • The SplatMap tab indicated that HDRP can only have 7 terrain layers + Mapbox. This seems like a serious limitation as CityGen3d alone has many more potential layers. Do all the high-end terrain tools (i.e. Gaia) have a fundamentally different approach that circumvents this layer limitation?
    • How do you go about making a pavement cul-de-sac. I went back and used the Toolbar (Road icon selected) and started Ctrl-left mouse clicking (Inside red circle), and it kept instantiating a new “(Minor Road)”. Why do I not see any new road on the 2D map, and can a circle road shape be created (See image)?

      upload_2024-6-4_23-38-30.png

    • Do you have an option to supply CityGen3D source code for future assurance?
    Mapbox questions:
    • Mapbox image is only good at high altitude and obviously looks unrealistic at angles. I tried to use with your “Texture Rule” Distribution=Altitude, but it never shows the lower altitude grass. Can explain how to use “Altitude” properly?

    • Can you explain the basic idea on how to make Global Texturing module work with CityGen3D? The idea is to make a smooth transition from Mapbox image to the CityGen3D 3D world. Some prefabs like tress will surely not match Mapbox image, but I guess that is unavoidable?
     
    Last edited: Jun 5, 2024
    dsilverthorn likes this.
  15. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    This default surface feature is known not to work correctly in Unity 6 Preview (it's a result of the triangulation error you are seeing), so worth re-evaluating this after next update. I'm testing a workaround for this issue at the moment, although it may be fixed by Unity at some point anyway.
    In normal operation, CityGen creates a default Grass surface as the background. In cities and towns, setting Residential as a default works well though (Data->Location->Processing), because grass, woodland and parks (etc) are normally mapped separately so you can assume everything else is residential.
    You can also manually draw Surface areas of any type using the CityGen Map Editor, but with a suitable default assigned you'll likely find this is not necessary unless you really want to spend time defining these regions for a specific purpose. Note that the Map Editor is likely unstable in Unity 6 too for now, so worth waiting for an update (or use LTS version).


    CityGen is supplied with some default tree prefabs, but you can replace these with third-party assets (see Generator->Trees & Generator->Detail).
    For instance, you could replace the CityGen oak tree with a prefab from the Forest Environment asset that is setup appropriately with its own LOD system.

    This is a limitation of the default Unity HDRP terrain shader, it is not linked to Unity Layers in that sense.
    It is documented by Unity here: https://docs.unity3d.com/6000.0/Documentation/Manual/class-TerrainLayer.html
    You can use a third-party terrain shader such as Microsplat to get around this, which works well with CityGen3D.


    You can click a road in Map View and view its settings in the Inspector. Changing Start/End Edge to Rounded from Squared will make it curved, but I'm not sure what is what you are after.
    If that doesn't help, please can you show me a real life picture of a road that you are trying to replicate, just so I understand exactly what you are trying to do?


    It is possible there'll be an upgrade in future to provide optional access to source code, but nothing definite at the moment.


    CityGen spawns tree models where they are individually mapped in OSM, however this is fairly rare. It is more common for areas to simply be marked as woodland/forest (etc) and CityGen will simply spawn trees based on the distribution rules (Generator->Trees) inside these areas.

    The Altitude setting is a way of limiting terrain texturing to within a certain heightmap range.
    A common usage is to assign snow instead of grass a high altitude (eg 0.9 to 1.0), something like that.
    Likewise the gradient setting can be used to automatically have rock instead of grass at steeper inclines.
    As you indicated, using a specialised shader for blending between satellite imagery and splatmap textures is the way to go. I did experiment a few years ago with Microsplats Global Texturing module, which is good for this. This will only change the terrain texturing though, nothing else.
    Microsplat + CityGen workflow in general is just a case of generating CityGen terrains as normal and then following standard Microsplat guidelines for adding Microsplat to existing Unity Terrains. If you have no experience with Microsplat I recommend getting familiar with their Free base module first.
     
  16. aidesigner

    aidesigner

    Joined:
    May 2, 2012
    Posts:
    125
    Thanks for all the great insight, and it led to some follow-up questions.
    • With my “Default Surface” set to residential the entire 2D map has a box for “(Residential) Land”, which I think means it is the default. When I max out all the “Prefab Selection” options the “Generate Buildings” still only picks the procedural houses (See below)? I suppose this must be a prefab size filter, but a typical house plot has Plot length=18/Plot Depth=23.
    upload_2024-6-6_22-39-55.png

    • On Generator->Detail tab I added a grass from “Dynamic Nature”. However, despite a “Periline Noise” Threshold of 1 it is still far from filling in grass completely (See image). Can you explain this outcome and also the settings - “Detail” tab settings “Render Distance”, “Density”, “Noise”, “Healthy”, “Dry”, and “Patch Resolution”? Also note I think there is a bug where the last “Distribution” item is always missing the “Threshold”.
    upload_2024-6-6_22-39-21.png

    • How can I replicate your nice looking lawn from NatureManufacture biome forum post? I did no follow the use of biome, which seems to be a Vegetation Studio Pro concept that is depreciated.

    • It would help to get some additional real-world facts correct. For example, all the real world 1 story houses become fabricated 2 story, which I know can be fixed manually. Are you aware of any other real world data sources that can fill in this missing real-world data hints? Then of course I would need to get CityGen3D to understand this data (Preferred) or replace houses in post-processing.

    • My driveway is at 45deg and rises 18ft going to my house. However, everything is pretty much flat on the terrain. I know this is likely a OSM sampling issue, which flattens to the lowest point. Do you have a suggestion that could help?

    • On Generator->Trees can you describe the range/scale of “Surface Distribution”->“Weight”?
     
    Last edited: Jun 7, 2024
  17. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    687
    Make sure Spawn Prefabs checkbox is enabled on the Buildings window.
    As noted above, Unity 6 isn't able to sample the default surface, so make sure you are testing this in LTS version for time being to get intended results.

    The default Detail settings have fairly dense grass. Notice the density slider for the grass billboard is 4 instead of 1, which is the biggest factor here. Patchy sections are influenced by the Perlin Noise.
    Screenshot 2024-06-10 103135.png
    It's probably ok to use high density for texture assets like this, but you'll probably notice a performance hit using high density on mesh assets.
    Detail settings just map to the equivalent settings for Unity Terrains (the global ones) and their Detail Objects (where you can specify values per object).
    You can find more info on these here: docs.unity3d.com/Manual/terrain-Grass.html

    OSM is probably the best free data source. In some cases you may be able to obtain more accurate data for a specific location.
    Then you would need to write your own script to create CityGen Map data as if it had come from OSM.
    eg.
    Map.Instance.mapBuildings.Create( typeIndex, shape2d );

    The free heightmap data CityGen uses is interpolated between one sample every 30 metres so it wont pick up finer details.
    Its sometimes possible to obtain higher resolution heightmap data for a given region, but while this sounds good, in practice its actually harder to work with. It will often have false positives for manmade structures (eg. result in higher terrain where tall buildings are). I find it easier to work with lower resolution heightmaps that are enough to give you a good starting point, and to use the Unity Terrain tools and CityGen heightmap modifier & road levelling tools for added realism.

    Its how many attempts will be made to find a valid spawn position for a tree instance (per 1km x 1km terrain area). So higher number increases density of trees in selected surfaces, while keeping tree density within valid surfaces independent of actually how frequent a surface appears. For example, a terrain that is covered 50% in woodland will have twice as many trees as a terrain covered only 25% in woodland, but the density of trees within the actual woodland is the same and relative to the Weight value.