partially functional transform

This commit is contained in:
itsmattkc
2019-09-09 18:11:04 +10:00
parent ba7a10177f
commit 9ff4a81ec8
14 changed files with 155 additions and 11 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ extern "C" {
#include "core.h"
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
// Create application instance
QApplication a(argc, argv);
+5
View File
@@ -114,6 +114,11 @@ QVariant OpacityNode::Value(NodeOutput *output, const rational &time)
return 0;
}
void OpacityNode::Retranslate()
{
opacity_input_->set_name(tr("Opacity"));
}
NodeInput *OpacityNode::texture_input()
{
return texture_input_;
+2
View File
@@ -38,6 +38,8 @@ public:
virtual QVariant Value(NodeOutput *output, const rational &time) override;
virtual void Retranslate() override;
NodeInput* texture_input();
NodeOutput* texture_output();
+18 -3
View File
@@ -35,6 +35,7 @@ TransformDistort::TransformDistort()
scale_input_ = new NodeInput("scale_in");
scale_input_->add_data_input(NodeParam::kVec2);
scale_input_->set_value(QVector2D(100.0f, 100.0f));
AddParameter(scale_input_);
anchor_input_ = new NodeInput("anchor_in");
@@ -71,14 +72,28 @@ NodeOutput *TransformDistort::matrix_output()
return matrix_output_;
}
void TransformDistort::Retranslate()
{
position_input_->set_name(tr("Position"));
rotation_input_->set_name(tr("Rotation"));
scale_input_->set_name(tr("Scale"));
anchor_input_->set_name(tr("Anchor Point"));
}
QVariant TransformDistort::Value(NodeOutput *output, const rational &time)
{
if (output == matrix_output_) {
QMatrix4x4 mat;
mat.translate(position_input_->get_value(time).value<QVector2D>());
//mat.rotate(0)
//mat.scale()
// Position translate
QVector2D pos = position_input_->get_value(time).value<QVector2D>() * 0.01f;
mat.translate(pos);
// Rotation
mat.rotate(rotation_input_->get_value(time).toFloat(), 0, 0, 1);
// Scale
mat.scale(scale_input_->get_value(time).value<QVector2D>()*0.01f);
return mat;
}
+2
View File
@@ -36,6 +36,8 @@ public:
NodeOutput* matrix_output();
virtual void Retranslate() override;
protected:
virtual QVariant Value(NodeOutput *output, const rational &time) override;
+7
View File
@@ -164,10 +164,17 @@ void NodeInput::set_maximum(const QVariant &max)
NodeParam::DataType NodeInput::data_type()
{
if (IsConnected()) {
// Return the connected output's data type
return edges_.first()->output()->data_type();
}
if (inputs_.isEmpty()) {
// Safety if no inputs have been added
return kNone;
}
// Return first
return inputs_.first();
}
+6 -1
View File
@@ -45,6 +45,10 @@ void Node::Release()
{
}
void Node::Retranslate()
{
}
void Node::AddParameter(NodeParam *param)
{
// Ensure no other param with this ID has been added to this Node (since that defeats the purpose)
@@ -334,7 +338,8 @@ void Node::Hash(QCryptographicHash *hash, NodeOutput* from, const rational &time
&& static_cast<NodeInput*>(param)->dependent()) {
// Get the value at this time
QVariant v = static_cast<NodeInput*>(param)->get_value(time);
hash->addData(v.toByteArray()); // FIXME: Does this work on all value types?
hash->addData(NodeParam::ValueToBytes(param->data_type(), v));
}
}
+5
View File
@@ -90,6 +90,11 @@ public:
*/
virtual void Release();
/**
* @brief Function called to retranslate parameter names (should be overridden in derivatives)
*/
virtual void Retranslate();
/**
* @brief Return the parameter at a given index
*/
+15
View File
@@ -39,7 +39,22 @@ NodeParam::DataType NodeOutput::data_type()
void NodeOutput::set_data_type(const NodeParam::DataType &type)
{
if (data_type_ == type) {
return;
}
data_type_ = type;
// If this output is connected to other inputs, check if they're compatible with this new data type
if (IsConnected()) {
foreach (NodeEdgePtr edge, edges_) {
if (!AreDataTypesCompatible(this, edge->input())) {
// FIXME: Possible array out of bounds since this function removes edges while we're iterating through them?
// I'm not sure how Qt's `foreach` works.
DisconnectEdge(edge);
}
}
}
}
QVariant NodeOutput::get_value(const rational& time)
+48
View File
@@ -20,7 +20,12 @@
#include "param.h"
#include <QColor>
#include <QDebug>
#include <QMatrix4x4>
#include <QVector2D>
#include <QVector3D>
#include <QVector4D>
#include "node/node.h"
#include "node/input.h"
@@ -241,6 +246,35 @@ QString NodeParam::GetDefaultDataTypeName(const DataType& type)
return QString();
}
QByteArray NodeParam::ValueToBytes(const NodeParam::DataType &type, const QVariant &value)
{
switch (type) {
case kInt: return ValueToBytesInternal<int>(value);
case kFloat: return ValueToBytesInternal<float>(value);
case kColor: return ValueToBytesInternal<QColor>(value);
case kString: return ValueToBytesInternal<QString>(value);
case kBoolean: return ValueToBytesInternal<bool>(value);
case kFont: return ValueToBytesInternal<QString>(value); // FIXME: This should probably be a QFont?
case kFile: return ValueToBytesInternal<QString>(value);
case kMatrix: return ValueToBytesInternal<QMatrix4x4>(value);
case kFootage: return ValueToBytesInternal<float>(value); // FIXME: Unsustainble, find some other way to match Footage
case kRational: return ValueToBytesInternal<rational>(value);
case kVec2: return ValueToBytesInternal<QVector2D>(value);
case kVec3: return ValueToBytesInternal<QVector3D>(value);
case kVec4: return ValueToBytesInternal<QVector4D>(value);
// These types have no persistent input
case kNone:
case kTexture:
case kBlock:
case kTrack:
case kAny:
break;
}
return QByteArray();
}
void NodeParam::ClearCachedValue()
{
// Since get_value() will (read: should) never receive a negative number, this will effectively invalidate any value
@@ -257,3 +291,17 @@ void NodeParam::SetValueCachingEnabled(bool enabled)
{
value_caching_ = enabled;
}
template<typename T>
QByteArray NodeParam::ValueToBytesInternal(const QVariant &v)
{
QByteArray bytes;
int size_of_type = sizeof(T);
bytes.resize(size_of_type);
T raw_val = v.value<T>();
memcpy(bytes.data(), &raw_val, static_cast<size_t>(size_of_type));
return bytes;
}
+11
View File
@@ -240,6 +240,11 @@ public:
*/
static QString GetDefaultDataTypeName(const DataType &type);
/**
* @brief Convert a value from a NodeParam into bytes
*/
static QByteArray ValueToBytes(const DataType &type, const QVariant& value);
/**
* @brief Clear the cached value
*/
@@ -293,6 +298,12 @@ protected:
bool value_caching_;
private:
/**
* @brief Internal function for returning a value in the form of bytes
*/
template<typename T>
static QByteArray ValueToBytesInternal(const QVariant& v);
/**
* @brief Internal name string
*/
+1 -1
View File
@@ -364,7 +364,7 @@ void RendererProcessor::CacheNext()
rational cache_frame = cache_queue_.takeFirst();
//qDebug() << "[RendererProcessor] Caching" << cache_frame.toDouble();
qDebug() << "[RendererProcessor] Caching" << cache_frame.toDouble();
threads_.first()->Queue(NodeDependency(texture_input_->get_connected_output(), cache_frame), true);
+30 -5
View File
@@ -22,7 +22,7 @@
#include <QCheckBox>
#include <QDebug>
#include <QEvent>
#include <QPainter>
#include "project/item/sequence/sequence.h"
@@ -92,7 +92,9 @@ bool NodeParamViewItem::CanAddNode(Node* n)
void NodeParamViewItem::changeEvent(QEvent *e)
{
// FIXME: Retranslate all UI elements
if (e->type() == QEvent::LanguageChange && !nodes_.isEmpty()) {
Retranslate();
}
QWidget::changeEvent(e);
}
@@ -103,8 +105,6 @@ void NodeParamViewItem::SetupUI()
Node* first_node = nodes_.first();
title_bar_lbl_->setText(first_node->Name());
int row_count = 0;
for (int i=0;i<first_node->ParameterCount();i++) {
@@ -114,7 +114,8 @@ void NodeParamViewItem::SetupUI()
if (param->type() == NodeParam::kInput) {
// Add descriptor label
QLabel* param_label = new QLabel(tr("%1:").arg(param->name()));
QLabel* param_label = new QLabel();
param_lbls_.append(param_label);
content_layout_->addWidget(param_label, row_count, 0);
@@ -132,6 +133,8 @@ void NodeParamViewItem::SetupUI()
row_count++;
}
}
Retranslate();
}
void NodeParamViewItem::AddAdditionalNode(Node *n)
@@ -149,6 +152,28 @@ void NodeParamViewItem::AddAdditionalNode(Node *n)
}
}
void NodeParamViewItem::Retranslate()
{
Node* first_node = nodes_.first();
first_node->Retranslate();
title_bar_lbl_->setText(first_node->Name());
int row_count = 0;
for (int i=0;i<first_node->ParameterCount();i++) {
NodeParam* param = first_node->ParamAt(i);
// This widget only needs to show input parameters
if (param->type() == NodeParam::kInput) {
param_lbls_.at(row_count)->setText(tr("%1:").arg(param->name()));
row_count++;
}
}
}
void NodeParamViewItem::SetExpanded(bool e)
{
expanded_ = e;
@@ -56,12 +56,16 @@ private:
void AddAdditionalNode(Node* n);
void Retranslate();
bool expanded_;
NodeParamViewItemTitleBar* title_bar_;
QLabel* title_bar_lbl_;
QVector<QLabel*> param_lbls_;
QPushButton* title_bar_collapse_btn_;
QWidget* contents_;