From ec47c209195b8e1e259441016ae74085da483557 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sat, 20 Oct 2018 21:30:59 +0800 Subject: [PATCH] Fix incorrect normal after texture auto unwrapped glTF normal export temporarily disabled. --- src/gltffile.cpp | 5 +++-- src/meshloader.cpp | 2 +- src/meshresultcontext.cpp | 2 +- src/meshresultcontext.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gltffile.cpp b/src/gltffile.cpp index a25ab188..055be263 100644 --- a/src/gltffile.cpp +++ b/src/gltffile.cpp @@ -26,7 +26,7 @@ GltfFileWriter::GltfFileWriter(MeshResultContext &resultContext, const std::map *resultRigWeights, const QString &filename) : m_filename(filename), - m_outputNormal(true), + m_outputNormal(false), m_outputAnimation(true), m_outputUv(true), m_testOutputAsWhole(false) @@ -221,6 +221,7 @@ GltfFileWriter::GltfFileWriter(MeshResultContext &resultContext, m_json["accessors"][bufferViewIndex]["min"] = {minX, minY, minZ}; bufferViewIndex++; + /* if (m_outputNormal) { bufferViewFromOffset = (int)binaries.size(); m_json["bufferViews"][bufferViewIndex]["buffer"] = 0; @@ -243,7 +244,7 @@ GltfFileWriter::GltfFileWriter(MeshResultContext &resultContext, m_json["accessors"][bufferViewIndex]["count"] = part.second.vertices.size(); m_json["accessors"][bufferViewIndex]["type"] = "VEC3"; bufferViewIndex++; - } + }*/ if (m_outputUv) { bufferViewFromOffset = (int)binaries.size(); diff --git a/src/meshloader.cpp b/src/meshloader.cpp index a01ed47f..9dad1dc7 100644 --- a/src/meshloader.cpp +++ b/src/meshloader.cpp @@ -252,7 +252,7 @@ MeshLoader::MeshLoader(MeshResultContext &resultContext) : for (auto i = 0; i < 3; i++) { int vertexIndex = it.indicies[i]; const ResultVertex *srcVert = &part.second.vertices[vertexIndex]; - const QVector3D *srcNormal = &part.second.interpolatedVertexNormals[vertexIndex]; + const QVector3D *srcNormal = &part.second.interpolatedTriangleVertexNormals[x * 3 + i]; const ResultVertexUv *srcUv = &part.second.vertexUvs[vertexIndex]; //const Material *srcMaterial = &part.second.material; const QVector3D *srcTangent = &part.second.triangleTangents[x]; diff --git a/src/meshresultcontext.cpp b/src/meshresultcontext.cpp index f4922270..436a5aec 100644 --- a/src/meshresultcontext.cpp +++ b/src/meshresultcontext.cpp @@ -339,7 +339,6 @@ void MeshResultContext::calculateResultParts(std::map &parts) bool isSeamVertex = m_seamVertices.end() != m_seamVertices.find(triangle.indicies[i]); if (isNewVertex || isSeamVertex) { int newIndex = resultPart.vertices.size(); - resultPart.interpolatedVertexNormals.push_back(normal); resultPart.verticesOldIndicies.push_back(triangle.indicies[i]); resultPart.vertices.push_back(vertices[triangle.indicies[i]]); ResultVertexUv vertexUv; @@ -352,6 +351,7 @@ void MeshResultContext::calculateResultParts(std::map &parts) } else { newTriangle.indicies[i] = it->second; } + resultPart.interpolatedTriangleVertexNormals.push_back(normal); } resultPart.triangles.push_back(newTriangle); resultPart.uvs.push_back(triangleUvs()[x]); diff --git a/src/meshresultcontext.h b/src/meshresultcontext.h index 60fd9804..8b7d83bc 100644 --- a/src/meshresultcontext.h +++ b/src/meshresultcontext.h @@ -57,7 +57,7 @@ struct ResultPart Material material; std::vector vertices; std::vector verticesOldIndicies; - std::vector interpolatedVertexNormals; + std::vector interpolatedTriangleVertexNormals; std::vector triangles; std::vector uvs; std::vector vertexUvs;