From 7d0decccaac3aa564b549d91a36279e7aca0814e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 24 Feb 2023 19:30:30 +0000 Subject: Support for recursive colouring of asset factory faces Updates colours in sample model. --- assetFactory/style.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 assetFactory/style.h (limited to 'assetFactory/style.h') diff --git a/assetFactory/style.h b/assetFactory/style.h new file mode 100644 index 0000000..0c7ad5a --- /dev/null +++ b/assetFactory/style.h @@ -0,0 +1,22 @@ +#pragma once + +#include "modelFactoryMesh.h" +#include "persistence.h" +#include "shape.h" +#include + +class Style { +public: + using StyleStack = std::vector; + + static ModelFactoryMesh::Color parseColour(const std::string_view &); + void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; + void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; + + static std::string_view getProperty(const StyleStack & parents, std::string Style::*member); + + std::string colour; + +protected: + bool persist(Persistence::PersistenceStore & store); +}; -- cgit v1.2.3 From 98df33e0a52e086b68df2a62ce2f41cc6b67db63 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Mar 2023 18:18:38 +0000 Subject: Parse colour values as they're read --- assetFactory/style.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'assetFactory/style.h') diff --git a/assetFactory/style.h b/assetFactory/style.h index 0c7ad5a..e8fd012 100644 --- a/assetFactory/style.h +++ b/assetFactory/style.h @@ -3,19 +3,31 @@ #include "modelFactoryMesh.h" #include "persistence.h" #include "shape.h" +#include #include +#include class Style { public: using StyleStack = std::vector; + using Colour = glm::vec3; + using ColourAlpha = glm::vec4; - static ModelFactoryMesh::Color parseColour(const std::string_view &); void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const Shape::CreatedFaces &) const; void applyStyle(ModelFactoryMesh &, const StyleStack & parents, const ModelFactoryMesh::FaceHandle &) const; - static std::string_view getProperty(const StyleStack & parents, std::string Style::*member); + template + static std::optional> + getProperty(const StyleStack & parents, T Style::*member, auto && test) + { + if (const auto itr = std::find_if(parents.rbegin(), parents.rend(), std::forward(test)); + itr != parents.rend()) { + return (*itr)->*member; + } + return {}; + } - std::string colour; + ColourAlpha colour {}; protected: bool persist(Persistence::PersistenceStore & store); -- cgit v1.2.3