mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 15:39:57 +02:00
texture line parse wip
This commit is contained in:
parent
64cd3d5cb5
commit
a44e00142d
2 changed files with 35 additions and 3 deletions
|
@ -303,8 +303,10 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
||||||
} else if (token == "Ks") {
|
} else if (token == "Ks") {
|
||||||
currentMaterial.specularColor = tokenizer.getVec3();
|
currentMaterial.specularColor = tokenizer.getVec3();
|
||||||
} else if ((token == "map_Kd") || (token == "map_Ke") || (token == "map_Ks") || (token == "map_bump")) {
|
} else if ((token == "map_Kd") || (token == "map_Ke") || (token == "map_Ks") || (token == "map_bump")) {
|
||||||
QByteArray textureLine = QString(tokenizer.getLineAsDatum()).toUtf8();
|
const QByteArray textureLine = tokenizer.getLineAsDatum();
|
||||||
QByteArray filename = textureLine; // TODO: parse texture options and filename from line
|
QByteArray filename;
|
||||||
|
OBJMaterialTextureOptions textureOptions;
|
||||||
|
parseTextureLine(textureLine, filename, textureOptions);
|
||||||
if (filename.endsWith(".tga")) {
|
if (filename.endsWith(".tga")) {
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
qCDebug(modelformat) << "OBJ Reader WARNING: currently ignoring tga texture " << filename << " in " << _url;
|
qCDebug(modelformat) << "OBJ Reader WARNING: currently ignoring tga texture " << filename << " in " << _url;
|
||||||
|
@ -315,7 +317,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
||||||
currentMaterial.diffuseTextureFilename = filename;
|
currentMaterial.diffuseTextureFilename = filename;
|
||||||
} else if (token == "map_Ke") {
|
} else if (token == "map_Ke") {
|
||||||
currentMaterial.emissiveTextureFilename = filename;
|
currentMaterial.emissiveTextureFilename = filename;
|
||||||
} else if( token == "map_Ks" ) {
|
} else if (token == "map_Ks" ) {
|
||||||
currentMaterial.specularTextureFilename = filename;
|
currentMaterial.specularTextureFilename = filename;
|
||||||
} else if (token == "map_bump") {
|
} else if (token == "map_bump") {
|
||||||
currentMaterial.bumpTextureFilename = filename;
|
currentMaterial.bumpTextureFilename = filename;
|
||||||
|
@ -324,6 +326,29 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions) {
|
||||||
|
QString parser = textureLine;
|
||||||
|
while (parser.length() > 0) {
|
||||||
|
if (parser.startsWith("-bm")) {
|
||||||
|
parser.remove(0, 4);
|
||||||
|
int multiplierEnd = parser.indexOf(' ');
|
||||||
|
if (multiplierEnd < 0) {
|
||||||
|
multiplierEnd = parser.length();
|
||||||
|
}
|
||||||
|
QString multiplier = parser.left(multiplierEnd);
|
||||||
|
textureOptions.bumpMultiplier = std::stof(multiplier.toStdString());
|
||||||
|
parser.remove(0, multiplier.length() + 1);
|
||||||
|
} else {
|
||||||
|
int fileEnd = parser.indexOf(' ');
|
||||||
|
if (fileEnd < 0) {
|
||||||
|
fileEnd = parser.length();
|
||||||
|
}
|
||||||
|
filename = parser.left(fileEnd).toUtf8();
|
||||||
|
parser.remove(0, filename.length() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::tuple<bool, QByteArray> requestData(QUrl& url) {
|
std::tuple<bool, QByteArray> requestData(QUrl& url) {
|
||||||
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(nullptr, url);
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,12 @@ public:
|
||||||
OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f) {}
|
OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OBJMaterialTextureOptions {
|
||||||
|
public:
|
||||||
|
float bumpMultiplier;
|
||||||
|
OBJMaterialTextureOptions() : bumpMultiplier(1.0f) {}
|
||||||
|
};
|
||||||
|
|
||||||
class OBJReader: public QObject { // QObject so we can make network requests.
|
class OBJReader: public QObject { // QObject so we can make network requests.
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -87,6 +93,7 @@ private:
|
||||||
bool parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry,
|
bool parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry,
|
||||||
float& scaleGuess, bool combineParts);
|
float& scaleGuess, bool combineParts);
|
||||||
void parseMaterialLibrary(QIODevice* device);
|
void parseMaterialLibrary(QIODevice* device);
|
||||||
|
void parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions);
|
||||||
bool isValidTexture(const QByteArray &filename); // true if the file exists. TODO?: check content-type header and that it is a supported format.
|
bool isValidTexture(const QByteArray &filename); // true if the file exists. TODO?: check content-type header and that it is a supported format.
|
||||||
|
|
||||||
int _partCounter { 0 };
|
int _partCounter { 0 };
|
||||||
|
|
Loading…
Reference in a new issue