├── BME.xml ├── BME.xml.meta ├── CrossingComplex8Course.xml ├── CrossingComplex8Course.xml.meta ├── ERVegetationStudio.cs ├── ERVegetationStudio.cs.meta ├── PathCreator.cs ├── PathCreator.cs.meta ├── README.md ├── Town01.xml ├── Town01.xml.meta ├── XODR2PATH.cs ├── XODR2PATH.cs.meta ├── XODR2PATH.zip ├── XODR2PATH.zip.meta ├── XODR_Basics.cs ├── XODR_Basics.cs.meta ├── comitted.meta ├── comitted ├── XODR2PATH.txt ├── XODR2PATH.txt.meta ├── XODR_Basics.txt └── XODR_Basics.txt.meta ├── desktop.ini ├── desktop.ini.meta ├── pics ├── MultiLane │ ├── 1Screenshot from 2020-09-18 15-27-50.png │ ├── 1Sign.png │ ├── 1_1.png │ ├── 1_2.png │ ├── 2Screenshot from 2020-09-18 15-28-00.png │ ├── 2Sign.png │ ├── 3Screenshot from 2020-09-18 15-37-35.png │ ├── 4Screenshot from 2020-09-18 15-29-23.png │ ├── FChart.png │ ├── Screenshot from 2020-09-18 15-27-57.png │ ├── Screenshot from 2020-09-18 15-28-08.png │ ├── Screenshot from 2020-09-18 15-28-24.png │ ├── Screenshot from 2020-09-18 15-28-26.png │ ├── Screenshot from 2020-09-18 15-28-28.png │ ├── Screenshot from 2020-09-18 15-28-38.png │ ├── Screenshot from 2020-09-18 15-28-39.png │ ├── Screenshot from 2020-09-18 15-29-01.png │ ├── Screenshot from 2020-09-18 15-29-13.png │ ├── Screenshot from 2020-09-18 15-29-57.png │ ├── Screenshot from 2020-09-18 15-29-59.png │ ├── Screenshot from 2020-09-18 15-37-26.png │ ├── Screenshot from 2020-09-18 15-37-27.png │ ├── Screenshot from 2020-09-18 15-37-43.png │ ├── Screenshot from 2020-09-18 15-37-50.png │ ├── Screenshot from 2020-09-18 15-37-53.png │ ├── Screenshot from 2020-09-18 15-37-56.png │ ├── Screenshot from 2020-09-24 16-20-25.png │ └── verification.png ├── arcGeo.png ├── arcNeg.png ├── arcPos.png └── xodr2path_Arcs_Lines.png ├── runtimeScript.cs ├── runtimeScript.cs.meta ├── simulinkPath.cs ├── simulinkPath.cs.meta ├── xodr2path(comitted).txt └── xodr2path(comitted).txt.meta /BME.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c44dc0c9b4de5b87d8ebea5d4a701885 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /CrossingComplex8Course.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2365e6e324f701cb684eb4f28ee16b76 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /ERVegetationStudio.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using EasyRoads3Dv3; 4 | 5 | public class ERVegetationStudio : ScriptableObject { 6 | 7 | static public bool VegetationStudio(){ 8 | #if VEGETATION_STUDIO 9 | return true; 10 | #else 11 | return false; 12 | #endif 13 | } 14 | 15 | static public void CreateVegetationMaskLine(GameObject go, float grassPerimeter, float plantPerimeter, float treePerimeter, float objectPerimeter, float largeObjectPerimeter){ 16 | #if VEGETATION_STUDIO 17 | AwesomeTechnologies.VegetationMaskLine vegetationMaskLine = go.GetComponent(); 18 | 19 | if (vegetationMaskLine == null) 20 | { 21 | vegetationMaskLine = go.AddComponent(); 22 | } 23 | 24 | vegetationMaskLine.AdditionalGrassPerimiter = grassPerimeter; 25 | vegetationMaskLine.AdditionalPlantPerimiter = plantPerimeter; 26 | vegetationMaskLine.AdditionalTreePerimiter = treePerimeter; 27 | vegetationMaskLine.AdditionalObjectPerimiter = objectPerimeter; 28 | vegetationMaskLine.AdditionalLargeObjectPerimiter = largeObjectPerimeter; 29 | #endif 30 | } 31 | 32 | 33 | static public void UpdateVegetationMaskLine(GameObject go, ERVSData[] vsData, float grassPerimeter, float plantPerimeter, float treePerimeter, float objectPerimeter, float largeObjectPerimeter){ 34 | #if VEGETATION_STUDIO 35 | AwesomeTechnologies.VegetationMaskLine vegetationMaskLine = go.GetComponent(); 36 | 37 | if (vegetationMaskLine == null) 38 | { 39 | vegetationMaskLine = go.AddComponent(); 40 | vegetationMaskLine.AdditionalGrassPerimiter = grassPerimeter; 41 | vegetationMaskLine.AdditionalPlantPerimiter = plantPerimeter; 42 | vegetationMaskLine.AdditionalTreePerimiter = treePerimeter; 43 | vegetationMaskLine.AdditionalObjectPerimiter = objectPerimeter; 44 | vegetationMaskLine.AdditionalLargeObjectPerimiter = largeObjectPerimeter; 45 | } 46 | 47 | vegetationMaskLine.ClearNodes(); 48 | 49 | 50 | foreach (ERVSData data in vsData) 51 | { 52 | vegetationMaskLine.AddNodeToEnd(data.position, data.width, data.active); 53 | } 54 | 55 | 56 | // vegetationMaskLine.AddNodeToEnd(nodePositions[0], widths[0], activeStates[0]); 57 | 58 | vegetationMaskLine.UpdateVegetationMask(); 59 | #endif 60 | } 61 | 62 | static public void UpdateHeightmap(Bounds bounds){ 63 | #if VEGETATION_STUDIO 64 | AwesomeTechnologies.VegetationStudio.VegetationStudioManager.RefreshTerrainHeightMap(); 65 | #endif 66 | } 67 | 68 | 69 | 70 | } 71 | 72 | -------------------------------------------------------------------------------- /ERVegetationStudio.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 773d0ff709563a04b8a0cd10d1e82808 3 | timeCreated: 1529944459 4 | licenseType: Store 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /PathCreator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using EasyRoads3Dv3; 5 | 6 | 7 | public class PathCreator : MonoBehaviour{ 8 | 9 | public ERRoadNetwork roadNetwork; 10 | //__________________________________________ 11 | public ERRoad road1; 12 | public ERRoad road2; 13 | public ERRoad road3; 14 | public ERRoad road4; 15 | public ERRoad road5; 16 | public ERRoad road6; 17 | public ERRoad road7; 18 | public ERRoad road8; 19 | public ERRoad road9; 20 | public ERRoad road10; 21 | public ERRoad road11; 22 | public ERRoad road12; 23 | 24 | //__________________________________________ 25 | //public ERRoad[] roads; 26 | //__________________________________________ 27 | public GameObject go; 28 | 29 | void Start() 30 | { 31 | 32 | roadNetwork = new ERRoadNetwork(); 33 | //_____________________________________________________________________________________________ 34 | ERRoadType roadType = new ERRoadType(); 35 | roadType.roadWidth = 35; 36 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 37 | //____________________________________________________________________________________________ 38 | 39 | /* 40 | roads[0] = roadNetwork.CreateRoad("road 1", roadType, markers1); 41 | roads[1] = roadNetwork.CreateRoad("road 2", roadType, markers2); 42 | 43 | roads[0] = roadNetwork.ConnectRoads(roads[0], roads[1]); 44 | */ 45 | 46 | //_____________________________________________________________________________________________ 47 | Vector3[] markers1 = new Vector3[2]; 48 | markers1[0] = new Vector3(70, 0, 0); 49 | markers1[1] = new Vector3(430, 0, 0); 50 | //_____________________________________________________________________________________________ 51 | Vector3[] markers2 = new Vector3[2]; 52 | markers2[0] = new Vector3(500, 0, 70); 53 | markers2[1] = new Vector3(500, 0, 430); 54 | //_____________________________________________________________________________________________ 55 | Vector3[] markers3 = new Vector3[2]; 56 | markers3[0] = new Vector3(570, 0, 500); 57 | markers3[1] = new Vector3(930, 0, 500); 58 | //_____________________________________________________________________________________________ 59 | Vector3[] markers4 = new Vector3[2]; 60 | markers4[0] = new Vector3(1000, 0, 430); 61 | markers4[1] = new Vector3(1000, 0, 70); 62 | //_____________________________________________________________________________________________ 63 | Vector3[] markers5 = new Vector3[2]; 64 | markers5[0] = new Vector3(1070, 0, 0); 65 | markers5[1] = new Vector3(1430, 0, 0); 66 | //_____________________________________________________________________________________________ 67 | Vector3[] markers6 = new Vector3[2]; 68 | markers6[0] = new Vector3(1500, 0, -70); 69 | markers6[1] = new Vector3(1500, 0, -430); 70 | //_____________________________________________________________________________________________ 71 | Vector3[] markers7 = new Vector3[2]; 72 | markers7[0] = new Vector3(1430, 0, -500); 73 | markers7[1] = new Vector3(1070, 0, -500); 74 | //_____________________________________________________________________________________________ 75 | Vector3[] markers8 = new Vector3[2]; 76 | markers8[0] = new Vector3(1000, 0, -570); 77 | markers8[1] = new Vector3(1000, 0, -930); 78 | //_____________________________________________________________________________________________ 79 | Vector3[] markers9 = new Vector3[2]; 80 | markers9[0] = new Vector3(930, 0, -1000); 81 | markers9[1] = new Vector3(570, 0, -1000); 82 | //_____________________________________________________________________________________________ 83 | Vector3[] markers10 = new Vector3[2]; 84 | markers10[0] = new Vector3(500, 0, -930); 85 | markers10[1] = new Vector3(500, 0, -570); 86 | //_____________________________________________________________________________________________ 87 | Vector3[] markers11 = new Vector3[2]; 88 | markers11[0] = new Vector3(430, 0, -500); 89 | markers11[1] = new Vector3(70, 0, -500); 90 | //_____________________________________________________________________________________________ 91 | Vector3[] markers12 = new Vector3[2]; 92 | markers12[0] = new Vector3(0, 0, -430); 93 | markers12[1] = new Vector3(0, 0, -70); 94 | //_____________________________________________________________________________________________ 95 | road1 = roadNetwork.CreateRoad("road 1", roadType, markers1); 96 | road2 = roadNetwork.CreateRoad("road 2", roadType, markers2); 97 | road3 = roadNetwork.CreateRoad("road 3", roadType, markers3); 98 | road4 = roadNetwork.CreateRoad("road 4", roadType, markers4); 99 | road5 = roadNetwork.CreateRoad("road 5", roadType, markers5); 100 | road6 = roadNetwork.CreateRoad("road 6", roadType, markers6); 101 | road7 = roadNetwork.CreateRoad("road 7", roadType, markers7); 102 | road8 = roadNetwork.CreateRoad("road 8", roadType, markers8); 103 | road9 = roadNetwork.CreateRoad("road 9", roadType, markers9); 104 | road10 = roadNetwork.CreateRoad("road 10", roadType, markers10); 105 | road11 = roadNetwork.CreateRoad("road 11", roadType, markers11); 106 | road12 = roadNetwork.CreateRoad("road 12", roadType, markers12); 107 | road1 = roadNetwork.ConnectRoads(road1, road2); 108 | road1 = roadNetwork.ConnectRoads(road1, road3); 109 | road1 = roadNetwork.ConnectRoads(road1, road4); 110 | road1 = roadNetwork.ConnectRoads(road1, road5); 111 | road1 = roadNetwork.ConnectRoads(road1, road6); 112 | road1 = roadNetwork.ConnectRoads(road1, road7); 113 | road1 = roadNetwork.ConnectRoads(road1, road8); 114 | road1 = roadNetwork.ConnectRoads(road1, road9); 115 | road1 = roadNetwork.ConnectRoads(road1, road10); 116 | road1 = roadNetwork.ConnectRoads(road1, road11); 117 | road1 = roadNetwork.ConnectRoads(road1, road12); 118 | road1.ClosedTrack(true); 119 | //road12 = roadNetwork.ConnectRoads(road12, road1); 120 | 121 | //road1 = roadNetwork.ConnectRoads(road1, road1); 122 | 123 | 124 | 125 | //go = Resources.Load("dynamic prefabs/zeg_T") as GameObject; // 126 | //go.transform.Translate(3.5f, 3.5f, 3.5f); 127 | //go.transform.Rotate(0.0f, 180.0f, 0.0f, Space.Self); 128 | //Instantiate(go, new Vector3(500, 0, 0), Quaternion.identity); 129 | //Instantiate (Resources.Load ("Category1/Hatchet")) as GameObject; 130 | 131 | 132 | } 133 | 134 | 135 | void Update() 136 | { 137 | 138 | } 139 | 140 | } 141 | 142 | 143 | -------------------------------------------------------------------------------- /PathCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5bccf001b74af9d96a542f3bab68fede 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Road Generator | Development of simulation environment in Unity based on OpenDRIVE file to simulate vehicle behavior and point cloud data 2 | ____________________________________________________________________________________________________________________________________________ 3 | 4 | ____________________________________________________________________________________________________________________________________________ 5 | 6 | Game engines can be used for the validation of environment simulation, vehicle dynamics, and complex AD algorithms in different scenarios. The goal of this project was to create a simulation environment in Unity3D using the predefined OpenDRIVE file to simulate vehicle behavior and point-cloud data gathered by perception sensors. This research work focuses on the development of a road generator application for creating a road structure and corresponding visualization data in a driving simulator. The application is based on the OpenDRIVE file, which is a standardized file format. The OpenDRIVE files contain a dataset that describes the road structure and covers all the properties regarding road geometry. 7 | 8 | 9 | ![image](https://user-images.githubusercontent.com/29532729/113411704-cc8c2680-93b6-11eb-8141-b8b7f7225606.png) 10 | 11 | To display the road and its environment in Unity, EasyRoads3D toolset which contains dynamic crossing prefabs and side objects, such as bridges, guard rails, traffic signs is used. 12 | 13 | 14 | ______________________________________________________________________________________________________________________________________________________ 15 | # OPEN DRIVE – ROAD DESCRIPTION STANDARD 16 | 17 | Several standardized file formats have been developed in the automotive industry for companies that require similar datasets for their simulators, including road networks and road objects. One of the most prominent standardized file formats developed by VIRES is OpenDRIVE. 18 | 19 | This file format was created in order to simplify the exchange of data between simulation programs and companies. The OpenDRIVE standard was recognized by many companies after the first public version was released in 2006. OpenDRIVE stores data in an XML format. In the XML file, nodes indicate various properties of the road, including intersections, elevations, and lane parameters. The figure below shows the hierarchical architecture of OpenDRIVE. 20 | 21 | 22 | ![image](https://user-images.githubusercontent.com/29532729/113411818-0a894a80-93b7-11eb-8ef8-8cd8f72dfde8.png) 23 | 24 | ______________________________________________________________________________________________________________________________________________________ 25 | # Road Geometry 26 | 27 | Geospatial data needs to be represented in various ways, including mapping and visualization. Therefore, a suitable type of data and object representation must be provided by the geodata models. In OpenDRIVE, the geometry of road segments is derived analytically from the chord line and the track coordinate system. In simulators, road layouts must be visualized relative to the center of the 3D world. 28 | 29 | ![image](https://user-images.githubusercontent.com/29532729/113411887-399fbc00-93b7-11eb-9503-1111135585d8.png) 30 | 31 | OpenDRIVE describes the layout of each road segment using geometric records based on its types, such as lines, arcs, and spirals. 32 | 33 | The following information is contained in each record: 34 | 35 | • An s offset, 36 | 37 | • A world coordinate which defines starting point, 38 | 39 | • A heading angle which describes the initial orientation of the road segment (In 40 | OpenDRIVE standard, heading angle is defined in terms of radians.) 41 | 42 | • The length of the road segment. 43 | 44 | 45 | Further, each geometry record contains an attribute that describes the type of geometry. 46 | 47 | Geometries can be divided into several types: 48 | 49 | • Lines – have no additional parameters 50 | 51 | • Arcs – have a constant curvature parameter 52 | 53 | • Spiral – have two curvature parameters for the start and end of the segment 54 | 55 | 56 | ______________________________________________________________________________________________________________________________________________________ 57 | 58 | ![image](https://user-images.githubusercontent.com/29532729/113412006-7ec3ee00-93b7-11eb-812a-4e916c4a3e53.png) 59 | 60 | 61 | 62 | - Line Geometry : In case of a line geometry as shown in the above figure, its ending points can be found using the following equations: 63 | 64 | • xEnding = xStarting + cos(hdg) ∗ (sEnding − sGeom ) 65 | 66 | • yEnding = yStarting + sin(hdg) ∗ (sEnding − sGeom ) 67 | 68 | 69 | ______________________________________________________________________________________________________________________________________________________ 70 | 71 | 72 | - Arc Geometry : Arc geometry is bit more complicated that the line geometry. By using curvature parameter, the radius of the arc can be computed as: 73 | 74 | • radius = | 1 / curvature | 75 | 76 | ![image](https://user-images.githubusercontent.com/29532729/113454566-d8083d80-9408-11eb-8261-22369df76716.png) 77 | 78 | Since the initial heading angle and arc radius are known, the center of the arc can be computed depending on the curvature sign: 79 | 80 | • xArc = xStarting + cos (hdg + ( (pi/2) * Sign * (-1)) − π) ∗ radius 81 | 82 | • yArc = yStarting + sin (hdg + ( (pi/2) * Sign * (-1)) − π) ∗ radius 83 | 84 | To compute the central angle of the arc in terms of radians, the following equation is used. 85 | 86 | θcentral = length_arc / radius 87 | 88 | ______________________________________________________________________________________________________________________________________________________ 89 | # DESIGN and DEVELOPMENT OF ROAD GENERATOR APPLICATION 90 | 91 | ![image](https://user-images.githubusercontent.com/29532729/113470544-ad44d600-9456-11eb-9bdf-43488373403e.png) 92 | 93 | 94 | As can be seen in the above fiure, the RoadGenerator application has several subcomponents that handle different tasks, like parsing and reading XML file, getting node attributes, etc. 95 | 96 | The RoadGenerator application is responsible for creating the segments of the road geometry, which is described in OpenDRIVE file, in Unity platform. Below figure indicates an overview of RoadGenerator application's flowchart. 97 | 98 | ![image](https://user-images.githubusercontent.com/29532729/113454962-c4110b80-9409-11eb-9244-d7d55a0e0b37.png) 99 | 100 | To be able to use the assets of EasyRoads3D toolset, it is required to create instances of ERRoadNetwork and ERRoadType classes. Moreover, the roadWidth and roadMaterial. 101 | 102 | ![image](https://user-images.githubusercontent.com/29532729/113454989-d428eb00-9409-11eb-9a4d-1314b57ac15a.png) 103 | 104 | Based on the order of geometry nodes in OpenDRIVE file, the Lineroads and Arcroads containers individually hold the road segment assets as a list. Likewise, the linePaths and arcPaths hold road geometry parameters such as, starting points, ending points, heading angle, etc. 105 | 106 | ![image](https://user-images.githubusercontent.com/29532729/113455014-dd19bc80-9409-11eb-8753-9c7c22a72b12.png) 107 | 108 | 109 | parseFile function deals with reading the file in given directory and selecting the nodes based on the desired tag name which is geometry. It returns those nodes in a list. 110 | 111 | ![image](https://user-images.githubusercontent.com/29532729/113455029-e30f9d80-9409-11eb-8e16-250b3921f6d2.png) 112 | 113 | 114 | In the OpenDRIVE file, the geometric parameters of road layout are represented as attributes of child nodes under geometry node. To be able to perform arithmetic calculations by using attributes, it is required to convert them from string to float format. As depicted in the below figure, the attribute format is converted from string to float. 115 | 116 | ![image](https://user-images.githubusercontent.com/29532729/113455113-1eaa6780-940a-11eb-9e8b-e3dbd67d3b4e.png) 117 | 118 | 119 | All types of road geometries have common parameters such as starting points in X and Y axes, road segment id, to describe road geometry. Therefore, an abstract class which is named paths was created to hold these information as its variables. Other classes which are responsible for holding information about relevant road type like, LinePath and ArcPath, are derived from the paths abstract class. 120 | 121 | ![image](https://user-images.githubusercontent.com/29532729/113455129-2a962980-940a-11eb-9dac-b7d569ab5f78.png) 122 | 123 | 124 | The constructor of LinePath class performs to compute ending point of a road segment based on the given starting point, road length, and heading angle. Both starting and ending points of road segment are stored in a 3D Vector to be used for creating game objects in Unity via EasyRoads3D toolset. 125 | 126 | ![image](https://user-images.githubusercontent.com/29532729/113455157-397cdc00-940a-11eb-95a4-81b658031022.png) 127 | 128 | 129 | In addition to the arguments taken by the LinePath class' constructor, the constructor of ArcPath class also takes the curvature parameter as an argument. By doing so, it acquires all parameters required for computing the starting point, final point, central point, and the points between starting and endpoint. 130 | 131 | 132 | ![image](https://user-images.githubusercontent.com/29532729/113455170-400b5380-940a-11eb-9c65-23e9f29c70eb.png) 133 | 134 | 135 | To visualize road segments in Unity platform based on the calculated points, the assets of the EasyRoads3D toolset are used as game objects. 136 | 137 | ![image](https://user-images.githubusercontent.com/29532729/113455180-48638e80-940a-11eb-83dd-2057bd60ccc4.png) 138 | 139 | ______________________________________________________________________________________________________________________________________________________ 140 | 141 | 142 | 143 | 144 | 145 | # EVALUATION 146 | 147 | We compared the road network generated in Unity with the SUMO simulator to determine how accurate the road generator can create road networks. The below figure indicates the comparison of the road networks simulated in different platforms. 148 | 149 | 150 | -------------------------------------------------------------------------------- /Town01.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87652740a70284430a6027016edd22a1 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /XODR2PATH.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Runtime.CompilerServices; 3 | using System.Security.AccessControl; 4 | using System.Data.SqlTypes; 5 | using System.Xml.Linq; 6 | 7 | using System; 8 | using System.Collections; 9 | using System.Collections.Generic; 10 | using UnityEngine; 11 | using EasyRoads3Dv3; 12 | //___________________________ 13 | using System.Xml; 14 | using System.IO; 15 | 16 | 17 | public enum PathType : ushort{ 18 | None = 0, 19 | Line = 1, 20 | Arc = 2, 21 | Spiral = 3 22 | } 23 | 24 | 25 | public class XODR2PATH : MonoBehaviour{ 26 | 27 | public ERRoadNetwork roadNetwork; 28 | 29 | void Start() 30 | { 31 | //_______________________________________________// 32 | roadNetwork = new ERRoadNetwork(); // 33 | ERRoadType roadType = new ERRoadType(); // 34 | //_______________________________________________// 35 | //____________________________________________________________________________________________// 36 | roadType.roadWidth = 8.0f; // Road Width 37 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; // Road Material -> Marking Type etc. 38 | roadType.layer = 1; // 39 | roadType.tag = "Untagged"; // 40 | //____________________________________________________________________________________________// 41 | //______________________________________________// 42 | //______________________________________________// 43 | var LineRoads = new List(); // The container individually keeps road components 44 | var linePaths = new List(); // The container individually keeps road components with the line geometry 45 | //______________________________________________// 46 | var ArcRoads = new List(); // The container individually keeps road components 47 | var arcPaths = new List(); // The container individually keeps road components with the arc geometry 48 | //______________________________________________// 49 | //______________________________________________/ 50 | 51 | 52 | //_____________________ XML PARSING _____________________// 53 | //_______________________________________________________// 54 | XML_File XODR_File = new XML_File(); // 55 | XmlNodeList geoList = XODR_File.getGeoList(); // 56 | XmlNodeList signalsList = XODR_File.getSignalsList(); // 57 | XmlNodeList PlanViewList = XODR_File.getPlanViewList(); // 58 | //_______________________________________________________// 59 | //_______________________________________________________// 60 | 61 | PathType pathType; 62 | double tmp; 63 | int numberOfSignal; 64 | 65 | int[] arrGeo = new int[PlanViewList.Count]; 66 | int[] arrSignal = new int[PlanViewList.Count]; 67 | 68 | int cntr = 0; 69 | int cntrGeo = 0; 70 | int cntrSig = 0; 71 | for(int i=0; i< PlanViewList.Count; i++){ 72 | //******************************************************************// 73 | cntr = 0; // 74 | foreach(XmlNode child in PlanViewList[i].ChildNodes){ // 75 | cntr ++; // 76 | } // 77 | //Debug.Log("Num of Geo" + cntr); // 78 | arrGeo[i] = cntr; // 79 | //**************************************************************// 80 | cntr = 0; // 81 | if(signalsList.Count != 0){ // 82 | foreach(XmlNode child in signalsList[i].ChildNodes){ // 83 | cntr ++; // 84 | } // 85 | } // 86 | //Debug.Log("Num of Signal" + cntr); // 87 | arrSignal[i] = cntr; // 88 | } // 89 | //******************************************************************// 90 | 91 | 92 | 93 | int generalGeoCounter = 0; 94 | int generalSignalCounter = 0; 95 | float x_refPos, y_refPos; 96 | 97 | 98 | for(int j=0; j< PlanViewList.Count; j++){ 99 | 100 | float[] sValues = new float[10]; 101 | float[] tValues = new float[10]; 102 | trafficObjects newTrafficObject = new trafficObjects(); 103 | 104 | if(signalsList.Count != 0){ 105 | //Debug.Log("Signal list count : " + signalsList.Count); 106 | for(int q=0; q< arrSignal[j]; q++){ 107 | //Debug.Log("---------------------------------*******************"); 108 | foreach(XmlNode child in signalsList[generalSignalCounter].ChildNodes){ 109 | //Debug.Log(child.Name); 110 | if(child.Name == "signal"){ 111 | newTrafficObject.place = 1; 112 | XmlElement trafficSign = (System.Xml.XmlElement)child; 113 | var nameObj = trafficSign.GetAttribute("name"); 114 | //Debug.Log("Name of object" + nameObj); 115 | //_______________________________ 116 | var s_Value = trafficSign.GetAttribute("s"); 117 | double.TryParse( s_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 118 | float sVal = Convert.ToSingle(tmp); 119 | //_______________________________ 120 | var t_Value = trafficSign.GetAttribute("t"); 121 | double.TryParse( t_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 122 | float tVal = Convert.ToSingle(tmp); 123 | //_______________________________ 124 | //sValues[0] = sVal; 125 | //tValues[0] = tVal; 126 | newTrafficObject.sPos = sVal; 127 | newTrafficObject.tPos = tVal; 128 | //Debug.Log(" Planview" + j +", S val -> " + sVal); 129 | //Debug.Log(" t val -> " + tVal.ToString()); 130 | }else 131 | { 132 | Debug.Log("Unknown Child --------------"); 133 | } 134 | } 135 | } 136 | } 137 | 138 | generalSignalCounter++; 139 | 140 | for(int k=0; k< arrGeo[j]; k++){ 141 | foreach(XmlNode child in geoList[generalGeoCounter].ChildNodes){ 142 | //Debug.Log(generalGeoCounter); 143 | //Debug.Log(geoList.Count); 144 | if(child.Name == "line") 145 | { 146 | //_______________________________________________________________________________________________________________________________ 147 | XmlElement geoA = (System.Xml.XmlElement)geoList[generalGeoCounter]; 148 | //_______________________________________________________________________________________________________________________________// 149 | var s_Value = geoA.GetAttribute("s"); 150 | double.TryParse( s_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 151 | float sVal = Convert.ToSingle(tmp); 152 | //_______________________________________________________________________________________________________________________________ 153 | var x_Value = geoA.GetAttribute("x"); 154 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 155 | float xVal = Convert.ToSingle(tmp); 156 | //_______________________________________________________________________________________________________________________________ 157 | var y_Value = geoA.GetAttribute("y"); 158 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 159 | float yVal = Convert.ToSingle(tmp); 160 | //_______________________________________________________________________________________________________________________________ 161 | var heading = geoA.GetAttribute("hdg"); 162 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 163 | float hdgVal = Convert.ToSingle(tmp); 164 | //_______________________________________________________________________________________________________________________________ 165 | var length = geoA.GetAttribute("length"); 166 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 167 | float lenVal = Convert.ToSingle(tmp); 168 | //_______________________________________________________________________________________________________________________________ 169 | pathType = PathType.Line; 170 | linePaths.Add(new LinePath( linePaths.Count, xVal, yVal, lenVal, hdgVal)); 171 | LineRoads.Add(new ERRoad()); 172 | LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers); 173 | LineRoads[linePaths.Count-1].SetResolution(1000f); 174 | if( sVal == 0f){ 175 | x_refPos = xVal; 176 | y_refPos = yVal; 177 | } 178 | 179 | if( newTrafficObject.place == 1 && (newTrafficObject.sPosStart < sVal ) ){ 180 | //Debug.Log("111111111111"); 181 | newTrafficObject.sPosStart = sVal ; 182 | newTrafficObject.pathIndex = linePaths.Count-1; 183 | newTrafficObject.pathType = PathType.Line; 184 | }else if( newTrafficObject.place == 1 && (newTrafficObject.done == 0 && (newTrafficObject.sPosStart >= sVal))){ 185 | newTrafficObject.sPosEnd = sVal; 186 | float ratio = Math.Abs(newTrafficObject.sPos - newTrafficObject.sPosStart) / Math.Abs( newTrafficObject.sPosStart - newTrafficObject.sPosEnd); 187 | Debug.Log( "_____________________________________________"); 188 | Debug.Log( "x start " + linePaths[linePaths.Count-1].xStart + " x end" + linePaths[linePaths.Count-1].xEnd ); 189 | Debug.Log( "y start " + linePaths[linePaths.Count-1].yStart + " y end" + linePaths[linePaths.Count-1].yEnd ); 190 | newTrafficObject.done = 1; 191 | } 192 | 193 | }else if(child.Name == "arc"){ // 194 | XmlElement geoA = (System.Xml.XmlElement)geoList[generalGeoCounter]; 195 | //_______________________________________________________________________________________________________________________________// 196 | var s_Value = geoA.GetAttribute("s"); 197 | double.TryParse( s_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 198 | float sVal = Convert.ToSingle(tmp); 199 | //_______________________________________________________________________________________________________________________________ 200 | var x_Value = geoA.GetAttribute("x"); 201 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 202 | float xVal = Convert.ToSingle(tmp); 203 | //_______________________________________________________________________________________________________________________________// 204 | var y_Value = geoA.GetAttribute("y"); 205 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 206 | float yVal = Convert.ToSingle(tmp); 207 | //_______________________________________________________________________________________________________________________________// 208 | var heading = geoA.GetAttribute("hdg"); 209 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 210 | float hdgVal = Convert.ToSingle(tmp); 211 | //_______________________________________________________________________________________________________________________________// 212 | var length = geoA.GetAttribute("length"); 213 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 214 | float lenVal = Convert.ToSingle(tmp); 215 | //_______________________________________________________________________________________________________________________________// 216 | var child_curvature = child.Attributes["curvature"]; 217 | double.TryParse( child_curvature.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 218 | float curveVal = Convert.ToSingle(tmp); 219 | //_______________________________________________________________________________________________________________________________// 220 | //______________________________________________________________________// 221 | pathType = PathType.Arc; 222 | arcPaths.Add(new ARCPath( arcPaths.Count , xVal , yVal , lenVal, hdgVal, curveVal)); 223 | ArcRoads.Add(new ERRoad()); 224 | ArcRoads[arcPaths.Count-1] = roadNetwork.CreateRoad("arc"+ (arcPaths.Count-1).ToString(), roadType, arcPaths[arcPaths.Count-1].markers); 225 | ArcRoads[arcPaths.Count-1].SetResolution(1000f); 226 | 227 | if( sVal == 0f){ 228 | x_refPos = xVal; 229 | y_refPos = yVal; 230 | } 231 | 232 | }else if(child.Name == "spiral"){ 233 | //Debug.Log("Child Node Name ==> spiral" + i.ToString()); 234 | pathType = PathType.Spiral; 235 | } 236 | generalGeoCounter++; 237 | } 238 | } 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | } 249 | 250 | 251 | } 252 | 253 | 254 | public XmlNodeList parseFile() 255 | { 256 | //____________________________________________________________ 257 | XmlDocument doc = new XmlDocument(); 258 | doc.Load("CrossingComplex8Course.xml"); // CrossingComplex8Course // CrossingComplex8Course.xodr 259 | //____________________________________________________________ 260 | XmlNodeList elemList = doc.GetElementsByTagName("road"); //Element("OpenDRIVE").Elements("road"); 261 | //Debug.Log("1-"); 262 | //Debug.Log("Number of planView => " + elemList.Count); 263 | //____________________________________________________________ 264 | XmlNodeList geoList = doc.GetElementsByTagName("geometry"); //Element("OpenDRIVE").Elements("road"); 265 | //Debug .Log("2-"); 266 | //Debug.Log("Num of geometry tags" + geoList.Count); 267 | //____________________________________________________________ 268 | //XmlNodeList plan = doc.GetElementsByTagName("planView"); //Element("OpenDRIVE").Elements("road"); 269 | //Debug.Log("************** Count" + plan.Count.ToString()); 270 | return geoList; 271 | } 272 | } 273 | 274 | 275 | 276 | //_______________________________________ Traffic Objects _______________________________ 277 | 278 | public class trafficObjects{// : MonoBehaviour{ 279 | //____________________________ 280 | public float xPos; 281 | public float yPos; 282 | public float sPos; 283 | public float tPos; 284 | public float sPosStart; 285 | public float sPosEnd; 286 | public float tPosEnd; 287 | public PathType pathType; 288 | public int pathIndex; 289 | public int place; // determines if the object will be placed into the sim env 290 | public int done; 291 | //____________________________ 292 | public trafficObjects(){ 293 | this.place = 0; 294 | this.xPos = 0; 295 | this.yPos = 0; 296 | this.sPos = 0; 297 | this.tPos = 0; 298 | this.sPosStart = 0; 299 | this.sPosEnd = 0; 300 | this.tPosEnd = 0; 301 | this.done = 0; 302 | } 303 | 304 | } 305 | 306 | 307 | 308 | //___________________________________________________________________________________________ 309 | public abstract class paths{// : MonoBehaviour{ 310 | 311 | public float xStart; 312 | public float yStart; 313 | public int pathIndex; 314 | public abstract void createPath(); 315 | 316 | } 317 | 318 | //_____________________________________________________________________________________________________________________________________________________________________ 319 | //____________________________________________________________________________ LINE GEOMETRY __________________________________________________________________________ 320 | //____________________________________________________________ _______________________________________________________________________________________________________ 321 | public class LinePath : paths{ 322 | 323 | public float xEnd; 324 | public float yEnd; 325 | public float angle; 326 | public float length; 327 | //______________________________________ 328 | public Vector3[] markers = new Vector3[2]; 329 | public LinePath(int road_index , float x_Start, float y_Start, float length, float hdg){ 330 | //_________________________________// 331 | this.xStart = x_Start; // 332 | this.yStart = y_Start; // 333 | this.angle = hdg; // 334 | this.length = length; // 335 | this.pathIndex = road_index; // 336 | //_________________________________// 337 | //________________________________________________________________________________________________// // 338 | this.markers[0] = new Vector3(this.xStart, 0, this.yStart); // 339 | this.xEnd = this.xStart + Convert.ToSingle(Math.Cos(this.angle)) * this.length; // 340 | this.yEnd = this.yStart + Convert.ToSingle(Math.Sin(this.angle)) * this.length; // 341 | this.markers[1] = new Vector3(this.xEnd, 0, this.yEnd); // 342 | //________________________________________________________________________________________________// 343 | } 344 | 345 | public override void createPath(){ 346 | 347 | } 348 | 349 | } 350 | //_____________________________________________________________________________________________________________________________________________________________________ 351 | //_____________________________________________________________________________________________________________________________________________________________________ 352 | //_____________________________________________________________________________________________________________________________________________________________________ 353 | 354 | 355 | 356 | 357 | //_____________________________________________________________________________________________________________________________________________________________________ 358 | //____________________________________________________________________________ ARC GEOMETRY ___________________________________________________________________________ 359 | //_____________________________________________________________________________________________________________________________________________________________________ 360 | public class ARCPath : paths{ 361 | 362 | public float xCentral; 363 | public float xEnd; 364 | public float xTemp; 365 | 366 | public float yCentral; 367 | public float yEnd; 368 | public float yTemp; 369 | public float angle; 370 | public float length; 371 | public float radius; 372 | public float centralAngle; 373 | public int arrSize; 374 | public int sign; 375 | public Vector3[] tmp_markers; 376 | public Vector3[] markers; 377 | 378 | 379 | public ARCPath(int road_index ,float x_Start, float y_Start, float length, float hdg, float curvature){ 380 | this.xStart = x_Start; 381 | this.yStart = y_Start; 382 | this.length = length; 383 | this.pathIndex = road_index; 384 | this.radius = (Math.Abs(1 / curvature)); 385 | this.centralAngle = this.length / this.radius; 386 | //______________________________________________________________________________// 387 | //____________________________ NUMBER OF ONCREMENTS ____________________________// 388 | this.arrSize = Mathf.FloorToInt(this.length / 0.5f) + 2; // must be at least 2 389 | //______________________________________________________________________________// 390 | this.sign = Math.Sign(curvature); // 391 | //_________________________________________________________________________________________________// 392 | this.markers = new Vector3[this.arrSize]; // 393 | //this.tmp_markers = new Vector3[this.arrSize]; // 394 | //_________________________________________________________________________________________________// 395 | 396 | //_________________________________________________________________________________________________// 397 | //_________________________________ CENTRAL POINT _________________________________________________// 398 | this.xCentral = this.xStart + Convert.ToSingle( Math.Cos(hdg + (Math.PI / 2) * this.sign * (-1) - Math.PI)) * this.radius; 399 | this.yCentral = this.yStart + Convert.ToSingle( Math.Sin(hdg + (Math.PI / 2) * this.sign * (-1) - Math.PI)) * this.radius; 400 | //______________________________________________________________________________________________________________________________________________________________________// 401 | //______________________________________________________________________________________________________________________________________________________________________// 402 | this.xEnd = this.xCentral + Convert.ToSingle( Math.Cos( (hdg + (this.centralAngle) * this.sign) - (Math.PI / 2) * this.sign ) ) * this.radius; // 403 | this.yEnd = this.yCentral + Convert.ToSingle( Math.Sin( (hdg + (this.centralAngle) * this.sign) - (Math.PI / 2) * this.sign ) ) * this.radius; // 404 | //______________________________________________________________________________________________________________________________________________________________________// 405 | this.markers[this.arrSize-1] = new Vector3(this.xEnd, 0f, this.yEnd); // END 406 | this.markers[0] = new Vector3((this.xStart), 0, (this.yStart)); // START 407 | //______________________________________________________________________________________________________________________________________________________________________// 408 | //______________________________________________________________________________________________________________________________________________________________________// 409 | //___________________________________________________________ POINT BETWEEN START and END POINTS ___________________________________________________________________________________________________// 410 | //__________________________________________________________________________________________________________________________________________________________________________________________________// 411 | for(int i =1; i<(this.arrSize-1); i++){ // 412 | this.xTemp = this.xCentral + Convert.ToSingle( Math.Cos( (hdg + ((i) * (this.centralAngle/(this.arrSize-1))) * this.sign) - (Math.PI / 2) * this.sign )) * this.radius; // TODO => sign of cuvature 413 | this.yTemp = this.yCentral + Convert.ToSingle( Math.Sin( (hdg + ((i) * (this.centralAngle/(this.arrSize-1))) * this.sign) - (Math.PI / 2) * this.sign )) * this.radius; // TODO => sign of cuvature 414 | this.markers[i] = new Vector3(this.xTemp, 0, this.yTemp); // 415 | } // 416 | //__________________________________________________________________________________________________________________________________________________________________________________________________// 417 | //__________________________________________________________________________________________________________________________________________________________________________________________________// 418 | 419 | } 420 | 421 | public override void createPath(){ 422 | } 423 | 424 | } 425 | //_____________________________________________________________________________________________________________________________________________________________________ 426 | //_____________________________________________________________________________________________________________________________________________________________________ 427 | //_____________________________________________________________________________________________________________________________________________________________________ 428 | 429 | 430 | 431 | public class XML_File{ 432 | 433 | //______________________// 434 | XmlDocument doc; // 435 | //______________________// 436 | public XML_File(){ 437 | doc = new XmlDocument(); 438 | doc.Load("Ahmet3.xml"); // ("CrossingComplex8Course.xml"); // ("BME.xml"); // ("Town01.xml"); 439 | } 440 | 441 | public void getRoadList(){ 442 | XmlNodeList roadList = doc.GetElementsByTagName("road"); // 443 | //Debug.Log("Number of planView => " + elemList.Count); 444 | //Debug.Log("Number of roadList => " + roadList.Count); 445 | //return roadList; 446 | } 447 | 448 | public XmlNodeList getGeoList(){ 449 | XmlNodeList geoList = doc.GetElementsByTagName("geometry"); // 450 | //Debug.Log("Num of geometry tags" + geoList.Count); 451 | return geoList; 452 | } 453 | public XmlNodeList getSignalsList(){ 454 | XmlNodeList signalsList = doc.GetElementsByTagName("signals"); // 455 | //Debug.Log("Number of Signals in first element => " + signalList[0].ChildNodes.Count); numberOfSignal 456 | return signalsList; 457 | } 458 | 459 | public XmlNodeList getPlanViewList(){ 460 | XmlNodeList planViewList = doc.GetElementsByTagName("planView"); // 461 | //Debug.Log("Number of planViewList => " + planViewList.Count); 462 | return planViewList; 463 | } 464 | 465 | } 466 | -------------------------------------------------------------------------------- /XODR2PATH.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 27e571d7318b2ee4ca111954478f01ed 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /XODR2PATH.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/XODR2PATH.zip -------------------------------------------------------------------------------- /XODR2PATH.zip.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea38770cecd2723e2a5ddb2df20b2bb8 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /XODR_Basics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using EasyRoads3Dv3; 6 | //___________________________ 7 | using System.Xml; 8 | using System.IO; 9 | using System; 10 | 11 | public class XODR_Basics : MonoBehaviour{ 12 | 13 | public ERRoad road1; 14 | public ERRoadNetwork roadNetwork; 15 | //__________________________________________ 16 | public GameObject go; 17 | 18 | public enum PathType : ushort{ 19 | None = 0, 20 | Line = 1, 21 | Arc = 2, 22 | Spiral = 3 23 | } 24 | 25 | void Start() 26 | { 27 | 28 | roadNetwork = new ERRoadNetwork(); 29 | //_____________________________________________________________________________________________ 30 | ERRoadType roadType = new ERRoadType(); 31 | roadType.roadWidth = 4; 32 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 33 | 34 | //____________________________________________________________________________________________ 35 | var LineRoads = new List(); // The container individually keeps road components 36 | var linePaths = new List(); // The container individually keeps road components with the line geometry 37 | var ArcRoads = new List(); // The container individually keeps road components 38 | var arcPaths = new List(); // The container individually keeps road components with the arc geometry 39 | //var SpiralRoads = new List(); // The container individually keeps road components 40 | //var spiralPaths = new List(); // TO DO : !!!!! // The container individually keeps road components with the spiral geometry 41 | 42 | //_____________________________________________________________________________________________ 43 | Vector3[] markers1 = new Vector3[5]; 44 | markers1[0] = new Vector3( 0, 0, 0); 45 | markers1[1] = new Vector3( 5, 0, 50); 46 | markers1[2] = new Vector3(10, 0, 0); 47 | markers1[3] = new Vector3(30, 0, 0); 48 | markers1[4] = new Vector3(50, 0, 0); 49 | //_____________________________________________________________________________________________ 50 | 51 | road1 = roadNetwork.CreateRoad("road 1", roadType, markers1); 52 | 53 | //LinePath l1 = new LinePath( 0, 0.0f, 0.0f, 400.0f, 0f); 54 | //LineRoads.Add(new ERRoad()); 55 | //LineRoads[0] = roadNetwork.CreateRoad("line"+ l1.pathIndex.ToString(), roadType, l1.markers); 56 | //ARCPath a1 = new ARCPath( 0, 2.61f, -325.3f, 7.93f, -4.02f, -0.086f); //0.212f, 0f, -0.002f); //l1.xEnd, l1.yEnd, 800.0f, 0f, -0.002f); 57 | //ArcRoads.Add(new ERRoad()); 58 | //ArcRoads[0] = roadNetwork.CreateRoad("line"+ a1.pathIndex.ToString(), roadType, a1.markers); // put parameters into the relevant 59 | } 60 | 61 | 62 | void Update() 63 | { 64 | 65 | } 66 | 67 | } 68 | 69 | -------------------------------------------------------------------------------- /XODR_Basics.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc7d7a1003c2ac687b072f674ad71d35 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /comitted.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 20b6c1dd2864ef5b19931b587bda3085 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /comitted/XODR2PATH.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using EasyRoads3Dv3; 6 | //___________________________ 7 | using System.Xml; 8 | using System.IO; 9 | using System; 10 | 11 | public class XODR2PATH : MonoBehaviour{ 12 | 13 | public ERRoadNetwork roadNetwork; 14 | //__________________________________________ 15 | public ERRoad Road; 16 | public ERRoad road2; 17 | public ERRoad roadTemp; 18 | //__________________________________________ 19 | public GameObject go; 20 | 21 | public enum PathType : ushort{ 22 | None = 0, 23 | Line = 1, 24 | Arc = 2, 25 | Spiral = 3 26 | } 27 | 28 | void Start() 29 | { 30 | 31 | roadNetwork = new ERRoadNetwork(); 32 | //_____________________________________________________________________________________________ 33 | ERRoadType roadType = new ERRoadType(); 34 | roadType.roadWidth = 4.0f; 35 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 36 | roadType.layer = 1; 37 | roadType.tag = "Untagged"; 38 | //____________________________________________________________________________________________ 39 | 40 | var LineRoads = new List(); // The container individually keeps road components 41 | var linePaths = new List(); // The container individually keeps road components with the line geometry 42 | var ArcRoads = new List(); // The container individually keeps road components 43 | var arcPaths = new List(); // The container individually keeps road components with the arc geometry 44 | 45 | 46 | 47 | //var SpiralRoads = new List(); // The container individually keeps road components 48 | //var spiralPaths = new List(); // TO DO : !!!!! // The container individually keeps road components with the spiral geometry 49 | var connectedRoads = new List(); 50 | /* 51 | LinePath l1 = new LinePath( 0, 0.0f, 0.0f, 400.0f, 0f); 52 | roads.Add(new ERRoad()); 53 | roads[0] = roadNetwork.CreateRoad("line"+ l1.pathIndex.ToString(), roadType, l1.markers); 54 | ARCPath a1 = new ARCPath( 1, l1.xEnd, l1.yEnd, 800.0f, 0f, -0.002f); 55 | roads.Add(new ERRoad()); 56 | roads[1] = roadNetwork.CreateRoad("line"+ a1.pathIndex.ToString(), roadType, a1.markers); 57 | */ 58 | 59 | PathType pathType; 60 | XmlNodeList geoList = parseFile(); 61 | double tmp; 62 | 63 | //Debug.Log("_________--------_________------"+geoList.Count); 64 | //Debug.Log("Sin 90 : 1 ?= "+ Math.Cos()); // operates with the values in terms of Radian 65 | 66 | 67 | for(int i=0; i< geoList.Count; i++){ 68 | connectedRoads.Add(new ERRoad()); 69 | var gotFirst = false; 70 | foreach(XmlNode child in geoList[i].ChildNodes) 71 | { 72 | if(child.Name == "line") 73 | { 74 | //_______________________________________________________________________________________________________________________________ 75 | XmlElement geoA = (System.Xml.XmlElement)geoList[i]; 76 | var x_Value = geoA.GetAttribute("x"); 77 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 78 | float xVal = Convert.ToSingle(tmp); 79 | //_______________________________________________________________________________________________________________________________ 80 | var y_Value = geoA.GetAttribute("y"); 81 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 82 | float yVal = Convert.ToSingle(tmp); 83 | //_______________________________________________________________________________________________________________________________ 84 | var heading = geoA.GetAttribute("hdg"); 85 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 86 | float hdgVal = Convert.ToSingle(tmp); 87 | //_______________________________________________________________________________________________________________________________ 88 | var length = geoA.GetAttribute("length"); 89 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 90 | float lenVal = Convert.ToSingle(tmp); 91 | //_______________________________________________________________________________________________________________________________ 92 | //Debug.Log("Child Node Name ==> line" + i.ToString()); 93 | //Debug.Log("TYPEOF => " + x_Value.GetType()); 94 | //Debug.Log("Child Node Name ==> line" + i.ToString()); 95 | pathType = PathType.Line; 96 | linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal)); 97 | LineRoads.Add(new ERRoad()); 98 | LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers); 99 | }else if(child.Name == "arc"){ 100 | XmlElement geoA = (System.Xml.XmlElement)geoList[i]; 101 | //_______________________________________________________________________________________________________________________________ 102 | var x_Value = geoA.GetAttribute("x"); 103 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 104 | float xVal = Convert.ToSingle(tmp); 105 | //_______________________________________________________________________________________________________________________________ 106 | var y_Value = geoA.GetAttribute("y"); 107 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 108 | float yVal = Convert.ToSingle(tmp); 109 | //_______________________________________________________________________________________________________________________________ 110 | var heading = geoA.GetAttribute("hdg"); 111 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 112 | float hdgVal = Convert.ToSingle(tmp); 113 | //_______________________________________________________________________________________________________________________________ 114 | var length = geoA.GetAttribute("length"); 115 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 116 | float lenVal = Convert.ToSingle(tmp); 117 | //_______________________________________________________________________________________________________________________________ 118 | var child_curvature = child.Attributes["curvature"]; 119 | double.TryParse( child_curvature.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 120 | float curveVal = Convert.ToSingle(tmp); 121 | //_______________________________________________________________________________________________________________________________ 122 | //______________________________________________________________________// 123 | if(lenVal < 3.0f){ 124 | pathType = PathType.Line; 125 | linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal)); 126 | LineRoads.Add(new ERRoad()); 127 | LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("arc"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers); 128 | }else{ 129 | pathType = PathType.Arc; 130 | arcPaths.Add(new ARCPath( arcPaths.Count , xVal , yVal , lenVal, hdgVal, curveVal)); 131 | ArcRoads.Add(new ERRoad()); 132 | ArcRoads[arcPaths.Count-1] = roadNetwork.CreateRoad("arc"+ (arcPaths.Count-1).ToString(), roadType, arcPaths[arcPaths.Count-1].markers); 133 | } 134 | 135 | 136 | 137 | 138 | }else if(child.Name == "spiral"){ 139 | Debug.Log("Child Node Name ==> spiral" + i.ToString()); 140 | pathType = PathType.Spiral; 141 | } 142 | 143 | } 144 | } 145 | 146 | } 147 | 148 | 149 | public XmlNodeList parseFile() 150 | { 151 | //____________________________________________________________ 152 | XmlDocument doc = new XmlDocument(); 153 | doc.Load("Town01.xml"); 154 | //____________________________________________________________ 155 | XmlNodeList elemList = doc.GetElementsByTagName("road"); //Element("OpenDRIVE").Elements("road"); 156 | //Debug.Log("1-"); 157 | //Debug.Log("Number of planView => " + elemList.Count); 158 | //____________________________________________________________ 159 | XmlNodeList geoList = doc.GetElementsByTagName("geometry"); //Element("OpenDRIVE").Elements("road"); 160 | //Debug.Log("2-"); 161 | //Debug.Log("Num of geometry tags" + geoList.Count); 162 | //____________________________________________________________ 163 | return geoList; 164 | } 165 | 166 | /* 167 | void Update() 168 | { 169 | 170 | } 171 | */ 172 | } 173 | 174 | 175 | 176 | public abstract class paths{// : MonoBehaviour{ 177 | 178 | public float xStart; 179 | public float yStart; 180 | public int pathIndex; 181 | public abstract void createPath(); 182 | 183 | } 184 | 185 | //_____________________________________________________________________________________________________________________________________________________________________ 186 | //____________________________________________________________________________ LINE GEOMETRY __________________________________________________________________________ 187 | //_____________________________________________________________________________________________________________________________________________________________________ 188 | public class LinePath : paths{ 189 | 190 | public float xEnd; 191 | public float yEnd; 192 | public float angle; 193 | public float length; 194 | //______________________________________ 195 | public Vector3[] markers = new Vector3[2]; 196 | 197 | 198 | public LinePath(int road_index , float x_Start, float y_Start, float length, float hdg){ 199 | this.xStart = x_Start; 200 | this.yStart = y_Start; 201 | this.angle = hdg; //Convert.ToSingle(Math.PI) * (hdg) / 180.0f; 202 | this.length = length; 203 | this.pathIndex = road_index; 204 | //________________________________________________________________________________________________// // 205 | this.markers[0] = new Vector3(this.xStart, 0, this.yStart); // 206 | this.xEnd = this.xStart + Convert.ToSingle(Math.Cos(this.angle)) * this.length; // 207 | this.yEnd = this.yStart + Convert.ToSingle(Math.Sin(this.angle)) * this.length; // 208 | this.markers[1] = new Vector3(this.xEnd, 0, this.yEnd); // 209 | //________________________________________________________________________________________________// 210 | //roads[road_index] = roadNetwork.CreateRoad("line"+ this.pathIndex.ToString(), roadType, this.markers); // 211 | //________________________________________________________________________________________________// 212 | Debug.Log( "LENGTH => " + this.length); 213 | Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString()); 214 | 215 | } 216 | 217 | public override void createPath(){ 218 | 219 | } 220 | 221 | } 222 | //_____________________________________________________________________________________________________________________________________________________________________ 223 | //_____________________________________________________________________________________________________________________________________________________________________ 224 | //_____________________________________________________________________________________________________________________________________________________________________ 225 | 226 | 227 | 228 | 229 | //_____________________________________________________________________________________________________________________________________________________________________ 230 | //____________________________________________________________________________ ARC GEOMETRY ___________________________________________________________________________ 231 | //_____________________________________________________________________________________________________________________________________________________________________ 232 | public class ARCPath : paths{ 233 | 234 | public float xCentral; 235 | public float xFinal; 236 | public float xTemp; 237 | 238 | 239 | public float yCentral; 240 | public float yFinal; 241 | public float yTemp; 242 | public float angle; 243 | public float length; 244 | public float radius; 245 | public float centralAngle; 246 | public int arrSize; 247 | public int sign; 248 | public Vector3[] markers; 249 | 250 | //______________________________________ 251 | //public Vector3[] markers; 252 | 253 | public ARCPath(int road_index ,float x_Start, float y_Start, float length, float hdg, float curvature){ 254 | this.xStart = x_Start; 255 | this.yStart = y_Start; 256 | //this.angle = (hdg) * 180.0f / (Convert.ToSingle(Math.PI)); 257 | //hdg = this.angle; //hdg - Convert.ToSingle(Math.PI * 2 ); // Convert.ToSingle(Math.PI / 2); 258 | this.length = length; 259 | this.pathIndex = road_index; 260 | this.radius = (Math.Abs(1 / curvature)); 261 | this.centralAngle = this.length / this.radius; 262 | //______________________________________________________________________________// 263 | //______________________________________________________________________________// 264 | this.arrSize = 2; //Mathf.FloorToInt(this.length / 3.0f)+2; // 265 | //______________________________________________________________________________// 266 | this.sign = Math.Sign(curvature); // 267 | //_________________________________________________________________________________________________// 268 | this.markers = new Vector3[this.arrSize]; // 269 | this.markers[0] = new Vector3(this.xStart, 0, this.yStart); // START 270 | //_________________________________________________________________________________________________// 271 | //_________________________________________________________________________________________________// 272 | //_________________________________________________________________________________________________// 273 | this.xCentral = this.xStart + Convert.ToSingle( Math.Cos(hdg + (Math.PI / 2) * this.sign * (-1) - Math.PI)) * this.radius; 274 | this.yCentral = this.yStart + Convert.ToSingle( Math.Sin(hdg + (Math.PI / 2) * this.sign * (-1) - Math.PI)) * this.radius; 275 | 276 | 277 | //_________________________________________________________________________________________________// 278 | this.xFinal = this.xStart + Convert.ToSingle( Math.Cos(this.centralAngle + hdg * this.sign * (-1) + (Math.PI / 2) * this.sign ) ) * ((this.radius * 4)/3); // 279 | this.yFinal = this.yStart + Convert.ToSingle( Math.Sin(this.centralAngle + hdg * this.sign * (-1) + (Math.PI / 2) * this.sign ) ) * ((this.radius * 4)/3); // 280 | //_________________________________________________________________________________________________// 281 | this.markers[this.arrSize-1] = new Vector3(this.xFinal, 0f, this.yFinal); // END 282 | //_________________________________________________________________________________________________// 283 | 284 | 285 | 286 | for(int i =1; i<(this.arrSize-1); i++){ 287 | this.xTemp = this.xStart + Convert.ToSingle(Math.Cos( ((i) * (this.centralAngle/(this.arrSize))) + hdg * this.sign * (-1) + (Math.PI / 2) * this.sign )) * this.radius; // TODO => sign of cuvature 288 | this.yTemp = this.yStart + Convert.ToSingle(Math.Sin( ((i) * (this.centralAngle/(this.arrSize))) + hdg * this.sign * (-1) + (Math.PI / 2) * this.sign )) * this.radius; // TODO => sign of cuvature 289 | this.markers[i] = new Vector3(this.xTemp, 0, this.yTemp); // 290 | } 291 | 292 | 293 | if(road_index == 8) 294 | Debug.Log( "Xc, Yc => " + this.xCentral + "," + this.yCentral); 295 | //Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString()); 296 | 297 | } 298 | 299 | public override void createPath(){ 300 | } 301 | 302 | 303 | 304 | } 305 | //_____________________________________________________________________________________________________________________________________________________________________ 306 | //_____________________________________________________________________________________________________________________________________________________________________ 307 | //_____________________________________________________________________________________________________________________________________________________________________ 308 | -------------------------------------------------------------------------------- /comitted/XODR2PATH.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b32b390a8fcfd7a5f9c4bf0751d012a3 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /comitted/XODR_Basics.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using EasyRoads3Dv3; 6 | //___________________________ 7 | using System.Xml; 8 | using System.IO; 9 | using System; 10 | 11 | public class XODR_Basics : MonoBehaviour{ 12 | 13 | public ERRoadNetwork roadNetwork; 14 | //__________________________________________ 15 | public GameObject go; 16 | 17 | public enum PathType : ushort{ 18 | None = 0, 19 | Line = 1, 20 | Arc = 2, 21 | Spiral = 3 22 | } 23 | 24 | void Start() 25 | { 26 | 27 | roadNetwork = new ERRoadNetwork(); 28 | //_____________________________________________________________________________________________ 29 | ERRoadType roadType = new ERRoadType(); 30 | roadType.roadWidth = 4; 31 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 32 | 33 | //____________________________________________________________________________________________ 34 | var LineRoads = new List(); // The container individually keeps road components 35 | var linePaths = new List(); // The container individually keeps road components with the line geometry 36 | var ArcRoads = new List(); // The container individually keeps road components 37 | var arcPaths = new List(); // The container individually keeps road components with the arc geometry 38 | //var SpiralRoads = new List(); // The container individually keeps road components 39 | //var spiralPaths = new List(); // TO DO : !!!!! // The container individually keeps road components with the spiral geometry 40 | 41 | 42 | //LinePath l1 = new LinePath( 0, 0.0f, 0.0f, 400.0f, 0f); 43 | //LineRoads.Add(new ERRoad()); 44 | //LineRoads[0] = roadNetwork.CreateRoad("line"+ l1.pathIndex.ToString(), roadType, l1.markers); 45 | ARCPath a1 = new ARCPath( 0, 2.61f, -325.3f, 7.93f, -4.02f, -0.086f); //0.212f, 0f, -0.002f); //l1.xEnd, l1.yEnd, 800.0f, 0f, -0.002f); 46 | ArcRoads.Add(new ERRoad()); 47 | ArcRoads[0] = roadNetwork.CreateRoad("line"+ a1.pathIndex.ToString(), roadType, a1.markers); // put parameters into the relevant 48 | } 49 | 50 | 51 | void Update() 52 | { 53 | 54 | } 55 | 56 | } 57 | 58 | -------------------------------------------------------------------------------- /comitted/XODR_Basics.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0026e170724c132ba8ff2081a30197a2 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /desktop.ini: -------------------------------------------------------------------------------- 1 | [.ShellClassInfo] 2 | InfoTip=Ez a mappa meg van osztva online. 3 | IconFile=C:\Program Files\Google\Drive\googledrivesync.exe 4 | IconIndex=16 5 | -------------------------------------------------------------------------------- /desktop.ini.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5a4915161368c5429f740938e7fd8b8 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /pics/MultiLane/1Screenshot from 2020-09-18 15-27-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/1Screenshot from 2020-09-18 15-27-50.png -------------------------------------------------------------------------------- /pics/MultiLane/1Sign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/1Sign.png -------------------------------------------------------------------------------- /pics/MultiLane/1_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/1_1.png -------------------------------------------------------------------------------- /pics/MultiLane/1_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/1_2.png -------------------------------------------------------------------------------- /pics/MultiLane/2Screenshot from 2020-09-18 15-28-00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/2Screenshot from 2020-09-18 15-28-00.png -------------------------------------------------------------------------------- /pics/MultiLane/2Sign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/2Sign.png -------------------------------------------------------------------------------- /pics/MultiLane/3Screenshot from 2020-09-18 15-37-35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/3Screenshot from 2020-09-18 15-37-35.png -------------------------------------------------------------------------------- /pics/MultiLane/4Screenshot from 2020-09-18 15-29-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/4Screenshot from 2020-09-18 15-29-23.png -------------------------------------------------------------------------------- /pics/MultiLane/FChart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/FChart.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-27-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-27-57.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-08.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-24.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-26.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-28.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-38.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-28-39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-28-39.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-29-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-29-01.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-29-13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-29-13.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-29-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-29-57.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-29-59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-29-59.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-26.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-27.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-43.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-50.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-53.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-18 15-37-56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-18 15-37-56.png -------------------------------------------------------------------------------- /pics/MultiLane/Screenshot from 2020-09-24 16-20-25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/Screenshot from 2020-09-24 16-20-25.png -------------------------------------------------------------------------------- /pics/MultiLane/verification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/MultiLane/verification.png -------------------------------------------------------------------------------- /pics/arcGeo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/arcGeo.png -------------------------------------------------------------------------------- /pics/arcNeg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/arcNeg.png -------------------------------------------------------------------------------- /pics/arcPos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/arcPos.png -------------------------------------------------------------------------------- /pics/xodr2path_Arcs_Lines.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IngTIKNA/Unity_OpenDrive_SimEnv/5fcff76c45386d3e991345f07cf0b934d8fbcba6/pics/xodr2path_Arcs_Lines.png -------------------------------------------------------------------------------- /runtimeScript.cs: -------------------------------------------------------------------------------- 1 |  2 | /* 3 | * EasyRoads3D Runtime API example 4 | * 5 | * Important: 6 | * 7 | * It has occured that the terrain was not restored leaving the road shape in the terrain 8 | * after exiting Play Mode. This happened after putting focus on the Scene View 9 | * window while in Play Mode! In another occasion this consistently happened until the 10 | * Scene View window got focus! 11 | * 12 | * Please check the above using a test terrain and / or backup your terrains before using this code! 13 | * 14 | * You can backup your terrain by simply duplicating the terrain object 15 | * in the project folder 16 | * 17 | * Also, check the OnDestroy() code, without this code the shape of the generated roads 18 | * will certainly remain in the terrain object after you exit Play Mode! 19 | * 20 | * 21 | * 22 | * 23 | * */ 24 | 25 | 26 | using UnityEngine; 27 | using System.Collections; 28 | using EasyRoads3Dv3; 29 | 30 | public class runtimeScript : MonoBehaviour { 31 | 32 | 33 | public ERRoadNetwork roadNetwork; 34 | 35 | public ERRoad road; 36 | 37 | public GameObject go; 38 | public int currentElement = 0; 39 | public float distance = 0; 40 | public float speed = 5f; 41 | 42 | 43 | 44 | 45 | void Start () { 46 | 47 | Debug.Log("Please read the comments at the top of the runtime script (/Assets/EasyRoads3D/Scripts/runtimeScript) before using the runtime API!"); 48 | 49 | // Create Road Network object 50 | roadNetwork = new ERRoadNetwork(); 51 | 52 | // Create road 53 | // ERRoad road = roadNetwork.CreateRoad(string name); 54 | // ERRoad road = roadNetwork.CreateRoad(string name, Vector3[] markers); 55 | // ERRoad road = roadNetwork.CreateRoad(string name, ERRoadType roadType); 56 | // ERRoad road = roadNetwork.CreateRoad(string name, ERRoadType roadType, Vector3[] markers); 57 | 58 | // get exisiting road types 59 | // ERRoadType[] roadTypes = roadNetwork.GetRoadTypes(); 60 | // ERRoadType roadType = roadNetwork.GetRoadTypeByName(string name); 61 | 62 | 63 | // create a new road type 64 | ERRoadType roadType = new ERRoadType(); 65 | roadType.roadWidth = 6; 66 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 67 | // optional 68 | roadType.layer = 1; 69 | roadType.tag = "Untagged"; 70 | // roadType.hasMeshCollider = false; // default is true 71 | 72 | // roadType = roadNetwork.GetRoadTypeByName("Train Rail"); 73 | // Debug.Log(roadType.roadMaterial); 74 | 75 | // create a new road 76 | Vector3[] markers = new Vector3[4]; 77 | markers[0] = new Vector3(200, 5, 200); 78 | markers[1] = new Vector3(250, 5, 200); 79 | markers[2] = new Vector3(250, 5, 250); 80 | markers[3] = new Vector3(300, 5, 250); 81 | 82 | road = roadNetwork.CreateRoad("road 1", roadType, markers); 83 | 84 | // road.SetResolution(float value):void; 85 | 86 | 87 | // Add Marker: ERRoad.AddMarker(Vector3); 88 | road.AddMarker(new Vector3(300, 5, 300)); 89 | 90 | // Add Marker: ERRoad.InsertMarker(Vector3); 91 | road.InsertMarker(new Vector3(275, 5, 235)); 92 | // road.InsertMarkerAt(Vector3 pos, int index): void; 93 | 94 | // Delete Marker: ERRoad.DeleteMarker(int index); 95 | road.DeleteMarker(2); 96 | 97 | 98 | // Set the road width : ERRoad.SetWidth(float width); 99 | // road.SetWidth(10); 100 | 101 | // Set the road material : ERRoad.SetMaterial(Material path); 102 | // Material mat = Resources.Load("Materials/roads/single lane") as Material; 103 | // road.SetMaterial(mat); 104 | 105 | // add / remove a meshCollider component 106 | // road.SetMeshCollider(bool value):void; 107 | 108 | // set the position of a marker 109 | // road.SetMarkerPosition(int index, Vector3 position):void; 110 | // road.SetMarkerPositions(Vector3[] position):void; 111 | // road.SetMarkerPositions(Vector3[] position, int index):void; 112 | 113 | // get the position of a marker 114 | // road.GetMarkerPosition(int index):Vector3; 115 | 116 | // get the position of a marker 117 | // road.GetMarkerPositions():Vector3[]; 118 | 119 | // Set the layer 120 | // road.SetLayer(int value):void; 121 | 122 | // Set the tag 123 | // road.SetTag(string value):void; 124 | 125 | // set marker control type 126 | // road.SetMarkerControlType(int marker, ERMarkerControlType type) : bool; // Spline, StraightXZ, StraightXZY, Circular 127 | 128 | // find a road 129 | // public static function ERRoadNetwork.GetRoadByName(string name) : ERRoad; 130 | 131 | // get all roads 132 | // public static function ERRoadNetwork.GetRoads() : ERRoad[]; 133 | 134 | // snap vertices to the terrain (no terrain deformation) 135 | // road.SnapToTerrain(true); 136 | 137 | // Build Road Network 138 | roadNetwork.BuildRoadNetwork(); 139 | 140 | // remove script components 141 | // roadNetwork.Finalize(); 142 | 143 | // Restore Road Network 144 | // roadNetwork.RestoreRoadNetwork(); 145 | 146 | // Show / Hide the white surfaces surrounding roads 147 | // public function roadNetwork.HideWhiteSurfaces(bool value) : void; 148 | 149 | // road.GetConnectionAtStart(): GameObject; 150 | // road.GetConnectionAtStart(out int connection): GameObject; // connections: 0 = bottom, 1= tip, 2 = left, 3 = right (the same for T crossings) 151 | 152 | // road.GetConnectionAtEnd(): GameObject; 153 | // road.GetConnectionAtEnd(out int connection): GameObject; // connections: 0 = bottom, 1= tip, 2 = left, 3 = right (the same for T crossings) 154 | 155 | // Snap the road vertices to the terrain following the terrain shape (no terrain deformation) 156 | // road.SnapToTerrain(bool value): void; 157 | // road.SnapToTerrain(bool value, float yOffset): void; 158 | 159 | // get the road length 160 | // road.GetLength() : float; 161 | 162 | // create dummy object 163 | go = GameObject.CreatePrimitive(PrimitiveType.Cube); 164 | 165 | 166 | } 167 | 168 | void Update () { 169 | 170 | if(roadNetwork != null){ 171 | float deltaT = Time.deltaTime; 172 | float rSpeed = (deltaT * speed); 173 | 174 | distance += rSpeed; 175 | 176 | // pass the current distance to get the position on the road 177 | // Debug.Log(road); 178 | Vector3 v = road.GetPosition(distance, ref currentElement); 179 | v.y += 1; 180 | 181 | go.transform.position = v; 182 | } 183 | 184 | // spline point info center of the road 185 | // public function ERRoad.GetSplinePointsCenter() : Vector3[]; 186 | 187 | // spline point info center of the road 188 | // public function ERRoad.GetSplinePointsRightSide() : Vector3[]; 189 | 190 | // spline point info center of the road 191 | // public function ERRoad.GetSplinePointsLeftSide() : Vector3[]; 192 | 193 | // Get the selected road in the Unity Editor 194 | // public static function EREditor.GetSelectedRoad() : ERRoad; 195 | 196 | 197 | 198 | } 199 | 200 | void OnDestroy(){ 201 | 202 | // Restore road networks that are in Build Mode 203 | // This is very important otherwise the shape of roads will still be visible inside the terrain! 204 | 205 | if(roadNetwork != null){ 206 | if(roadNetwork.isInBuildMode){ 207 | roadNetwork.RestoreRoadNetwork(); 208 | Debug.Log("Restore Road Network"); 209 | } 210 | } 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /runtimeScript.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddc8b38d9048ea941b04c086512f93d5 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /simulinkPath.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using EasyRoads3Dv3; 5 | 6 | 7 | public class simulinkPath : MonoBehaviour{ 8 | 9 | public ERRoadNetwork roadNetwork; 10 | //__________________________________________ 11 | public ERRoad road0; 12 | public ERRoad road1; 13 | public ERRoad road2; 14 | public ERRoad road3; 15 | public ERRoad road4; 16 | public ERRoad road5; 17 | public ERRoad road6; 18 | public ERRoad road7; 19 | public ERRoad road8; 20 | public ERRoad road9; 21 | public ERRoad road10; 22 | public ERRoad road11; 23 | public ERRoad road12; 24 | 25 | //__________________________________________ 26 | //public ERRoad[] roads; 27 | //__________________________________________ 28 | public GameObject go; 29 | 30 | void Start() 31 | { 32 | 33 | roadNetwork = new ERRoadNetwork(); 34 | //_____________________________________________________________________________________________ 35 | ERRoadType roadType = new ERRoadType(); 36 | roadType.roadWidth = 20; 37 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 38 | //____________________________________________________________________________________________ 39 | 40 | /* 41 | roads[0] = roadNetwork.CreateRoad("road 1", roadType, markers1); 42 | roads[1] = roadNetwork.CreateRoad("road 2", roadType, markers2); 43 | 44 | roads[0] = roadNetwork.ConnectRoads(roads[0], roads[1]); 45 | */ 46 | //_____________________________________________________________________________________________ 47 | Vector3[] markers0 = new Vector3[2]; 48 | markers0[0] = new Vector3(-80f, 0f, 0f); 49 | markers0[1] = new Vector3(-40f, 0.0f, 0.0f); 50 | //_____________________________________________________________________________________________ 51 | Vector3[] markers1 = new Vector3[2]; 52 | markers1[0] = new Vector3(0f, 0f, 5f); 53 | markers1[1] = new Vector3(162.2f, 0.0f, 30.82f); 54 | //_____________________________________________________________________________________________ 55 | Vector3[] markers2 = new Vector3[2]; 56 | markers2[0] = new Vector3(257.0f, 0, 87.46f); 57 | markers2[1] = new Vector3(685.2f, 0, 421.8f); 58 | //_____________________________________________________________________________________________ 59 | Vector3[] markers3 = new Vector3[2]; 60 | markers3[0] = new Vector3(771.8f, 0, 662.2f); 61 | markers3[1] = new Vector3(755.8f, 0, 742.6f); 62 | //_____________________________________________________________________________________________ 63 | //Vector3[] markers4 = new Vector3[2]; 64 | //markers4[0] = new Vector3(1000, 0, 430); 65 | //markers4[1] = new Vector3(1000, 0, 70); 66 | //_____________________________________________________________________________________________ 67 | //_____________________________________________________________________________________________ 68 | road0 = roadNetwork.CreateRoad("road 0", roadType, markers0); 69 | road1 = roadNetwork.CreateRoad("road 1", roadType, markers1); 70 | road2 = roadNetwork.CreateRoad("road 2", roadType, markers2); 71 | //road3 = roadNetwork.CreateRoad("road 3", roadType, markers3); 72 | road0 = roadNetwork.ConnectRoads(road0, road1); 73 | road0 = roadNetwork.ConnectRoads(road0, road2); 74 | //road1 = roadNetwork.ConnectRoads(road1, road3); 75 | road1.ClosedTrack(false); 76 | //road12 = roadNetwork.ConnectRoads(road12, road1); 77 | 78 | //road1 = roadNetwork.ConnectRoads(road1, road1); 79 | 80 | 81 | 82 | //go = Resources.Load("dynamic prefabs/zeg_T") as GameObject; // 83 | //go.transform.Translate(3.5f, 3.5f, 3.5f); 84 | //go.transform.Rotate(0.0f, 180.0f, 0.0f, Space.Self); 85 | //Instantiate(go, new Vector3(500, 0, 0), Quaternion.identity); 86 | //Instantiate (Resources.Load ("Category1/Hatchet")) as GameObject; 87 | 88 | 89 | } 90 | 91 | 92 | void Update() 93 | { 94 | 95 | } 96 | 97 | } 98 | 99 | 100 | -------------------------------------------------------------------------------- /simulinkPath.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16acb4360f890e4a4aaaa09c8e20391d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /xodr2path(comitted).txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using EasyRoads3Dv3; 6 | //___________________________ 7 | using System.Xml; 8 | using System.IO; 9 | using System; 10 | 11 | public class XODR2PATH : MonoBehaviour{ 12 | 13 | public ERRoadNetwork roadNetwork; 14 | //__________________________________________ 15 | public ERRoad Road; 16 | public ERRoad road2; 17 | public ERRoad roadTemp; 18 | //__________________________________________ 19 | public GameObject go; 20 | 21 | public enum PathType : ushort{ 22 | None = 0, 23 | Line = 1, 24 | Arc = 2, 25 | Spiral = 3 26 | } 27 | 28 | void Start() 29 | { 30 | 31 | roadNetwork = new ERRoadNetwork(); 32 | //_____________________________________________________________________________________________ 33 | ERRoadType roadType = new ERRoadType(); 34 | roadType.roadWidth = 4.0f; 35 | roadType.roadMaterial = Resources.Load("Materials/roads/road material") as Material; 36 | 37 | //____________________________________________________________________________________________ 38 | 39 | var LineRoads = new List(); // The container individually keeps road components 40 | var linePaths = new List(); // The container individually keeps road components with the line geometry 41 | var ArcRoads = new List(); // The container individually keeps road components 42 | var arcPaths = new List(); // The container individually keeps road components with the arc geometry 43 | //var SpiralRoads = new List(); // The container individually keeps road components 44 | //var spiralPaths = new List(); // TO DO : !!!!! // The container individually keeps road components with the spiral geometry 45 | var connectedRoads = new List(); 46 | /* 47 | LinePath l1 = new LinePath( 0, 0.0f, 0.0f, 400.0f, 0f); 48 | roads.Add(new ERRoad()); 49 | roads[0] = roadNetwork.CreateRoad("line"+ l1.pathIndex.ToString(), roadType, l1.markers); 50 | ARCPath a1 = new ARCPath( 1, l1.xEnd, l1.yEnd, 800.0f, 0f, -0.002f); 51 | roads.Add(new ERRoad()); 52 | roads[1] = roadNetwork.CreateRoad("line"+ a1.pathIndex.ToString(), roadType, a1.markers); 53 | */ 54 | 55 | PathType pathType; 56 | XmlNodeList geoList = parseFile(); 57 | double tmp; 58 | 59 | //Debug.Log("_________--------_________------"+geoList.Count); 60 | //Debug.Log("Sin 90 : 1 ?= "+ Math.Cos()); // operates with the values in terms of Radian 61 | 62 | 63 | for(int i=0; i< geoList.Count; i++){ 64 | connectedRoads.Add(new ERRoad()); 65 | var gotFirst = false; 66 | foreach(XmlNode child in geoList[i].ChildNodes) 67 | { 68 | if(child.Name == "line") 69 | { 70 | //_______________________________________________________________________________________________________________________________ 71 | XmlElement geoA = (System.Xml.XmlElement)geoList[i]; 72 | var x_Value = geoA.GetAttribute("x"); 73 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 74 | float xVal = Convert.ToSingle(tmp); 75 | //_______________________________________________________________________________________________________________________________ 76 | var y_Value = geoA.GetAttribute("y"); 77 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 78 | float yVal = Convert.ToSingle(tmp); 79 | //_______________________________________________________________________________________________________________________________ 80 | var heading = geoA.GetAttribute("hdg"); 81 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 82 | float hdgVal = Convert.ToSingle(tmp); 83 | //_______________________________________________________________________________________________________________________________ 84 | var length = geoA.GetAttribute("length"); 85 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 86 | float lenVal = Convert.ToSingle(tmp); 87 | //_______________________________________________________________________________________________________________________________ 88 | //Debug.Log("Child Node Name ==> line" + i.ToString()); 89 | //Debug.Log("TYPEOF => " + x_Value.GetType()); 90 | //Debug.Log("Child Node Name ==> line" + i.ToString()); 91 | pathType = PathType.Line; 92 | linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal)); 93 | LineRoads.Add(new ERRoad()); 94 | LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers); 95 | /* 96 | if(gotFirst == false){ 97 | connectedRoads[i] = LineRoads[linePaths.Count-1]; 98 | gotFirst = true; 99 | }else{ 100 | connectedRoads[i] = roadNetwork.ConnectRoads(connectedRoads[i], LineRoads[linePaths.Count-1]); 101 | } 102 | */ 103 | // LineRoads[0] = roadNetwork.ConnectRoads(LineRoads[0], LineRoads[linePaths.Count-1]); 104 | }else if(child.Name == "arc1"){ 105 | XmlElement geoA = (System.Xml.XmlElement)geoList[i]; 106 | //_______________________________________________________________________________________________________________________________ 107 | var x_Value = geoA.GetAttribute("x"); 108 | double.TryParse( x_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 109 | float xVal = Convert.ToSingle(tmp); 110 | //_______________________________________________________________________________________________________________________________ 111 | var y_Value = geoA.GetAttribute("y"); 112 | double.TryParse( y_Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 113 | float yVal = Convert.ToSingle(tmp); 114 | //_______________________________________________________________________________________________________________________________ 115 | var heading = geoA.GetAttribute("hdg"); 116 | double.TryParse( heading, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 117 | float hdgVal = Convert.ToSingle(tmp); 118 | //_______________________________________________________________________________________________________________________________ 119 | var length = geoA.GetAttribute("length"); 120 | double.TryParse( length, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 121 | float lenVal = Convert.ToSingle(tmp); 122 | //_______________________________________________________________________________________________________________________________ 123 | var child_curvature = child.Attributes["curvature"]; 124 | double.TryParse( child_curvature.Value, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out tmp); 125 | float curveVal = Convert.ToSingle(tmp); 126 | //_______________________________________________________________________________________________________________________________ 127 | //var child_curvature = child.GetAttribute("curvature"); 128 | //Debug.Log("Child Node Name ==> arc" + i.ToString()); 129 | pathType = PathType.Arc; 130 | //if(lenVal < 0.00001f){ 131 | // linePaths.Add(new LinePath( linePaths.Count , xVal, yVal, lenVal, hdgVal)); 132 | // LineRoads.Add(new ERRoad()); 133 | // LineRoads[linePaths.Count-1] = roadNetwork.CreateRoad("small_arc/Line"+ (linePaths.Count-1).ToString(), roadType, linePaths[linePaths.Count-1].markers); 134 | //}else{ 135 | arcPaths.Add(new ARCPath( arcPaths.Count , xVal , yVal , lenVal, hdgVal, curveVal)); 136 | ArcRoads.Add(new ERRoad()); 137 | ArcRoads[arcPaths.Count-1] = roadNetwork.CreateRoad("arc"+ (arcPaths.Count-1).ToString(), roadType, arcPaths[arcPaths.Count-1].markers); 138 | //} 139 | // ARCPath( 1, 0, 0, 800.0f, 0f, -0.002f); 140 | }else if(child.Name == "spiral"){ 141 | Debug.Log("Child Node Name ==> spiral" + i.ToString()); 142 | pathType = PathType.Spiral; 143 | } 144 | 145 | } 146 | } 147 | 148 | } 149 | 150 | 151 | public XmlNodeList parseFile() 152 | { 153 | //____________________________________________________________ 154 | XmlDocument doc = new XmlDocument(); 155 | doc.Load("Town01.xml"); 156 | //____________________________________________________________ 157 | XmlNodeList elemList = doc.GetElementsByTagName("road"); //Element("OpenDRIVE").Elements("road"); 158 | //Debug.Log("1-"); 159 | //Debug.Log("Number of planView => " + elemList.Count); 160 | //____________________________________________________________ 161 | XmlNodeList geoList = doc.GetElementsByTagName("geometry"); //Element("OpenDRIVE").Elements("road"); 162 | //Debug.Log("2-"); 163 | //Debug.Log("Num of geometry tags" + geoList.Count); 164 | //____________________________________________________________ 165 | return geoList; 166 | } 167 | 168 | 169 | void Update() 170 | { 171 | 172 | } 173 | 174 | } 175 | 176 | 177 | 178 | public abstract class paths{// : MonoBehaviour{ 179 | 180 | public float xStart; 181 | public float yStart; 182 | public int pathIndex; 183 | public abstract void createPath(); 184 | 185 | } 186 | 187 | //_____________________________________________________________________________________________________________________________________________________________________ 188 | //____________________________________________________________________________ LINE GEOMETRY __________________________________________________________________________ 189 | //_____________________________________________________________________________________________________________________________________________________________________ 190 | public class LinePath : paths{ 191 | 192 | public float xEnd; 193 | public float yEnd; 194 | public float angle; 195 | public float length; 196 | //______________________________________ 197 | public Vector3[] markers = new Vector3[2]; 198 | 199 | 200 | public LinePath(int road_index , float x_Start, float y_Start, float length, float hdg){ 201 | this.xStart = x_Start; 202 | this.yStart = y_Start; 203 | this.angle = hdg; //Convert.ToSingle(Math.PI) * (hdg) / 180.0f; 204 | this.length = length; 205 | this.pathIndex = road_index; 206 | //________________________________________________________________________________________________// // 207 | this.markers[0] = new Vector3(this.xStart, 0, this.yStart); // 208 | this.xEnd = this.xStart + Convert.ToSingle(Math.Cos(this.angle)) * this.length; // 209 | this.yEnd = this.yStart + Convert.ToSingle(Math.Sin(this.angle)) * this.length; // 210 | this.markers[1] = new Vector3(this.xEnd, 0, this.yEnd); // 211 | //________________________________________________________________________________________________// 212 | //roads[road_index] = roadNetwork.CreateRoad("line"+ this.pathIndex.ToString(), roadType, this.markers); // 213 | //________________________________________________________________________________________________// 214 | Debug.Log( "LENGTH => " + this.length); 215 | Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString()); 216 | 217 | } 218 | 219 | public override void createPath(){ 220 | 221 | } 222 | 223 | } 224 | //_____________________________________________________________________________________________________________________________________________________________________ 225 | //_____________________________________________________________________________________________________________________________________________________________________ 226 | //_____________________________________________________________________________________________________________________________________________________________________ 227 | 228 | 229 | 230 | 231 | //_____________________________________________________________________________________________________________________________________________________________________ 232 | //____________________________________________________________________________ ARC GEOMETRY ___________________________________________________________________________ 233 | //_____________________________________________________________________________________________________________________________________________________________________ 234 | public class ARCPath : paths{ 235 | 236 | public float xArc; 237 | public float xTemp; 238 | public float xFinal; 239 | public float yArc; 240 | public float yTemp; 241 | public float yFinal; 242 | public float angle; 243 | public float length; 244 | public float radius; 245 | public float centralAngle; 246 | public int arrSize; 247 | public int sign; 248 | public Vector3[] markers; 249 | 250 | //______________________________________ 251 | //public Vector3[] markers; 252 | 253 | public ARCPath(int road_index ,float x_Start, float y_Start, float length, float hdg, float curvature){ 254 | this.xStart = x_Start; 255 | this.yStart = y_Start; 256 | this.angle = (Convert.ToSingle(Math.PI) * (hdg)) / 180.0f; 257 | this.length = length; 258 | this.pathIndex = road_index; 259 | this.radius = (Math.Abs(1 / curvature)); 260 | this.centralAngle = this.length / this.radius; 261 | //______________________________________________________________________________// 262 | //______________________________________________________________________________// 263 | if(this.length < 1){ // 264 | this.arrSize = 2; // 265 | }else if(this.length >= 15 || this.length < 10){ // 266 | this.arrSize = Mathf.FloorToInt(this.length / 0.5f)+1; // 267 | }else if((this.length >= 1)){ // 268 | this.arrSize = Mathf.FloorToInt(this.length / 2.0f)+1; // 269 | }else{ // 270 | this.arrSize = 2; // 271 | } // 272 | //______________________________________________________________________________// 273 | //______________________________________________________________________________// 274 | this.sign = Math.Sign(curvature); // 275 | //_________________________________________________________________________________________________// 276 | this.markers = new Vector3[this.arrSize]; // 277 | this.markers[0] = new Vector3(this.xStart, 0, this.yStart); // 278 | //_________________________________________________________________________________________________// 279 | /* 280 | this.xArc = this.xStart + Convert.ToSingle(Math.Cos(this.angle + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; // TODO => sign of cuvature 281 | this.yArc = this.yStart + Convert.ToSingle(Math.Sin(this.angle + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; // 282 | */ 283 | this.xArc = this.xStart + Convert.ToSingle(Math.Cos(hdg + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; 284 | this.yArc = this.yStart + Convert.ToSingle(Math.Sin(hdg + (Math.PI / 2) * this.sign - Math.PI )) * this.radius; 285 | 286 | this.xFinal = this.xArc + Convert.ToSingle(Math.Cos(this.centralAngle)) * this.radius; // TODO => sign of cuvature 287 | this.yFinal = this.yArc + Convert.ToSingle(Math.Sin(this.centralAngle)) * this.radius; // TODO => sign of cuvature 288 | 289 | this.markers[this.arrSize-1] = new Vector3(this.xFinal, 0f, this.yFinal); 290 | 291 | for(int i =1; i<(this.arrSize-1); i++){ 292 | this.xTemp = this.xArc + Convert.ToSingle(Math.Cos( ((i) * (this.centralAngle / (this.arrSize+1))) )) * this.radius; // TODO => sign of cuvature 293 | this.yTemp = this.yArc + Convert.ToSingle(Math.Sin( ((i) * (this.centralAngle / (this.arrSize+1))) )) * this.radius; // TODO => sign of cuvature 294 | this.markers[i] = new Vector3(this.xTemp, 0, this.yTemp); // 295 | } 296 | 297 | Debug.Log( "LENGTH => " + this.length); 298 | Debug.Log( "X_start , Y_start = " + this.xStart.ToString() + "," + this.yStart.ToString()); 299 | 300 | } 301 | public override void createPath(){ 302 | } 303 | 304 | } 305 | //_____________________________________________________________________________________________________________________________________________________________________ 306 | //_____________________________________________________________________________________________________________________________________________________________________ 307 | //_____________________________________________________________________________________________________________________________________________________________________ 308 | -------------------------------------------------------------------------------- /xodr2path(comitted).txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51b9c8d7ac5a7f1ba980800de2046600 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------