mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:16:51 +02:00
Refactor helper from lambda to static fn
This commit is contained in:
parent
19c83e869f
commit
d5a5ce8c70
1 changed files with 25 additions and 25 deletions
|
@ -304,50 +304,50 @@ static NetworkMesh* buildNetworkMesh(const FBXMesh& mesh, const QUrl& textureBas
|
||||||
return networkMesh;
|
return networkMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const QUrl& textureBaseUrl) {
|
static model::TextureMapPointer setupNetworkTextureMap(const QUrl& textureBaseUrl,
|
||||||
// Create a local url to cache inline textures
|
const FBXTexture& texture, TextureType type,
|
||||||
auto localBaseUrl = QUrl(textureBaseUrl.url() + "/");
|
NetworkTexturePointer& networkTexture, QString& networkTextureName) {
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
|
|
||||||
|
// If content is inline, cache it under the fbx file, not its base url
|
||||||
|
const auto baseUrl = texture.content.isEmpty() ? textureBaseUrl : QUrl(textureBaseUrl.url() + "/");
|
||||||
|
const auto filename = baseUrl.resolved(QUrl(texture.filename));
|
||||||
|
|
||||||
|
networkTexture = textureCache->getTexture(filename, type, texture.content);
|
||||||
|
networkTextureName = texture.name;
|
||||||
|
|
||||||
|
auto map = std::make_shared<model::TextureMap>();
|
||||||
|
map->setTextureSource(networkTexture->_textureSource);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const QUrl& textureBaseUrl) {
|
||||||
NetworkMaterial* networkMaterial = new NetworkMaterial();
|
NetworkMaterial* networkMaterial = new NetworkMaterial();
|
||||||
networkMaterial->_material = material._material;
|
networkMaterial->_material = material._material;
|
||||||
|
|
||||||
auto setupMaterialTexture = [&](const FBXTexture& texture,
|
|
||||||
TextureType type, model::MaterialKey::MapChannel channel,
|
|
||||||
NetworkTexturePointer& networkTexture, QString& networkTextureName){
|
|
||||||
const auto& baseUrl = texture.content.isEmpty() ? textureBaseUrl : localBaseUrl;
|
|
||||||
networkTexture = textureCache->getTexture(baseUrl.resolved(QUrl(texture.filename)), type, texture.content);
|
|
||||||
networkTextureName = texture.name;
|
|
||||||
|
|
||||||
auto map = std::make_shared<model::TextureMap>();
|
|
||||||
map->setTextureSource(networkTexture->_textureSource);
|
|
||||||
material._material->setTextureMap(channel, map);
|
|
||||||
return map;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!material.diffuseTexture.filename.isEmpty()) {
|
if (!material.diffuseTexture.filename.isEmpty()) {
|
||||||
auto diffuseMap = setupMaterialTexture(material.diffuseTexture,
|
auto diffuseMap = setupNetworkTextureMap(textureBaseUrl, material.diffuseTexture, DEFAULT_TEXTURE,
|
||||||
DEFAULT_TEXTURE, model::MaterialKey::DIFFUSE_MAP,
|
|
||||||
networkMaterial->diffuseTexture, networkMaterial->diffuseTextureName);
|
networkMaterial->diffuseTexture, networkMaterial->diffuseTextureName);
|
||||||
diffuseMap->setTextureTransform(material.diffuseTexture.transform);
|
diffuseMap->setTextureTransform(material.diffuseTexture.transform);
|
||||||
|
networkMaterial->_material->setTextureMap(model::MaterialKey::DIFFUSE_MAP, diffuseMap);
|
||||||
}
|
}
|
||||||
if (!material.normalTexture.filename.isEmpty()) {
|
if (!material.normalTexture.filename.isEmpty()) {
|
||||||
setupMaterialTexture(material.normalTexture,
|
auto normalMap = setupNetworkTextureMap(textureBaseUrl, material.normalTexture,
|
||||||
(material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE), model::MaterialKey::NORMAL_MAP,
|
(material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE),
|
||||||
networkMaterial->normalTexture, networkMaterial->normalTextureName);
|
networkMaterial->normalTexture, networkMaterial->normalTextureName);
|
||||||
|
networkMaterial->_material->setTextureMap(model::MaterialKey::NORMAL_MAP, normalMap);
|
||||||
}
|
}
|
||||||
if (!material.specularTexture.filename.isEmpty()) {
|
if (!material.specularTexture.filename.isEmpty()) {
|
||||||
setupMaterialTexture(material.specularTexture,
|
auto glossMap = setupNetworkTextureMap(textureBaseUrl, material.specularTexture, SPECULAR_TEXTURE,
|
||||||
SPECULAR_TEXTURE, model::MaterialKey::GLOSS_MAP,
|
|
||||||
networkMaterial->specularTexture, networkMaterial->specularTextureName);
|
networkMaterial->specularTexture, networkMaterial->specularTextureName);
|
||||||
|
networkMaterial->_material->setTextureMap(model::MaterialKey::GLOSS_MAP, glossMap);
|
||||||
}
|
}
|
||||||
if (!material.emissiveTexture.filename.isEmpty()) {
|
if (!material.emissiveTexture.filename.isEmpty()) {
|
||||||
auto lightmapMap = setupMaterialTexture(material.emissiveTexture,
|
auto lightmapMap = setupNetworkTextureMap(textureBaseUrl, material.emissiveTexture, LIGHTMAP_TEXTURE,
|
||||||
LIGHTMAP_TEXTURE, model::MaterialKey::LIGHTMAP_MAP,
|
|
||||||
networkMaterial->emissiveTexture, networkMaterial->emissiveTextureName);
|
networkMaterial->emissiveTexture, networkMaterial->emissiveTextureName);
|
||||||
lightmapMap->setTextureTransform(material.emissiveTexture.transform);
|
lightmapMap->setTextureTransform(material.emissiveTexture.transform);
|
||||||
lightmapMap->setLightmapOffsetScale(material.emissiveParams.x, material.emissiveParams.y);
|
lightmapMap->setLightmapOffsetScale(material.emissiveParams.x, material.emissiveParams.y);
|
||||||
|
networkMaterial->_material->setTextureMap(model::MaterialKey::LIGHTMAP_MAP, lightmapMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return networkMaterial;
|
return networkMaterial;
|
||||||
|
|
Loading…
Reference in a new issue