Files
UnrealEngineUWP/Engine/Source/Editor/CurveEditor/Private/CurveEditorHelpers.cpp

122 lines
5.1 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
This is a significant overhaul to the Curve Editor used by Sequencer which adds a plugin-based architecture and extensibility. New tools and toolbar buttons can be added to all usages of the curve editor via user plugins, and the different views for data can be created modularly so new implementations of the editor can register their own way of drawing their data and the tools should just work. Additionally, you can now write your own filters to operate on curve editor data for custom implementations of smoothing, key generation, etc. The curve editor supports three view types by default - an absolute view (default, matches old behavior), a stacked view and a normalized view. Stacked views draw each curve separately (so non-overlapping) and normalized against their own min/max values. The normalized view draws all curves overlapping with each one normalized against its own min/max values. A tree view has been added to help effectively manage large numbers of curves. Selecting curves in the treeview controls which curves are visible in the view area. The treeview also supports pinning curves. These pinned curves will always be visible regardless of your selection in the tree view. A transform tool and a retiming tool have been implemented (via a plugin) which is enabled by default. The transform tool allows you to do a marquee selection of keys and then translate and scale the positions of these keys. The retiming tool allows you to create a 1 dimensional lattice to adjust the timing of your keys with a linear falloff between each lattice point. These tools work across multiple views at the same time which is especially useful if you are representing one dimensional data (such as event keys) in a view, as it allows you to adjust this data at the same time as your animation curves. A smoothing filter has been implemented (via a plugin) to allow running highpass and lowpass filters on your keys. Opening the curve editor in Sequencer/UMG now creates a separate dockable tab which can be resized and docked as desired. A time slider has been added to the Curve Editor which is synchronized to the playback time in Sequencer. This allows you to scrub time in the curve editor without having to find the Sequencer window and adjust time there while looking at your keys and previewing your animation in the viewport at the same time. Rudimentary support has been added for saving and later restoring a set of curves in your current session. This allows you to do a rudimentary copy/paste of entire curves but can also be useful for saving a curve, making adjustments to it and then deciding you want to go back - simply reapply the saved curve! Each curve added supports an intention name (such as "Location.X" or "FieldOfView"), and these intention names will be used when trying to apply curves. This allows you to reliably take all of the curves of a transform on one object and apply them to another object (and ensure that Location.X gets applied to the new Location.X, etc.) this can be helpful if you have a mixed set of curves buffered (such as a location and a field of view). In the event that no curves match by intention you can store and apply a single curve at a time from any intention to any other intention. The Curve Asset editors (float, vector and color curve assets) have been changed to use the new editor. They support the same treeviews, filtering and tools that the Sequencer editor does. In addition, the Color Curve asset editor adds an additional view which provides a 1 dimensional gradient editor as an easier way to visualize and edit colors instead of the channels individually. #rb Max.Chen, Andrew.Rodham #ROBOMERGE-SOURCE: CL 6631811 via CL 6633746 #ROBOMERGE-BOT: (vundefined-6620334) [CL 6633863 by matt hoffman in Main branch]
2019-05-24 14:42:05 -04:00
#include "CurveEditorHelpers.h"
#include "Fonts/FontMeasure.h"
#include "Slate/Public/Framework/Application/SlateApplication.h"
This is a significant overhaul to the Curve Editor used by Sequencer which adds a plugin-based architecture and extensibility. New tools and toolbar buttons can be added to all usages of the curve editor via user plugins, and the different views for data can be created modularly so new implementations of the editor can register their own way of drawing their data and the tools should just work. Additionally, you can now write your own filters to operate on curve editor data for custom implementations of smoothing, key generation, etc. The curve editor supports three view types by default - an absolute view (default, matches old behavior), a stacked view and a normalized view. Stacked views draw each curve separately (so non-overlapping) and normalized against their own min/max values. The normalized view draws all curves overlapping with each one normalized against its own min/max values. A tree view has been added to help effectively manage large numbers of curves. Selecting curves in the treeview controls which curves are visible in the view area. The treeview also supports pinning curves. These pinned curves will always be visible regardless of your selection in the tree view. A transform tool and a retiming tool have been implemented (via a plugin) which is enabled by default. The transform tool allows you to do a marquee selection of keys and then translate and scale the positions of these keys. The retiming tool allows you to create a 1 dimensional lattice to adjust the timing of your keys with a linear falloff between each lattice point. These tools work across multiple views at the same time which is especially useful if you are representing one dimensional data (such as event keys) in a view, as it allows you to adjust this data at the same time as your animation curves. A smoothing filter has been implemented (via a plugin) to allow running highpass and lowpass filters on your keys. Opening the curve editor in Sequencer/UMG now creates a separate dockable tab which can be resized and docked as desired. A time slider has been added to the Curve Editor which is synchronized to the playback time in Sequencer. This allows you to scrub time in the curve editor without having to find the Sequencer window and adjust time there while looking at your keys and previewing your animation in the viewport at the same time. Rudimentary support has been added for saving and later restoring a set of curves in your current session. This allows you to do a rudimentary copy/paste of entire curves but can also be useful for saving a curve, making adjustments to it and then deciding you want to go back - simply reapply the saved curve! Each curve added supports an intention name (such as "Location.X" or "FieldOfView"), and these intention names will be used when trying to apply curves. This allows you to reliably take all of the curves of a transform on one object and apply them to another object (and ensure that Location.X gets applied to the new Location.X, etc.) this can be helpful if you have a mixed set of curves buffered (such as a location and a field of view). In the event that no curves match by intention you can store and apply a single curve at a time from any intention to any other intention. The Curve Asset editors (float, vector and color curve assets) have been changed to use the new editor. They support the same treeviews, filtering and tools that the Sequencer editor does. In addition, the Color Curve asset editor adds an additional view which provides a 1 dimensional gradient editor as an easier way to visualize and edit colors instead of the channels individually. #rb Max.Chen, Andrew.Rodham #ROBOMERGE-SOURCE: CL 6631811 via CL 6633746 #ROBOMERGE-BOT: (vundefined-6620334) [CL 6633863 by matt hoffman in Main branch]
2019-05-24 14:42:05 -04:00
namespace CurveEditor
{
FVector2D ComputeScreenSpaceTangentOffset(const FCurveEditorScreenSpace& CurveSpace, float Tangent, float Weight)
{
const float Angle = FMath::Atan(-Tangent);
FVector2D Offset;
FMath::SinCos(&Offset.Y, &Offset.X, Angle);
Offset *= Weight;
Offset.X *= CurveSpace.PixelsPerInput();
Offset.Y *= CurveSpace.PixelsPerOutput();
return Offset;
}
void TangentAndWeightFromOffset(const FCurveEditorScreenSpace& CurveSpace, const FVector2D& TangentOffset, float& OutTangent, float& OutWeight)
{
float X = CurveSpace.ScreenToSeconds(TangentOffset.X) - CurveSpace.ScreenToSeconds(0);
float Y = CurveSpace.ScreenToValue(TangentOffset.Y) - CurveSpace.ScreenToValue(0);
OutTangent = Y / X;
OutWeight = FMath::Sqrt(X*X + Y*Y);
}
FVector2D GetVectorFromSlopeAndLength(float Slope, float Length)
{
float x = Length / FMath::Sqrt(Slope*Slope + 1.f);
float y = Slope * x;
return FVector2D(x, y);
}
void ConstructYGridLines(const FCurveEditorScreenSpace& ViewSpace, uint8 InMinorDivisions, TArray<float>& OutMajorGridLines, TArray<float>& OutMinorGridLines, FText GridLineLabelFormatY, TArray<FText>* OutMajorGridLabels)
{
const float GridPixelSpacing = ViewSpace.GetPhysicalHeight() / 5.f;
const float Order = FMath::Pow(10.f, FMath::FloorToInt(FMath::LogX(10.f, GridPixelSpacing / ViewSpace.PixelsPerOutput())));
static const int32 DesirableBases[] = { 2, 5 };
static const int32 NumDesirableBases = UE_ARRAY_COUNT(DesirableBases);
This is a significant overhaul to the Curve Editor used by Sequencer which adds a plugin-based architecture and extensibility. New tools and toolbar buttons can be added to all usages of the curve editor via user plugins, and the different views for data can be created modularly so new implementations of the editor can register their own way of drawing their data and the tools should just work. Additionally, you can now write your own filters to operate on curve editor data for custom implementations of smoothing, key generation, etc. The curve editor supports three view types by default - an absolute view (default, matches old behavior), a stacked view and a normalized view. Stacked views draw each curve separately (so non-overlapping) and normalized against their own min/max values. The normalized view draws all curves overlapping with each one normalized against its own min/max values. A tree view has been added to help effectively manage large numbers of curves. Selecting curves in the treeview controls which curves are visible in the view area. The treeview also supports pinning curves. These pinned curves will always be visible regardless of your selection in the tree view. A transform tool and a retiming tool have been implemented (via a plugin) which is enabled by default. The transform tool allows you to do a marquee selection of keys and then translate and scale the positions of these keys. The retiming tool allows you to create a 1 dimensional lattice to adjust the timing of your keys with a linear falloff between each lattice point. These tools work across multiple views at the same time which is especially useful if you are representing one dimensional data (such as event keys) in a view, as it allows you to adjust this data at the same time as your animation curves. A smoothing filter has been implemented (via a plugin) to allow running highpass and lowpass filters on your keys. Opening the curve editor in Sequencer/UMG now creates a separate dockable tab which can be resized and docked as desired. A time slider has been added to the Curve Editor which is synchronized to the playback time in Sequencer. This allows you to scrub time in the curve editor without having to find the Sequencer window and adjust time there while looking at your keys and previewing your animation in the viewport at the same time. Rudimentary support has been added for saving and later restoring a set of curves in your current session. This allows you to do a rudimentary copy/paste of entire curves but can also be useful for saving a curve, making adjustments to it and then deciding you want to go back - simply reapply the saved curve! Each curve added supports an intention name (such as "Location.X" or "FieldOfView"), and these intention names will be used when trying to apply curves. This allows you to reliably take all of the curves of a transform on one object and apply them to another object (and ensure that Location.X gets applied to the new Location.X, etc.) this can be helpful if you have a mixed set of curves buffered (such as a location and a field of view). In the event that no curves match by intention you can store and apply a single curve at a time from any intention to any other intention. The Curve Asset editors (float, vector and color curve assets) have been changed to use the new editor. They support the same treeviews, filtering and tools that the Sequencer editor does. In addition, the Color Curve asset editor adds an additional view which provides a 1 dimensional gradient editor as an easier way to visualize and edit colors instead of the channels individually. #rb Max.Chen, Andrew.Rodham #ROBOMERGE-SOURCE: CL 6631811 via CL 6633746 #ROBOMERGE-BOT: (vundefined-6620334) [CL 6633863 by matt hoffman in Main branch]
2019-05-24 14:42:05 -04:00
const int32 Scale = FMath::RoundToInt(GridPixelSpacing / ViewSpace.PixelsPerOutput() / Order);
int32 Base = DesirableBases[0];
for (int32 BaseIndex = 1; BaseIndex < NumDesirableBases; ++BaseIndex)
{
if (FMath::Abs(Scale - DesirableBases[BaseIndex]) < FMath::Abs(Scale - Base))
{
Base = DesirableBases[BaseIndex];
}
}
double MajorGridStep = FMath::Pow(static_cast<float>(Base), FMath::FloorToFloat(FMath::LogX(static_cast<float>(Base), static_cast<float>(Scale)))) * Order;
This is a significant overhaul to the Curve Editor used by Sequencer which adds a plugin-based architecture and extensibility. New tools and toolbar buttons can be added to all usages of the curve editor via user plugins, and the different views for data can be created modularly so new implementations of the editor can register their own way of drawing their data and the tools should just work. Additionally, you can now write your own filters to operate on curve editor data for custom implementations of smoothing, key generation, etc. The curve editor supports three view types by default - an absolute view (default, matches old behavior), a stacked view and a normalized view. Stacked views draw each curve separately (so non-overlapping) and normalized against their own min/max values. The normalized view draws all curves overlapping with each one normalized against its own min/max values. A tree view has been added to help effectively manage large numbers of curves. Selecting curves in the treeview controls which curves are visible in the view area. The treeview also supports pinning curves. These pinned curves will always be visible regardless of your selection in the tree view. A transform tool and a retiming tool have been implemented (via a plugin) which is enabled by default. The transform tool allows you to do a marquee selection of keys and then translate and scale the positions of these keys. The retiming tool allows you to create a 1 dimensional lattice to adjust the timing of your keys with a linear falloff between each lattice point. These tools work across multiple views at the same time which is especially useful if you are representing one dimensional data (such as event keys) in a view, as it allows you to adjust this data at the same time as your animation curves. A smoothing filter has been implemented (via a plugin) to allow running highpass and lowpass filters on your keys. Opening the curve editor in Sequencer/UMG now creates a separate dockable tab which can be resized and docked as desired. A time slider has been added to the Curve Editor which is synchronized to the playback time in Sequencer. This allows you to scrub time in the curve editor without having to find the Sequencer window and adjust time there while looking at your keys and previewing your animation in the viewport at the same time. Rudimentary support has been added for saving and later restoring a set of curves in your current session. This allows you to do a rudimentary copy/paste of entire curves but can also be useful for saving a curve, making adjustments to it and then deciding you want to go back - simply reapply the saved curve! Each curve added supports an intention name (such as "Location.X" or "FieldOfView"), and these intention names will be used when trying to apply curves. This allows you to reliably take all of the curves of a transform on one object and apply them to another object (and ensure that Location.X gets applied to the new Location.X, etc.) this can be helpful if you have a mixed set of curves buffered (such as a location and a field of view). In the event that no curves match by intention you can store and apply a single curve at a time from any intention to any other intention. The Curve Asset editors (float, vector and color curve assets) have been changed to use the new editor. They support the same treeviews, filtering and tools that the Sequencer editor does. In addition, the Color Curve asset editor adds an additional view which provides a 1 dimensional gradient editor as an easier way to visualize and edit colors instead of the channels individually. #rb Max.Chen, Andrew.Rodham #ROBOMERGE-SOURCE: CL 6631811 via CL 6633746 #ROBOMERGE-BOT: (vundefined-6620334) [CL 6633863 by matt hoffman in Main branch]
2019-05-24 14:42:05 -04:00
const double FirstMajorLine = FMath::FloorToDouble(ViewSpace.GetOutputMin() / MajorGridStep) * MajorGridStep;
const double LastMajorLine = FMath::CeilToDouble(ViewSpace.GetOutputMax() / MajorGridStep) * MajorGridStep;
FNumberFormattingOptions FormattingOptions;
FormattingOptions.SetMaximumFractionalDigits(6);
for (double CurrentMajorLine = FirstMajorLine; CurrentMajorLine <= LastMajorLine; CurrentMajorLine += MajorGridStep)
{
OutMajorGridLines.Add(ViewSpace.ValueToScreen(CurrentMajorLine));
if (OutMajorGridLabels)
{
OutMajorGridLabels->Add(FText::Format(GridLineLabelFormatY, FText::AsNumber(CurrentMajorLine, &FormattingOptions)));
}
for (int32 Step = 1; Step < InMinorDivisions; ++Step)
{
OutMinorGridLines.Add(ViewSpace.ValueToScreen(CurrentMajorLine + Step * MajorGridStep / InMinorDivisions));
}
}
}
void ConstructFixedYGridLines(const FCurveEditorScreenSpace& ViewSpace, uint8 InMinorDivisions, double InMinorGridStep, TArray<float>& OutMajorGridLines, TArray<float>& OutMinorGridLines, FText GridLineLabelFormatY,
TArray<FText>* OutMajorGridLabels, TOptional<double> InOutputMin, TOptional<double> InOutputMax)
{
const double MajorGridStep = InMinorGridStep * InMinorDivisions;
const double FirstMinorLine = InOutputMin ? FMath::CeilToDouble(InOutputMin.GetValue() / InMinorGridStep) * InMinorGridStep
: FMath::FloorToDouble(ViewSpace.GetOutputMin() / InMinorGridStep) * InMinorGridStep;
const double LastMinorLine = InOutputMax ? FMath::FloorToDouble(InOutputMax.GetValue() / InMinorGridStep) * InMinorGridStep
: FMath::CeilToDouble(ViewSpace.GetOutputMax() / InMinorGridStep) * InMinorGridStep;
FNumberFormattingOptions FormattingOptions;
FormattingOptions.SetMaximumFractionalDigits(6);
// calculate min. distance between labels
const FSlateFontInfo FontInfo = FCoreStyle::Get().GetFontStyle("ToolTip.LargerFont");
const TSharedRef<FSlateFontMeasure> FontMeasureService = FSlateApplication::Get().GetRenderer()->GetFontMeasureService();
uint16 FontHeight = FontMeasureService->GetMaxCharacterHeight(FontInfo);
const double LabelDist = (1 / ViewSpace.PixelsPerOutput()) * (FontHeight + 3.0); // 3.0 for margin
double LineSkip = FMath::CeilToDouble(LabelDist / MajorGridStep) * MajorGridStep;
LineSkip = FMath::IsNearlyZero(LineSkip) ? KINDA_SMALL_NUMBER : LineSkip; // prevent mod by zero errors
for (double CurrentMinorLine = FirstMinorLine; CurrentMinorLine <= LastMinorLine; CurrentMinorLine += InMinorGridStep)
{
// check if is major grid line
if (FMath::IsNearlyZero(FMath::Fmod(FMath::Abs(CurrentMinorLine), MajorGridStep)))
{
OutMajorGridLines.Add(ViewSpace.ValueToScreen(CurrentMinorLine));
if (OutMajorGridLabels)
{
OutMajorGridLabels->Add(FMath::IsNearlyZero(FMath::Fmod(FMath::Abs(CurrentMinorLine), LineSkip))
? FText::Format(GridLineLabelFormatY, FText::AsNumber(CurrentMinorLine, &FormattingOptions))
: FText());
}
}
else
{
OutMinorGridLines.Add(ViewSpace.ValueToScreen(CurrentMinorLine));
}
}
}
This is a significant overhaul to the Curve Editor used by Sequencer which adds a plugin-based architecture and extensibility. New tools and toolbar buttons can be added to all usages of the curve editor via user plugins, and the different views for data can be created modularly so new implementations of the editor can register their own way of drawing their data and the tools should just work. Additionally, you can now write your own filters to operate on curve editor data for custom implementations of smoothing, key generation, etc. The curve editor supports three view types by default - an absolute view (default, matches old behavior), a stacked view and a normalized view. Stacked views draw each curve separately (so non-overlapping) and normalized against their own min/max values. The normalized view draws all curves overlapping with each one normalized against its own min/max values. A tree view has been added to help effectively manage large numbers of curves. Selecting curves in the treeview controls which curves are visible in the view area. The treeview also supports pinning curves. These pinned curves will always be visible regardless of your selection in the tree view. A transform tool and a retiming tool have been implemented (via a plugin) which is enabled by default. The transform tool allows you to do a marquee selection of keys and then translate and scale the positions of these keys. The retiming tool allows you to create a 1 dimensional lattice to adjust the timing of your keys with a linear falloff between each lattice point. These tools work across multiple views at the same time which is especially useful if you are representing one dimensional data (such as event keys) in a view, as it allows you to adjust this data at the same time as your animation curves. A smoothing filter has been implemented (via a plugin) to allow running highpass and lowpass filters on your keys. Opening the curve editor in Sequencer/UMG now creates a separate dockable tab which can be resized and docked as desired. A time slider has been added to the Curve Editor which is synchronized to the playback time in Sequencer. This allows you to scrub time in the curve editor without having to find the Sequencer window and adjust time there while looking at your keys and previewing your animation in the viewport at the same time. Rudimentary support has been added for saving and later restoring a set of curves in your current session. This allows you to do a rudimentary copy/paste of entire curves but can also be useful for saving a curve, making adjustments to it and then deciding you want to go back - simply reapply the saved curve! Each curve added supports an intention name (such as "Location.X" or "FieldOfView"), and these intention names will be used when trying to apply curves. This allows you to reliably take all of the curves of a transform on one object and apply them to another object (and ensure that Location.X gets applied to the new Location.X, etc.) this can be helpful if you have a mixed set of curves buffered (such as a location and a field of view). In the event that no curves match by intention you can store and apply a single curve at a time from any intention to any other intention. The Curve Asset editors (float, vector and color curve assets) have been changed to use the new editor. They support the same treeviews, filtering and tools that the Sequencer editor does. In addition, the Color Curve asset editor adds an additional view which provides a 1 dimensional gradient editor as an easier way to visualize and edit colors instead of the channels individually. #rb Max.Chen, Andrew.Rodham #ROBOMERGE-SOURCE: CL 6631811 via CL 6633746 #ROBOMERGE-BOT: (vundefined-6620334) [CL 6633863 by matt hoffman in Main branch]
2019-05-24 14:42:05 -04:00
} // namespace CurveEditor