Overte C++ Documentation
ModelBaker.h
1 //
2 // ModelBaker.h
3 // libraries/baking/src
4 //
5 // Created by Utkarsh Gautam on 9/29/17.
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_ModelBaker_h
13 #define hifi_ModelBaker_h
14 
15 #include <QtCore/QFutureSynchronizer>
16 #include <QtCore/QDir>
17 #include <QtCore/QUrl>
18 #include <QtNetwork/QNetworkReply>
19 #include <QJsonArray>
20 #include <QtCore/QSharedPointer>
21 
22 #include "Baker.h"
23 #include "MaterialBaker.h"
24 
25 #include "ModelBakingLoggingCategory.h"
26 
27 #include <FBX.h>
28 #include <hfm/HFM.h>
29 
30 using GetMaterialIDCallback = std::function <int(int)>;
31 
32 static const QString FST_EXTENSION { ".fst" };
33 static const QString BAKED_FST_EXTENSION { ".baked.fst" };
34 static const QString FBX_EXTENSION { ".fbx" };
35 static const QString BAKED_FBX_EXTENSION { ".baked.fbx" };
36 static const QString OBJ_EXTENSION { ".obj" };
37 static const QString GLTF_EXTENSION { ".gltf" };
38 static const QString VRM_EXTENSION { ".vrm" };
39 
40 class ModelBaker : public Baker {
41  Q_OBJECT
42 
43 public:
44  ModelBaker(const QUrl& inputModelURL, const QString& bakedOutputDirectory, const QString& originalOutputDirectory = "", bool hasBeenBaked = false);
45 
46  void setOutputURLSuffix(const QUrl& urlSuffix);
47  void setMappingURL(const QUrl& mappingURL);
48  void setMapping(const hifi::VariantHash& mapping);
49 
50  void initializeOutputDirs();
51 
52  bool buildDracoMeshNode(FBXNode& dracoMeshNode, const QByteArray& dracoMeshBytes, const std::vector<hifi::ByteArray>& dracoMaterialList);
53  virtual void setWasAborted(bool wasAborted) override;
54 
55  QUrl getModelURL() const { return _modelURL; }
56  QUrl getOriginalInputModelURL() const { return _originalInputModelURL; }
57  virtual QUrl getFullOutputMappingURL() const;
58  QUrl getBakedModelURL() const { return _bakedModelURL; }
59 
60 signals:
61  void modelLoaded();
62 
63 public slots:
64  virtual void bake() override;
65  virtual void abort() override;
66 
67 protected:
68  void saveSourceModel();
69  virtual void bakeProcessedSource(const hfm::Model::Pointer& hfmModel, const std::vector<hifi::ByteArray>& dracoMeshes, const std::vector<std::vector<hifi::ByteArray>>& dracoMaterialLists) = 0;
70  void exportScene();
71 
72  FBXNode _rootNode;
73  QUrl _originalInputModelURL;
74  QUrl _modelURL;
75  QUrl _outputURLSuffix;
76  QUrl _mappingURL;
77  hifi::VariantHash _mapping;
78  QString _bakedOutputDir;
79  QString _originalOutputDir;
80  QString _originalOutputModelPath;
81  QString _outputMappingURL;
82  QUrl _bakedModelURL;
83 
84 protected slots:
85  void handleModelNetworkReply();
86  virtual void bakeSourceCopy();
87  void handleFinishedMaterialBaker();
88  void handleFinishedMaterialMapBaker();
89 
90 private:
91  void outputUnbakedFST();
92  void outputBakedFST();
93  void bakeMaterialMap();
94 
95  bool _hasBeenBaked { false };
96 
97  hfm::Model::Pointer _hfmModel;
98  MaterialMapping _materialMapping;
99  int _materialMapIndex { 0 };
100  QJsonArray _materialMappingJSON;
101  QSharedPointer<MaterialBaker> _materialBaker;
102 };
103 
104 #endif // hifi_ModelBaker_h
A node within an FBX document.
Definition: FBX.h:41