From d9b65f9bd80f33b72668f09c945874b1dccedab2 Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Sat, 24 May 2014 08:41:33 -0700 Subject: [PATCH] Properly orient mirrored blend mesh faces If the mirrored axis count is odd, the face orientation has logically been inverted. In such cases, the winding order should be inverted as well, easing the burden on applications sensitive to index ordering (e.g., one-sided renderers) to detect and fix such issues after import. Add this functionality for .blend meshes. --- code/BlenderModifier.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/code/BlenderModifier.cpp b/code/BlenderModifier.cpp index e2bea4d85..74410d0a0 100644 --- a/code/BlenderModifier.cpp +++ b/code/BlenderModifier.cpp @@ -248,6 +248,15 @@ void BlenderModifier_Mirror :: DoIt(aiNode& out, ConversionData& conv_data, co } } + // Only reverse the winding order if an odd number of axes were mirrored. + if (xs * ys * zs < 0) { + for( unsigned int i = 0; i < mesh->mNumFaces; i++) { + aiFace& face = mesh->mFaces[i]; + for( unsigned int fi = 0; fi < face.mNumIndices / 2; ++fi) + std::swap( face.mIndices[fi], face.mIndices[face.mNumIndices - 1 - fi]); + } + } + conv_data.meshes->push_back(mesh); } unsigned int* nind = new unsigned int[out.mNumMeshes*2];