polygon node: early crude implementation

This commit is contained in:
itsmattkc
2020-05-05 00:22:49 +10:00
parent b6696f3161
commit c387ce1cd7
38 changed files with 611 additions and 93 deletions
+3
View File
@@ -26,6 +26,7 @@
#include "block/gap/gap.h"
#include "block/transition/externaltransition.h"
#include "generator/matrix/matrix.h"
#include "generator/polygon/polygon.h"
#include "input/media/video/video.h"
#include "input/media/audio/audio.h"
#include "input/time/timeinput.h"
@@ -141,6 +142,8 @@ Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id)
return new ClipBlock();
case kGapBlock:
return new GapBlock();
case kPolygonGenerator:
return new PolygonGenerator();
case kMatrixGenerator:
return new MatrixGenerator();
case kVideoInput:
+1
View File
@@ -36,6 +36,7 @@ public:
kClipBlock,
kGapBlock,
kAudioInput,
kPolygonGenerator,
kMatrixGenerator,
kVideoInput,
kTrackOutput,
+1
View File
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(matrix)
add_subdirectory(polygon)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
+36 -22
View File
@@ -90,27 +90,9 @@ void MatrixGenerator::Retranslate()
NodeValueTable MatrixGenerator::Value(NodeValueDatabase &value) const
{
QMatrix4x4 mat;
// Position translate
QVector2D pos = value[position_input_].Get(NodeParam::kVec2).value<QVector2D>();
mat.translate(pos);
// Rotation
mat.rotate(value[rotation_input_].Get(NodeParam::kFloat).toFloat(), 0, 0, 1);
// Scale and Uniform Scale
QVector2D scale = value[scale_input_].Get(NodeParam::kVec2).value<QVector2D>();
if (value[uniform_scale_input_].Get(NodeParam::kBoolean).toBool()) {
scale.setY(scale.x());
}
mat.scale(scale);
// Anchor Point
mat.translate(-value[anchor_input_].Get(NodeParam::kVec2).value<QVector2D>());
// Push matrix output
NodeValueTable output;
QMatrix4x4 mat = GenerateMatrix(value);
NodeValueTable output = value.Merge();
output.Push(NodeParam::kMatrix, mat);
return output;
}
@@ -120,10 +102,42 @@ bool MatrixGenerator::HasGizmos() const
return true;
}
void MatrixGenerator::DrawGizmos(QPainter *p, const QRect& viewport) const
void MatrixGenerator::DrawGizmos(NodeValueDatabase &db, QPainter *p) const
{
p->setPen(Qt::white);
p->drawEllipse(viewport);
// Fold values into a matrix
QMatrix4x4 matrix = GenerateMatrix(db);
// Set QPainter transform to our matrix
p->setTransform(matrix.toTransform());
// Draw ellipse
p->drawEllipse(QRect(0, 0, 100, 100));
}
QMatrix4x4 MatrixGenerator::GenerateMatrix(NodeValueDatabase &value) const
{
QMatrix4x4 mat;
// Position translate
QVector2D pos = value[position_input_].Take(NodeParam::kVec2).value<QVector2D>();
mat.translate(pos);
// Rotation
mat.rotate(value[rotation_input_].Take(NodeParam::kFloat).toFloat(), 0, 0, 1);
// Scale and Uniform Scale
QVector2D scale = value[scale_input_].Take(NodeParam::kVec2).value<QVector2D>();
if (value[uniform_scale_input_].Take(NodeParam::kBoolean).toBool()) {
scale.setY(scale.x());
}
mat.scale(scale);
// Anchor Point
mat.translate(-value[anchor_input_].Take(NodeParam::kVec2).value<QVector2D>());
return mat;
}
void MatrixGenerator::UniformScaleChanged()
+3 -1
View File
@@ -44,9 +44,11 @@ public:
virtual NodeValueTable Value(NodeValueDatabase& value) const override;
virtual bool HasGizmos() const override;
virtual void DrawGizmos(QPainter *p, const QRect &viewport) const override;
virtual void DrawGizmos(NodeValueDatabase& db, QPainter *p) const override;
private:
QMatrix4x4 GenerateMatrix(NodeValueDatabase& value) const;
NodeInput* position_input_;
NodeInput* rotation_input_;
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
node/generator/polygon/polygon.h
node/generator/polygon/polygon.cpp
PARENT_SCOPE
)
+120
View File
@@ -0,0 +1,120 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "polygon.h"
#include <QVector2D>
OLIVE_NAMESPACE_ENTER
PolygonGenerator::PolygonGenerator()
{
points_input_ = new NodeInputArray("points_in", NodeParam::kVec2);
AddInput(points_input_);
color_input_ = new NodeInput("color_in", NodeParam::kColor);
AddInput(color_input_);
// Default to "a color" that isn't
color_input_->set_standard_value(1.0, 0);
color_input_->set_standard_value(1.0, 1);
color_input_->set_standard_value(1.0, 2);
color_input_->set_standard_value(1.0, 3);
// FIXME: Test code
points_input_->SetSize(5);
points_input_->At(0)->set_standard_value(960, 0);
points_input_->At(0)->set_standard_value(240, 1);
points_input_->At(1)->set_standard_value(640, 0);
points_input_->At(1)->set_standard_value(480, 1);
points_input_->At(2)->set_standard_value(760, 0);
points_input_->At(2)->set_standard_value(800, 1);
points_input_->At(3)->set_standard_value(1100, 0);
points_input_->At(3)->set_standard_value(800, 1);
points_input_->At(4)->set_standard_value(1280, 0);
points_input_->At(4)->set_standard_value(480, 1);
// End test
}
Node *PolygonGenerator::copy() const
{
return new PolygonGenerator();
}
QString PolygonGenerator::Name() const
{
return tr("Polygon");
}
QString PolygonGenerator::id() const
{
return QStringLiteral("org.olivevideoeditor.Olive.polygon");
}
QString PolygonGenerator::Category() const
{
return tr("Generator");
}
QString PolygonGenerator::Description() const
{
return tr("Generate a 2D polygon of any amount of points.");
}
void PolygonGenerator::Retranslate()
{
points_input_->set_name(tr("Points"));
color_input_->set_name(tr("Color"));
}
Node::Capabilities PolygonGenerator::GetCapabilities(const NodeValueDatabase &) const
{
return kShader;
}
QString PolygonGenerator::ShaderFragmentCode(const NodeValueDatabase &) const
{
return Node::ReadFileAsString(":/shaders/polygon.frag");
}
bool PolygonGenerator::HasGizmos() const
{
return true;
}
void PolygonGenerator::DrawGizmos(NodeValueDatabase &db, QPainter *p) const
{
QVector<QPointF> points(points_input_->GetSize());
p->setPen(Qt::white);
p->setBrush(Qt::white);
for (int i=0;i<points_input_->GetSize();i++) {
points[i] = db[points_input_->At(i)].Take(NodeParam::kVec2).value<QVector2D>().toPointF();
QRectF rect(points[i] - QPointF(10, 10),
points[i] + QPointF(10, 10));
p->drawRect(rect);
}
p->drawPolyline(points.constData(), points_input_->GetSize());
}
OLIVE_NAMESPACE_EXIT
+63
View File
@@ -0,0 +1,63 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef POLYGONGENERATOR_H
#define POLYGONGENERATOR_H
#include "node/node.h"
OLIVE_NAMESPACE_ENTER
class PolygonGenerator : public Node
{
public:
PolygonGenerator();
virtual Node* copy() const override;
virtual QString Name() const override;
virtual QString id() const override;
virtual QString Category() const override;
virtual QString Description() const override;
virtual void Retranslate() override;
virtual Capabilities GetCapabilities(const NodeValueDatabase&) const override;
virtual QString ShaderFragmentCode(const NodeValueDatabase&) const override;
virtual bool HasGizmos() const override;
virtual void DrawGizmos(NodeValueDatabase& db, QPainter *p) const override;
/*
virtual bool GizmoPress(const QPointF &p) override;
virtual void GizmoMove(const QPointF &p) override;
virtual void GizmoRelease(const QPointF &p) override;
*/
private:
NodeInputArray* points_input_;
NodeInput* color_input_;
};
OLIVE_NAMESPACE_EXIT
#endif // POLYGONGENERATOR_H
+14 -1
View File
@@ -293,7 +293,20 @@ bool Node::HasGizmos() const
return false;
}
void Node::DrawGizmos(QPainter *, const QRect &) const
void Node::DrawGizmos(NodeValueDatabase &, QPainter *) const
{
}
bool Node::GizmoPress(const QPointF &)
{
return false;
}
void Node::GizmoMove(const QPointF &)
{
}
void Node::GizmoRelease(const QPointF &)
{
}
+5 -1
View File
@@ -362,7 +362,11 @@ public:
virtual bool HasGizmos() const;
virtual void DrawGizmos(QPainter* p, const QRect &viewport) const;
virtual void DrawGizmos(NodeValueDatabase& db, QPainter* p) const;
virtual bool GizmoPress(const QPointF& p);
virtual void GizmoMove(const QPointF& p);
virtual void GizmoRelease(const QPointF& p);
const QString& GetLabel() const;
void SetLabel(const QString& s);
+30 -9
View File
@@ -29,21 +29,29 @@ NodeValueDatabase NodeTraverser::GenerateDatabase(const Node* node, const TimeRa
NodeValueDatabase database;
// We need to insert tables into the database for each input
foreach (NodeParam* param, node->parameters()) {
QList<NodeInput*> inputs = node->GetInputsIncludingArrays();
foreach (NodeInput* input, inputs) {
if (IsCancelled()) {
return NodeValueDatabase();
}
if (param->type() == NodeParam::kInput) {
NodeInput* input = static_cast<NodeInput*>(param);
TimeRange input_time = node->InputTimeAdjustment(input, range);
TimeRange input_time = node->InputTimeAdjustment(input, range);
NodeValueTable table = ProcessInput(input, input_time);
NodeValueTable table = ProcessInput(input, input_time);
InputProcessingEvent(input, input_time, &table);
// Exception for Footage types where we actually retrieve some Footage data from a decoder
if (input->data_type() == NodeParam::kFootage) {
StreamPtr stream = ResolveStreamFromInput(input);
database.Insert(input, table);
if (stream) {
FootageProcessingEvent(stream, input_time, &table);
}
}
database.Insert(input, table);
}
// Insert global variables
@@ -79,8 +87,21 @@ NodeValueTable NodeTraverser::ProcessNode(const NodeDependency& dep)
NodeValueTable NodeTraverser::RenderBlock(const TrackOutput *track, const TimeRange &range)
{
// By default, don't bother traversing blocks
return NodeValueTable();
// By default, just follow the in point
Block* active_block = track->BlockAtTime(range.in());
NodeValueTable table;
if (active_block) {
table = ProcessNode(NodeDependency(active_block, range));
}
return table;
}
StreamPtr NodeTraverser::ResolveStreamFromInput(NodeInput *input)
{
return input->get_standard_value().value<StreamPtr>();
}
NodeValueTable NodeTraverser::ProcessInput(const NodeInput *input, const TimeRange& range)
+5 -2
View File
@@ -37,17 +37,20 @@ public:
NodeValueTable ProcessNode(const NodeDependency &dep);
protected:
NodeValueDatabase GenerateDatabase(const Node *node, const TimeRange &range);
protected:
virtual NodeValueTable RenderBlock(const TrackOutput *track, const TimeRange& range);
NodeValueTable ProcessInput(const NodeInput* input, const TimeRange &range);
virtual void InputProcessingEvent(NodeInput*, const TimeRange&, NodeValueTable*){}
virtual void FootageProcessingEvent(StreamPtr, const TimeRange&, NodeValueTable*){}
virtual void ProcessNodeEvent(const Node*, const TimeRange&, NodeValueDatabase&, NodeValueTable&){}
private:
StreamPtr ResolveStreamFromInput(NodeInput* input);
};
OLIVE_NAMESPACE_EXIT