Overte C++ Documentation
MaterialBaker.h
1 //
2 // MaterialBaker.h
3 // libraries/baking/src
4 //
5 // Created by Sam Gondelman on 2/26/2019
6 // Copyright 2019 High Fidelity, Inc.
7 // Copyright 2023 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_MaterialBaker_h
15 #define hifi_MaterialBaker_h
16 
17 #include <QtCore/QSharedPointer>
18 
19 #include "Baker.h"
20 
21 #include "TextureBaker.h"
22 #include "baking/TextureFileNamer.h"
23 
24 #include <HelperScriptEngine.h>
25 #include <procedural/ProceduralMaterialCache.h>
26 #include <ScriptEngine.h>
27 
28 static const QString BAKED_MATERIAL_EXTENSION = ".baked.json";
29 
30 using TextureKey = QPair<QUrl, image::TextureUsage::Type>;
31 
32 class MaterialBaker : public Baker {
33  Q_OBJECT
34 public:
35  MaterialBaker(const QString& materialData, bool isURL, const QString& bakedOutputDir, QUrl destinationPath = QUrl());
36 
37  QString getMaterialData() const { return _materialData; }
38  bool isURL() const { return _isURL; }
39  QString getBakedMaterialData() const { return _bakedMaterialData; }
40 
41  void setMaterials(const QHash<QString, hfm::Material>& materials, const QString& baseURL);
42  void setMaterials(const NetworkMaterialResourcePointer& materialResource);
43 
44  NetworkMaterialResourcePointer getNetworkMaterialResource() const { return _materialResource; }
45 
46  static void setNextOvenWorkerThreadOperator(std::function<QThread*()> getNextOvenWorkerThreadOperator) { _getNextOvenWorkerThreadOperator = getNextOvenWorkerThreadOperator; }
47 
48 public slots:
49  virtual void bake() override;
50  virtual void abort() override;
51 
52 signals:
53  void originalMaterialLoaded();
54 
55 private slots:
56  void processMaterial();
57  void outputMaterial();
58  void handleFinishedTextureBaker();
59 
60 private:
61  void loadMaterial();
62 
63  QString _materialData;
64  bool _isURL;
65  QUrl _destinationPath;
66 
67  NetworkMaterialResourcePointer _materialResource;
68 
69  QHash<TextureKey, QSharedPointer<TextureBaker>> _textureBakers;
70  QMultiHash<TextureKey, std::shared_ptr<NetworkMaterial>> _materialsNeedingRewrite;
71 
72  QString _bakedOutputDir;
73  QString _textureOutputDir;
74  QString _bakedMaterialData;
75 
76  HelperScriptEngine _helperScriptEngine;
77  static std::function<QThread*()> _getNextOvenWorkerThreadOperator;
78  TextureFileNamer _textureFileNamer;
79 
80  void addTexture(const QString& materialName, image::TextureUsage::Type textureUsage, const hfm::Texture& texture);
81  struct TextureUsageHash {
82  std::size_t operator()(image::TextureUsage::Type textureUsage) const {
83  return static_cast<std::size_t>(textureUsage);
84  }
85  };
86  std::unordered_map<std::string, std::unordered_map<image::TextureUsage::Type, std::pair<QByteArray, QString>, TextureUsageHash>> _textureContentMap;
87 };
88 
89 #endif // !hifi_MaterialBaker_h
Provides a wrapper around script engine that does not have ScriptManager.
Definition: HelperScriptEngine.h:31
A texture map.
Definition: HFM.h:132