6#ifndef QSSGSCENEDESCRIPTION_P_H
7#define QSSGSCENEDESCRIPTION_P_H
9#include <QtQuick3DAssetUtils/private/qtquick3dassetutilsglobal_p.h>
10#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
11#include <QtQuick3DRuntimeRender/private/qssgperframeallocator_p.h>
12#include <QtQuick3DUtils/private/qssgmesh_p.h>
14#include <QtCore/qlist.h>
15#include <QtCore/qhash.h>
16#include <QtCore/qvariant.h>
17#include <QtCore/qflags.h>
18#include <QtQml/qqmllist.h>
21#include <QtQuick3D/private/qquick3dobject_p.h>
23#include <QtQuick3D/private/qquick3dcustommaterial_p.h>
24#include <QtQuick3D/private/qquick3ddefaultmaterial_p.h>
25#include <QtQuick3D/private/qquick3dprincipledmaterial_p.h>
26#include <QtQuick3D/private/qquick3dspecularglossymaterial_p.h>
27#include <QtQuick3D/private/qquick3dmodel_p.h>
29#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
30#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
31#include <QtQuick3D/private/qquick3dcustomcamera_p.h>
33#include <QtQuick3D/private/qquick3ddirectionallight_p.h>
34#include <QtQuick3D/private/qquick3dpointlight_p.h>
35#include <QtQuick3D/private/qquick3dspotlight_p.h>
37#include <QtQuick3D/private/qquick3dtexture_p.h>
38#include <QtQuick3D/private/qquick3dcubemaptexture_p.h>
39#include <QtQuick3D/private/qquick3dtexturedata_p.h>
41#include <QtQuick3D/private/qquick3dskeleton_p.h>
42#include <QtQuick3D/private/qquick3djoint_p.h>
43#include <QtQuick3D/private/qquick3dinstancing_p.h>
46#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
48#include <QtGui/qquaternion.h>
72struct Q_QUICK3DASSETUTILS_EXPORT
Scene
100Q_QUICK3DASSETUTILS_EXPORT
void destructValue(QVariant &value);
121 destructValue(value);
130 const auto size =
sizeof(Node *) * n;
131 head =
reinterpret_cast<Node **>(malloc(size));
132 memcpy(
head, data, size);
140struct Q_QUICK3DASSETUTILS_EXPORT
Node
190#define QSSG_DECLARE_NODE(NODE) static_assert
191 (is_node_v<NODE>, #NODE " - does not inherit from Node!"); template
192 <> struct TypeMap<NODE::type> { using type = QSSGSceneDesc::NODE; };
341 case ValueType::Number:
343 case ValueType::Vec2:
344 return value.toVector2D();
345 case ValueType::Vec3:
346 return value.toVector3D();
347 case ValueType::Vec4:
349 case ValueType::Quaternion:
350 return QQuaternion(value);
411Q_QUICK3DASSETUTILS_EXPORT
void addNode(Node &parent, Node &node);
414Q_QUICK3DASSETUTILS_EXPORT
void addNode(Scene &scene, Node &node);
432template <
typename R,
typename... A>
443template <
typename R,
typename C,
typename... A>
446 enum {
value =
sizeof... (A) == 1 };
454template <
typename T,
typename C>
464template <
typename Ret,
typename Arg>
467 using Setter = Ret (*)(QQuick3DObject &,
const char *, Arg);
470 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
471 bool set(QQuick3DObject &that,
const char *name,
const void *value)
override
479 bool set(QQuick3DObject &that,
const char *name,
const QVariant &var)
override
486template <
typename Ret,
typename Class,
typename Arg>
492 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
493 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
496 (qobject_cast<Class *>(&that)->*
call)(
reinterpret_cast<
typename FuncType<
Setter>::Arg0>(
const_cast<
void *>(value)));
498 (qobject_cast<Class *>(&that)->*
call)(*
reinterpret_cast<
typename FuncType<
Setter>::Arg0Base *>(
const_cast<
void *>(value)));
502 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
504 (qobject_cast<Class *>(&that)->*
call)(qvariant_cast<
typename FuncType<
Setter>::Arg0Base>(var));
509template <
typename Ret,
typename Class,
typename Arg>
517 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
518 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
520 if (
const auto listView =
reinterpret_cast<
const ListView *>(value)) {
521 if (listView->count > 0) {
522 const auto begin =
reinterpret_cast<It *>(listView
->data);
523 const auto end =
reinterpret_cast<It *>(listView
->data) + listView->count;
524 (qobject_cast<Class *>(&that)->*
call)(
ListT{begin, end});
526 (qobject_cast<Class *>(&that)->*
call)(
ListT{});
533 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
535 if (
const auto listView = qvariant_cast<
const ListView *>(var)) {
536 if (listView->count > 0) {
537 const auto begin =
reinterpret_cast<It *>(listView->data);
538 const auto end =
reinterpret_cast<It *>(listView->data) + listView->count;
539 (qobject_cast<Class *>(&that)->*
call)(
ListT{begin, end});
541 (qobject_cast<Class *>(&that)->*
call)(
ListT{});
548template <
typename Class,
typename T,
template <
typename>
typename List>
558 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
564 auto head =
reinterpret_cast<as_node_type_t<T> **>(nodeList
.head);
565 for (
int i = 0, end = nodeList.count; i != end; ++i)
566 list.append(&list, qobject_cast<T *>((*(head + i))->obj));
569 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
573 doSet(that, nodeList);
579 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
583 doSet(that, *nodeList);
590template <
typename NodeT>
594template <
typename Setter,
typename T>
602template<
typename Setter,
typename T, if_compatible_t<Setter, T> =
false>
605 Q_ASSERT(node.scene);
609 prop->value = QVariant::fromValue(std::forward<T>(value));
610 node.properties.push_back(prop);
613template<
typename Setter,
typename T, if_compatible_t<Setter, QFlags<T>> =
false>
616 Q_ASSERT(node.scene);
620 prop->value = QVariant::fromValue(Flag{ QMetaEnum::fromType<rm_cvref_t<T>>(), value.toInt() });
621 node.properties.push_back(prop);
625template<
typename Setter,
typename T, if_compatible_t<Setter, QList<T>> =
false>
628 Q_ASSERT(node.scene);
629 static_assert(!
std::is_pointer_v<T>,
"Type cannot be a pointer!");
630 static_assert(
std::is_trivially_destructible_v<T> &&
std::is_trivially_copy_constructible_v<T>,
631 "List parameter type needs to be trivially constructable and trivially destructible!");
633 const auto count = value.size();
634 void *data =
nullptr;
636 const auto asize = count *
sizeof(T);
637 data = malloc(asize);
638 memcpy(data, value.constData(), asize);
643 prop->value = QVariant::fromValue(
new ListView{ QMetaType::fromType<rm_cvref_t<T>>(), data, count });
644 node.properties.push_back(prop);
652template<
typename Setter>
655 Q_ASSERT(node.scene);
656 Property *prop =
new Property;
658 prop->call =
new PropertySetter(setter);
660 node.properties.push_back(prop);
663template<
typename Setter,
typename Value, if_compatible_proxy_t<Setter, Value> =
true>
666 Q_ASSERT(node.scene);
667 static_assert(std::is_trivially_destructible_v<rm_cvref_t<Value>>,
"Value needs to be trivially destructible!");
668 Property *prop =
new Property;
670 prop->call =
new PropertyProxySetter(setter);
671 prop->value = QVariant::fromValue(value);
673 node.properties.push_back(prop);
676template<
typename Setter,
typename ViewValue, if_compatible_t<Setter,
typename ViewValue::type> =
false>
679 Q_ASSERT(node.scene);
680 static_assert(
std::is_same_v<
typename ViewValue::type,
typename FuncType<Setter>::Arg0Base>,
"Type cannot be mapped to slot argument");
681 Property *prop =
new Property;
683 prop->call =
new PropertySetter(setter);
684 prop->value = QVariant::fromValue(view);
685 node.properties.push_back(prop);
688template<
typename Setter,
typename Value, if_compatible_t<Setter, as_scene_type_t<Value> *> =
true>
691 Q_ASSERT(node.scene);
692 Property *prop =
new Property;
694 prop->call =
new PropertySetter(setter);
696 prop->value = QVariant::fromValue(
static_cast<Node *>(value));
697 node.properties.push_back(prop);
701template<
typename Setter,
typename NodeT, qsizetype Prealloc, if_compatible_node_list_t<Setter, NodeT> =
true>
704 Q_ASSERT(node.scene);
705 if (!list.isEmpty()) {
706 NodeList *l =
new NodeList(
reinterpret_cast<
void *
const*>(list.constData()), list.count());
708 Property *prop =
new Property;
710 prop->call =
new PropertyList(setter);
711 prop->value = QVariant::fromValue(l);
712 node.properties.push_back(prop);
bool isDefaultValue(QSSGSceneDesc::Node::RuntimeType type, const char *property, const QVariant &value)
PropertiesMap propertiesForType(QSSGSceneDesc::Node::RuntimeType type)
static PropertyMap * instance()
QVariant getDefaultValue(QSSGSceneDesc::Node::RuntimeType type, const char *property)
QHash< QByteArray, QVariant > PropertiesMap
The QVector2D class represents a vector or vertex in 2D space.
The QVector3D class represents a vector or vertex in 3D space.
The QVector4D class represents a vector or vertex in 4D space.
static QString getInstancesFolder()
static const char * blockEnd()
static constexpr QByteArrayView qml_basic_types[]
QString builtinQmlType(const QVariant &var)
static void generateKeyframeData(const QSSGSceneDesc::Animation::Channel &channel, QByteArray &keyframeData)
void writeQmlComponent(const QSSGSceneDesc::Node &node, QTextStream &stream, const QDir &outDir)
static QString getIdForNode(const QSSGSceneDesc::Node &node)
QString asString(const QVariant &var)
static void writeNodeProperties(const QSSGSceneDesc::Node &node, OutputContext &output, const char *skipProperty=nullptr)
static QString getTextureFolder()
QString qmlComponentName(const QString &name)
static PropertyMap::PropertiesMap getObjectPropertiesMap(QObject *object)
static QString getAnimationFolder()
static QString getAnimationExtension()
static ValueToQmlResult valueToQml(const QSSGSceneDesc::Node &target, const QSSGSceneDesc::Property &property, OutputContext &output)
static QString outputInstanceTableAsset(const QSSGSceneDesc::Instancing &instancing, const QDir &outdir)
static void writeQml(const QSSGSceneDesc::Model &model, OutputContext &output)
QString colorToQml(const QColor &color)
void createTimelineAnimation(const QSSGSceneDesc::Animation &anim, QObject *parent, bool isEnabled, bool useBinaryKeyframes)
static QString getMeshExtension()
static const char * blockBegin()
static const char * blockBegin(OutputContext &output)
static void writeQml(const QSSGSceneDesc::Node &transform, OutputContext &output)
static QStringList expandComponents(const QString &value, QMetaType mt)
void writeQmlForResources(const QSSGSceneDesc::Scene::ResourceNodes &resources, OutputContext &output)
const char * qmlElementName()
QString sanitizeQmlId(const QString &id)
static QString toQmlStringLiteral(const QString &value)
static const char * blockEnd(OutputContext &output)
static QString outputTextureAsset(const QSSGSceneDesc::TextureData &textureData, const QDir &outdir)
static const char * comment()
static QTextStream & indent(OutputContext &output)
static QString toQuotedString(const QString &text)
static QString getIdForAnimation(const QByteArray &inName)
static QString getMeshFolder()
static void writeImportHeader(OutputContext &output, bool hasAnimation=false)
static QStringList expandComponentsPartially(const QString &value, QMetaType mt)
QPair< QString, QString > writeQmlForAnimation(const QSSGSceneDesc::Animation &anim, qsizetype index, OutputContext &output, bool useBinaryKeyframes=true, bool generateTimelineAnimations=true)
const char * getQmlElementName(const QSSGSceneDesc::Node &node)
static std::pair< QString, QString > copyTextureAsset(const QUrl &texturePath, OutputContext &output)
static std::pair< QString, QString > meshAssetName(const QSSGSceneDesc::Scene &scene, const QSSGSceneDesc::Mesh &meshNode, const QDir &outdir)
static const char * indent()
QString getAnimationSourceName(const QString &id, const QString &property, qsizetype index)
QString getMeshSourceName(const QString &name)
QString variantToQml(const QVariant &variant)
QString stripParentDirectory(const QString &filePath)
QString asString(QSSGSceneDesc::Animation::Channel::TargetProperty prop)
static void writeQmlForResourceNode(const QSSGSceneDesc::Node &node, OutputContext &output)
QString sanitizeQmlSourcePath(const QString &source, bool removeParentDirectory)
QString getTextureSourceName(const QString &name, const QString &fmt)
static void resetIdAllocator()
static QByteArrayView typeName(QMetaType mt)
void writeQml(const QSSGSceneDesc::Scene &scene, QTextStream &stream, const QDir &outdir, const QJsonObject &optionsObject)
static QString indentString(OutputContext &output)
void writeQml(const QSSGSceneDesc::Material &material, OutputContext &output)
static void writeQmlForNode(const QSSGSceneDesc::Node &node, OutputContext &output)
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, T &&value)
Q_QUICK3DASSETUTILS_EXPORT void addNode(Node &parent, Node &node)
static constexpr bool is_node_v
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, QFlags< T > value)
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, Value *value)
typename TypeMap< T >::type as_node_type_t
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, ViewValue view)
typename T::type as_scene_type_t
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, Value &&value, QSSGSceneDesc::Property::Type type=QSSGSceneDesc::Property::Type::Static)
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, QVariant &&value)
Q_QUICK3DASSETUTILS_EXPORT void destructNode(QSSGSceneDesc::Node &node)
static void setProperty(QSSGSceneDesc::Node &node, const char *name, Setter setter, const QVarLengthArray< NodeT *, Prealloc > &list)
Q_QUICK3DASSETUTILS_EXPORT void destructValue(QVariant &value)
Combined button and popup list for selecting options.
#define QSSG_DECLARE_NODE(NODE)
@ DesignStudioWorkarounds
QSSGQmlScopedIndent(OutputContext &out)
QStringList expandedProperties
TargetProperty targetProperty
KeyType getKeyType() const
QVariant getValue() const
ValueType getValueType() const
NodeList(void *const *data, qsizetype n)
bool get(const QQuick3DObject &, const void *[]) const override
typename FuncType< Setter >::Arg0Base ListT
bool set(QQuick3DObject &that, const char *, const void *value) override
constexpr PropertyListSetter(Setter fn)
bool set(QQuick3DObject &that, const char *, const QVariant &var) override
Ret(Class::*)(Arg) Setter
void doSet(QQuick3DObject &that, const QSSGSceneDesc::NodeList &nodeList)
constexpr PropertyList(ListFunc fn)
bool set(QQuick3DObject &that, const char *, const QVariant &var) override
ListType(Class::*)() ListFunc
bool set(QQuick3DObject &that, const char *, const void *value) override
bool get(const QQuick3DObject &, const void *[]) const override
constexpr PropertyProxySetter(Setter fn)
Ret(*)(QQuick3DObject &, const char *, Arg) Setter
bool set(QQuick3DObject &that, const char *name, const QVariant &var) override
bool set(QQuick3DObject &that, const char *name, const void *value) override
bool get(const QQuick3DObject &, const void *[]) const override
bool set(QQuick3DObject &that, const char *, const QVariant &var) override
Ret(Class::*)(Arg) Setter
constexpr PropertySetter(Setter fn)
bool set(QQuick3DObject &that, const char *, const void *value) override
bool get(const QQuick3DObject &, const void *[]) const override
QSSGSceneDesc::PropertyCall * call