QGIS API Documentation 4.1.0-Master (9af12b5a203)
Loading...
Searching...
No Matches
qgsgltfutils.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 QGSGLTFUTILS_H
17#define QGSGLTFUTILS_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 <optional>
33
34#include "qgis.h"
35#include "qgis_core.h"
37
38#include <QMatrix4x4>
39#include <QVector>
40
41#define SIP_NO_FILE
42
43class QMatrix4x4;
44class QImage;
45
46class QgsMatrix4x4;
48class QgsVector3D;
49
50namespace tinygltf
51{
52 struct Image;
53 class Model;
54 class Node;
55 class TinyGLTF;
56} //namespace tinygltf
57
58
66class CORE_EXPORT QgsGltfUtils
67{
68 public:
83 static bool accessorToMapCoordinates(
84 const tinygltf::Model &model,
85 int accessorIndex,
86 const QgsMatrix4x4 &tileTransform,
87 const QgsCoordinateTransform *ecefToTargetCrs,
88 const QgsVector3D &tileTranslationEcef,
89 const QMatrix4x4 *nodeTransform,
90 Qgis::Axis gltfUpAxis,
91 QVector<double> &vx,
92 QVector<double> &vy,
93 QVector<double> &vz
94 );
95
99 enum class ResourceType
100 {
101 Embedded,
102 Linked,
103 };
104
111 static ResourceType imageResourceType( const tinygltf::Model &model, int index );
112
121 static QImage extractEmbeddedImage( const tinygltf::Model &model, int index );
122
131 static QString linkedImagePath( const tinygltf::Model &model, int index );
132
138 static std::unique_ptr<QMatrix4x4> parseNodeTransform( const tinygltf::Node &node );
139
145 static QgsVector3D extractTileTranslation( tinygltf::Model &model, Qgis::Axis upAxis = Qgis::Axis::Y );
146
150 static bool loadImageDataWithQImage(
151 tinygltf::Image *image, const int image_idx, std::string *err, std::string *warn, int req_width, int req_height, const unsigned char *bytes, int size, void *user_data
152 );
153
157 static bool extractTextureCoordinates( const tinygltf::Model &model, int accessorIndex, QVector<float> &x, QVector<float> &y );
158
164 static bool loadGltfModel( const QByteArray &data, tinygltf::Model &model, QString *errors, QString *warnings, const QString &baseDir = QString() );
165
174 static std::size_t sourceSceneForModel( const tinygltf::Model &model, bool &ok );
175
181 struct CORE_EXPORT I3SNodeContext
182 {
184 void initFromTile( const QgsTiledSceneTile &tile, const QgsCoordinateReferenceSystem &layerCrs, const QgsCoordinateReferenceSystem &sceneCrs, const QgsCoordinateTransformContext &transformContext );
185
190 QVariantMap materialInfo;
191
197 bool isGlobalMode = false;
198
203 QgsCoordinateTransform datasetToSceneTransform;
204
209 QgsVector3D nodeCenterEcef;
210 };
211
226 static bool loadDracoModel( const QByteArray &data, const I3SNodeContext &context, tinygltf::Model &model, QString *errors = nullptr );
227
239 static int loadMaterialFromMetadata( const QVariantMap &materialInfo, tinygltf::Model &model );
240
245 static bool writeGltfModel( const tinygltf::Model &model, const QString &outputFilename );
246
252 struct InstancedPrimitive
253 {
254 int meshIndex = -1;
255 int primitiveIndex = -1;
256 int materialIndex = -1;
257
262 QVector<QMatrix4x4> instanceTransforms;
263 };
264};
265
267
268#endif // QGSGLTFUTILS_H
Axis
Cartesian axes.
Definition qgis.h:2607
@ Y
Y-axis.
Definition qgis.h:2609
A simple 4x4 matrix implementation useful for transformation in 3D space.
Represents an individual tile from a tiled scene data source.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33