Skip to content

Commit b7fcc94

Browse files
committed
Removed assimp matrices and vectors and added conversion functions
1 parent e310e84 commit b7fcc94

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

engine/utils/math/mat/Mat4.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ struct Mat<T, 4, 4>
214214
{matrix[0][3], matrix[1][3], matrix[2][3], matrix[3][3]}};
215215
}
216216

217+
static inline constexpr Mat<T, 4, 4> Scale(const Vec<T, 3>& scale)
218+
{
219+
Mat<T,4,4> mat = Mat<T,4,4>::Identity();
220+
mat[0][0] = scale.x;
221+
mat[1][1] = scale.y;
222+
mat[2][2] = scale.z;
223+
return mat;
224+
}
225+
217226
// 'Structors
218227

219228
/**

packer/src/types/MathUtils.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright (c) 2020-present Caps Collective & contributors
3+
// Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr)
4+
//
5+
// This code is released under an unmodified zlib license.
6+
// For conditions of distribution and use, please see:
7+
// https://opensource.org/licenses/Zlib
8+
//
9+
10+
#ifndef SIEGE_ENGINE_PACKER_MATHUTILS_H
11+
#define SIEGE_ENGINE_PACKER_MATHUTILS_H
12+
13+
#include <utils/math/mat/Mat4.h>
14+
#include <assimp/Importer.hpp>
15+
16+
static inline constexpr Siege::Mat4 AssimptMat4ToMat4(const aiMatrix4x4& matrix)
17+
{
18+
return {{matrix.a1, matrix.b1, matrix.c1, matrix.d1},
19+
{matrix.a2, matrix.b2, matrix.c2, matrix.d2},
20+
{matrix.a3, matrix.b3, matrix.c3, matrix.d3},
21+
{matrix.a4, matrix.b4, matrix.c4, matrix.d4}};
22+
}
23+
24+
#endif // SIEGE_ENGINE_PACKER_MATHUTILS_H

packer/src/types/StaticMeshDataPacker.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//
99

1010
#include "StaticMeshDataPacker.h"
11+
#include "MathUtils.h"
1112

1213
#include <assimp/postprocess.h>
1314
#include <assimp/scene.h>
@@ -16,7 +17,6 @@
1617
#include <utils/Logging.h>
1718

1819
#include <algorithm>
19-
#include <assimp/Importer.hpp>
2020
#include <fstream>
2121

2222
enum RequestPathStage
@@ -50,7 +50,7 @@ static RequestPathStage GetRequestPathStage(const Siege::String& requestPath,
5050

5151
static void GetMeshData(const aiScene* scene,
5252
const aiMesh* mesh,
53-
const aiMatrix4x4t<ai_real>& matrix,
53+
const Siege::Mat4& mat,
5454
OUT std::vector<Siege::BaseVertex>& vertices,
5555
OUT std::vector<uint32_t>& indices)
5656
{
@@ -59,8 +59,11 @@ static void GetMeshData(const aiScene* scene,
5959
Siege::BaseVertex vertex {};
6060

6161
aiVector3t<ai_real> vert = mesh->mVertices[i];
62-
vert *= matrix;
63-
vertex.position = {vert.x, vert.y, vert.z};
62+
Siege::Vec4 v = {vert.x, vert.y, vert.z, 1.f};
63+
64+
v = mat * v;
65+
66+
vertex.position = {v.x, v.y, v.z};
6467

6568
aiVector3t<ai_real> norm = mesh->mNormals[i];
6669
vertex.normal = {norm.x, norm.y, norm.z};
@@ -93,7 +96,7 @@ static void GetMeshesForNode(const aiScene* scene,
9396
const aiNode* node,
9497
const Siege::String& requestPath,
9598
Siege::String currentPath,
96-
aiMatrix4x4t<ai_real> matrix,
99+
Siege::Mat4 matrix,
97100
OUT std::vector<Siege::BaseVertex>& vertices,
98101
OUT std::vector<uint32_t>& indices)
99102
{
@@ -109,7 +112,7 @@ static void GetMeshesForNode(const aiScene* scene,
109112

110113
if (nodePathStage == CHILD || nodePathStage == SELF)
111114
{
112-
matrix *= node->mTransformation;
115+
matrix *= AssimptMat4ToMat4(node->mTransformation);
113116
}
114117

115118
for (uint32_t i = 0; i < node->mNumMeshes; i++)
@@ -175,7 +178,7 @@ void* PackStaticMeshFile(const Siege::String& filePath, const Siege::String& ass
175178

176179
CC_LOG_INFO("Reading static mesh for file {} with node path {}", it->second, requestedNodePath)
177180

178-
aiMatrix4x4t<ai_real> baseXform;
181+
Siege::Mat4 baseXform = Siege::Mat4::Identity();
179182
auto flipAxesIt = attributes.find(TOKEN_FLIP_AXES);
180183
if (flipAxesIt != attributes.end())
181184
{
@@ -186,7 +189,7 @@ void* PackStaticMeshFile(const Siege::String& filePath, const Siege::String& ass
186189

187190
for (int32_t i = 0; i < flipAxesIt->second.Size(); ++i)
188191
{
189-
aiVector3t<ai_real> scale {1.f, 1.f, 1.f};
192+
Siege::Vec4 scale = {1.f, 1.f, 1.f, 1.f};
190193
switch (flipAxesIt->second[i])
191194
{
192195
case 'x':
@@ -203,8 +206,7 @@ void* PackStaticMeshFile(const Siege::String& filePath, const Siege::String& ass
203206
flipAxesIt->second[i])
204207
break;
205208
}
206-
aiMatrix4x4t<ai_real> scalingMat;
207-
baseXform *= aiMatrix4x4t<ai_real>::Scaling(scale, scalingMat);
209+
baseXform *= Siege::Mat4::Scale(scale);
208210
}
209211
}
210212

0 commit comments

Comments
 (0)