Skip to content

Commit

Permalink
Fix glm detail namespace issue
Browse files Browse the repository at this point in the history
  • Loading branch information
KredeGC committed Nov 30, 2023
1 parent bad3fde commit 873a858
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
18 changes: 9 additions & 9 deletions Mahakam/src/Mahakam/Math/Math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ namespace Mahakam::Math

// Compute X scale factor and normalize first row.
scale.x = length(Row[0]);
Row[0] = detail::scale(Row[0], static_cast<T>(1));
Row[0] = glm::detail::scale(Row[0], static_cast<T>(1));
scale.y = length(Row[1]);
Row[1] = detail::scale(Row[1], static_cast<T>(1));
Row[1] = glm::detail::scale(Row[1], static_cast<T>(1));
scale.z = length(Row[2]);
Row[2] = detail::scale(Row[2], static_cast<T>(1));
Row[2] = glm::detail::scale(Row[2], static_cast<T>(1));

// At this point, the matrix (in rows[]) is orthonormal.
// Check for a coordinate system flip. If the determinant
Expand Down Expand Up @@ -156,26 +156,26 @@ namespace Mahakam::Math
// Compute X scale factor and normalize first row.
scale.x = length(Row[0]);// v3Length(Row[0]);

Row[0] = detail::scale(Row[0], static_cast<T>(1));
Row[0] = glm::detail::scale(Row[0], static_cast<T>(1));

// Compute XY shear factor and make 2nd row orthogonal to 1st.
Skew.z = dot(Row[0], Row[1]);
Row[1] = detail::combine(Row[1], Row[0], static_cast<T>(1), -Skew.z);
Row[1] = glm::detail::combine(Row[1], Row[0], static_cast<T>(1), -Skew.z);

// Now, compute Y scale and normalize 2nd row.
scale.y = length(Row[1]);
Row[1] = detail::scale(Row[1], static_cast<T>(1));
Row[1] = glm::detail::scale(Row[1], static_cast<T>(1));
Skew.z /= scale.y;

// Compute XZ and YZ shears, orthogonalize 3rd row.
Skew.y = glm::dot(Row[0], Row[2]);
Row[2] = detail::combine(Row[2], Row[0], static_cast<T>(1), -Skew.y);
Row[2] = glm::detail::combine(Row[2], Row[0], static_cast<T>(1), -Skew.y);
Skew.x = glm::dot(Row[1], Row[2]);
Row[2] = detail::combine(Row[2], Row[1], static_cast<T>(1), -Skew.x);
Row[2] = glm::detail::combine(Row[2], Row[1], static_cast<T>(1), -Skew.x);

// Next, get Z scale and normalize 3rd row.
scale.z = length(Row[2]);
Row[2] = detail::scale(Row[2], static_cast<T>(1));
Row[2] = glm::detail::scale(Row[2], static_cast<T>(1));
Skew.y /= scale.z;
Skew.x /= scale.z;

Expand Down
54 changes: 26 additions & 28 deletions Mahakam/src/Mahakam/Renderer/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,45 +334,43 @@ namespace Mahakam
{
UnorderedMap<uint32_t, uint32_t> nodeIndex; // Node ID to hierarchy index

// Populate node hierarchy
for (int rootNode : scene.nodes)
{
// Populate node hierarchy
GLTFReadNodeHierarchy(model, nodeIndex, rootNode, -1, skinnedMesh);

// Extract bone transformations
if (skinnedMesh->Props.IncludeBones)
// Extract bone transformations
if (skinnedMesh->Props.IncludeBones)
{
for (auto& skinNode : model.nodes)
{
for (auto& skinNode : model.nodes)
{
if (skinNode.skin < 0)
continue;
if (skinNode.skin < 0)
continue;

// Get the skin from the node
auto& skin = model.skins[skinNode.skin];
// Get the skin from the node
auto& skin = model.skins[skinNode.skin];

// Get the affected nodes and their bind matrices
auto& joints = skin.joints;
const auto& accessor = model.accessors[skin.inverseBindMatrices];
const auto& bufferView = model.bufferViews[accessor.bufferView];
const auto& buffer = model.buffers[bufferView.buffer];
// Get the affected nodes and their bind matrices
auto& joints = skin.joints;
const auto& accessor = model.accessors[skin.inverseBindMatrices];
const auto& bufferView = model.bufferViews[accessor.bufferView];
const auto& buffer = model.buffers[bufferView.buffer];

MH_ASSERT(joints.size() == accessor.count, "Bone count doesn't match joint count");
MH_ASSERT(joints.size() == accessor.count, "Bone count doesn't match joint count");

const glm::mat4* invMatrices = reinterpret_cast<const glm::mat4*>(&buffer.data[bufferView.byteOffset + accessor.byteOffset]);
const glm::mat4* invMatrices = reinterpret_cast<const glm::mat4*>(&buffer.data[bufferView.byteOffset + accessor.byteOffset]);

// Extract joint data
skinnedMesh->BoneMap.reserve(joints.size());
// Extract joint data
skinnedMesh->BoneMap.reserve(joints.size());

// Add the bones to the skinned mesh
for (uint32_t i = 0; i < joints.size(); i++)
{
int nodeID = joints[i];
const auto& node = model.nodes[nodeID];
// Add the bones to the skinned mesh
for (uint32_t i = 0; i < joints.size(); i++)
{
int nodeID = joints[i];
const auto& node = model.nodes[nodeID];

// Override offset to be the bone's inverse matrix
skinnedMesh->NodeHierarchy[nodeIndex[nodeID]].Offset = invMatrices[i];
skinnedMesh->BoneMap.insert({ nodeIndex[nodeID], i });
}
// Override offset to be the bone's inverse matrix
skinnedMesh->NodeHierarchy[nodeIndex[nodeID]].Offset = invMatrices[i];
skinnedMesh->BoneMap.insert({ nodeIndex[nodeID], i });
}
}
}
Expand Down

0 comments on commit 873a858

Please sign in to comment.