From ae8b4d1f6da07f489d658873fc3151d7e9f74cd9 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 9 Mar 2024 13:12:19 -0500 Subject: [PATCH 1/2] Add Model(raylib::Mesh) constructor to throw an exception --- examples/models/models_first_person_maze.cpp | 2 +- include/Model.hpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/models/models_first_person_maze.cpp b/examples/models/models_first_person_maze.cpp index 4910aa79..a62b1258 100644 --- a/examples/models/models_first_person_maze.cpp +++ b/examples/models/models_first_person_maze.cpp @@ -25,7 +25,7 @@ int main(void) raylib::Image imMap("resources/cubicmap.png"); // Load cubicmap image (RAM) raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM) - raylib::MeshUnmanaged mesh = raylib::MeshUnmanaged::Cubicmap(imMap, Vector3{ 1.0f, 1.0f, 1.0f }); // Use MeshUnmanaged, Mesh will be handled by Model + raylib::MeshUnmanaged mesh = raylib::Mesh::Cubicmap(imMap, Vector3{ 1.0f, 1.0f, 1.0f }); // Use MeshUnmanaged, Mesh will be handled by Model raylib::Model model(mesh); // NOTE: By default each cube is mapped to one part of texture atlas diff --git a/include/Model.hpp b/include/Model.hpp index a2e1cf97..d82be53b 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -43,6 +43,15 @@ class Model : public ::Model { Load(mesh); } + /* + * Load a model from a mesh. + * + * @throws raylib::RaylibException Throws if failed to load the Modal. + */ + Model(const raylib::Mesh& mesh) { + throw raylib::RaylibException("Model(mesh) constructor expects a ::Mesh or raylib::MeshUnmanaged, as it takes ownership of the Mesh itself."); + } + ~Model() { Unload(); } From 6ef220cd32da62aa2c1a0256f3f6e531fafabbe5 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 9 Mar 2024 13:16:09 -0500 Subject: [PATCH 2/2] Update docs --- include/Model.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Model.hpp b/include/Model.hpp index d82be53b..65fbcfe1 100644 --- a/include/Model.hpp +++ b/include/Model.hpp @@ -44,9 +44,9 @@ class Model : public ::Model { } /* - * Load a model from a mesh. + * Overloaded constructor to catch when passing in a `raylib::Mesh`. It expects a `raylib::MeshUnmanaged or `::Mesh`. * - * @throws raylib::RaylibException Throws if failed to load the Modal. + * @throws raylib::RaylibException Since the model takes ownership of the Mesh, a `::Mesh` or `raylib::UnmanagedMesh` is required here. */ Model(const raylib::Mesh& mesh) { throw raylib::RaylibException("Model(mesh) constructor expects a ::Mesh or raylib::MeshUnmanaged, as it takes ownership of the Mesh itself.");