void CleanupSettingsAsset() { UnityHelpers.Destroy(m_WindowSettingsAsset, true); m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>(); AssetDatabase.CreateAsset(m_WindowSettingsAsset, FRPackagerPaths.GetRecorderRootPath() + "/RecorderWindowSettings.asset"); AssetDatabase.Refresh(); }
void BuildInputEditors() { var rs = target as RecorderSettings; if (!rs.inputsSettings.hasBrokenBindings && rs.inputsSettings.Count == m_InputEditors.Count) { return; } if (rs.inputsSettings.hasBrokenBindings) { rs.BindSceneInputSettings(); } foreach (var editor in m_InputEditors) { UnityHelpers.Destroy(editor.editor); } m_InputEditors.Clear(); foreach (var input in rs.inputsSettings) { m_InputEditors.Add(new InputEditorState(GetFieldDisplayState, input) { visible = true }); } }
public void Dispose() { UnityHelpers.Destroy(m_WorkTexture); m_WorkTexture = null; UnityHelpers.Destroy(m_VFLipMaterial); m_VFLipMaterial = null; }
public void OnRecorderSelected() { if (m_Editor != null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; } if (m_recorderSelector.selectedRecorder == null) { return; } m_Category = m_recorderSelector.category; if (m_WindowSettingsAsset.m_Settings != null && RecordersInventory.GetRecorderInfo(m_recorderSelector.selectedRecorder).settingsClass != m_WindowSettingsAsset.m_Settings.GetType()) { CleanupSettingsAsset(); } if (m_WindowSettingsAsset.m_Settings == null) { m_WindowSettingsAsset.m_Settings = RecordersInventory.GenerateRecorderInitialSettings(m_WindowSettingsAsset, m_recorderSelector.selectedRecorder); } m_Editor = Editor.CreateEditor(m_WindowSettingsAsset.m_Settings) as RecorderEditor; AssetDatabase.Refresh(); }
void DeleteRecorder(RecorderItem item) { var s = item.settings; m_ControllerSettings.RemoveRecorder(s); UnityHelpers.Destroy(item.editor, true); m_RecordingListItem.Remove(item); }
public static string GetRecorderVersionFilePath() { var dummy = ScriptableObject.CreateInstance <RecorderVersion>(); var path = Application.dataPath + AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(dummy)).Substring("Assets".Length); UnityHelpers.Destroy(dummy); return(path); }
public override void RecordFrame(RecordingSession session) { if (m_Inputs.Count != 1) throw new Exception("Unsupported number of sources"); Texture2D tex = null; if (m_Inputs[0] is GameViewInput) { tex = ((GameViewInput)m_Inputs[0]).image; if (m_Settings.outputFormat == ImageRecorderOutputFormat.EXR) { var textx = new Texture2D(tex.width, tex.height, TextureFormat.RGBAFloat, false); textx.SetPixels(tex.GetPixels()); tex = textx; } else if (m_Settings.outputFormat == ImageRecorderOutputFormat.PNG) { var textx = new Texture2D(tex.width, tex.height, TextureFormat.RGB24, false); textx.SetPixels(tex.GetPixels()); tex = textx; } } else { var input = (BaseRenderTextureInput)m_Inputs[0]; var width = input.outputRT.width; var height = input.outputRT.height; tex = new Texture2D(width, height, m_Settings.outputFormat != ImageRecorderOutputFormat.EXR ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat, false); var backupActive = RenderTexture.active; RenderTexture.active = input.outputRT; tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, false); tex.Apply(); RenderTexture.active = backupActive; } byte[] bytes; switch (m_Settings.outputFormat) { case ImageRecorderOutputFormat.PNG: bytes = tex.EncodeToPNG(); break; case ImageRecorderOutputFormat.JPEG: bytes = tex.EncodeToJPG(); break; case ImageRecorderOutputFormat.EXR: bytes = tex.EncodeToEXR(); break; default: throw new ArgumentOutOfRangeException(); } if(m_Inputs[0] is BaseRenderTextureInput || m_Settings.outputFormat != ImageRecorderOutputFormat.JPEG) UnityHelpers.Destroy(tex); var path = m_Settings.fileNameGenerator.BuildAbsolutePath(session); File.WriteAllBytes( path, bytes); }
public void Dispose() { if (recorder != null) { EndRecording(); UnityHelpers.Destroy(recorder); } }
public static string GetFrameRecorderPath() { var dummy = ScriptableObject.CreateInstance <FRPackagerPaths>(); var path = Application.dataPath + AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(dummy)).Substring("Assets".Length); UnityHelpers.Destroy(dummy); return(path.Replace("/Framework/Packager/Editor/FRPackagerPaths.cs", "")); }
internal void Flip(RenderTexture target) { if (m_WorkTexture == null || m_WorkTexture.width != target.width || m_WorkTexture.height != target.height) { UnityHelpers.Destroy(m_WorkTexture); m_WorkTexture = new RenderTexture(target.width, target.height, target.depth, target.format, RenderTextureReadWrite.Linear); } Graphics.Blit(target, m_WorkTexture, m_VFLipMaterial); Graphics.Blit(m_WorkTexture, target); }
void ResetSettings() { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_recorderSelector = null; var path = AssetDatabase.GetAssetPath(m_WindowSettingsAsset); UnityHelpers.Destroy(m_WindowSettingsAsset, true); AssetDatabase.DeleteAsset(path); AssetDatabase.Refresh(ImportAssetOptions.Default); m_WindowSettingsAsset = null; }
void StopRecording() { if (m_Editor != null) { var settings = (RecorderSettings)m_Editor.target; if (settings != null) { var recorderGO = SceneHook.FindRecorder(settings); if (recorderGO != null) { UnityHelpers.Destroy(recorderGO); } } } }
void DeleteRecorder(RecorderItem item, bool prompt) { if (!prompt || EditorUtility.DisplayDialog("Delete Recoder?", "Are you sure you want to delete '" + item.settings.name + "' ?", "Delete", "Cancel")) { var s = item.settings; m_ControllerSettings.RemoveRecorder(s); UnityHelpers.Destroy(s, true); UnityHelpers.Destroy(item.editor, true); m_RecordingListItem.Remove(item); } if (prompt) { Focus(); } }
void StopRecording() { if (m_Editor != null) { var settings = (RecorderSettings)m_Editor.target; if (settings != null) { var recorderGO = SceneHook.FindRecorder(settings); if (recorderGO != null) { UnityHelpers.Destroy(recorderGO); } } } m_FrameCount = 0; m_State = EState.Idle; }
internal void Flip(RenderTexture target) { if (m_WorkTexture == null || m_WorkTexture.width != target.width || m_WorkTexture.height != target.height) { UnityHelpers.Destroy(m_WorkTexture); m_WorkTexture = new RenderTexture(target); } var sRGBWrite = GL.sRGBWrite; GL.sRGBWrite = PlayerSettings.colorSpace == ColorSpace.Linear; Graphics.Blit(target, m_WorkTexture, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 1.0f)); Graphics.Blit(m_WorkTexture, target); GL.sRGBWrite = sRGBWrite; }
protected override void WriteFrame(Texture2D tex) { byte[] bytes; Profiler.BeginSample("AOVRecorder.EncodeImage"); try { switch (Settings.m_OutputFormat) { case ImageRecorderSettings.ImageRecorderOutputFormat.EXR: { bytes = tex.EncodeToEXR(ImageRecorderSettings.ToNativeType(Settings.EXRCompression)); WriteToFile(bytes); break; } case ImageRecorderSettings.ImageRecorderOutputFormat.PNG: bytes = tex.EncodeToPNG(); WriteToFile(bytes); break; case ImageRecorderSettings.ImageRecorderOutputFormat.JPEG: bytes = tex.EncodeToJPG(); WriteToFile(bytes); break; default: Profiler.EndSample(); throw new ArgumentOutOfRangeException(); } } finally { Profiler.EndSample(); } if (m_Inputs[0] is BaseRenderTextureInput || Settings.m_OutputFormat != ImageRecorderSettings.ImageRecorderOutputFormat.JPEG) { UnityHelpers.Destroy(tex); } }
/// <summary> /// Releases the encoder resources. /// </summary> protected virtual void DisposeEncoder() { UnityHelpers.Destroy(m_ReadbackTexture); Recording = false; }
public void Dispose() { UnityHelpers.Destroy(m_WorkTexture); m_WorkTexture = null; }
internal void Init(RenderTexture template) { UnityHelpers.Destroy(workTexture); workTexture = new RenderTexture(template); workTexture.name = "TextureFlipper_worktexture"; }
protected override void WriteFrame(Texture2D tex) { byte[] bytes; Profiler.BeginSample("AOVRecorder.EncodeImage"); try { switch (Settings.outputFormat) { case AOVRecorderOutputFormat.EXR: { #if OIIO_AVAILABLE TypeDesc typedesc = new TypeDesc(TypeDesc.BASETYPE.HALF); var width = tex.width; var height = tex.height; int nchanels = 4; m_imgSpec = new ImageSpec(width, height, nchanels, typedesc); string comp = m_Settings.AOVCompression.ToString(); m_imgSpec.attribute("compression", comp); bytes = tex.GetRawTextureData(); string path = m_PathQueue.Dequeue(); m_imgOutput.open(path, m_imgSpec); GCHandle bufferHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned); int scanwidth = width * nchanels * sizeof(float); int scanheight = nchanels * sizeof(float); int scanlinesize = (int)m_imgSpec.scanline_bytes(); TypeDesc odesc = new TypeDesc(TypeDesc.BASETYPE.FLOAT); m_imgOutput.write_image(odesc, new IntPtr(bufferHandle.AddrOfPinnedObject().ToInt64() + (height - 1) * scanwidth), scanheight, -scanwidth, Globals.AutoStride); bufferHandle.Free(); m_imgOutput.close(); #else bytes = tex.EncodeToEXR(); WriteToFile(bytes); #endif break; } case AOVRecorderOutputFormat.PNG: bytes = tex.EncodeToPNG(); WriteToFile(bytes); break; case AOVRecorderOutputFormat.JPEG: bytes = tex.EncodeToJPG(); WriteToFile(bytes); break; default: Profiler.EndSample(); throw new ArgumentOutOfRangeException(); } } finally { Profiler.EndSample(); } if (m_Inputs[0] is BaseRenderTextureInput || Settings.outputFormat != AOVRecorderOutputFormat.JPEG) { UnityHelpers.Destroy(tex); } }
public void OnDestroy() { StopRecording(); UnityHelpers.Destroy(m_Editor); m_Editor = null; }
public void OnGUI() { try { m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos); try { m_LastRepaint = DateTime.Now; // Bug? work arround: on Stop play, Enable is not called. if (m_Editor != null && m_Editor.target == null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_recorderSelector = null; } if (m_recorderSelector == null) { if (m_WindowSettingsAsset == null) { var candidates = AssetDatabase.FindAssets("t:RecorderWindowSettings"); if (candidates.Length > 0) { var path = AssetDatabase.GUIDToAssetPath(candidates[0]); m_WindowSettingsAsset = AssetDatabase.LoadAssetAtPath <RecorderWindowSettings>(path); if (m_WindowSettingsAsset == null) { AssetDatabase.DeleteAsset(path); } } if (m_WindowSettingsAsset == null) { m_WindowSettingsAsset = ScriptableObject.CreateInstance <RecorderWindowSettings>(); AssetDatabase.CreateAsset(m_WindowSettingsAsset, FRPackagerPaths.GetRecorderRootPath() + "/RecorderWindowSettings.asset"); AssetDatabase.Refresh(); } } m_recorderSelector = new RecorderSelector(OnRecorderSelected, false); m_recorderSelector.Init(m_WindowSettingsAsset.m_Settings, m_Category); } if (m_State == EState.WaitingForPlayModeToStartRecording && EditorApplication.isPlaying) { DelayedStartRecording(); } using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) m_recorderSelector.OnGui(); if (m_Editor != null) { m_Editor.showBounds = true; using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) { EditorGUILayout.Separator(); m_Editor.OnInspectorGUI(); EditorGUILayout.Separator(); } RecordButtonOnGui(); GUILayout.Space(50); } } finally { EditorGUILayout.EndScrollView(); } } catch (ExitGUIException) { } catch (Exception ex) { if (m_State == EState.Recording) { try { Debug.LogError("Aborting recording due to an exception!\n" + ex.ToString()); StopRecording(); } catch (Exception) {} } else { EditorGUILayout.HelpBox("An exception was raised while editing the settings. This can be indicative of corrupted settings.", MessageType.Warning); if (GUILayout.Button("Reset settings to default")) { ResetSettings(); } } } }
internal void Init(RenderTexture template) { UnityHelpers.Destroy(workTexture); workTexture = new RenderTexture(template); }