Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
gltfsceneconverter.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#pragma once
6
7#include <QtQuick3DAssetUtils/private/qssgscenedesc_p.h>
8#include <QtQuick3DGltf/private/qssggltfdocument_p.h>
9#include <QtQuick3DUtils/private/qssgmesh_p.h>
10
11#include <QtCore/qfileinfo.h>
12#include <QtCore/qhash.h>
13#include <QtCore/qjsonobject.h>
14
16
18{
19 int count = 0;
20 bool hasPositions = false;
21 bool hasNormals = false;
22 bool hasTangents = false;
23};
24
25// Converts a QSSGGltfDocument into a QSSGSceneDesc::Scene
27{
28public:
29 struct Options
30 {
36 bool generateMipMaps = false;
37 bool generateMeshLODs = false;
38 float lodNormalMergeAngle = 60.0f;
39 float lodNormalSplitAngle = 25.0f;
40 float globalScaleValue = 1.0f;
41 float animationSampleRate = 30.0f;
42 QString materialVariant; // KHR_materials_variants variant name to import
43 int materialVariantIndex = -1; // resolved from materialVariant per document
44 };
45
46 // Returns an empty string on success, the error message otherwise.
47 QString convert(const QSSGGltfDocument &document, const QJsonObject &optionsObject,
48 const QFileInfo &sourceFile, QSSGSceneDesc::Scene &targetScene);
49
50private:
51 void processNode(int nodeIndex, QSSGSceneDesc::Node &parent);
52 QSSGSceneDesc::Node *createSceneNode(const QSSGGltf::Node &node);
53 void setNodeProperties(QSSGSceneDesc::Node &target, const QSSGGltf::Node &source);
54 void setCameraProperties(QSSGSceneDesc::Camera &target, const QSSGGltf::Camera &source);
55 void setLightProperties(QSSGSceneDesc::Light &target, const QSSGGltf::Light &source);
56 void convertAnimations();
57 void convertSkins();
58 QSSGSceneDesc::Instancing *convertInstancing(const QSSGGltf::Node &source, QSSGSceneDesc::Node &owner);
59 void setModelProperties(QSSGSceneDesc::Model &target, const QSSGGltf::Node &source, int nodeIndex);
60 void setMaterialProperties(QSSGSceneDesc::Material &target, const QSSGGltf::Material &source);
61 void setSpecularGlossyProperties(QSSGSceneDesc::Material &target, const QSSGGltf::Material &source);
62 QSSGSceneDesc::Material *ensureMaterial(int materialIndex, QSSGSceneDesc::Node &owner);
63 QSSGSceneDesc::Texture *ensureTexture(const QSSGGltf::TextureInfo &textureInfo, QSSGSceneDesc::Node &owner);
64
65 static Options parseOptions(const QJsonObject &optionsObject);
66
67 const QSSGGltfDocument *m_document = nullptr;
68 QSSGSceneDesc::Scene *m_scene = nullptr;
69 Options m_options;
70 QHash<int, QSSGSceneDesc::Node *> m_nodeMap; // glTF node index -> scene node
71 QHash<int, QSSGSceneDesc::Mesh *> m_meshMap; // glTF mesh index -> mesh resource
72 QHash<int, QList<int>> m_meshUsedPrimitives; // glTF mesh index -> primitives that became subsets
73 QHash<int, GltfMorphTargetInfo> m_meshMorphInfo; // glTF mesh index -> morph target info
74 struct BuiltMesh {
75 QSSGMesh::Mesh mesh;
76 QList<int> usedPrimitives;
77 GltfMorphTargetInfo morphInfo;
78 };
79 QHash<int, BuiltMesh> m_builtMeshes; // glTF mesh index -> pre-built mesh data
80 QHash<int, QList<QSSGSceneDesc::MorphTarget *>> m_morphTargetMap; // glTF node index -> morph target nodes
81 QHash<int, QSSGSceneDesc::Material *> m_materialMap; // glTF material index -> material (-1 = default)
82 QHash<QByteArray, QSSGSceneDesc::Texture *> m_textureMap; // dedup key -> texture
83 QHash<int, QSSGSceneDesc::TextureData *> m_textureDataMap; // glTF image index -> embedded data
84 QHash<int, QSSGSceneDesc::Skin *> m_skinMap; // glTF skin index -> skin resource
85};
86
87QT_END_NAMESPACE
QString type() const override
QJsonObject importOptions() const override
QString name() const override
int priority() const override
QString import(const QString &sourceFile, const QDir &savePath, const QJsonObject &options, QStringList *generatedFiles) override
QStringList inputExtensions() const override
QString import(const QUrl &sourceFile, const QJsonObject &options, QSSGSceneDesc::Scene &scene) override
QString typeDescription() const override
QString outputExtension() const override
QString convert(const QSSGGltfDocument &document, const QJsonObject &optionsObject, const QFileInfo &sourceFile, QSSGSceneDesc::Scene &targetScene)
static QString importImp(const QUrl &url, const QJsonObject &options, QSSGSceneDesc::Scene &targetScene)
Combined button and popup list for selecting options.