node: implement transform parenting

This commit is contained in:
itsmattkc
2022-07-26 11:04:24 -07:00
parent d05146170e
commit f6dc3c7fcc
4 changed files with 27 additions and 23 deletions
@@ -22,12 +22,9 @@
#include <QGuiApplication>
#include "common/range.h"
#include "core.h"
#include "node/traverser.h"
namespace olive {
const QString TransformDistortNode::kParentInput = QStringLiteral("parent_in");
const QString TransformDistortNode::kTextureInput = QStringLiteral("tex_in");
const QString TransformDistortNode::kAutoscaleInput = QStringLiteral("autoscale_in");
const QString TransformDistortNode::kInterpolationInput = QStringLiteral("interpolation_in");
@@ -36,6 +33,8 @@ const QString TransformDistortNode::kInterpolationInput = QStringLiteral("interp
TransformDistortNode::TransformDistortNode()
{
AddInput(kParentInput, NodeValue::kMatrix);
AddInput(kAutoscaleInput, NodeValue::kCombo, 0);
AddInput(kInterpolationInput, NodeValue::kCombo, 2);
@@ -73,6 +72,7 @@ void TransformDistortNode::Retranslate()
{
super::Retranslate();
SetInputName(kParentInput, tr("Parent"));
SetInputName(kAutoscaleInput, tr("Auto-Scale"));
SetInputName(kTextureInput, tr("Texture"));
SetInputName(kInterpolationInput, tr("Interpolation"));
@@ -84,12 +84,12 @@ void TransformDistortNode::Retranslate()
void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
{
// Generate matrix
QMatrix4x4 generated_matrix = GenerateMatrix(value, false, false, false);
QMatrix4x4 generated_matrix = GenerateMatrix(value, false, false, false, value[kParentInput].toMatrix());
// Pop texture
NodeValue texture_meta = value[kTextureInput];
bool pushed_job = false;
QVariant job_to_push;
// If we have a texture, generate a matrix and make it happen
if (TexturePtr texture = texture_meta.toTexture()) {
@@ -103,15 +103,17 @@ void TransformDistortNode::Value(const NodeValueRow &value, const NodeGlobals &g
job.Insert(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, real_matrix, this));
job.SetInterpolation(QStringLiteral("ove_maintex"), static_cast<Texture::Interpolation>(value[kInterpolationInput].toInt()));
table->Push(NodeValue::kTexture, QVariant::fromValue(job), this);
pushed_job = true;
job_to_push = QVariant::fromValue(job);
}
}
if (!pushed_job) {
table->Push(NodeValue::kMatrix, QVariant::fromValue(generated_matrix), this);
if (job_to_push.isNull()) {
// Re-push whatever value we received
table->Push(texture_meta);
} else {
table->Push(NodeValue::kTexture, job_to_push, this);
}
}
@@ -129,7 +131,7 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
if (gizmo == anchor_gizmo_) {
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, false).toTransform().inverted();
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, false, row[kParentInput].toMatrix()).toTransform().inverted();
} else if (IsAScaleGizmo(gizmo)) {
@@ -171,7 +173,7 @@ void TransformDistortNode::GizmoDragStart(const NodeValueRow &row, double x, dou
}
// Store current matrix
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, true).toTransform().inverted();
gizmo_inverted_transform_ = GenerateMatrix(row, true, true, true, row[kParentInput].toMatrix()).toTransform().inverted();
} else if (gizmo == rotation_gizmo_) {
@@ -356,7 +358,7 @@ void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const N
// Fold values into a matrix for the rectangle
QMatrix4x4 rectangle_matrix;
rectangle_matrix.scale(sequence_half_res);
rectangle_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, false, false, false),
rectangle_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix()),
sequence_res,
tex_sz,
tex_offset,
@@ -376,7 +378,7 @@ void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const N
// Draw anchor point
QMatrix4x4 anchor_matrix;
anchor_matrix.scale(sequence_half_res);
anchor_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, true, false, false),
anchor_matrix *= AdjustMatrixByResolutions(GenerateMatrix(row, true, false, false, row[kParentInput].toMatrix()),
sequence_res,
tex_sz,
tex_offset,
@@ -402,7 +404,7 @@ void TransformDistortNode::UpdateGizmoPositions(const NodeValueRow &row, const N
QTransform TransformDistortNode::GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const
{
if (TexturePtr texture = row[kTextureInput].toTexture()) {
auto m = GenerateMatrix(row, false, false, false);
auto m = GenerateMatrix(row, false, false, false, row[kParentInput].toMatrix());
return GenerateAutoScaledMatrix(m, row, globals, texture->params()).toTransform();
}
return super::GizmoTransformation(row, globals);
@@ -84,6 +84,7 @@ public:
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
virtual QTransform GizmoTransformation(const NodeValueRow &row, const NodeGlobals &globals) const override;
static const QString kParentInput;
static const QString kTextureInput;
static const QString kAutoscaleInput;
static const QString kInterpolationInput;
+6 -6
View File
@@ -90,11 +90,11 @@ void MatrixGenerator::Retranslate()
void MatrixGenerator::Value(const NodeValueRow &value, const NodeGlobals &globals, NodeValueTable *table) const
{
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value, false, false, false);
QMatrix4x4 mat = GenerateMatrix(value, false, false, false, QMatrix4x4());
table->Push(NodeValue::kMatrix, mat, this);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale) const
QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const
{
QVector2D anchor;
QVector2D position;
@@ -116,17 +116,17 @@ QMatrix4x4 MatrixGenerator::GenerateMatrix(const NodeValueRow &value, bool ignor
value[kRotationInput].toDouble(),
scale,
value[kUniformScaleInput].toBool(),
anchor);
anchor,
mat);
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(const QVector2D& pos,
const float& rot,
const QVector2D& scale,
bool uniform_scale,
const QVector2D& anchor)
const QVector2D& anchor,
QMatrix4x4 mat)
{
QMatrix4x4 mat;
// Position
mat.translate(pos);
+3 -2
View File
@@ -53,12 +53,13 @@ public:
static const QString kAnchorInput;
protected:
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale) const;
QMatrix4x4 GenerateMatrix(const NodeValueRow &value, bool ignore_anchor, bool ignore_position, bool ignore_scale, const QMatrix4x4 &mat) const;
static QMatrix4x4 GenerateMatrix(const QVector2D &pos,
const float &rot,
const QVector2D &scale,
bool uniform_scale,
const QVector2D &anchor);
const QVector2D &anchor,
QMatrix4x4 mat);
virtual void InputValueChangedEvent(const QString& input, int element) override;