diff --git a/Editor/Scripts/Fulldome.meta b/Editor/Scripts/Panels/CamControl Panel.meta similarity index 77% rename from Editor/Scripts/Fulldome.meta rename to Editor/Scripts/Panels/CamControl Panel.meta index 4ee8643..9d2776d 100644 --- a/Editor/Scripts/Fulldome.meta +++ b/Editor/Scripts/Panels/CamControl Panel.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a5141ac757691644b9acecc2a3386ef1 +guid: 1e663b641b1d74a46860fa6ce3f6356a folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs b/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs new file mode 100644 index 0000000..8099147 --- /dev/null +++ b/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System; + +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using UnityEngine.Playables; +using UnityEngine.Timeline; +using UnityEditor.PackageManager; + +using Unity.Formats.USD; + +public class AttachCamController : EditorWindow +{ + public static DropdownField m_dropDown; + public static DropdownField m_orientationDropdown; + private static List listOfCameras = new List(); + + [MenuItem("USD/Previsualization Panels/Add Camera Controller", priority = 130)] + public static void FullDomeView() + { + EditorWindow wnd = GetWindow(); + wnd.titleContent = new GUIContent("[Previz] Camera Controller"); + + // this makes it so that its not resizable + wnd.minSize = new Vector2(300,140); + wnd.maxSize = new Vector2(300,140); + + wnd.ShowPopup(); + } + + void CreateGUI() { + m_dropDown = new DropdownField(); + + foreach (Camera cam in FindObjectsOfType()) + { + listOfCameras.Add(cam.name); + m_dropDown.value = cam.name; + } + + m_dropDown.choices = listOfCameras; + + rootVisualElement.Add(new Label("\n Select a camera to attach controller script:")); + rootVisualElement.Add(m_dropDown); + rootVisualElement.Add(new Label("")); + + var switchButton = new Button(); + switchButton.text = "Switch to Camera"; + switchButton.clicked += switchCamera; + rootVisualElement.Add(switchButton); + + var addButton = new Button(); + addButton.text = "Add Camera Controller Script"; + addButton.clicked += addScript; + rootVisualElement.Add(addButton); + + var removeButton = new Button(); + removeButton.text = "Remove Camera Controller Script"; + removeButton.clicked += removeScript; + rootVisualElement.Add(removeButton); + + } + + // add camera movement script + private void addScript() { + if (m_dropDown.value == null) { + return; + } + + GameObject.Find(m_dropDown.value).AddComponent(); + + Debug.Log("[PREVIZ] Added the camera controller script to the " + m_dropDown.value + " camera!"); + } + + // remove camera movement script + private void removeScript() { + if (m_dropDown.value == null) { + return; + } + + if (GameObject.Find(m_dropDown.value).GetComponent() != null) { + if (Application.isPlaying) { + Destroy(GameObject.Find(m_dropDown.value).GetComponent()); + } else { + DestroyImmediate(GameObject.Find(m_dropDown.value).GetComponent()); + } + Debug.Log("[PREVIZ] Removed the camera controller script from the " + m_dropDown.value + " camera!"); + } + } + + // switch to selected camera + private void switchCamera() { + foreach (string camname in listOfCameras) + { + if (camname == m_dropDown.value) + { + GameObject.Find(camname).GetComponent().enabled = true; + } + else + { + GameObject.Find(camname).GetComponent().enabled = false; + } + } + } +} diff --git a/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs.meta b/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs.meta new file mode 100644 index 0000000..8185510 --- /dev/null +++ b/Editor/Scripts/Panels/CamControl Panel/AttachCamController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b8c6c9f7dc79f6f4887483cf8a3f3ea5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Panels/Fulldome Panel/AttachFulldome.cs b/Editor/Scripts/Panels/Fulldome Panel/AttachFulldome.cs index 2095a30..6601b0a 100644 --- a/Editor/Scripts/Panels/Fulldome Panel/AttachFulldome.cs +++ b/Editor/Scripts/Panels/Fulldome Panel/AttachFulldome.cs @@ -25,8 +25,8 @@ public static void FullDomeView() wnd.titleContent = new GUIContent("[Previz] Fulldome Camera"); // this makes it so that its not resizable - wnd.minSize = new Vector2(300,200); - wnd.maxSize = new Vector2(300,200); + wnd.minSize = new Vector2(300,170); + wnd.maxSize = new Vector2(300,170); wnd.ShowPopup(); } @@ -119,6 +119,7 @@ private void removeFulldome() { } else { DestroyImmediate(GameObject.Find("Fulldome Camera")); } + Debug.Log("[PREVIZ] Removed the fulldome camera script from " + m_dropDown.value + "!"); } diff --git a/Editor/Scripts/Timeline/ExportTimeline.cs b/Editor/Scripts/Timeline/ExportTimeline.cs index 17edd00..3529e41 100644 --- a/Editor/Scripts/Timeline/ExportTimeline.cs +++ b/Editor/Scripts/Timeline/ExportTimeline.cs @@ -56,7 +56,12 @@ public static void ExportToJson() if (path.Length != 0) { Debug.Log(timelineJson); - File.WriteAllText(path, JsonConvert.SerializeObject(JObject.Parse(timelineJson), Formatting.Indented)); + try { + File.WriteAllText(path, JsonConvert.SerializeObject(JObject.Parse(timelineJson), Formatting.Indented)); + } catch { + File.WriteAllText(path, timelineJson); + } + Debug.Log("[PREVIZ] Saved timeline information to " + path + "!"); } diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..0b5f155 --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 977d7401e0d09f142b9fcc6f0f086505 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 1d484fa..59b6313 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ The following is a brief list of features of this addon: * Toggle scene cameras to be seen through a fulldome lens * To stream fulldome footage to the dome, see [fulldome docs](https://github.com/shdw9/fulldome_previz_plugin/tree/main/Documentation~/Fulldome.md) * Utilizies Open Source Project: [FulldomeCameraForUnity](https://github.com/rsodre/FulldomeCameraForUnity) +* Camera Movement Script + * Control scene cameras with controls in the play scene + * Customizable settings *(smoothing, sensitivity, camera speed)* * Export Timeline Information * Save timeline changes to a JSON file * Allows you to import that information to different Digital Content Creation tools diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..22fc74f --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cccbee6f6437222498ca5961efd0646a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CameraControllerScript.meta b/Runtime/CameraControllerScript.meta new file mode 100644 index 0000000..c3a9d7f --- /dev/null +++ b/Runtime/CameraControllerScript.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b0d9261065e76dc47bf6da5ee048307f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CameraControllerScript/CameraController.cs b/Runtime/CameraControllerScript/CameraController.cs new file mode 100644 index 0000000..c57c721 --- /dev/null +++ b/Runtime/CameraControllerScript/CameraController.cs @@ -0,0 +1,114 @@ +using UnityEngine; + +// Daniel Flanigan, 2014 +// This is a combined mouse look and camera move script. +// The cam move script is by: Francis R. Griffiths-Keam +// original source: https://forum.unity.com/threads/combined-camera-movement-and-mouse-look-script.283290/ + +public class CameraController : MonoBehaviour +{ + Vector2 _mouseAbsolute; + Vector2 _smoothMouse; + [Space(20)] + [Header("Mouse Look Settings :")] + public Vector2 + clampInDegrees = new Vector2(360, 180); + public bool lockCursor; + public Vector2 sensitivity = new Vector2(2, 2); + public Vector2 smoothing = new Vector2(3, 3); + public Vector2 targetDirection; + public Vector2 targetCharacterDirection; + + // Assign this if there's a parent object controlling motion, such as a Character Controller. + // Yaw rotation will affect this object instead of the camera if set. + public GameObject characterBody; + + [Space(20)] + [Header("Camera Move Settings :")] + + public float speed = 5.0f; + + public KeyCode fwdKey = KeyCode.W; + public KeyCode leftKey = KeyCode.A; + public KeyCode backKey = KeyCode.S; + public KeyCode rightKey = KeyCode.D; + + Animator animator; + + void Start() + { + // Set target direction to the camera's initial orientation. + targetDirection = transform.localRotation.eulerAngles; + + // Set target direction for the character body to its inital state. + if (characterBody) + targetCharacterDirection = characterBody.transform.localRotation.eulerAngles; + } + + void Update() + { + // Ensure the cursor is always locked when set + Screen.lockCursor = lockCursor; + + // Allow the script to clamp based on a desired target value. + var targetOrientation = Quaternion.Euler(targetDirection); + var targetCharacterOrientation = Quaternion.Euler(targetCharacterDirection); + + // Get raw mouse input for a cleaner reading on more sensitive mice. + var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); + + // Scale input against the sensitivity setting and multiply that against the smoothing value. + mouseDelta = Vector2.Scale(mouseDelta, new Vector2(sensitivity.x * smoothing.x, sensitivity.y * smoothing.y)); + + // Interpolate mouse movement over time to apply smoothing delta. + _smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x); + _smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y); + + // Find the absolute mouse movement value from point zero. + _mouseAbsolute += _smoothMouse; + + // Clamp and apply the local x value first, so as not to be affected by world transforms. + if (clampInDegrees.x < 360) + _mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x * 0.5f, clampInDegrees.x * 0.5f); + + var xRotation = Quaternion.AngleAxis(-_mouseAbsolute.y, targetOrientation * Vector3.right); + transform.localRotation = xRotation; + + // Then clamp and apply the global y value. + if (clampInDegrees.y < 360) + _mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y * 0.5f, clampInDegrees.y * 0.5f); + + transform.localRotation *= targetOrientation; + + // If there's a character body that acts as a parent to the camera + if (characterBody) + { + var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, characterBody.transform.up); + characterBody.transform.localRotation = yRotation; + characterBody.transform.localRotation *= targetCharacterOrientation; + } + else + { + var yRotation = Quaternion.AngleAxis(_mouseAbsolute.x, transform.InverseTransformDirection(Vector3.up)); + transform.localRotation *= yRotation; + } + + if (Input.GetKey(rightKey)) + { + transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0)); + } + if (Input.GetKey(leftKey)) + { + transform.Translate(new Vector3(-speed * Time.deltaTime, 0, 0)); + } + if (Input.GetKey(backKey)) + { + transform.Translate(new Vector3(0, 0, -speed * Time.deltaTime)); + } + if (Input.GetKey(fwdKey)) + { + transform.Translate(new Vector3(0, 0, speed * Time.deltaTime)); + } + + } +} diff --git a/Runtime/CameraControllerScript/CameraController.cs.meta b/Runtime/CameraControllerScript/CameraController.cs.meta new file mode 100644 index 0000000..34c0f95 --- /dev/null +++ b/Runtime/CameraControllerScript/CameraController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 31966354d3e01ec4eaf4bb5071548515 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 13e643d..53b155c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.sfsucsc631team3b.fulldomepreviz", - "version": "1.0.0", + "version": "1.1.0", "displayName": "Fulldome Previsualization", - "description": "SFSU CSC 631 2023 - Team 3B Fulldome Previsualization Plugin in Unity\n\nThe Fulldome Previsualization Plugin modifies the USD menu to allow you to: \n - Import USD files with animation clips\n - Export USD files with modified animations\n - Add a fulldome camera rig to any specified camera in the scene\n - Export timeline information to a JSON file\n\nUnity Version: Unity.2022.2.9f1", + "description": "SFSU CSC 631 2023 - Team 3B Fulldome Previsualization Plugin in Unity\n\nThe Fulldome Previsualization Plugin modifies the USD menu to allow you to: \n\n - Import USD files with animation clips\n - Export USD files with modified animations using Unity Recorder\n - Toggle scene cameras to be seen through a fisheye/fulldome lens\n - Control scene cameras with controls in the play scene\n - Export timeline information to a JSON file\n\nBased on a student project proposal by Jeroen Lapr\u00e9 for the Computer Science Department of San Francisco State University\n\nUnity Version: Unity.2022.2.9f1", "unity": "2022.2", "unityRelease": "9f1", "documentationUrl": "https://github.com/shdw9/fulldome_previz_plugin/",