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
+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;
}