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// Qt-Security score:significant reason:default
4
5
6#ifndef QSSGMESHUTILITIES_P_H
7#define QSSGMESHUTILITIES_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3DUtils/private/qtquick3dutilsglobal_p.h>
21
22#include <QtQuick3DUtils/private/qssgbounds3_p.h>
23
24#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
25
26#include <QtCore/qstring.h>
27#include <QtCore/qbytearray.h>
28#include <QtCore/qiodevice.h>
29#include <QtCore/qmap.h>
30
31QT_BEGIN_NAMESPACE
32
33struct QSSGRenderVertexBufferEntry
34{
35 QByteArray m_name;
36 /** Datatype of the this entry points to in the buffer */
37 QSSGRenderComponentType m_componentType;
38 /** Number of components of each data member. 1,2,3, or 4. Don't be stupid.*/
39 quint32 m_numComponents;
40 /** Offset from the beginning of the buffer of the first item */
41 quint32 m_firstItemOffset;
42
43 QSSGRenderVertexBufferEntry(const QByteArray &nm,
44 QSSGRenderComponentType type,
45 quint32 numComponents,
46 quint32 firstItemOffset = 0)
47 : m_name(nm), m_componentType(type), m_numComponents(numComponents), m_firstItemOffset(firstItemOffset)
48 {
49 }
50
51 QSSGRenderVertexBufferEntry()
52 : m_componentType(QSSGRenderComponentType::Float32), m_numComponents(0), m_firstItemOffset(0)
53 {
54 }
55
56 QSSGRenderVertexBufferEntry(const QSSGRenderVertexBufferEntry &inOther)
57 : m_name(inOther.m_name)
58 , m_componentType(inOther.m_componentType)
59 , m_numComponents(inOther.m_numComponents)
60 , m_firstItemOffset(inOther.m_firstItemOffset)
61 {
62 }
63
64 QSSGRenderVertexBufferEntry &operator=(const QSSGRenderVertexBufferEntry &inOther)
65 {
66 if (this != &inOther) {
67 m_name = inOther.m_name;
68 m_componentType = inOther.m_componentType;
69 m_numComponents = inOther.m_numComponents;
70 m_firstItemOffset = inOther.m_firstItemOffset;
71 }
72 return *this;
73 }
74};
75
76namespace QSSGMesh {
77
78struct AssetVertexEntry;
79struct AssetMeshSubset;
80struct RuntimeMeshData;
81struct AssetLodEntry;
82
83class Q_QUICK3DUTILS_EXPORT Mesh
84{
85public:
89
103
109
114
120
125
126 struct Lod {
129 float distance = 0.0f;
130 };
131
140
141 // can just return by value (big data is all implicitly shared)
145 QVector<Subset> subsets() const { return m_subsets; }
146
147 // id 0 == first, otherwise has to match
148 static Mesh loadMesh(QIODevice *device, quint32 id = 0);
149
151
157
159 QString *error);
160
161 bool isValid() const { return !m_subsets.isEmpty(); }
162
163 DrawMode drawMode() const { return m_drawMode; }
164 Winding winding() const { return m_winding; }
165
166 // id 0 == generate new id; otherwise uses it as-is, and must be an unused one
167 quint32 save(QIODevice *device, quint32 id = 0) const;
168
169 bool hasLightmapUVChannel() const;
171
172private:
179 friend struct MeshInternal;
180};
181
182struct Q_QUICK3DUTILS_EXPORT AssetVertexEntry // for asset importer plugins (Assimp, FBX)
183{
188 qint32 morphTargetId = -1; // -1 menas that this entry belongs to the original mesh.
189};
190
191struct Q_QUICK3DUTILS_EXPORT AssetMeshSubset // for asset importer plugins (Assimp, FBX)
192{
200};
201
202struct Q_QUICK3DUTILS_EXPORT RuntimeMeshData // for custom geometry (QQuick3DGeometry, QSSGRenderGeometry)
203{
204 struct Attribute {
205 enum Semantic {
207 PositionSemantic, // attr_pos
208 NormalSemantic, // attr_norm
209 TexCoordSemantic, // attr_uv0
210 TangentSemantic, // attr_textan
211 BinormalSemantic, // attr_binormal
212 JointSemantic, // attr_joints
213 WeightSemantic, // attr_weights
214 ColorSemantic, // attr_color
215 TexCoord1Semantic, // attr_uv1
217 };
218
221 int offset = 0;
222
223 int componentCount() const {
224 switch (semantic) {
225 case IndexSemantic: return 1;
226 case PositionSemantic: return 3;
227 case NormalSemantic: return 3;
228 case TexCoord0Semantic: return 2;
229 case TexCoord1Semantic: return 2;
230 case TangentSemantic: return 3;
231 case BinormalSemantic: return 3;
232 case JointSemantic: return 4;
233 case WeightSemantic: return 4;
234 case ColorSemantic: return 4;
235 }
237 }
238 };
239
245
246 static const int MAX_ATTRIBUTES = 16;
247 static const int MAX_TARGET_ATTRIBUTES = 32;
248
249 void clear()
250 {
252 clearTarget();
253 }
263 {
266 }
267
272
278 int m_stride = 0;
279};
280
281struct Q_QUICK3DUTILS_EXPORT MeshInternal
282{
287 static const quint32 FILE_ID = 555777497;
288 static const quint32 FILE_VERSION = 1;
289 bool isValid() const {
290 return fileId == FILE_ID && fileVersion == FILE_VERSION;
291 }
293 return { FILE_ID, FILE_VERSION, {} };
294 }
295 };
296
302
303 static const quint32 FILE_ID = 3365961549;
304
305 // Version 3 and 4 is only different in the "offset" values that are
306 // all zeroes in version 4 because they are not used by the new mesh
307 // reader. So to support both with the new loader, no branching is
308 // needed at all, it just needs to accept both versions.
310 // Version 5 differs from 4 with the added lightmapSizeHint per subset.
311 // This needs branching in the deserializer.
312 // Version 6 differs from 5 with additional lodCount per subset as well
313 // as a list of Level of Detail data after the subset names.
314 // Version 7 will split the morph target data
315 static const quint32 FILE_VERSION = 7;
316
318 return { FILE_ID, FILE_VERSION, 0, 0 };
319 }
320
321 bool isValid() const {
322 return fileId == FILE_ID
325 }
326
327 bool hasLightmapSizeHint() const {
328 return fileVersion >= 5;
329 }
330
331 bool hasLodDataHint() const {
332 return fileVersion >= 6;
333 }
334
336 return fileVersion >= 7;
337 }
338 };
339
362
385
391
393
394 static const char *getPositionAttrName() { return "attr_pos"; }
395 static const char *getNormalAttrName() { return "attr_norm"; }
396 static const char *getUV0AttrName() { return "attr_uv0"; }
397 static const char *getUV1AttrName() { return "attr_uv1"; }
398 static const char *getLightmapUVAttrName() { return "attr_lightmapuv"; }
399 static const char *getTexTanAttrName() { return "attr_textan"; }
400 static const char *getTexBinormalAttrName() { return "attr_binormal"; }
401 static const char *getColorAttrName() { return "attr_color"; }
402 static const char *getJointAttrName() { return "attr_joints"; }
403 static const char *getWeightAttrName() { return "attr_weights"; }
404
412};
413
414size_t Q_QUICK3DUTILS_EXPORT simplifyMesh(unsigned int* destination,
415 const unsigned int* indices,
417 const float* vertexPositions,
421 float targetError,
422 unsigned int options,
423 float* resultError);
424
425float Q_QUICK3DUTILS_EXPORT simplifyScale(const float* vertexPositions,
428
429void Q_QUICK3DUTILS_EXPORT optimizeVertexCache(unsigned int* destination,
430 const unsigned int* indices,
433
434} // namespace QSSGMesh
435
436QT_END_NAMESPACE
437
438#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:30
static const size_t SUBSET_STRUCT_SIZE_V3_V4
Definition qssgmesh.cpp:36
static const size_t VERTEX_BUFFER_ENTRY_STRUCT_SIZE
Definition qssgmesh.cpp:33
static const size_t MULTI_ENTRY_STRUCT_SIZE
Definition qssgmesh.cpp:24
static const size_t SUBSET_STRUCT_SIZE_V6
Definition qssgmesh.cpp:40
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:21
static const size_t LOD_STRUCT_SIZE
Definition qssgmesh.cpp:43
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:27
static const size_t SUBSET_STRUCT_SIZE_V5
Definition qssgmesh.cpp:38
static quint32 getAlignedOffset(quint32 offset, quint32 align)
Definition qssgmesh.cpp:618