mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:53:08 +02:00
embedded textures and relative material paths
This commit is contained in:
parent
b98f47d1f3
commit
585a022dca
3 changed files with 42 additions and 4 deletions
|
@ -149,8 +149,18 @@ void MaterialBaker::processMaterial() {
|
||||||
if (!_textureBakers.contains(textureKey)) {
|
if (!_textureBakers.contains(textureKey)) {
|
||||||
auto baseTextureFileName = _textureFileNamer.createBaseTextureFileName(textureURL.fileName(), it->second);
|
auto baseTextureFileName = _textureFileNamer.createBaseTextureFileName(textureURL.fileName(), it->second);
|
||||||
|
|
||||||
|
QByteArray content;
|
||||||
|
{
|
||||||
|
auto textureContentMapIter = _textureContentMap.find(networkMaterial.second->getName());
|
||||||
|
if (textureContentMapIter != _textureContentMap.end()) {
|
||||||
|
auto textureUsageIter = textureContentMapIter->second.find(it->second);
|
||||||
|
if (textureUsageIter != textureContentMapIter->second.end()) {
|
||||||
|
content = textureUsageIter->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
QSharedPointer<TextureBaker> textureBaker {
|
QSharedPointer<TextureBaker> textureBaker {
|
||||||
new TextureBaker(textureURL, it->second, _textureOutputDir, "", baseTextureFileName),
|
new TextureBaker(textureURL, it->second, _textureOutputDir, "", baseTextureFileName, content),
|
||||||
&TextureBaker::deleteLater
|
&TextureBaker::deleteLater
|
||||||
};
|
};
|
||||||
textureBaker->setMapChannel(mapChannel);
|
textureBaker->setMapChannel(mapChannel);
|
||||||
|
@ -159,6 +169,7 @@ void MaterialBaker::processMaterial() {
|
||||||
textureBaker->moveToThread(_getNextOvenWorkerThreadOperator ? _getNextOvenWorkerThreadOperator() : thread());
|
textureBaker->moveToThread(_getNextOvenWorkerThreadOperator ? _getNextOvenWorkerThreadOperator() : thread());
|
||||||
QMetaObject::invokeMethod(textureBaker.data(), "bake");
|
QMetaObject::invokeMethod(textureBaker.data(), "bake");
|
||||||
}
|
}
|
||||||
|
// FIXME: we need to detect when our material has opacity and output the opacityMap
|
||||||
_materialsNeedingRewrite.insert(textureKey, networkMaterial.second);
|
_materialsNeedingRewrite.insert(textureKey, networkMaterial.second);
|
||||||
} else {
|
} else {
|
||||||
qCDebug(material_baking) << "Texture extension not supported: " << extension;
|
qCDebug(material_baking) << "Texture extension not supported: " << extension;
|
||||||
|
@ -254,10 +265,31 @@ void MaterialBaker::outputMaterial() {
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MaterialBaker::addTexture(const QString& materialName, image::TextureUsage::Type textureUsage, const hfm::Texture& texture) {
|
||||||
|
std::string name = materialName.toStdString();
|
||||||
|
auto& textureUsageMap = _textureContentMap[materialName.toStdString()];
|
||||||
|
if (textureUsageMap.find(textureUsage) == textureUsageMap.end()) {
|
||||||
|
// Content may be empty, unless the data is inlined
|
||||||
|
textureUsageMap[textureUsage] = texture.content;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void MaterialBaker::setMaterials(const QHash<QString, hfm::Material>& materials, const QString& baseURL) {
|
void MaterialBaker::setMaterials(const QHash<QString, hfm::Material>& materials, const QString& baseURL) {
|
||||||
_materialResource = NetworkMaterialResourcePointer(new NetworkMaterialResource(), [](NetworkMaterialResource* ptr) { ptr->deleteLater(); });
|
_materialResource = NetworkMaterialResourcePointer(new NetworkMaterialResource(), [](NetworkMaterialResource* ptr) { ptr->deleteLater(); });
|
||||||
for (auto& material : materials) {
|
for (auto& material : materials) {
|
||||||
_materialResource->parsedMaterials.names.push_back(material.name.toStdString());
|
_materialResource->parsedMaterials.names.push_back(material.name.toStdString());
|
||||||
_materialResource->parsedMaterials.networkMaterials[material.name.toStdString()] = std::make_shared<NetworkMaterial>(material, baseURL);
|
_materialResource->parsedMaterials.networkMaterials[material.name.toStdString()] = std::make_shared<NetworkMaterial>(material, baseURL);
|
||||||
|
|
||||||
|
// Store any embedded texture content
|
||||||
|
addTexture(material.name, image::TextureUsage::NORMAL_TEXTURE, material.normalTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::ALBEDO_TEXTURE, material.albedoTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::GLOSS_TEXTURE, material.glossTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::ROUGHNESS_TEXTURE, material.roughnessTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::SPECULAR_TEXTURE, material.specularTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::METALLIC_TEXTURE, material.metallicTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::EMISSIVE_TEXTURE, material.emissiveTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::OCCLUSION_TEXTURE, material.occlusionTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::SCATTERING_TEXTURE, material.scatteringTexture);
|
||||||
|
addTexture(material.name, image::TextureUsage::LIGHTMAP_TEXTURE, material.lightmapTexture);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -65,6 +65,9 @@ private:
|
||||||
QScriptEngine _scriptEngine;
|
QScriptEngine _scriptEngine;
|
||||||
static std::function<QThread*()> _getNextOvenWorkerThreadOperator;
|
static std::function<QThread*()> _getNextOvenWorkerThreadOperator;
|
||||||
TextureFileNamer _textureFileNamer;
|
TextureFileNamer _textureFileNamer;
|
||||||
|
|
||||||
|
void addTexture(const QString& materialName, image::TextureUsage::Type textureUsage, const hfm::Texture& texture);
|
||||||
|
std::unordered_map<std::string, std::unordered_map<image::TextureUsage::Type, QByteArray>> _textureContentMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !hifi_MaterialBaker_h
|
#endif // !hifi_MaterialBaker_h
|
||||||
|
|
|
@ -275,15 +275,18 @@ 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 " << bakedMaterialURL;
|
qCDebug(model_baking) << "Adding baked material to FST mapping " << baker->getBakedMaterialData();
|
||||||
|
|
||||||
|
QString relativeBakedMaterialURL = "/" + _modelURL.fileName();
|
||||||
|
auto baseName = relativeBakedMaterialURL.left(relativeBakedMaterialURL.lastIndexOf('.'));
|
||||||
|
relativeBakedMaterialURL = baseName + BAKED_MATERIAL_EXTENSION;
|
||||||
|
|
||||||
// First we add the materials in the model
|
// First we add the materials in the model
|
||||||
QJsonArray materialMapping;
|
QJsonArray materialMapping;
|
||||||
for (auto material : _hfmModel->materials) {
|
for (auto material : _hfmModel->materials) {
|
||||||
QJsonObject json;
|
QJsonObject json;
|
||||||
json["mat::" + material.name] = bakedMaterialURL + "?" + material.name;
|
json["mat::" + material.name] = relativeBakedMaterialURL + "?" + material.name;
|
||||||
materialMapping.push_back(json);
|
materialMapping.push_back(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue