浏览代码

Base Work on Simplification

/main
Thomas ICHÉ 5 年前
当前提交
80ab0699
共有 50 个文件被更改,包括 545 次插入671 次删除
  1. 4
      ImageSequencer/Editor/Attributes/ProcessorAttribute.cs
  2. 3
      ImageSequencer/Editor/FilterPopup/ProcessorDataProvider.cs
  3. 139
      ImageSequencer/Editor/FrameProcessor.cs
  4. 5
      ImageSequencer/Editor/FrameProcessorStack.Serialization.cs
  5. 18
      ImageSequencer/Editor/FrameProcessorStack.cs
  6. 2
      ImageSequencer/Editor/ImageSequenceAssetEditor.cs
  7. 1
      ImageSequencer/Editor/ImageSequencerCanvas.cs
  8. 2
      ImageSequencer/Editor/Serialization/ImageSequence.cs
  9. 10
      ImageSequencer/Editor/Serialization/ProcessorInfo.cs
  10. 28
      ImageSequencer/Editor/Serialization/ProcessorBase.cs
  11. 317
      ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs
  12. 109
      ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs
  13. 17
      ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessorSettings.cs
  14. 12
      ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessorSettings.cs.meta
  15. 25
      ImageSequencer/Editor/Serialization/Processors/AssembleProcessorSettings.cs
  16. 16
      ImageSequencer/Editor/Serialization/Processors/BreakFilpbookProcessorSettings.cs
  17. 32
      ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessorSettings.cs
  18. 12
      ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessorSettings.cs.meta
  19. 23
      ImageSequencer/Editor/Serialization/Processors/CropProcessorSettings.cs
  20. 12
      ImageSequencer/Editor/Serialization/Processors/CropProcessorSettings.cs.meta
  21. 15
      ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessorSettings.cs
  22. 12
      ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessorSettings.cs.meta
  23. 12
      ImageSequencer/Editor/Serialization/Processors/DecimateProcessorSettings.cs.meta
  24. 17
      ImageSequencer/Editor/Serialization/Processors/FadeProcessorSettings.cs
  25. 12
      ImageSequencer/Editor/Serialization/Processors/FadeProcessorSettings.cs.meta
  26. 12
      ImageSequencer/Editor/Serialization/Processors/FixBordersProcessorSettings.cs.meta
  27. 12
      ImageSequencer/Editor/Serialization/Processors/LoopingProcessorSettings.cs.meta
  28. 12
      ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessorSettings.cs.meta
  29. 12
      ImageSequencer/Editor/Serialization/Processors/RemapColorProcessorSettings.cs.meta
  30. 12
      ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundSettings.cs.meta
  31. 12
      ImageSequencer/Editor/Serialization/Processors/ResizeProcessorSettings.cs.meta
  32. 12
      ImageSequencer/Editor/Serialization/Processors/RetimeProcessorSettings.cs.meta
  33. 12
      ImageSequencer/Editor/Serialization/Processors/RotateProcessorSettings.cs.meta
  34. 15
      ImageSequencer/Editor/Serialization/Processors/DecimateProcessorSettings.cs
  35. 23
      ImageSequencer/Editor/Serialization/Processors/FixBordersProcessorSettings.cs
  36. 19
      ImageSequencer/Editor/Serialization/Processors/LoopingProcessorSettings.cs
  37. 15
      ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessorSettings.cs
  38. 35
      ImageSequencer/Editor/Serialization/Processors/RemapColorProcessorSettings.cs
  39. 15
      ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundSettings.cs
  40. 16
      ImageSequencer/Editor/Serialization/Processors/ResizeProcessorSettings.cs
  41. 19
      ImageSequencer/Editor/Serialization/Processors/RetimeProcessorSettings.cs
  42. 22
      ImageSequencer/Editor/Serialization/Processors/RotateProcessorSettings.cs
  43. 11
      ImageSequencer/Editor/Serialization/ProcessorSettingsBase.cs
  44. 54
      ImageSequencer/Editor/GPUFrameProcessor.cs
  45. 12
      ImageSequencer/Editor/GPUFrameProcessor.cs.meta
  46. 9
      ImageSequencer/Editor/Processors.meta
  47. 0
      /ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs.meta
  48. 0
      /ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs.meta
  49. 0
      /ImageSequencer/Editor/Serialization/ProcessorBase.cs.meta

4
ImageSequencer/Editor/Attributes/ProcessorAttribute.cs


{
public readonly string category;
public readonly string name;
public readonly Type processorType;
public ProcessorAttribute(string category, string name, Type processorType)
public ProcessorAttribute(string category, string name)
this.processorType = processorType;
}
}
}

3
ImageSequencer/Editor/FilterPopup/ProcessorDataProvider.cs


// Reflection Stuff here
ProcessorAttribute attribute = m_processorStack.settingsDefinitions[settingType];
Type processorType = attribute.processorType;
processor = (FrameProcessor)Activator.CreateInstance(processorType, m_processorStack, info);
processor = (FrameProcessor)Activator.CreateInstance(typeof(FrameProcessor), m_processorStack, info);
if(processor != null)
{

139
ImageSequencer/Editor/FrameProcessor.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
internal abstract class FrameProcessor
internal class FrameProcessor
{
public int OutputWidth
{

{
get {
if (Enabled)
return GetNumU();
return m_Processor.GetNumU(this);
else
return InputSequence.numU;
}

get {
if (Enabled)
return GetNumV();
return m_Processor.GetNumV(this);
else
return InputSequence.numV;
}

protected int m_OutputWidth;
protected int m_OutputHeight;
protected ProcessorInfo m_ProcessorInfo;
public ProcessorBase settings { get { return m_Processor; } private set { m_Processor = value; m_SerializedObject = new SerializedObject(m_Processor); } }
private SerializedObject m_SerializedObject;
private ProcessorBase m_Processor;
private ProcessorInfo m_ProcessorInfo;
public Shader shader { get; private set; }
public Material material { get; private set; }
m_ProcessorInfo.ProcessorName = GetName();
settings = m_ProcessorInfo.Settings;
shader = AssetDatabase.LoadAssetAtPath<Shader>(settings.shaderPath);
material = new Material(shader) { hideFlags = HideFlags.DontSave };
material.hideFlags = HideFlags.DontSave;
Linear = true;
GenerateMipMaps = true;
}

info.ApplyModifiedProperties();
}
public virtual void Dispose()
public void Dispose()
Material.DestroyImmediate(material);
m_OutputSequence.Dispose();
}

Enabled = m_ProcessorInfo.Enabled;
UpdateSequenceLength();
UpdateOutputSize();
}
protected virtual void UpdateOutputSize()
{
SetOutputSize(InputSequence.width, InputSequence.height);
m_Processor.UpdateOutputSize(this);
UpdateOutputSize();
m_Processor.UpdateOutputSize(this);
UpdateOutputSize();
m_Processor.UpdateOutputSize(this);
public void SetOutputSize(int width, int height)
{
if(m_OutputWidth != width || m_OutputHeight != height)

}
}
protected abstract int GetNumU();
protected abstract int GetNumV();
protected int GetNumU()
{
if (InputSequence.processor == null)
return 1;
return InputSequence.numU;
}
protected int GetNumV()
{
if (InputSequence.processor == null)
return 1;
return InputSequence.numV;
}
protected bool DrawSidePanelHeader()
{
bool bHasChanged = false;

}
return bHasChanged;
}
public bool OnSidePanelGUI(ImageSequence asset, int ProcessorIndex)
{
bool bHasChanged = DrawSidePanelHeader();
protected abstract bool DrawSidePanelContent(bool hasChanged);
using (new EditorGUI.DisabledScope(!Enabled))
{
m_SerializedObject.Update();
bHasChanged = m_Processor.OnInspectorGUI(bHasChanged, m_SerializedObject, this);
m_SerializedObject.ApplyModifiedProperties();
}
public abstract bool OnSidePanelGUI(ImageSequence asset, int ProcessorIndex);
public abstract bool OnCanvasGUI(ImageSequencerCanvas canvas);
public virtual void RequestProcessOneFrame(int currentFrame)
return bHasChanged;
}
public bool OnCanvasGUI(ImageSequencerCanvas canvas)
{
return m_Processor.OnCanvasGUI(canvas);
}
public void RequestProcessOneFrame(int currentFrame)
{
int length = OutputSequence.length;

i %= length;
}
}
public bool Process(int frame)
{
return m_Processor.Process(this, frame);
}
public abstract bool Process(int frame);
public virtual int GetProcessorSequenceLength()
public void ExecuteShaderAndDump(int outputframe, Texture mainTex)
{
ExecuteShaderAndDump(outputframe, mainTex, material);
}
public void ExecuteShaderAndDump(int outputframe, Texture mainTex, Material material)
{
RenderTexture backup = RenderTexture.active;
Graphics.Blit(mainTex, (RenderTexture)m_OutputSequence.frames[outputframe].texture, material);
RenderTexture.active = backup;
}
public int GetProcessorSequenceLength()
return InputSequence.length;
return m_Processor.GetProcessorSequenceLength(this);
}
public bool Process(ProcessingFrame frame)

}
}
public virtual void Invalidate()
public void Invalidate()
{
UpdateSequenceLength();
SetOutputSize(GetOutputWidth(), GetOutputHeight());

next.Invalidate();
}
public abstract string GetName();
public string GetName()
{
return m_Processor.processorName;
}
public virtual string GetLabel()
public string GetLabel()
return GetName();
return m_Processor.label;
}
public override string ToString()

public abstract ProcessorSettingsBase GetSettingsAbstract();
}
internal abstract class FrameProcessor<T> : FrameProcessor where T : ProcessorSettingsBase
{
public T settings { get { return m_Settings; } private set { m_Settings = value; m_SerializedObject = new SerializedObject(m_Settings); } }
private T m_Settings;
protected SerializedObject m_SerializedObject;
public FrameProcessor(FrameProcessorStack stack, ProcessorInfo info) : base(stack, info)
{
m_ProcessorInfo = info;
settings = (T)m_ProcessorInfo.Settings;
}
public override bool OnSidePanelGUI(ImageSequence asset, int ProcessorIndex)
public ProcessorBase GetSettingsAbstract()
bool bHasChanged = DrawSidePanelHeader();
using (new EditorGUI.DisabledScope(!Enabled))
{
m_SerializedObject.Update();
bHasChanged = DrawSidePanelContent(bHasChanged);
m_SerializedObject.ApplyModifiedProperties();
}
return bHasChanged;
return settings;
public sealed override ProcessorSettingsBase GetSettingsAbstract()
{
return settings;
}
}
}

5
ImageSequencer/Editor/FrameProcessorStack.Serialization.cs


AddProcessorInfoObjectToAsset(asset, processor.ProcessorInfo);
asset.processorInfos.Add(processor.ProcessorInfo);
ProcessorSettingsBase settings = processor.GetSettingsAbstract();
ProcessorBase settings = processor.GetSettingsAbstract();
if (settings != null)
{
AddSettingsObjectToAsset(asset, settings);

// Creating Runtime
foreach(ProcessorInfo procInfo in infos)
{
Type processorType = settingsDefinitions[procInfo.Settings.GetType()].processorType;
var processor = (FrameProcessor)Activator.CreateInstance(processorType, this, procInfo);
var processor = (FrameProcessor)Activator.CreateInstance(typeof(FrameProcessor), this, procInfo);
m_Processors.Add(processor);
}
}

18
ImageSequencer/Editor/FrameProcessorStack.cs


{
settingsDefinitions = new Dictionary<Type, ProcessorAttribute>();
var assembly = Assembly.GetAssembly(typeof(ProcessorSettingsBase));
var assembly = Assembly.GetAssembly(typeof(ProcessorBase));
var processorSettingsType = typeof(ProcessorSettingsBase);
var processorType = typeof(ProcessorBase);
var processorSettingTypes = types
var allProcessorTypes = types
&& t.IsSubclassOf(processorSettingsType)
&& t.IsSubclassOf(processorType)
foreach (var processorSettingType in processorSettingTypes)
foreach (var type in allProcessorTypes)
var attr = (ProcessorAttribute)processorSettingType.GetCustomAttributes(attrType, false)[0];
Type processorType = attr.processorType;
var attr = (ProcessorAttribute)type.GetCustomAttributes(attrType, false)[0];
if (!processorType.IsClass || !processorType.IsSubclassOf(typeof(FrameProcessor)) || processorType.IsAbstract)
throw new InvalidOperationException("Invalid RendererAttribute parameter, type must be a non-abstract class that extends GPUFrameProcessor<>");
settingsDefinitions.Add(processorSettingType, attr);
settingsDefinitions.Add(type, attr);
}
}

2
ImageSequencer/Editor/ImageSequenceAssetEditor.cs


for(int i = 0; i < processorsCount; i++)
{
var item = processors.GetArrayElementAtIndex(i).objectReferenceValue as ProcessorInfo;
EditorGUILayout.LabelField("#"+i+" - " + item.ProcessorName + (item.Enabled?"":" (Disabled)"));
EditorGUILayout.LabelField("#"+i+" - " + item.Settings.label + (item.Enabled?"":" (Disabled)"));
}
EditorGUI.indentLevel--;
}

1
ImageSequencer/Editor/ImageSequencerCanvas.cs


{
internal class ImageSequencerCanvas : VFXToolboxCanvas
{
public bool showExtraInfo
{
get

2
ImageSequencer/Editor/Serialization/ImageSequence.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[HelpURL("https://drive.google.com/open?id=1YUwzA1mGvzWRpajDV-XF0iUd4RhW--bhMpqo-gmj9B8")]
public class ImageSequence : ScriptableObject
internal class ImageSequence : ScriptableObject
{
public List<string> inputFrameGUIDs = new List<string>();
public List<ProcessorInfo> processorInfos = new List<ProcessorInfo>();

10
ImageSequencer/Editor/Serialization/ProcessorInfo.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
public class ProcessorInfo : ScriptableObject
internal class ProcessorInfo : ScriptableObject
public string ProcessorName;
public ProcessorSettingsBase Settings;
public ProcessorBase Settings;
p.ProcessorName = name;
p.Settings = ScriptableObject.CreateInstance(type) as ProcessorSettingsBase;
p.Settings = ScriptableObject.CreateInstance(type) as ProcessorBase;
p.Settings.Default();
return p;
}

return ProcessorName + (Enabled ? "" : "Disabled") ;
return Settings.label + (Enabled ? "" : "Disabled") ;
}
}

28
ImageSequencer/Editor/Serialization/ProcessorBase.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
internal abstract class ProcessorBase : ScriptableObject
{
public abstract string shaderPath { get; }
public abstract string processorName { get; }
public virtual string label => processorName;
public virtual int GetNumU(FrameProcessor processor) => 1;
public virtual int GetNumV(FrameProcessor processor) => 1;
public abstract bool Process(FrameProcessor processor, int frame);
public virtual void UpdateOutputSize(FrameProcessor processor)
{
processor.SetOutputSize(processor.InputSequence.width, processor.InputSequence.height);
}
public abstract int GetProcessorSequenceLength(FrameProcessor processor);
public abstract bool OnInspectorGUI(bool changed, SerializedObject serializedObject, FrameProcessor processor);
public abstract bool OnCanvasGUI(ImageSequencerCanvas canvas);
public abstract void Default();
}
}

317
ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs


using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Texture Sheet", "Assemble Flipbook")]
internal class AssembleProcessor : ProcessorBase
{
public enum AssembleMode
{
FullSpriteSheet = 0,
VerticalSequence = 1
}
public int FlipbookNumU;
public int FlipbookNumV;
public AssembleMode Mode;
public override string shaderPath => "Packages/com.unity.vfx-toolbox/ImageSequencer/Editor/Shaders/AssembleBlit.shader";
public override string processorName => "Assemble Flipbook";
public override string label
{
get
{
string numU = (Mode == AssembleMode.VerticalSequence) ? "*" : FlipbookNumU.ToString();
string numV = FlipbookNumV.ToString();
return $"{processorName} ({numU}x{numV})";
}
}
public override void Default()
{
FlipbookNumU = 5;
FlipbookNumV = 5;
Mode = AssembleMode.FullSpriteSheet;
}
public override void UpdateOutputSize(FrameProcessor processor)
{
switch (Mode)
{
case AssembleMode.FullSpriteSheet:
processor.SetOutputSize(processor.InputSequence.width * FlipbookNumU, processor.InputSequence.height * FlipbookNumV);
break;
case AssembleMode.VerticalSequence:
processor.SetOutputSize(processor.InputSequence.width, processor.InputSequence.height * FlipbookNumV);
break;
}
}
public override int GetProcessorSequenceLength(FrameProcessor processor)
{
switch (Mode)
{
default:
case AssembleMode.FullSpriteSheet:
return 1;
case AssembleMode.VerticalSequence:
return processor.InputSequence.length / FlipbookNumV;
}
}
public override bool OnCanvasGUI(ImageSequencerCanvas canvas)
{
if (Event.current.type != EventType.Repaint)
return false;
Vector2 topRight;
Vector2 bottomLeft;
topRight = canvas.CanvasToScreen(new Vector2(-canvas.currentFrame.texture.width / 2, canvas.currentFrame.texture.height / 2));
bottomLeft = canvas.CanvasToScreen(new Vector2(canvas.currentFrame.texture.width / 2, -canvas.currentFrame.texture.height / 2));
// Texts
GUI.color = canvas.styles.green;
for (int i = 0; i < FlipbookNumU; i++)
{
float cw = (topRight.x - bottomLeft.x) / FlipbookNumU;
GUI.Label(new Rect(bottomLeft.x + i * cw, topRight.y - 16, cw, 16), (i + 1).ToString(), canvas.styles.miniLabelCenter);
}
for (int i = 0; i < FlipbookNumV; i++)
{
float ch = (bottomLeft.y - topRight.y) / FlipbookNumV;
VFXToolboxGUIUtility.GUIRotatedLabel(new Rect(bottomLeft.x - 8, topRight.y + i * ch, 16, ch), (i + 1).ToString(), -90.0f, canvas.styles.miniLabelCenter);
}
GUI.color = Color.white;
return false;
}
public override int GetNumU(FrameProcessor processor)
{
switch (Mode)
{
default:
case AssembleMode.FullSpriteSheet:
return FlipbookNumU * processor.InputSequence.numU;
case AssembleMode.VerticalSequence:
return processor.InputSequence.numU;
}
}
public override int GetNumV(FrameProcessor processor)
{
return FlipbookNumV * processor.InputSequence.numV;
}
public override bool Process(FrameProcessor processor, int frame)
{
int length = processor.InputSequence.length;
RenderTexture backup = RenderTexture.active;
switch (Mode)
{
case AssembleMode.FullSpriteSheet:
// Blit Every Image inside output
for (int i = 0; i < (FlipbookNumU * FlipbookNumV); i++)
{
int u = i % FlipbookNumU;
int v = (FlipbookNumV - 1) - (int)Mathf.Floor((float)i / FlipbookNumU);
Vector2 size = new Vector2(1.0f / FlipbookNumU, 1.0f / FlipbookNumV);
int idx = Mathf.Clamp(i, 0, length - 1);
Texture currentTexture = processor.InputSequence.RequestFrame(idx).texture;
Vector4 ClipCoordinates = new Vector4(u * size.x, v * size.y, size.x, size.y);
processor.material.SetTexture("_MainTex", currentTexture);
processor.material.SetVector("_CC", ClipCoordinates);
Graphics.Blit(currentTexture, (RenderTexture)processor.OutputSequence.frames[0].texture, processor.material);
}
RenderTexture.active = backup;
break;
case AssembleMode.VerticalSequence:
// Blit Every N'th Image inside output
int cycleLength = processor.InputSequence.length / FlipbookNumV;
for (int i = 0; i < FlipbookNumV; i++)
{
int u = 0;
int v = FlipbookNumV - 1 - i;
Vector2 size = new Vector2(1.0f, 1.0f / FlipbookNumV);
int idx = Mathf.Clamp((i * cycleLength) + frame, 0, length - 1);
Texture currentTexture = processor.InputSequence.RequestFrame(idx).texture;
Vector4 ClipCoordinates = new Vector4(u * size.x, v * size.y, size.x, size.y);
processor.material.SetTexture("_MainTex", currentTexture);
processor.material.SetVector("_CC", ClipCoordinates);
Graphics.Blit(currentTexture, (RenderTexture)processor.OutputSequence.frames[frame].texture, processor.material);
}
RenderTexture.active = backup;
break;
}
return true;
}
bool hasChanged = false;
public override bool OnInspectorGUI(bool changed, SerializedObject serializedObject, FrameProcessor processor)
{
var flipbookNumU = serializedObject.FindProperty("FlipbookNumU");
var flipbookNumV = serializedObject.FindProperty("FlipbookNumV");
var mode = serializedObject.FindProperty("Mode");
var assembleMode = (AssembleMode)mode.intValue;
EditorGUI.BeginChangeCheck();
assembleMode = (AssembleMode)EditorGUILayout.EnumPopup(VFXToolboxGUIUtility.Get("Assemble Mode"), assembleMode);
if (assembleMode != (AssembleMode)mode.intValue)
{
mode.intValue = (int)assembleMode;
hasChanged = true;
}
switch (assembleMode)
{
case AssembleMode.FullSpriteSheet:
int newU = EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Columns (U) : "), flipbookNumU.intValue);
int newV = EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue);
if (processor.InputSequence.length > 0)
{
using (new GUILayout.HorizontalScope())
{
GUILayout.Label(VFXToolboxGUIUtility.Get("Find Best Ratios"), GUILayout.Width(EditorGUIUtility.labelWidth));
if (GUILayout.Button(VFXToolboxGUIUtility.Get("Get")))
{
float frameRatio = (float)processor.InputSequence.frames[0].texture.width / (float)processor.InputSequence.frames[0].texture.height;
int length = processor.InputSequence.frames.Count;
List<int> ratios = new List<int>();
SortedDictionary<int, float> coeffs = new SortedDictionary<int, float>();
float rad = Mathf.Sqrt(length);
for (int i = (int)rad; i >= 1; i--)
{
if (((float)length / (float)i) % 1.0f == 0.0f)
{
float pageRatio = (float)i / (length / i);
float fullRatio = frameRatio * pageRatio;
float divergence = Mathf.Abs(Mathf.Log(fullRatio, 2.0f) % 1.0f);
if (!ratios.Contains(i))
{
ratios.Add(i);
coeffs.Add(i, divergence);
}
fullRatio = frameRatio / pageRatio;
divergence = Mathf.Abs(Mathf.Log(fullRatio, 2.0f) % 1.0f);
if (!ratios.Contains(length / i))
{
ratios.Add(length / i);
coeffs.Add((length / i), divergence);
}
}
}
GenericMenu menu = new GenericMenu();
var sortedValues = coeffs.OrderBy(kvp => kvp.Value);
foreach (KeyValuePair<int, float> kvp in sortedValues)
{
int value = kvp.Key;
menu.AddItem(new GUIContent(value + " x " + (length / value) + ((kvp.Value == 0.0f) ? " (PERFECT)" : "")), false,
(o) => {
var seq_length = processor.InputSequence.length;
var seq_numU = (int)o;
var seq_numV = seq_length / seq_numU;
serializedObject.Update();
var seq_flipbookNumU = serializedObject.FindProperty("FlipbookNumU");
var seq_flipbookNumV = serializedObject.FindProperty("FlipbookNumV");
seq_flipbookNumU.intValue = seq_numU;
seq_flipbookNumV.intValue = seq_numV;
serializedObject.ApplyModifiedProperties();
UpdateOutputSize(processor);
processor.Invalidate();
}
, value);
}
if (menu.GetItemCount() > 0)
menu.ShowAsContext();
}
}
EditorGUILayout.HelpBox("Find Best Ratios will try to find matching possibilities for the current sequence, ordered by ratio pertinence, meaning that first results will have less stretch when resized to power-of-two textures.", MessageType.Info);
}
if (newU != flipbookNumU.intValue)
{
newU = Mathf.Clamp(newU, 1, processor.InputSequence.length / newV);
flipbookNumU.intValue = newU;
}
if (newV != flipbookNumV.intValue)
{
newV = Mathf.Clamp(newV, 1, processor.InputSequence.length / newU);
flipbookNumV.intValue = newV;
}
break;
case AssembleMode.VerticalSequence:
int numRows = EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue);
if (numRows != flipbookNumV.intValue)
{
numRows = Mathf.Clamp(numRows, 1, processor.InputSequence.length);
flipbookNumV.intValue = numRows;
}
break;
}
if (EditorGUI.EndChangeCheck())
{
UpdateOutputSize(processor);
processor.Invalidate();
hasChanged = true;
}
return hasChanged;
}
}
}

109
ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Texture Sheet", "Break Flipbook")]
internal class BreakFlipbookProcessor : ProcessorBase
{
public int FlipbookNumU;
public int FlipbookNumV;
public override string shaderPath => "Packages/com.unity.vfx-toolbox/ImageSequencer/Editor/Shaders/GetSubUV.shader";
public override string processorName => "Break Flipbook";
public override string label => $"{name} ({FlipbookNumU}x{FlipbookNumV}): {FlipbookNumU * FlipbookNumV} frame(s).";
private bool m_BypassSecurityCheck = false;
public override void Default()
{
FlipbookNumU = 5;
FlipbookNumV = 5;
}
public override void UpdateOutputSize(FrameProcessor processor)
{
int width = (int)Mathf.Ceil((float)processor.InputSequence.RequestFrame(0).texture.width / FlipbookNumU);
int height = (int)Mathf.Ceil((float)processor.InputSequence.RequestFrame(0).texture.height / FlipbookNumV);
processor.SetOutputSize(width, height);
}
public override int GetProcessorSequenceLength(FrameProcessor processor)
{
return Mathf.Min(FlipbookNumU, processor.InputSequence.width) * Mathf.Min(FlipbookNumV, processor.InputSequence.height);
}
public override bool OnCanvasGUI(ImageSequencerCanvas canvas)
{
return false;
}
public override bool Process(FrameProcessor processor, int frame)
{
Texture texture = processor.InputSequence.RequestFrame(0).texture;
processor.material.SetTexture("_MainTex", texture);
Vector4 rect = new Vector4();
int u = Mathf.Min(FlipbookNumU, texture.width);
int v = Mathf.Min(FlipbookNumV, texture.height);
int x = frame % FlipbookNumU;
int y = (int)Mathf.Floor((float)frame / u);
rect.x = (float)x;
rect.y = (float)(v - 1) - y;
rect.z = 1.0f / u;
rect.w = 1.0f / v;
processor.material.SetVector("_Rect", rect);
processor.ExecuteShaderAndDump(frame, texture);
return true;
}
public override bool OnInspectorGUI(bool hasChanged, SerializedObject serializedObject, FrameProcessor processor)
{
var flipbookNumU = serializedObject.FindProperty("FlipbookNumU");
var flipbookNumV = serializedObject.FindProperty("FlipbookNumV");
EditorGUI.BeginChangeCheck();
int newU = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Columns (U) : "), flipbookNumU.intValue), 1, processor.InputSequence.width);
int newV = Mathf.Clamp(EditorGUILayout.IntField(VFXToolboxGUIUtility.Get("Rows (V) : "), flipbookNumV.intValue), 1, processor.InputSequence.height);
if (newU != flipbookNumU.intValue || flipbookNumV.intValue != newV)
GUI.changed = true;
if (m_BypassSecurityCheck)
EditorGUILayout.HelpBox("Warning: you are currently bypassing frame count limits. Proceed with caution when entering values, as it can take a long time to process and stall your editor.", MessageType.Warning);
if (EditorGUI.EndChangeCheck())
{
Debug.Log("Updated");
if (newU * newV <= 4096)
{
flipbookNumU.intValue = newU;
flipbookNumV.intValue = newV;
}
else
{
if (!m_BypassSecurityCheck && EditorUtility.DisplayDialog("VFX Toolbox", "CAUTION : You are going to generate a sequence of " + newU * newV + " frames. This could take a long time to process, stall your editor, and consume a large amount of memory. Are you SURE you want to Continue?", "I know what I am doing, proceed", "Cancel"))
m_BypassSecurityCheck = true;
if (m_BypassSecurityCheck)
{
flipbookNumU.intValue = newU;
flipbookNumV.intValue = newV;
}
}
processor.Invalidate();
hasChanged = true;
}
return hasChanged;
}
}
}

17
ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Alpha From RGB", typeof(AlphaFromRGBProcessor))]
public class AlphaFromRGBProcessorSettings : ProcessorSettingsBase
{
public Color BWFilterTint;
//public Vector3 Weights;
public override void Default()
{
BWFilterTint = Color.white;
//Weights = new Vector3(0.2126f, 0.7152f, 0.0722f);
}
}
}

12
ImageSequencer/Editor/Serialization/Processors/AlphaFromRGBProcessorSettings.cs.meta


fileFormatVersion: 2
guid: fa620cc053ad857459f8451c2f9f2823
timeCreated: 1474881116
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
ImageSequencer/Editor/Serialization/Processors/AssembleProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Texture Sheet","Assemble Flipbook", typeof(AssembleProcessor))]
public class AssembleProcessorSettings : ProcessorSettingsBase
{
public enum AssembleMode
{
FullSpriteSheet = 0,
VerticalSequence = 1
}
public int FlipbookNumU;
public int FlipbookNumV;
public AssembleMode Mode;
public override void Default()
{
FlipbookNumU = 5;
FlipbookNumV = 5;
Mode = AssembleMode.FullSpriteSheet;
}
}
}

16
ImageSequencer/Editor/Serialization/Processors/BreakFilpbookProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Texture Sheet","Break Flipbook", typeof(BreakFlipbookProcessor))]
public class BreakFilpbookProcessorSettings : ProcessorSettingsBase
{
public int FlipbookNumU;
public int FlipbookNumV;
public override void Default()
{
FlipbookNumU = 5;
FlipbookNumV = 5;
}
}
}

32
ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessorSettings.cs


using UnityEngine;
using UnityEngine.VFXToolbox;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Color Correction", typeof(ColorCorrectionProcessor))]
public class ColorCorrectionProcessorSettings : ProcessorSettingsBase
{
[FloatSlider(0.0f,2.0f)]
public float Brightness;
[FloatSlider(0.0f,2.0f)]
public float Contrast;
[FloatSlider(0.0f,2.0f)]
public float Saturation;
public AnimationCurve AlphaCurve;
public override void Default()
{
Brightness = 1.0f;
Contrast = 1.0f;
Saturation = 1.0f;
DefaultCurve();
}
public void DefaultCurve()
{
AlphaCurve = AnimationCurve.Linear(0, 0, 1, 1);
}
}
}

12
ImageSequencer/Editor/Serialization/Processors/ColorCorrectionProcessorSettings.cs.meta


fileFormatVersion: 2
guid: a3ca7dec4216fca4f943c6c73a5f5819
timeCreated: 1471449594
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

23
ImageSequencer/Editor/Serialization/Processors/CropProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Crop", typeof(CropProcessor))]
public class CropProcessorSettings : ProcessorSettingsBase
{
public uint Crop_Top;
public uint Crop_Bottom;
public uint Crop_Left;
public uint Crop_Right;
public float AutoCropThreshold = 0.003f;
public override void Default()
{
Crop_Top = 0;
Crop_Bottom = 0;
Crop_Left = 0;
Crop_Right = 0;
AutoCropThreshold = 0.003f;
}
}
}

12
ImageSequencer/Editor/Serialization/Processors/CropProcessorSettings.cs.meta


fileFormatVersion: 2
guid: ffd658e7a2564734aaef1a1eddf45e1a
timeCreated: 1464881358
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("","Custom Material", typeof(CustomMaterialProcessor))]
public class CustomMaterialProcessorSettings : ProcessorSettingsBase
{
public Material material;
public override void Default()
{
material = null;
}
}
}

12
ImageSequencer/Editor/Serialization/Processors/CustomMaterialProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 05487723e0bf7674d8819359ce0d8fdc
timeCreated: 1478610071
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/DecimateProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 35539f9025900914e96e7eb931166504
timeCreated: 1465476802
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

17
ImageSequencer/Editor/Serialization/Processors/FadeProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Fade", typeof(FadeProcessor))]
public class FadeProcessorSettings : ProcessorSettingsBase
{
public AnimationCurve FadeCurve;
public Color FadeToColor;
public override void Default()
{
FadeCurve = new AnimationCurve();
FadeToColor = new Color(0.25f,0.25f,0.25f,0.0f);
}
}
}

12
ImageSequencer/Editor/Serialization/Processors/FadeProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 4cecbc83322782040aa2e239d6bb99be
timeCreated: 1464795182
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/FixBordersProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 524ca2e5a7796534ab1f8dc4bd20c436
timeCreated: 1465982250
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/LoopingProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 0af546431c1df1e4cbb10dcd3b8c8e73
timeCreated: 1463757012
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessorSettings.cs.meta


fileFormatVersion: 2
guid: a5e0ec12414f668468843340c4ea49d5
timeCreated: 1471447757
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/RemapColorProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 94fe7c5309b5be14584db469f32df97c
timeCreated: 1474890317
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundSettings.cs.meta


fileFormatVersion: 2
guid: ba009c82a545a464986d0e411726f3a9
timeCreated: 1465487664
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/ResizeProcessorSettings.cs.meta


fileFormatVersion: 2
guid: ba984ba4af4e5884b8c8e887abee8051
timeCreated: 1464771182
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/RetimeProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 67121233fc1872a4e9b4d2c8f5fc6542
timeCreated: 1463757012
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

12
ImageSequencer/Editor/Serialization/Processors/RotateProcessorSettings.cs.meta


fileFormatVersion: 2
guid: 74b10a87cbc48a5458e7ebe6abc6b861
timeCreated: 1464879392
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

15
ImageSequencer/Editor/Serialization/Processors/DecimateProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Decimate", typeof(DecimateProcessor))]
class DecimateProcessorSettings : ProcessorSettingsBase
{
public ushort DecimateBy;
public override void Default()
{
DecimateBy = 3;
}
}
}

23
ImageSequencer/Editor/Serialization/Processors/FixBordersProcessorSettings.cs


using UnityEngine;
using UnityEngine.VFXToolbox;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Fix Borders", typeof(FixBordersProcessor))]
class FixBordersProcessorSettings : ProcessorSettingsBase
{
public Vector4 FixFactors;
public Color FadeToColor;
public float FadeToAlpha;
[FloatSlider(0.5f,4.0f)]
public float Exponent;
public override void Default()
{
FixFactors = Vector4.zero;
FadeToColor = new Color(0.0f, 0.0f, 0.0f, 0.0f);
FadeToAlpha = 0.0f;
Exponent = 1.5f;
}
}
}

19
ImageSequencer/Editor/Serialization/Processors/LoopingProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Loop Sequence", typeof(LoopingProcessor))]
class LoopingProcessorSettings : ProcessorSettingsBase
{
public AnimationCurve curve;
public int syncFrame;
public int outputSequenceLength;
public override void Default()
{
curve = new AnimationCurve();
syncFrame = 25;
outputSequenceLength = 25;
}
}
}

15
ImageSequencer/Editor/Serialization/Processors/PremultiplyAlphaProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Premultiply Alpha", typeof(PremultiplyAlphaProcessor))]
class PremultiplyAlphaProcessorSettings : ProcessorSettingsBase
{
public bool RemoveAlpha;
public float AlphaValue;
public override void Default()
{
RemoveAlpha = false;
AlphaValue = 1.0f;
}
}
}

35
ImageSequencer/Editor/Serialization/Processors/RemapColorProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Remap Color", typeof(RemapColorProcessor))]
class RemapColorProcessorSettings : ProcessorSettingsBase
{
public enum RemapColorSource
{
sRGBLuminance = 0,
LinearRGBLuminance = 1,
Alpha = 2,
LinearR = 3,
LinearG = 4,
LinearB = 5
}
public Gradient Gradient;
public RemapColorSource ColorSource;
public override void Default()
{
ColorSource = RemapColorSource.sRGBLuminance;
DefaultGradient();
}
public void DefaultGradient()
{
Gradient = new Gradient();
GradientColorKey[] colors = new GradientColorKey[2] { new GradientColorKey(Color.black, 0),new GradientColorKey(Color.white, 1) };
GradientAlphaKey[] alpha = new GradientAlphaKey[2] { new GradientAlphaKey(0,0), new GradientAlphaKey(1,1) };
Gradient.SetKeys(colors, alpha);
}
}
}

15
ImageSequencer/Editor/Serialization/Processors/RemoveBackgroundSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Color","Remove Background", typeof(RemoveBackgroundBlendingProcessor))]
class RemoveBackgroundSettings : ProcessorSettingsBase
{
public Color BackgroundColor;
public override void Default()
{
BackgroundColor = new Color(0.25f,0.25f,0.25f,0.0f);
}
}
}

16
ImageSequencer/Editor/Serialization/Processors/ResizeProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Resize", typeof(ResizeProcessor))]
class ResizeProcessorSettings : ProcessorSettingsBase
{
public ushort Width;
public ushort Height;
public override void Default()
{
Width = 256;
Height = 256;
}
}
}

19
ImageSequencer/Editor/Serialization/Processors/RetimeProcessorSettings.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Retime", typeof(RetimeProcessor))]
class RetimeProcessorSettings : ProcessorSettingsBase
{
public AnimationCurve curve;
public int outputSequenceLength;
public bool useCurve;
public override void Default()
{
curve = new AnimationCurve();
outputSequenceLength = 25;
useCurve = true;
}
}
}

22
ImageSequencer/Editor/Serialization/Processors/RotateProcessorSettings.cs


namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Common","Rotate", typeof(RotateProcessor))]
class RotateProcessorSettings : ProcessorSettingsBase
{
public enum RotateMode
{
None = 0,
Rotate90 = 1,
Rotate180 = 2,
Rotate270 = 3
}
public RotateMode FrameRotateMode;
public override void Default()
{
FrameRotateMode = 0;
}
}
}

11
ImageSequencer/Editor/Serialization/ProcessorSettingsBase.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
public abstract class ProcessorSettingsBase : ScriptableObject
{
public abstract void Default();
}
}

54
ImageSequencer/Editor/GPUFrameProcessor.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
internal abstract class GPUFrameProcessor<T> : FrameProcessor<T> where T : ProcessorSettingsBase
{
protected Shader m_Shader;
protected Material m_Material;
public GPUFrameProcessor(string shaderPath, FrameProcessorStack processorStack, ProcessorInfo info )
: this(AssetDatabase.LoadAssetAtPath<Shader>(shaderPath),processorStack, info)
{ }
public GPUFrameProcessor(Shader shader, FrameProcessorStack processorStack, ProcessorInfo info ) : base(processorStack, info)
{
m_Shader = shader;
m_Material = new Material(m_Shader) { hideFlags = HideFlags.DontSave };
m_Material.hideFlags = HideFlags.DontSave;
}
public void ExecuteShaderAndDump(int outputframe, Texture mainTex)
{
ExecuteShaderAndDump(outputframe, mainTex, m_Material);
}
public void ExecuteShaderAndDump(int outputframe, Texture mainTex, Material material)
{
RenderTexture backup = RenderTexture.active;
Graphics.Blit(mainTex, (RenderTexture)m_OutputSequence.frames[outputframe].texture, material);
RenderTexture.active = backup;
}
public override void Dispose()
{
Material.DestroyImmediate(m_Material);
base.Dispose();
}
protected override int GetNumU()
{
if (InputSequence.processor == null)
return 1;
return InputSequence.numU;
}
protected override int GetNumV()
{
if (InputSequence.processor == null)
return 1;
return InputSequence.numV;
}
}
}

12
ImageSequencer/Editor/GPUFrameProcessor.cs.meta


fileFormatVersion: 2
guid: a00044f5e3e7b924e925a45bcb585727
timeCreated: 1461162132
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
ImageSequencer/Editor/Processors.meta


fileFormatVersion: 2
guid: ea5d7b44dca491240a1a52832e86c71e
folderAsset: yes
timeCreated: 1461139447
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

/ImageSequencer/Editor/Serialization/Processors/AssembleProcessorSettings.cs.meta → /ImageSequencer/Editor/Serialization/Processors/AssembleProcessor.cs.meta

/ImageSequencer/Editor/Serialization/Processors/BreakFilpbookProcessorSettings.cs.meta → /ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs.meta

/ImageSequencer/Editor/Serialization/ProcessorSettingsBase.cs.meta → /ImageSequencer/Editor/Serialization/ProcessorBase.cs.meta

正在加载...
取消
保存