Ejemplo n.º 1
0
        void AddSolidLaneLine(
            NativeArray <RigidTransform> samples,
            float xOffset,
            RoadMarking marking,
            DynamicBuffer <CombinedVertex> vertexBuffer,
            DynamicBuffer <Triangle> triangleBuffer,
            DynamicBuffer <SubMesh> subMeshBuffer)
        {
            var newSubMesh        = new SubMesh();
            var markingWidth      = marking.Width / 2;
            var leftOffsetSpline  = SplineUtility.OffsetSpline(samples, new float3(-markingWidth + xOffset, 0f, 0f), Allocator.Temp);
            var rightOffsetSpline = SplineUtility.OffsetSpline(samples, new float3(markingWidth + xOffset, 0f, 0f), Allocator.Temp);

            newSubMesh.VertexStartIndex = vertexBuffer.Length;
            newSubMesh.VertexCount      = samples.Length * 2;
            vertexBuffer.ResizeUninitialized(vertexBuffer.Length + samples.Length * 2);

            var upVector = new float3(0f, 1f, 0f);

            for (int i = 0, j = newSubMesh.VertexStartIndex; i < samples.Length; i++)
            {
                var leftPoint = leftOffsetSpline[i];
                vertexBuffer[j++] = new CombinedVertex
                {
                    Vertex = leftPoint.pos,
                    Normal = math.mul(leftPoint.rot, upVector),
                    Uv     = leftPoint.pos.xz
                };
                var rightPoint = rightOffsetSpline[i];
                vertexBuffer[j++] = new CombinedVertex
                {
                    Vertex = rightPoint.pos,
                    Normal = math.mul(rightPoint.rot, upVector),
                    Uv     = rightPoint.pos.xz
                };
            }
            leftOffsetSpline.Dispose();
            rightOffsetSpline.Dispose();

            newSubMesh.TriangleStartIndex = triangleBuffer.Length;
            newSubMesh.TriangleCount      = (samples.Length - 1) * 6;
            triangleBuffer.ResizeUninitialized(triangleBuffer.Length + newSubMesh.TriangleCount);
            for (int i = 0, j = newSubMesh.TriangleStartIndex; i < newSubMesh.VertexCount - 2; i += 2)
            {
                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 3;
                triangleBuffer[j++] = i + 1;

                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 2;
                triangleBuffer[j++] = i + 3;
            }

            newSubMesh.Material = marking.Material;
            subMeshBuffer.Add(newSubMesh);
        }
Ejemplo n.º 2
0
        void AppendRightTurnCornerSamples(NativeList <RigidTransform> samples, Entity cornerEntity)
        {
            var cornerSamples = RoadCenterLineSamples[cornerEntity]
                                .Reinterpret <RigidTransform>().AsNativeArray();

            var offset = new float3(-OffsetFromCurb, 0f, 0f);

            var offsetSamples = SplineUtility.OffsetSpline(cornerSamples, offset, Allocator.Temp);

            samples.AddRange(offsetSamples);
            offsetSamples.Dispose();
        }
Ejemplo n.º 3
0
        void AppendRightTurnCornerSamples(NativeList <RigidTransform> samples, Entity cornerEntity)
        {
            var cornerSamples = RoadCenterLineSamples[cornerEntity]
                                .Reinterpret <RigidTransform>().AsNativeArray();

            var lateralProfileEntity  = LateralProfileEntityRefs[cornerEntity].Reinterpret <Entity>()[0];
            var lateralProfileSamples = LateralProfileSampleBuffers[lateralProfileEntity].Reinterpret <float2>();

            var lateralOffset = lateralProfileSamples[lateralProfileSamples.Length - 1].x;
            var offset        = new float3(lateralOffset, 0f, 0f);

            var offsetSamples = SplineUtility.OffsetSpline(cornerSamples, offset, Allocator.Temp);

            samples.AddRange(offsetSamples);
            offsetSamples.Dispose();
        }
Ejemplo n.º 4
0
        void AppendRoadSamples(NativeList <RigidTransform> samples, IntersectionRoadConnection connection)
        {
            var centerLineSamples = RoadCenterLineSamples[connection.Road]
                                    .Reinterpret <RigidTransform>().AsNativeArray();

            var lateralProfileEntity  = LateralProfileEntityRefs[connection.Road].Reinterpret <Entity>()[0];
            var lateralProfileSamples = LateralProfileSampleBuffers[lateralProfileEntity].Reinterpret <float2>();

            var lateralOffset = connection.Direction == IntersectionRoadDirection.Incoming
                ? lateralProfileSamples[0].x
                : lateralProfileSamples[lateralProfileSamples.Length - 1].x;

            var offset        = new float3(lateralOffset, 0f, 0f);
            var offsetSamples = SplineUtility.OffsetSpline(centerLineSamples, offset, Allocator.Temp);

            if (connection.Direction == IntersectionRoadDirection.Incoming)
            {
                SplineUtility.ReverseSpline(offsetSamples);
            }

            samples.AddRange(offsetSamples);
            offsetSamples.Dispose();
        }
Ejemplo n.º 5
0
        void AppendRoadSamples(NativeList <RigidTransform> samples, IntersectionRoadConnection connection)
        {
            var centerLineSamples = RoadCenterLineSamples[connection.Road]
                                    .Reinterpret <RigidTransform>().AsNativeArray();

            var lateralProfileEntity = LateralProfileEntityRefs[connection.Road].Reinterpret <Entity>()[0];
            var lateralProfile       = LateralProfileComponents[lateralProfileEntity];

            var lateralOffset = connection.Direction == IntersectionRoadDirection.Incoming
                ? lateralProfile.LeftDrivableOffset.x + OffsetFromCurb
                : lateralProfile.RightDrivableOffset.x - OffsetFromCurb;

            var offset        = new float3(lateralOffset, 0f, 0f);
            var offsetSamples = SplineUtility.OffsetSpline(centerLineSamples, offset, Allocator.Temp);

            if (connection.Direction == IntersectionRoadDirection.Incoming)
            {
                SplineUtility.ReverseSpline(offsetSamples);
            }

            samples.AddRange(offsetSamples);
            offsetSamples.Dispose();
        }
Ejemplo n.º 6
0
        void AddDashedLaneLine(
            NativeArray <RigidTransform> samples,
            float xOffset,
            RoadMarking marking,
            DynamicBuffer <CombinedVertex> vertexBuffer,
            DynamicBuffer <Triangle> triangleBuffer,
            DynamicBuffer <SubMesh> subMeshBuffer,
            DynamicBuffer <RigidTransform> roadMarkingSamples,
            DynamicBuffer <DashPoint> dashPoints)
        {
            DashSamples(samples, marking, out var dashSamples, out var dashCaps);
            roadMarkingSamples.AddRange(dashSamples);
            dashPoints.AddRange(dashCaps);

            var markingWidth      = marking.Width / 2;
            var leftOffsetSpline  = SplineUtility.OffsetSpline(dashSamples, new float3(-markingWidth + xOffset, 0f, 0f), Allocator.Temp);
            var rightOffsetSpline = SplineUtility.OffsetSpline(dashSamples, new float3(markingWidth + xOffset, 0f, 0f), Allocator.Temp);
            var dashVertices      = new NativeList <CombinedVertex>(leftOffsetSpline.Length / 2, Allocator.Temp);
            var nonDashVertices   = new NativeList <CombinedVertex>(leftOffsetSpline.Length / 2, Allocator.Temp);

            var upVector = new float3(0f, 1f, 0f);

            for (var i = 0; i < dashSamples.Length - 1; i++)
            {
                if (dashCaps[i].Cap == DashCap.Start)
                {
                    var leftPoint = leftOffsetSpline[i];
                    dashVertices.Add(new CombinedVertex
                    {
                        Vertex = leftPoint.pos,
                        Normal = math.mul(leftPoint.rot, upVector),
                        Uv     = leftPoint.pos.xz
                    });
                    var rightPoint = rightOffsetSpline[i];
                    dashVertices.Add(new CombinedVertex
                    {
                        Vertex = rightPoint.pos,
                        Normal = math.mul(rightPoint.rot, upVector),
                        Uv     = rightPoint.pos.xz
                    });
                    leftPoint = leftOffsetSpline[i + 1];
                    dashVertices.Add(new CombinedVertex
                    {
                        Vertex = leftPoint.pos,
                        Normal = math.mul(leftPoint.rot, upVector),
                        Uv     = leftPoint.pos.xz
                    });
                    rightPoint = rightOffsetSpline[i + 1];
                    dashVertices.Add(new CombinedVertex
                    {
                        Vertex = rightPoint.pos,
                        Normal = math.mul(rightPoint.rot, upVector),
                        Uv     = rightPoint.pos.xz
                    });
                }
                else
                {
                    var leftPoint = leftOffsetSpline[i];
                    nonDashVertices.Add(new CombinedVertex
                    {
                        Vertex = leftPoint.pos,
                        Normal = math.mul(leftPoint.rot, upVector),
                        Uv     = leftPoint.pos.xz
                    });
                    var rightPoint = rightOffsetSpline[i];
                    nonDashVertices.Add(new CombinedVertex
                    {
                        Vertex = rightPoint.pos,
                        Normal = math.mul(rightPoint.rot, upVector),
                        Uv     = rightPoint.pos.xz
                    });
                    leftPoint = leftOffsetSpline[i + 1];
                    nonDashVertices.Add(new CombinedVertex
                    {
                        Vertex = leftPoint.pos,
                        Normal = math.mul(leftPoint.rot, upVector),
                        Uv     = leftPoint.pos.xz
                    });
                    rightPoint = rightOffsetSpline[i + 1];
                    nonDashVertices.Add(new CombinedVertex
                    {
                        Vertex = rightPoint.pos,
                        Normal = math.mul(rightPoint.rot, upVector),
                        Uv     = rightPoint.pos.xz
                    });
                }
            }
            leftOffsetSpline.Dispose();
            rightOffsetSpline.Dispose();
            dashSamples.Dispose();
            dashCaps.Dispose();

            var dashSubMesh = new SubMesh
            {
                VertexCount        = dashVertices.Length,
                VertexStartIndex   = vertexBuffer.Length,
                TriangleCount      = (dashVertices.Length * 3) / 2,
                TriangleStartIndex = triangleBuffer.Length,
                Material           = marking.Material
            };

            var nonDashSubMesh = new SubMesh
            {
                VertexCount        = nonDashVertices.Length,
                VertexStartIndex   = dashSubMesh.VertexStartIndex + dashSubMesh.VertexCount,
                TriangleCount      = (nonDashVertices.Length * 3) / 2,
                TriangleStartIndex = dashSubMesh.TriangleStartIndex + dashSubMesh.TriangleCount,
                Material           = RoadMaterial.RoadSurface
            };

            vertexBuffer.AddRange(dashVertices);
            vertexBuffer.AddRange(nonDashVertices);

            triangleBuffer.ResizeUninitialized(triangleBuffer.Length + dashSubMesh.TriangleCount + nonDashSubMesh.TriangleCount);
            for (int i = 0, j = dashSubMesh.TriangleStartIndex; i < dashSubMesh.VertexCount; i += 4)
            {
                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 3;
                triangleBuffer[j++] = i + 1;

                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 2;
                triangleBuffer[j++] = i + 3;
            }

            for (int i = 0, j = nonDashSubMesh.TriangleStartIndex; i < nonDashSubMesh.VertexCount; i += 4)
            {
                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 3;
                triangleBuffer[j++] = i + 1;

                triangleBuffer[j++] = i;
                triangleBuffer[j++] = i + 2;
                triangleBuffer[j++] = i + 3;
            }

            subMeshBuffer.Add(dashSubMesh);
            subMeshBuffer.Add(nonDashSubMesh);
            dashVertices.Dispose();
            nonDashVertices.Dispose();
        }