From 7b46e71f33913351f0605667cd621cbf77dcb4e1 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 25 Apr 2020 12:01:21 +0200 Subject: [PATCH] Added flag to flip vertex position y coordinates --- base/VulkanglTFModel.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/base/VulkanglTFModel.hpp b/base/VulkanglTFModel.hpp index cf035e67..242b13dc 100644 --- a/base/VulkanglTFModel.hpp +++ b/base/VulkanglTFModel.hpp @@ -541,7 +541,8 @@ namespace vkglTF typedef enum FileLoadingFlags { None = 0, PreTransformVertices = 1, - PreMultiplyVertexColors = 2 + PreMultiplyVertexColors = 2, + FlipY = 3 }; /* @@ -1042,9 +1043,10 @@ namespace vkglTF } // Pre-Calculations for requested features - if ((fileLoadingFlags & FileLoadingFlags::PreTransformVertices) || (fileLoadingFlags & FileLoadingFlags::PreMultiplyVertexColors)) { + if ((fileLoadingFlags & FileLoadingFlags::PreTransformVertices) || (fileLoadingFlags & FileLoadingFlags::PreMultiplyVertexColors) || (fileLoadingFlags & FileLoadingFlags::FlipY)) { const bool preTransform = fileLoadingFlags & FileLoadingFlags::PreTransformVertices; const bool preMultiplyColor = fileLoadingFlags & FileLoadingFlags::PreMultiplyVertexColors; + const bool flipY = fileLoadingFlags & FileLoadingFlags::FlipY; for (Node* node : linearNodes) { if (node->mesh) { const glm::mat4 localMatrix = node->getMatrix(); @@ -1055,6 +1057,10 @@ namespace vkglTF if (preTransform) { vertex.pos = glm::vec3(localMatrix * glm::vec4(vertex.pos, 1.0f)); } + // Flip Y-Axis of vertex positions + if (preTransform) { + vertex.pos.y *= -1.0f; + } // Pre-Multiply vertex colors with material base color if (preMultiplyColor) { vertex.color = primitive->material.baseColorFactor * vertex.color;