From 0ee9b8c6036899f95dfd54f151cb60a03645f87a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Mar 2023 01:05:18 +0000 Subject: Support loading texture references into faces --- assetFactory/style.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'assetFactory/style.cpp') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index fc5c34e..5303d96 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -42,5 +42,5 @@ Style::persist(Persistence::PersistenceStore & store) } }; - return STORE_HELPER(colour, ColourParser); + return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(texture) && STORE_MEMBER(textureRotation); } -- cgit v1.2.3 From 0d5b57f31e17b8e46979d8c29b5a3205fbdbd44b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Mar 2023 01:29:38 +0000 Subject: Dedupe looking up the style stack for colour --- assetFactory/style.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'assetFactory/style.cpp') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 5303d96..fa585ac 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -4,11 +4,7 @@ void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Shape::CreatedFaces & faces) const { - if (const auto effectiveColour = getProperty(parents, &Style::colour, - [](auto && style) { - return style->colour.a > 0; - }); - effectiveColour.has_value()) { + if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { for (const auto & face : faces) { mesh.set_color(face.second, effectiveColour->get()); } @@ -18,15 +14,19 @@ Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const Sha void Style::applyStyle(ModelFactoryMesh & mesh, const StyleStack & parents, const ModelFactoryMesh::FaceHandle & face) const { - if (const auto effectiveColour = getProperty(parents, &Style::colour, - [](auto && style) { - return style->colour.a > 0; - }); - effectiveColour.has_value()) { + if (const auto effectiveColour = getColour(parents); effectiveColour.has_value()) { mesh.set_color(face, effectiveColour->get()); } } +std::optional> +Style::getColour(const StyleStack & parents) +{ + return getProperty(parents, &Style::colour, [](auto && style) { + return style->colour.a > 0; + }); +} + bool Style::persist(Persistence::PersistenceStore & store) { -- cgit v1.2.3 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 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'assetFactory/style.cpp') 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) { -- cgit v1.2.3 From 3fea21a2d8f2aa67fd212837fe7e09e4f29ad515 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 14 Mar 2023 19:16:57 +0000 Subject: Support creating a super texture from fragments Currently makes wild assumptions about vertices and doesn't actually populate the texture, it's just grey --- assetFactory/style.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'assetFactory/style.cpp') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index b5ddcf1..8aecc71 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -19,8 +19,21 @@ void Style::applyStyle( ModelFactoryMesh & mesh, const ModelFactoryMesh::FaceHandle & face, EffectiveColour effectiveColour) const { - if (effectiveColour.has_value()) { - mesh.set_color(face, effectiveColour->get()); + if (texture.empty()) { + if (effectiveColour.has_value()) { + mesh.set_color(face, effectiveColour->get()); + } + } + else { + mesh.set_color(face, {}); + if (auto mf = Persistence::ParseBase::getShared("assetFactory")) { + auto coords = mf->getTextureCoords(texture); + auto coord = coords.begin(); + // Wild assumption that face is a quad and the texture should apply linearly + for (const auto & vh : mesh.fv_range(face)) { + mesh.set_texcoord2D(vh, *coord++); + } + } } } -- cgit v1.2.3 From 51f0f60bd24a3d7ed77cf713f846bc49c2f1aed5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Mar 2023 02:44:00 +0000 Subject: Use halfedge for texture coordinates More unique than vertex as it is also per face, allowing for a different texture on adjacent faces --- assetFactory/style.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'assetFactory/style.cpp') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index 8aecc71..d1d4adc 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -30,8 +30,8 @@ Style::applyStyle( auto coords = mf->getTextureCoords(texture); auto coord = coords.begin(); // Wild assumption that face is a quad and the texture should apply linearly - for (const auto & vh : mesh.fv_range(face)) { - mesh.set_texcoord2D(vh, *coord++); + for (const auto & heh : mesh.fh_range(face)) { + mesh.set_texcoord2D(heh, *coord++); } } } -- cgit v1.2.3 From 2508112e2853e1a6c012b19c7232aa09f98d3969 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 20 Mar 2023 23:30:21 +0000 Subject: Move smooth property into Style and make it optional This allows it to cascade down as faces are created and also be overridden as required --- assetFactory/style.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'assetFactory/style.cpp') diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index d1d4adc..12346a6 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -19,6 +19,9 @@ void Style::applyStyle( ModelFactoryMesh & mesh, const ModelFactoryMesh::FaceHandle & face, EffectiveColour effectiveColour) const { + if (smooth.has_value()) { + mesh.property(mesh.smoothFaceProperty, face) = smooth.value(); + } if (texture.empty()) { if (effectiveColour.has_value()) { mesh.set_color(face, effectiveColour->get()); @@ -60,5 +63,6 @@ Style::persist(Persistence::PersistenceStore & store) } }; - return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(texture) && STORE_MEMBER(textureRotation); + return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(smooth) && STORE_MEMBER(texture) + && STORE_MEMBER(textureRotation); } -- cgit v1.2.3