Browse Source

Add camera slots and Z rotation and FOV sliders

Different "cameras" can be switched between and are independent of
each other.

No additional cameras are actually added. Only the position,
rotation, distance and FOV are saved when switching between cameras to
simulate multiple cameras.

Keyboard shortcuts have been added to quickly switch between cameras.
Q + (1..5).

Z and FOV sliders are introduced that do exactly what you'd expect.

Closes #14
habeebweeb 4 years ago
parent
commit
767e15e84b

+ 5 - 0
COM3D2.MeidoPhotoStudio.Plugin/Config/MeidoPhotoStudio/Translations/en/translation.ui.json

@@ -251,6 +251,11 @@
         "spot": "Spot Angle",
         "shadow": "Shadow"
     },
+    "cameraPane": {
+        "header": "Camera",
+        "zRotation": "Z Rotation",
+        "fov": "FOV"
+    },
     "lightsPane": {
         "header": "Lights",
         "add": "+",

+ 83 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/BackgroundWindowPanes/CameraPane.cs

@@ -0,0 +1,83 @@
+using System.Linq;
+using UnityEngine;
+
+namespace COM3D2.MeidoPhotoStudio.Plugin
+{
+    public class CameraPane : BasePane
+    {
+        private readonly EnvironmentManager environmentManager;
+        private readonly SelectionGrid cameraGrid;
+        private readonly Slider zRotationSlider;
+        private readonly Slider fovSlider;
+
+        private string header;
+        private Vector3 cameraRotation;
+
+        public CameraPane(EnvironmentManager environmentManager)
+        {
+            this.environmentManager = environmentManager;
+            this.environmentManager.CameraChange += (s, a) => UpdatePane();
+
+            Camera camera = CameraUtility.MainCamera.camera;
+            Vector3 eulerAngles = camera.transform.eulerAngles;
+
+            cameraRotation = eulerAngles;
+
+            zRotationSlider = new Slider(Translation.Get("cameraPane", "zRotation"), 0f, 360f, eulerAngles.z);
+            zRotationSlider.ControlEvent += (s, a) =>
+            {
+                if (updating) return;
+                cameraRotation.z = zRotationSlider.Value;
+                camera.transform.rotation = Quaternion.Euler(cameraRotation);
+            };
+            fovSlider = new Slider(Translation.Get("cameraPane", "fov"), 20f, 150f, camera.fieldOfView);
+            fovSlider.ControlEvent += (s, a) =>
+            {
+                if (updating) return;
+                camera.fieldOfView = fovSlider.Value;
+            };
+            cameraGrid = new SelectionGrid(
+                Enumerable.Range(1, environmentManager.CameraCount).Select(x => x.ToString()).ToArray()
+            );
+            cameraGrid.ControlEvent += (s, a) =>
+            {
+                if (updating) return;
+                environmentManager.CurrentCameraIndex = cameraGrid.SelectedItemIndex;
+            };
+
+            header = Translation.Get("cameraPane", "header");
+        }
+
+        protected override void ReloadTranslation()
+        {
+            zRotationSlider.Label = Translation.Get("cameraPane", "zRotation");
+            fovSlider.Label = Translation.Get("cameraPane", "fov");
+            header = Translation.Get("cameraPane", "header");
+        }
+
+        public override void Draw()
+        {
+            MpsGui.Header(header);
+            MpsGui.WhiteLine();
+            cameraGrid.Draw();
+            zRotationSlider.Draw();
+            fovSlider.Draw();
+        }
+
+        public override void UpdatePane()
+        {
+            Camera camera = CameraUtility.MainCamera.camera;
+            Vector3 eulerAngles = camera.transform.eulerAngles;
+            cameraRotation = eulerAngles;
+
+            updating = true;
+
+            zRotationSlider.Value = eulerAngles.z;
+            fovSlider.Value = camera.fieldOfView;
+
+            cameraGrid.SelectedItemIndex = environmentManager.CurrentCameraIndex;
+
+            updating = false;
+        }
+    }
+}

+ 6 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/GUI/Panes/MainWindowPanes/BGWindowPane.cs

@@ -5,6 +5,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
     public class BGWindowPane : BaseMainWindowPane
     {
         private readonly BackgroundSelectorPane backgroundSelectorPane;
+        private readonly CameraPane cameraPane;
         private readonly LightsPane lightsPane;
         private readonly EffectsPane effectsPane;
         private readonly DragPointPane dragPointPane;
@@ -20,6 +21,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             sceneManagerButton.ControlEvent += (s, a) => sceneWindow.Visible = !sceneWindow.Visible;
 
             backgroundSelectorPane = AddPane(new BackgroundSelectorPane(environmentManager));
+            cameraPane = AddPane(new CameraPane(environmentManager));
             dragPointPane = AddPane(new DragPointPane());
             lightsPane = AddPane(new LightsPane(lightManager));
 
@@ -45,10 +47,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             sceneManagerButton.Draw();
             backgroundSelectorPane.Draw();
             dragPointPane.Draw();
+
             scrollPos = GUILayout.BeginScrollView(scrollPos);
+
+            cameraPane.Draw();
             lightsPane.Draw();
             effectsPane.Draw();
             otherEffectsPane.Draw();
+
             GUILayout.EndScrollView();
         }
 

+ 35 - 1
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Managers/EnvironmentManager.cs

@@ -7,6 +7,7 @@ using Object = UnityEngine.Object;
 namespace COM3D2.MeidoPhotoStudio.Plugin
 {
     using Input = InputManager;
+    using UInput = Input;
     public class EnvironmentManager : IManager, ISerializable
     {
         private static readonly BgMgr bgMgr = GameMain.Instance.BgMgr;
@@ -60,6 +61,22 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         private const float cameraFastMoveSpeed = 0.1f;
         private const float cameraFastZoomSpeed = 3f;
         private CameraInfo tempCameraInfo;
+        private int currentCameraIndex;
+        private const KeyCode AlphaOne = KeyCode.Alpha1;
+        public int CameraCount => cameraInfos.Length;
+        public EventHandler CameraChange;
+
+        public int CurrentCameraIndex
+        {
+            get => currentCameraIndex;
+            set
+            {
+                cameraInfos[currentCameraIndex] = mainCamera.GetInfo();
+                currentCameraIndex = value;
+                LoadCameraInfo(cameraInfos[currentCameraIndex]);
+            }
+        }
+        private CameraInfo[] cameraInfos;
 
         static EnvironmentManager()
         {
@@ -165,6 +182,12 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
             SaveTempCamera();
 
+            CameraInfo initalInfo = mainCamera.GetInfo();
+
+            cameraInfos = new CameraInfo[5];
+
+            for (var i = 0; i < CameraCount; i++) cameraInfos[i] = initalInfo;
+
             CubeSmallChange += OnCubeSmall;
             CubeActiveChange += OnCubeActive;
         }
@@ -210,6 +233,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
                 if (Input.GetKeyDown(MpsKey.CameraSave)) SaveTempCamera();
                 else if (Input.GetKeyDown(MpsKey.CameraLoad)) LoadCameraInfo(tempCameraInfo);
                 else if (Input.GetKeyDown(MpsKey.CameraReset)) ResetCamera();
+
+                for (var i = 0; i < CameraCount; i++)
+                {
+                    if (i != CurrentCameraIndex && UInput.GetKeyDown(AlphaOne + i)) CurrentCameraIndex = i;
+                }
             }
 
             var shift = Input.Shift;
@@ -255,7 +283,11 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
 
         private void SaveTempCamera() => tempCameraInfo = mainCamera.GetInfo(true);
 
-        public void LoadCameraInfo(CameraInfo info) => mainCamera.ApplyInfo(info, true);
+        public void LoadCameraInfo(CameraInfo info)
+        {
+            mainCamera.ApplyInfo(info, true);
+            CameraChange?.Invoke(this, EventArgs.Empty);
+        }
 
         private void ResetCamera()
         {
@@ -280,12 +312,14 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
         public Vector3 TargetPos { get; }
         public Quaternion Angle { get; }
         public float Distance { get; }
+        public float FOV { get; }
 
         public CameraInfo(CameraMain camera)
         {
             TargetPos = camera.GetTargetPos();
             Angle = camera.transform.rotation;
             Distance = camera.GetDistance();
+            FOV = camera.camera.fieldOfView;
         }
     }
 }

+ 1 - 0
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Utility.cs

@@ -243,6 +243,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             camera.SetTargetPos(info.TargetPos);
             camera.SetDistance(info.Distance);
             camera.transform.rotation = info.Angle;
+            camera.camera.fieldOfView = info.FOV;
             if (stop) StopAll();
         }