Пример #1
0
        List <List <IntPoint> > PolygonsFromRoadOutline(float extensionDistance)
        {
            var polygons = new List <List <IntPoint> >();
            var rnd      = Parameters.roadNetworkDescription;

            foreach (var road in rnd.AllRoads)
            {
                var points = GeometrySampling.BuildSamplesFromRoadOutlineWithExtensionDistance(
                    road, 0.5f, extensionDistance, Parameters.outermostLaneType);
                var path = new List <IntPoint>(points.Length);
                foreach (var point in points)
                {
                    path.Add(new IntPoint(
                                 point.pose.pos.x * PlacementUtility.UpScaleFactor,
                                 point.pose.pos.z * PlacementUtility.UpScaleFactor));
                }

                if (!Clipper.Orientation(path))
                {
                    path.Reverse();
                }

                polygons.Add(path);

                points.Dispose();
            }

            return(polygons);
        }
        /// <summary>
        /// This approach uses a single large NativeArray of samples filled in by each job instead of adding temporary DynamicBuffers to the entities.
        /// This appears to be the best balance between speed and simplicity.
        ///
        /// Test results:
        /// Total: ~40ms
        /// Setup: ~0ms
        /// Combine: 2.27ms
        /// </summary>
        private List <List <IntPoint> > PolygonsFromRoadOutlineEntityForEachSeparateBuffer(float extensionDistance, JobHandle jobHandle)
        {
            Profiler.BeginSample("PolygonsFromRoadOutlineEntityForEachSeparateBuffer");
            Profiler.BeginSample("PolygonsFromRoadOutlineEntityForEachSeparateBuffer_Setup");
            var polygons = new List <List <IntPoint> >();

            var sampleStartIndexMap = new NativeHashMap <Entity, RoadSampleSpan>(300, Allocator.TempJob);
            var sampleCountTotal    = 0;

            Entities.ForEach((int entityInQueryIndex, Entity entity, ref EcsRoad road) =>
            {
                var sampleCount             = GeometrySampling.ComputeSampleCountForRoadOutline(road, .5f);
                sampleStartIndexMap[entity] = new RoadSampleSpan
                {
                    startIndex = sampleCountTotal,
                    count      = sampleCount
                };
                sampleCountTotal += sampleCount;
            }).Run();

            var samples = new NativeArray <PointSampleGlobal>(sampleCountTotal, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            var job = Entities.ForEach((Entity entity,
                                        ref EcsRoad road,
                                        in DynamicBuffer <Geometry> ecsGeometries,
                                        in DynamicBuffer <EcsLane> ecsLanes,
                                        in DynamicBuffer <EcsLaneSection> ecsLaneSections,
                                        in DynamicBuffer <LaneOffset> laneOffsets,
                                        in DynamicBuffer <LaneWidthRecord> laneWidthRecords) => //(Entity entity, ref EcsRoad road) =>
            {
                var ecsRoadData = new EcsRoadData()
                {
                    ecsRoad          = road,
                    ecsGeometries    = ecsGeometries,
                    ecsLaneSections  = ecsLaneSections,
                    ecsLanes         = ecsLanes,
                    laneOffsets      = laneOffsets,
                    laneWidthRecords = laneWidthRecords
                };;
                var roadSampleSpan = sampleStartIndexMap[entity];
                GeometrySampling.BuildSamplesFromRoadOutlineWithExtensionDistance(
                    ecsRoadData, 0.5f, extensionDistance, new NativeSlice <PointSampleGlobal>(samples, roadSampleSpan.startIndex, roadSampleSpan.count));
            }).WithReadOnly(sampleStartIndexMap).WithoutBurst().Schedule(jobHandle);
 public void Execute()
 {
     for (int i = 0; i < outlineJobBatch.count; i++)
     {
         var outlineJobParam = outlineJobParams[outlineJobBatch.startIndex + i];
         var entity          = outlineJobParam.entity;
         var ecsRoadData     = new EcsRoadData()
         {
             ecsRoad          = ecsRoadGetter[entity],
             ecsGeometries    = geometryGetter[entity],
             ecsLaneSections  = laneSectionGetter[entity],
             ecsLanes         = laneGetter[entity],
             laneOffsets      = laneOffsetGetter[entity],
             laneWidthRecords = laneWidthRecordGetter[entity]
         };
         GeometrySampling.BuildSamplesFromRoadOutlineWithExtensionDistance(
             ecsRoadData, 0.5f, extensionDistance, new NativeSlice <PointSampleGlobal>(samples, outlineJobParam.startIndex, outlineJobParam.count));
     }
 }