From 2c6036f653e712692abe488397d89d0946ec5aa7 Mon Sep 17 00:00:00 2001 From: Jip Date: Sat, 4 May 2024 23:12:24 +0200 Subject: [PATCH] Got the meshes somewhat working, the models are not consistent with their winding order and ray doesn't allow to render both sides of a face?, to truly see if everything works correctly we need the bone transformation to be applied to the model --- library/CMakeLists.txt | 6 + library/libvitaboy/CMakeLists.txt | 1 + library/renderdemo_ray/CMakeLists.txt | 36 +++ library/renderdemo_ray/main.cpp | 349 ++++++++++++++++++++++++++ 4 files changed, 392 insertions(+) create mode 100644 library/renderdemo_ray/CMakeLists.txt create mode 100644 library/renderdemo_ray/main.cpp diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 5991521..640f88d 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 2.6) enable_language(ASM) +option(BUILD_EXAMPLES "Build the render demos" ON) option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) if(BUILD_SHARED_LIBS) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) @@ -141,4 +142,9 @@ add_subdirectory(formats) add_subdirectory(libgldemo) add_subdirectory(libvitaboy) +if(BUILD_EXAMPLES) + add_subdirectory(renderdemo_ray) +endif() + unset(BUILD_SHARED_LIBS CACHE) +unset(BUILD_EXAMPLES CACHE) diff --git a/library/libvitaboy/CMakeLists.txt b/library/libvitaboy/CMakeLists.txt index 2c616cd..3ff4278 100644 --- a/library/libvitaboy/CMakeLists.txt +++ b/library/libvitaboy/CMakeLists.txt @@ -17,6 +17,7 @@ set(LIBVITABOY_SOURCES po.cpp skel.cpp ) + if(WIN32) set(LIBVITABOY_SOURCES ${LIBVITABOY_SOURCES} resource.rc) else() diff --git a/library/renderdemo_ray/CMakeLists.txt b/library/renderdemo_ray/CMakeLists.txt new file mode 100644 index 0000000..080638b --- /dev/null +++ b/library/renderdemo_ray/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.0) +project(renderdemoray) + +# Adding Raylib +include(FetchContent) +set(FETCHCONTENT_QUIET FALSE) +set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples +set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games + +#set raylib settings +add_compile_definitions(SUPPORT_FILEFORMAT_JPG) + +FetchContent_Declare( + raylib + GIT_REPOSITORY "https://github.com/raysan5/raylib.git" + GIT_TAG "master" + GIT_PROGRESS TRUE +) +FetchContent_MakeAvailable(raylib) + +include_directories(${FILEHANDLER_INCLUDE}) +include_directories(${VITABOY_INCLUDE}) + +# Adding our source files +file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/*.cpp") # Define PROJECT_SOURCES as a list of all source files +set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/*.h") # Define PROJECT_INCLUDE to be the path to the include directory of the project + +# Declaring our executable +add_executable(${PROJECT_NAME}) +target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE}) +target_link_libraries(${PROJECT_NAME} PRIVATE raylib libvitaboy_static FileHandler_static) + +# Setting ASSETS_PATH +target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine +#target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets") # Set the asset path macro in release mode to a relative path that assumes the assets folder is in the same directory as the game executable \ No newline at end of file diff --git a/library/renderdemo_ray/main.cpp b/library/renderdemo_ray/main.cpp new file mode 100644 index 0000000..6e6c197 --- /dev/null +++ b/library/renderdemo_ray/main.cpp @@ -0,0 +1,349 @@ +#include "raylib.h" +#include "raymath.h" // Required for: Vector3, Quaternion and Matrix functionality +#include "utils.h" // Required for: TRACELOG(), LoadFileData(), LoadFileText(), SaveFileText() + +#include +#include +#include +#include "../libvitaboy/libvitaboy.hpp" + + +#define SCREEN_WIDTH (1920) +#define SCREEN_HEIGHT (1080) +#define WINDOW_TITLE "libvitaboy - Renderer - Ray" + +//we dont look in this mess for now +#pragma region TSO + +//util +static bool Read(const char* Filename, uint8_t** InData) { + *InData = File::ReadFile(Filename); + if (*InData != NULL) { + VBFile.set(*InData, File::FileSize); + return true; + } + return false; +} + +//globals +//skeleton +static Skeleton_t Skeleton; +static void DrawBonesSkeleton(Bone_t& Bone) +{ + const float size = 0.1f; + const Vector3 position{Bone.Translation.x, Bone.Translation.y, Bone.Translation.z}; + Color color; + if(!strcmp(Bone.Name, "ROOT")) + { + color = RED; + } + else if(!strcmp(Bone.Name, "HEAD")) + { + color = YELLOW; + } + else + { + color = GREEN; + } + DrawCube(position, size, size, size, color); + + if(Bone.ChildrenCount == 1) + { + DrawBonesSkeleton(*Bone.Children[0]); + } + else if(Bone.ChildrenCount > 1) + { + for(unsigned i=0; i