Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -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;
```
57 changes: 36 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
# 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()
6 changes: 4 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"installDir": "${sourceDir}/install/debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"BUILD_TESTING": "ON"
"BUILD_TESTING": "ON",
"PRISM_BUILD_DEMO": "ON"
}
},
{
Expand All @@ -20,7 +21,8 @@
"installDir": "${sourceDir}/install/release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_TESTING": "OFF"
"BUILD_TESTING": "OFF",
"PRISM_BUILD_DEMO": "OFF"
}
}
],
Expand Down
95 changes: 64 additions & 31 deletions README.MD → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

---
34 changes: 34 additions & 0 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<TARGET_FILE_DIR:prism_demo>/data
COMMENT "Copying data folder for debug/run..."
)
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion data/input/scene.yml → demo/data/input/scene.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp → demo/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading