Overte C++ Documentation
GLTFSerializer.h
1 //
2 // GLTFSerializer.h
3 // libraries/model-serializers/src
4 //
5 // Created by Luis Cuenca on 8/30/17.
6 // Copyright 2017 High Fidelity, Inc.
7 // Copyright 2023-2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 
14 #ifndef hifi_GLTFSerializer_h
15 #define hifi_GLTFSerializer_h
16 
17 #include <memory.h>
18 #include <QtNetwork/QNetworkReply>
19 #include <hfm/ModelFormatLogging.h>
20 #include <hfm/HFMSerializer.h>
21 
22 float atof_locale_independent(char* str);
23 
24 #define CGLTF_ATOF(str) atof_locale_independent(str)
25 
26 #include "cgltf.h"
27 
28 
29 class GLTFSerializer : public QObject, public HFMSerializer {
30  Q_OBJECT
31 public:
32  MediaType getMediaType() const override;
33  std::unique_ptr<hfm::Serializer::Factory> getFactory() const override;
34 
35  HFMModel::Pointer read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url = hifi::URL()) override;
36  ~GLTFSerializer();
37 private:
38  cgltf_data* _data {nullptr};
39  hifi::URL _url;
40  QVector<hifi::ByteArray> _externalData;
41 
42  glm::mat4 getModelTransform(const cgltf_node& node);
43  bool getSkinInverseBindMatrices(std::vector<std::vector<float>>& inverseBindMatrixValues);
44  bool generateTargetData(cgltf_accessor *accessor, float weight, QVector<glm::vec3>& returnVector);
45 
46  bool buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& mapping, const hifi::URL& url);
47 
48  bool readBinary(const QString& url, cgltf_buffer &buffer);
49 
50  void retriangulate(const QVector<int>& in_indices, const QVector<glm::vec3>& in_vertices,
51  const QVector<glm::vec3>& in_normals, QVector<int>& out_indices,
52  QVector<glm::vec3>& out_vertices, QVector<glm::vec3>& out_normals);
53 
54  std::tuple<bool, hifi::ByteArray> requestData(hifi::URL& url);
55  hifi::ByteArray requestEmbeddedData(const QString& url);
56 
57  QNetworkReply* request(hifi::URL& url, bool isTest);
58 
59  void setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& material);
60  HFMTexture getHFMTexture(const cgltf_texture *texture, cgltf_int texCoordSet);
61 };
62 
63 #endif // hifi_GLTFSerializer_h
The runtime model format.
Definition: HFM.h:305
A texture map.
Definition: HFM.h:133