Exemple #1
0
 // Function used to take control of the world rendering camera.
 public void mountCameraOnVehicle()
 {
     UI.Notify("Mounting camera to the vehicle.");
     if (Game.Player.Character.IsInVehicle())
     {
         if (activeCameraIndex == -1)
         {
             UI.Notify("Mounting free camera");
             CamerasList.ActivateMainCamera();
         }
         else if (activeCameraIndex == -2)
         {
             UI.Notify("Mounting free camera");
             CamerasList.ActivateGameplayCamera();
         }
         else
         {
             UI.Notify("Mounting camera from list");
             UI.Notify("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation);
             Logger.WriteLine("My current rotation: " + Game.Player.Character.CurrentVehicle.Rotation);
             activeCamera = CamerasList.ActivateCamera(activeCameraIndex);
         }
     }
     else
     {
         UI.Notify("Please enter a vehicle.");
     }
 }
        private void GatherData(int delay = 50)
        {
            Game.TimeScale = 0.005f;

            var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff";
            var guid           = Guid.NewGuid();

            Logger.WriteLine("generated scene guid: " + guid);

            if (useMultipleCameras)
            {
                for (var i = 0; i < CamerasList.cameras.Count; i++)
                {
                    Logger.WriteLine("activating camera " + i);
                    CamerasList.ActivateCamera(i);
                    Wait(delay);
                    GatherDatForOneCamera(dateTimeFormat, guid);
                }

                CamerasList.Deactivate();
            }
            else
            {
//                when multiple cameras are not used, only main camera is being used.
//                now it checks if it is active or not, and sets it
                if (!CamerasList.mainCamera.IsActive)
                {
                    CamerasList.ActivateMainCamera();
                }

                GatherDatForOneCamera(dateTimeFormat, guid);
            }

            Wait(delay);
        }
Exemple #3
0
        public VisionExport()
        {
            // loading ini file
            var parser = new FileIniDataParser();

            location = AppDomain.CurrentDomain.BaseDirectory;
            var data = parser.ReadFile(Path.Combine(location, "GTAVision.ini"));

            //UINotify(ConfigurationManager.AppSettings["database_connection"]);
            dataPath           = data["Snapshots"]["OutputDir"];
            logFilePath        = data["Snapshots"]["LogFile"];
            Logger.logFilePath = logFilePath;

            Logger.WriteLine("VisionExport constructor called.");
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            PostgresExport.InitSQLTypes();
            player = Game.Player;
            server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            server.Bind(new IPEndPoint(IPAddress.Loopback, 5555));
            server.Listen(5);
            //server = new UdpClient(5555);
            //outputPath = @"D:\Datasets\GTA\";
            //outputPath = Path.Combine(outputPath, "testData.yaml");
            //outStream = File.CreateText(outputPath);
            this.Tick    += new EventHandler(this.OnTick);
            this.KeyDown += OnKeyDown;

            Interval = 50;
            if (enabled)
            {
                postgresTask?.Wait();
                postgresTask = StartSession();
                runTask?.Wait();
                runTask = StartRun();
            }

            Logger.WriteLine("Logger prepared");
            UINotify("Logger initialized. Going to initialize cameras.");
            CamerasList.initialize();
            initialize4cameras();

//            var newCamera = World.CreateCamera(new Vector3(), new Vector3(), 50);
//            newCamera.NearClip = 0.15f;
//            newCamera.IsActive = true;
//            newCamera.Position = new Vector3(-1078f, -216f, 37f);
////            newCamera.Rotation = new Vector3(270f, 0f, 0f);  // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2
//            newCamera.Rotation = new Vector3(0f, 270f, 0f);  // x and y rotation seem to be switched. Can be fixed by setting the last parameter to 2
//            World.RenderingCamera = newCamera;

//            {-1078,-216,37}
//            CamerasList.setMainCamera(new Vector3(358f, -1308f, 52f), new Vector3(0f, 90f, 0f), 150, 0.15f);

            UINotify("VisionExport plugin initialized.");
        }
        private void InitializeCameras()
        {
            CamerasList.setMainCamera();

            CamerasList.addCamera(new Vector3(0f, 0f, 2.5626f), new Vector3(0f, 0f, 0f), 65, 0.15f);
            CamerasList.addCamera(new Vector3(0f, 0f, 2.5626f), new Vector3(0f, 0f, 90f), 65, 0.15f);
            CamerasList.addCamera(new Vector3(0f, 0f, 2.5626f), new Vector3(0f, 0f, 180f), 65, 0.15f);
            CamerasList.addCamera(new Vector3(0f, 0f, 2.5626f), new Vector3(0f, 0f, 270f), 65, 0.15f);
        }
        public VisionExport()
        {
            // loading ini file
            var parser = new FileIniDataParser();

            Location = AppDomain.CurrentDomain.BaseDirectory;
            var data = parser.ReadFile(Path.Combine(Location, "GTAVision.ini"));

            dataPath           = data["Snapshots"]["OutputDir"];
            LogFilePath        = data["Snapshots"]["LogFile"];
            everyNth           = int.Parse(data["Snapshots"]["EveryNth"]);
            ticked             = 0;
            Logger.logFilePath = LogFilePath;

            Logger.WriteLine("VisionExport constructor called.");
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }
            PostgresExport.InitSQLTypes();
            Tick    += OnTick;
            KeyDown += OnKeyDown;

            Interval = 100;
            if (enabled)
            {
                postgresTask?.Wait();
                postgresTask = StartSession();
                runTask?.Wait();
                runTask = StartRun();
            }

            Logger.WriteLine("Logger prepared");
            UI.Notify("Logger initialized. Going to initialize cameras.");
            CamerasList.initialize();
            InitializeCameras();
            UI.Notify("VisionExport plugin initialized.");
        }
Exemple #6
0
        private void gatherData(int delay = 5)
        {
            if (clearEverything)
            {
                ClearSurroundingEverything(Game.Player.Character.Position, 1000f);
            }

            Wait(100);

            var dateTimeFormat = @"yyyy-MM-dd--HH-mm-ss--fff";
            var guid           = Guid.NewGuid();

            Logger.WriteLine("generated scene guid: " + guid.ToString());

            if (useMultipleCameras)
            {
                for (var i = 0; i < CamerasList.cameras.Count; i++)
                {
                    Logger.WriteLine("activating camera " + i.ToString());
                    CamerasList.ActivateCamera(i);
                    gatherDatForOneCamera(dateTimeFormat, guid);
                    Wait(delay);
                }
                CamerasList.Deactivate();
            }
            else
            {
//                when multiple cameras are not used, only main camera is being used.
//                now it checks if it is active or not, and sets it
                if (!CamerasList.mainCamera.IsActive)
                {
                    CamerasList.ActivateMainCamera();
                }
                gatherDatForOneCamera(dateTimeFormat, guid);
            }
        }
Exemple #7
0
 // Function used to allows the user original control of the camera.
 public void restoreCamera()
 {
     UI.Notify("Relinquishing control");
     CamerasList.Deactivate();
 }
Exemple #8
0
        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;
            }
        }
Exemple #9
0
        private void initialize4cameras()
        {
//            cameras initialization:

//            for cameras mapping area before the car
//            float r = 8f; //radius of circle with 4 cameras
//            CamerasList.setMainCamera();
//            CamerasList.addCamera(new Vector3(0f, 2f, 0.4f), new Vector3(0f, 0f, 0f), 50, 1.5f);
//            CamerasList.addCamera(new Vector3(r, r + 2f, 0.4f), new Vector3(0f, 0f, 90f), 50, 1.5f);
//            CamerasList.addCamera(new Vector3(0f, 2*r + 2f, 0.4f), new Vector3(0f, 0f, 180f), 50, 1.5f);
//            CamerasList.addCamera(new Vector3(-r, r + 2f, 0.4f), new Vector3(0f, 0f, 270f), 50, 1.5f);

////            for 4 cameras of different sides of the car, for šochman
//            CamerasList.setMainCamera();
//            CamerasList.addCamera(new Vector3(0f, 2f, 0.3f), new Vector3(0f, 0f, 0f), 50, 0.15f);
//            CamerasList.addCamera(new Vector3(-0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 90f), 50, 0.15f);
//            CamerasList.addCamera(new Vector3(0f, -2.3f, 0.3f), new Vector3(0f, 0f, 180f), 50, 0.15f);
//            CamerasList.addCamera(new Vector3(0.8f, 0.8f, 0.4f), new Vector3(0f, 0f, 270f), 50, 0.15f);

//            for 4 cameras on top of car, heading 4 directions
//            CamerasList.setMainCamera();
//            CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), 58, 0.15f);
//            CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 90f), 58, 0.15f);
//            CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 180f), 58, 0.15f);
//            CamerasList.addCamera(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 270f), 58, 0.15f);

//            set only main camera for static traffic camera
//            CamerasList.setMainCamera(new Vector3(-1078f, -216f, 57f), new Vector3(270f, 0f, 0f), 50, 0.15f);

////            two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo
////            for cameras mapping area before the car
//            CamerasList.setMainCamera();
//            const float r = 8f; //radius of circle with 4 cameras
//            // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground
//            var carCenter = 0.5735f;
//            var camOne = new Vector3(-0.06f, 0.27f, 1.65f - carCenter);
//            var camTwo = new Vector3(-0.06f+0.54f, 0.27f, 1.65f - carCenter);
//            CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f);
////            4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras
//            CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 50, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f);
////            and now, one camera from birds-eye view, with this configuration, it sees all other cameras
//            CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f);

////            two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa
////            for cameras mapping area before the car
////            KITTI images have ratio of 3.32, they are very large and thus have large horizontal fov. This ratio can not be obtained here
////            so I set higher vertical fov and image may be then cropped into KITTI-like one
//            CamerasList.setMainCamera();
//            const float r = 8f; //radius of circle with 4 cameras
//            // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground
//            var carCenter = 0.5735f;
//            var camOne = new Vector3(-0.06f, 1.5f, 1.65f - carCenter);
//            var camTwo = new Vector3(-0.06f+0.54f, 1.5f, 1.65f - carCenter);
//            CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 90, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 90, 0.15f);
//            CamerasList.addCamera(camOne + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 90, 0.15f);
////            4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras
//            CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(r, r, 0f), new Vector3(0f, 0f, 90f), 50, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(0, 2*r, 0f), new Vector3(0f, 0f, 180f), 50, 0.15f);
////            CamerasList.addCamera(camTwo + new Vector3(-r, r, 0f), new Vector3(0f, 0f, 270f), 50, 0.15f);
////            and now, one camera from birds-eye view, with this configuration, it sees all other cameras
//            CamerasList.addCamera(camOne + new Vector3(0, r, r + 4), new Vector3(270f, 0f, 0f), 70, 0.15f);

//            na 32 metrů průměr, výš a natočit dolů
//            two "cameras", as in KITTI dataset, so we have 4-camera setup in stereo, but for offroad car, specifically, for Mesa
//            for cameras mapping area before the car
//            KITTI images have ratio of 3.32, they are very large and thus have large horizontal fov. This ratio can not be obtained here
//            so I set higher vertical fov and image may be then cropped into KITTI-like one
            CamerasList.setMainCamera();
            const float r = 16f; //radius of circle with 4 cameras
            // this height is for 1.65 m above ground, as in KITTI. The car has height of model ASEA is 1.5626, its center is in 0.5735 above ground
            var carCenter = 0.5735f;
            var camOne    = new Vector3(-0.06f, 1.5f, 1.65f - carCenter);
            var camTwo    = new Vector3(-0.06f + 0.54f, 1.5f, 1.65f - carCenter);

            CamerasList.addCamera(camOne + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f);

            CamerasList.addCamera(camOne + new Vector3(r, r, 5f), new Vector3(-30f, 0f, 90f), 90, 0.15f);
            CamerasList.addCamera(camOne + new Vector3(0, 2 * r, 5f), new Vector3(-30f, 0f, 180f), 90, 0.15f);
            CamerasList.addCamera(camOne + new Vector3(-r, r, 5f), new Vector3(-30f, 0f, 270f), 90, 0.15f);
//            4 camera layout from 1 camera should be ernough to reconstruct 3D map for both cameras
            CamerasList.addCamera(camTwo + new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), 90, 0.15f);
//            and now, one camera from birds-eye view, with this configuration, it sees all other cameras
            CamerasList.addCamera(camOne + new Vector3(0, r, r + 8), new Vector3(270f, 0f, 90f), 70, 0.15f);    //to have bigger view of area in front of and behind car
        }