Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes and fully working automatic data gathering. #16

Open
wants to merge 181 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 144 commits
Commits
Show all changes
181 commits
Select commit Hold shift + click to select a range
27f5236
Updated README of native driver.
Oct 11, 2017
81b1d83
indentation
Oct 11, 2017
37de58d
Little clarified install instructions.
Oct 11, 2017
dadb6b7
Added some notes to fix crashing game during screenshot.
Oct 12, 2017
bc5271e
Fixed postgres schema for managed plugin.
Oct 14, 2017
6d02a9f
Fully working dumping to files.
Oct 31, 2017
fcc4b8b
Added ini information.
Oct 31, 2017
8d625e7
Added scripts info.
Oct 31, 2017
f0844cf
Added docker compose and some printing.
Nov 11, 2017
3319207
Added sandbox to test things.
Nov 11, 2017
b4ef112
Fixed fucking typo
Nov 11, 2017
f78255f
Merge branch 'master' of https://github.com/umautobots/GTAVisionExport
Nov 11, 2017
ef31618
Merge branch 'master' of https://github.com/umautobots/GTAVisionExport
Nov 11, 2017
a0ed51b
Added infor about the database in docker.
Nov 11, 2017
aa2473d
Merge branch 'master' of https://github.com/racinmat/GTAVisionExport
Nov 11, 2017
31b4e90
added created
Nov 11, 2017
a4b0469
copied not working system inserts
Nov 11, 2017
1d6c516
Fixed fucking insert to db with duplicate and casting to string.
Nov 11, 2017
d42c2b7
fixed bigint
Nov 11, 2017
9f2b93c
added created everywhere
Nov 11, 2017
c2e668f
Merge remote-tracking branch 'origin/master'
Nov 11, 2017
d1fa562
Merge branch 'master' of https://github.com/racinmat/GTAVisionExport
Nov 11, 2017
451e678
added null prints, just to see what is wrong
Nov 12, 2017
dbcd228
Added some debug information.
Nov 12, 2017
571ccc3
added null check
Nov 12, 2017
b74ddeb
Merge branch 'master' of https://github.com/racinmat/GTAVisionExport
Nov 12, 2017
2c483a5
Merge remote-tracking branch 'origin/master'
Nov 12, 2017
a382d5b
added position showing
Nov 12, 2017
5e68cbd
added null check
Nov 12, 2017
b150e63
Fixed enum.
Nov 12, 2017
3580934
Moved UI Notify outside the postgres export
Nov 12, 2017
22bc074
Drastically changed uploading procedure. Now it saved to local disk i…
Nov 12, 2017
c135b8f
commented all archive related garbage
Nov 12, 2017
e719b5d
more meaningful file names. Based on real datetime.
Nov 12, 2017
84f71fb
lower time wait.
Nov 12, 2017
5fb80c3
better printscreens name
Nov 12, 2017
06c0d0c
Added some more description.
Nov 12, 2017
7259605
Tiff file is now created inside tiff
Nov 13, 2017
67d4882
Unified compression.
Nov 13, 2017
b5acb1e
Removed directories from single page tiff.
Nov 14, 2017
de7d10a
Async saving data to files.
Nov 14, 2017
9426f15
Commented 2D bounding box visualization
Nov 15, 2017
3bf97df
Added setting time.
Nov 16, 2017
9258989
Migrated to json.
Nov 16, 2017
a4f4a32
Fixed json reading values.
Nov 19, 2017
2fbec2a
Fixed json types.
Nov 19, 2017
e194f5c
Fixed null username.
racinmat Nov 20, 2017
940a241
dded original postprocessing script.
Nov 22, 2017
d502773
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
Nov 22, 2017
711b969
Reading output from ini file.
Nov 22, 2017
cec9095
Added key for turning notifications on and off.
Nov 23, 2017
6da3a46
All UI notify calls are wrapped now.
Nov 23, 2017
26d3f3c
Added comment.
racinmat Nov 23, 2017
8e95333
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Nov 23, 2017
12abd0c
Added milliseconds to the tiff name.
Nov 23, 2017
23d9abb
only milliseconds used. Useless when trying to set bigger precission.
Nov 23, 2017
2368634
Added info about correct ingame settings.
Nov 24, 2017
f933b8d
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Nov 24, 2017
83ef863
Changed interval.
Nov 24, 2017
d721484
Removed default path params.
Nov 24, 2017
4765e08
Added saving to one tiff, for BC.
Nov 24, 2017
19c157b
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Nov 24, 2017
4c7a863
fixed output name for jpeg conversion.
Nov 25, 2017
e1bb0ef
Used JPEG compression for RGB images
Nov 27, 2017
994e906
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Dec 7, 2017
5cc50fc
Added weather setting. Added persisting to trycatch
racinmat Dec 7, 2017
c8a502c
N now saves to database
racinmat Dec 7, 2017
eadaee9
added some thread testing things
Dec 7, 2017
fc54328
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
Dec 7, 2017
5c1cd93
Weather parsing throws exception (thich is caught, but incorrectly pa…
Dec 7, 2017
cdf3f48
added new weather to UINotify
Dec 7, 2017
c08e7f5
Added time interval constraint.
Dec 7, 2017
df6e9e3
Added support for one weather.
racinmat Dec 8, 2017
4dd2f85
added multiple weather options
racinmat Dec 8, 2017
cf14459
Added check for manual printscreen.
Dec 8, 2017
7fcc22d
Added manual starting.
Dec 8, 2017
f82ceb3
waiting for run and session to properly start
Dec 8, 2017
08a8bb3
Logger moved to utils
Dec 8, 2017
cbc4392
datetime in logs
Dec 8, 2017
3515aaa
added nam
Dec 8, 2017
d63201e
fixed inconsistent logging
Dec 8, 2017
9c931d5
removed on delete cascade from snapshot to run
Dec 13, 2017
1596083
Merge remote-tracking branch 'origin/master'
Dec 13, 2017
a744ba8
adding bounding box only for visible entities
racinmat Dec 13, 2017
9059e2d
added null checking for data from native plugin
racinmat Dec 13, 2017
3de1dcf
from debug to data collecting
racinmat Dec 13, 2017
9f49a2f
Added trycatch
racinmat Dec 13, 2017
de5b7d2
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
Dec 13, 2017
a9073f1
added additional attributes, used for 3D to 2D projection in the post…
Jan 3, 2018
77bfc1f
Addeed new class, for testing the scripted camera.
Jan 3, 2018
4e1c315
added original postprocessing, with modification for samples, added f…
Jan 18, 2018
6ea4c5e
wrapper for game pausing.
Jan 21, 2018
e1363f3
added velocity to both player and all detected entities
Jan 25, 2018
0c789c7
added new columns to database in readme
Jan 25, 2018
206d1de
merging
Jan 26, 2018
a757d94
changed database
racinmat Jan 26, 2018
2c1bc9b
added other script for camera handling. Using correct camera, hopefully
Jan 26, 2018
5372b1f
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Jan 26, 2018
733d54b
detection sql bugfix
racinmat Jan 26, 2018
3bb8540
added values for velocity
racinmat Jan 26, 2018
d140c29
all entities are put to db, not only visible ones. Increased range fo…
Jan 29, 2018
7be1f0b
added some modifications
Jan 29, 2018
cee1f90
added posibility of clearing everything
Jan 29, 2018
6431d31
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
Jan 29, 2018
5b8b898
added new cameras
Feb 6, 2018
a554479
created setup for multiple cameras
Feb 6, 2018
090804f
fixed cameras. Added description for downgrading
Feb 6, 2018
b38092b
changed log location
racinmat Feb 6, 2018
a19658f
added logging of obtained json
Feb 6, 2018
cef05d1
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Feb 6, 2018
1b9d8e4
fixed camera trainer stuff. Added som debug printing.
Feb 6, 2018
36073e3
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
racinmat Feb 6, 2018
d38f2e7
added possibility to specify field of view, logger uses windows newlines
racinmat Feb 7, 2018
ee45658
fully working screenshots taking from 4 camers
racinmat Feb 7, 2018
1553379
more logging
racinmat Feb 7, 2018
4576021
scene id persisten to db
racinmat Feb 7, 2018
2653abc
added loggin scene guid
racinmat Feb 7, 2018
8c592d4
added initialization
racinmat Feb 7, 2018
f3ecb5a
typo
racinmat Feb 7, 2018
0989d4b
better managing of game pauses. Added more time between camera activa…
racinmat Feb 7, 2018
848996c
increased waiting time after camera is set
racinmat Feb 7, 2018
7624a2d
correct game pauses management
racinmat Feb 7, 2018
345818f
unified manual and automatic data gathering
racinmat Feb 7, 2018
33605f9
fixed cameras manual handling
racinmat Feb 7, 2018
7e1ea11
unified main camera handling with multiple cameras
racinmat Feb 7, 2018
06d1015
finally working cameras with the new setup and without native calls
racinmat Feb 8, 2018
887759e
finally fully working multiple cameras data gathering!
racinmat Feb 8, 2018
8cd33a9
added relative rotation saving to database
racinmat Feb 11, 2018
2de37ee
fixed relative rotation persisting
Feb 19, 2018
c89bfe3
parameterized wait after camera switch
Feb 20, 2018
b9dab2a
optional setting near clip, persisting model matrix
Feb 21, 2018
57605a5
specified near clip and fov for scripted camera
Feb 22, 2018
0780864
used SHVDN2 as a nuget package
Feb 25, 2018
3d2b6ec
added multiple cameras inspection scripts, added more inspections for…
Feb 26, 2018
afdcdbe
added infor about path and not seeing msbuild
racinmat Mar 6, 2018
5850481
formatted and updated structure dump.
racinmat Mar 7, 2018
513d4a1
fixed db dump
racinmat Mar 7, 2018
768cbe3
update readme, removed aws library, fixed libraries
racinmat Mar 7, 2018
d08608c
updated advice when scripts dont load
racinmat Mar 7, 2018
e8a0ba3
set 4 cameras on the car, back to 0.15 near clip.
racinmat Mar 29, 2018
e299f7f
camera relative position is persisted into db along with relative rot…
racinmat Mar 30, 2018
b50dca5
upgraded hookversion, some playing with static camera
racinmat Apr 5, 2018
a6fefd9
upgraded to 1.10.5 version of scripthookvdotnet2
racinmat Apr 10, 2018
658f6ea
fixing dimensions for voxelmap depth image metrics
Apr 22, 2018
866e578
Merge branch 'master' of https://gitlab.com/racinmat/GTAVisionExport
May 6, 2018
48a2bee
redactored for multibatch evaluation
Jun 1, 2018
d0cf4be
added notes on managed plusing dependencies
Jun 27, 2018
8b90d83
new schema with added columns
Jun 27, 2018
aea6e85
added schema
Jun 27, 2018
e79ae78
specified schema, added types
Jun 27, 2018
309cf46
new db schema
Jun 27, 2018
dfd6915
removed user gta_v from dump
Jun 27, 2018
ea88c1f
added saving of ego vehicle model size, good for estimation of car mi…
Jul 17, 2018
6017286
updated db schema
Jul 17, 2018
246f2f3
finally found parameters for multi-camera KITTI-like setup
Jul 18, 2018
83a74b0
less frames during manual capturing
Jul 24, 2018
805d9cf
some other examples of using GTA api, minor modifications
racinmat Jul 24, 2018
1dc8883
Merge remote-tracking branch 'origin/master'
racinmat Jul 24, 2018
37e1e6a
some small refactoring, code cleanup
racinmat Jul 24, 2018
a0009ec
implemented threadsafe logging, more detailed logging of tiff-related…
racinmat Jul 25, 2018
d2433ce
fixed bug in logger initialization
racinmat Jul 25, 2018
c8c6c40
fixed another bug in logger initialization
racinmat Jul 25, 2018
8b23ea2
fixed fucking cameras visualization
racinmat Jul 26, 2018
af0f266
finally fucking working rotation of cameras relatively to the car
racinmat Jul 26, 2018
c398c6f
slight refactoring, added more starting positions
racinmat Jul 26, 2018
b7478e1
added some utilities for offroad preparation
racinmat Jul 27, 2018
ea3c2ed
added more offroad areas
racinmat Jul 30, 2018
0b7e01f
8 offroad areas, for some time that should suffice
racinmat Jul 31, 2018
a855caf
added the basic logic for offroad
racinmat Jul 31, 2018
6f3c794
refactored, now should be consistent with onread driving
racinmat Jul 31, 2018
433e2f3
fixed some bugs, but still needs some more work to function
racinmat Jul 31, 2018
ec20e5a
hopefully finally working the magic behind getting the z ground coord
racinmat Aug 1, 2018
1995f9e
other car, tried and is working in single player
racinmat Aug 1, 2018
09dedf8
hopefully correctly set cameras fov for being like kitti
racinmat Aug 2, 2018
3210342
added and refactored failsafe mechanisms for car stuck in offroad
racinmat Aug 8, 2018
7ec1a4a
better failsafe mechanisms
racinmat Aug 9, 2018
6a4d24a
done fixing failsafe mechanisms, sometimes false positives, but much …
racinmat Aug 9, 2018
308fc7c
cleaned db structure sql file, updated
racinmat Aug 9, 2018
e0ed3c3
fixed sql for current target
racinmat Aug 10, 2018
1f87aad
fixed sql for inserting current target
racinmat Aug 13, 2018
d841d9d
Update README.md
racinmat Jan 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions managed/GTAVision.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[Database]
ConnectionString=Server=127.0.0.1;Port=5432;Database=postgres;User Id=postgres;Password=postgres;
ConnectionString=Server=127.0.0.1;Port=5432;Database=gta_v;User Id=postgres;Password=postgres;
[Snapshots]
OutputDir=D:\GTAV_extraction_output\
LogFile=D:\GTAV_extraction_output\log.txt
LogFile=D:\Program Files\Rockstar Games\Grand Theft Auto V\my_log.txt
[MultiCamera]
GameplayTimeAfterSwitch=2000
10 changes: 10 additions & 0 deletions managed/GTAVisionExport.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GTAVisionUtils", "GTAVision
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageViewer", "ImageViewer\ImageViewer.csproj", "{30284E7F-F081-42AA-AC6A-6D4267E87024}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Sandbox\Sandbox.csproj", "{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,6 +43,14 @@ Global
{30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|Any CPU.Build.0 = Release|Any CPU
{30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|x64.ActiveCfg = Release|Any CPU
{30284E7F-F081-42AA-AC6A-6D4267E87024}.Release|x64.Build.0 = Release|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Debug|x64.Build.0 = Debug|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|Any CPU.Build.0 = Release|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|x64.ActiveCfg = Release|Any CPU
{35EC1C44-BEB8-4CF7-A5D8-AD3A2A029A5C}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
188 changes: 188 additions & 0 deletions managed/GTAVisionExport/CameraHandling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using GTA;
using GTA.Native;
using GTA.Math;
using GTA.NaturalMotion;
using GTAVisionUtils;
using MathNet.Spatial.Euclidean;
using MathNet.Spatial.Units;

namespace GTAVisionExport {
// Controls:
// P - mounts rendering camera on vehicle
// O - restores the rendering camera to original control

public class CameraHandling : Script {
// camera used on the vehicle
private Camera activeCamera;
private bool enabled = false;
private int activeCameraIndex = -1;
private bool showCameras = false;

public CameraHandling() {
UI.Notify("Loaded CameraHandling.cs");

// create a new camera
// World.DestroyAllCameras();

// attach time methods
Tick += OnTick;
KeyUp += onKeyUp;
}

// 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 main camera");
CamerasList.ActivateMainCamera();
}
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.");
}
}

// Function used to allows the user original control of the camera.
public void restoreCamera() {
UI.Notify("Relinquishing control");
CamerasList.Deactivate();
}

// Function used to keep camera on vehicle and facing forward on each tick step.
public void keepCameraOnVehicle() {
if (Game.Player.Character.IsInVehicle() && enabled) {
// keep the camera in the same position relative to the car
CamerasList.mainCamera.AttachTo(Game.Player.Character.CurrentVehicle, CamerasList.mainCameraPosition);

// rotate the camera to face the same direction as the car
CamerasList.mainCamera.Rotation = Game.Player.Character.CurrentVehicle.Rotation;
}
}

// Test vehicle controls
private void onKeyUp(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.P) {
activeCameraIndex = -1;
mountCameraOnVehicle();
enabled = true;
}

if (e.KeyCode == Keys.O) {
restoreCamera();
enabled = false;
}

// UI.Notify("keycode is:" + e.KeyCode);

if (e.KeyCode == Keys.Add) {
UI.Notify("Pressed numpad +");
showCameras = !showCameras;
UI.Notify("there are " + CamerasList.camerasPositions.Count + " cameras");
if (showCameras) {
UI.Notify("enabled cameras showing");
}
else {
UI.Notify("disabled cameras showing");
}

}

if (e.KeyCode == Keys.NumPad0) {
UI.Notify("Pressed numpad 0");
activeCameraIndex = 0;
mountCameraOnVehicle();
}

if (e.KeyCode == Keys.NumPad1) {
UI.Notify("Pressed numpad 1");
activeCameraIndex = 1;
mountCameraOnVehicle();
}

if (e.KeyCode == Keys.NumPad2) {
UI.Notify("Pressed numpad 2");
activeCameraIndex = 2;
mountCameraOnVehicle();
}

if (e.KeyCode == Keys.NumPad3) {
UI.Notify("Pressed numpad 3");
activeCameraIndex = 3;
mountCameraOnVehicle();
}

if (e.KeyCode == Keys.Decimal) {
UI.Notify("Pressed numpad ,");
activeCameraIndex = -1;
mountCameraOnVehicle();
}
}

void OnTick(object sender, EventArgs e) {
keepCameraOnVehicle();
if (showCameras) {
drawCamerasBoxes();
}
// drawAxesBoxesAround(new Vector3(-1078f, -216f, 200f));
}

void drawCamerasBoxes() {
// this shows white boxes where cameras are
foreach (var camPos in CamerasList.camerasPositions) {
var curVehicle = Game.Player.Character.CurrentVehicle;
// Logger.writeLine("rotation");
// Logger.writeLine(curVehicle.Rotation);
// Logger.writeLine("forward vector");
// Logger.writeLine(curVehicle.ForwardVector);
// Logger.writeLine("right vector");
// Logger.writeLine(curVehicle.RightVector);
// Logger.writeLine("up vector");
// Logger.writeLine(curVehicle.UpVector);
// var camPosToCar = Vector3.Modulate(curVehicle.ForwardVector, cameraPosition);
// camPosToCar += Vector3.Modulate(curVehicle.RightVector, cameraPosition);
// camPosToCar += Vector3.Modulate(curVehicle.UpVector, cameraPosition);
var rot = curVehicle.Rotation;
var rotX = Matrix3D.RotationAroundXAxis(Angle.FromDegrees(rot.X));
var rotY = Matrix3D.RotationAroundYAxis(Angle.FromDegrees(rot.Y));
var rotZ = Matrix3D.RotationAroundZAxis(Angle.FromDegrees(rot.Z));
var rotMat = rotX * rotY * rotZ;
var camPosToCar = rotMat * new Vector3D(camPos.X, camPos.Y, camPos.Z);
var absolutePosition = curVehicle.Position + new Vector3((float) camPosToCar[0], (float) camPosToCar[1], (float) camPosToCar[2]);
HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f));
}
}

void drawAxesBoxesAround(Vector3 position) {
var dist = 10;
var vectors = new[] {
new Vector3(dist, 0, 0), new Vector3(-dist, 0, 0), // x, pos and neg
new Vector3(0, dist, 0), new Vector3(0, -dist, 0), // y, pos and neg
new Vector3(0, 0, dist), new Vector3(0, 0, -dist), // z, pos and neg
};
var colors = new[] {
new Vector3(255, 0, 0), new Vector3(255, 180, 180), // x, pos and neg
new Vector3(0, 255, 0), new Vector3(180, 255, 180), // y, pos and neg
new Vector3(0, 0, 255), new Vector3(180, 180, 255), // z, pos and neg
};
for (int i = 0; i < vectors.Length; i++) {
var relativePos = vectors[i];
var color = colors[i];
var absolutePosition = position + new Vector3((float) relativePos[0], (float) relativePos[1], (float) relativePos[2]);
HashFunctions.Draw3DBox(absolutePosition, new Vector3(0.3f, 0.3f, 0.3f),
(byte) colors[i][0], (byte) colors[i][1], (byte) colors[i][2]);
}
}
}
}
150 changes: 150 additions & 0 deletions managed/GTAVisionExport/CamerasList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System;
using System.Collections.Generic;
using System.IO;
using GTA;
using GTA.Math;
using GTA.Native;
using GTAVisionUtils;
using IniParser;

namespace GTAVisionExport {
public static class CamerasList {
public static Camera mainCamera { get; private set; }
public static Vector3 mainCameraPosition { get; private set; }
public static Vector3 mainCameraRotation { get; private set; }

public static List<Camera> cameras { get; } = new List<Camera>();
public static List<Vector3> camerasPositions { get; } = new List<Vector3>();
public static List<Vector3> camerasRotations { get; } = new List<Vector3>();

public static Vector3? activeCameraRotation { get; private set; } = null;
public static Vector3? activeCameraPosition { get; private set; } = null;

private static int? gameplayInterval = null;

// public static Camera gameCam;
private static bool initialized = false;

public static void initialize() {
if (initialized) {
return;
}

World.DestroyAllCameras();
Logger.writeLine("destroying all cameras at the beginning, to be clear");
var parser = new FileIniDataParser();
var data = parser.ReadFile(Path.Combine(VisionExport.location, "GTAVision.ini"));
gameplayInterval = Convert.ToInt32(data["MultiCamera"]["GameplayTimeAfterSwitch"]);
// gameCam = World.RenderingCamera;

// mainCamera.IsActive = false;

initialized = true;
}

public static void setMainCamera(Vector3 position = new Vector3(), Vector3 rotation = new Vector3(), float? fov = null, float? nearClip = null) {
if (!initialized) {
throw new Exception("not initialized, please, call CamerasList.initialize() method before this one");
}

Logger.writeLine("setting main camera");
if (!fov.HasValue) {
fov = GameplayCamera.FieldOfView;
}
if (!nearClip.HasValue) {
nearClip = World.RenderingCamera.NearClip;
}

mainCamera = World.CreateCamera(position, rotation, fov.Value);
// mainCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value);
mainCamera.NearClip = nearClip.Value;
// mainCamera.IsActive = true;
mainCameraPosition = position;
mainCameraRotation = rotation;

mainCamera.IsActive = false;
World.RenderingCamera = null;
}

public static void addCamera(Vector3 position, Vector3 rotation, float? fov = null, float? nearClip = null) {
if (!initialized) {
throw new Exception("not initialized, please, call CamerasList.initialize() method before this one");
}

Logger.writeLine("adding new camera");
if (!fov.HasValue) {
fov = GameplayCamera.FieldOfView;
}
if (!nearClip.HasValue) {
nearClip = World.RenderingCamera.NearClip;
}

var newCamera = World.CreateCamera(new Vector3(), new Vector3(), fov.Value);
newCamera.NearClip = nearClip.Value;
cameras.Add(newCamera);
camerasPositions.Add(position);
camerasRotations.Add(rotation);
}

public static void ActivateMainCamera() {
if (!initialized) {
throw new Exception("not initialized, please, call CamerasList.initialize() method before this one");
}

if (mainCamera == null) {
throw new Exception("please, set main camera");
}

mainCamera.IsActive = true;
World.RenderingCamera = mainCamera;
activeCameraRotation = mainCameraRotation;
activeCameraPosition = mainCameraPosition;
}

public static Camera ActivateCamera(int i) {
if (!initialized) {
throw new Exception("not initialized, please, call CamerasList.initialize() method before this one");
}

if (i >= cameras.Count) {
throw new Exception("there is no camera with index " + i);
}

Game.Pause(false);
cameras[i].IsActive = true;
World.RenderingCamera = cameras[i];
cameras[i].AttachTo(Game.Player.Character.CurrentVehicle, camerasPositions[i]);
cameras[i].Rotation = Game.Player.Character.CurrentVehicle.Rotation + camerasRotations[i];
// WARNING: CAMERAS SETTING DO NOT WORK WHEN GAME IS PAUSED, SO WE NEED TO UNPAUSE THE GAME, SET THINGS UP, AND THEN PAUSE GAME AGAIN
// Script.Wait(1);
// //with time 1, sometimes depth does not correspond, and bounding boxes dont correspond by 3 frames
// //with time 2, depth does correspond, but bounding boxes dont correspond by 2 frames
// //with time 3, sometimes depth does not correspond, but bounding boxes dont correspond by 1 frames
// Script.Wait(4);//tried 4 milliseconds instead of one, so screenshots correspond to their data
Script.Wait(gameplayInterval.Value);
Game.Pause(true);
// UI.Notify("new camera rotation is: " + rotation.ToString());
Script.Wait(20);
Logger.writeLine("new camera position is: " + World.RenderingCamera.Position.ToString());
Logger.writeLine("new camera rotation is: " + World.RenderingCamera.Rotation.ToString());
Logger.writeLine("new camera position offset is: " + camerasPositions[i].ToString());
Logger.writeLine("new camera rotation offset is: " + camerasRotations[i].ToString());
activeCameraRotation = camerasRotations[i];
activeCameraPosition = camerasPositions[i];
return cameras[i];
}

public static void Deactivate() {
if (!initialized) {
throw new Exception("not initialized, please, call CamerasList.initialize() method before this one");
}

mainCamera.IsActive = false;
foreach (var camera in cameras) {
camera.IsActive = false;
}

World.RenderingCamera = null;
}
}
}
Loading