public LateralProfileBuilder( Allocator allocator, Entity roadEntity, Entity profileEntity, NativeArray <Entity> surfaceEntities, NativeArray <Entity> roadMarkingEntities) { m_NumLeftSurfaces = 0; m_NumLeftSamples = 0; Profile = new LateralProfile(); Samples = new NativeList <float2>(allocator); RoadMarkings = new NativeList <RoadMarking>(allocator); Surfaces = new NativeList <LateralProfileSurface>(allocator); m_RoadEntity = roadEntity; m_ProfileEntity = profileEntity; m_SurfaceEntities = surfaceEntities; m_RoadMarkingEntities = roadMarkingEntities; }
public void Complete() { // Propagate profile offsets { var offset = float2.zero; var samplesIdx = m_NumLeftSamples; for (var i = m_NumLeftSurfaces - 1; i >= 0; --i) { for (var j = Surfaces[i].SampleCount - 1; j >= 0; --j) { Samples[--samplesIdx] += offset; } offset = Samples[samplesIdx]; } offset = float2.zero; samplesIdx = m_NumLeftSamples - 1; for (var i = m_NumLeftSurfaces; i < Surfaces.Length; i++) { for (var j = 0; j < Surfaces[i].SampleCount; j++) { Samples[++samplesIdx] += offset; } offset = Samples[samplesIdx]; } } // Record start indices { var sampleCount = 0; for (var i = 0; i < Surfaces.Length; i++) { var surface = Surfaces[i]; surface.Profile = m_ProfileEntity; surface.StartIndex = sampleCount; Surfaces[i] = surface; sampleCount += surface.SampleCount; } } // Record road center and road surface extents { var profile = new LateralProfile { Road = m_RoadEntity, LeftDrivableIndex = m_NumLeftSurfaces, RightDrivableIndex = m_NumLeftSurfaces, CenterIndex = m_NumLeftSurfaces, }; for (var i = 0; i < m_NumLeftSamples; i++) { var surface = Surfaces[i]; if (!surface.Drivable) { continue; } profile.LeftDrivableOffset = Samples[surface.StartIndex]; profile.LeftDrivableIndex = i; break; } for (var i = Surfaces.Length - 1; i >= m_NumLeftSurfaces; --i) { var surface = Surfaces[i]; if (!surface.Drivable) { continue; } profile.RightDrivableOffset = Samples[surface.EndIndex]; profile.RightDrivableIndex = i; break; } Profile = profile; } }