From 45047d5231e3b0f4be801a061be5b15fb4a60a06 Mon Sep 17 00:00:00 2001 From: Hapaxia Date: Wed, 19 Feb 2025 17:08:54 +0000 Subject: [PATCH] update Sprite3d to v1.3 updates Sprite 3D to v1.0.0 adds ability to "setTexture" with no parameters, allowing no texture to be set. this allows textures to be disabled and the solid colour used instead. note that this can be done per face so one side can be textured and the other can be a solid colour, for example. note also, that this means that disabling the texture does not disable the subdivisions and 3D calculations even though they are likely unnoticeable. changing the subdivisions and mesh size when disabling/enabling textures can increase efficiency and optimise performance, if required. --- src/SelbaWard/Sprite3d.cpp | 30 +++++++++++++++++++----------- src/SelbaWard/Sprite3d.hpp | 4 +++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/SelbaWard/Sprite3d.cpp b/src/SelbaWard/Sprite3d.cpp index 482c1f2..5819269 100644 --- a/src/SelbaWard/Sprite3d.cpp +++ b/src/SelbaWard/Sprite3d.cpp @@ -188,6 +188,11 @@ void Sprite3d::setTexture(const sf::Texture& texture, const bool resetRect, cons m_pTexture = &texture; } +void Sprite3d::setTexture() +{ + m_pTexture = nullptr; +} + void Sprite3d::setBackTexture(const sf::Texture& texture, const bool resetOffset) { m_pBackTexture = &texture; @@ -195,6 +200,12 @@ void Sprite3d::setBackTexture(const sf::Texture& texture, const bool resetOffset m_backTextureOffset = sf::Vector2i(0, 0); } +void Sprite3d::setBackTexture() +{ + // + m_pBackTexture = nullptr; +} + void Sprite3d::setFlipBack(const bool flipBack) { m_flipBack = flipBack; @@ -475,19 +486,16 @@ float Sprite3d::getDepth() const void Sprite3d::draw(sf::RenderTarget& target, sf::RenderStates states) const { - if (m_pTexture != nullptr) - { - updateTransformedPoints(); - updateVertices(); - states.transform *= getTransform(); + updateTransformedPoints(); + updateVertices(); + states.transform *= getTransform(); - if (m_isBackFacing && (m_pBackTexture != nullptr)) - states.texture = m_pBackTexture; - else - states.texture = m_pTexture; + if (m_isBackFacing && (m_pBackTexture != nullptr)) + states.texture = m_pBackTexture; + else + states.texture = m_pTexture; - target.draw(m_vertices.data(), m_vertices.size(), sf::PrimitiveType::TriangleStrip, states); - } + target.draw(m_vertices.data(), m_vertices.size(), sf::PrimitiveType::TriangleStrip, states); } void Sprite3d::updateTransformedPoints() const diff --git a/src/SelbaWard/Sprite3d.hpp b/src/SelbaWard/Sprite3d.hpp index 674f950..3b14d70 100644 --- a/src/SelbaWard/Sprite3d.hpp +++ b/src/SelbaWard/Sprite3d.hpp @@ -44,7 +44,7 @@ namespace selbaward { -// Sprite3d version 1.2.3 +// Sprite3d version 1.3.0 class Sprite3d : public sf::Drawable, public sf::Transformable { public: @@ -71,6 +71,7 @@ class Sprite3d : public sf::Drawable, public sf::Transformable sf::FloatRect getGlobalBounds() const; void setTexture(const sf::Texture& texture, bool resetRect = false, bool resetBackOffset = false); + void setTexture(); void setTextureRect(const sf::IntRect& rectangle); void setColor(const sf::Color& color); @@ -83,6 +84,7 @@ class Sprite3d : public sf::Drawable, public sf::Transformable sf::Vector2i getBackTextureOffset() const; void setBackTexture(const sf::Texture& texture, bool resetOffset = false); + void setBackTexture(); void setFlipBack(bool flipBack = true); void setTextureOffset(sf::Vector2i textureOffset = { 0, 0 }); void setBackTextureOffset(sf::Vector2i backTextureOffset = { 0, 0 });