From 7bf24d23a7db872f7bd13060da9817a9ee5f816c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Mar 2023 01:36:50 +0000 Subject: Dedupe applying style to a face --- assetFactory/style.cpp | 17 +++++++++++------ assetFactory/style.h | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index fa585ac..b5ddcf1 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -4,22 +4,27 @@ void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Shape::CreatedFaces & faces) const { - if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { - for (const auto & face : faces) { - mesh.set_color(face.second, effectiveColour->get()); - } + for (const auto & face : faces) { + applyStyle(mesh, face.second, getColour(parents)); } } void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const ModelFactoryMesh::FaceHandle & face) const { - if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { + applyStyle(mesh, face, getColour(parents)); +} + +void +Style::applyStyle( + ModelFactoryMesh & mesh, const ModelFactoryMesh::FaceHandle & face, EffectiveColour effectiveColour) const +{ + if (effectiveColour.has_value()) { mesh.set_color(face, effectiveColour->get()); } } -std::optional> +Style::EffectiveColour Style::getColour(const StyleStack & parents) { return getProperty(parents, &Style::colour, [](auto && style) { diff --git a/assetFactory/style.h b/assetFactory/style.h index 8c64276..f3bc707 100644 --- a/assetFactory/style.h +++ b/assetFactory/style.h @@ -12,6 +12,7 @@ public: using StyleStack = std::vector; using Colour = glm::vec3; using ColourAlpha = glm::vec4; + using EffectiveColour = std::optional>; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; @@ -27,7 +28,7 @@ public: return {}; } - static std::optional> getColour(const StyleStack & parents); + static EffectiveColour getColour(const StyleStack & parents); ColourAlpha colour {}; std::string texture; @@ -35,4 +36,5 @@ public: protected: bool persist(Persistence::PersistenceStore & store); + void applyStyle(ModelFactoryMesh &, const ModelFactoryMesh::FaceHandle &, EffectiveColour) const; }; -- cgit v1.2.3