public void GenerateMesh_OnLine_ReturnsCorrectVertices()
        {
            var geometry = new Geometry()
            {
                geometryKind = GeometryKind.Line,
                startPose    = new RigidTransform(quaternion.identity, float3.zero),
                length       = 0.4f,
                sRoad        = 0f
            };

            var wd2 = RoadNetworkMesher.RoadWidth * .5f;
            // NOTE: The expected values here vary with respect to the const values in RoadNetworkMesher
            var verticesExpected = new[]
            {
                new Vector3(-wd2, 0, 0),
                new Vector3(wd2, 0, 0),
                new Vector3(-wd2, 0, 0.3f),
                new Vector3(wd2, 0, 0.3f),
                new Vector3(-wd2, 0, 0.4f),
                new Vector3(wd2, 0, 0.4f)
            };

            var mesh           = RoadNetworkMesher.BuildMeshForGeometry(geometry, 3);
            var verticesActual = mesh.vertices;

            Assert.AreEqual(verticesExpected.Length, verticesActual.Length);
            // It is ok for the generated vertices to be slightly off from the exact values we expect
            var laxVectorComparer = new Vector3EqualityComparer(0.1f);

            foreach (var vertex in verticesExpected)
            {
                Assert.IsTrue(verticesActual.Contains(vertex, laxVectorComparer));
            }
        }
        public void RoadNetworkMesher_TransformsAreInverses()
        {
            var pointOriginal    = new Vector3(1, 0, -2);
            var pointPolygon     = RoadNetworkMesher.ToPolygonPoint(pointOriginal);
            var pointTransformed = RoadNetworkMesher.ToVector3(pointPolygon);

            Assert.AreEqual(pointOriginal, pointTransformed);
        }
        protected override void OnUpdate()
        {
            Polygon poly  = null;
            var     holes = new List <Polygon>();

            Entities.ForEach((ref PolygonOrientationComponent polygonOrientation, DynamicBuffer <PointSampleGlobal> points) =>
            {
                PolygonPoint[] pointArray = new PolygonPoint[points.Length];
                for (var i = 0; i < points.Length; i++)
                {
                    pointArray[i] = new PolygonPoint(points[i].pose.pos.x, points[i].pose.pos.z);
                }
                var polygon = new Polygon(pointArray);
                if (polygonOrientation.Orientation == PolygonOrientation.Outside)
                {
                    if (poly != null)
                    {
                        Debug.LogError("Multiple outside polygons detected. " +
                                       "Multiple outside polygons indicate a disconnected road network.");
                    }
                    poly = polygon;
                }
                else
                {
                    holes.Add(polygon);
                }
            });

            if (poly == null)
            {
                throw new NullReferenceException($"Polygon is null - will be unable to create mesh for " +
                                                 $"{Parameters.Parent.name}.");
            }

            foreach (var hole in holes)
            {
                poly.AddHole(hole);
            }

            var mesh = RoadNetworkMesher.PolygonToMesh(poly, Parameters.UVMultiplier);

            GameObject go = new GameObject("Road mesh");

            go.transform.parent        = Parameters.Parent;
            go.transform.localPosition = new Vector3(0, .1f, 0);
            var meshRenderer = go.AddComponent <MeshRenderer>();

            meshRenderer.material = Parameters.Material;
            var meshFilter = go.AddComponent <MeshFilter>();

            meshFilter.mesh = mesh;
            go.AddComponent <MeshCollider>();
        }
Ejemplo n.º 4
0
        public static void RoadNetworkToLineRenderer()
        {
            var roadNetworkDescription = GetSelectedRoadNetwork();

            if (roadNetworkDescription == null)
            {
                return;
            }

            var go = RoadNetworkMesher.GenerateLineRenderer(roadNetworkDescription);

            AddRoadNetworkReference(go, roadNetworkDescription);
        }
Ejemplo n.º 5
0
        public static void RoadNetworkLanesToMesh()
        {
            var roadNetworkDescription = GetSelectedRoadNetwork();

            if (roadNetworkDescription == null)
            {
                Debug.LogWarning("No RoadNetworkDescription selected.");
                return;
            }

            var go = RoadNetworkMesher.GenerateMeshWithLanes(roadNetworkDescription);

            AddRoadNetworkReference(go, roadNetworkDescription);
        }
Ejemplo n.º 6
0
 public void GenerateMeshTypeRoads(RoadNetworkDescription road, MeshGenerationType roadMeshGenerationType)
 {
     if (roadMeshGenerationType == MeshGenerationType.MeshRoad)
     {
         RoadNetworkMesher.GenerateMesh(road);
     }
     else if (roadMeshGenerationType == MeshGenerationType.MeshLanes)
     {
         RoadNetworkMesher.GenerateLineRenderer(road);
     }
     else if (roadMeshGenerationType == MeshGenerationType.MeshLineRenderer)
     {
         RoadNetworkMesher.GenerateLineRenderer(road);
     }
 }
        public void GenerateOpenDRIVELanesToMesh(string file)
        {
            testHelpers.GetTestRoadNetwork(file, out road);
            testHelpers.GenerateMeshTypeRoads(road, TestHelpers.MeshGenerationType.MeshRoad);

            var meshContainer = RoadNetworkMesher.GenerateMesh(road);
            var laneContainer = RoadNetworkMesher.GenerateMeshWithLanes(road);

            var roadContainer = new GameObject("TestOpenDRIVE");

            meshContainer.name             = "Mesh";
            laneContainer.name             = "Lanes";
            meshContainer.transform.parent = roadContainer.transform;
            laneContainer.transform.parent = roadContainer.transform;

            Assert.IsNotNull(roadContainer, "TestOpenDrive was never created");
            Assert.IsNotNull(meshContainer, "Mesh container was never created");
            Assert.IsNotNull(laneContainer, "Lane container was never created");
            Assert.IsNotEmpty(road.AllJunctions, "OpenDrive mesh doesn't junction contain data");
            Assert.IsNotEmpty(road.AllRoads, "OpenDrive mesh doesn't road contain data");
            LogAssert.NoUnexpectedReceived();
        }