mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 19:56:44 +02:00
More fixes for the OBJ reader. The data seems to be fine. The rendering seems not so fine.
This commit is contained in:
parent
c5bb419bd1
commit
e9035a1efb
1 changed files with 25 additions and 21 deletions
|
@ -463,7 +463,6 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
QMap<QString, int> materialMeshIdMap;
|
QMap<QString, int> materialMeshIdMap;
|
||||||
QVector<FBXMesh> fbxMeshes;
|
QVector<FBXMesh> fbxMeshes;
|
||||||
for (int i = 0, meshPartCount = 0; i < geometry.meshes[0].parts.count(); i++, meshPartCount++) {
|
for (int i = 0, meshPartCount = 0; i < geometry.meshes[0].parts.count(); i++, meshPartCount++) {
|
||||||
FBXMeshPart& meshPart = geometry.meshes[0].parts[i];
|
|
||||||
FaceGroup faceGroup = faceGroups[meshPartCount];
|
FaceGroup faceGroup = faceGroups[meshPartCount];
|
||||||
bool specifiesUV = false;
|
bool specifiesUV = false;
|
||||||
foreach(OBJFace face, faceGroup) {
|
foreach(OBJFace face, faceGroup) {
|
||||||
|
@ -473,20 +472,15 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
// Create a new FBXMesh for this material mapping.
|
// Create a new FBXMesh for this material mapping.
|
||||||
materialMeshIdMap.insert(face.materialName, materialMeshIdMap.count());
|
materialMeshIdMap.insert(face.materialName, materialMeshIdMap.count());
|
||||||
|
|
||||||
FBXMesh meshNew = geometry.meshes[0];
|
FBXMesh meshNew;
|
||||||
meshNew.meshIndex = fbxMeshes.count();
|
meshNew.modelTransform = geometry.meshes[0].modelTransform;
|
||||||
|
meshNew.meshExtents = geometry.meshes[0].meshExtents;
|
||||||
|
meshNew.meshIndex = 0;// fbxMeshes.count();
|
||||||
meshNew.clusters.append(cluster);
|
meshNew.clusters.append(cluster);
|
||||||
|
|
||||||
// Add this mesh part to the mesh.
|
|
||||||
meshNew.parts.append(meshPart);
|
|
||||||
|
|
||||||
// Add it to the mesh vector.
|
|
||||||
fbxMeshes.append(meshNew);
|
|
||||||
|
|
||||||
// Do some of the material logic (which previously lived below) now.
|
// Do some of the material logic (which previously lived below) now.
|
||||||
// All the faces in the same group will have the same name and material.
|
// All the faces in the same group will have the same name and material.
|
||||||
OBJFace leadFace = faceGroup[0];
|
QString groupMaterialName = face.materialName;
|
||||||
QString groupMaterialName = leadFace.materialName;
|
|
||||||
if (groupMaterialName.isEmpty() && specifiesUV) {
|
if (groupMaterialName.isEmpty() && specifiesUV) {
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
qCDebug(modelformat) << "OBJ Reader WARNING: " << url
|
qCDebug(modelformat) << "OBJ Reader WARNING: " << url
|
||||||
|
@ -505,14 +499,21 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
needsMaterialLibrary = groupMaterialName != SMART_DEFAULT_MATERIAL_NAME;
|
needsMaterialLibrary = groupMaterialName != SMART_DEFAULT_MATERIAL_NAME;
|
||||||
}
|
}
|
||||||
materials[groupMaterialName] = material;
|
materials[groupMaterialName] = material;
|
||||||
meshPart.materialID = groupMaterialName;
|
geometry.meshes[0].parts[i].materialID = groupMaterialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add this mesh part.
|
||||||
|
meshNew.parts.append(FBXMeshPart(geometry.meshes[0].parts[i]));
|
||||||
|
|
||||||
|
// Add it to the mesh vector.
|
||||||
|
fbxMeshes.append(meshNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that each mesh has been created with its own unique material mappings, fill them with data (vertex data is duplicated, face data is not).
|
// Now that each mesh has been created with its own unique material mappings, fill them with data (vertex data is duplicated, face data is not).
|
||||||
foreach(OBJFace face, faceGroup) {
|
foreach(OBJFace face, faceGroup) {
|
||||||
FBXMesh& mesh = fbxMeshes[materialMeshIdMap[face.materialName]];
|
FBXMesh& mesh = fbxMeshes[materialMeshIdMap[face.materialName]];
|
||||||
|
FBXMeshPart& meshPart = mesh.parts.last();
|
||||||
|
|
||||||
glm::vec3 v0 = checked_at(vertices, face.vertexIndices[0]);
|
glm::vec3 v0 = checked_at(vertices, face.vertexIndices[0]);
|
||||||
glm::vec3 v1 = checked_at(vertices, face.vertexIndices[1]);
|
glm::vec3 v1 = checked_at(vertices, face.vertexIndices[1]);
|
||||||
|
@ -527,11 +528,11 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
|
|
||||||
// Add the vertices.
|
// Add the vertices.
|
||||||
meshPart.triangleIndices.append(mesh.vertices.count()); // not face.vertexIndices into vertices
|
meshPart.triangleIndices.append(mesh.vertices.count()); // not face.vertexIndices into vertices
|
||||||
mesh.vertices << v0;
|
mesh.vertices.append(v0);
|
||||||
meshPart.triangleIndices.append(mesh.vertices.count());
|
meshPart.triangleIndices.append(mesh.vertices.count());
|
||||||
mesh.vertices << v1;
|
mesh.vertices.append(v1);
|
||||||
meshPart.triangleIndices.append(mesh.vertices.count());
|
meshPart.triangleIndices.append(mesh.vertices.count());
|
||||||
mesh.vertices << v2;
|
mesh.vertices.append(v2);
|
||||||
|
|
||||||
glm::vec3 n0, n1, n2;
|
glm::vec3 n0, n1, n2;
|
||||||
if (face.normalIndices.count()) {
|
if (face.normalIndices.count()) {
|
||||||
|
@ -543,17 +544,20 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
// generate normals from triangle plane if not provided
|
// generate normals from triangle plane if not provided
|
||||||
n0 = n1 = n2 = glm::cross(v1 - v0, v2 - v0);
|
n0 = n1 = n2 = glm::cross(v1 - v0, v2 - v0);
|
||||||
}
|
}
|
||||||
mesh.normals << n0 << n1 << n2;
|
mesh.normals.append(n0);
|
||||||
|
mesh.normals.append(n1);
|
||||||
|
mesh.normals.append(n2);
|
||||||
if (face.textureUVIndices.count()) {
|
if (face.textureUVIndices.count()) {
|
||||||
specifiesUV = true;
|
specifiesUV = true;
|
||||||
mesh.texCoords <<
|
mesh.texCoords.append(checked_at(textureUVs, face.textureUVIndices[0]));
|
||||||
checked_at(textureUVs, face.textureUVIndices[0]) <<
|
mesh.texCoords.append(checked_at(textureUVs, face.textureUVIndices[1]));
|
||||||
checked_at(textureUVs, face.textureUVIndices[1]) <<
|
mesh.texCoords.append(checked_at(textureUVs, face.textureUVIndices[2]));
|
||||||
checked_at(textureUVs, face.textureUVIndices[2]);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
glm::vec2 corner(0.0f, 1.0f);
|
glm::vec2 corner(0.0f, 1.0f);
|
||||||
mesh.texCoords << corner << corner << corner;
|
mesh.texCoords.append(corner);
|
||||||
|
mesh.texCoords.append(corner);
|
||||||
|
mesh.texCoords.append(corner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue