Search Unity

Assets [BETA RELEASED] CityGen3D | Procedural city generation from map data

Discussion in 'Works In Progress' started by CityGen3D, Jan 28, 2018.

  1. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    1. Intended workflow is that you should be able to copy the Generator prefab (Assets\CityGen3D\Resources\) and make changes to it. Then reference it in the Generator Profile on Location panel so it gets loaded into the scene when you click the Load Generator button. So you could have different Generators for different locations, themes, and art styles just by having different copies of the prefab.
    One day I'll demo this by setting up a Generator to use low-poly cartoon style assets instead of the defaults.
    With the CityGen3D map data, you just have to copy the CityGen3D prefab and drag it into the scene at the start.

    Making copies of these two prefabs is a good thing to do, because naturally if you download a CityGen3D update, the defaults will be overwritten.

    I hope this helps give you some ideas with organization, but let me know how you get on, or if you think there is still scope for improvements.

    2. It may not make v0.9 but I am developing a mechanism for modifying building instances after generation. I really want to able to do this for all the reason you mention, so it's high priority. So although options may be limited initially in this regard, it will be something being actively worked on.

    3. Yeah so the last time CityGen3D is aware of the raw OSM data is when you click Process to generate the 2D map. After that, it gets all the data from the gameobjects parented to the CityGen3D root object. It's from this data that the 2D map is created.

    Long term, you'll be able to edit the 2D map at this point to modify surfaces and roads, or add features and entities.
    There are some limited editing capabilities already present for some objects. For instance, if you click a surface on the map like "Farmland" and view the Inspector, you'll be able to change it to a different surface type via the listbox and the changes will be reflected immediately in 2D map view. Likewise you can change some road attributes on the map as well and see the changes in 2D.

    This is quite limited at the moment, and is just proof of concept, but after v1.0 there'll be a toolbar for adding new objects and you'll be able to move and add nodes to change the shape of objects.
     
    chmodseven likes this.
  2. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    Here's a procedurally generated supermarket from OpenStreetMap data.
    I manually added the "Supermarket" sign after generation, which is really easy to do with Unity's TextMeshPro.

    Also wrote a quick prefab spawner for some shopping cart fun! :)

    screenshot2.png
     
  3. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    47
    Looks like my local Sainsburys on a normal day. :D
     
    CityGen3D likes this.
  4. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    Funnily enough the building was actually generated from a Sainsbury's in UK, hence I went with the orange trim. :D
     
  5. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    218
    Status report on next version of CityGen3D? I think that the landscapes are already loaded in the scene before playing the game, the truck lands on the terrain as expected. If the landscapes are set for "scene streaming", the truck falls to flat roads without terrains.
     
    Last edited: Apr 1, 2020
  6. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    We should be able to debug this by finding out the following:
    • What is your trucks world space position?
    • What landscape should be loaded at this position?
    • Is the landscape present and added to the build settings?
    There is a debug checkbox on the Landscape Manager to help us.
    When enabled this should show the camera position and the landscape it thinks should be at this location.
    While game is running look at top left and top right of screen for this information.

    So please can you send me screenshot of your game running with this debug option on, your Landscape Manager component setup, and any console output generated during loading.

    As I recall I think the console will report if a scene can't be found by the Landscape Manager so there may be a clue there as to what is going on if you try it in the Editor.

    As soon as I get chance I'll also try and do a demo video showing how to set this up more clearly.
     
  7. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    Definitely coming this month, hopefully around Easter.

    It's going to be an even bigger update than originally planned with more content and features.
    Here you can see a building with flat roof that was generated from building rules being modified afterwards in the Inspector and rebuilt on demand.

    The red gizmo indicates the change of roof shape which updates in real time when you change the settings.
    Each level of the building has it's own component from which you can replace sections of it using a drop-down.

    Whichever façade section you are interacting with is also outlined with the gizmo when you mouse over it, and I've just changed one of the facades to be a door.
    Then I click Rebuild, and the building is regenerated with your customizations.

    I will release a video once v0.9 is ready for release to show this more clearly, but this will allow you to customise your building quite a bit after generation, which will be really useful for door placement.

    before.png
    after.png
     
  8. unity_cJZCcV76bQUTFQ

    unity_cJZCcV76bQUTFQ

    Joined:
    Aug 26, 2019
    Posts:
    2
    Hello, CityGen3d, i'm using Unity 2019.3.7f1 on a Mac OS Catalina, when i open the Generator toolbar, after process the Data, i have this error.

    Code (CSharp):
    1. CityGen3D.EditorExtension.EditorGenerator.ShowHeightmapModifiersPanel () (at C:/Dev/CityGen3D/CityGen3D Editor/Editor/EditorGenerator_Heightmap.cs:423)

    The latitude and longitude is, Vila Velha - ES, Brazil, Latitude: -20.3305, Longitude: -40.2922
     

    Attached Files:

  9. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    218
    After I download and process OSM data, I press CTRL-M keys to bring up 2D map. Where are the 2D maps located in Windows Explorer?
     
  10. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    Hi,

    Thanks for your message, I’ll try and get you back on track.

    First thing to try if you’ve not already would be to simply delete the Generator gameobject from your Hierarchy, go back to Data window and click Load Generator to reload it.

    If you still have issues then check that you have definitely setup the Unity Layers as detailed in the manual. (Most reported errors can be traced back to this).

    If they aren’t you may want to try a fresh project, installing the packages, and setting up layers, just to be sure everything is setup correctly.

    If these are setup correctly, please try again by loading the New City scene and trying the steps to generate a location again.

    If none of the above helps please take a screenshot of your Inspector with the Generator gameObject selected, and also one with the child Heightmap object selected.

    This should help me identify exactly what’s going on.
     
  11. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    The 2D map exists only as a collection of game objects. It doesn’t exist anywhere outside of the Unity scene.

    What file format were you hoping to find it in?
     
  12. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    218
    I thought that the 2D map is an image. I need the building footprints that are not shown on 3D terrains but shown on 2D maps. I want to create temporary 3D buildings until you release the next version of CityGen3D. I tried to use the "Raise or Lower Terrain" tool but I can't lower part of the terrain because the position of the terrains are at X,0,Z. I created flat terrains because of weird problems between terrains - the roads just drop from height of terrain to X,0,Z (I think) between terrains.
     
  13. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    The 2D map that appears in the Map view after processing data is clickable. You can select any object in it, and in some cases basic editing functionality is supported such as changing surface types (with more to come).

    Note that it's already possible to process Building data in v0.82, so rather than an image, I think you just want to access this data.

    Before you click Process to create the map, ensure Buildings (or "Everything") is selected as filter in the Processing listbox. Building processing may be off by default until the Generator can work with it.
    Although from your description it sounds like you've already done that and you can see buildings on the 2D map.

    The following code shows you how you can access the building data, either to get a world position of the building, or more accurately, the world position of each node in the building shape.

    Code (CSharp):
    1. using CityGen3D;
    2.  
    3. // loop through each building in turn
    4. foreach (MapBuilding mapBuilding in Map.Instance.mapBuildings.GetMapBuildings() )
    5. {
    6.     //loop through shapes that define building (a building may be more than one shape, but in most cases there'll just be one)
    7.     foreach( Shape shape in mapBuilding.GetComponents<Shape>() )
    8.     {
    9.         // find centre of shape - this will essentially give you building position in Unity world space
    10.         Vector3 worldPos = shape.GetCentre();
    11.  
    12.         // get each node position for more detailed building shape
    13.         foreach( Vector3 node in shape.GetPositions() )
    14.         {
    15.         }
    16.     }
    17. }
    Then with this data you can do what you want with it.
    As discussed previously I'll be doing a more detailed demonstration of the CItyGen3D API a bit later, using it to hook-up to BuildR, in the hope this will provide a useful example so coders can start experimenting with using CityGen3D data with other third-party tools.
    So while the above code snippet isn't a fully working example, there may be enough there to get started with and hopefully it shows how easy it is to access the OpenStreetMap data through the API.
     
  14. jeffmorris1956

    jeffmorris1956

    Joined:
    Jul 3, 2012
    Posts:
    218
    I already enabled Buildings in the Processing listbox. Where should I put the code above? Will I generate low-poly buildings?
     
  15. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    The code posted above won’t do anything on its own, it’s just an example of how to get the building data from CityGen3D to code your own solution.

    For example you could use it to spawn a prefab at building location, or to extrude a mesh in the actual shape of a building, if you already know how to do those things.

    However the upcoming building generator will do all this for you so you don’t need to code anything.

    So if you can hold off for just another week or so, I promise you’ll have some buildings to play with :)
     
  16. chmodseven

    chmodseven

    Joined:
    Jul 20, 2012
    Posts:
    47
    Does that mean BuildR functionality is coming in 0.9? What advantages would BuildR have over (or in addition to) your own building functionality in CityGen3D? I haven't bought BuildR yet, so knowing what the added value might be will be good to know in deciding whether to get it or not.

    I'm looking forward to seeing the API details. I'm hoping things are coded in such a way as to use interfaces/polymorphism so that we can potentially add in our own map or data type importers and have CityGen3D work with those - for example swapping out OSM for OpenZoomstack, as long as the interface signature matches.
     
    Santa36 likes this.
  17. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    The API will mainly provide a code interface to the parsed OSM data, rather than providing an interface between different data inputs.
    Once you start coding AI for your project you may need to know things like:
    What surface is below my character/car?
    Where's the nearest bus stop?
    What's the speed limit on this road?
    What are the waypoints for lanes on roads?

    Access to this data is largely already possible in CityGen3D, it's just a case of documenting it and tidying the API up a bit.
    Up to now focus has been on getting the UI sorted so non-coders can use CityGen3D via the Generator window.
    But much of the tool's power comes from being able to use the data yourself in scripts, even at run-time.
    Here's a very simple example of a component that uses the GetMapRoadAtWorldPosition function.
    If you attach it to a gameobject (eg camera) it will tell you the road at the objects location in the Inspector.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace CityGen3D
    4. {
    5.     // attach to gameobject to get road data at its location
    6.     public class RoadInfo : MonoBehaviour
    7.     {    
    8.         public MapRoad road; // the road at current location
    9.         public float checkRadius = 1.0f; // how far away from location do we consider to be within bounds
    10.         public float checkFrequency = 1.0f; // how often should be check for change (seconds)
    11.  
    12.         void Start()
    13.         {
    14.             InvokeRepeating( "RefreshRoad", 0.0f, checkFrequency );
    15.         }
    16.  
    17.         void RefreshRoad()
    18.         {
    19.             road = Map.Instance.mapRoads.GetMapRoadAtWorldPosition( transform.position.x, transform.position.z, checkRadius );
    20.         }
    21.     }
    22. }
    So I imagine users being able to eventually search the CityGen3D API for public functions online and have little code examples like this to show you how to use it.

    The BuildR integration will just be a more elaborate example, showing you how you could write your own Generator that hooks up the data CityGen3D already has to another asset.

    Please see this thread for more info on BuildR. The next version is in active development so I wont be releasing the BuildR integration demo until after that is out properly, but it's not far away either.

    Jasper is about to close the open beta but you may still be able to get on it if you want to try that asset out.
     
    Santa36 and hopeful like this.
  18. Denzellz

    Denzellz

    Joined:
    Apr 2, 2016
    Posts:
    8
    Usually how long does it take until approved after purchase.
     
  19. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    Not very long, the 24 hour approval window is just a worst case scenario, it’s normally done within an hour.

    You should be ready to go now, but let me know if you need any help.
     
    Santa36 likes this.
  20. Denzellz

    Denzellz

    Joined:
    Apr 2, 2016
    Posts:
    8
    Anyone know and great locations for a street racing game? would love get some opinions.
     
  21. CityGen3D

    CityGen3D

    Joined:
    Nov 23, 2012
    Posts:
    265
    I can’t really give specific locations, although it will be interesting to see if anyone else has some suggestions. But I can answer your question more generally.

    What I have enjoyed about racing around CityGen3D environments in testing is the organic European style roads, where junctions are less likely to be at right angles.

    The way the road networks are generated from OSM data allows these winding roads to be created just as easily as grid based American style city layouts, which otherwise are quite time consuming to create manually because they don’t lend themselves well to modular assets.

    Coupled with undulating terrain, this type of environment can be lots of fun!

    But it really depend on the type of game you want to make and what atmosphere you are looking to create, whether it’s high speed motorway pursuits or close urban street racing.

    The great thing is, with CityGen3D you’ll be able to prototype different types of road layout and environments very easily! :)
     
    Denzellz and StevenPicard like this.
  22. Denzellz

    Denzellz

    Joined:
    Apr 2, 2016
    Posts:
    8
    thanks for the great information ill start testing around that area :)
     
    CityGen3D likes this.
  23. Denzellz

    Denzellz

    Joined:
    Apr 2, 2016
    Posts:
    8
    Idk what im doing wrong but my terrain is all black and all objects and roads are placed under the map.


    upload_2020-4-8_22-53-44.png upload_2020-4-8_22-54-37.png upload_2020-4-8_22-55-12.png
     
  24. Denzellz

    Denzellz

    Joined:
    Apr 2, 2016
    Posts:
    8
unityunity