mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 11:58:10 +02:00
add baked materials to fst materialMapping
This commit is contained in:
parent
310d01feff
commit
b98f47d1f3
5 changed files with 40 additions and 5 deletions
|
@ -253,3 +253,11 @@ void MaterialBaker::outputMaterial() {
|
||||||
// emit signal to indicate the material baking is finished
|
// emit signal to indicate the material baking is finished
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBaker::setMaterials(const QHash<QString, hfm::Material>& materials, const QString& baseURL) {
|
||||||
|
_materialResource = NetworkMaterialResourcePointer(new NetworkMaterialResource(), [](NetworkMaterialResource* ptr) { ptr->deleteLater(); });
|
||||||
|
for (auto& material : materials) {
|
||||||
|
_materialResource->parsedMaterials.names.push_back(material.name.toStdString());
|
||||||
|
_materialResource->parsedMaterials.networkMaterials[material.name.toStdString()] = std::make_shared<NetworkMaterial>(material, baseURL);
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,8 @@ public:
|
||||||
bool isURL() const { return _isURL; }
|
bool isURL() const { return _isURL; }
|
||||||
QString getBakedMaterialData() const { return _bakedMaterialData; }
|
QString getBakedMaterialData() const { return _bakedMaterialData; }
|
||||||
|
|
||||||
|
void setMaterials(const QHash<QString, hfm::Material>& materials, const QString& baseURL);
|
||||||
|
|
||||||
static void setNextOvenWorkerThreadOperator(std::function<QThread*()> getNextOvenWorkerThreadOperator) { _getNextOvenWorkerThreadOperator = getNextOvenWorkerThreadOperator; }
|
static void setNextOvenWorkerThreadOperator(std::function<QThread*()> getNextOvenWorkerThreadOperator) { _getNextOvenWorkerThreadOperator = getNextOvenWorkerThreadOperator; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
|
|
||||||
#include "baking/BakerLibrary.h"
|
#include "baking/BakerLibrary.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
ModelBaker::ModelBaker(const QUrl& inputModelURL, const QUrl& destinationPath, const QString& bakedOutputDirectory, const QString& originalOutputDirectory, bool hasBeenBaked) :
|
ModelBaker::ModelBaker(const QUrl& inputModelURL, const QUrl& destinationPath, const QString& bakedOutputDirectory, const QString& originalOutputDirectory, bool hasBeenBaked) :
|
||||||
_modelURL(inputModelURL),
|
_modelURL(inputModelURL),
|
||||||
_destinationPath(destinationPath),
|
_destinationPath(destinationPath),
|
||||||
|
@ -208,7 +210,6 @@ void ModelBaker::bakeSourceCopy() {
|
||||||
}
|
}
|
||||||
hifi::ByteArray modelData = modelFile.readAll();
|
hifi::ByteArray modelData = modelFile.readAll();
|
||||||
|
|
||||||
hfm::Model::Pointer bakedModel;
|
|
||||||
std::vector<hifi::ByteArray> dracoMeshes;
|
std::vector<hifi::ByteArray> dracoMeshes;
|
||||||
std::vector<std::vector<hifi::ByteArray>> dracoMaterialLists; // Material order for per-mesh material lookup used by dracoMeshes
|
std::vector<std::vector<hifi::ByteArray>> dracoMaterialLists; // Material order for per-mesh material lookup used by dracoMeshes
|
||||||
|
|
||||||
|
@ -244,23 +245,24 @@ void ModelBaker::bakeSourceCopy() {
|
||||||
// Begin hfm baking
|
// Begin hfm baking
|
||||||
baker.run();
|
baker.run();
|
||||||
|
|
||||||
bakedModel = baker.getHFMModel();
|
_hfmModel = baker.getHFMModel();
|
||||||
dracoMeshes = baker.getDracoMeshes();
|
dracoMeshes = baker.getDracoMeshes();
|
||||||
dracoMaterialLists = baker.getDracoMaterialLists();
|
dracoMaterialLists = baker.getDracoMaterialLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do format-specific baking
|
// Do format-specific baking
|
||||||
bakeProcessedSource(bakedModel, dracoMeshes, dracoMaterialLists);
|
bakeProcessedSource(_hfmModel, dracoMeshes, dracoMaterialLists);
|
||||||
|
|
||||||
if (shouldStop()) {
|
if (shouldStop()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bakedModel->materials.size() > 0) {
|
if (_hfmModel->materials.size() > 0) {
|
||||||
_materialBaker = QSharedPointer<MaterialBaker>(
|
_materialBaker = QSharedPointer<MaterialBaker>(
|
||||||
new MaterialBaker(_modelURL.fileName(), true, _bakedOutputDir, _destinationPath),
|
new MaterialBaker(_modelURL.fileName(), true, _bakedOutputDir, _destinationPath),
|
||||||
&MaterialBaker::deleteLater
|
&MaterialBaker::deleteLater
|
||||||
);
|
);
|
||||||
|
_materialBaker->setMaterials(_hfmModel->materials, _modelURL.toString());
|
||||||
connect(_materialBaker.data(), &MaterialBaker::finished, this, &ModelBaker::handleFinishedMaterialBaker);
|
connect(_materialBaker.data(), &MaterialBaker::finished, this, &ModelBaker::handleFinishedMaterialBaker);
|
||||||
_materialBaker->bake();
|
_materialBaker->bake();
|
||||||
} else {
|
} else {
|
||||||
|
@ -273,9 +275,30 @@ void ModelBaker::handleFinishedMaterialBaker() {
|
||||||
|
|
||||||
if (baker) {
|
if (baker) {
|
||||||
if (!baker->hasErrors()) {
|
if (!baker->hasErrors()) {
|
||||||
|
auto bakedMaterialURL = baker->getBakedMaterialData();
|
||||||
// this MaterialBaker is done and everything went according to plan
|
// this MaterialBaker is done and everything went according to plan
|
||||||
qCDebug(model_baking) << "Adding baked material to FST mapping " << baker->getBakedMaterialData();
|
qCDebug(model_baking) << "Adding baked material to FST mapping " << bakedMaterialURL;
|
||||||
|
|
||||||
|
// First we add the materials in the model
|
||||||
|
QJsonArray materialMapping;
|
||||||
|
for (auto material : _hfmModel->materials) {
|
||||||
|
QJsonObject json;
|
||||||
|
json["mat::" + material.name] = bakedMaterialURL + "?" + material.name;
|
||||||
|
materialMapping.push_back(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The we add any existing mappings from the mapping
|
||||||
|
if (_mapping.contains(MATERIAL_MAPPING_FIELD)) {
|
||||||
|
QByteArray materialMapValue = _mapping[MATERIAL_MAPPING_FIELD].toByteArray();
|
||||||
|
QJsonObject oldMaterialMapping = QJsonDocument::fromJson(materialMapValue).object();
|
||||||
|
for (auto key : oldMaterialMapping.keys()) {
|
||||||
|
QJsonObject json;
|
||||||
|
json[key] = oldMaterialMapping[key];
|
||||||
|
materialMapping.push_back(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_mapping[MATERIAL_MAPPING_FIELD] = QJsonDocument(materialMapping).toJson(QJsonDocument::Compact);
|
||||||
} else {
|
} else {
|
||||||
// this material failed to bake - this doesn't fail the entire bake but we need to add the errors from
|
// this material failed to bake - this doesn't fail the entire bake but we need to add the errors from
|
||||||
// the material to our warnings
|
// the material to our warnings
|
||||||
|
|
|
@ -87,6 +87,7 @@ private:
|
||||||
|
|
||||||
bool _hasBeenBaked { false };
|
bool _hasBeenBaked { false };
|
||||||
|
|
||||||
|
hfm::Model::Pointer _hfmModel;
|
||||||
QSharedPointer<MaterialBaker> _materialBaker;
|
QSharedPointer<MaterialBaker> _materialBaker;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ static const QString JOINT_FIELD = "joint";
|
||||||
static const QString BLENDSHAPE_FIELD = "bs";
|
static const QString BLENDSHAPE_FIELD = "bs";
|
||||||
static const QString SCRIPT_FIELD = "script";
|
static const QString SCRIPT_FIELD = "script";
|
||||||
static const QString JOINT_NAME_MAPPING_FIELD = "jointMap";
|
static const QString JOINT_NAME_MAPPING_FIELD = "jointMap";
|
||||||
|
static const QString MATERIAL_MAPPING_FIELD = "materialMap";
|
||||||
|
|
||||||
class FSTReader {
|
class FSTReader {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue