FBX파일 읽기 로직 완성

This commit is contained in:
2025-05-18 19:23:30 +09:00
parent 45ee4f0056
commit 3a9dbcb470
5 changed files with 42 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
#include "assimp/Importer.hpp"
#include "assimp/postprocess.h"
#include "assimp/scene.h"
#include "glfw/glfw_initialization.h"
#include "glfw/glfw_monitor.h"
#include "glfw/glfw_window.h"
@@ -23,21 +24,31 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
const struct aiScene* scene = assetImporter.ReadFile(
"assets/player.fbx", aiProcess_CalcTangentSpace | aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);
aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
if (nullptr == scene) {
if (scene == nullptr || !scene->HasMeshes()) {
spdlog::error(assetImporter.GetErrorString());
return false;
}
std::array<veng::Vertex, 4> vertices = {
veng::Vertex{{-.5f, -.5f, 0.f}, {0.f, 1.f}},
veng::Vertex{{.5f, -.5f, 0.f}, {1.f, 1.f}},
veng::Vertex{{-.5f, .5f, 0.f}, {0.f, 0.f}},
veng::Vertex{{.5f, .5f, 0.f}, {1.f, 0.f}}};
std::vector<veng::Vertex> vertices;
aiMesh* mesh = scene->mMeshes[0];
for (std::uint32_t i = 0; i < mesh->mNumVertices; i++) {
vertices.emplace_back(
glm::vec3{mesh->mVertices[i].x, mesh->mVertices[i].y,
mesh->mVertices[i].z},
glm::vec2{mesh->mTextureCoords[0][i].x, mesh->mTextureCoords[0][i].y});
}
veng::BufferHandle buffer = graphics.CreateVertexBuffer(vertices);
std::array<std::uint32_t, 6> indices = {0, 3, 2, 0, 1, 3};
std::vector<std::uint32_t> indices;
for (std::uint32_t i = 0; i < mesh->mNumFaces; i++) {
aiFace face = mesh->mFaces[i];
for (unsigned int j = 0; j < face.mNumIndices; ++j) {
indices.push_back(face.mIndices[j]);
}
}
veng::BufferHandle index_buffer = graphics.CreateIndexBuffer(indices);
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), glm::radians(45.f),
@@ -46,7 +57,9 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
glm::mat4 rotation2 =
glm::rotate(glm::mat4(1.0f), glm::radians(0.f), glm::vec3(0.f, 0.f, 1.f));
glm::mat4 view = glm::translate(glm::mat4(1.f), glm::vec3(0.f, 0.f, -2.f));
glm::mat4 view =
glm::lookAt(glm::vec3(0.f, 0.f, 10.f), glm::vec3(0.f, 0.f, 0.f),
glm::vec3(0.f, 1.f, 0.f));
glm::mat4 projection =
glm::perspective(glm::radians(150.f), 800.f / 600.f, 0.1f, 100.f);
graphics.SetViewProjection(view, projection);
@@ -61,7 +74,8 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
glfwPollEvents();
glm::ivec2 current_window_size = window.GetFramebufferSize();
if (current_window_size != window_size && current_window_size.x != 0 && current_window_size.y != 0) {
if (current_window_size != window_size && current_window_size.x != 0 &&
current_window_size.y != 0) {
window_size = current_window_size;
projection = glm::perspective(
glm::radians(90.f),