diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index d30aa3fc..1ca82650 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -8,10 +8,20 @@ #include "Model/Model.hpp" #include "Exceptions/RayError.hpp" -RAY::Drawables::Drawables3D::Model::Model(const std::string &filename, const RAY::Vector3 &position, const RAY::Vector3 &rotationAxis, float rotationAngle, const RAY::Vector3 &scale): - ADrawable3D(position, WHITE), _model(LoadModel(filename.c_str())), - _rotationAxis(rotationAxis), _rotationAngle(rotationAngle), _scale(scale) +RAY::Drawables::Drawables3D::Model::Model(const std::string &filename, + std::optional> texture, + const RAY::Vector3 &position, + const RAY::Vector3 &rotationAxis, + float rotationAngle, + const RAY::Vector3 &scale) + : ADrawable3D(position, WHITE), + _model(LoadModel(filename.c_str())), + _rotationAxis(rotationAxis), + _rotationAngle(rotationAngle), + _scale(scale) { + if (texture.has_value()) + this->setTextureToMaterial(texture->first, texture->second); } RAY::Drawables::Drawables3D::Model::Model(const Mesh &mesh) @@ -58,7 +68,15 @@ bool RAY::Drawables::Drawables3D::Model::setAnimation(const RAY::ModelAnimation bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const RAY::Texture &texture) { - SetMaterialTexture(&this->_model.materials[materialType], materialType, texture); + this->_textureList[materialType] = texture; + SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]); + return true; +} + +bool RAY::Drawables::Drawables3D::Model::setTextureToMaterial(RAY::Drawables::Drawables3D::Model::MaterialType materialType, const std::string &texturePath) +{ + this->_textureList.emplace(materialType, texturePath); + SetMaterialTexture(&this->_model.materials[materialType], materialType, this->_textureList[materialType]); return true; } diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index c86e7693..1f50119e 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -14,6 +14,8 @@ #include "Model/ModelAnimation.hpp" #include #include +#include +#include namespace RAY::Drawables::Drawables3D { //! @brief Basic 3D Model type @@ -24,7 +26,12 @@ namespace RAY::Drawables::Drawables3D { //! @brief Create an model, loading a file //! @param filePath: path to file to load - Model(const std::string &filePath, const RAY::Vector3 &position = {0, 0, 0}, const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), float rotationAngle = 0, const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1)); + Model(const std::string &filePath, + std::optional> texture = std::nullopt, + const RAY::Vector3 &position = {0, 0, 0}, + const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0), + float rotationAngle = 0, + const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1)); //! @brief Create an model, loading a file //! @param mesh: mesh to load @@ -58,6 +65,7 @@ namespace RAY::Drawables::Drawables3D { //! @param materielIndex The type of material to apply the texture to (serves as an index) //! @param texture the texture to apply bool setTextureToMaterial(MaterialType materialType, const RAY::Texture &texture); + bool setTextureToMaterial(MaterialType materialType, const std::string &texture); //! @return The number of bones in the model int getBoneCount() const; @@ -85,6 +93,8 @@ namespace RAY::Drawables::Drawables3D { private: //! @brief Raw data from raylib ::Model _model; + //! @brief The list of textures that can be applied to this model. + std::map _textureList; //! @brief Rotation property RAY::Vector3 _rotationAxis; //! @brief Rotation property diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 370401f2..12f5da60 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include "Models/Vector2.hpp" @@ -15,6 +16,9 @@ #include "Runner.hpp" #include "Models/GameState.hpp" +namespace RAY2D = RAY::Drawables::Drawables2D; +namespace RAY3D = RAY::Drawables::Drawables3D; + namespace BBM { void updateState(WAL::Wal &engine, GameState &state) @@ -29,20 +33,23 @@ namespace BBM { RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE); -// wal.addSystem>(); + wal.addSystem>(); wal.addSystem(window) - .addSystem>(); + .addSystem>(); wal.addSystem(window); } - WAL::Scene loadGameScene() + std::shared_ptr loadGameScene() { - WAL::Scene scene; - scene.addEntity("cube") + auto scene = std::make_shared(); + scene->addEntity("cube") .addComponent() - .addComponent>(Vector2f(), Vector2f(10, 10), RED); - scene.addEntity("camera") + .addComponent>(Vector2f(), Vector2f(10, 10), RED); + scene->addEntity("player") + .addComponent() + .addComponent>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")); + scene->addEntity("camera") .addComponent(10, 10, 10) .addComponent(); return scene; @@ -50,15 +57,10 @@ namespace BBM int run() { - WAL::Scene gameScene = loadGameScene(); WAL::Wal wal; wal.addSystem(); enableRaylib(wal); - WAL::Scene scene = loadGameScene(); - wal.scene = std::make_shared(scene); - - - // wal.scene = loadGameScene(); + wal.scene = loadGameScene(); try { wal.run(updateState); diff --git a/sources/System/Renderer/Renderer3DSystem.hpp b/sources/System/Renderer/Renderer3DSystem.hpp index b8435aed..8dba98f6 100644 --- a/sources/System/Renderer/Renderer3DSystem.hpp +++ b/sources/System/Renderer/Renderer3DSystem.hpp @@ -21,11 +21,10 @@ namespace BBM RAY::Window &_window; public: //! @brief ctor - explicit Renderer3DSystem(RAY::Window &window) + explicit Renderer3DSystem() : WAL::System({typeid(PositionComponent), typeid(Drawable3DComponent)}), - _window(window) - { - } + _window(RAY::Window::getInstance()) + {} //! @brief Update the corresponding component of the given entity //! @param entity The entity to update. diff --git a/sources/main.cpp b/sources/main.cpp index 50c4035c..6f0e68da 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -50,13 +50,12 @@ int demo() WAL::Wal wal; const int screenWidth = 800; const int screenHeight = 450; - std::vector::const_iterator iterator = textures.begin(); + auto iterator = textures.begin(); const std::string modelPath = "assets/player/player.iqm"; - RAY::TraceLog::setLevel(LOG_WARNING); +// RAY::TraceLog::setLevel(LOG_WARNING); RAY::Window &window = RAY::Window::getInstance(screenWidth, screenHeight, "Bidibidibop", FLAG_WINDOW_RESIZABLE); RAY::Image icon("assets/icon.png"); - RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position - RAY::Drawables::Drawables3D::Model model(modelPath, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f )); + RAY::Drawables::Drawables3D::Model model(modelPath, std::pair(MAP_DIFFUSE, "assets/player/blue.png")); RAY::Camera::Camera3D camera(RAY::Vector3(10.0f, 10.0f, 10.0f), RAY::Vector3(0.0f, 0.0f, 0.0f), RAY::Vector3(0.0f, 1.0f, 0.0f), @@ -66,18 +65,19 @@ int demo() RAY::Drawables::Drawables3D::Circle circle({0, 0, 0}, 5, MAROON, {0, 0, 0}, 0); BBM::Drawable3DComponent circleComponent(entityPlayer, circle); - BBM::Renderer3DSystem circleSystem(window); + BBM::Renderer3DSystem circleSystem; wal.addSystem(circleSystem); entityPlayer.addComponent(circleComponent); - RAY::Texture texture(get_full_path(*iterator)); +// RAY::Texture texture(get_full_path(*iterator)); RAY::ModelAnimations animations(modelPath); RAY::Drawables::Drawables3D::Grid grid(10, 1.0f); RAY::Drawables::Drawables2D::Text instructionText("PRESS SPACE to PLAY MODEL ANIMATION", 10, {10, 20} , MAROON); size_t animationIndex = 0; + RAY::Vector3 position(0.0f, 0.0f, 0.0f); // Set model position - model.setTextureToMaterial(MAP_DIFFUSE, texture); +// model.setTextureToMaterial(MAP_DIFFUSE, texture); window.setIcon(icon); camera.setMode(CAMERA_FREE); // Set free camera mode @@ -99,9 +99,9 @@ int demo() ++iterator; if (iterator == textures.end()) iterator = textures.begin(); - texture.unload(); - texture.load(get_full_path(*iterator)); - model.setTextureToMaterial(MAP_DIFFUSE, texture); +// texture.unload(); +// texture.load(get_full_path(*iterator)); +// model.setTextureToMaterial(MAP_DIFFUSE, texture); } if (RAY::Controller::Keyboard::isReleased(KEY_LEFT)) { @@ -113,17 +113,17 @@ int demo() animationIndex = ++animationIndex % animations.getAnimationsCount(); model.setAnimation(animations[animationIndex]); } -// window.setDrawingState(RAY::Window::DRAWING); - window.clear(); - window.useCamera(camera); + window.draw(); + window.clear(); + window.useCamera(camera); - window.draw(model); + model.drawOn(window);//, position, RAY::Vector3(1.0f, 20, 0.0f), -180.0f, RAY::Vector3( 3.0f, 3.0f, 3.0f )); - window.draw(grid); - window.draw(circle); - window.unuseCamera(); - window.draw(instructionText); -// window.setDrawingState(RAY::Window::IDLE); + window.draw(grid); + window.draw(circle); + window.unuseCamera(); + window.draw(instructionText); + window.draw(); } window.close();