浏览代码

Simplified/Renamed/Set Private + Added Retime Processor (+ Preview fetch functions)

/main
Thomas ICHÉ 5 年前
当前提交
c1233c37
共有 5 个文件被更改,包括 169 次插入12 次删除
  1. 24
      ImageSequencer/Editor/FrameProcessor.cs
  2. 2
      ImageSequencer/Editor/Serialization/Processors/BreakFlipbookProcessor.cs
  3. 2
      ImageSequencer/Editor/Serialization/Processors/DecimateProcessor.cs
  4. 141
      ImageSequencer/Editor/Serialization/Processors/RetimeProcessor.cs
  5. 12
      ImageSequencer/Editor/Serialization/Processors/RetimeProcessor.cs.meta

24
ImageSequencer/Editor/FrameProcessor.cs


get { return m_ProcessorInfo; }
}
protected FrameProcessorStack m_ProcessorStack;
protected ProcessingFrameSequence m_OutputSequence;
private FrameProcessorStack m_ProcessorStack;
private ProcessingFrameSequence m_OutputSequence;
protected bool m_bEnabled;
private bool m_bEnabled;
protected int m_OutputWidth;
protected int m_OutputHeight;
private int m_OutputWidth;
private int m_OutputHeight;
public ProcessorBase settings { get { return m_Processor; } private set { m_Processor = value; m_SerializedObject = new SerializedObject(m_Processor); } }
public ProcessorBase processor { get { return m_Processor; } private set { m_Processor = value; m_SerializedObject = new SerializedObject(m_Processor); } }
private SerializedObject m_SerializedObject;
private ProcessorBase m_Processor;

public bool isCurrentlyPreviewed => m_ProcessorStack.imageSequencer.previewCanvas.sequence.processor == this;
public int currentPreviewFrame => m_ProcessorStack.imageSequencer.previewCanvas.currentFrameIndex;
public int currentPreviewSequenceLength => m_ProcessorStack.imageSequencer.previewCanvas.numFrames;
settings = m_ProcessorInfo.Settings;
processor = m_ProcessorInfo.Settings;
shader = AssetDatabase.LoadAssetAtPath<Shader>(settings.shaderPath);
shader = AssetDatabase.LoadAssetAtPath<Shader>(processor.shaderPath);
material = new Material(shader) { hideFlags = HideFlags.DontSave };
material.hideFlags = HideFlags.DontSave;

settings.AttachTo(this);
processor.AttachTo(this);
}
public void SetEnabled(bool value)

}
public ProcessorBase GetSettingsAbstract()
{
return settings;
return processor;
}
}

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


public override string processorName => "Break Flipbook";
public override string label => $"{name} ({FlipbookNumU}x{FlipbookNumV}): {FlipbookNumU * FlipbookNumV} frame(s).";
public override string label => $"{processorName} ({FlipbookNumU}x{FlipbookNumV}): {FlipbookNumU * FlipbookNumV} frame(s).";
private bool m_BypassSecurityCheck = false;

2
ImageSequencer/Editor/Serialization/Processors/DecimateProcessor.cs


public override string shaderPath => "Packages/com.unity.vfx-toolbox/ImageSequencer/Editor/Shaders/Null.shader";
public override string label => $"{name} (1 of {DecimateBy})";
public override string label => $"{processorName} (1 of {DecimateBy})";
public override string processorName => "Decimate";

141
ImageSequencer/Editor/Serialization/Processors/RetimeProcessor.cs


using UnityEngine;
namespace UnityEditor.VFXToolbox.ImageSequencer
{
[Processor("Sequence","Retime")]
class RetimeProcessor : ProcessorBase
{
public AnimationCurve curve;
public int outputSequenceLength;
public bool useCurve;
public override string shaderPath => "Packages/com.unity.vfx-toolbox/ImageSequencer/Editor/Shaders/Blend.shader";
public override string processorName => "Retime";
public override string label => $"{processorName} ({outputSequenceLength} frames)";
public override int sequenceLength
{
get
{
if (processor.InputSequence.length > 0)
return outputSequenceLength;
else
return 0;
}
}
public override void Default()
{
curve = new AnimationCurve();
curve.AddKey(new Keyframe(0, 0));
curve.AddKey(new Keyframe(1, 24));
outputSequenceLength = 25;
useCurve = true;
}
public override bool Process(int frame)
{
int inputlength = processor.InputSequence.length;
int outputlength = sequenceLength;
float t = (float)frame / outputlength;
float Frame;
if (useCurve)
Frame = curve.Evaluate(t);
else
Frame = t * inputlength;
float blendFactor = Frame % 1.0f;
int Prev = Mathf.Clamp((int)Mathf.Floor(Frame), 0, inputlength - 1);
int Next = Mathf.Clamp((int)Mathf.Ceil(Frame), 0, inputlength - 1);
Texture prevtex = processor.InputSequence.RequestFrame(Prev).texture;
Texture nexttex = processor.InputSequence.RequestFrame(Next).texture;
processor.material.SetTexture("_MainTex", prevtex);
processor.material.SetTexture("_AltTex", nexttex);
processor.material.SetFloat("_BlendFactor", blendFactor);
processor.ExecuteShaderAndDump(frame, prevtex);
return true;
}
CurveDrawer m_CurveDrawer;
public override bool OnInspectorGUI(bool changed, SerializedObject serializedObject)
{
if (m_CurveDrawer == null)
{
m_CurveDrawer = new CurveDrawer("Retime Curve", 0.0f, 1.0f, 0.0f, processor.InputSequence.length, 140, false);
m_CurveDrawer.AddCurve(serializedObject.FindProperty("curve"), new Color(0.5f, 0.75f, 1.0f), "Retime Curve");
m_CurveDrawer.OnPostGUI = OnCurveFieldGUI;
}
var useCurve = serializedObject.FindProperty("useCurve");
var outputSequenceLength = serializedObject.FindProperty("outputSequenceLength");
EditorGUI.BeginChangeCheck();
int length = outputSequenceLength.intValue;
int newlength = EditorGUILayout.IntSlider(VFXToolboxGUIUtility.Get("Sequence Length"), length, 1, processor.InputSequence.length);
if (newlength != length)
{
outputSequenceLength.intValue = newlength;
}
EditorGUILayout.PropertyField(useCurve, VFXToolboxGUIUtility.Get("Use Retiming Curve"));
if (useCurve.boolValue)
{
m_CurveDrawer.SetBounds(new Rect(0, 0, 1, processor.InputSequence.length - 1));
if (m_CurveDrawer.OnGUILayout())
{
changed = true;
}
}
if (EditorGUI.EndChangeCheck())
{
changed = true;
}
return changed;
}
void OnCurveFieldGUI(Rect renderArea, Rect curveArea)
{
float seqRatio = -1.0f;
if (processor.isCurrentlyPreviewed)
{
seqRatio = (processor.currentPreviewSequenceLength > 1) ? (float)processor.currentPreviewFrame / (processor.currentPreviewSequenceLength - 1) : 0.0f;
}
// If previewing current sequence : draw trackbar
if (seqRatio >= 0.0f)
{
Handles.color = Color.white;
Handles.DrawLine(new Vector3(curveArea.xMin + seqRatio * curveArea.width, renderArea.yMin), new Vector3(curveArea.xMin + seqRatio * curveArea.width, renderArea.yMax));
}
}
bool CurveEquals(AnimationCurve target)
{
for (int i = 0; i < target.keys.Length; i++)
{
if (target[i].time != curve[i].time ||
target[i].value != curve[i].value ||
target[i].inTangent != curve[i].inTangent ||
target[i].outTangent != curve[i].outTangent)
{
return false;
}
}
return true;
}
}
}

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


fileFormatVersion: 2
guid: 67121233fc1872a4e9b4d2c8f5fc6542
timeCreated: 1463757012
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存