From 68d33a6e133bd0732b58462f2de77a88978e1e1c Mon Sep 17 00:00:00 2001 From: Promit Roy Date: Thu, 17 Mar 2022 14:55:26 -0400 Subject: [PATCH 1/2] Added support for more bone weights in GLTF2 The GLTF2 importer doesn't actually read beyond the first four bone weights (first attribute). This patch expands the parser to store as many bone weights as are available in the file. --- code/AssetLib/glTF2/glTF2Importer.cpp | 43 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index d2fb1e9b8..47f563c16 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -935,8 +935,10 @@ static void BuildVertexWeightMapping(Mesh::Primitive &primitive, std::vectorExtractData(weights); + Weights **weights = new Weights*[attr.weight.size()]; + for (size_t w = 0; w < attr.weight.size(); ++w) { + attr.weight[w]->ExtractData(weights[w]); + } struct Indices8 { uint8_t values[4]; @@ -944,12 +946,18 @@ static void BuildVertexWeightMapping(Mesh::Primitive &primitive, std::vectorGetElementSize() == 4) { - attr.joint[0]->ExtractData(indices8); + indices8 = new Indices8*[attr.joint.size()]; + for (size_t j = 0; j < attr.joint.size(); ++j) { + attr.joint[j]->ExtractData(indices8[j]); + } } else { - attr.joint[0]->ExtractData(indices16); + indices16 = new Indices16 *[attr.joint.size()]; + for (size_t j = 0; j < attr.joint.size(); ++j) { + attr.joint[j]->ExtractData(indices16[j]); + } } // if (nullptr == indices8 && nullptr == indices16) { @@ -958,17 +966,26 @@ static void BuildVertexWeightMapping(Mesh::Primitive &primitive, std::vector 0 && bone < map.size()) { - map[bone].reserve(8); - map[bone].emplace_back(static_cast(i), weight); + for (size_t w = 0; w < attr.weight.size(); ++w) { + for (size_t i = 0; i < num_vertices; ++i) { + for (int j = 0; j < 4; ++j) { + const unsigned int bone = (indices8 != nullptr) ? indices8[w][i].values[j] : indices16[w][i].values[j]; + const float weight = weights[w][i].values[j]; + if (weight > 0 && bone < map.size()) { + map[bone].reserve(8); + map[bone].emplace_back(static_cast(i), weight); + } } } } + for (size_t w = 0; w < attr.weight.size(); ++w) { + delete[] weights[w]; + if(indices8) + delete[] indices8[w]; + if (indices16) + delete[] indices16[w]; + } delete[] weights; delete[] indices8; delete[] indices16; From 0e4ba1fdd1cce363bfa5e727ddd5f44e3cd1dff4 Mon Sep 17 00:00:00 2001 From: Koekto-code <97475827+Koekto-code@users.noreply.github.com> Date: Thu, 11 Aug 2022 22:10:16 +0300 Subject: [PATCH 2/2] Fix problems setting DirectX_LIBRARY DirectX_LIBRARY was always clearing, though DirectX_PREFIX_PATH was not changed. This is because I had some semicolons at begin of DirectX_PREFIX_PATH and the macro `clear_if_changed` discarded them. Now it saves all extra semicolons and check passes. --- cmake-modules/FindPkgMacros.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake-modules/FindPkgMacros.cmake b/cmake-modules/FindPkgMacros.cmake index 074cce352..d3a6042a7 100644 --- a/cmake-modules/FindPkgMacros.cmake +++ b/cmake-modules/FindPkgMacros.cmake @@ -54,7 +54,7 @@ macro(clear_if_changed TESTVAR) set(${var} "NOTFOUND" CACHE STRING "x" FORCE) endforeach(var) endif () - set(${TESTVAR}_INT_CHECK ${${TESTVAR}} CACHE INTERNAL "x" FORCE) + set(${TESTVAR}_INT_CHECK "${${TESTVAR}}" CACHE INTERNAL "x" FORCE) endmacro(clear_if_changed) # Try to get some hints from pkg-config, if available