Search Unity

World Building EasyRoads3D v3 - the upcoming new road system

Discussion in 'Tools In Progress' started by raoul, Feb 19, 2014.

  1. imDanOush

    imDanOush

    Joined:
    Oct 12, 2013
    Posts:
    368
    Yup weirdly (and fortunately(!)) all of them are gone.
    This is a great tool, look at the image below to know stuffs I made with only the connections that I've sent you.


    Still I'm not sure it made the road creation process faster than the 3D Max way or not. Since I'm very new to this tool. I don't judge now. But obviously the 3DS max way is more precise (I'm using satellite images to recreate a city). I'm trying to make more precise roads with this tool. I believe once I get the hang of this tool, I'd be able to make roads quicker and better than I used to create in 3DS Max.


    Aha okay. Thanks. You know it is a dirt texture, once I use asphalt texture, I'll use the option.
    Best.
     
  2. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Ok, glad to hear you are back on track. :)

    If your terrain is 100% flat and you are used to creating roads in 3DS Max, indeed the 3DS way might be faster for you. I quess being familiar with the tool does help.

    However, if your terrains are not 100% flat, try matching your Unity terrains with your 3DS road network ;). This is the reason why we started experimenting with generating roads in Unity in 2009, https://forum.unity3d.com/threads/easy-roads-in-unity.19307/ . Adjusting the terrain was extremely time consuming, not to speak about the final results which doesn't come even close to when you automate this process.

    Let me know if you have further questions.

    Thanks,
    Raoul
     
    imDanOush likes this.
  3. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    385
    Hi, here are some screenshots of my environment study with new custom road models specially made for EasyRoads3D plugin + Gaia for surroundings.
    Can’t wait to continue exploring!

    Environment study 02.jpg
    Environment study 03.jpg
    Environment study 04.jpg
    Environment study 05.jpg
    Environment study 06.jpg
     
    emergki, Artomiano, radimoto and 3 others like this.
  4. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,685
    @600 - Love what you did with the overpasses and the rough patch in the final pic. :)
     
    600 likes this.
  5. FallenTreeGames

    FallenTreeGames

    Joined:
    Jun 22, 2016
    Posts:
    29
    Hi, thanks for the tool, is a great asset!

    We are looking to use the runtime API to get information about the roads and I wondered whether you could help. I've got the current ERRoad which our AI car is driving along and I know when they reach the end of the road.

    What I want to do is get the connection at the end of the road and choose a random next road to drive down from there. I assumed I needed to get the ERConnection, which I've done, but I'm not seeing anything on that script which details the ERRoads which are connected to it?

    I 'could' go through a list of all roads and find the ones which have this connection as it's start or end, but that seems a long winded way of doing it when we have a lot of roads.

    Is there a way to do this currently in the current API?
     
  6. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi FallenTreeGames,

    Glad to hear you like the tool!

    I had a quick look. Indeed there is no direct way to get this info other then what you suggested. The scripting API is currently expanded upon user requests. I will add this.

    Thanks,
    Raoul
     
  7. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    600 likes this.
  8. FallenTreeGames

    FallenTreeGames

    Joined:
    Jun 22, 2016
    Posts:
    29
    Great, thank you.

    I have got it working via iterating over all the roads to determine the connections and it works fine, but if there was a direct method in the API that would better.

    (I'm not using it but I did notice you've also misspelled Threshold in ERRoad.GetAngleTreshold & ERRoad.SetAngleTreshold)
     
  9. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Thank you for reporting this, I will fix that!

    Raoul
     
    Danua likes this.
  10. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    197
    Hello, I had issue with road width, I can't adjust it, i try to tune it and it's revert to default value . I use version v 3.0.beta 8.0.
    I put this prefab on scene ER Road Network.
     
  11. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi Danua,

    Do you mean the road is connected to a crossing prefab? In that case indeed the road width cannot be changed. Currently roads inherit the connection settings of the prefab it is attached to. To adjust the width of the connection:

    1. Select it and click "Select" Connection Hierarchy"
    2. Click the "Connection Settings" foldout
    3. Adjust the Connection Width

    The recommended workflow however is to create your scene specific road types including the width and material etc. Then create your scene specific crossings (General Settings > Crossing Connection Prefabs). And select the road type per connection. Roads pulled out of this connection or attached to this connection will inherit the settings of that road type. And you can reuse these new crossing prefabs from the Inspector tab, it will speed up the development process.

    The below video shows the workflow for creating new dynamic crossings
    )

    If the road is not connected to a crossing prefab you should be able to adjust the width in the Inspector afters electing that road.

    Thanks,
    Raoul
     
    Last edited: Oct 13, 2016
    Artomiano and Danua like this.
  12. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    197
    I talk about road width. look at the picture
     
  13. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Please try to change the road width after creating the road, it works fine, I just double checked. Newly created roads are currently build according the default road type settings.

    If you want to create a road with width 4 without having to adjust the road width in the road settings afterwards, you can create a new road type with width 4 in General Settings > Road Types. That is more efficient, you do not have to set the materials etc. all the time.

    Thanks,
    Raoul
     
    Danua likes this.
  14. Danua

    Danua

    Joined:
    Feb 20, 2015
    Posts:
    197
    Thanks, it's helps, I just create road type preset, with custom settings and materials.
     
    raoul likes this.
  15. SgtLame

    SgtLame

    Joined:
    Nov 26, 2015
    Posts:
    129
    Hi Raoul,

    In order to build walls, I use a procedural mesh side object.

    Problem is, depending on the resolution, it deforms/tiles materials applied on it (I guess this is the intended behaviour), as in the screenshot below:


    The ideal behaviour for materials would be the one that is used with shape side objects (but the problem with shape side objects is that you can't clamp them to road geometry, which is something I need)



    Actually, shape side objects do clamp to road geometry, but not perfectly, especially on the end markers, which is (correct me if I'm wrong) the normal behaviour, since the resolution for shape side objects can't go below 0.5. I hope I'm making myself clear.

    Is what I want to do possible? And if not, would it be possible to add the "clamp to road geometry" option to shape side objects?
     
    Last edited: Oct 16, 2016
  16. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi SgtLame,

    Indeed "clamp to road geometry" also exists for Shape type of side objects.

    For Procedural side objects the original UVs are used. So if the UVs are setup correctly for the source mesh all should look good. I just checked this for the Concrete barrier side object in the package by assigning a detaled texture like in your sceenshot. The texture does seamlessly tile.

    But indeed your texture selection and side object settings are important. If you chose "clamp to road geometry" a segment could be squeezed together or stretch a little bit in some areas depending on the road geometry (certainly when using low Angle Thresholds). When using a detailed texture like in your screenshot this may become visible on the wall.

    Is "clamp to road geometry" really required for this wall? I would think, generally a wall should simply follow the road shape based on the original setup of the source mesh.

    This particular setup indeed will look better for Shape Type of side objects for which the UVs are generated internally based on distance. What is the exact issue you are having with this? I did notice that the UVs are not always accurate on the very last segment, is that what you meant? That will be fixed.

    Thanks,
    Raoul
     
  17. 600

    600

    Joined:
    Dec 18, 2013
    Posts:
    385
    Hi, happy Sunday!

    Here are some screenshots of dirt road testing :)

    Dusty Screenshot Saturday.jpg
    Dusty Screenshot Saturday 1.jpg
    Dusty Screenshot Saturday 2.jpg
     
  18. James_FallenTreeGames

    James_FallenTreeGames

    Joined:
    Sep 30, 2016
    Posts:
    16
    Hi,

    In our game we are using EasyRoads for roads + train tracks. In the API I'm trying to get a list of all the 'roads' + 'train tracks'.

    I've got all the EasyRoads Roads and then I'm trying to get the 'type' from here so I know if it's a road or train track.

    I'm getting a bit confused though, on the ERRoad there is a GetRoadType function, perfect I thought, but the result coming back is always 'Default Road', even though I've got various different road types set up.

    I'm using this function
    public ERRoadType GetRoadType( ERRoadType[] roadTypes );
    such as:
    Code (CSharp):
    1. var allRoads = _roadNetwork.GetRoads();
    2. var allRoadTypes = _roadNetwork.GetRoadTypes();
    3. for( int i = 0; i < allRoads.Length; i++ )
    4. {
    5.   var roadType = allRoads[ i ].GetRoadType( allRoadTypes );
    6.  
    7.   // Process the roadType but it's always coming back as the Default Road
    8. }
    Is this a bug in the API or am I using it wrong? I'm confused why I have to pass in a list of roads, I would have thought ERRoad.GetRoadType() would be been possible? (which is actually what the manual says, but the code is different).

    I've looked in the runtimeScript file but this function isn't mentioned in there.
     
  19. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
    Often I get to a point where it has these high ridges or deep cuts where I can't seem to get it to work smoothly. How do I prevent this? Im using easy roads 2.


     
  20. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi James,

    Is that the exact code you are using?

    Because there is no need to pass all the road types to get the road type of a road:

    ERRoad.GetRoadType()

    Or is that what you are using?

    Thanks,
    Raoul
     
  21. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735

    Hi voncarp,

    Looking at the road markers this is indeed done with v2. This is the v3 thread :)

    Do you have multiple terrains in your scene? In that case, in v2 you have to enable Multiple Terrains in General Settings and select the active terrain.

    But it is very much recommended to start using v3, it is part of the asset store download as a separate package, please check the _Readme file in the root directory.

    Multiple terrains are dealt with automatically in v3.

    Thanks,
    Raoul
     
    Last edited: Oct 20, 2016
  22. James_FallenTreeGames

    James_FallenTreeGames

    Joined:
    Sep 30, 2016
    Posts:
    16
    Yes that's the exact code I'm using, in my ERRoad I only have this function relating to road types:
    public ERRoadType GetRoadType( ERRoadType[] roadTypes );

    I think we might have had a custom dll to fix an issue my boss reported, could it be an issue with the API being different in that dll?
     
  23. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Which version is that? If this was a fix only, the latest 8.1 build (on the asset store) should work as well. You probably want to import the beta package only from the import window and double click it afterwards in /Assets/EasyRoads3D/. And, as always with upgrades, please backup your project first!

    I will double check the behaviour of ERRoad.GetRoadType() tomorrow morning.

    Thanks,
    Raoul
     
  24. James_FallenTreeGames

    James_FallenTreeGames

    Joined:
    Sep 30, 2016
    Posts:
    16
    I believe we have a pre-release of 8.2 (t4 to be exact)
     
  25. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Yes, this is indeed updated in 8.2, I will check this.

    Raoul
     
  26. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    @James_FallenTreeGames,

    You are right, this was indeed not working properly. It is fixed, a new build will be available soon. Let me know if you need this urgently, I can send another alpha build in that case.

    Thank you for reporting this!

    Raoul
     
  27. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Hello Raoul. I have a few spots in the road where sharp angles or tight zig zags occur that should be smoothly curved. I tried to select the marker and adjust the spline but it screwed things up worse in those short sections. There are only about 20 over a 21km road. What is the fix for this step by step?
     
  28. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi ippdev,

    Can you show screenshots?

    It seems this is related to the particular spline shape in that area and the road resolution / Angle Threshold settings.

    Thanks,
    Raoul
     
  29. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Hi Raoul. I thought I answered this on Thursday and was awaiting a reply to light up my Alerts. Basically the issue is used OSM data to build the road..hwy 129..Tail Of The Dragon in North Carolina...and have now planted vegetation along both sides of the road that is as dense as the real world run. I have sections of the road that should have a smooth curve that are series of straight sections. There are other areas that have zigzags that look really bad. Not a fault of your excellent tool at all. This road travels over 21 separate terrains. I was just trying to get the markers back to adjust but for the life of me i cannot edit the road. I click and get the toolbar but as soon as i click any of the tabs it returns to the Road Network parent with the ER Modular base script on it. Another issue I want to find the answer to is this. I had previously, in a test version, been able to place an empty game object or null every ten metres. How the heck did i do that??

    So..to enumerate..
    1. How do i edit a road that won't allow me to access the editor features.
    2. What is the best method..hot keys..editor or marker settings... to get the road to smoothly conform to the proper curves as indicated by the markers just prior to and after the anomalies such as straightened sections that should be smooth curves and eliminate zigzags which are short..5-10 meters ..but horribly incongruent?
    3. Refresh my memory as to how i placed markers along the road center every 10 meters.

    I must not disturb the terrains at all..I have a good month solid texturing and planting vegetation..and a busted wrist:)
     
  30. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    Hi Raoul, if I want to simply create a track that has different materials on different segments (e.g. one half of the track tarmac, one half gravel) is there any simple way to do this? I had thought you could use "Split Road at Selected Marker" to do this, it seems to allow you to split the unclosed road into separate roads, however they aren't joined at the ends.

    I know you can join them using a dynamic prefab but I was wondering if there was an even simpler way, just to have the road segments joined as per normal but with different materials? Decals and game objects could then be used where the materials changed.

    Is that possible at all or do you absolutely have to use dynamic prefabs between segments? Thanks
     
  31. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Hi Raoul. I am using 5.5.0b5 and the last version of your plugin was updated several months back in early summer. The version number is 7.7.2.

    Is this why I cannot edit the road?
     
    Last edited: Oct 23, 2016
  32. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Another issue I want to find the answer to is this. I had previously, in a test version, been able to place an empty game object or null every ten metres. How the heck did i do that??

    So..to enumerate..
    1. How do i edit a road that won't allow me to access the editor features.
    2. What is the best method..hot keys..editor or marker settings... to get the road to smoothly conform to the proper curves as indicated by the markers just prior to and after the anomalies such as straightened sections that should be smooth curves and eliminate zigzags which are short..5-10 meters ..but horribly incongruent?
    3. Refresh my memory as to how i placed markers along the road center every 10 meters.

    I must not disturb the terrains at all..I have a good month solid texturing and planting vegetation..and a busted wrist:)[/QUOTE]

    Hi ippdev,

    It sounds like the road object itself was selected in the hierarchy? In v3 the main road network object should always be selected when changing markers. It should show markers of all the roads, you can select markers and ove them around.

    In my previous reply I asked or screenshot. It is just hard to answer this question without knowing the situation, there is no magical solution that works for all situations. In my previous reply I mentioned the road resolution and Angle Threshold options. The default Angle Threshold is high, this forces the road resolution value to be used along the full road. If you lower the Angle Threshold and raise the resolution values you will see that the geometry adjusts. A low Angle Threshold will result in a smoother road. A low resolution value wil do that as well but since you mentioned that you have a long road it is probably better to achieve this with the Angle Threshold control which is also a good way to optimize your road geometery without losing detail.

    That sounds like a Mesh Type of side object setup with an empty game object as the source object and 10 for the "Distance between objects" in the Side Object Manager. Activate this side object for your road.

    Is this the same as above or did you actually mean markers instead of "empty game object". I don't know how you achieve that, markers at every 10 meters? Or is this about the older waypoint option that instantiated waypoints every X meters? You can get spline info through scripting API. Or you could do what described above using side objects.

    EasyRoads3D does have backup options. Nevertheless I would also recommend to backup your terrains yourself. You cannot be cautious enough with this sort of things.

    Thanks,
    Raoul
     
  33. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi radimoto,

    You can use the Split Road option to achieve this but make sure to use the "Straight XYZ" controller type on the markers where you split the road. This way both pieces will nicely connect.

    At this moment it is not yet possible to change materials on the same object, it is on the list.

    Thanks,
    Raoul
     
  34. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    For sure it is recommended to always update to the latest version but there is no known issue with editing roads, moving markers. Please check my reply above posted a minute ago and let me know if that doesn't resolve it.

    Thanks,
    Raoul
     
  35. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    I grabbed the latest beta 5.5.0b8 and the latest Asset Store version of your plugin. I cannot edit the current Road Network, nor create a new Road Network from the 3D menu. I figured I would just recreate it from the .osm file I created the previous highway from. No go. No new game object of any kind was created in the Hierarchy. I am getting console errors so maybe these will help you track down my issues. This is what i do step by step.

    1. Select the road from Scene View.
    2.The Hwy 129 is selected in the Hierarchy with the ER3 toolbar.
    3.Click on any tab and it take me to the top level Road network parent with the ER Modular Base script on it but no toolbar , text nor anything.
    4. The Console starts spitting out
    "MethodAccessException: Method 'UnityEditor.EditorUtility:SetSelectedWireframeHidden (UnityEngine.Renderer,bool)' is inaccessible from method 'EasyRoads3Dv3Editor.OQQCOOCCDO:OnEnable()'
    ...and this one spams the Console
    NullReferenceException: Object reference not set to instance of an object
    'EasyRoads3Dv3Editor.OQQCOOCCDO:OnSceneGUI()'
    ...and
    NullReferenceException: Object reference not set to instance of an object
    'EasyRoads3Dv3Editor.OQQCOOCCDO:OnInspectorGUI()'
    ...and this which may be trashing the toolbar??
    Releasing RenderTexture that is set to be RenderTexture.active!
    UnityEditor.DockArea:OnGUI()

    Somewhere the connection got lost it appears to me. I transferred the entire project from OS X to Windows to implement VR. Is there a way to reset this connection if my guess is correct. I have all the terrains backed up via the ER Terrain scripts on the terrains themselves. Other than that if i could export the road mesh and just fuss with it for a half hour in my 3D app I could get rid of all my woes:). It is extremely odd i cannot even create a new road network as well. Thanks for your continued assistance.

    edit: I just tried using the MegaShapes plugin and it also had errors that EditorUtility.SetSelectedWireframeHidden did not have a definition. I commented out the lines on the two MegaShapes scripts and they went away and the API does indeed show an EditorUtility.SetSelectedWireframeHidden
     
    Last edited: Oct 23, 2016
  36. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi ippdev,

    If you get that error message, other functionality might be affected as well. I will check the latest Unity 5.5 beta. Once that is resolved I can send you a test build so you can see if your other issues are resolved as well. Do I have your email?

    General Settings > Scene Settings > Refresh Road network

    This might help but again, if you already have other error messages, these connection issues migt be related to that as well.

    Thanks,
    Raoul
     
  37. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi ippdev,

    I did a quick search and found some threads where this same error is mentioned. According to one of the unity devs who responded it is a small "bug" and EditorUtility.SetSelectedWireframeHidden will make it back into Unity 5.5.

    Are you in the position to test your project on Unity 5.4 just to see if that is working well?

    Thanks,
    Raoul
     
  38. Siamant

    Siamant

    Joined:
    Oct 27, 2016
    Posts:
    3
    hi, Raoul
    what are the constraints to mesh object in Procedural Mesh Object menu? i'm doing country track and i'm using procedural mesh to generate road from the specific mesh, sometimes it works and sometimes it generates empty mesh
     
  39. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi Siamant,

    The Procedural Mesh Object is side object related. Do you want to create a road based on your own source mesh? You could do that but it will not be possible to integrate it with the crossings system.

    What do you mean with "empty mesh"? No mesh asset at all or no geometry? Can you notice a pattern?

    It is hard to comment on this without further info. If you want you can send me the souce mesh so I can test it, or better, a project / scene where I can see the problem. Please send me an email or PM in that case.

    Thanks,
    Raoul
     
  40. Siamant

    Siamant

    Joined:
    Oct 27, 2016
    Posts:
    3
    Yeah, I want to make road, based on my own mesh, because I need the road to be not flat. Empty mesh varies =) Sometimes, it is just mesh with zero vertices and sometimes I get mesh, erased in a single line, but it contains about 36k vertices.

    Finally, I get the result, but I don't know, what I've changed to solve the problem)
    Here is my road mesh

    Thank you
     

    Attached Files:

    • Road.zip
      File size:
      43.6 KB
      Views:
      476
  41. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    So you got it working now?

    I just tested the mesh as a procedural side object, adding markers, inserting markers changing the shape for a couple of minutes. It was always generated as expected.



    Thanks,
    Raoul
     
  42. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    Hi Raoul. Long time, no seen :)

    I have a little problem. I know, I can somehow via hundreds of errors make
    editor for 2x and 4x roading too, but this maid be a good thing for easyroads too.

    Lets see, I have terrain, splitted to 4 pieces. I edit only one of them and I want
    copy all objects from it to other pieces too.

    Right now I can modify terrain, copy objects and paint that way, but I have a problem
    with roads. I even try copy "master" road points and create a new road
    to another position, but it is hard to get those roads to same start/end position.
    Also, I have to connect them by hand later on on waypoint data.

    So, do you have a time to expand your editor to work with 2x and 4x worlds.

     
    Last edited: Oct 31, 2016
  43. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Hi Jari, :)

    So what you want is copy all roads on a terrain to a similar position on another terrain?

    This seems to be a very project specific operation. Have you tried doing this through the scripting API?

    Or did I misunderstood the question, in that case please let me know in detail what you need.

    Thanks,
    Raoul
     
  44. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    No, not to another terrain. To same terrain, what is divided by 2 (left & right) or by 4.

    This kind of roading system is MUST for RPG style game coders.

    For example 4x. Terrain's middle is positioned as 0,0. Coords x,z below 0 belongs to editable
    part, any others are just copies from editable part.

    For 2x coord x < 0 belongs to editable...
     
  45. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Sorry Jari, please be more specific in detail.

    What kind of functionality would you like to see added to EasyRoads3D for this?

    Thanks,
    Raoul
     
  46. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    Hey, now I know how I can put it to work, BUT I need an public call for "Flip Road Texture" button's code! That button makes copied road visible.

    Otherwise simple road copy via markers duplicate leaves the road invisible (after baking roads to my road system, it is visible via terrain shaders, but for editing it's not)
     
    Last edited: Oct 31, 2016
  47. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    Now I know how to do it By my code, but RPG coders usually make an one BIG terrain and split it several visual pieces. NOT splitting to many terrains, just for visualing. So, they make only an one players area ready and copy that area for other players position too. So, every players have an identical view on their own "box". Same resources, same roads if any, same prebuilded houses etc....

    This code below copies all ORIGINAL roads to new positions. But it needs that
    Flip Road Texture function. Now I have to click by hand on every selected road.

    Code (CSharp):
    1.    
    2. void Roading()
    3.     {
    4.         if (rnet == null)
    5.         {
    6.             rnet = new ERRoadNetwork();
    7.             rnet.roadNetwork.enableBackWithoutRestore = true;
    8.         }
    9.         GameObject rr = GameObject.Find("RuntimeRoads");
    10.         ERRoad[] allobjects_a;
    11.         List<ERRoad> allobjects_b = new List<ERRoad>();
    12.         FatherObjects.Clear();
    13.         // First get all roads....
    14.  
    15.         allobjects_a = rnet.GetRoads();
    16.  
    17.         foreach(ERRoad er in allobjects_a)
    18.         {
    19.             if (er.gameObject.name.Contains("LR-") ||
    20.                 er.gameObject.name.Contains("UR-") ||
    21.                 er.gameObject.name.Contains("UL-"))
    22.             {
    23.                 er.Destroy(); // Cloned, so, delete before creating a new one
    24.             }
    25.             else
    26.             {
    27.                 allobjects_b.Add(er); // If not cloned, add for copylist
    28.             }
    29.         }
    30.  
    31.         if (allobjects_b.Count > 0)
    32.         {
    33.             foreach (ERRoad go in allobjects_b)
    34.             {
    35.                 if (go != null)
    36.                 {
    37.                     Vector3[] rpoints = go.GetMarkerPositions();
    38.                     List<Vector3> lrpoints = new List<Vector3>();
    39.                     List<Vector3> urpoints = new List<Vector3>();
    40.                     List<Vector3> ulpoints = new List<Vector3>();
    41.                     foreach (Vector3 rp in rpoints)
    42.                     {
    43.                         // Transfer point positions to lower right
    44.                         Vector3 temp = rp;
    45.                         temp.z = rp.x;
    46.                         temp.x = rp.z * -1;
    47.                         lrpoints.Add(temp);
    48.                         // Transfer point positions to upper right
    49.                         temp = rp;
    50.                         temp.z = rp.z * -1;
    51.                         temp.x = rp.x * -1;
    52.                         urpoints.Add(temp);
    53.                         // Transfer point positions to upper right
    54.                         temp = rp;
    55.                         temp.z = rp.x * -1;
    56.                         temp.x = rp.z;
    57.                         ulpoints.Add(temp);
    58.                     }
    59.                     ERRoadType roadType = new ERRoadType();
    60.                     roadType.tag = "ROAD";
    61.                     roadType.layer = 11;
    62.                     roadType.roadWidth = go.roadScript.roadWidth;
    63.                     roadType.sidewalks = false;
    64.                     roadType.roadMaterial = go.roadScript.roadMaterial;
    65.  
    66.                     ERRoad newlr = rnet.CreateRoad("LR-" + go.gameObject.name,roadType,lrpoints.ToArray());
    67.                     newlr.SetResolution(1);
    68.                     newlr.SnapToTerrain(true, 0.01f);
    69.  
    70.                     ERRoad newur = rnet.CreateRoad("UR-" + go.gameObject.name, roadType, urpoints.ToArray());
    71.                     newur.SetResolution(1);
    72.                     newur.SnapToTerrain(true, 0.01f);
    73.  
    74.                     ERRoad newul = rnet.CreateRoad("UL-" + go.gameObject.name, roadType, ulpoints.ToArray());
    75.                     newul.SetResolution(1);
    76.                     newul.SnapToTerrain(true, 0.01f);
    77.                 }
    78.             }
    79.         }
    80.         roadingtime = Time.time;
    81.     }
    82.  
    And the result:

     
    Last edited: Oct 31, 2016
  48. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Ok I will add the flip texture option to the API. An API option for "Duplicate Object" is probably als useful in the case that side objects are involved. You will only have to update the marker positions either by mirroring or rotating relative to the center.

    Thanks,
    Raoul
     
  49. JOKaija

    JOKaija

    Joined:
    Feb 8, 2015
    Posts:
    161
    It would be a nice draw WALLS like that :)

    Btw, I can't get this work:

    roadType.roadMaterial = go.roadScript.roadMaterial;

    roadType.roadMaterial = xxxx will never change the material. I have to always find a road By name
    from assets folder and at runtime set it's gameobject.getcomponent<MeshRenderer>().material = xxxx;
     
    Last edited: Oct 31, 2016
  50. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    That will only update the road type material, newly created roads using that road type should show the new material.

    For existing roads you can use:

    ERRoad.SetMaterial(Material mat)

    Thanks,
    Raoul