mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 18:24:09 +02:00
Restoring hifi version of the OBJ files to get rid of my debug nonsense.
This commit is contained in:
parent
dd2ed559b6
commit
5bf3da9a7f
2 changed files with 96 additions and 104 deletions
|
@ -302,10 +302,9 @@ QNetworkReply* OBJReader::request(QUrl& url, bool isTest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry, float& scaleGuess, int index) {
|
bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry, float& scaleGuess) {
|
||||||
FaceGroup faces;
|
FaceGroup faces;
|
||||||
geometry.meshes.append(FBXMesh());
|
FBXMesh& mesh = geometry.meshes[0];
|
||||||
FBXMesh& mesh = geometry.meshes.last();
|
|
||||||
mesh.parts.append(FBXMeshPart());
|
mesh.parts.append(FBXMeshPart());
|
||||||
FBXMeshPart& meshPart = mesh.parts.last();
|
FBXMeshPart& meshPart = mesh.parts.last();
|
||||||
bool sawG = false;
|
bool sawG = false;
|
||||||
|
@ -434,15 +433,15 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
|
|
||||||
_url = url;
|
_url = url;
|
||||||
geometry.meshExtents.reset();
|
geometry.meshExtents.reset();
|
||||||
// geometry.meshes.append(FBXMesh());
|
geometry.meshes.append(FBXMesh());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// call parseOBJGroup as long as it's returning true. Each successful call will
|
// call parseOBJGroup as long as it's returning true. Each successful call will
|
||||||
// add a new meshPart to the geometry's single mesh.
|
// add a new meshPart to the geometry's single mesh.
|
||||||
int i = 0;
|
while (parseOBJGroup(tokenizer, mapping, geometry, scaleGuess)) {}
|
||||||
while (parseOBJGroup(tokenizer, mapping, geometry, scaleGuess, i)) {
|
|
||||||
++i;
|
FBXMesh& mesh = geometry.meshes[0];
|
||||||
}
|
mesh.meshIndex = 0;
|
||||||
|
|
||||||
geometry.joints.resize(1);
|
geometry.joints.resize(1);
|
||||||
geometry.joints[0].isFree = false;
|
geometry.joints[0].isFree = false;
|
||||||
|
@ -456,10 +455,6 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
|
|
||||||
geometry.jointIndices["x"] = 1;
|
geometry.jointIndices["x"] = 1;
|
||||||
|
|
||||||
for (int i = 0; i < geometry.meshes.count(); i++) {
|
|
||||||
FBXMesh& mesh = geometry.meshes[i];
|
|
||||||
mesh.meshIndex = i;
|
|
||||||
|
|
||||||
FBXCluster cluster;
|
FBXCluster cluster;
|
||||||
cluster.jointIndex = 0;
|
cluster.jointIndex = 0;
|
||||||
cluster.inverseBindMatrix = glm::mat4(1, 0, 0, 0,
|
cluster.inverseBindMatrix = glm::mat4(1, 0, 0, 0,
|
||||||
|
@ -468,11 +463,10 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
0, 0, 0, 1);
|
0, 0, 0, 1);
|
||||||
mesh.clusters.append(cluster);
|
mesh.clusters.append(cluster);
|
||||||
|
|
||||||
for (int meshPartCount = 0; meshPartCount < mesh.parts.count( ); ++meshPartCount) {
|
for (int i = 0, meshPartCount = 0; i < mesh.parts.count(); i++, meshPartCount++) {
|
||||||
FBXMeshPart& meshPart = mesh.parts[meshPartCount];
|
FBXMeshPart& meshPart = mesh.parts[i];
|
||||||
FaceGroup faceGroup = faceGroups[meshPartCount];
|
FaceGroup faceGroup = faceGroups[meshPartCount];
|
||||||
bool specifiesUV = false;
|
bool specifiesUV = false;
|
||||||
|
|
||||||
foreach(OBJFace face, faceGroup) {
|
foreach(OBJFace face, faceGroup) {
|
||||||
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]);
|
||||||
|
@ -489,8 +483,7 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
n0 = checked_at(normals, face.normalIndices[0]);
|
n0 = checked_at(normals, face.normalIndices[0]);
|
||||||
n1 = checked_at(normals, face.normalIndices[1]);
|
n1 = checked_at(normals, face.normalIndices[1]);
|
||||||
n2 = checked_at(normals, face.normalIndices[2]);
|
n2 = checked_at(normals, face.normalIndices[2]);
|
||||||
}
|
} else { // generate normals from triangle plane if not provided
|
||||||
else { // 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 << n0 << n1 << n2;
|
||||||
|
@ -500,8 +493,7 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
checked_at(textureUVs, face.textureUVIndices[0]) <<
|
checked_at(textureUVs, face.textureUVIndices[0]) <<
|
||||||
checked_at(textureUVs, face.textureUVIndices[1]) <<
|
checked_at(textureUVs, face.textureUVIndices[1]) <<
|
||||||
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 << corner << corner << corner;
|
||||||
}
|
}
|
||||||
|
@ -510,10 +502,10 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
OBJFace leadFace = faceGroup[0];
|
OBJFace leadFace = faceGroup[0];
|
||||||
QString groupMaterialName = leadFace.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
|
||||||
<< " needs a texture that isn't specified. Using default mechanism.";
|
<< " needs a texture that isn't specified. Using default mechanism.";
|
||||||
#endif
|
#endif
|
||||||
groupMaterialName = SMART_DEFAULT_MATERIAL_NAME;
|
groupMaterialName = SMART_DEFAULT_MATERIAL_NAME;
|
||||||
}
|
}
|
||||||
if (!groupMaterialName.isEmpty()) {
|
if (!groupMaterialName.isEmpty()) {
|
||||||
|
@ -529,6 +521,7 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
materials[groupMaterialName] = material;
|
materials[groupMaterialName] = material;
|
||||||
meshPart.materialID = groupMaterialName;
|
meshPart.materialID = groupMaterialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we got a hint about units, scale all the points
|
// if we got a hint about units, scale all the points
|
||||||
|
@ -539,13 +532,12 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.meshExtents.reset();
|
mesh.meshExtents.reset();
|
||||||
foreach(const glm::vec3& vertex, mesh.vertices) {
|
foreach (const glm::vec3& vertex, mesh.vertices) {
|
||||||
mesh.meshExtents.addPoint(vertex);
|
mesh.meshExtents.addPoint(vertex);
|
||||||
geometry.meshExtents.addPoint(vertex);
|
geometry.meshExtents.addPoint(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
FBXReader::buildModelMesh(mesh, url.toString());
|
FBXReader::buildModelMesh(mesh, url.toString());
|
||||||
}
|
|
||||||
// fbxDebugDump(geometry);
|
// fbxDebugDump(geometry);
|
||||||
} catch(const std::exception& e) {
|
} catch(const std::exception& e) {
|
||||||
qCDebug(modelformat) << "OBJ reader fail: " << e.what();
|
qCDebug(modelformat) << "OBJ reader fail: " << e.what();
|
||||||
|
|
|
@ -79,7 +79,7 @@ private:
|
||||||
QUrl _url;
|
QUrl _url;
|
||||||
|
|
||||||
QHash<QByteArray, bool> librariesSeen;
|
QHash<QByteArray, bool> librariesSeen;
|
||||||
bool parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry, float& scaleGuess, int index);
|
bool parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, FBXGeometry& geometry, float& scaleGuess);
|
||||||
void parseMaterialLibrary(QIODevice* device);
|
void parseMaterialLibrary(QIODevice* device);
|
||||||
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.
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue