Skip to content

Commit

Permalink
update Sprite3d to v1.3
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hapaxia committed Feb 19, 2025
1 parent 2cf5a33 commit 45047d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
30 changes: 19 additions & 11 deletions src/SelbaWard/Sprite3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,24 @@ 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;
if (m_pBackTexture == nullptr || resetOffset)
m_backTextureOffset = sf::Vector2i(0, 0);
}

void Sprite3d::setBackTexture()
{
//
m_pBackTexture = nullptr;
}

void Sprite3d::setFlipBack(const bool flipBack)
{
m_flipBack = flipBack;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/SelbaWard/Sprite3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);

Expand All @@ -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 });
Expand Down

0 comments on commit 45047d5

Please sign in to comment.