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
qssggltfdocument_p.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#ifndef QSSGGLTFDOCUMENT_P_H
6#define QSSGGLTFDOCUMENT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DGltf/qtquick3dgltfexports.h>
20
21#include <QtCore/qbytearray.h>
22#include <QtCore/qhash.h>
23#include <QtCore/qjsonobject.h>
24#include <QtCore/qlist.h>
25#include <QtCore/qmath.h>
26#include <QtCore/qstring.h>
27#include <QtCore/qstringlist.h>
28#include <QtGui/qmatrix4x4.h>
29#include <QtGui/qquaternion.h>
30#include <QtGui/qvector2d.h>
31#include <QtGui/qvector3d.h>
32#include <QtGui/qvector4d.h>
33
34#include <optional>
35
36QT_BEGIN_NAMESPACE
37
38// A value-struct representation of a glTF 2.0 document, mirroring the JSON
39// schema. Object references are integer indices into the document-level
40// arrays, exactly as in the format; -1 means "not set". Data specific to
41// supported extensions is parsed into typed members; anything else stays
42// available through the raw extension objects.
43namespace QSSGGltf {
44
52
53struct Buffer
54{
57 QByteArray data; // resolved contents (GLB BIN chunk, data: URI, or external file)
58};
59
61{
62 int buffer = -1;
65 int byteStride = 0; // 0 = tightly packed
66 int target = 0;
68};
69
71{
72 // Values match the glTF componentType constants
73 enum class ComponentType {
74 Byte = 5120,
76 Short = 5122,
79 Float = 5126
80 };
90
100
101 int bufferView = -1; // -1 = all zeros (unless sparse)
106 bool normalized = false;
107 QList<double> min;
108 QList<double> max;
109 std::optional<Sparse> sparse;
111
112 static int componentByteSize(ComponentType componentType)
113 {
114 switch (componentType) {
117 return 1;
120 return 2;
123 return 4;
124 }
125 return 0;
126 }
127
128 static int componentCount(Type type)
129 {
130 switch (type) {
131 case Type::Scalar: return 1;
132 case Type::Vec2: return 2;
133 case Type::Vec3: return 3;
134 case Type::Vec4: return 4;
135 case Type::Mat2: return 4;
136 case Type::Mat3: return 9;
137 case Type::Mat4: return 16;
138 }
139 return 0;
140 }
141
146};
147
155
157{
158 // Values match the glTF/GL filter and wrap constants; 0 = unspecified
167 enum WrapMode {
168 ClampToEdge = 33071,
170 Repeat = 10497
171 };
172
173 int magFilter = 0;
174 int minFilter = 0;
178};
179
187
188struct TextureTransform // KHR_texture_transform
189{
190 QVector2D offset { 0.0f, 0.0f };
191 QVector2D scale { 1.0f, 1.0f };
192 float rotation = 0.0f;
193 int texCoord = -1; // -1 = keep the TextureInfo texCoord
194};
195
197{
198 int index = -1;
199 int texCoord = 0;
200 // scale for normalTexture, strength for occlusionTexture; 1.0 otherwise
201 float scaleOrStrength = 1.0f;
203
204 bool isSet() const { return index >= 0; }
205};
206
208{
209 enum class AlphaMode {
213 };
214
215 struct SpecularGlossiness // KHR_materials_pbrSpecularGlossiness
216 {
217 QVector4D diffuseFactor { 1.0f, 1.0f, 1.0f, 1.0f };
219 QVector3D specularFactor { 1.0f, 1.0f, 1.0f };
220 float glossinessFactor = 1.0f;
222 };
223
224 struct Clearcoat // KHR_materials_clearcoat
225 {
226 float clearcoatFactor = 0.0f;
230 TextureInfo clearcoatNormalTexture; // scaleOrStrength = normal scale
231 };
232
233 struct Transmission // KHR_materials_transmission
234 {
235 float transmissionFactor = 0.0f;
237 };
238
239 struct Volume // KHR_materials_volume
240 {
241 float thicknessFactor = 0.0f;
243 float attenuationDistance = 0.0f; // 0 = +infinity per spec default
244 QVector3D attenuationColor { 1.0f, 1.0f, 1.0f };
245 };
246
247 struct Specular // KHR_materials_specular
248 {
249 float specularFactor = 1.0f;
251 QVector3D specularColorFactor { 1.0f, 1.0f, 1.0f };
253 };
254
256
257 // pbrMetallicRoughness
258 QVector4D baseColorFactor { 1.0f, 1.0f, 1.0f, 1.0f };
260 float metallicFactor = 1.0f;
261 float roughnessFactor = 1.0f;
263
264 TextureInfo normalTexture; // scaleOrStrength = scale
265 TextureInfo occlusionTexture; // scaleOrStrength = strength
267 QVector3D emissiveFactor { 0.0f, 0.0f, 0.0f };
268
270 float alphaCutoff = 0.5f;
271 bool doubleSided = false;
272
273 // Extensions
274 bool unlit = false; // KHR_materials_unlit
278 std::optional<Volume> volume;
279 std::optional<float> ior; // KHR_materials_ior
280 std::optional<float> emissiveStrength; // KHR_materials_emissive_strength
282
283 QJsonObject extensions; // raw, incl. unsupported ones (sheen, iridescence, ...)
284};
285
287{
288 // Values match the glTF primitive.mode constants
298
299 QHash<QByteArray, int> attributes; // semantic (POSITION, NORMAL, ...) -> accessor
300 int indices = -1;
301 int material = -1;
303 QList<QHash<QByteArray, int>> targets; // morph targets
305};
306
307struct Mesh
308{
310 QList<float> weights; // default morph target weights
312};
313
314struct Node
315{
317 int mesh = -1;
318 int skin = -1;
319 int camera = -1;
320 int light = -1; // KHR_lights_punctual
321 bool hasMatrix = false;
323 QVector3D translation { 0.0f, 0.0f, 0.0f };
325 QVector3D scale { 1.0f, 1.0f, 1.0f };
326 QList<float> weights; // overrides mesh.weights
329};
330
331struct Skin
332{
333 int inverseBindMatrices = -1; // -1 = identity matrices
334 int skeleton = -1;
337};
338
340{
346
347 int input = -1; // accessor with key times (seconds)
348 int output = -1; // accessor with key values
350};
351
365
372
373struct Camera
374{
379
381 // perspective
382 float aspectRatio = 0.0f; // 0 = unspecified
383 float yfov = 0.0f; // radians
384 // orthographic
385 float xmag = 0.0f;
386 float ymag = 0.0f;
387 // shared
388 float znear = 0.0f;
389 float zfar = 0.0f; // 0 = infinite for perspective
391};
392
393struct Light // KHR_lights_punctual
394{
395 enum class Type {
399 };
400
402 QVector3D color { 1.0f, 1.0f, 1.0f };
403 float intensity = 1.0f; // candela for point/spot, lux for directional
404 float range = 0.0f; // 0 = +infinity per spec default
405 // spot only
406 float innerConeAngle = 0.0f; // radians
407 float outerConeAngle = qDegreesToRadians(45.0f);
409};
410
411struct Scene
412{
415};
416
417} // namespace QSSGGltf
418
419class Q_QUICK3DGLTF_EXPORT QSSGGltfDocument
420{
421public:
422 QSSGGltf::Asset asset;
423 QList<QSSGGltf::Buffer> buffers;
424 QList<QSSGGltf::BufferView> bufferViews;
425 QList<QSSGGltf::Accessor> accessors;
426 QList<QSSGGltf::Image> images;
427 QList<QSSGGltf::Sampler> samplers;
428 QList<QSSGGltf::Texture> textures;
429 QList<QSSGGltf::Material> materials;
430 QList<QSSGGltf::Mesh> meshes;
431 QList<QSSGGltf::Node> nodes;
432 QList<QSSGGltf::Skin> skins;
433 QList<QSSGGltf::Animation> animations;
434 QList<QSSGGltf::Camera> cameras;
435 QList<QSSGGltf::Light> lights; // KHR_lights_punctual
436 QList<QSSGGltf::Scene> scenes;
437 int scene = -1;
438
439 QStringList extensionsUsed;
440 QStringList extensionsRequired;
441 QJsonObject rootExtensions;
442
443 // Directory the document was loaded from, used to resolve relative URIs.
444 // Local filesystem or qrc (":/...") path.
445 QString baseDir;
446};
447
448QT_END_NAMESPACE
449
450#endif // QSSGGLTFDOCUMENT_P_H
ComponentType componentType
static int componentByteSize(ComponentType componentType)
std::optional< Sparse > sparse
static int componentCount(Type type)
QList< AnimationSampler > samplers
QList< AnimationChannel > channels
std::optional< Specular > specular
std::optional< Clearcoat > clearcoat
TextureInfo metallicRoughnessTexture
std::optional< float > ior
std::optional< SpecularGlossiness > specularGlossiness
std::optional< Volume > volume
std::optional< Transmission > transmission
std::optional< float > emissiveStrength
QHash< QByteArray, int > attributes
QList< QHash< QByteArray, int > > targets
QList< float > weights
QList< MeshPrimitive > primitives
QList< int > children
QList< float > weights
std::optional< TextureTransform > transform