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>
45#include <QtQuick3DUtils/private/qssginvasivelinkedlist_p.h>
47#include <QtGui/qquaternion.h>
71struct Q_QUICK3DASSETUTILS_EXPORT
Scene
98Q_QUICK3DASSETUTILS_EXPORT
void destructValue(QVariant &value);
119 destructValue(value);
128 const auto size =
sizeof(Node *) * n;
129 head =
reinterpret_cast<Node **>(malloc(size));
130 memcpy(
head, data, size);
138struct Q_QUICK3DASSETUTILS_EXPORT
Node
187#define QSSG_DECLARE_NODE(NODE) static_assert
188 (is_node_v<NODE>, #NODE " - does not inherit from Node!"); template
189 <> struct TypeMap<NODE::type> { using type = QSSGSceneDesc::NODE; };
326 case ValueType::Number:
328 case ValueType::Vec2:
329 return value.toVector2D();
330 case ValueType::Vec3:
331 return value.toVector3D();
332 case ValueType::Vec4:
334 case ValueType::Quaternion:
335 return QQuaternion(value);
396Q_QUICK3DASSETUTILS_EXPORT
void addNode(Node &parent, Node &node);
399Q_QUICK3DASSETUTILS_EXPORT
void addNode(Scene &scene, Node &node);
417template <
typename R,
typename... A>
428template <
typename R,
typename C,
typename... A>
431 enum {
value =
sizeof... (A) == 1 };
439template <
typename T,
typename C>
449template <
typename Ret,
typename Arg>
452 using Setter = Ret (*)(QQuick3DObject &,
const char *, Arg);
455 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
456 bool set(QQuick3DObject &that,
const char *name,
const void *value)
override
464 bool set(QQuick3DObject &that,
const char *name,
const QVariant &var)
override
471template <
typename Ret,
typename Class,
typename Arg>
477 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
478 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
481 (qobject_cast<Class *>(&that)->*
call)(
reinterpret_cast<
typename FuncType<
Setter>::Arg0>(
const_cast<
void *>(value)));
483 (qobject_cast<Class *>(&that)->*
call)(*
reinterpret_cast<
typename FuncType<
Setter>::Arg0Base *>(
const_cast<
void *>(value)));
487 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
489 (qobject_cast<Class *>(&that)->*
call)(qvariant_cast<
typename FuncType<
Setter>::Arg0Base>(var));
494template <
typename Ret,
typename Class,
typename Arg>
502 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
503 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
505 if (
const auto listView =
reinterpret_cast<
const ListView *>(value)) {
506 if (listView->count > 0) {
507 const auto begin =
reinterpret_cast<It *>(listView
->data);
508 const auto end =
reinterpret_cast<It *>(listView
->data) + listView->count;
509 (qobject_cast<Class *>(&that)->*
call)(
ListT{begin, end});
511 (qobject_cast<Class *>(&that)->*
call)(
ListT{});
518 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
520 if (
const auto listView = qvariant_cast<
const ListView *>(var)) {
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{});
533template <
typename Class,
typename T,
template <
typename>
typename List>
543 bool get(
const QQuick3DObject &,
const void *[])
const override {
return false; }
549 auto head =
reinterpret_cast<as_node_type_t<T> **>(nodeList
.head);
550 for (
int i = 0, end = nodeList.count; i != end; ++i)
551 list.append(&list, qobject_cast<T *>((*(head + i))->obj));
554 bool set(QQuick3DObject &that,
const char *,
const void *value)
override
558 doSet(that, nodeList);
564 bool set(QQuick3DObject &that,
const char *,
const QVariant &var)
override
568 doSet(that, *nodeList);
575template <
typename NodeT>
579template <
typename Setter,
typename T>
587template<
typename Setter,
typename T, if_compatible_t<Setter, T> =
false>
590 Q_ASSERT(node.scene);
594 prop->value = QVariant::fromValue(std::forward<T>(value));
595 node.properties.push_back(prop);
598template<
typename Setter,
typename T, if_compatible_t<Setter, QFlags<T>> =
false>
601 Q_ASSERT(node.scene);
605 prop->value = QVariant::fromValue(Flag{ QMetaEnum::fromType<rm_cvref_t<T>>(), value.toInt() });
606 node.properties.push_back(prop);
610template<
typename Setter,
typename T, if_compatible_t<Setter, QList<T>> =
false>
613 Q_ASSERT(node.scene);
614 static_assert(!
std::is_pointer_v<T>,
"Type cannot be a pointer!");
615 static_assert(
std::is_trivially_destructible_v<T> &&
std::is_trivially_copy_constructible_v<T>,
616 "List parameter type needs to be trivially constructable and trivially destructible!");
618 const auto count = value.size();
619 void *data =
nullptr;
621 const auto asize = count *
sizeof(T);
622 data = malloc(asize);
623 memcpy(data, value.constData(), asize);
628 prop->value = QVariant::fromValue(
new ListView{ QMetaType::fromType<rm_cvref_t<T>>(), data, count });
629 node.properties.push_back(prop);
637template<
typename Setter>
640 Q_ASSERT(node.scene);
641 Property *prop =
new Property;
643 prop->call =
new PropertySetter(setter);
645 node.properties.push_back(prop);
648template<
typename Setter,
typename Value, if_compatible_proxy_t<Setter, Value> =
true>
651 Q_ASSERT(node.scene);
652 static_assert(std::is_trivially_destructible_v<rm_cvref_t<Value>>,
"Value needs to be trivially destructible!");
653 Property *prop =
new Property;
655 prop->call =
new PropertyProxySetter(setter);
656 prop->value = QVariant::fromValue(value);
658 node.properties.push_back(prop);
661template<
typename Setter,
typename ViewValue, if_compatible_t<Setter,
typename ViewValue::type> =
false>
664 Q_ASSERT(node.scene);
665 static_assert(
std::is_same_v<
typename ViewValue::type,
typename FuncType<Setter>::Arg0Base>,
"Type cannot be mapped to slot argument");
666 Property *prop =
new Property;
668 prop->call =
new PropertySetter(setter);
669 prop->value = QVariant::fromValue(view);
670 node.properties.push_back(prop);
673template<
typename Setter,
typename Value, if_compatible_t<Setter, as_scene_type_t<Value> *> =
true>
676 Q_ASSERT(node.scene);
677 Property *prop =
new Property;
679 prop->call =
new PropertySetter(setter);
681 prop->value = QVariant::fromValue(
static_cast<Node *>(value));
682 node.properties.push_back(prop);
686template<
typename Setter,
typename NodeT, qsizetype Prealloc, if_compatible_node_list_t<Setter, NodeT> =
true>
689 Q_ASSERT(node.scene);
690 if (!list.isEmpty()) {
691 NodeList *l =
new NodeList(
reinterpret_cast<
void *
const*>(list.constData()), list.count());
693 Property *prop =
new Property;
695 prop->call =
new PropertyList(setter);
696 prop->value = QVariant::fromValue(l);
697 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)
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