mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 18:42:55 +02:00
Fixing buggy hash map look up and cleaning of name
This commit is contained in:
parent
c9cb768945
commit
a41c20a1b7
3 changed files with 63 additions and 34 deletions
|
@ -817,12 +817,12 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
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);
|
filename = fileOnUrl(filename, url);
|
||||||
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
|
||||||
QString name = QString(subobject.properties.at(0).toByteArray());
|
QString name = QString(subobject.properties.at(0).toByteArray());
|
||||||
name = name.left(name.indexOf('['));
|
name = name.left(name.indexOf('['));
|
||||||
textureNames.insert(getID(object.properties), name);
|
_textureNames.insert(getID(object.properties), name);
|
||||||
} else if (subobject.name == "Texture_Alpha_Source") {
|
} else if (subobject.name == "Texture_Alpha_Source") {
|
||||||
tex.assign<uint8_t>(tex.alphaSource, subobject.properties.at(0).value<int>());
|
tex.assign<uint8_t>(tex.alphaSource, subobject.properties.at(0).value<int>());
|
||||||
} else if (subobject.name == "ModelUVTranslation") {
|
} else if (subobject.name == "ModelUVTranslation") {
|
||||||
|
@ -831,6 +831,12 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
} else if (subobject.name == "ModelUVScaling") {
|
} else if (subobject.name == "ModelUVScaling") {
|
||||||
tex.assign(tex.UVScaling, glm::vec2(subobject.properties.at(0).value<double>(),
|
tex.assign(tex.UVScaling, glm::vec2(subobject.properties.at(0).value<double>(),
|
||||||
subobject.properties.at(1).value<double>()));
|
subobject.properties.at(1).value<double>()));
|
||||||
|
if (tex.UVScaling.x == 0.0f) {
|
||||||
|
tex.UVScaling.x = 1.0f;
|
||||||
|
}
|
||||||
|
if (tex.UVScaling.y == 0.0f) {
|
||||||
|
tex.UVScaling.y = 1.0f;
|
||||||
|
}
|
||||||
} else if (subobject.name == "Cropping") {
|
} else if (subobject.name == "Cropping") {
|
||||||
tex.assign(tex.cropping, glm::vec4(subobject.properties.at(0).value<int>(),
|
tex.assign(tex.cropping, glm::vec4(subobject.properties.at(0).value<int>(),
|
||||||
subobject.properties.at(1).value<int>(),
|
subobject.properties.at(1).value<int>(),
|
||||||
|
@ -857,6 +863,15 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
tex.assign(tex.rotation, getVec3(property.properties, index));
|
tex.assign(tex.rotation, getVec3(property.properties, index));
|
||||||
} else if (property.properties.at(0) == "Scaling") {
|
} else if (property.properties.at(0) == "Scaling") {
|
||||||
tex.assign(tex.scaling, getVec3(property.properties, index));
|
tex.assign(tex.scaling, getVec3(property.properties, index));
|
||||||
|
if (tex.scaling.x == 0.0f) {
|
||||||
|
tex.scaling.x = 1.0f;
|
||||||
|
}
|
||||||
|
if (tex.scaling.y == 0.0f) {
|
||||||
|
tex.scaling.y = 1.0f;
|
||||||
|
}
|
||||||
|
if (tex.scaling.z == 0.0f) {
|
||||||
|
tex.scaling.z = 1.0f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#if defined(DEBUG_FBXREADER)
|
#if defined(DEBUG_FBXREADER)
|
||||||
else {
|
else {
|
||||||
|
@ -882,7 +897,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tex.isDefault) {
|
if (!tex.isDefault) {
|
||||||
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 filename;
|
||||||
|
@ -897,7 +912,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
textureContent.insert(filename, content);
|
_textureContent.insert(filename, content);
|
||||||
}
|
}
|
||||||
} else if (object.name == "Material") {
|
} else if (object.name == "Material") {
|
||||||
FBXMaterial material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(), glm::vec2(0.f, 1.0f), 96.0f, 1.0f,
|
FBXMaterial material = { glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(), glm::vec2(0.f, 1.0f), 96.0f, 1.0f,
|
||||||
|
@ -1299,7 +1314,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
geometry.materials = _fbxMaterials;
|
geometry.materials = _fbxMaterials;
|
||||||
|
|
||||||
// see if any materials have texture children
|
// see if any materials have texture children
|
||||||
bool materialsHaveTextures = checkMaterialsHaveTextures(_fbxMaterials, textureFilenames, _connectionChildMap);
|
bool materialsHaveTextures = checkMaterialsHaveTextures(_fbxMaterials, _textureFilenames, _connectionChildMap);
|
||||||
|
|
||||||
for (QHash<QString, ExtractedMesh>::iterator it = meshes.begin(); it != meshes.end(); it++) {
|
for (QHash<QString, ExtractedMesh>::iterator it = meshes.begin(); it != meshes.end(); it++) {
|
||||||
ExtractedMesh& extracted = it.value();
|
ExtractedMesh& extracted = it.value();
|
||||||
|
@ -1344,7 +1359,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS
|
||||||
|
|
||||||
materialIndex++;
|
materialIndex++;
|
||||||
|
|
||||||
} else if (textureFilenames.contains(childID)) {
|
} else if (_textureFilenames.contains(childID)) {
|
||||||
FBXTexture texture = getTexture(childID);
|
FBXTexture texture = getTexture(childID);
|
||||||
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
for (int j = 0; j < extracted.partMaterialTextures.size(); j++) {
|
||||||
int partTexture = extracted.partMaterialTextures.at(j).second;
|
int partTexture = extracted.partMaterialTextures.at(j).second;
|
||||||
|
|
|
@ -312,7 +312,8 @@ FBXGeometry* readFBX(const QByteArray& model, const QVariantHash& mapping, const
|
||||||
/// \exception QString if an error occurs in parsing
|
/// \exception QString if an error occurs in parsing
|
||||||
FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f);
|
FBXGeometry* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f);
|
||||||
|
|
||||||
struct TextureParam {
|
class TextureParam {
|
||||||
|
public:
|
||||||
glm::vec2 UVTranslation;
|
glm::vec2 UVTranslation;
|
||||||
glm::vec2 UVScaling;
|
glm::vec2 UVScaling;
|
||||||
glm::vec4 cropping;
|
glm::vec4 cropping;
|
||||||
|
@ -351,6 +352,21 @@ struct TextureParam {
|
||||||
useMaterial(true),
|
useMaterial(true),
|
||||||
isDefault(true)
|
isDefault(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
TextureParam(const TextureParam& src) :
|
||||||
|
UVTranslation(src.UVTranslation),
|
||||||
|
UVScaling(src.UVScaling),
|
||||||
|
cropping(src.cropping),
|
||||||
|
UVSet(src.UVSet),
|
||||||
|
translation(src.translation),
|
||||||
|
rotation(src.rotation),
|
||||||
|
scaling(src.scaling),
|
||||||
|
alphaSource(src.alphaSource),
|
||||||
|
currentTextureBlendMode(src.currentTextureBlendMode),
|
||||||
|
useMaterial(src.useMaterial),
|
||||||
|
isDefault(src.isDefault)
|
||||||
|
{}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExtractedMesh;
|
class ExtractedMesh;
|
||||||
|
@ -370,10 +386,10 @@ public:
|
||||||
|
|
||||||
FBXTexture getTexture(const QString& textureID);
|
FBXTexture getTexture(const QString& textureID);
|
||||||
|
|
||||||
QHash<QString, QString> textureNames;
|
QHash<QString, QString> _textureNames;
|
||||||
QHash<QString, QByteArray> textureFilenames;
|
QHash<QString, QByteArray> _textureFilenames;
|
||||||
QHash<QByteArray, QByteArray> textureContent;
|
QHash<QByteArray, QByteArray> _textureContent;
|
||||||
QHash<QString, TextureParam> textureParams;
|
QHash<QString, TextureParam> _textureParams;
|
||||||
|
|
||||||
|
|
||||||
QHash<QString, QString> diffuseTextures;
|
QHash<QString, QString> diffuseTextures;
|
||||||
|
|
|
@ -28,17 +28,30 @@ 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);
|
texture.filename = _textureFilenames.value(textureID);
|
||||||
texture.name = textureNames.value(textureID);
|
texture.name = _textureNames.value(textureID);
|
||||||
texture.content = textureContent.value(texture.filename);
|
texture.content = _textureContent.value(texture.filename);
|
||||||
texture.transform.setIdentity();
|
texture.transform.setIdentity();
|
||||||
texture.texcoordSet = 0;
|
texture.texcoordSet = 0;
|
||||||
QHash<QString, TextureParam>::const_iterator it = textureParams.constFind(textureID);
|
if (_textureParams.contains(textureID)) {
|
||||||
if (it != textureParams.end()) {
|
auto p = _textureParams.value(textureID);
|
||||||
const TextureParam& p = (*it);
|
|
||||||
texture.transform.setTranslation(p.translation);
|
texture.transform.setTranslation(p.translation);
|
||||||
texture.transform.setRotation(glm::quat(glm::radians(p.rotation)));
|
texture.transform.setRotation(glm::quat(glm::radians(p.rotation)));
|
||||||
texture.transform.setScale(p.scaling);
|
|
||||||
|
auto scaling = p.scaling;
|
||||||
|
// Protect from bad scaling which should never happen
|
||||||
|
if (scaling.x == 0.0f) {
|
||||||
|
scaling.x = 1.0f;
|
||||||
|
}
|
||||||
|
if (scaling.y == 0.0f) {
|
||||||
|
scaling.y = 1.0f;
|
||||||
|
}
|
||||||
|
if (scaling.z == 0.0f) {
|
||||||
|
scaling.z = 1.0f;
|
||||||
|
}
|
||||||
|
texture.transform.setScale(scaling);
|
||||||
|
|
||||||
if ((p.UVSet != "map1") && (p.UVSet != "UVSet0")) {
|
if ((p.UVSet != "map1") && (p.UVSet != "UVSet0")) {
|
||||||
texture.texcoordSet = 1;
|
texture.texcoordSet = 1;
|
||||||
}
|
}
|
||||||
|
@ -61,14 +74,11 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
|
|
||||||
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
|
// FBX files generated by 3DSMax have an intermediate texture parent, apparently
|
||||||
foreach (const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) {
|
foreach (const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) {
|
||||||
if (textureFilenames.contains(childTextureID)) {
|
if (_textureFilenames.contains(childTextureID)) {
|
||||||
diffuseTexture = getTexture(diffuseTextureID);
|
diffuseTexture = getTexture(diffuseTextureID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO associate this per part
|
|
||||||
//diffuseTexture.texcoordSet = matchTextureUVSetToAttributeChannel(diffuseTexture.texcoordSetName, extracted.texcoordSetMap);
|
|
||||||
|
|
||||||
material.diffuseTexture = diffuseTexture;
|
material.diffuseTexture = diffuseTexture;
|
||||||
|
|
||||||
detectDifferentUVs = (diffuseTexture.texcoordSet != 0) || (!diffuseTexture.transform.isIdentity());
|
detectDifferentUVs = (diffuseTexture.texcoordSet != 0) || (!diffuseTexture.transform.isIdentity());
|
||||||
|
@ -79,12 +89,6 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
if (!bumpTextureID.isNull()) {
|
if (!bumpTextureID.isNull()) {
|
||||||
normalTexture = getTexture(bumpTextureID);
|
normalTexture = getTexture(bumpTextureID);
|
||||||
|
|
||||||
// TODO Need to generate tangent space at association per part
|
|
||||||
//generateTangents = true;
|
|
||||||
|
|
||||||
// TODO at per part association time
|
|
||||||
// normalTexture.texcoordSet = matchTextureUVSetToAttributeChannel(normalTexture.texcoordSetName, extracted.texcoordSetMap);
|
|
||||||
|
|
||||||
material.normalTexture = normalTexture;
|
material.normalTexture = normalTexture;
|
||||||
|
|
||||||
detectDifferentUVs |= (normalTexture.texcoordSet != 0) || (!normalTexture.transform.isIdentity());
|
detectDifferentUVs |= (normalTexture.texcoordSet != 0) || (!normalTexture.transform.isIdentity());
|
||||||
|
@ -94,8 +98,6 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
QString specularTextureID = specularTextures.value(material.materialID);
|
QString specularTextureID = specularTextures.value(material.materialID);
|
||||||
if (!specularTextureID.isNull()) {
|
if (!specularTextureID.isNull()) {
|
||||||
specularTexture = getTexture(specularTextureID);
|
specularTexture = getTexture(specularTextureID);
|
||||||
// TODO at per part association time
|
|
||||||
// specularTexture.texcoordSet = matchTextureUVSetToAttributeChannel(specularTexture.texcoordSetName, extracted.texcoordSetMap);
|
|
||||||
detectDifferentUVs |= (specularTexture.texcoordSet != 0) || (!specularTexture.transform.isIdentity());
|
detectDifferentUVs |= (specularTexture.texcoordSet != 0) || (!specularTexture.transform.isIdentity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,13 +117,9 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
emissiveTexture = getTexture(ambientTextureID);
|
emissiveTexture = getTexture(ambientTextureID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : do this at per part association
|
|
||||||
//emissiveTexture.texcoordSet = matchTextureUVSetToAttributeChannel(emissiveTexture.texcoordSetName, extracted.texcoordSetMap);
|
|
||||||
|
|
||||||
material.emissiveParams = emissiveParams;
|
material.emissiveParams = emissiveParams;
|
||||||
material.emissiveTexture = emissiveTexture;
|
material.emissiveTexture = emissiveTexture;
|
||||||
|
|
||||||
|
|
||||||
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
detectDifferentUVs |= (emissiveTexture.texcoordSet != 0) || (!emissiveTexture.transform.isIdentity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue