From 4566e195269c0c27d94411d08aa64d2f85825761 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Thu, 23 Jan 2025 16:10:28 +0100 Subject: [PATCH] Adding clang format --- .clang-format | 6 ++++++ src/util/Model.h | 1 + src/util/ModelLoader.cpp | 27 +++++++++++++++++++++++++-- src/util/ModelLoader.h | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c7e273c --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +BasedOnStyle: LLVM +IndentWidth: 4 +ColumnLimit: 140 +DerivePointerAlignment: false +PointerAlignment: Left +BreakBeforeBraces: Allman \ No newline at end of file diff --git a/src/util/Model.h b/src/util/Model.h index 76a799a..efee0e6 100644 --- a/src/util/Model.h +++ b/src/util/Model.h @@ -5,6 +5,7 @@ class Model { +public: std::vector positions; std::vector indices; }; diff --git a/src/util/ModelLoader.cpp b/src/util/ModelLoader.cpp index ffee823..793d2a3 100644 --- a/src/util/ModelLoader.cpp +++ b/src/util/ModelLoader.cpp @@ -1,6 +1,29 @@ #include "ModelLoader.h" +#include +#include +#include +#include +#include -PModel ModelLoader::loadModel(std::string_view filename) +std::vector ModelLoader::loadModel(std::string_view filename) { - + Assimp::Importer importer; + const aiScene* scene = importer.ReadFile(filename, 0); + for (int m = 0; m < scene->mNumMeshes; ++m) + { + PModel result = std::make_unique(); + const aiMesh* mesh = scene->mMeshes[m]; + for (int v = 0; v < mesh->mNumVertices; ++v) + { + auto aiVert = mesh->mVertices[v]; + result->positions.add(glm::vec3(aiVert.x, aiVert.y, aiVert.z)); + } + for (int i = 0; i < mesh->mNumFaces; ++i) + { + auto face = mesh->mFaces[i]; + result->indices.add(face.mIndices[0]); + result->indices.add(face.mIndices[1]); + result->indices.add(face.mIndices[2]); + } + } } diff --git a/src/util/ModelLoader.h b/src/util/ModelLoader.h index 066de6d..4632a5a 100644 --- a/src/util/ModelLoader.h +++ b/src/util/ModelLoader.h @@ -4,6 +4,6 @@ class ModelLoader { public: - static PModel loadModel(std::string_view filename); + static std::vector loadModel(std::string_view filename); private: }; \ No newline at end of file