Updated gif recorder to work with new camera system

This commit is contained in:
katboi01
2022-11-05 10:39:11 +01:00
parent 96ec72b396
commit efabf105f3
4 changed files with 82 additions and 34 deletions
+65 -4
View File
@@ -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:
+4 -19
View File
@@ -82,25 +82,10 @@ public class CameraOrbit : MonoBehaviour
if (AAMode != AAModeDropdown.value)
{
var postprocessLayer = Camera.main.GetComponent<PostProcessLayer>();
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<PostProcessLayer>();
var postprocessLayerPreview = UmaViewerBuilder.Instance.PreviewCamera.GetComponent<PostProcessLayer>();
postprocessLayerMain.antialiasingMode = postprocessLayerPreview.antialiasingMode = (PostProcessLayer.Antialiasing)AAModeDropdown.value;
Debug.Log($"Switched AntiAliasing to {(PostProcessLayer.Antialiasing)AAModeDropdown.value}");
AAMode = AAModeDropdown.value;
}
#if UNITY_ANDROID
+12 -10
View File
@@ -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<PostProcessLayer>();
var camera = UmaViewerBuilder.Instance.PreviewCamera.enabled ? UmaViewerBuilder.Instance.PreviewCamera : Camera.main;
var ppLayer = camera.GetComponent<PostProcessLayer>();
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;
+1 -1
View File
@@ -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