FBX파일 읽기 로직 완성
This commit is contained in:
Binary file not shown.
@@ -39,6 +39,7 @@ class Graphics final {
|
|||||||
BufferHandle CreateIndexBuffer(gsl::span<std::uint32_t> indices);
|
BufferHandle CreateIndexBuffer(gsl::span<std::uint32_t> indices);
|
||||||
void DestroyBuffer(BufferHandle handle);
|
void DestroyBuffer(BufferHandle handle);
|
||||||
TextureHandle CreateTexture(gsl::czstring path);
|
TextureHandle CreateTexture(gsl::czstring path);
|
||||||
|
TextureHandle CreateTexture(gsl::span<std::uint8_t> image_file_data);
|
||||||
void DestroyTexture(TextureHandle handle);
|
void DestroyTexture(TextureHandle handle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
12
include/vulkan/model.h
Normal file
12
include/vulkan/model.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "vertex.h"
|
||||||
|
|
||||||
|
namespace veng {
|
||||||
|
struct Model {
|
||||||
|
std::vector<veng::Vertex> vertices;
|
||||||
|
std::vector<std::uint32_t> indices;
|
||||||
|
glm::mat4 transform;
|
||||||
|
};
|
||||||
|
} // namespace veng
|
||||||
34
src/main.cpp
34
src/main.cpp
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "assimp/Importer.hpp"
|
#include "assimp/Importer.hpp"
|
||||||
#include "assimp/postprocess.h"
|
#include "assimp/postprocess.h"
|
||||||
|
#include "assimp/scene.h"
|
||||||
#include "glfw/glfw_initialization.h"
|
#include "glfw/glfw_initialization.h"
|
||||||
#include "glfw/glfw_monitor.h"
|
#include "glfw/glfw_monitor.h"
|
||||||
#include "glfw/glfw_window.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(
|
const struct aiScene* scene = assetImporter.ReadFile(
|
||||||
"assets/player.fbx", aiProcess_CalcTangentSpace | aiProcess_Triangulate |
|
"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());
|
spdlog::error(assetImporter.GetErrorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<veng::Vertex, 4> vertices = {
|
std::vector<veng::Vertex> vertices;
|
||||||
veng::Vertex{{-.5f, -.5f, 0.f}, {0.f, 1.f}},
|
aiMesh* mesh = scene->mMeshes[0];
|
||||||
veng::Vertex{{.5f, -.5f, 0.f}, {1.f, 1.f}},
|
for (std::uint32_t i = 0; i < mesh->mNumVertices; i++) {
|
||||||
veng::Vertex{{-.5f, .5f, 0.f}, {0.f, 0.f}},
|
vertices.emplace_back(
|
||||||
veng::Vertex{{.5f, .5f, 0.f}, {1.f, 0.f}}};
|
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);
|
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);
|
veng::BufferHandle index_buffer = graphics.CreateIndexBuffer(indices);
|
||||||
|
|
||||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), glm::radians(45.f),
|
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::mat4 rotation2 =
|
||||||
glm::rotate(glm::mat4(1.0f), glm::radians(0.f), glm::vec3(0.f, 0.f, 1.f));
|
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::mat4 projection =
|
||||||
glm::perspective(glm::radians(150.f), 800.f / 600.f, 0.1f, 100.f);
|
glm::perspective(glm::radians(150.f), 800.f / 600.f, 0.1f, 100.f);
|
||||||
graphics.SetViewProjection(view, projection);
|
graphics.SetViewProjection(view, projection);
|
||||||
@@ -61,7 +74,8 @@ std::int32_t main(std::int32_t argc, gsl::zstring* argv) {
|
|||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
glm::ivec2 current_window_size = window.GetFramebufferSize();
|
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;
|
window_size = current_window_size;
|
||||||
projection = glm::perspective(
|
projection = glm::perspective(
|
||||||
glm::radians(90.f),
|
glm::radians(90.f),
|
||||||
|
|||||||
@@ -31,9 +31,13 @@ void Graphics::CreateTextureSampler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextureHandle Graphics::CreateTexture(gsl::czstring path) {
|
TextureHandle Graphics::CreateTexture(gsl::czstring path) {
|
||||||
|
std::vector<std::uint8_t> data = ReadFile(path);
|
||||||
|
return CreateTexture({data.data(), data.size()});
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureHandle Graphics::CreateTexture(gsl::span<std::uint8_t> image_file_data) {
|
||||||
glm::ivec2 image_extents;
|
glm::ivec2 image_extents;
|
||||||
std::int32_t channels;
|
std::int32_t channels;
|
||||||
std::vector<std::uint8_t> image_file_data = ReadFile(path);
|
|
||||||
stbi_uc* pixel_data = stbi_load_from_memory(
|
stbi_uc* pixel_data = stbi_load_from_memory(
|
||||||
image_file_data.data(), image_file_data.size(), &image_extents.x,
|
image_file_data.data(), image_file_data.size(), &image_extents.x,
|
||||||
&image_extents.y, &channels, STBI_rgb_alpha);
|
&image_extents.y, &channels, STBI_rgb_alpha);
|
||||||
|
|||||||
Reference in New Issue
Block a user