Bläddra i källkod

Merge pull request #1712 from wanadev/gltf2-fixes

[glTF2] Fixed buffer alignment
Kim Kulling 7 år sedan
förälder
incheckning
8358d585b0
2 ändrade filer med 8 tillägg och 2 borttagningar
  1. 2 1
      code/glTF2Asset.inl
  2. 6 1
      code/glTF2Exporter.cpp

+ 2 - 1
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;
 }

+ 6 - 1
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<Accessor> 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) {