From 5e6cae3094fee7212eff7e27e65f287a4b778243 Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Tue, 16 Jan 2018 09:56:44 +0100 Subject: [PATCH] Force normalized normals --- code/glTF2Exporter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/glTF2Exporter.cpp b/code/glTF2Exporter.cpp index 221a3bf9f..7d420f462 100644 --- a/code/glTF2Exporter.cpp +++ b/code/glTF2Exporter.cpp @@ -708,8 +708,13 @@ void glTF2Exporter::ExportMeshes() if (v) p.attributes.position.push_back(v); /******************** Normals ********************/ + // Normalize all normals as the validator can emit a warning otherwise + for (auto i = 0u; i < aim->mNumVertices; ++i) { + aim->mNormals[i].Normalize(); + } + Ref n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); - if (n) p.attributes.normal.push_back(n); + if (n) p.attributes.normal.push_back(n); /************** Texture coordinates **************/ for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {