diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..978acb1 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,138 @@ +# 🏛️ Prism Project Architecture + +This document provides a visual overview of the dependency structure of the Prism rendering engine, from a high-level view down to the internal class relationships. + +--- + +## High-Level Project Dependency Graph + +This graph shows how the main project components (the demo application, the core library, and the unit tests) interact with each other and with external libraries. + +```mermaid +graph TD; + subgraph "External Dependencies" + YAML_CPP["📚 yaml-cpp"]; + GTEST["🧪 GoogleTest"]; + end + + subgraph "Prism Project" + DEMO["💻 prism_demo (Demo App)"]; + PRISM_LIB["🎨 Prism (Library)"]; + TESTS["⚙️ runTests (Unit Tests)"]; + end + + DEMO --> PRISM_LIB; + TESTS --> PRISM_LIB; + TESTS --> GTEST; + PRISM_LIB --> YAML_CPP; +``` + +--- + +## Internal Library Dependencies + +This section details the dependencies within the Prism library, divided into different levels of abstraction for greater clarity and understanding of the project's architecture. + +--- + +### 1. Dependencies between Modules (High-Level Overview) + +This graph shows the high-level dependencies between the main modules of the Prism library. An arrow from A to B indicates that Module A depends on Module B. + +```mermaid +graph TD; + CORE["🔧 Core"]; + OBJECTS["🧩 Objects"]; + SCENE["🎬 Scene"]; + + OBJECTS --> CORE; + SCENE --> CORE; + SCENE --> OBJECTS; +``` + +--- + +### 2. Internal Dependencies by Module + +These graphs detail the relationships between the classes within each module. To simplify, common dependencies to basic types from other modules (like the Core classes) are abstracted and not explicitly shown here. + +#### 2.1. Module: Core + +This graph focuses on the internal dependencies of the fundamental math and data type classes within the Core module. + +```mermaid +graph TD; + subgraph "Core" + RAY["➡️ Ray"]; + POINT3["📍 Point3"]; + VECTOR3["📏 Vector3"]; + MATRIX["🧮 Matrix"]; + MATERIAL["✨ Material"]; + COLOR["🌈 Color"]; + STYLE["🎨 Style"]; + INIT["🔧 Init"]; + UTILS["🛠️ Utils"]; + end + + INIT --> STYLE; + MATRIX --> POINT3; + MATRIX --> VECTOR3; + POINT3 --> VECTOR3; + VECTOR3 --> POINT3; + RAY --> POINT3; + RAY --> VECTOR3; + RAY --> MATRIX; + UTILS --> MATRIX; + UTILS --> POINT3; + UTILS --> VECTOR3; +``` + +--- + +#### 2.2. Module: Objects + +This graph illustrates the dependencies between the objects and the associated I/O classes, excluding dependencies on basic Core types. + +```mermaid +graph TD; + subgraph " Objects" + OBJECT["🧩 Object (Base)"]; + SPHERE["⚪ Sphere"]; + PLANE["🌐 Plane"]; + TRIANGLE["🔺 Triangle"]; + MESH["🧊 Mesh"]; + OBJ_READER["📑 ObjReader"]; + COLORMAP["🌈 ColorMap"]; + end + + MESH --> OBJECT; + MESH --> OBJ_READER; + OBJ_READER --> COLORMAP; + SPHERE --> OBJECT; + PLANE --> OBJECT; + TRIANGLE --> OBJECT; +``` + +--- + +#### 2.3. Module: Scene + +This graph details the relationships within the scene module, including the interaction with the external YAML dependency. + +```mermaid +graph TD; + subgraph "Scene Management" + SCENE["🎬 Scene"]; + CAMERA["📷 Camera"]; + SCENE_PARSER["📄 SceneParser"]; + end + + subgraph "External Dependency" + YAML_CPP["📄 yaml-cpp"]; + end + + SCENE --> CAMERA; + SCENE_PARSER --> CAMERA; + SCENE_PARSER --> YAML_CPP; + SCENE_PARSER --> SCENE; +``` diff --git a/CMakeLists.txt b/CMakeLists.txt index e5ee1d9..3ca556e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,46 @@ -cmake_minimum_required(VERSION 3.14.0) -cmake_policy(SET CMP0135 NEW) # Policy to modern FetchContent behavior +# =================================================================== +# Prism Library | Root CMakeLists.txt +# +# This is the main project file that orchestrates the entire build. +# It sets global settings and includes the sub-projects. +# =================================================================== +cmake_minimum_required(VERSION 3.22) +project(Prism VERSION 0.1.0 LANGUAGES CXX) -project(PG_Project VERSION 0.0.1 LANGUAGES C CXX) +# Set the policy for FetchContent to use modern, safer behavior. +cmake_policy(SET CMP0135 NEW) +# --- Global Project Settings --- set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -enable_testing() +# --- Build Options --- +# Add an option to control whether the demo application is built. +# Defaults to ON for typical development, but can be turned off. +set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries" FORCE) +option(PRISM_BUILD_DEMO "Build the Prism demo application" ON) +# Set a common output directory for all executables. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -add_subdirectory(libs) -add_subdirectory(src) +# --- Sub-projects --- +add_subdirectory(src) # The Prism library +add_subdirectory(demo) # The demo application + +# --- Testing --- +enable_testing() if(BUILD_TESTING) - ### include GoogleTest via FetchContent - include(FetchContent) - FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/v1.14.0.zip - ) - - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - FetchContent_MakeAvailable(googletest) - ### - add_subdirectory(tests) -endif() - -install(TARGETS ${PROJECT_NAME} DESTINATION bin) -install(DIRECTORY data DESTINATION bin) \ No newline at end of file + # Fetch GoogleTest only when tests are enabled. + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/v1.14.0.zip + ) + set(INSTALL_GTEST OFF CACHE BOOL "Disable GTest installation" FORCE) + set(BUILD_GTEST_INSTALL OFF CACHE BOOL "Disable GTest installation" FORCE) + FetchContent_MakeAvailable(googletest) + + + add_subdirectory(tests) +endif() \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 7c8bf60..c367c02 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,7 +9,8 @@ "installDir": "${sourceDir}/install/debug", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", - "BUILD_TESTING": "ON" + "BUILD_TESTING": "ON", + "PRISM_BUILD_DEMO": "ON" } }, { @@ -20,7 +21,8 @@ "installDir": "${sourceDir}/install/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "BUILD_TESTING": "OFF" + "BUILD_TESTING": "OFF", + "PRISM_BUILD_DEMO": "OFF" } } ], diff --git a/README.MD b/README.md similarity index 74% rename from README.MD rename to README.md index e6eafb8..187a199 100644 --- a/README.MD +++ b/README.md @@ -5,7 +5,7 @@ To build and run this project, you will need: * **Git** -* **CMake** (version 3.15 or higher recommended) +* **CMake** (version 3.22 or higher recommended) * A **C++17 compliant compiler** (e.g., GCC, Clang, MSVC) ## Building the Project @@ -55,36 +55,6 @@ The following presets are available: --- -## Code Formatting - -This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules. - -Before committing any changes, please format your code. - -### Installing clang-format - -You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with: - -```sh -sudo apt install clang-format -``` - -### Formatting the Entire Project - -To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**: - -```sh -find src libs tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i -``` - -**What this command does:** - -* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders. -* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`. -* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place. - ---- - ## Running the Application The executable (`PG_Project`) will be located in the `bin` subdirectory of your build folder. @@ -128,3 +98,66 @@ This project includes rules to create a clean, distributable package in a local ``` The `install/release` folder will then contain the `PG_Project` executable and the `libPrism.so` (or `Prism.dll`) library, ready to be run together. + +## Code Formatting + +This project uses `clang-format` to maintain a consistent code style across the entire codebase. A configuration file (`.clang-format`) is included in the project root to define the style rules. + +Before committing any changes, please format your code. + +### Installing clang-format + +You must have `clang-format` installed on your system. On Debian/Ubuntu-based systems, you can install it with: + +```sh +sudo apt install clang-format +``` + +### Formatting the Entire Project + +To format all `.hpp` and `.cpp` files in the `src`, `libs`, and `tests` directories at once, run the following command from the **root directory of the project**: + +```sh +find src demo tests -name "*.cpp" -o -name "*.hpp" | xargs clang-format -i +``` + +**What this command does:** + +* `find src libs tests ...`: Searches for files within the `src`, `libs`, and `tests` folders. +* `-name "*.cpp" -o -name "*.hpp"`: Finds files that end in `.cpp` OR `.hpp`. +* `| xargs clang-format -i`: For every file found, it runs the command `clang-format -i` to format it in-place. + +--- + +## 🏛️ Project Architecture + +The project is organized into three main components: the core `Prism` library, a `prism_demo` application that uses the library, and a `runTests` executable for unit testing. The dependencies are managed by CMake and are visualized below. + +```mermaid +graph TD; + subgraph "External Dependencies" + YAML_CPP["📚 yaml-cpp"]; + GTEST["🧪 GoogleTest"]; + end + + subgraph "Prism Project" + DEMO["💻 prism_demo (Demo App)"]; + PRISM_LIB["🎨 Prism (Library)"]; + TESTS["⚙️ runTests (Unit Tests)"]; + end + + DEMO --> PRISM_LIB; + TESTS --> PRISM_LIB; + TESTS --> GTEST; + PRISM_LIB --> YAML_CPP; + + style DEMO fill:#cce5ff,stroke:#333,stroke-width:2px; + style TESTS fill:#d5e8d4,stroke:#333,stroke-width:2px; + style PRISM_LIB fill:#ffcce5,stroke:#333,stroke-width:2px; + style YAML_CPP fill:#fff2cc,stroke:#333,stroke-width:2px; + style GTEST fill:#fff2cc,stroke:#333,stroke-width:2px; +``` + +For a more detailed breakdown of the internal library dependencies, please see the ARCHITECTURE.md file. + +--- diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..1459dfa --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,34 @@ +# =================================================================== +# Prism Demo Application +# +# This CMakeLists.txt file defines the demo application that uses the +# Prism library. It sets up the executable target, links against the +# Prism library, and handles installation. +# =================================================================== + +add_executable(prism_demo src/main.cpp) + +target_link_libraries(prism_demo PRIVATE Prism) + +set_target_properties(prism_demo PROPERTIES + INSTALL_RPATH "$ORIGIN/../lib" +) + +# --- Installation --- +install(TARGETS prism_demo DESTINATION bin) + +# This command is now much cleaner. It copies the 'data' directory +# from this subdirectory into the install directory. +install(DIRECTORY data/ DESTINATION ./bin/data) + +# --- Development/Debugging Support --- + +# This is the key command that solves the debugging issue. +# It copies the 'data' directory into the build output directory +# *after* the executable is built. +add_custom_command(TARGET prism_demo POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/data + $/data + COMMENT "Copying data folder for debug/run..." +) \ No newline at end of file diff --git a/data/input/cubo.mtl b/demo/data/input/cubo.mtl similarity index 100% rename from data/input/cubo.mtl rename to demo/data/input/cubo.mtl diff --git a/data/input/cubo.obj b/demo/data/input/cubo.obj similarity index 100% rename from data/input/cubo.obj rename to demo/data/input/cubo.obj diff --git a/data/input/scene.yml b/demo/data/input/scene.yml similarity index 98% rename from data/input/scene.yml rename to demo/data/input/scene.yml index 260ba1f..1572623 100644 --- a/data/input/scene.yml +++ b/demo/data/input/scene.yml @@ -69,7 +69,7 @@ objects: - name: Malha de Cubo Metálico type: mesh - path: "./data/input/cubo.obj" # Caminho para o arquivo .obj + path: "./cubo.obj" # Caminho para o arquivo .obj material: *material_cubo_metalico # Reutiliza o material metálico # Múltiplas transformações são aplicadas em ordem transform: diff --git a/src/main.cpp b/demo/src/main.cpp similarity index 96% rename from src/main.cpp rename to demo/src/main.cpp index ac573fc..0b8fe66 100644 --- a/src/main.cpp +++ b/demo/src/main.cpp @@ -4,7 +4,7 @@ int main() { try { Prism::SceneParser("./data/input/scene.yml").parse().render(); - + } catch (const std::exception& e) { Prism::Style::logError(e.what()); return 1; diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt deleted file mode 100644 index 8a36e9a..0000000 --- a/libs/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_library(include INTERFACE) - -add_subdirectory(Prism) -target_link_libraries(include INTERFACE Prism) diff --git a/libs/Prism/CMakeLists.txt b/libs/Prism/CMakeLists.txt deleted file mode 100644 index 957ee2a..0000000 --- a/libs/Prism/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -include(FetchContent) -FetchContent_Declare( - yaml-cpp - GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git - GIT_TAG 0.8.0 -) -FetchContent_MakeAvailable(yaml-cpp) - -file(GLOB_RECURSE PRISM_SOURCES CONFIGURE_DEPENDS "src/*.cpp") -add_library(Prism SHARED ${PRISM_SOURCES}) - -include(GenerateExportHeader) -generate_export_header(Prism) - -target_include_directories(Prism PUBLIC - "${CMAKE_CURRENT_SOURCE_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" -) - -target_link_libraries(Prism PUBLIC yaml-cpp) - -install(TARGETS Prism - RUNTIME DESTINATION bin # Para .dll no Windows - LIBRARY DESTINATION lib # Para .so no Linux, .dylib no macOS - ARCHIVE DESTINATION lib # Para .lib no Windows (bibliotecas de importação) -) \ No newline at end of file diff --git a/libs/Prism/include/Prism.hpp b/libs/Prism/include/Prism.hpp deleted file mode 100644 index f4eb640..0000000 --- a/libs/Prism/include/Prism.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "Prism/Colormap.hpp" -#include "Prism/ObjReader.hpp" -#include "Prism/camera.hpp" -#include "Prism/color.hpp" -#include "Prism/material.hpp" -#include "Prism/matrix.hpp" -#include "Prism/mesh.hpp" -#include "Prism/objects.hpp" -#include "Prism/plane.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/scene.hpp" -#include "Prism/sphere.hpp" -#include "Prism/triangle.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" -#include "Prism/scene_parser.hpp" -#include "Prism/style.hpp" \ No newline at end of file diff --git a/libs/Prism/include/Prism/style.hpp b/libs/Prism/include/Prism/style.hpp deleted file mode 100644 index 4bc034d..0000000 --- a/libs/Prism/include/Prism/style.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef PRISM_STYLE_HPP_ -#define PRISM_STYLE_HPP_ - -#include "prism_export.h" -#include -#include - -namespace Prism { - -/** - * @namespace Style - * @brief Provides constants for colored console output. - * - * This namespace centralizes ANSI escape codes for styling text in the terminal, - * ensuring a consistent look and feel for all engine logs. - */ -namespace Style { - - // --- Basic Colors --- - const std::string RESET = "\033[0m"; - const std::string YELLOW = "\033[0;33m"; - const std::string GREEN = "\033[0;32m"; - const std::string CYAN = "\033[0;36m"; - const std::string GRAY = "\033[0;90m"; - const std::string RED = "\033[0;31m"; - - // --- Bold Variants --- - const std::string BOLD_CYAN = "\033[1;36m"; - const std::string BOLD_GREEN = "\033[1;32m"; - const std::string BOLD_RED = "\033[1;31m"; - const std::string BOLD_YELLOW= "\033[1;33m"; - - /** - * @brief Logs a formatted informational message to std::clog. - * @param message The message to display. - */ - inline void logInfo(const std::string& message) { - std::clog << YELLOW << "[INFO] " << RESET << message << std::endl; - } - - /** - * @brief Logs a formatted completion message to std::clog. - * @param message The message to display. - */ - inline void logDone(const std::string& message) { - std::clog << GREEN << "[DONE] " << RESET << message << std::endl; - } - - /** - * @brief Logs a formatted error message to std::cerr. - * @param message The error message to display. - */ - inline void logError(const std::string& message) { - std::cerr << BOLD_RED << "[ERROR] " << RESET - << RED << message << RESET << std::endl; - } - - /** - * @brief Logs a formatted warning message to std::clog. - * @param message The warning message to display. - */ - inline void logWarning(const std::string& message) { - std::clog << BOLD_YELLOW << "[WARNING] " << RESET - << YELLOW << message << RESET << std::endl; - } - - /** - * @brief Displays a dynamic status bar on the current line in std::clog. - * @param progress A value between 0.0 and 1.0 indicating completion. - * @param width The total character width of the bar itself. - */ - inline void logStatusBar(double progress, int width = 25) { - if (progress < 0.0) progress = 0.0; - if (progress > 1.0) progress = 1.0; - - int bar_fill = static_cast(progress * width); - int percentage = static_cast(progress * 100.0); - - // \r (carriage return) move o cursor para o início da linha - std::clog << GREEN << "\rProgress: [" << RESET; - for (int i = 0; i < width; ++i) { - if (i < bar_fill) std::clog << "="; - else std::clog << " "; - } - std::clog << GREEN << "] " << percentage << "%" << RESET << std::flush; - - if (progress >= 1.0) { - std::clog << '\n' << std::endl; - } - } - -} // namespace Style -} // namespace Prism - -#endif // PRISM_STYLE_HPP_ \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cb43e8..fba2e22 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,160 @@ -add_executable(${PROJECT_NAME}) +# =================================================================== +# Prism Library | Library Target +# +# This CMakeLists.txt file defines the main shared library target, +# manages its dependencies, and sets up installation rules. +# =================================================================== -target_sources(${PROJECT_NAME} PRIVATE main.cpp) +# --- Dependencies --- -target_link_libraries(${PROJECT_NAME} PRIVATE include) +include(FetchContent) +FetchContent_Declare( + yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + # Pinned to a specific commit to fix build issues with modern compilers. + GIT_TAG 2f86d13775d119edbb69af52e5f566fd65c6953b +) +FetchContent_MakeAvailable(yaml-cpp) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${PROJECT_SOURCE_DIR}/data - "$/data" - COMMENT "Copying data for Debug build..." - ) +set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "Disable building yaml-cpp contrib tools" FORCE) +set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Disable building yaml-cpp parse tools" FORCE) +set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Disable building yaml-cpp tests" FORCE) +set(YAML_CPP_FORMAT_SOURCE OFF CACHE BOOL "Disable yaml-cpp source formatting" FORCE) + + +# --- Build Options --- + +# Option to build the core math and data structures (mandatory) +option(PRISM_BUILD_CORE "Build the Core module (math, etc.)" ON) + +# Optional modules +option(PRISM_BUILD_OBJECTS "Build the Objects module (Sphere, Plane, Mesh, etc.)" ON) +option(PRISM_BUILD_SCENE "Build the Scene module (Scene, Camera)" ON) + +# The CORE module is essential for all other parts of the library. +if(NOT PRISM_BUILD_CORE) + message(FATAL_ERROR "PRISM_BUILD_CORE is a required module and cannot be disabled.") +endif() + + +# --- Build Source File Collection --- + +# Start with an empty list for our library's source files. +set(PRISM_SOURCES "") + +# Always add the core source files. +if(PRISM_BUILD_CORE) + file(GLOB CORE_SOURCES CONFIGURE_DEPENDS "src/core/*.cpp") + list(APPEND PRISM_SOURCES ${CORE_SOURCES}) endif() + +# Conditionally add sources for the other modules. +if(PRISM_BUILD_OBJECTS) + file(GLOB GEOMETRY_SOURCES CONFIGURE_DEPENDS "src/objects/*.cpp") + list(APPEND PRISM_SOURCES ${GEOMETRY_SOURCES}) +endif() + +if(PRISM_BUILD_SCENE) + file(GLOB SCENE_SOURCES CONFIGURE_DEPENDS "src/scene/*.cpp") + list(APPEND PRISM_SOURCES ${SCENE_SOURCES}) +endif() + +# Add any remaining top-level source files (e.g., init.cpp) +file(GLOB OTHER_SOURCES CONFIGURE_DEPENDS "src/*.cpp") +list(APPEND PRISM_SOURCES ${OTHER_SOURCES}) + + +# --- Target Definition --- + +# Define the library target using the conditionally populated source list. +add_library(Prism SHARED ${PRISM_SOURCES}) + +# Automatically generate export headers for Windows/Linux/macOS. +include(GenerateExportHeader) +generate_export_header(Prism) + + +# --- Target Properties --- + +# Define the public and private include directories. +target_include_directories(Prism + PUBLIC + $ + $ + $ +) + +# +set_target_properties(Prism PROPERTIES + # Define the library's version. + VERSION "${PROJECT_VERSION}" + # Define the SOVERSION, which is used for shared libraries. + # This should match the major version of the library. + SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" + # Identify debug and release builds. + DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}" +) + +# Define the RPATH settings for the library. +set_target_properties(Prism PROPERTIES + INSTALL_RPATH "$ORIGIN/." +) + +# Link the library against its dependencies. +# The yaml-cpp dependency is only needed if the IO module is built. +if(PRISM_BUILD_OBJECTS) + target_link_libraries(Prism PRIVATE yaml-cpp::yaml-cpp) +endif() +# Set Submodule flags for the library. +# This ensures that the library is built with the correct visibility settings. +if (PRISM_BUILD_CORE) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_CORE) +endif() + +if (PRISM_BUILD_OBJECTS) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_OBJECTS) +endif() + +if (PRISM_BUILD_SCENE) + target_compile_definitions(Prism PUBLIC PRISM_BUILD_SCENE) +endif() + + +# --- Installation --- + +install(TARGETS Prism + EXPORT PrismTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + +# Install the public headers, preserving the subdirectory structure. +install(DIRECTORY + include/Prism/core + include/Prism/objects + include/Prism/scene + DESTINATION include/Prism +) + +# Install any top-level header files like Prism.hpp +install(FILES + include/Prism.hpp + DESTINATION include +) + +# Install yaml-cpp headers and library if the OBJECTS module is built. +if(PRISM_BUILD_OBJECTS) + + install(DIRECTORY ${yaml-cpp_SOURCE_DIR}/include/yaml-cpp + DESTINATION include + ) + + if(YAML_BUILD_SHARED_LIBS) + install(TARGETS yaml-cpp + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + endif() +endif() \ No newline at end of file diff --git a/src/include/Prism.hpp b/src/include/Prism.hpp new file mode 100644 index 0000000..5476f47 --- /dev/null +++ b/src/include/Prism.hpp @@ -0,0 +1,26 @@ +#ifdef PRISM_BUILD_CORE +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/utils.hpp" +#include "Prism/core/vector.hpp" +#endif // PRISM_CORE + +#ifdef PRISM_BUILD_OBJECTS +#include "Prism/objects/Colormap.hpp" +#include "Prism/objects/ObjReader.hpp" +#include "Prism/objects/mesh.hpp" +#include "Prism/objects/objects.hpp" +#include "Prism/objects/plane.hpp" +#include "Prism/objects/sphere.hpp" +#include "Prism/objects/triangle.hpp" +#endif // PRISM_BUILD_OBJECTS + +#ifdef PRISM_BUILD_SCENE +#include "Prism/scene/camera.hpp" +#include "Prism/scene/scene.hpp" +#include "Prism/scene/scene_parser.hpp" +#endif diff --git a/libs/Prism/include/Prism/color.hpp b/src/include/Prism/core/color.hpp similarity index 100% rename from libs/Prism/include/Prism/color.hpp rename to src/include/Prism/core/color.hpp diff --git a/libs/Prism/include/Prism/material.hpp b/src/include/Prism/core/material.hpp similarity index 96% rename from libs/Prism/include/Prism/material.hpp rename to src/include/Prism/core/material.hpp index 726f964..6908211 100644 --- a/libs/Prism/include/Prism/material.hpp +++ b/src/include/Prism/core/material.hpp @@ -1,10 +1,11 @@ #ifndef PRISM_MATERIAL_HPP_ #define PRISM_MATERIAL_HPP_ -#include "Prism/color.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/core/color.hpp" +#include "Prism/core/vector.hpp" + namespace Prism { /** diff --git a/libs/Prism/include/Prism/matrix.hpp b/src/include/Prism/core/matrix.hpp similarity index 99% rename from libs/Prism/include/Prism/matrix.hpp rename to src/include/Prism/core/matrix.hpp index d5440a7..d9ec7fc 100644 --- a/libs/Prism/include/Prism/matrix.hpp +++ b/src/include/Prism/core/matrix.hpp @@ -3,15 +3,15 @@ #include "prism_export.h" +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" + #include #include #include #include #include -#include "Prism/point.hpp" -#include "Prism/vector.hpp" - namespace Prism { class Matrix; // Forward declaration for proxy classes diff --git a/libs/Prism/include/Prism/point.hpp b/src/include/Prism/core/point.hpp similarity index 97% rename from libs/Prism/include/Prism/point.hpp rename to src/include/Prism/core/point.hpp index d1b1556..77e148c 100644 --- a/libs/Prism/include/Prism/point.hpp +++ b/src/include/Prism/core/point.hpp @@ -2,11 +2,12 @@ #define PRISM_POINT_HPP_ #include "prism_export.h" + #include + namespace Prism { class Vector3; // Forward declaration of Vector3 class -class Matrix; // Forward declaration of Matrix class /** * @class Point3 diff --git a/libs/Prism/include/Prism/ray.hpp b/src/include/Prism/core/ray.hpp similarity index 91% rename from libs/Prism/include/Prism/ray.hpp rename to src/include/Prism/core/ray.hpp index 75e945f..24fa619 100644 --- a/libs/Prism/include/Prism/ray.hpp +++ b/src/include/Prism/core/ray.hpp @@ -1,16 +1,17 @@ #ifndef PRISM_RAY_HPP_ #define PRISM_RAY_HPP_ -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" + #include #include #include -namespace Prism { -class Object; // Forward declaration of Object class -struct HitRecord; // Forward declaration of HitRecord struct +namespace Prism { /** * @class Ray diff --git a/src/include/Prism/core/style.hpp b/src/include/Prism/core/style.hpp new file mode 100644 index 0000000..4b53364 --- /dev/null +++ b/src/include/Prism/core/style.hpp @@ -0,0 +1,98 @@ +#ifndef PRISM_STYLE_HPP_ +#define PRISM_STYLE_HPP_ + +#include "prism_export.h" + +#include +#include + +namespace Prism { + +/** + * @namespace Style + * @brief Provides constants for colored console output. + * + * This namespace centralizes ANSI escape codes for styling text in the terminal, + * ensuring a consistent look and feel for all engine logs. + */ +namespace Style { + +// --- Basic Colors --- +const std::string RESET = "\033[0m"; +const std::string YELLOW = "\033[0;33m"; +const std::string GREEN = "\033[0;32m"; +const std::string CYAN = "\033[0;36m"; +const std::string GRAY = "\033[0;90m"; +const std::string RED = "\033[0;31m"; + +// --- Bold Variants --- +const std::string BOLD_CYAN = "\033[1;36m"; +const std::string BOLD_GREEN = "\033[1;32m"; +const std::string BOLD_RED = "\033[1;31m"; +const std::string BOLD_YELLOW = "\033[1;33m"; + +/** + * @brief Logs a formatted informational message to std::clog. + * @param message The message to display. + */ +inline void logInfo(const std::string& message) { + std::clog << YELLOW << "[INFO] " << RESET << message << std::endl; +} + +/** + * @brief Logs a formatted completion message to std::clog. + * @param message The message to display. + */ +inline void logDone(const std::string& message) { + std::clog << GREEN << "[DONE] " << RESET << message << std::endl; +} + +/** + * @brief Logs a formatted error message to std::cerr. + * @param message The error message to display. + */ +inline void logError(const std::string& message) { + std::cerr << BOLD_RED << "[ERROR] " << RESET << RED << message << RESET << std::endl; +} + +/** + * @brief Logs a formatted warning message to std::clog. + * @param message The warning message to display. + */ +inline void logWarning(const std::string& message) { + std::clog << BOLD_YELLOW << "[WARNING] " << RESET << YELLOW << message << RESET << std::endl; +} + +/** + * @brief Displays a dynamic status bar on the current line in std::clog. + * @param progress A value between 0.0 and 1.0 indicating completion. + * @param width The total character width of the bar itself. + */ +inline void logStatusBar(double progress, int width = 25) { + if (progress < 0.0) + progress = 0.0; + if (progress > 1.0) + progress = 1.0; + + int bar_fill = static_cast(progress * width); + int percentage = static_cast(progress * 100.0); + + // \r (carriage return) move o cursor para o início da linha + std::clog << GREEN << "\rProgress: [" << RESET; + for (int i = 0; i < width; ++i) { + if (i < bar_fill) + std::clog << "="; + else + std::clog << " "; + } + std::clog << GREEN << "] " << percentage << "%" << RESET << std::flush; + + if (progress >= 1.0) { + std::clog << '\n' << std::endl; + } +} + +} // namespace Style +} // namespace Prism + +#endif // PRISM_STYLE_HPP_ \ No newline at end of file diff --git a/libs/Prism/include/Prism/utils.hpp b/src/include/Prism/core/utils.hpp similarity index 93% rename from libs/Prism/include/Prism/utils.hpp rename to src/include/Prism/core/utils.hpp index 5530d46..53bd7f7 100644 --- a/libs/Prism/include/Prism/utils.hpp +++ b/src/include/Prism/core/utils.hpp @@ -1,10 +1,12 @@ #ifndef PRISM_UTILS_HPP_ #define PRISM_UTILS_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/libs/Prism/include/Prism/vector.hpp b/src/include/Prism/core/vector.hpp similarity index 97% rename from libs/Prism/include/Prism/vector.hpp rename to src/include/Prism/core/vector.hpp index 38dcd8e..b88fb08 100644 --- a/libs/Prism/include/Prism/vector.hpp +++ b/src/include/Prism/core/vector.hpp @@ -2,17 +2,12 @@ #define PRISM_VECTOR_HPP_ #include "prism_export.h" -#include -/** - * @file vector.hpp - * @brief Defines the Vector class for 3D vector operations in the Prism namespace. - */ +#include namespace Prism { class Point3; // Forward declaration of Point3 class -class Matrix; // Forward declaration of Matrix class /** * @class Vector3 diff --git a/libs/Prism/include/Prism/Colormap.hpp b/src/include/Prism/objects/Colormap.hpp similarity index 96% rename from libs/Prism/include/Prism/Colormap.hpp rename to src/include/Prism/objects/Colormap.hpp index 6e93f11..2938691 100644 --- a/libs/Prism/include/Prism/Colormap.hpp +++ b/src/include/Prism/objects/Colormap.hpp @@ -17,16 +17,19 @@ A saber que: A classe precisa ser instânciada passando o caminho do arquivo .mtl correspondente */ -#include "Prism/material.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/vector.hpp" + #include #include #include #include #include #include -#include "Prism/style.hpp" + using namespace std; namespace Prism { diff --git a/libs/Prism/include/Prism/ObjReader.hpp b/src/include/Prism/objects/ObjReader.hpp similarity index 94% rename from libs/Prism/include/Prism/ObjReader.hpp rename to src/include/Prism/objects/ObjReader.hpp index 3281010..929f725 100644 --- a/libs/Prism/include/Prism/ObjReader.hpp +++ b/src/include/Prism/objects/ObjReader.hpp @@ -1,13 +1,10 @@ #ifndef PRISM_OBJREADER_HPP_ #define PRISM_OBJREADER_HPP_ -#include "Prism/Colormap.hpp" -#include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/triangle.hpp" -#include "Prism/vector.hpp" -#include "Prism/style.hpp" #include "prism_export.h" + +#include "Prism/objects/Colormap.hpp" + #include #include #include diff --git a/libs/Prism/include/Prism/mesh.hpp b/src/include/Prism/objects/mesh.hpp similarity index 89% rename from libs/Prism/include/Prism/mesh.hpp rename to src/include/Prism/objects/mesh.hpp index 3571a59..b400f8a 100644 --- a/libs/Prism/include/Prism/mesh.hpp +++ b/src/include/Prism/objects/mesh.hpp @@ -1,15 +1,19 @@ #ifndef PRISM_MESH_HPP_ #define PRISM_MESH_HPP_ -#include "Prism/ObjReader.hpp" -#include "Prism/material.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/triangle.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/ObjReader.hpp" +#include "Prism/objects/objects.hpp" +#include "Prism/objects/triangle.hpp" + #include #include #include +#include namespace Prism { @@ -29,7 +33,7 @@ class PRISM_EXPORT Mesh : public Object { * This constructor initializes the Mesh by reading points and triangles from the specified OBJ * file. */ - explicit Mesh(std::string path); + explicit Mesh(std::filesystem::path& path); /** * @brief Constructs a Mesh object from an ObjReader. diff --git a/libs/Prism/include/Prism/objects.hpp b/src/include/Prism/objects/objects.hpp similarity index 95% rename from libs/Prism/include/Prism/objects.hpp rename to src/include/Prism/objects/objects.hpp index e008491..3206e19 100644 --- a/libs/Prism/include/Prism/objects.hpp +++ b/src/include/Prism/objects/objects.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_OBJECT_HPP_ #define PRISM_OBJECT_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/libs/Prism/include/Prism/plane.hpp b/src/include/Prism/objects/plane.hpp similarity index 92% rename from libs/Prism/include/Prism/plane.hpp rename to src/include/Prism/objects/plane.hpp index ee02017..7f15390 100644 --- a/libs/Prism/include/Prism/plane.hpp +++ b/src/include/Prism/objects/plane.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_PLANE_HPP_ #define PRISM_PLANE_HPP_ -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/objects.hpp" + namespace Prism { /** diff --git a/libs/Prism/include/Prism/sphere.hpp b/src/include/Prism/objects/sphere.hpp similarity index 93% rename from libs/Prism/include/Prism/sphere.hpp rename to src/include/Prism/objects/sphere.hpp index 867806d..94afeda 100644 --- a/libs/Prism/include/Prism/sphere.hpp +++ b/src/include/Prism/objects/sphere.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_SPHERE_HPP_ #define PRISM_SPHERE_HPP_ -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/objects.hpp" + namespace Prism { /** diff --git a/libs/Prism/include/Prism/triangle.hpp b/src/include/Prism/objects/triangle.hpp similarity index 97% rename from libs/Prism/include/Prism/triangle.hpp rename to src/include/Prism/objects/triangle.hpp index a7de231..38ffc6b 100644 --- a/libs/Prism/include/Prism/triangle.hpp +++ b/src/include/Prism/objects/triangle.hpp @@ -1,10 +1,13 @@ #ifndef PRISM_TRIANGLE_HPP_ #define PRISM_TRIANGLE_HPP_ -#include "Prism/material.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" #include "prism_export.h" + +#include "Prism/core/material.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/objects/objects.hpp" + #include #include diff --git a/libs/Prism/include/Prism/camera.hpp b/src/include/Prism/scene/camera.hpp similarity index 97% rename from libs/Prism/include/Prism/camera.hpp rename to src/include/Prism/scene/camera.hpp index 1119b3b..e084892 100644 --- a/libs/Prism/include/Prism/camera.hpp +++ b/src/include/Prism/scene/camera.hpp @@ -1,11 +1,13 @@ #ifndef PRISM_CAMERA_HPP_ #define PRISM_CAMERA_HPP_ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/vector.hpp" #include "prism_export.h" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/ray.hpp" +#include "Prism/core/vector.hpp" + #include #include namespace Prism { diff --git a/libs/Prism/include/Prism/scene.hpp b/src/include/Prism/scene/scene.hpp similarity index 94% rename from libs/Prism/include/Prism/scene.hpp rename to src/include/Prism/scene/scene.hpp index 68359c5..97f767d 100644 --- a/libs/Prism/include/Prism/scene.hpp +++ b/src/include/Prism/scene/scene.hpp @@ -1,11 +1,11 @@ #ifndef PRISM_SCENE_HPP_ #define PRISM_SCENE_HPP_ -#include "Prism/camera.hpp" -#include "Prism/color.hpp" -#include "Prism/objects.hpp" -#include "Prism/ray.hpp" #include "prism_export.h" + +#include "Prism/objects/objects.hpp" +#include "Prism/scene/camera.hpp" + #include #include #include diff --git a/libs/Prism/include/Prism/scene_parser.hpp b/src/include/Prism/scene/scene_parser.hpp similarity index 90% rename from libs/Prism/include/Prism/scene_parser.hpp rename to src/include/Prism/scene/scene_parser.hpp index 52f195b..45f9623 100644 --- a/libs/Prism/include/Prism/scene_parser.hpp +++ b/src/include/Prism/scene/scene_parser.hpp @@ -1,8 +1,12 @@ +#ifdef PRISM_BUILD_SCENE + #ifndef PRISM_SCENEPARSER_HPP_ #define PRISM_SCENEPARSER_HPP_ -#include "Prism/scene.hpp" #include "prism_export.h" + +#include "Prism/scene/scene.hpp" + #include namespace Prism { @@ -34,4 +38,5 @@ class PRISM_EXPORT SceneParser { } // namespace Prism -#endif // PRISM_SCENEPARSER_HPP_ \ No newline at end of file +#endif // PRISM_SCENEPARSER_HPP_ +#endif // PRISM_BUILD_SCENE \ No newline at end of file diff --git a/libs/Prism/src/color.cpp b/src/src/core/color.cpp similarity index 92% rename from libs/Prism/src/color.cpp rename to src/src/core/color.cpp index 5ab9e8c..b8e69f2 100644 --- a/libs/Prism/src/color.cpp +++ b/src/src/core/color.cpp @@ -1,4 +1,4 @@ -#include "Prism/color.hpp" +#include "Prism/core/color.hpp" namespace Prism { diff --git a/libs/Prism/src/init.cpp b/src/src/core/init.cpp similarity index 93% rename from libs/Prism/src/init.cpp rename to src/src/core/init.cpp index a661694..d5b2860 100644 --- a/libs/Prism/src/init.cpp +++ b/src/src/core/init.cpp @@ -1,4 +1,5 @@ -#include "Prism/style.hpp" +#include "Prism/core/style.hpp" + #include namespace Prism { diff --git a/libs/Prism/src/matrix.cpp b/src/src/core/matrix.cpp similarity index 99% rename from libs/Prism/src/matrix.cpp rename to src/src/core/matrix.cpp index a1f6546..71c3b5c 100644 --- a/libs/Prism/src/matrix.cpp +++ b/src/src/core/matrix.cpp @@ -1,4 +1,5 @@ -#include "Prism/matrix.hpp" +#include "Prism/core/matrix.hpp" + #include #include #include diff --git a/libs/Prism/src/point.cpp b/src/src/core/point.cpp similarity index 92% rename from libs/Prism/src/point.cpp rename to src/src/core/point.cpp index 428d19c..adf5a46 100644 --- a/libs/Prism/src/point.cpp +++ b/src/src/core/point.cpp @@ -1,6 +1,7 @@ -#include "Prism/point.hpp" -#include "Prism/matrix.hpp" -#include "Prism/vector.hpp" +#include "Prism/core/point.hpp" + +#include "Prism/core/vector.hpp" + #include namespace Prism { diff --git a/libs/Prism/src/ray.cpp b/src/src/core/ray.cpp similarity index 82% rename from libs/Prism/src/ray.cpp rename to src/src/core/ray.cpp index 8769fae..b6030db 100644 --- a/libs/Prism/src/ray.cpp +++ b/src/src/core/ray.cpp @@ -1,10 +1,5 @@ -#include "Prism/ray.hpp" -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/core/ray.hpp" + #include #include diff --git a/libs/Prism/src/utils.cpp b/src/src/core/utils.cpp similarity index 97% rename from libs/Prism/src/utils.cpp rename to src/src/core/utils.cpp index d73d091..81c1976 100644 --- a/libs/Prism/src/utils.cpp +++ b/src/src/core/utils.cpp @@ -1,4 +1,5 @@ -#include "Prism/utils.hpp" +#include "Prism/core/utils.hpp" + #include #include diff --git a/libs/Prism/src/vector.cpp b/src/src/core/vector.cpp similarity index 97% rename from libs/Prism/src/vector.cpp rename to src/src/core/vector.cpp index 543b725..e078ffd 100644 --- a/libs/Prism/src/vector.cpp +++ b/src/src/core/vector.cpp @@ -1,6 +1,6 @@ -#include "Prism/vector.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" +#include "Prism/core/vector.hpp" + +#include "Prism/core/point.hpp" #include #include diff --git a/libs/Prism/src/mesh.cpp b/src/src/objects/mesh.cpp similarity index 90% rename from libs/Prism/src/mesh.cpp rename to src/src/objects/mesh.cpp index cb6bcc4..9cb88ee 100644 --- a/libs/Prism/src/mesh.cpp +++ b/src/src/objects/mesh.cpp @@ -1,12 +1,13 @@ -#include "Prism/mesh.hpp" -#include "Prism/matrix.hpp" +#include "Prism/objects/mesh.hpp" + +#include "Prism/core/matrix.hpp" #include namespace Prism { // TODO: Implementar BVH aqui -Mesh::Mesh(std::string path) { - ObjReader reader(path); +Mesh::Mesh(std::filesystem::path& path) { + ObjReader reader(path.string()); material = std::move(reader.curMaterial); for (auto& point : reader.vertices) { diff --git a/libs/Prism/src/plane.cpp b/src/src/objects/plane.cpp similarity index 86% rename from libs/Prism/src/plane.cpp rename to src/src/objects/plane.cpp index 98e8260..9e7f881 100644 --- a/libs/Prism/src/plane.cpp +++ b/src/src/objects/plane.cpp @@ -1,9 +1,7 @@ -#include "Prism/plane.hpp" -#include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/objects/plane.hpp" + +#include "Prism/core/matrix.hpp" + #include namespace Prism { diff --git a/libs/Prism/src/sphere.cpp b/src/src/objects/sphere.cpp similarity index 93% rename from libs/Prism/src/sphere.cpp rename to src/src/objects/sphere.cpp index 749dfc5..203e875 100644 --- a/libs/Prism/src/sphere.cpp +++ b/src/src/objects/sphere.cpp @@ -1,6 +1,8 @@ -#include "Prism/sphere.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" +#include "Prism/objects/sphere.hpp" + +#include "Prism/core/matrix.hpp" +#include "Prism/core/utils.hpp" + #include namespace Prism { diff --git a/libs/Prism/src/triangle.cpp b/src/src/objects/triangle.cpp similarity index 96% rename from libs/Prism/src/triangle.cpp rename to src/src/objects/triangle.cpp index f3e487a..03f8de1 100644 --- a/libs/Prism/src/triangle.cpp +++ b/src/src/objects/triangle.cpp @@ -1,7 +1,7 @@ -#include "Prism/triangle.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" +#include "Prism/objects/triangle.hpp" + +#include "Prism/core/matrix.hpp" + #include namespace Prism { diff --git a/libs/Prism/src/camera.cpp b/src/src/scene/camera.cpp similarity index 87% rename from libs/Prism/src/camera.cpp rename to src/src/scene/camera.cpp index 542a9ce..04bff16 100644 --- a/libs/Prism/src/camera.cpp +++ b/src/src/scene/camera.cpp @@ -1,9 +1,7 @@ -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism/scene/camera.hpp" + +#include "Prism/core/utils.hpp" + #include #include diff --git a/libs/Prism/src/scene.cpp b/src/src/scene/scene.cpp similarity index 93% rename from libs/Prism/src/scene.cpp rename to src/src/scene/scene.cpp index 020b21e..8e6dd2f 100644 --- a/libs/Prism/src/scene.cpp +++ b/src/src/scene/scene.cpp @@ -1,7 +1,9 @@ -#include "Prism/scene.hpp" -#include "Prism/color.hpp" -#include "Prism/material.hpp" -#include "Prism/style.hpp" +#include "Prism/scene/scene.hpp" + +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/style.hpp" + #include #include #include @@ -70,7 +72,7 @@ void Scene::render() const { } auto clean_path = std::filesystem::weakly_canonical(output_dir); - + Style::logInfo("Output directory: " + Prism::Style::CYAN + clean_path.string()); Style::logInfo("Starting render...\n"); @@ -106,14 +108,15 @@ void Scene::render() const { image_file << pixel_color << '\n'; pixels_done++; - int current_progress_percent = static_cast((static_cast(pixels_done) / total_pixels) * 100.0); + int current_progress_percent = + static_cast((static_cast(pixels_done) / total_pixels) * 100.0); if (current_progress_percent > last_progress_percent) { last_progress_percent = current_progress_percent; Style::logStatusBar(static_cast(current_progress_percent) / 100.0); } } - + image_file.close(); Style::logDone("Rendering complete."); diff --git a/libs/Prism/src/scene_parser.cpp b/src/src/scene/scene_parser.cpp similarity index 68% rename from libs/Prism/src/scene_parser.cpp rename to src/src/scene/scene_parser.cpp index d6a9f83..4ee4210 100644 --- a/libs/Prism/src/scene_parser.cpp +++ b/src/src/scene/scene_parser.cpp @@ -1,23 +1,25 @@ -#include "Prism/scene_parser.hpp" -#include +#ifdef PRISM_BUILD_SCENE + +#include "Prism/scene/scene_parser.hpp" + +#include "Prism/core/color.hpp" +#include "Prism/core/material.hpp" +#include "Prism/core/matrix.hpp" +#include "Prism/core/point.hpp" +#include "Prism/core/style.hpp" +#include "Prism/core/vector.hpp" +#include "Prism/objects/mesh.hpp" +#include "Prism/objects/plane.hpp" +#include "Prism/objects/sphere.hpp" +#include "Prism/objects/triangle.hpp" +#include "Prism/scene/camera.hpp" + +#include #include #include #include #include -#include "Prism/scene.hpp" -#include "Prism/camera.hpp" -#include "Prism/material.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" -#include "Prism/matrix.hpp" -#include "Prism/objects.hpp" -#include "Prism/sphere.hpp" -#include "Prism/plane.hpp" -#include "Prism/triangle.hpp" -#include "Prism/mesh.hpp" -#include "Prism/color.hpp" -#include "Prism/style.hpp" -#include +#include #ifndef M_PI #define M_PI 3.14159265358979323846 // Define M_PI if not already defined @@ -46,21 +48,31 @@ Vector3 parseVector(const YAML::Node& node) { // Converts a YAML node with material properties to a Material std::shared_ptr parseMaterial(const YAML::Node& node) { auto mat = std::make_shared(); - - if (node["color"]) {Vector3 v = parseVector(node["color"]); mat->color = Color(v.x, v.y, v.z);} - if (node["ka"]) mat->ka = parseVector(node["ka"]); - if (node["ks"]) mat->ks = parseVector(node["ks"]); - if (node["ke"]) mat->ke = parseVector(node["ke"]); - if (node["ns"]) mat->ns = node["ns"].as(); - if (node["ni"]) mat->ni = node["ni"].as(); - if (node["d"]) mat->d = node["d"].as(); + + if (node["color"]) { + Vector3 v = parseVector(node["color"]); + mat->color = Color(v.x, v.y, v.z); + } + if (node["ka"]) + mat->ka = parseVector(node["ka"]); + if (node["ks"]) + mat->ks = parseVector(node["ks"]); + if (node["ke"]) + mat->ke = parseVector(node["ke"]); + if (node["ns"]) + mat->ns = node["ns"].as(); + if (node["ni"]) + mat->ni = node["ni"].as(); + if (node["d"]) + mat->d = node["d"].as(); return mat; } // Converts a YAML list of transformations into a single transformation matrix Matrix parseTransformations(const YAML::Node& node) { Matrix final_transform = Matrix::identity(4); - if (!node) return final_transform; + if (!node) + return final_transform; // Transformations are applied in the reverse order of the list (standard in computer graphics) for (int i = node.size() - 1; i >= 0; --i) { @@ -79,7 +91,8 @@ Matrix parseTransformations(const YAML::Node& node) { Vector3 v = parseVector(transform_node["factors"]); current_transform = Matrix::scaling(v.x, v.y, v.z); } else { - Style::logWarning("Unknown transformation type: " + type + ". Skipping this transformation."); + Style::logWarning("Unknown transformation type: " + type + + ". Skipping this transformation."); continue; // Skip unknown transformation types } final_transform = final_transform * current_transform; @@ -89,7 +102,8 @@ Matrix parseTransformations(const YAML::Node& node) { // --- SceneParser Class Implementation --- -SceneParser::SceneParser(const std::string& sceneFilePath) : filePath(sceneFilePath) {} +SceneParser::SceneParser(const std::string& sceneFilePath) : filePath(sceneFilePath) { +} Scene SceneParser::parse() { YAML::Node root; @@ -106,16 +120,10 @@ Scene SceneParser::parse() { throw std::runtime_error("'camera' node not found in the scene file."); } const auto& cam_node = root["camera"]; - Camera camera( - parsePoint(cam_node["lookfrom"]), - parsePoint(cam_node["lookat"]), - parseVector(cam_node["vup"]), - cam_node["screen_distance"].as(), - cam_node["viewport_height"].as(), - cam_node["viewport_width"].as(), - cam_node["image_height"].as(), - cam_node["image_width"].as() - ); + Camera camera(parsePoint(cam_node["lookfrom"]), parsePoint(cam_node["lookat"]), + parseVector(cam_node["vup"]), cam_node["screen_distance"].as(), + cam_node["viewport_height"].as(), cam_node["viewport_width"].as(), + cam_node["image_height"].as(), cam_node["image_width"].as()); Scene scene(std::move(camera)); @@ -135,7 +143,7 @@ Scene SceneParser::parse() { for (const auto& obj_node : root["objects"]) { std::string type = obj_node["type"].as(); - + // Find the material (whether defined inline or by reference) std::shared_ptr material; if (obj_node["material"].IsMap()) { @@ -154,26 +162,23 @@ Scene SceneParser::parse() { std::unique_ptr object; if (type == "sphere") { - object = std::make_unique( - parsePoint(obj_node["center"]), - obj_node["radius"].as(), - material); + object = std::make_unique(parsePoint(obj_node["center"]), + obj_node["radius"].as(), material); } else if (type == "plane") { - object = std::make_unique( - parsePoint(obj_node["point_on_plane"]), - parseVector(obj_node["normal"]), - material); + object = std::make_unique(parsePoint(obj_node["point_on_plane"]), + parseVector(obj_node["normal"]), material); } else if (type == "triangle") { - object = std::make_unique( - parsePoint(obj_node["p1"]), - parsePoint(obj_node["p2"]), - parsePoint(obj_node["p3"]), - material); + object = + std::make_unique(parsePoint(obj_node["p1"]), parsePoint(obj_node["p2"]), + parsePoint(obj_node["p3"]), material); } else if (type == "mesh") { - std::string path = obj_node["path"].as(); - object = std::make_unique(path); + std::filesystem::path scene_dir = std::filesystem::path(filePath).parent_path(); + std::string mesh_path_str = obj_node["path"].as(); + std::filesystem::path full_mesh_path = scene_dir / mesh_path_str; + + object = std::make_unique(full_mesh_path); // Overrides the .obj material with the one from the .yml, if specified - if(obj_node["material"]) { + if (obj_node["material"]) { auto mesh_ptr = static_cast(object.get()); // (A material setter would be needed in the Mesh class here) } @@ -191,4 +196,6 @@ Scene SceneParser::parse() { return scene; } -} // namespace Prism \ No newline at end of file +} // namespace Prism + +#endif // PRISM_BUILD_SCENE \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fd3869a..e1c74a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,23 @@ +# =================================================================== +# Prism Unit Tests +# +# This CMakeLists.txt file sets up the unit tests for the Prism +# library. It defines the test runner executable, links it against +# the Prism library and registers the tests with CTest. +# =================================================================== + +# Collect all test source files. file(GLOB_RECURSE TEST_SOURCES "src/*.cpp") + +# Define the test runner executable. add_executable(runTests ${TEST_SOURCES}) -target_link_libraries(runTests PRIVATE include gtest_main) -target_include_directories(runTests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) +# Add the local `include` directory for test helpers. +target_include_directories(runTests PRIVATE include) + +# Link the test runner against the library being tested (Prism) +# and the GoogleTest framework. +target_link_libraries(runTests PRIVATE Prism GTest::gtest_main) +# Register the executable with CTest. add_test(NAME UnitTests COMMAND runTests) \ No newline at end of file diff --git a/tests/include/TestHelpers.hpp b/tests/include/TestHelpers.hpp index 7e91376..093990f 100644 --- a/tests/include/TestHelpers.hpp +++ b/tests/include/TestHelpers.hpp @@ -1,9 +1,8 @@ #ifndef TESTS_TESTHELPERS_HPP #define TESTS_TESTHELPERS_HPP -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include namespace Prism { diff --git a/tests/src/CameraTest.cpp b/tests/src/CameraTest.cpp index 0232be8..9b5ce5a 100644 --- a/tests/src/CameraTest.cpp +++ b/tests/src/CameraTest.cpp @@ -1,11 +1,9 @@ -#include "Prism/camera.hpp" -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/ray.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include using namespace Prism; diff --git a/tests/src/MatrixTest.cpp b/tests/src/MatrixTest.cpp index 8f38d55..255b3d3 100644 --- a/tests/src/MatrixTest.cpp +++ b/tests/src/MatrixTest.cpp @@ -1,10 +1,11 @@ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" -#include + #include +#include + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif diff --git a/tests/src/PlaneTest.cpp b/tests/src/PlaneTest.cpp index 282cecf..93ee9de 100644 --- a/tests/src/PlaneTest.cpp +++ b/tests/src/PlaneTest.cpp @@ -1,7 +1,10 @@ #include "Prism.hpp" + #include "TestHelpers.hpp" + #include -#include // Incluído para std::shared_ptr + +#include using namespace Prism; diff --git a/tests/src/Point3Test.cpp b/tests/src/Point3Test.cpp index 2e067ec..80d02da 100644 --- a/tests/src/Point3Test.cpp +++ b/tests/src/Point3Test.cpp @@ -1,8 +1,7 @@ -#include "Prism/matrix.hpp" -#include "Prism/point.hpp" -#include "Prism/utils.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include using Prism::Matrix; diff --git a/tests/src/RayTest.cpp b/tests/src/RayTest.cpp index 95ad687..1aa2a61 100644 --- a/tests/src/RayTest.cpp +++ b/tests/src/RayTest.cpp @@ -1,9 +1,9 @@ -#include "Prism/ray.hpp" -#include "Prism/objects.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include #include diff --git a/tests/src/SphereTest.cpp b/tests/src/SphereTest.cpp index a2971b9..91db57e 100644 --- a/tests/src/SphereTest.cpp +++ b/tests/src/SphereTest.cpp @@ -1,7 +1,10 @@ #include "Prism.hpp" + #include "TestHelpers.hpp" -#include + #include + +#include #include using namespace Prism; diff --git a/tests/src/TransformationsTest.cpp b/tests/src/TransformationsTest.cpp index 0e608d5..d8b446c 100644 --- a/tests/src/TransformationsTest.cpp +++ b/tests/src/TransformationsTest.cpp @@ -1,14 +1,16 @@ -#include +#include "Prism.hpp" + +#include "TestHelpers.hpp" + #include + +#include #include #ifndef M_PI #define M_PI 3.14159265358979323846 #endif -#include "Prism.hpp" -#include "TestHelpers.hpp" // Para comparações de ponto flutuante - using namespace Prism; // Testa a transformação de um raio diff --git a/tests/src/UtilsTest.cpp b/tests/src/UtilsTest.cpp index 2f065c8..330ae06 100644 --- a/tests/src/UtilsTest.cpp +++ b/tests/src/UtilsTest.cpp @@ -1,8 +1,9 @@ -#include "Prism/utils.hpp" -#include "Prism/point.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include + #include using Prism::centroid; diff --git a/tests/src/Vector3Test.cpp b/tests/src/Vector3Test.cpp index e578d78..e9a88c3 100644 --- a/tests/src/Vector3Test.cpp +++ b/tests/src/Vector3Test.cpp @@ -1,6 +1,7 @@ -#include "Prism/matrix.hpp" -#include "Prism/vector.hpp" +#include "Prism.hpp" + #include "TestHelpers.hpp" + #include using Prism::Matrix;