From efabf105f3e25ee689bae17da8b5e2985c5d5201 Mon Sep 17 00:00:00 2001 From: katboi01 <59540382+katboi01@users.noreply.github.com> Date: Sat, 5 Nov 2022 10:39:11 +0100 Subject: [PATCH] Updated gif recorder to work with new camera system --- Assets/Scenes/Version2.unity | 69 +++++++++++++++++++++++++-- Assets/Scripts/CameraOrbit.cs | 23 ++------- Assets/Scripts/Screenshot.cs | 22 +++++---- ProjectSettings/ProjectSettings.asset | 2 +- 4 files changed, 82 insertions(+), 34 deletions(-) diff --git a/Assets/Scenes/Version2.unity b/Assets/Scenes/Version2.unity index b7acae1..c656df2 100644 --- a/Assets/Scenes/Version2.unity +++ b/Assets/Scenes/Version2.unity @@ -7329,7 +7329,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: ' PreviewCamera' + m_text: Use Animation Camera m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -7356,8 +7356,8 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 22 - m_fontSizeBase: 22 + m_fontSize: 18.4 + m_fontSizeBase: 18.4 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 @@ -14708,6 +14708,7 @@ GameObject: m_Component: - component: {fileID: 790387848} - component: {fileID: 790387849} + - component: {fileID: 790387850} m_Layer: 0 m_Name: PreviewCamera m_TagString: Untagged @@ -14772,6 +14773,66 @@ Camera: m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 +--- !u!114 &790387850 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 790387847} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3} + m_Name: + m_EditorClassIdentifier: + volumeTrigger: {fileID: 790387848} + volumeLayer: + serializedVersion: 2 + m_Bits: 1 + stopNaNPropagation: 1 + finalBlitToCameraTarget: 0 + antialiasingMode: 0 + temporalAntialiasing: + jitterSpread: 0.75 + sharpness: 0.25 + stationaryBlending: 0.615 + motionBlending: 0.85 + subpixelMorphologicalAntialiasing: + quality: 2 + fastApproximateAntialiasing: + fastMode: 1 + keepAlpha: 1 + fog: + enabled: 1 + excludeSkybox: 1 + debugLayer: + lightMeter: + width: 512 + height: 256 + showCurves: 1 + histogram: + width: 512 + height: 256 + channel: 3 + waveform: + exposure: 0.12 + height: 256 + vectorscope: + size: 256 + exposure: 0.12 + overlaySettings: + linearDepth: 0 + motionColorIntensity: 4 + motionGridSize: 64 + colorBlindnessType: 0 + colorBlindnessStrength: 1 + m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2} + m_ShowToolkit: 0 + m_ShowCustomSorter: 0 + breakBeforeColorGrading: 0 + m_BeforeTransparentBundles: [] + m_BeforeStackBundles: [] + m_AfterStackBundles: [] --- !u!1 &793664715 GameObject: m_ObjectHideFlags: 0 @@ -21982,7 +22043,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1882365342} m_Direction: 2 m_Value: 1 - m_Size: 0.88527817 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: diff --git a/Assets/Scripts/CameraOrbit.cs b/Assets/Scripts/CameraOrbit.cs index c0b2e7a..58a27dd 100644 --- a/Assets/Scripts/CameraOrbit.cs +++ b/Assets/Scripts/CameraOrbit.cs @@ -82,25 +82,10 @@ public class CameraOrbit : MonoBehaviour if (AAMode != AAModeDropdown.value) { - var postprocessLayer = Camera.main.GetComponent(); - switch (AAModeDropdown.value) //new - { - case 0: - postprocessLayer.antialiasingMode = PostProcessLayer.Antialiasing.None; - break; - case 1: - postprocessLayer.antialiasingMode = PostProcessLayer.Antialiasing.FastApproximateAntialiasing; - break; - case 2: - postprocessLayer.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; - break; - case 3: - postprocessLayer.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing; - break; - default: - postprocessLayer.antialiasingMode = PostProcessLayer.Antialiasing.None; - break; - } + var postprocessLayerMain = Camera.main.GetComponent(); + var postprocessLayerPreview = UmaViewerBuilder.Instance.PreviewCamera.GetComponent(); + postprocessLayerMain.antialiasingMode = postprocessLayerPreview.antialiasingMode = (PostProcessLayer.Antialiasing)AAModeDropdown.value; + Debug.Log($"Switched AntiAliasing to {(PostProcessLayer.Antialiasing)AAModeDropdown.value}"); AAMode = AAModeDropdown.value; } #if UNITY_ANDROID diff --git a/Assets/Scripts/Screenshot.cs b/Assets/Scripts/Screenshot.cs index 4c16fa0..09b5723 100644 --- a/Assets/Scripts/Screenshot.cs +++ b/Assets/Scripts/Screenshot.cs @@ -19,11 +19,12 @@ public class Screenshot : MonoBehaviour public static void TakeScreenshot() { + var camera = UmaViewerBuilder.Instance.PreviewCamera.enabled ? UmaViewerBuilder.Instance.PreviewCamera : Camera.main; int width = int.Parse(UmaViewerUI.Instance.SSWidth.text); int height = int.Parse(UmaViewerUI.Instance.SSHeight.text); width = width == -1 ? Screen.width : width; height = height == -1 ? Screen.height : height; - var image = GrabFrame(width, height, UmaViewerUI.Instance.SSTransparent.isOn); + var image = GrabFrame(camera, width, height, UmaViewerUI.Instance.SSTransparent.isOn); string fileName = Application.dataPath + "/../Screenshots/" + string.Format("UmaViewer_{0}", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff")); byte[] pngShot = ImageConversion.EncodeToPNG(image); @@ -39,13 +40,14 @@ public class Screenshot : MonoBehaviour recording = true; UmaViewerUI.Instance.GifButton.interactable = false; UmaViewerUI.Instance.GifSlider.value = 0; - StartCoroutine(RecordGif(int.Parse(UmaViewerUI.Instance.GifWidth.text), int.Parse(UmaViewerUI.Instance.GifHeight.text), UmaViewerUI.Instance.GifTransparent.isOn, (int)UmaViewerUI.Instance.GifQuality.value)); + StartCoroutine(RecordGif(int.Parse(UmaViewerUI.Instance.GifWidth.text), int.Parse(UmaViewerUI.Instance.GifHeight.text), UmaViewerUI.Instance.GifTransparent.isOn, 10)); //(int)UmaViewerUI.Instance.GifQuality.value)); } private IEnumerator RecordGif(int width, int height, bool transparent, int quality) { - var ppLayer = Camera.main.GetComponent(); + var camera = UmaViewerBuilder.Instance.PreviewCamera.enabled ? UmaViewerBuilder.Instance.PreviewCamera : Camera.main; + var ppLayer = camera.GetComponent(); bool oldPpState = ppLayer.enabled; ppLayer.enabled = false; @@ -58,36 +60,36 @@ public class Screenshot : MonoBehaviour var clipFrameCount = Mathf.RoundToInt(animeClip.length * animeClip.frameRate); StartCoroutine(CaptureToGIFCustom.Instance.Encode(animeClip.frameRate, quality)); - animator.speed = 0; - animator.Play(0, -1, 0); + UmaViewerUI.Instance.AnimationSpeedChange(0); + UmaViewerUI.Instance.AnimationProgressChange(0); yield return new WaitForSeconds(1); //wait for dynamicBone to settle; while (frame < clipFrameCount) { UmaViewerUI.Instance.GifSlider.value = (float)frame / clipFrameCount; - animator.Play(0, -1, (float)frame/clipFrameCount); + UmaViewerUI.Instance.AnimationProgressChange((float)frame / clipFrameCount); yield return new WaitForEndOfFrame(); - var tex = GrabFrame(width, height, transparent, transparent); + var tex = GrabFrame(camera, width, height, transparent, transparent); CaptureToGIFCustom.Instance.Frames.Add(new Image(tex)); Destroy(tex); frame++; } recording = false; - animator.speed = 1; + UmaViewerUI.Instance.AnimationProgressChange(0); + UmaViewerUI.Instance.AnimationSpeedChange(1); ppLayer.enabled = oldPpState; CaptureToGIFCustom.Instance.stop = true; UmaViewerUI.Instance.GifButton.interactable = true; UmaViewerUI.Instance.GifSlider.value = 1; } - public static Texture2D GrabFrame(int width, int height, bool transparent = true, bool gifBackground = false) + public static Texture2D GrabFrame(Camera cam, int width, int height, bool transparent = true, bool gifBackground = false) { var dimensions = GetResolution(width, height); width = dimensions.x; height = dimensions.y; - Camera cam = Camera.main; int oldMask = cam.cullingMask; var oldClearFlags = cam.clearFlags; Color oldBG = cam.backgroundColor; diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 158d8d4..b947e84 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -134,7 +134,7 @@ PlayerSettings: 16:10: 1 16:9: 1 Others: 1 - bundleVersion: 2.1.1 + bundleVersion: 2.1.2 preloadedAssets: [] metroInputSource: 0 wsaTransparentSwapchain: 0