Skip to content

Commit

Permalink
Initial commit with Recorder stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
mminer committed May 19, 2021
0 parents commit baece27
Show file tree
Hide file tree
Showing 19 changed files with 341 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions Editor/BigCameraInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Linq;
using UnityEditor.Recorder;
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
/// <summary>
/// Input that divides a tagged camera's projection matrix and renders the tiles to individual render textures.
/// </summary>
class BigCameraInput : RecorderInput
{
BigCameraInputSettings InputSettings => settings as BigCameraInputSettings;

protected override void BeginRecording(RecordingSession session)
{
base.BeginRecording(session);
// TODO: create render textures
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
// TODO: throw out render textures
}

protected override void NewFrameReady(RecordingSession session)
{
base.NewFrameReady(session);
var camera = GetTargetCamera(InputSettings.CameraTag);

// TODO:
// save current projection matrix
// save current render target
// change projection matrix
// change render target
// render camera
// reset render target
// reset projection matrix
}

static Camera GetTargetCamera(string cameraTag)
{
try
{
var cameras = GameObject
.FindGameObjectsWithTag(cameraTag)
.Select(gameObject => gameObject.GetComponent<Camera>())
.Where(camera => camera != null)
.ToList();

if (cameras.Count > 1)
{
Debug.LogWarning($"Found more than one camera with tag '{cameraTag}'.");
}

return cameras.FirstOrDefault();
}
catch (UnityException)
{
Debug.LogWarning($"Tag '{cameraTag}' does not exist.");
return null;
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigCameraInput.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions Editor/BigCameraInputSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using UnityEditor.Recorder.Input;
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
[Serializable]
class BigCameraInputSettings : ImageInputSettings
{
protected override Type InputType => typeof(BigCameraInput);

public string CameraTag
{
get => cameraTag;
set => cameraTag = value;
}

[SerializeField] string cameraTag = "MainCamera";

public override int OutputHeight
{
get => outputHeight;
set => outputHeight = value;
}

[SerializeField] int outputHeight = 8096;

public override int OutputWidth
{
get => outputWidth;
set => outputWidth = value;
}

[SerializeField] int outputWidth = 8096;

protected override bool ValidityCheck(List<string> errors)
{
var ok = true;

if (OutputWidth <= 0 || OutputHeight <= 0)
{
errors.Add($"Invalid output resolution: {OutputWidth}x{OutputHeight}");
ok = false;
}

return ok;
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigCameraInputSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Editor/BigCameraInputSettingsPropertyDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
[CustomPropertyDrawer(typeof(BigCameraInputSettings))]
class BigCameraInputSettingsPropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
// Removes gap above controls.
return 0;
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var cameraTag = property.FindPropertyRelative("cameraTag");
var outputHeight = property.FindPropertyRelative("outputHeight");
var outputWidth = property.FindPropertyRelative("outputWidth");

using (new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.PropertyField(cameraTag);
EditorGUILayout.PropertyField(outputWidth);
EditorGUILayout.PropertyField(outputHeight);
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigCameraInputSettingsPropertyDrawer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Editor/BigImageInputSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using UnityEditor.Recorder;
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
/// <summary>
/// Input settings specialization with a camera input as the only option.
/// </summary>
[Serializable]
class BigImageInputSelector : InputSettingsSelector
{
[SerializeField] BigCameraInputSettings cameraInputSettings = new BigCameraInputSettings();
}
}
11 changes: 11 additions & 0 deletions Editor/BigImageInputSelector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Editor/BigImageRecorder.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "BigImageRecorder.Editor",
"rootNamespace": "",
"references": [
"Unity.Recorder.Editor"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Editor/BigImageRecorder.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Editor/BigImageRecorder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEditor.Recorder;

namespace UnityEditor.BigImageRecorder
{
/// <summary>
/// Recorder to capture image sequences that exceed Unity's maximum texture size.
/// </summary>
class BigImageRecorder : GenericRecorder<BigImageRecorderSettings>
{
protected override void RecordFrame(RecordingSession session)
{
var path = Settings.FileNameGenerator.BuildAbsolutePath(session);
var input = m_Inputs[0] as BigCameraInput;
// TODO: save images
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigImageRecorder.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Editor/BigImageRecorderEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using UnityEditor.Recorder;
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
[CustomEditor(typeof(BigImageRecorderSettings))]
class BigImageRecorderEditor : RecorderEditor
{
protected override void FileTypeAndFormatGUI()
{
base.FileTypeAndFormatGUI();
GUILayout.Label("PNG is the only supported image format.");
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigImageRecorderEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Editor/BigImageRecorderSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using UnityEditor.Recorder;
using UnityEngine;

namespace UnityEditor.BigImageRecorder
{
[RecorderSettings(typeof(BigImageRecorder), "Big Image Sequence", "imagesequence_16")]
class BigImageRecorderSettings : RecorderSettings
{
[SerializeField] BigImageInputSelector imageInputSelector = new BigImageInputSelector();

protected override string Extension => "png";

public override IEnumerable<RecorderInputSettings> InputsSettings
{
get { yield return imageInputSelector.Selected; }
}

public BigImageRecorderSettings()
{
FileNameGenerator.FileName = $"image_{DefaultWildcard.Frame}";
}
}
}
11 changes: 11 additions & 0 deletions Editor/BigImageRecorderSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "com.matthewminer.bigimagerecorder",
"displayName": "Big Image Recorder",
"version": "0.0.1",
"unity": "2020.3",
"description": "Recorder to capture image sequences that exceed Unity's maximum texture size.",
"dependencies": {
"com.unity.recorder": "2.5.0"
}
}
7 changes: 7 additions & 0 deletions package.json.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit baece27

Please sign in to comment.