9#include <QtCore/qurl.h>
10#include <QtCore/qbuffer.h>
12#include <QtGui/qimage.h>
13#include <QtGui/qimagereader.h>
14#include <QtGui/qimagewriter.h>
15#include <QtGui/qquaternion.h>
17#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
25 auto *
obj = qobject_cast<QQuick3DObject *>(
o ?
o : node->
obj);
29 auto *metaObj =
obj->metaObject();
30 int propertyIndex = metaObj->indexOfProperty(
property->name);
31 if (propertyIndex < 0) {
32 qWarning() <<
"QSSGSceneDesc: could not find property" <<
property->name <<
"in" <<
obj;
35 auto metaProp = metaObj->property(propertyIndex);
38 auto metaId =
property->value.metaType().id();
41 if (metaId == qMetaTypeId<QSSGSceneDesc::Node *>()) {
42 const auto *valueNode = qvariant_cast<QSSGSceneDesc::Node *>(
property->value);
43 QObject *
obj = valueNode ? valueNode->obj :
nullptr;
45 }
else if (metaId == qMetaTypeId<QSSGSceneDesc::Mesh *>()) {
49 const auto meshNode = qvariant_cast<const QSSGSceneDesc::Mesh *>(
property->value);
52 }
else if (metaId == qMetaTypeId<QUrl>()) {
53 const auto url = qvariant_cast<QUrl>(
property->value);
58 }
else if (metaId == qMetaTypeId<QSSGSceneDesc::Flag>() &&
property->call) {
60 const auto flag = qvariant_cast<QSSGSceneDesc::Flag>(
property->value);
61 property->call->set(*
obj,
property->name, flag.value);
62 qDebug() <<
"Flag special case, probably shouldn't happen" << node->
name <<
property->name <<
property->value << flag.value;
65 value =
property->value;
68 if (
value.metaType().id() == qMetaTypeId<QString>()) {
70 auto propType = metaProp.metaType();
71 if (propType.id() == qMetaTypeId<QVector3D>()) {
73 if (l.length() != 3) {
76 QVector3D vec3(l.at(0).toFloat(), l.at(1).toFloat(), l.at(2).toFloat());
79 }
else if (propType.id() == qMetaTypeId<QVector2D>()) {
81 if (l.length() != 2) {
84 QVector2D vec(l.at(0).toFloat(), l.at(1).toFloat());
87 }
else if (propType.id() == qMetaTypeId<QVector4D>()) {
89 if (l.length() != 2) {
92 QVector4D vec(l.at(0).toFloat(), l.at(1).toFloat(), l.at(2).toFloat(), l.at(3).toFloat());
95 }
else if (propType.id() == qMetaTypeId<QQuaternion>()) {
97 if (l.length() != 4) {
98 qWarning() <<
"Wrong format for QQuaternion:" <<
str;
100 QQuaternion quat(l.at(0).toFloat(), l.at(1).toFloat(), l.at(2).toFloat(), l.at(3).toFloat());
106 }
else if (
value.metaType().id() == qMetaTypeId<QSSGSceneDesc::NodeList*>()) {
107 auto qmlListVar = metaProp.read(
obj);
112 auto qmlList = qvariant_cast<QQmlListProperty<QQuick3DMaterial>>(qmlListVar);
113 auto nodeList = qvariant_cast<QSSGSceneDesc::NodeList*>(
value);
116 for (
int i = 0,
end = nodeList->count;
i !=
end; ++
i)
117 qmlList.append(&qmlList, qobject_cast<QQuick3DMaterial *>((*(head +
i))->obj));
120 qWarning() <<
"Can't handle list property type" << qmlListVar.metaType();
127 value.convert(metaProp.metaType());
135 bool success = metaProp.write(
obj,
value);
138 qWarning() <<
"Failure when setting property" <<
property->name <<
"to" <<
property->value <<
"maps to" <<
value
139 <<
"property metatype:" << metaProp.typeName();
158 const auto *node = qvariant_cast<Node *>(
var);
160 }
else if (
var.
metaType() == QMetaType::fromType<Mesh *>()) {
164 const auto meshNode = qvariant_cast<const Mesh *>(
var);
167 }
else if (
var.
metaType() == QMetaType::fromType<QUrl>()) {
168 const auto url = qvariant_cast<QUrl>(
var);
171 v->call->set(
obj,
v->name, &qurl);
172 }
else if (
var.
metaType().
id() == qMetaTypeId<QSSGSceneDesc::Flag>()) {
173 const auto flag = qvariant_cast<QSSGSceneDesc::Flag>(
var);
174 v->call->set(
obj,
v->name, flag.value);
181template<
typename GraphObjectType,
typename NodeType>
184 GraphObjectType *
obj = qobject_cast<GraphObjectType *>(node.obj);
186 node.obj = qobject_cast<QQuick3DObject *>(
obj =
new GraphObjectType);
204 const auto &texData = node.
data;
205 const bool isCompressed = ((node.
flgs &
quint8(QSSGSceneDesc::TextureData::Flags::Compressed)) != 0);
207 if (!texData.isEmpty()) {
213 image = imageReader.read();
215 qWarning() << imageReader.errorString();
217 const auto &
size = node.
sz;
221 if (!
image.isNull()) {
225 if (
image.colorCount()) {
236 image.convertTo(targetFormat);
239 const auto bytes =
image.sizeInBytes();
241 obj->setFormat(textureFormat);
242 obj->setTextureData(
QByteArray(
reinterpret_cast<const char *
>(
image.constBits()), bytes));
262 case Node::Type::Skeleton:
264 qWarning(
"Skeleton runtime import not supported");
269 obj = createRuntimeObject<QQuick3DSkeleton>(
static_cast<Skeleton &
>(node),
parent);
271 obj = qobject_cast<QQuick3DSkeleton *>(node.
obj);
276 case Node::Type::Joint:
277 obj = createRuntimeObject<QQuick3DJoint>(
static_cast<Joint &
>(node),
parent);
279 case Node::Type::Skin:
280 obj = createRuntimeObject<QQuick3DSkin>(
static_cast<Skin &
>(node),
parent);
282 case Node::Type::MorphTarget:
285 case Node::Type::Light:
287 auto &light =
static_cast<Light &
>(node);
288 if (light.runtimeType == Node::RuntimeType::DirectionalLight)
289 obj = createRuntimeObject<QQuick3DDirectionalLight>(light,
parent);
290 else if (light.runtimeType == Node::RuntimeType::PointLight)
291 obj = createRuntimeObject<QQuick3DPointLight>(light,
parent);
292 else if (light.runtimeType == Node::RuntimeType::SpotLight)
293 obj = createRuntimeObject<QQuick3DSpotLight>(light,
parent);
298 case Node::Type::Transform:
299 obj = createRuntimeObject<QQuick3DNode>(node,
parent);
301 case Node::Type::Camera:
304 if (
camera.runtimeType == Node::RuntimeType::OrthographicCamera)
306 else if (
camera.runtimeType == Node::RuntimeType::PerspectiveCamera)
308 else if (
camera.runtimeType == Node::RuntimeType::CustomCamera)
314 case Node::Type::Model:
315 obj = createRuntimeObject<QQuick3DModel>(
static_cast<Model &
>(node),
parent);
317 case Node::Type::Texture:
318 if (node.
runtimeType == Node::RuntimeType::TextureData)
320 else if (node.
runtimeType == Node::RuntimeType::Image2D)
321 obj = createRuntimeObject<QQuick3DTexture>(
static_cast<Texture &
>(node),
parent);
322 else if (node.
runtimeType == Node::RuntimeType::ImageCube)
323 obj = createRuntimeObject<QQuick3DCubeMapTexture>(
static_cast<Texture &
>(node),
parent);
327 case Node::Type::Material:
329 if (node.
runtimeType == Node::RuntimeType::PrincipledMaterial)
330 obj = createRuntimeObject<QQuick3DPrincipledMaterial>(
static_cast<Material &
>(node),
parent);
331 else if (node.
runtimeType == Node::RuntimeType::CustomMaterial)
332 obj = createRuntimeObject<QQuick3DCustomMaterial>(
static_cast<Material &
>(node),
parent);
333 else if (node.
runtimeType == Node::RuntimeType::SpecularGlossyMaterial)
334 obj = createRuntimeObject<QQuick3DSpecularGlossyMaterial>(
static_cast<Material &
>(node),
parent);
339 case Node::Type::Mesh:
345 if (
obj && traverseChildrenAndSetProperties) {
355 qWarning(
"Incomplete scene description (missing plugin?)");
363 auto root =
scene.root;
364 for (
const auto &resource :
scene.resources)
371 for (
const auto &resource :
scene.resources) {
372 if (resource->obj !=
nullptr)
378 bool isFirstAnimation =
true;
379 for (
const auto &anim:
scene.animations) {
381 if (isFirstAnimation)
382 isFirstAnimation =
false;
385 return qobject_cast<QQuick3DNode *>(
scene.root->obj);
\inmodule QtCore \reentrant
The QImageReader class provides a format independent interface for reading images from files or other...
Format
The following image formats are available in Qt.
@ Format_RGBA8888_Premultiplied
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
The QQuaternion class represents a quaternion consisting of a vector and scalar.
static QQuick3DObjectPrivate * get(QQuick3DObject *item)
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
\qmltype TextureData \inherits Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DTextureData
Format
Returns the color format of the texture data assigned in \l textureData property.
static void registerMeshData(const QString &assetId, const QVector< QSSGMesh::Mesh > &meshData)
static QString runtimeMeshSourceName(const QString &assetId, qsizetype meshId)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory=QString(), UserInputResolutionOptions options=DefaultResolution)
Returns a valid URL from a user supplied userInput string if one can be deduced.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QMetaType metaType() const
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.
QSet< QString >::iterator it
void createTimelineAnimation(const QSSGSceneDesc::Animation &anim, QObject *parent, bool isEnabled, bool useBinaryKeyframes)
Q_QUICK3DASSETUTILS_EXPORT void applyPropertyValue(const QSSGSceneDesc::Node *node, QObject *obj, QSSGSceneDesc::Property *property)
Q_QUICK3DASSETUTILS_EXPORT QQuick3DNode * createScene(QQuick3DNode &parent, const QSSGSceneDesc::Scene &scene)
Q_QUICK3DASSETUTILS_EXPORT void createGraphObject(QSSGSceneDesc::Node &node, QQuick3DObject &parent, bool traverseChildrenAndSetProperties=true)
Combined button and popup list for selecting options.
static const QCssKnownValue properties[NumProperties - 1]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield GLuint readBuffer
GraphObjectType * createRuntimeObject(NodeType &node, QQuick3DObject &parent)
QQuick3DTextureData * createRuntimeObject< QQuick3DTextureData >(QSSGSceneDesc::TextureData &node, QQuick3DObject &parent)
static void setProperties(QQuick3DObject &obj, const QSSGSceneDesc::Node &node, const QString &workingDir={})
QUrl url("example.com")
[constructor-url-reference]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent