mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:16:45 +02:00
Add helper to buildNetworkMaterial
This commit is contained in:
parent
c5cb3543eb
commit
19c83e869f
1 changed files with 26 additions and 34 deletions
|
@ -309,53 +309,45 @@ static NetworkMaterial* buildNetworkMaterial(const FBXMaterial& material, const
|
||||||
auto localBaseUrl = QUrl(textureBaseUrl.url() + "/");
|
auto localBaseUrl = QUrl(textureBaseUrl.url() + "/");
|
||||||
|
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
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()) {
|
||||||
const auto& baseUrl = material.diffuseTexture.content.isEmpty() ? textureBaseUrl : localBaseUrl;
|
auto diffuseMap = setupMaterialTexture(material.diffuseTexture,
|
||||||
networkMaterial->diffuseTexture = textureCache->getTexture(baseUrl.resolved(QUrl(material.diffuseTexture.filename)), DEFAULT_TEXTURE, material.diffuseTexture.content);
|
DEFAULT_TEXTURE, model::MaterialKey::DIFFUSE_MAP,
|
||||||
networkMaterial->diffuseTextureName = material.diffuseTexture.name;
|
networkMaterial->diffuseTexture, networkMaterial->diffuseTextureName);
|
||||||
|
|
||||||
auto diffuseMap = model::TextureMapPointer(new model::TextureMap());
|
|
||||||
diffuseMap->setTextureSource(networkMaterial->diffuseTexture->_textureSource);
|
|
||||||
diffuseMap->setTextureTransform(material.diffuseTexture.transform);
|
diffuseMap->setTextureTransform(material.diffuseTexture.transform);
|
||||||
|
|
||||||
material._material->setTextureMap(model::MaterialKey::DIFFUSE_MAP, diffuseMap);
|
|
||||||
}
|
}
|
||||||
if (!material.normalTexture.filename.isEmpty()) {
|
if (!material.normalTexture.filename.isEmpty()) {
|
||||||
const auto& baseUrl = material.normalTexture.content.isEmpty() ? textureBaseUrl : localBaseUrl;
|
setupMaterialTexture(material.normalTexture,
|
||||||
networkMaterial->normalTexture = textureCache->getTexture(baseUrl.resolved(QUrl(material.normalTexture.filename)), (material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE), material.normalTexture.content);
|
(material.normalTexture.isBumpmap ? BUMP_TEXTURE : NORMAL_TEXTURE), model::MaterialKey::NORMAL_MAP,
|
||||||
networkMaterial->normalTextureName = material.normalTexture.name;
|
networkMaterial->normalTexture, networkMaterial->normalTextureName);
|
||||||
|
|
||||||
auto normalMap = model::TextureMapPointer(new model::TextureMap());
|
|
||||||
normalMap->setTextureSource(networkMaterial->normalTexture->_textureSource);
|
|
||||||
|
|
||||||
material._material->setTextureMap(model::MaterialKey::NORMAL_MAP, normalMap);
|
|
||||||
}
|
}
|
||||||
if (!material.specularTexture.filename.isEmpty()) {
|
if (!material.specularTexture.filename.isEmpty()) {
|
||||||
const auto& baseUrl = material.specularTexture.content.isEmpty() ? textureBaseUrl : localBaseUrl;
|
setupMaterialTexture(material.specularTexture,
|
||||||
networkMaterial->specularTexture = textureCache->getTexture(baseUrl.resolved(QUrl(material.specularTexture.filename)), SPECULAR_TEXTURE, material.specularTexture.content);
|
SPECULAR_TEXTURE, model::MaterialKey::GLOSS_MAP,
|
||||||
networkMaterial->specularTextureName = material.specularTexture.name;
|
networkMaterial->specularTexture, networkMaterial->specularTextureName);
|
||||||
|
|
||||||
auto glossMap = model::TextureMapPointer(new model::TextureMap());
|
|
||||||
glossMap->setTextureSource(networkMaterial->specularTexture->_textureSource);
|
|
||||||
|
|
||||||
material._material->setTextureMap(model::MaterialKey::GLOSS_MAP, glossMap);
|
|
||||||
}
|
}
|
||||||
if (!material.emissiveTexture.filename.isEmpty()) {
|
if (!material.emissiveTexture.filename.isEmpty()) {
|
||||||
const auto& baseUrl = material.emissiveTexture.content.isEmpty() ? textureBaseUrl : localBaseUrl;
|
auto lightmapMap = setupMaterialTexture(material.emissiveTexture,
|
||||||
networkMaterial->emissiveTexture = textureCache->getTexture(baseUrl.resolved(QUrl(material.emissiveTexture.filename)), LIGHTMAP_TEXTURE, material.emissiveTexture.content);
|
LIGHTMAP_TEXTURE, model::MaterialKey::LIGHTMAP_MAP,
|
||||||
networkMaterial->emissiveTextureName = material.emissiveTexture.name;
|
networkMaterial->emissiveTexture, networkMaterial->emissiveTextureName);
|
||||||
|
|
||||||
|
|
||||||
auto lightmapMap = model::TextureMapPointer(new model::TextureMap());
|
|
||||||
lightmapMap->setTextureSource(networkMaterial->emissiveTexture->_textureSource);
|
|
||||||
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);
|
||||||
|
|
||||||
material._material->setTextureMap(model::MaterialKey::LIGHTMAP_MAP, lightmapMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return networkMaterial;
|
return networkMaterial;
|
||||||
|
|
Loading…
Reference in a new issue