public void ImportApolloMap(string filePath) { Settings = EditorSettings.Load(); if (ImportApolloMapCalculate(filePath)) { Debug.Log("Successfully imported Apollo HD Map!\nPlease check your imported intersections and adjust if they are wrongly grouped."); Debug.Log("Currently yield signs are imported as stop signs for NPCs."); Debug.LogWarning("!!! You need to adjust the triggerBounds for each MapIntersection."); } else { Debug.LogError("Failed to import Apollo HD Map."); } }
void Generate(MapLane[] lanes) { var settings = EditorSettings.Load(); var lidar = Instantiate(settings.LidarSensor); lidar.Init(); lidar.TemplateIndex = LidarTemplate; lidar.LaserCount = LidarLaserCount; lidar.MinDistance = LidarMinDistance; lidar.MaxDistance = LidarMaxDistance; lidar.RotationFrequency = LidarRotationFrequency; lidar.RotationFrequency = LidarRotationFrequency; lidar.MeasurementsPerRotation = LidarMeasurementsPerRotation; lidar.RotationFrequency = LidarRotationFrequency; lidar.FieldOfView = LidarFieldOfView; lidar.CenterAngle = LidarCenterAngle; lidar.ApplyTemplate(); lidar.Reset(); int mapLayerMask = LayerMask.GetMask("Default"); try { using (var writer = new PcdWriter(FileName)) { for (int i = 0; i < lanes.Length; i++) { var lane = lanes[i]; float progress = (float)i / (lanes.Length - 1); var size = EditorUtility.FormatBytes(writer.Size); if (EditorUtility.DisplayCancelableProgressBar("Generating Point Cloud...", $"{writer.Count:N0} points ({size})", progress)) { return; } var positions = lane.mapLocalPositions; if (positions.Count > 1) { Vector3 p0 = lane.transform.TransformPoint(positions[0]); Vector3 p1; foreach (var next in positions.Skip(1)) { p1 = lane.transform.TransformPoint(next); RaycastHit hit; if (Physics.Raycast(p0 + Vector3.up * LidarMaxDistance, Vector2.down, out hit, float.MaxValue, mapLayerMask)) { float length = Vector3.Distance(p0, p1); int capturesPerSegment = (int)(Mathf.Max(Distance, length) / Distance); var delta = (p1 - p0) / capturesPerSegment; for (int c = 0; c < capturesPerSegment; c++) { var position = p0 + delta * c + hit.normal * Height; lidar.transform.position = position; var points = lidar.Capture(); for (int p = 0; p < points.Length; p++) { var point = points[p]; if (point != Vector4.zero && Random.value < Ratio) { var pt = point; writer.Write(new Vector3(pt.x, pt.z, pt.y), point.w); } } ; } } p0 = p1; } } } } } finally { EditorUtility.ClearProgressBar(); lidar.OnDestroy(); DestroyImmediate(lidar.gameObject); } }