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
qssgmesh_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGMESHUTILITIES_P_H
5#define QSSGMESHUTILITIES_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
19
20#include <QtQuick3DUtils/private/qssgbounds3_p.h>
21
22#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
23
24#include <QtCore/qstring.h>
25#include <QtCore/qbytearray.h>
26#include <QtCore/qiodevice.h>
27#include <QtCore/qmap.h>
28
29QT_BEGIN_NAMESPACE
30
31struct QSSGRenderVertexBufferEntry
32{
33 QByteArray m_name;
34 /** Datatype of the this entry points to in the buffer */
35 QSSGRenderComponentType m_componentType;
36 /** Number of components of each data member. 1,2,3, or 4. Don't be stupid.*/
37 quint32 m_numComponents;
38 /** Offset from the beginning of the buffer of the first item */
39 quint32 m_firstItemOffset;
40
41 QSSGRenderVertexBufferEntry(const QByteArray &nm,
42 QSSGRenderComponentType type,
43 quint32 numComponents,
44 quint32 firstItemOffset = 0)
45 : m_name(nm), m_componentType(type), m_numComponents(numComponents), m_firstItemOffset(firstItemOffset)
46 {
47 }
48
49 QSSGRenderVertexBufferEntry()
50 : m_componentType(QSSGRenderComponentType::Float32), m_numComponents(0), m_firstItemOffset(0)
51 {
52 }
53
54 QSSGRenderVertexBufferEntry(const QSSGRenderVertexBufferEntry &inOther)
55 : m_name(inOther.m_name)
56 , m_componentType(inOther.m_componentType)
57 , m_numComponents(inOther.m_numComponents)
58 , m_firstItemOffset(inOther.m_firstItemOffset)
59 {
60 }
61
62 QSSGRenderVertexBufferEntry &operator=(const QSSGRenderVertexBufferEntry &inOther)
63 {
64 if (this != &inOther) {
65 m_name = inOther.m_name;
66 m_componentType = inOther.m_componentType;
67 m_numComponents = inOther.m_numComponents;
68 m_firstItemOffset = inOther.m_firstItemOffset;
69 }
70 return *this;
71 }
72};
73
74namespace QSSGMesh {
75
76struct AssetVertexEntry;
77struct AssetMeshSubset;
78struct RuntimeMeshData;
79struct AssetLodEntry;
80
81class Q_QUICK3DUTILS_EXPORT Mesh
82{
83public:
87
101
107
112
118
123
124 struct Lod {
127 float distance = 0.0f;
128 };
129
138
139 // can just return by value (big data is all implicitly shared)
143 QVector<Subset> subsets() const { return m_subsets; }
144
145 // id 0 == first, otherwise has to match
146 static Mesh loadMesh(QIODevice *device, quint32 id = 0);
147
149
155
157 QString *error);
158
159 bool isValid() const { return !m_subsets.isEmpty(); }
160
161 DrawMode drawMode() const { return m_drawMode; }
162 Winding winding() const { return m_winding; }
163
164 // id 0 == generate new id; otherwise uses it as-is, and must be an unused one
165 quint32 save(QIODevice *device, quint32 id = 0) const;
166
167 bool hasLightmapUVChannel() const;
169
170private:
177 friend struct MeshInternal;
178};
179
180struct Q_QUICK3DUTILS_EXPORT AssetVertexEntry // for asset importer plugins (Assimp, FBX)
181{
186 qint32 morphTargetId = -1; // -1 menas that this entry belongs to the original mesh.
187};
188
189struct Q_QUICK3DUTILS_EXPORT AssetMeshSubset // for asset importer plugins (Assimp, FBX)
190{
198};
199
200struct Q_QUICK3DUTILS_EXPORT RuntimeMeshData // for custom geometry (QQuick3DGeometry, QSSGRenderGeometry)
201{
202 struct Attribute {
203 enum Semantic {
205 PositionSemantic, // attr_pos
206 NormalSemantic, // attr_norm
207 TexCoordSemantic, // attr_uv0
208 TangentSemantic, // attr_textan
209 BinormalSemantic, // attr_binormal
210 JointSemantic, // attr_joints
211 WeightSemantic, // attr_weights
212 ColorSemantic, // attr_color
213 TexCoord1Semantic, // attr_uv1
215 };
216
219 int offset = 0;
220
221 int componentCount() const {
222 switch (semantic) {
223 case IndexSemantic: return 1;
224 case PositionSemantic: return 3;
225 case NormalSemantic: return 3;
226 case TexCoord0Semantic: return 2;
227 case TexCoord1Semantic: return 2;
228 case TangentSemantic: return 3;
229 case BinormalSemantic: return 3;
230 case JointSemantic: return 4;
231 case WeightSemantic: return 4;
232 case ColorSemantic: return 4;
233 }
235 }
236 };
237
243
244 static const int MAX_ATTRIBUTES = 16;
245 static const int MAX_TARGET_ATTRIBUTES = 32;
246
247 void clear()
248 {
250 clearTarget();
251 }
261 {
264 }
265
270
276 int m_stride = 0;
277};
278
279struct Q_QUICK3DUTILS_EXPORT MeshInternal
280{
285 static const quint32 FILE_ID = 555777497;
286 static const quint32 FILE_VERSION = 1;
287 bool isValid() const {
288 return fileId == FILE_ID && fileVersion == FILE_VERSION;
289 }
291 return { FILE_ID, FILE_VERSION, {} };
292 }
293 };
294
300
301 static const quint32 FILE_ID = 3365961549;
302
303 // Version 3 and 4 is only different in the "offset" values that are
304 // all zeroes in version 4 because they are not used by the new mesh
305 // reader. So to support both with the new loader, no branching is
306 // needed at all, it just needs to accept both versions.
308 // Version 5 differs from 4 with the added lightmapSizeHint per subset.
309 // This needs branching in the deserializer.
310 // Version 6 differs from 5 with additional lodCount per subset as well
311 // as a list of Level of Detail data after the subset names.
312 // Version 7 will split the morph target data
313 static const quint32 FILE_VERSION = 7;
314
316 return { FILE_ID, FILE_VERSION, 0, 0 };
317 }
318
319 bool isValid() const {
320 return fileId == FILE_ID
323 }
324
325 bool hasLightmapSizeHint() const {
326 return fileVersion >= 5;
327 }
328
329 bool hasLodDataHint() const {
330 return fileVersion >= 6;
331 }
332
334 return fileVersion >= 7;
335 }
336 };
337
360
383
389
391
392 static const char *getPositionAttrName() { return "attr_pos"; }
393 static const char *getNormalAttrName() { return "attr_norm"; }
394 static const char *getUV0AttrName() { return "attr_uv0"; }
395 static const char *getUV1AttrName() { return "attr_uv1"; }
396 static const char *getLightmapUVAttrName() { return "attr_lightmapuv"; }
397 static const char *getTexTanAttrName() { return "attr_textan"; }
398 static const char *getTexBinormalAttrName() { return "attr_binormal"; }
399 static const char *getColorAttrName() { return "attr_color"; }
400 static const char *getJointAttrName() { return "attr_joints"; }
401 static const char *getWeightAttrName() { return "attr_weights"; }
402
410};
411
412size_t Q_QUICK3DUTILS_EXPORT simplifyMesh(unsigned int* destination,
413 const unsigned int* indices,
415 const float* vertexPositions,
419 float targetError,
420 unsigned int options,
421 float* resultError);
422
423float Q_QUICK3DUTILS_EXPORT simplifyScale(const float* vertexPositions,
426
427void Q_QUICK3DUTILS_EXPORT optimizeVertexCache(unsigned int* destination,
428 const unsigned int* indices,
431
432} // namespace QSSGMesh
433
434QT_END_NAMESPACE
435
436#endif // QSSGMESHUTILITIES_P_H
float simplifyScale(const float *vertexPositions, size_t vertexCount, size_t vertexPositionsStride)
static const size_t MESH_STRUCT_SIZE
Definition qssgmesh.cpp:28
static const size_t SUBSET_STRUCT_SIZE_V3_V4
Definition qssgmesh.cpp:34
static const size_t VERTEX_BUFFER_ENTRY_STRUCT_SIZE
Definition qssgmesh.cpp:31
static const size_t MULTI_ENTRY_STRUCT_SIZE
Definition qssgmesh.cpp:22
static const size_t SUBSET_STRUCT_SIZE_V6
Definition qssgmesh.cpp:38
size_t simplifyMesh(unsigned int *destination, const unsigned int *indices, size_t indexCount, const float *vertexPositions, size_t vertexCount, size_t vertexPositionsStride, size_t targetIndexCount, float targetError, unsigned int options, float *resultError)
static const size_t MULTI_HEADER_STRUCT_SIZE
Definition qssgmesh.cpp:19
static const size_t LOD_STRUCT_SIZE
Definition qssgmesh.cpp:41
void optimizeVertexCache(unsigned int *destination, const unsigned int *indices, size_t indexCount, size_t vertexCount)
static const size_t MESH_HEADER_STRUCT_SIZE
Definition qssgmesh.cpp:25
static const size_t SUBSET_STRUCT_SIZE_V5
Definition qssgmesh.cpp:36
static quint32 getAlignedOffset(quint32 offset, quint32 align)
Definition qssgmesh.cpp:616