From 0f4189c77e6f28ae0423ea617747ad33c617a92d Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Tue, 16 Jan 2018 09:26:00 +0100 Subject: [PATCH 1/2] Forced 4-bits alignment for glTF buffers --- code/glTF2Asset.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/glTF2Asset.inl b/code/glTF2Asset.inl index 549df747e..53e1aeed1 100644 --- a/code/glTF2Asset.inl +++ b/code/glTF2Asset.inl @@ -485,7 +485,8 @@ uint8_t* new_data; inline size_t Buffer::AppendData(uint8_t* data, size_t length) { size_t offset = this->byteLength; - Grow(length); + // Force alignment to 4 bits + Grow((length + 3) & ~3); memcpy(mData.get() + offset, data, length); return offset; } From 5e6cae3094fee7212eff7e27e65f287a4b778243 Mon Sep 17 00:00:00 2001 From: Alexis Breust Date: Tue, 16 Jan 2018 09:56:44 +0100 Subject: [PATCH 2/2] 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) {