QGIS API Documentation 4.1.0-Master (659fe69c07c)
Loading...
Searching...
No Matches
qgsgltf3dutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgltfutils.h
3 --------------------------------------
4 Date : July 2023
5 Copyright : (C) 2023 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSGLTF3DUTILS_H
17#define QGSGLTF3DUTILS_H
18
20
21//
22// W A R N I N G
23// -------------
24//
25// This file is not part of the QGIS API. It exists purely as an
26// implementation detail. This header file may change from version to
27// version without notice, or even be removed.
28//
29
30
31#include <memory>
32#include <vector>
33
34#include "qgis_3d.h"
35#include "qgs3dutils.h"
36#include "qgsgltfutils.h"
37#include "qgsmaterial.h"
38#include "qgsmatrix4x4.h"
39
40#include <QQuaternion>
41#include <QVector3D>
42
43#define SIP_NO_FILE
44
45#define TINYGLTF_NO_STB_IMAGE // we use QImage-based reading of images
46#define TINYGLTF_NO_STB_IMAGE_WRITE // we don't need writing of images
47#include "tiny_gltf.h"
48
52
53namespace Qt3DCore
54{
55 class QEntity;
56 class QGeometry;
57 class QNode;
58 class QBuffer;
59} //namespace Qt3DCore
60
68class _3D_EXPORT QgsGltf3DUtils
69{
70 public:
72 struct EntityTransform
73 {
75 QgsVector3D chunkOriginTargetCrs;
77 QgsMatrix4x4 tileTransform;
79 const QgsCoordinateTransform *ecefToTargetCrs = nullptr;
80
82 Qgis::Axis gltfUpAxis = Qgis::Axis::Y;
83
84 double zValueScale = 1;
85 double zValueOffset = 0;
86 };
87
101 static Qt3DCore::QEntity *gltfToEntity( const QByteArray &data, const EntityTransform &transform, const QString &baseUri, const Qgs3DRenderContext &context, QStringList *errors = nullptr );
102
107 static Qt3DCore::QEntity *parsedGltfToEntity( tinygltf::Model &model, const QgsGltf3DUtils::EntityTransform &transform, QString baseUri, const Qgs3DRenderContext &context, QStringList *errors );
108
113 struct InstanceChunkTransform
114 {
115 QVector3D translation;
116 QQuaternion rotation;
117 QVector3D scale;
118 };
119
132 static QMatrix3x3 ecefToTargetCrsRotationCorrection( const QgsVector3D &ecefPos, const QgsVector3D &mapPos, const QgsCoordinateTransform &ecefToTargetCrs );
133
138 static QVector<InstanceChunkTransform> tileSpaceToChunkLocal( const QgsGltfUtils::InstancedPrimitive &primitive, const EntityTransform &transform );
139
144 static void createInstanceBuffer( Qt3DCore::QGeometry *geometry, const QVector<InstanceChunkTransform> &instances );
145
150 static QVector<Qt3DCore::QEntity *> createInstancedEntities(
151 tinygltf::Model &model, const QVector<QgsGltfUtils::InstancedPrimitive> &primitives, const EntityTransform &transform, const QString &baseUri, const QgsMaterialContext &context, QStringList *errors
152 );
153
166 static std::vector<QgsMeshNodeData> buildGltfGeometries( const QString &filePath, const QgsMaterialContext &context, QStringList *errors = nullptr, Qt3DCore::QNode *bufferParent = nullptr );
167};
168
170
171#endif // QGSGLTF3DUTILS_H
Axis
Cartesian axes.
Definition qgis.h:2608
@ Y
Y-axis.
Definition qgis.h:2610
Rendering context for preparation of 3D entities.
Handles coordinate transforms between two coordinate systems.
Context settings for a material.