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 "cgltf.h"
18 
19 #include <memory.h>
20 #include <QtNetwork/QNetworkReply>
21 #include <hfm/ModelFormatLogging.h>
22 #include <hfm/HFMSerializer.h>
23 
24 
25 class GLTFSerializer : public QObject, public HFMSerializer {
26  Q_OBJECT
27 public:
28  MediaType getMediaType() const override;
29  std::unique_ptr<hfm::Serializer::Factory> getFactory() const override;
30 
31  HFMModel::Pointer read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url = hifi::URL()) override;
32  ~GLTFSerializer();
33 private:
34  cgltf_data* _data {nullptr};
35  hifi::URL _url;
36  QVector<hifi::ByteArray> _externalData;
37 
38  glm::mat4 getModelTransform(const cgltf_node& node);
39  bool getSkinInverseBindMatrices(std::vector<std::vector<float>>& inverseBindMatrixValues);
40  bool generateTargetData(cgltf_accessor *accessor, float weight, QVector<glm::vec3>& returnVector);
41 
42  bool buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& mapping, const hifi::URL& url);
43 
44  bool readBinary(const QString& url, cgltf_buffer &buffer);
45 
46  void retriangulate(const QVector<int>& in_indices, const QVector<glm::vec3>& in_vertices,
47  const QVector<glm::vec3>& in_normals, QVector<int>& out_indices,
48  QVector<glm::vec3>& out_vertices, QVector<glm::vec3>& out_normals);
49 
50  std::tuple<bool, hifi::ByteArray> requestData(hifi::URL& url);
51  hifi::ByteArray requestEmbeddedData(const QString& url);
52 
53  QNetworkReply* request(hifi::URL& url, bool isTest);
54 
55  void setHFMMaterial(HFMMaterial& hfmMat, const cgltf_material& material);
56  HFMTexture getHFMTexture(const cgltf_texture *texture);
57 };
58 
59 #endif // hifi_GLTFSerializer_h
The runtime model format.
Definition: HFM.h:302
A texture map.
Definition: HFM.h:132