From 70c09b18cd389f5efb167d1bded8aec74500369d Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sun, 12 Jun 2022 21:20:43 +0100
Subject: [PATCH] assimp import

---
 .gitignore                 |  3 ++-
 CMakeLists.txt             |  1 +
 fggl/CMakeLists.txt        |  6 ++---
 fggl/debug/CMakeLists.txt  |  4 +++
 include/fggl/data/geom.hpp | 53 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 include/fggl/data/geom.hpp

diff --git a/.gitignore b/.gitignore
index 68ae9ca..8d5b73b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@ build/
 builds/
 cmake-build-debug/
 cmake-build-debug-coverage/
+cmake-build-debug-coverage-event-trace/
 imgui.ini
 .flatpak-builder/
 compile_commands.json
@@ -13,4 +14,4 @@ compile_commands.json
 # windows vs stuff
 .vs/
 CMakePresets.json
-CMakeSettings.json
\ No newline at end of file
+CMakeSettings.json
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7075353..ed81edf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
 
         conan_cmake_configure(
             REQUIRES
+                assimp/5.2.2
                 opengl/system
                 glfw/3.3.7
                 glad/0.1.35
diff --git a/fggl/CMakeLists.txt b/fggl/CMakeLists.txt
index 99e994a..0c2e40a 100644
--- a/fggl/CMakeLists.txt
+++ b/fggl/CMakeLists.txt
@@ -64,9 +64,9 @@ target_sources(${PROJECT_NAME}
 find_package(yaml-cpp)
 target_link_libraries(fggl PUBLIC yaml-cpp)
 
-# spdlog for cleaner logging
-find_package(spdlog)
-target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog)
+# model loading
+find_package(assimp)
+target_link_libraries(${PROJECT_NAME} PUBLIC assimp)
 
 find_package(freetype)
 target_link_libraries(${PROJECT_NAME} PUBLIC freetype)
diff --git a/fggl/debug/CMakeLists.txt b/fggl/debug/CMakeLists.txt
index 09ac442..3cb822e 100644
--- a/fggl/debug/CMakeLists.txt
+++ b/fggl/debug/CMakeLists.txt
@@ -12,3 +12,7 @@ target_sources(fggl
 	imgui/imgui_impl_glfw.cpp
 	imgui/imgui_impl_opengl3.cpp
 )
+
+# spdlog for cleaner logging
+find_package(spdlog)
+target_link_libraries(fggl PRIVATE spdlog::spdlog)
diff --git a/include/fggl/data/geom.hpp b/include/fggl/data/geom.hpp
new file mode 100644
index 0000000..c640737
--- /dev/null
+++ b/include/fggl/data/geom.hpp
@@ -0,0 +1,53 @@
+/*
+ * ${license.title}
+ * Copyright (C) 2022 ${license.owner}
+ * ${license.mailto}
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+//
+// Created by webpigeon on 11/06/22.
+//
+
+#ifndef FGGL_DATA_GEOM_HPP
+#define FGGL_DATA_GEOM_HPP
+
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+#include <filesystem>
+#include "storage.hpp"
+#include "model.hpp"
+
+namespace fggl::data {
+
+	template<>
+	bool fggl_deserialize(std::filesystem::path &data, StaticMesh *out) {
+		Assimp::Importer importer;
+		const aiScene* scene = importer.ReadFile( data.c_str(), aiProcess_Triangulate | aiProcess_FlipUVs );
+
+		if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) {
+			return false;
+		}
+
+		//TODO implement the rest of this
+		return false;
+	}
+
+} // namespace fggl::data
+
+#endif //FGGL_DATA_GEOM_HPP
-- 
GitLab