4#ifndef QSSGSCENEDESCRIPTION_P_H
5#define QSSGSCENEDESCRIPTION_P_H
7#include <QtQuick3DAssetUtils/private/qtquick3dassetutilsglobal_p.h>
8#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
9#include <QtQuick3DRuntimeRender/private/qssgperframeallocator_p.h>
10#include <QtQuick3DUtils/private/qssgmesh_p.h>
12#include <QtCore/qlist.h>
13#include <QtCore/qhash.h>
14#include <QtCore/qvariant.h>
15#include <QtCore/qflags.h>
16#include <QtQml/qqmllist.h>
19#include <QtQuick3D/private/qquick3dobject_p.h>
21#include <QtQuick3D/private/qquick3dcustommaterial_p.h>
22#include <QtQuick3D/private/qquick3ddefaultmaterial_p.h>
23#include <QtQuick3D/private/qquick3dprincipledmaterial_p.h>
24#include <QtQuick3D/private/qquick3dspecularglossymaterial_p.h>
25#include <QtQuick3D/private/qquick3dmodel_p.h>
27#include <QtQuick3D/private/qquick3dorthographiccamera_p.h>
28#include <QtQuick3D/private/qquick3dperspectivecamera_p.h>
29#include <QtQuick3D/private/qquick3dcustomcamera_p.h>
31#include <QtQuick3D/private/qquick3ddirectionallight_p.h>
32#include <QtQuick3D/private/qquick3dpointlight_p.h>
33#include <QtQuick3D/private/qquick3dspotlight_p.h>
35#include <QtQuick3D/private/qquick3dtexture_p.h>
36#include <QtQuick3D/private/qquick3dcubemaptexture_p.h>
37#include <QtQuick3D/private/qquick3dtexturedata_p.h>
39#include <QtQuick3D/private/qquick3dskeleton_p.h>
40#include <QtQuick3D/private/qquick3djoint_p.h>
43#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
45#include <QtGui/qquaternion.h>
69struct Q_QUICK3DASSETUTILS_EXPORT
Scene
96Q_QUICK3DASSETUTILS_EXPORT
void destructValue(QVariant &value);
117 destructValue(value);
126 const auto size =
sizeof(Node *) * n;
127 head =
reinterpret_cast<Node **>(malloc(size));
128 memcpy(
head, data, size);
136struct Q_QUICK3DASSETUTILS_EXPORT
Node
185#define QSSG_DECLARE_NODE(NODE) static_assert
186 (is_node_v<NODE>, #NODE " - does not inherit from Node!"); template
187 <> struct TypeMap<NODE::type> { using type = QSSGSceneDesc::NODE; };
324 case ValueType::Number:
326 case ValueType::Vec2:
327 return value.toVector2D();
328 case ValueType::Vec3:
329 return value.toVector3D();
330 case ValueType::Vec4:
332 case ValueType::Quaternion:
333 return QQuaternion(value);
394Q_QUICK3DASSETUTILS_EXPORT
void addNode(Node &parent, Node &node);
397Q_QUICK3DASSETUTILS_EXPORT
void addNode(Scene &scene, Node &node);
415template <
typename R,
typename... A>
426template <
typename R,
typename C,
typename... A>
429 enum {
value =
sizeof... (A) == 1 };
437template <
typename T,
typename C>
447template <
typename Ret,
typename Arg>
450 using Setter = Ret (*)(QQuick3DObject &,
const char *, Arg);
453 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
454 bool set(QQuick3DObject &that,
const char *name,
const void *value)
override
462 bool set(QQuick3DObject &that,
const char *name,
const QVariant &var)
override
469template <
typename Ret,
typename Class,
typename Arg>
475 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
476 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
479 (qobject_cast<Class *>(&that)->*
call)(
reinterpret_cast<
typename FuncType<
Setter>::Arg0>(
const_cast<
void *>(value)));
481 (qobject_cast<Class *>(&that)->*
call)(*
reinterpret_cast<
typename FuncType<
Setter>::Arg0Base *>(
const_cast<
void *>(value)));
485 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
487 (qobject_cast<Class *>(&that)->*
call)(qvariant_cast<
typename FuncType<
Setter>::Arg0Base>(var));
492template <
typename Ret,
typename Class,
typename Arg>
500 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
501 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
503 if (
const auto listView =
reinterpret_cast<
const ListView *>(value)) {
504 if (listView->count > 0) {
505 const auto begin =
reinterpret_cast<It *>(listView
->data);
506 const auto end =
reinterpret_cast<It *>(listView
->data) + listView->count;
507 (qobject_cast<Class *>(&that)->*
call)(
ListT{begin, end});
509 (qobject_cast<Class *>(&that)->*
call)(
ListT{});
516 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
518 if (
const auto listView = qvariant_cast<
const ListView *>(var)) {
519 if (listView->count > 0) {
520 const auto begin =
reinterpret_cast<It *>(listView->data);
521 const auto end =
reinterpret_cast<It *>(listView->data) + listView->count;
522 (qobject_cast<Class *>(&that)->*
call)(
ListT{begin, end});
524 (qobject_cast<Class *>(&that)->*
call)(
ListT{});
531template <
typename Class,
typename T,
template <
typename>
typename List>
541 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
547 auto head =
reinterpret_cast<as_node_type_t<T> **>(nodeList
.head);
548 for (
int i = 0, end = nodeList.count; i != end; ++i)
549 list.append(&list, qobject_cast<T *>((*(head + i))->obj));
552 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
556 doSet(that, nodeList);
562 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
566 doSet(that, *nodeList);
573template <
typename NodeT>
577template <
typename Setter,
typename T>
585template<
typename Setter,
typename T, if_compatible_t<Setter, T> =
false>
588 Q_ASSERT(node.scene);
592 prop->value = QVariant::fromValue(std::forward<T>(value));
593 node.properties.push_back(prop);
596template<
typename Setter,
typename T, if_compatible_t<Setter, QFlags<T>> =
false>
599 Q_ASSERT(node.scene);
603 prop->value = QVariant::fromValue(Flag{ QMetaEnum::fromType<rm_cvref_t<T>>(), value.toInt() });
604 node.properties.push_back(prop);
608template<
typename Setter,
typename T, if_compatible_t<Setter, QList<T>> =
false>
611 Q_ASSERT(node.scene);
612 static_assert(!
std::is_pointer_v<T>,
"Type cannot be a pointer!");
613 static_assert(
std::is_trivially_destructible_v<T> &&
std::is_trivially_copy_constructible_v<T>,
614 "List parameter type needs to be trivially constructable and trivially destructible!");
616 const auto count = value.size();
617 void *data =
nullptr;
619 const auto asize = count *
sizeof(T);
620 data = malloc(asize);
621 memcpy(data, value.constData(), asize);
626 prop->value = QVariant::fromValue(
new ListView{ QMetaType::fromType<rm_cvref_t<T>>(), data, count });
627 node.properties.push_back(prop);
635template<
typename Setter>
638 Q_ASSERT(node.scene);
639 Property *prop =
new Property;
641 prop->call =
new PropertySetter(setter);
643 node.properties.push_back(prop);
646template<
typename Setter,
typename Value, if_compatible_proxy_t<Setter, Value> =
true>
649 Q_ASSERT(node.scene);
650 static_assert(std::is_trivially_destructible_v<rm_cvref_t<Value>>,
"Value needs to be trivially destructible!");
651 Property *prop =
new Property;
653 prop->call =
new PropertyProxySetter(setter);
654 prop->value = QVariant::fromValue(value);
656 node.properties.push_back(prop);
659template<
typename Setter,
typename ViewValue, if_compatible_t<Setter,
typename ViewValue::type> =
false>
662 Q_ASSERT(node.scene);
663 static_assert(
std::is_same_v<
typename ViewValue::type,
typename FuncType<Setter>::Arg0Base>,
"Type cannot be mapped to slot argument");
664 Property *prop =
new Property;
666 prop->call =
new PropertySetter(setter);
667 prop->value = QVariant::fromValue(view);
668 node.properties.push_back(prop);
671template<
typename Setter,
typename Value, if_compatible_t<Setter, as_scene_type_t<Value> *> =
true>
674 Q_ASSERT(node.scene);
675 Property *prop =
new Property;
677 prop->call =
new PropertySetter(setter);
679 prop->value = QVariant::fromValue(
static_cast<Node *>(value));
680 node.properties.push_back(prop);
684template<
typename Setter,
typename NodeT, qsizetype Prealloc, if_compatible_node_list_t<Setter, NodeT> =
true>
687 Q_ASSERT(node.scene);
688 if (!list.isEmpty()) {
689 NodeList *l =
new NodeList(
reinterpret_cast<
void *
const*>(list.constData()), list.count());
691 Property *prop =
new Property;
693 prop->call =
new PropertyList(setter);
694 prop->value = QVariant::fromValue(l);
695 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 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 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 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 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)
static void writeNodeProperties(const QSSGSceneDesc::Node &node, OutputContext &output)
QPair< QString, QString > writeQmlForAnimation(const QSSGSceneDesc::Animation &anim, qsizetype index, OutputContext &output, bool useBinaryKeyframes=true, bool generateTimelineAnimations=true)
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 * getQmlElementName(const QSSGSceneDesc::Node &node)
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 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)
#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