mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:03:11 +02:00
Change FBXReader impl to recognize inlined tex
This commit is contained in:
parent
b780fad83f
commit
77958e2a48
3 changed files with 29 additions and 16 deletions
|
@ -428,17 +428,17 @@ FBXLight extractLight(const FBXNode& object) {
|
||||||
return light;
|
return light;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray fileOnUrl(const QByteArray& filenameString, const QString& url) {
|
QByteArray fileOnUrl(const QByteArray& filepath, const QString& url) {
|
||||||
QString path = QFileInfo(url).path();
|
QString path = QFileInfo(url).path();
|
||||||
QByteArray filename = filenameString;
|
QByteArray filename = filepath;
|
||||||
QFileInfo checkFile(path + "/" + filename.replace('\\', '/'));
|
QFileInfo checkFile(path + "/" + filepath);
|
||||||
//check if the file exists at the RelativeFileName
|
|
||||||
if (checkFile.exists() && checkFile.isFile()) {
|
// check if the file exists at the RelativeFilename
|
||||||
filename = filename.replace('\\', '/');
|
if (!(checkFile.exists() && checkFile.isFile())) {
|
||||||
} else {
|
// if not, assume it is in the fbx directory
|
||||||
// there is no texture at the fbx dir with the filename added. Assume it is in the fbx dir.
|
filename = filename.mid(filename.lastIndexOf('/') + 1);
|
||||||
filename = filename.mid(qMax(filename.lastIndexOf('\\'), filename.lastIndexOf('/')) + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,7 +765,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
foreach (const FBXNode& subobject, object.children) {
|
foreach (const FBXNode& subobject, object.children) {
|
||||||
if (subobject.name == "RelativeFilename") {
|
if (subobject.name == "RelativeFilename") {
|
||||||
QByteArray filename = subobject.properties.at(0).toByteArray();
|
QByteArray filename = subobject.properties.at(0).toByteArray();
|
||||||
filename = fileOnUrl(filename, url);
|
QByteArray filepath = filename.replace('\\', '/');
|
||||||
|
filename = fileOnUrl(filepath, url);
|
||||||
|
_textureFilepaths.insert(getID(object.properties), filepath);
|
||||||
_textureFilenames.insert(getID(object.properties), filename);
|
_textureFilenames.insert(getID(object.properties), filename);
|
||||||
} else if (subobject.name == "TextureName") {
|
} else if (subobject.name == "TextureName") {
|
||||||
// trim the name from the timestamp
|
// trim the name from the timestamp
|
||||||
|
@ -849,19 +851,19 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
_textureParams.insert(getID(object.properties), tex);
|
_textureParams.insert(getID(object.properties), tex);
|
||||||
}
|
}
|
||||||
} else if (object.name == "Video") {
|
} else if (object.name == "Video") {
|
||||||
QByteArray filename;
|
QByteArray filepath;
|
||||||
QByteArray content;
|
QByteArray content;
|
||||||
foreach (const FBXNode& subobject, object.children) {
|
foreach (const FBXNode& subobject, object.children) {
|
||||||
if (subobject.name == "RelativeFilename") {
|
if (subobject.name == "RelativeFilename") {
|
||||||
filename = subobject.properties.at(0).toByteArray();
|
filepath= subobject.properties.at(0).toByteArray();
|
||||||
filename = fileOnUrl(filename, url);
|
filepath = filepath.replace('\\', '/');
|
||||||
|
|
||||||
} else if (subobject.name == "Content" && !subobject.properties.isEmpty()) {
|
} else if (subobject.name == "Content" && !subobject.properties.isEmpty()) {
|
||||||
content = subobject.properties.at(0).toByteArray();
|
content = subobject.properties.at(0).toByteArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
_textureContent.insert(filename, content);
|
_textureContent.insert(filepath, content);
|
||||||
}
|
}
|
||||||
} else if (object.name == "Material") {
|
} else if (object.name == "Material") {
|
||||||
FBXMaterial material;
|
FBXMaterial material;
|
||||||
|
|
|
@ -411,7 +411,11 @@ public:
|
||||||
FBXTexture getTexture(const QString& textureID);
|
FBXTexture getTexture(const QString& textureID);
|
||||||
|
|
||||||
QHash<QString, QString> _textureNames;
|
QHash<QString, QString> _textureNames;
|
||||||
|
// Hashes the original RelativeFilename of textures
|
||||||
|
QHash<QString, QByteArray> _textureFilepaths;
|
||||||
|
// Hashes the place to look for textures, in case they are not inlined
|
||||||
QHash<QString, QByteArray> _textureFilenames;
|
QHash<QString, QByteArray> _textureFilenames;
|
||||||
|
// Hashes texture content by filepath, in case they are inlined
|
||||||
QHash<QByteArray, QByteArray> _textureContent;
|
QHash<QByteArray, QByteArray> _textureContent;
|
||||||
QHash<QString, TextureParam> _textureParams;
|
QHash<QString, TextureParam> _textureParams;
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,16 @@ bool FBXMaterial::needTangentSpace() const {
|
||||||
|
|
||||||
FBXTexture FBXReader::getTexture(const QString& textureID) {
|
FBXTexture FBXReader::getTexture(const QString& textureID) {
|
||||||
FBXTexture texture;
|
FBXTexture texture;
|
||||||
texture.filename = _textureFilenames.value(textureID);
|
const QByteArray& filepath = _textureFilepaths.value(textureID);
|
||||||
|
texture.content = _textureContent.value(filepath);
|
||||||
|
|
||||||
|
if (texture.content.isEmpty()) { // the content is not inlined
|
||||||
|
texture.filename = _textureFilenames.value(textureID);
|
||||||
|
} else { // use supplied filepath for inlined content
|
||||||
|
texture.filename = filepath;
|
||||||
|
}
|
||||||
|
|
||||||
texture.name = _textureNames.value(textureID);
|
texture.name = _textureNames.value(textureID);
|
||||||
texture.content = _textureContent.value(texture.filename);
|
|
||||||
texture.transform.setIdentity();
|
texture.transform.setIdentity();
|
||||||
texture.texcoordSet = 0;
|
texture.texcoordSet = 0;
|
||||||
if (_textureParams.contains(textureID)) {
|
if (_textureParams.contains(textureID)) {
|
||||||
|
|
Loading…
Reference in a new issue