mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:23:35 +02:00
sliding texture caps for models
This commit is contained in:
parent
d65cbbb455
commit
8b2c720e29
3 changed files with 83 additions and 2 deletions
|
@ -1465,6 +1465,33 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
|
|
||||||
// Create the Material Library
|
// Create the Material Library
|
||||||
consolidateFBXMaterials(mapping);
|
consolidateFBXMaterials(mapping);
|
||||||
|
|
||||||
|
// HACK: until we get proper LOD management we're going to cap model textures
|
||||||
|
// according to how many unique textures the model uses:
|
||||||
|
// 1 - 7 textures --> 2048
|
||||||
|
// 8 - 31 textures --> 1024
|
||||||
|
// 32 - 127 textures --> 512
|
||||||
|
// etc...
|
||||||
|
QSet<QString> uniqueTextures;
|
||||||
|
for (auto& material : _fbxMaterials) {
|
||||||
|
material.getTextureNames(uniqueTextures);
|
||||||
|
}
|
||||||
|
int numTextures = uniqueTextures.size();
|
||||||
|
const int MAX_NUM_TEXTURES_AT_MAX_RESOLUTION = 7;
|
||||||
|
if (numTextures > MAX_NUM_TEXTURES_AT_MAX_RESOLUTION) {
|
||||||
|
int maxWidth = sqrt(MAX_NUM_PIXELS_FOR_FBX_TEXTURE + 1);
|
||||||
|
int t = numTextures;
|
||||||
|
t /= MAX_NUM_TEXTURES_AT_MAX_RESOLUTION;
|
||||||
|
while (t > 0) {
|
||||||
|
maxWidth /= 2;
|
||||||
|
t /= 4;
|
||||||
|
}
|
||||||
|
qCDebug(modelformat) << "max square texture width =" << maxWidth << " for model" << url;
|
||||||
|
for (auto& material : _fbxMaterials) {
|
||||||
|
material.setMaxNumPixelsPerTexture(maxWidth * maxWidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
geometry.materials = _fbxMaterials;
|
geometry.materials = _fbxMaterials;
|
||||||
|
|
||||||
// see if any materials have texture children
|
// see if any materials have texture children
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#define hifi_FBXReader_h
|
#define hifi_FBXReader_h
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
|
#include <QSet>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QVarLengthArray>
|
#include <QVarLengthArray>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
@ -105,7 +106,7 @@ public:
|
||||||
glm::mat4 inverseBindMatrix;
|
glm::mat4 inverseBindMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
const int MAX_FBX_TEXTURE_NUM_PIXELS = 1024 * 1024;
|
const int MAX_NUM_PIXELS_FOR_FBX_TEXTURE = 2048 * 2048;
|
||||||
|
|
||||||
/// A texture map in an FBX document.
|
/// A texture map in an FBX document.
|
||||||
class FBXTexture {
|
class FBXTexture {
|
||||||
|
@ -115,7 +116,7 @@ public:
|
||||||
QByteArray content;
|
QByteArray content;
|
||||||
|
|
||||||
Transform transform;
|
Transform transform;
|
||||||
int maxNumPixels { MAX_FBX_TEXTURE_NUM_PIXELS };
|
int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE };
|
||||||
int texcoordSet;
|
int texcoordSet;
|
||||||
QString texcoordSetName;
|
QString texcoordSetName;
|
||||||
|
|
||||||
|
@ -146,6 +147,9 @@ public:
|
||||||
shininess(shininess),
|
shininess(shininess),
|
||||||
opacity(opacity) {}
|
opacity(opacity) {}
|
||||||
|
|
||||||
|
void getTextureNames(QSet<QString>& textureList) const;
|
||||||
|
void setMaxNumPixelsPerTexture(int maxNumPixels);
|
||||||
|
|
||||||
glm::vec3 diffuseColor{ 1.0f };
|
glm::vec3 diffuseColor{ 1.0f };
|
||||||
float diffuseFactor{ 1.0f };
|
float diffuseFactor{ 1.0f };
|
||||||
glm::vec3 specularColor{ 0.02f };
|
glm::vec3 specularColor{ 0.02f };
|
||||||
|
|
|
@ -27,6 +27,56 @@
|
||||||
|
|
||||||
#include "ModelFormatLogging.h"
|
#include "ModelFormatLogging.h"
|
||||||
|
|
||||||
|
void FBXMaterial::getTextureNames(QSet<QString>& textureList) const {
|
||||||
|
if (!normalTexture.isNull()) {
|
||||||
|
textureList.insert(normalTexture.name);
|
||||||
|
}
|
||||||
|
if (!albedoTexture.isNull()) {
|
||||||
|
textureList.insert(albedoTexture.name);
|
||||||
|
}
|
||||||
|
if (!opacityTexture.isNull()) {
|
||||||
|
textureList.insert(opacityTexture.name);
|
||||||
|
}
|
||||||
|
if (!glossTexture.isNull()) {
|
||||||
|
textureList.insert(glossTexture.name);
|
||||||
|
}
|
||||||
|
if (!roughnessTexture.isNull()) {
|
||||||
|
textureList.insert(roughnessTexture.name);
|
||||||
|
}
|
||||||
|
if (!specularTexture.isNull()) {
|
||||||
|
textureList.insert(specularTexture.name);
|
||||||
|
}
|
||||||
|
if (!metallicTexture.isNull()) {
|
||||||
|
textureList.insert(metallicTexture.name);
|
||||||
|
}
|
||||||
|
if (!emissiveTexture.isNull()) {
|
||||||
|
textureList.insert(emissiveTexture.name);
|
||||||
|
}
|
||||||
|
if (!occlusionTexture.isNull()) {
|
||||||
|
textureList.insert(occlusionTexture.name);
|
||||||
|
}
|
||||||
|
if (!scatteringTexture.isNull()) {
|
||||||
|
textureList.insert(scatteringTexture.name);
|
||||||
|
}
|
||||||
|
if (!lightmapTexture.isNull()) {
|
||||||
|
textureList.insert(lightmapTexture.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FBXMaterial::setMaxNumPixelsPerTexture(int maxNumPixels) {
|
||||||
|
normalTexture.maxNumPixels = maxNumPixels;
|
||||||
|
albedoTexture.maxNumPixels = maxNumPixels;
|
||||||
|
opacityTexture.maxNumPixels = maxNumPixels;
|
||||||
|
glossTexture.maxNumPixels = maxNumPixels;
|
||||||
|
roughnessTexture.maxNumPixels = maxNumPixels;
|
||||||
|
specularTexture.maxNumPixels = maxNumPixels;
|
||||||
|
metallicTexture.maxNumPixels = maxNumPixels;
|
||||||
|
emissiveTexture.maxNumPixels = maxNumPixels;
|
||||||
|
occlusionTexture.maxNumPixels = maxNumPixels;
|
||||||
|
scatteringTexture.maxNumPixels = maxNumPixels;
|
||||||
|
lightmapTexture.maxNumPixels = maxNumPixels;
|
||||||
|
}
|
||||||
|
|
||||||
bool FBXMaterial::needTangentSpace() const {
|
bool FBXMaterial::needTangentSpace() const {
|
||||||
return !normalTexture.isNull();
|
return !normalTexture.isNull();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue