diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 23:29:00 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-09 23:29:00 +0100 |
commit | b6b3944e9507f337f77a72ea44b5c0ccba7a2c01 (patch) | |
tree | a487df54853522f973ed987006e787117804b9eb /assetFactory/style.cpp | |
parent | Swap messy glmvec wrapper for OpenMesh Point/Normal with real glm::vec and a ... (diff) | |
parent | Move remaining split/plane functions to use library (diff) | |
download | ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.bz2 ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.xz ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.zip |
Merge branch 'model-factory-textures'
Diffstat (limited to 'assetFactory/style.cpp')
-rw-r--r-- | assetFactory/style.cpp | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/assetFactory/style.cpp b/assetFactory/style.cpp index fc5c34e..12346a6 100644 --- a/assetFactory/style.cpp +++ b/assetFactory/style.cpp @@ -4,27 +4,48 @@ 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()) { - 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 = getProperty(parents, &Style::colour, - [](auto && style) { - return style->colour.a > 0; - }); - effectiveColour.has_value()) { - mesh.set_color(face, effectiveColour->get()); + applyStyle(mesh, face, getColour(parents)); +} + +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()); + } } + else { + mesh.set_color(face, {}); + if (auto mf = Persistence::ParseBase::getShared<const AssetFactory>("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 & heh : mesh.fh_range(face)) { + mesh.set_texcoord2D(heh, *coord++); + } + } + } +} + +Style::EffectiveColour +Style::getColour(const StyleStack & parents) +{ + return getProperty(parents, &Style::colour, [](auto && style) { + return style->colour.a > 0; + }); } bool @@ -42,5 +63,6 @@ Style::persist(Persistence::PersistenceStore & store) } }; - return STORE_HELPER(colour, ColourParser); + return STORE_HELPER(colour, ColourParser) && STORE_MEMBER(smooth) && STORE_MEMBER(texture) + && STORE_MEMBER(textureRotation); } |