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 
39 class ModelBaker : public Baker {
40  Q_OBJECT
41 
42 public:
43  ModelBaker(const QUrl& inputModelURL, const QString& bakedOutputDirectory, const QString& originalOutputDirectory = "", bool hasBeenBaked = false);
44 
45  void setOutputURLSuffix(const QUrl& urlSuffix);
46  void setMappingURL(const QUrl& mappingURL);
47  void setMapping(const hifi::VariantHash& mapping);
48 
49  void initializeOutputDirs();
50 
51  bool buildDracoMeshNode(FBXNode& dracoMeshNode, const QByteArray& dracoMeshBytes, const std::vector<hifi::ByteArray>& dracoMaterialList);
52  virtual void setWasAborted(bool wasAborted) override;
53 
54  QUrl getModelURL() const { return _modelURL; }
55  QUrl getOriginalInputModelURL() const { return _originalInputModelURL; }
56  virtual QUrl getFullOutputMappingURL() const;
57  QUrl getBakedModelURL() const { return _bakedModelURL; }
58 
59 signals:
60  void modelLoaded();
61 
62 public slots:
63  virtual void bake() override;
64  virtual void abort() override;
65 
66 protected:
67  void saveSourceModel();
68  virtual void bakeProcessedSource(const hfm::Model::Pointer& hfmModel, const std::vector<hifi::ByteArray>& dracoMeshes, const std::vector<std::vector<hifi::ByteArray>>& dracoMaterialLists) = 0;
69  void exportScene();
70 
71  FBXNode _rootNode;
72  QUrl _originalInputModelURL;
73  QUrl _modelURL;
74  QUrl _outputURLSuffix;
75  QUrl _mappingURL;
76  hifi::VariantHash _mapping;
77  QString _bakedOutputDir;
78  QString _originalOutputDir;
79  QString _originalOutputModelPath;
80  QString _outputMappingURL;
81  QUrl _bakedModelURL;
82 
83 protected slots:
84  void handleModelNetworkReply();
85  virtual void bakeSourceCopy();
86  void handleFinishedMaterialBaker();
87  void handleFinishedMaterialMapBaker();
88 
89 private:
90  void outputUnbakedFST();
91  void outputBakedFST();
92  void bakeMaterialMap();
93 
94  bool _hasBeenBaked { false };
95 
96  hfm::Model::Pointer _hfmModel;
97  MaterialMapping _materialMapping;
98  int _materialMapIndex { 0 };
99  QJsonArray _materialMappingJSON;
100  QSharedPointer<MaterialBaker> _materialBaker;
101 };
102 
103 #endif // hifi_ModelBaker_h
A node within an FBX document.
Definition: FBX.h:41