private void GatherDatForOneCamera(string dateTimeFormat, Guid guid) { GTAData dat; bool success; var weather = World.Weather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); if (CamerasList.activeCameraRotation.HasValue) { dat.CamRelativeRot = new GTAVector(CamerasList.activeCameraRotation.Value); } else { dat.CamRelativeRot = null; } if (CamerasList.activeCameraPosition.HasValue) { dat.CamRelativePos = new GTAVector(CamerasList.activeCameraPosition.Value); } else { dat.CamRelativePos = null; } dat.CurrentTarget = null; dat.sceneGuid = guid; if (dat == null) { return; } success = SaveSnapshotToFile(dat.ImageName); if (!success) { return; } PostgresExport.SaveSnapshot(dat, run.Id); }
public void OnKeyDown(object o, KeyEventArgs k) { // Logger.WriteLine("VisionExport OnKeyDown called."); switch (k.KeyCode) { case Keys.PageUp: postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); UINotify("GTA Vision Enabled"); // there is set weather, just for testing World.Weather = wantedWeather; break; case Keys.PageDown: if (staticCamera) { CamerasList.Deactivate(); } StopRun(); StopSession(); UINotify("GTA Vision Disabled"); break; // temp modification case Keys.H: EnterVehicle(); UINotify("Trying to enter vehicle"); ToggleNavigation(); break; // temp modification case Keys.Y: ReloadGame(); break; // temp modification case Keys.X: notificationsAllowed = !notificationsAllowed; if (notificationsAllowed) { UI.Notify("Notifications Enabled"); } else { UI.Notify("Notifications Disabled"); } break; // temp modification case Keys.U: var settings = ScriptSettings.Load("GTAVisionExport.xml"); var loc = AppDomain.CurrentDomain.BaseDirectory; //UINotify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); UINotify("BaseDirectory: " + loc); UINotify("ConnectionString: " + str); break; // temp modification case Keys.G: /* * IsGamePaused = true; * Game.Pause(true); * Script.Wait(500); * TraverseWeather(); * Script.Wait(500); * IsGamePaused = false; * Game.Pause(false); */ GTAData data; if (multipleWeathers) { data = GTAData.DumpData(Game.GameTime + ".tiff", wantedWeathers.ToList()); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; data = GTAData.DumpData(Game.GameTime + ".tiff", weather); } string path = @"D:\GTAV_extraction_output\trymatrix.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter file = File.CreateText(path)) { file.WriteLine("cam direction file"); file.WriteLine("direction:"); file.WriteLine( $"{World.RenderingCamera.Direction.X} {World.RenderingCamera.Direction.Y} {World.RenderingCamera.Direction.Z}"); file.WriteLine("Dot Product:"); file.WriteLine(Vector3.Dot(World.RenderingCamera.Direction, World.RenderingCamera.Rotation)); file.WriteLine("position:"); file.WriteLine( $"{World.RenderingCamera.Position.X} {World.RenderingCamera.Position.Y} {World.RenderingCamera.Position.Z}"); file.WriteLine("rotation:"); file.WriteLine( $"{World.RenderingCamera.Rotation.X} {World.RenderingCamera.Rotation.Y} {World.RenderingCamera.Rotation.Z}"); file.WriteLine("relative heading:"); file.WriteLine(GameplayCamera.RelativeHeading.ToString()); file.WriteLine("relative pitch:"); file.WriteLine(GameplayCamera.RelativePitch.ToString()); file.WriteLine("fov:"); file.WriteLine(GameplayCamera.FieldOfView.ToString()); } } break; // temp modification case Keys.T: World.Weather = Weather.Raining; /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */ Function.Call(Hash._SET_RAIN_FX_INTENSITY, 0.5f); var test = Function.Call <float>(Hash.GET_RAIN_LEVEL); UINotify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); break; case Keys.N: UINotify("N pressed, going to take screenshots"); startRunAndSessionManual(); postgresTask?.Wait(); runTask?.Wait(); UINotify("starting screenshots"); for (int i = 0; i < 2; i++) { GamePause(true); gatherData(100); GamePause(false); Script.Wait(200); // hoping game will go on during this wait } if (staticCamera) { CamerasList.Deactivate(); } StopRun(); StopSession(); break; case Keys.OemMinus: //to tlačítko vlevo od pravého shiftu, - UINotify("- pressed, going to rotate cameras"); Game.Pause(true); for (int i = 0; i < CamerasList.cameras.Count; i++) { Logger.WriteLine($"activating camera {i}"); CamerasList.ActivateCamera(i); Script.Wait(1000); } CamerasList.Deactivate(); Game.Pause(false); break; case Keys.I: var info = new GTAVisionUtils.InstanceData(); UINotify(info.type); UINotify(info.publichostname); break; case Keys.Divide: Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); var startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); var start = OffroadPlanning.GetRandomPoint(startRect); var startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); // OffroadPlanning.setNextStart(); startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); start = OffroadPlanning.GetRandomPoint(startRect); somePos = start; startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); // when I use the same position, the GetGroundHeight call takes coordinates of player as ground height Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, 800); Logger.WriteLine($"teleporting player above teh position."); Script.Wait(50); startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); Logger.ForceFlush(); break; case Keys.F12: Logger.WriteLine($"{World.GetGroundHeight(Game.Player.Character.Position)} is the current player ({Game.Player.Character.Position}) ground position."); Logger.WriteLine($"{World.GetGroundHeight(somePos)} is the {somePos} ground position."); break; case Keys.F11: Model mod = new Model(GTAConst.OffroadVehicleHash); var player = Game.Player; var vehicle = World.CreateVehicle(mod, player.Character.Position); player.Character.SetIntoVehicle(vehicle, VehicleSeat.Driver); break; case Keys.F10: startRect = OffroadPlanning.GetRandomRect(OffroadPlanning.GetRandomArea()); start = OffroadPlanning.GetRandomPoint(startRect); somePos = start; startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); for (int i = 900; i > 100; i -= 50) { // when I use the same position, the GetGroundHeight call takes coordinates of player as ground height Game.Player.Character.Position = new Vector3(start.X + 5, start.Y + 5, i); Logger.WriteLine($"teleporting player above teh position to height {i}."); Script.Wait(500); startZ = World.GetGroundHeight(new Vector2(start.X, start.Y)); Logger.WriteLine($"{startZ} is the ground position of {start}."); } break; case Keys.F9: //turn on and off for datagathering during driving, mostly for testing offroad gatheringData = !gatheringData; if (gatheringData) { UI.Notify("will be gathering data"); } else { UI.Notify("won't be gathering data"); } break; } }
private void gatherDatForOneCamera(string dateTimeFormat, Guid guid) { GTAData dat; bool success; if (multipleWeathers) { dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), wantedWeathers.ToList()); } else { Weather weather = currentWeather ? GTA.World.Weather : wantedWeather; dat = GTAData.DumpData(DateTime.UtcNow.ToString(dateTimeFormat), weather); } if (CamerasList.activeCameraRotation.HasValue) { dat.CamRelativeRot = new GTAVector(CamerasList.activeCameraRotation.Value); } else { dat.CamRelativeRot = null; } if (CamerasList.activeCameraPosition.HasValue) { dat.CamRelativePos = new GTAVector(CamerasList.activeCameraPosition.Value); } else { dat.CamRelativePos = null; } if (drivingOffroad && OffroadPlanning.currentTarget != null) { dat.CurrentTarget = GTAVector2.fromVector2(OffroadPlanning.currentTarget.Value); } else { dat.CurrentTarget = null; } dat.sceneGuid = guid; if (dat == null) { return; } if (multipleWeathers) { success = saveSnapshotToFile(dat.ImageName, wantedWeathers, false); } else { Weather weather = currentWeather ? World.Weather : wantedWeather; success = saveSnapshotToFile(dat.ImageName, weather, false); } if (!success) { // when getting data and saving to file failed, saving to db is skipped return; } PostgresExport.SaveSnapshot(dat, run.guid); }
public void OnKeyDown(object o, KeyEventArgs k) { if (k.KeyCode == Keys.PageUp) { postgresTask?.Wait(); postgresTask = StartSession(); runTask?.Wait(); runTask = StartRun(); UI.Notify("GTA Vision Enabled"); } if (k.KeyCode == Keys.PageDown) { StopRun(); StopSession(); UI.Notify("GTA Vision Disabled"); } if (k.KeyCode == Keys.H) // temp modification { EnterVehicle(); UI.Notify("Trying to enter vehicle"); ToggleNavigation(); } if (k.KeyCode == Keys.Y) // temp modification { ReloadGame(); } if (k.KeyCode == Keys.U) // temp modification { var settings = ScriptSettings.Load("GTAVisionExport.xml"); var loc = AppDomain.CurrentDomain.BaseDirectory; //UI.Notify(ConfigurationManager.AppSettings["database_connection"]); var str = settings.GetValue("", "ConnectionString"); UI.Notify(loc); } if (k.KeyCode == Keys.G) // temp modification { /* * IsGamePaused = true; * Game.Pause(true); * Script.Wait(500); * TraverseWeather(); * Script.Wait(500); * IsGamePaused = false; * Game.Pause(false); */ var data = GTAData.DumpData(Game.GameTime + ".tiff", new List <Weather>(wantedWeather)); string path = @"C:\Users\NGV-02\Documents\Data\trymatrix.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter file = File.CreateText(path)) { file.WriteLine("cam direction file"); file.WriteLine("direction:"); file.WriteLine(GameplayCamera.Direction.X.ToString() + ' ' + GameplayCamera.Direction.Y.ToString() + ' ' + GameplayCamera.Direction.Z.ToString()); file.WriteLine("Dot Product:"); file.WriteLine(Vector3.Dot(GameplayCamera.Direction, GameplayCamera.Rotation)); file.WriteLine("position:"); file.WriteLine(GameplayCamera.Position.X.ToString() + ' ' + GameplayCamera.Position.Y.ToString() + ' ' + GameplayCamera.Position.Z.ToString()); file.WriteLine("rotation:"); file.WriteLine(GameplayCamera.Rotation.X.ToString() + ' ' + GameplayCamera.Rotation.Y.ToString() + ' ' + GameplayCamera.Rotation.Z.ToString()); file.WriteLine("relative heading:"); file.WriteLine(GameplayCamera.RelativeHeading.ToString()); file.WriteLine("relative pitch:"); file.WriteLine(GameplayCamera.RelativePitch.ToString()); file.WriteLine("fov:"); file.WriteLine(GameplayCamera.FieldOfView.ToString()); } } } if (k.KeyCode == Keys.T) // temp modification { World.Weather = Weather.Raining; /* set it between 0 = stop, 1 = heavy rain. set it too high will lead to sloppy ground */ Function.Call(GTA.Native.Hash._SET_RAIN_FX_INTENSITY, 0.5f); var test = Function.Call <float>(GTA.Native.Hash.GET_RAIN_LEVEL); UI.Notify("" + test); World.CurrentDayTime = new TimeSpan(12, 0, 0); //Script.Wait(5000); } if (k.KeyCode == Keys.N) { /* * //var color = VisionNative.GetColorBuffer(); * * List<byte[]> colors = new List<byte[]>(); * Game.Pause(true); * Script.Wait(1); * var depth = VisionNative.GetDepthBuffer(); * var stencil = VisionNative.GetStencilBuffer(); * foreach (var wea in wantedWeather) { * World.TransitionToWeather(wea, 0.0f); * Script.Wait(1); * colors.Add(VisionNative.GetColorBuffer()); * } * Game.Pause(false); * if (depth != null) * { * var res = Game.ScreenResolution; * var t = Tiff.Open(Path.Combine(dataPath, "test.tiff"), "w"); * ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); * t.Close(); * UI.Notify(GameplayCamera.FieldOfView.ToString()); * } * else * { * UI.Notify("No Depth Data quite yet"); * } * //UI.Notify((connection != null && connection.Connected).ToString()); */ //var color = VisionNative.GetColorBuffer(); for (int i = 0; i < 100; i++) { List <byte[]> colors = new List <byte[]>(); Game.Pause(true); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); foreach (var wea in wantedWeather) { World.TransitionToWeather(wea, 0.0f); Script.Wait(1); colors.Add(VisionNative.GetColorBuffer()); } Game.Pause(false); var res = Game.ScreenResolution; var t = Tiff.Open(Path.Combine(dataPath, "info" + i.ToString() + ".tiff"), "w"); ImageUtils.WriteToTiff(t, res.Width, res.Height, colors, depth, stencil); t.Close(); UI.Notify(GameplayCamera.FieldOfView.ToString()); //UI.Notify((connection != null && connection.Connected).ToString()); var data = GTAData.DumpData(Game.GameTime + ".dat", new List <Weather>(wantedWeather)); string path = @"C:\Users\NGV-02\Documents\Data\info.txt"; // This text is added only once to the file. if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter file = File.CreateText(path)) { file.WriteLine("cam direction & Ped pos file"); } } using (StreamWriter file = File.AppendText(path)) { file.WriteLine("==============info" + i.ToString() + ".tiff 's metadata======================="); file.WriteLine("cam pos"); file.WriteLine(GameplayCamera.Position.X.ToString()); file.WriteLine(GameplayCamera.Position.Y.ToString()); file.WriteLine(GameplayCamera.Position.Z.ToString()); file.WriteLine("cam direction"); file.WriteLine(GameplayCamera.Direction.X.ToString()); file.WriteLine(GameplayCamera.Direction.Y.ToString()); file.WriteLine(GameplayCamera.Direction.Z.ToString()); file.WriteLine("character"); file.WriteLine(data.Pos.X.ToString()); file.WriteLine(data.Pos.Y.ToString()); file.WriteLine(data.Pos.Z.ToString()); foreach (var detection in data.Detections) { file.WriteLine(detection.Type.ToString()); file.WriteLine(detection.Pos.X.ToString()); file.WriteLine(detection.Pos.Y.ToString()); file.WriteLine(detection.Pos.Z.ToString()); } } Script.Wait(200); } } if (k.KeyCode == Keys.I) { var info = new GTAVisionUtils.InstanceData(); UI.Notify(info.type); UI.Notify(info.publichostname); } }
public void OnTick(object o, EventArgs e) { if (server.Poll(10, SelectMode.SelectRead) && connection == null) { connection = server.Accept(); UI.Notify("CONNECTED"); connection.Blocking = false; } handlePipeInput(); if (!enabled) { return; } //Array values = Enum.GetValues(typeof(Weather)); switch (checkStatus()) { case GameStatus.NeedReload: //TODO: need to get a new session and run? StopRun(); runTask?.Wait(); runTask = StartRun(); //StopSession(); //Autostart(); UI.Notify("need reload game"); Script.Wait(100); ReloadGame(); break; case GameStatus.NeedStart: //TODO do the autostart manually or automatically? //Autostart(); // use reloading temporarily StopRun(); ReloadGame(); Script.Wait(100); runTask?.Wait(); runTask = StartRun(); //Autostart(); break; case GameStatus.NoActionNeeded: break; } if (!runTask.IsCompleted) { return; } if (!postgresTask.IsCompleted) { return; } List <byte[]> colors = new List <byte[]>(); Game.Pause(true); Script.Wait(500); GTAData dat = GTAData.DumpData(Game.GameTime + ".tiff", new List <Weather>(wantedWeather)); if (dat == null) { return; } var thisframe = VisionNative.GetCurrentTime(); var depth = VisionNative.GetDepthBuffer(); var stencil = VisionNative.GetStencilBuffer(); colors.Add(VisionNative.GetColorBuffer()); /* * foreach (var wea in wantedWeather) { * World.TransitionToWeather(wea, 0.0f); * Script.Wait(1); * colors.Add(VisionNative.GetColorBuffer()); * }*/ Game.Pause(false); /* * if (World.Weather != Weather.Snowing) * { * World.TransitionToWeather(Weather.Snowing, 1); * * }*/ var colorframe = VisionNative.GetLastColorTime(); var depthframe = VisionNative.GetLastConstantTime(); var constantframe = VisionNative.GetLastConstantTime(); //UI.Notify("DIFF: " + (colorframe - depthframe) + " FRAMETIME: " + (1 / Game.FPS) * 1000); if (depth == null || stencil == null) { return; } /* * this code checks to see if there's drift * it's kinda pointless because we end up "straddling" a present call, * so the capture time difference can be ~1/4th of a frame but still the * depth/stencil and color buffers are one frame offset from each other * if (Math.Abs(thisframe - colorframe) < 60 && Math.Abs(colorframe - depthframe) < 60 && * Math.Abs(colorframe - constantframe) < 60) * { * * * * * * PostgresExport.SaveSnapshot(dat, run.guid); * } */ ImageUtils.WaitForProcessing(); ImageUtils.StartUploadTask(archive, Game.GameTime.ToString(), Game.ScreenResolution.Width, Game.ScreenResolution.Height, colors, depth, stencil); PostgresExport.SaveSnapshot(dat, run.guid); if (S3Stream.Length > 512 * 1024 * 1024) { ImageUtils.WaitForProcessing(); StopRun(); runTask?.Wait(); runTask = StartRun(); } }