Models funny

This commit is contained in:
Kaydax 2023-12-28 22:23:45 -05:00
parent 7b1993ece1
commit 2a36a746e8
5 changed files with 22007 additions and 43 deletions

1
.gitignore vendored
View File

@ -17,7 +17,6 @@ Makefile
*.o
*.so
*.ko
*.obj
*.elf
# Ignore IDE/project files

View File

@ -98,9 +98,9 @@ target_link_libraries(iridium-modules PUBLIC imgui glfw glad Vulkan::Vulkan glm
add_executable(iridium ${SOURCE})
target_link_libraries(iridium PUBLIC iridium-modules)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(iridium PUBLIC -g -fsanitize=address)
target_link_options(iridium PUBLIC -g -fsanitize=address)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(iridium PUBLIC -g)
target_link_options(iridium PUBLIC -g)
endif()
# Collect all shader files into a variable
@ -120,13 +120,37 @@ foreach(SHADER ${SHADER_FILES})
# Add a custom command to copy the shader to the output directory
add_custom_command(
TARGET iridium POST_BUILD
TARGET copy-shaders POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${SHADER}
${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_REL_PATH}
)
endforeach()
# Collect all model files into a variable
file(GLOB_RECURSE MODEL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/models/*")
add_custom_target(copy-models ALL)
foreach(MODEL ${MODEL_FILES})
# Get the relative path of the model
file(RELATIVE_PATH MODEL_REL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/models" ${MODEL})
# Get the directory of the relative path
get_filename_component(MODEL_DIR ${MODEL_REL_PATH} DIRECTORY)
# Create the directory in the output directory
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/models/${MODEL_DIR}")
# Add a custom command to copy the model to the output directory
add_custom_command(
TARGET copy-models POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${MODEL}
${CMAKE_CURRENT_BINARY_DIR}/models/${MODEL_REL_PATH}
)
endforeach()
add_custom_target(iridium-windows
WORKING_DIRECTORY ../
COMMAND ./build-windows.sh

12011
models/spot.obj Normal file

File diff suppressed because it is too large Load Diff

9965
models/teapot.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +1,11 @@
#include <GLFW/glfw3.h>
#include <functional>
#include <glm/glm.hpp>
#include <memory>
#include <ranges>
#include <iostream>
#include <rapidobj/rapidobj.hpp>
import iridium;
static PosColorVertex cubeVertices[] = {
{-1.0f, 1.0f, 1.0f, 0xff000000},
{1.0f, 1.0f, 1.0f, 0xff0000ff},
{-1.0f, -1.0f, 1.0f, 0xff00ff00},
{1.0f, -1.0f, 1.0f, 0xff00ffff},
{-1.0f, 1.0f, -1.0f, 0xffff0000},
{1.0f, 1.0f, -1.0f, 0xffff00ff},
{-1.0f, -1.0f, -1.0f, 0xffffff00},
{1.0f, -1.0f, -1.0f, 0xffffffff},
};
// Clangd doesn't have an option to not format this from what I found, so just ignore it
// clang-format off
static const uint16_t cubeTriList[] =
{
0, 1, 2,
1, 3, 2,
4, 6, 5,
5, 6, 7,
0, 2, 4,
4, 2, 6,
1, 5, 3,
5, 7, 3,
0, 4, 1,
4, 5, 1,
2, 3, 6,
6, 3, 7,
};
// clang-format on
int windowPosX, windowPosY, windowWidth, windowHeight;
/**
@ -55,15 +21,15 @@ std::unique_ptr<T> spawn_renderer(IWindow* window)
auto renderer = std::make_unique<T>();
renderer->init_renderer(window);
auto teapot = rapidobj::ParseFile("teapot.obj");
auto model = rapidobj::ParseFile("models/spot.obj");
std::vector<PosColorVertex> vertices;
std::vector<uint16_t> indices;
for (const auto& vertex : teapot.attributes.positions | std::views::chunk(3))
for(const auto &vertex : model.attributes.positions | std::views::chunk(3))
{
vertices.push_back({vertex[0], vertex[1], vertex[2], 0xff000000});
}
for (const auto& index : teapot.shapes.at(0).mesh.indices)
for(const auto &index : model.shapes.at(0).mesh.indices)
{
indices.push_back(index.position_index);
}
@ -106,7 +72,6 @@ static void resize_callback(std::unique_ptr<IRenderer> &renderer, glm::vec2 size
int main()
{
using namespace std::placeholders;
int width = 1280;
int height = 720;