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 bool meshoptFallback = false; // EXT_meshopt_compression fallback, never loaded
59};
60
62{
63 int buffer = -1;
66 int byteStride = 0; // 0 = tightly packed
67 int target = 0;
69};
70
72{
73 // Values match the glTF componentType constants
74 enum class ComponentType {
75 Byte = 5120,
77 Short = 5122,
80 Float = 5126
81 };
91
101
102 int bufferView = -1; // -1 = all zeros (unless sparse)
107 bool normalized = false;
108 QList<double> min;
109 QList<double> max;
110 std::optional<Sparse> sparse;
112
113 static int componentByteSize(ComponentType componentType)
114 {
115 switch (componentType) {
118 return 1;
121 return 2;
124 return 4;
125 }
126 return 0;
127 }
128
129 static int componentCount(Type type)
130 {
131 switch (type) {
132 case Type::Scalar: return 1;
133 case Type::Vec2: return 2;
134 case Type::Vec3: return 3;
135 case Type::Vec4: return 4;
136 case Type::Mat2: return 4;
137 case Type::Mat3: return 9;
138 case Type::Mat4: return 16;
139 }
140 return 0;
141 }
142
147};
148
156
158{
159 // Values match the glTF/GL filter and wrap constants; 0 = unspecified
168 enum WrapMode {
169 ClampToEdge = 33071,
171 Repeat = 10497
172 };
173
174 int magFilter = 0;
175 int minFilter = 0;
179};
180
182{
183 int sampler = -1;
184 int source = -1;
185 int webpSource = -1; // EXT_texture_webp; preferred over source when set
188};
189
190struct TextureTransform // KHR_texture_transform
191{
192 QVector2D offset { 0.0f, 0.0f };
193 QVector2D scale { 1.0f, 1.0f };
194 float rotation = 0.0f;
195 int texCoord = -1; // -1 = keep the TextureInfo texCoord
196};
197
199{
200 int index = -1;
201 int texCoord = 0;
202 // scale for normalTexture, strength for occlusionTexture; 1.0 otherwise
203 float scaleOrStrength = 1.0f;
205
206 bool isSet() const { return index >= 0; }
207};
208
210{
211 enum class AlphaMode {
215 };
216
217 struct SpecularGlossiness // KHR_materials_pbrSpecularGlossiness
218 {
219 QVector4D diffuseFactor { 1.0f, 1.0f, 1.0f, 1.0f };
221 QVector3D specularFactor { 1.0f, 1.0f, 1.0f };
222 float glossinessFactor = 1.0f;
224 };
225
226 struct Clearcoat // KHR_materials_clearcoat
227 {
228 float clearcoatFactor = 0.0f;
232 TextureInfo clearcoatNormalTexture; // scaleOrStrength = normal scale
233 };
234
235 struct Transmission // KHR_materials_transmission
236 {
237 float transmissionFactor = 0.0f;
239 };
240
241 struct Volume // KHR_materials_volume
242 {
243 float thicknessFactor = 0.0f;
245 float attenuationDistance = 0.0f; // 0 = +infinity per spec default
246 QVector3D attenuationColor { 1.0f, 1.0f, 1.0f };
247 };
248
249 struct Specular // KHR_materials_specular
250 {
251 float specularFactor = 1.0f;
253 QVector3D specularColorFactor { 1.0f, 1.0f, 1.0f };
255 };
256
257 struct Sheen // KHR_materials_sheen
258 {
259 QVector3D sheenColorFactor { 0.0f, 0.0f, 0.0f };
263 };
264
265 struct Anisotropy // KHR_materials_anisotropy
266 {
267 float anisotropyStrength = 0.0f;
268 float anisotropyRotation = 0.0f; // radians
270 };
271
272 struct Iridescence // KHR_materials_iridescence
273 {
274 float iridescenceFactor = 0.0f;
276 float iridescenceIor = 1.3f;
277 float iridescenceThicknessMinimum = 100.0f; // nanometers
278 float iridescenceThicknessMaximum = 400.0f; // nanometers
280 };
281
283
284 // pbrMetallicRoughness
285 QVector4D baseColorFactor { 1.0f, 1.0f, 1.0f, 1.0f };
287 float metallicFactor = 1.0f;
288 float roughnessFactor = 1.0f;
290
291 TextureInfo normalTexture; // scaleOrStrength = scale
292 TextureInfo occlusionTexture; // scaleOrStrength = strength
294 QVector3D emissiveFactor { 0.0f, 0.0f, 0.0f };
295
297 float alphaCutoff = 0.5f;
298 bool doubleSided = false;
299
300 // Extensions
301 bool unlit = false; // KHR_materials_unlit
305 std::optional<Volume> volume;
306 std::optional<float> ior; // KHR_materials_ior
307 std::optional<float> emissiveStrength; // KHR_materials_emissive_strength
309 std::optional<Sheen> sheen;
312 std::optional<float> dispersion; // KHR_materials_dispersion
313
314 QJsonObject extensions; // raw, including any we do not support
315};
316
318{
319 // Values match the glTF primitive.mode constants
329
330 struct VariantMapping // KHR_materials_variants
331 {
332 int material = -1;
333 QList<int> variants; // indices into QSSGGltfDocument::materialVariants
334 };
335
336 QHash<QByteArray, int> attributes; // semantic (POSITION, NORMAL, ...) -> accessor
337 int indices = -1;
338 int material = -1;
340 QList<QHash<QByteArray, int>> targets; // morph targets
341 QList<VariantMapping> variantMappings; // KHR_materials_variants
343
344 // -1 or an unmapped variant selects the default; the first match wins
345 int effectiveMaterial(int variantIndex) const
346 {
347 if (variantIndex >= 0) {
348 for (const VariantMapping &mapping : variantMappings) {
349 if (mapping.variants.contains(variantIndex))
350 return mapping.material;
351 }
352 }
353 return material;
354 }
355};
356
357struct Mesh
358{
360 QList<float> weights; // default morph target weights
362};
363
364struct Node
365{
367 int mesh = -1;
368 int skin = -1;
369 int camera = -1;
370 int light = -1; // KHR_lights_punctual
371 bool hasMatrix = false;
373 QVector3D translation { 0.0f, 0.0f, 0.0f };
375 QVector3D scale { 1.0f, 1.0f, 1.0f };
376 QList<float> weights; // overrides mesh.weights
377 bool visible = true; // KHR_node_visibility; applies to the node's subtree
378 // EXT_mesh_gpu_instancing accessors
379 bool hasInstancing = false;
385};
386
387struct Skin
388{
389 int inverseBindMatrices = -1; // -1 = identity matrices
390 int skeleton = -1;
393};
394
396{
402
403 int input = -1; // accessor with key times (seconds)
404 int output = -1; // accessor with key values
406};
407
421
428
429struct Camera
430{
435
437 // perspective
438 float aspectRatio = 0.0f; // 0 = unspecified
439 float yfov = 0.0f; // radians
440 // orthographic
441 float xmag = 0.0f;
442 float ymag = 0.0f;
443 // shared
444 float znear = 0.0f;
445 float zfar = 0.0f; // 0 = infinite for perspective
447};
448
449struct Light // KHR_lights_punctual
450{
451 enum class Type {
455 };
456
458 QVector3D color { 1.0f, 1.0f, 1.0f };
459 float intensity = 1.0f; // candela for point/spot, lux for directional
460 float range = 0.0f; // 0 = +infinity per spec default
461 // spot only
462 float innerConeAngle = 0.0f; // radians
463 float outerConeAngle = qDegreesToRadians(45.0f);
465};
466
467struct Scene
468{
471};
472
473} // namespace QSSGGltf
474
475class Q_QUICK3DGLTF_EXPORT QSSGGltfDocument
476{
477public:
478 QSSGGltf::Asset asset;
479 QList<QSSGGltf::Buffer> buffers;
480 QList<QSSGGltf::BufferView> bufferViews;
481 QList<QSSGGltf::Accessor> accessors;
482 QList<QSSGGltf::Image> images;
483 QList<QSSGGltf::Sampler> samplers;
484 QList<QSSGGltf::Texture> textures;
485 QList<QSSGGltf::Material> materials;
486 QList<QSSGGltf::Mesh> meshes;
487 QList<QSSGGltf::Node> nodes;
488 QList<QSSGGltf::Skin> skins;
489 QList<QSSGGltf::Animation> animations;
490 QList<QSSGGltf::Camera> cameras;
491 QList<QSSGGltf::Light> lights; // KHR_lights_punctual
492 QList<QSSGGltf::Scene> scenes;
493 int scene = -1;
494
495 QStringList extensionsUsed;
496 QStringList extensionsRequired;
497 QStringList materialVariants; // KHR_materials_variants variant names
498 QJsonObject rootExtensions;
499
500 // Directory the document was loaded from, used to resolve relative URIs.
501 // Local filesystem or qrc (":/...") path.
502 QString baseDir;
503};
504
505QT_END_NAMESPACE
506
507#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
std::optional< Anisotropy > anisotropy
std::optional< float > dispersion
TextureInfo metallicRoughnessTexture
std::optional< float > ior
std::optional< Sheen > sheen
std::optional< SpecularGlossiness > specularGlossiness
std::optional< Volume > volume
std::optional< Transmission > transmission
std::optional< Iridescence > iridescence
std::optional< float > emissiveStrength
int effectiveMaterial(int variantIndex) const
QList< VariantMapping > variantMappings
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