Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Fill layers in the app: Paint Layers panel, Material Recipes list, Mesh Maps baked in the background and live
islandmed32c5b1435624
diff --git a/CMakeLists.txt b/CMakeLists.txtindex fd882b2f..4c4ad2b5 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -288,6 +288,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelPaintLayers.cppsrc/app/PanelTexture.cppsrc/app/PanelPbr.cpp+ src/app/PanelFill.cppsrc/app/PanelGeometry.cppsrc/app/Gizmo.cppsrc/app/PanelBake.cppdiff --git a/assets/materials/painted_edges.sfmaterial b/assets/materials/painted_edges.sfmaterialindex fe48899c..1978bc48 100644--- a/assets/materials/painted_edges.sfmaterial+++ b/assets/materials/painted_edges.sfmaterial@@ -16,7 +16,7 @@"name": "Paint","fill": {"material": {"channels": ["base_color", "roughness", "metallic", "height"], "color": [0.62, 0.16, 0.1], "roughness": 0.55, "metallic": 0.0, "height": 0.53},- "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.5, "softness": 0.08, "breakup": 0.9, "scale": 0.025, "seed": 5},+ "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.42, "softness": 0.08, "breakup": 0.55, "scale": 0.025, "seed": 5},{"kind": "invert"}]}},diff --git a/assets/materials/worn_metal.sfmaterial b/assets/materials/worn_metal.sfmaterialindex cc215674..853f471e 100644--- a/assets/materials/worn_metal.sfmaterial+++ b/assets/materials/worn_metal.sfmaterial@@ -23,7 +23,7 @@"name": "Polished Edges","fill": {"material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.78, 0.79, 0.8], "roughness": 0.18, "metallic": 1.0},- "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.55, "softness": 0.2, "breakup": 0.6, "scale": 0.03, "seed": 3}]+ "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.45, "softness": 0.2, "breakup": 0.45, "scale": 0.03, "seed": 3}]}},{diff --git a/src/app/App.cpp b/src/app/App.cppindex 28411b29..61626612 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1,6 +1,7 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later#include "app/App.h"+#include "core/LayerStack.h"#include "app/ShellQuote.h"#include "app/SpaceCamera.h"#include "app/AsyncStroke.h"@@ -170,6 +171,8 @@ bool App::init(const AppOptions& options) {return false;}renderer_.setEnvironmentWake([] { wakeMainLoop(); }); // (PBR view: a new environment's lighting is ready)+ // Fill layers ask for Mesh Maps: the app bakes them on a worker thread (PanelFill.cpp, updateMeshMaps).+ setMeshMapRequester([this](Document&) { meshMapsWanted_ = true; });IMGUI_CHECKVERSION();ImGui::CreateContext();@@ -644,7 +647,7 @@ bool App::backgroundBusy() const {return running(pendingBrush_) || running(pendingGenerator_) || running(pendingModels_) || running(pendingUnreal_) ||running(pendingComfyCheck_) || galleryBusy() || thumbs_.busy() || libraryScanner_.busy() || autoUv_ ||bakeBusy() || qremesh_ || voxelRemesh_ || updateJob_ || splatTrainBusy() || sculptableBusy() || phoneBusy() ||- supportCardLoading() || renderer_.environmentPending();+ supportCardLoading() || renderer_.environmentPending() || meshMapsBusy();}void App::redrawIn(double seconds) {@@ -1943,6 +1946,10 @@ Mesh& App::displayedMesh() {void App::syncScene() {if (solverBusy()) return; // the solver thread is changing the mesh: the GPU keeps what it has (AsyncStroke.cpp)+ // Fill layers: Mesh Maps bakes started and landed (live after sculpting), and a painted mask's tiles evaluated.+ updateMeshMaps();+ if (paintsTexture(doc_.mesh) && doc_.mesh.texture->fillRevision != doc_.mesh.texture->revision)+ updateFillLayers(doc_.mesh, mutableTexture(doc_.mesh));// The active SubTool's slot shows the LOD being previewed instead of the sculpt.Mesh& shown = displayedMesh();if (&shown != lastDisplayed_) shown.topologyDirty = true;diff --git a/src/app/App.h b/src/app/App.hindex 16d7e94b..05b9910d 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -682,6 +682,20 @@ private:void registerPbrUiActions();double benchmarkDrawMs(int frames); // PanelPbr.cpp: UI tests' draw_msdouble pbrTestValue(const std::string& name) const; // UI test values (UiTest.cpp), NaN when not one of ours+ // Fill layers, Material Recipes and Mesh Maps (PanelFill.cpp).+ struct MeshMapJob;+ std::shared_ptr<MeshMapJob> meshMapJob_; // a Mesh Maps bake on a worker thread (full, or the tiles near a change)+ bool meshMapsWanted_ = false; // bake the active Part's Mesh Maps in full (Bake, or a Fill layer asked)+ uint64_t meshMapsRevision_ = 0; // the undo revision the live update last looked at+ std::string meshMapStatus_;+ double lastMeshMapUpdateMs_ = 0.0;+ uint64_t meshMapUpdates_ = 0;+ glm::vec3 fillColorEdit_{1.0f};+ bool fillColorEditing_ = false;+ void updateMeshMaps(); // once a frame (syncScene): starts and lands Mesh Maps bakes+ bool meshMapsBusy() const;+ void drawFillLayerControls(); // Tool > Paint Layers, below the layer list+ double fillTestValue(const std::string& name) const;int exportPresetChoice_ = 0;// Dense textured meshes: while the Paint brush hovers, the texture painting caches for the area under it are// built ahead of the first dab (PanelPbr.cpp; TexturePainter::prewarm).diff --git a/src/app/PanelFill.cpp b/src/app/PanelFill.cppnew file mode 100644index 00000000..06e178da--- /dev/null+++ b/src/app/PanelFill.cpp@@ -0,0 +1,347 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Fill layers, Material Recipes and Mesh Maps in the interface (core/LayerStack.h, core/MaterialRecipe.h,+// core/MeshMaps.h), under Tool > Paint Layers:+// - New Fill Layer and the Material Recipes list;+// - the Mesh Maps line: what is baked, Bake, and Live (re-bake the tiles near a change after each stroke);+// - with a Fill layer active: its material and its mask effects, each with its own settings.+// Every change runs a command (fill_layer, material_recipe, mesh_maps), so it is undoable and scriptable.+//+// Mesh Maps are baked on a worker thread (updateMeshMaps, once a frame): in full when a Fill layer needs maps the+// Part doesn't have, and after sculpting only the tiles within reach of the change (live). When a bake lands, the+// Fill layers re-evaluate those tiles, so wear and dirt follow the sculpt.+#include "app/App.h"+#include "app/I18n.h"+#include "app/Ui.h"++#include "core/LayerStack.h"+#include "core/MaterialRecipe.h"+#include "core/MeshMaps.h"+#include "core/Polypaint.h"+#include "core/Texture.h"++#include <IconsLucide.h>++#include <atomic>+#include <chrono>+#include <cstdio>+#include <limits>+#include <thread>++namespace sf {++namespace {+constexpr const char* kFillPath = "Tool > Paint Layers > Fill";+}++struct App::MeshMapJob {+ uint32_t part = 0;+ bool full = true;+ std::atomic<bool> done{false};+ std::atomic<float> progress{0.0f};+ std::atomic<bool> cancel{false};+ // Full bake+ std::shared_ptr<Mesh> mesh;+ int width = 0, height = 0;+ uint32_t kinds = 0;+ MeshMapSettings settings;+ std::shared_ptr<MeshMapSet> result;+ std::string error;+ // Live update+ MeshMapUpdate update;+ double started = 0.0;+};++void App::updateMeshMaps() {+ using Clock = std::chrono::steady_clock;+ const auto now = [] { return std::chrono::duration<double>(Clock::now().time_since_epoch()).count(); };+ Mesh& m = doc_.mesh;+ const uint32_t part = doc_.activeSubtoolInfo().id;+ // A finished job: its maps go in when the Part still has the same texture layout.+ if (meshMapJob_) {+ if (!meshMapJob_->done) return;+ const std::shared_ptr<MeshMapJob> job = std::move(meshMapJob_);+ if (job->part != part || !hasTexture(m)) return;+ PaintTexture& t = *m.texture;+ if (job->full) {+ if (!job->result) {+ status_ = job->error == "Cancelled" ? "Mesh Maps bake cancelled" : "Mesh Maps: " + job->error;+ return;+ }+ if (!job->result->matches(m, t.width, t.height)) return; // (the Part changed meanwhile: baked again next frame)+ mutableTexture(m).meshMaps = job->result;+ notifyMeshMapsChanged(doc_, m);+ char buf[160];+ std::snprintf(buf, sizeof buf, "Mesh Maps baked at %dx%d in %.1f s", job->result->width, job->result->height,+ job->result->seconds);+ status_ = buf;+ } else {+ if (!job->update.ok || t.meshMaps != job->update.base) return;+ std::shared_ptr<MeshMapSet> set = applyMeshMapUpdate(job->update);+ if (!set) return;+ mutableTexture(m).meshMaps = std::move(set);+ notifyMeshMapsChanged(doc_, m, &job->update.tiles);+ char buf[160];+ std::snprintf(buf, sizeof buf, "Mesh Maps: %zu tiles updated in %.0f ms", job->update.tiles.size(), (now() - job->started) * 1000.0);+ meshMapStatus_ = buf;+ lastMeshMapUpdateMs_ = (now() - job->started) * 1000.0;+ ++meshMapUpdates_;+ }+ return;+ }+ if (!hasTexture(m) || doc_.sculptor.strokeActive() || drag_ == Drag::Stroke) return;+ const PaintTexture& t = *m.texture;+ const uint32_t need = fillMapsNeeded(t);+ if (!need && !meshMapsWanted_) return;+ const MeshMapSet* have = t.meshMaps.get();+ if (meshMapsWanted_ || !have || !have->matches(m, t.width, t.height) || (have->kinds & need) != need) {+ meshMapsWanted_ = false;+ auto job = std::make_shared<MeshMapJob>();+ job->part = part;+ job->full = true;+ job->mesh = std::make_shared<Mesh>(m);+ job->mesh->texture.reset();+ job->width = t.width;+ job->height = t.height;+ job->kinds = kAllMeshMaps;+ if (have) job->settings = have->settings;+ else job->settings.aoRays = 24, job->settings.thicknessRays = 12;+ job->started = now();+ const bool live = have ? have->live : true;+ const uint64_t revision = have ? have->revision : 0;+ std::thread([job, live, revision] {+ auto set = std::make_shared<MeshMapSet>();+ set->revision = revision;+ if (bakeMeshMaps(*job->mesh, job->width, job->height, job->kinds, job->settings, *set, job->error, [&](float f) {+ job->progress = f;+ return !job->cancel.load();+ })) {+ set->live = live;+ job->result = std::move(set);+ }+ job->mesh.reset();+ job->done = true;+ wakeMainLoop();+ }).detach();+ meshMapJob_ = std::move(job);+ return;+ }+ // Live: after sculpting, the tiles near the change.+ if (!have->live || doc_.undo.revision() == meshMapsRevision_) return;+ meshMapsRevision_ = doc_.undo.revision();+ std::vector<uint32_t> moved;+ const AABB region = changedRegion(*have, m, &moved);+ if (!region.valid()) return;+ auto job = std::make_shared<MeshMapJob>();+ job->part = part;+ job->full = false;+ job->started = now();+ if (!prepareMeshMapUpdate(m, t.meshMaps, region, std::move(moved), job->update)) return;+ std::thread([job] {+ runMeshMapUpdate(job->update, &job->cancel);+ job->done = true;+ wakeMainLoop();+ }).detach();+ meshMapJob_ = std::move(job);+}++bool App::meshMapsBusy() const { return meshMapJob_ != nullptr; }++void App::drawFillLayerControls() {+ const Mesh& mesh = doc_.mesh;+ if (!hasTexture(mesh)) return;+ const PaintTexture& t = *mesh.texture;+ const ImGuiStyle& style = ImGui::GetStyle();+ ImGui::Spacing();+ ImGui::TextDisabled("%s", tr("Fill Layers"));+ const float half = (ImGui::GetContentRegionAvail().x - style.ItemSpacing.x) * 0.5f;+ if (ImGui::Button(ICON_LC_PLUS " Fill Layer##fill", ImVec2(half, 0)))+ runCommand("fill_layer", {{"name", std::string("Fill")}, {"color", colorToHex(doc_.paintColor)}});+ ui::HelpText("New Fill Layer", nullptr,+ "Add a Fill layer: a material over the whole Part through a mask you build from effects (Edge Wear, "+ "Dirt, Gradient, Thickness, Light Direction, Noise, a painted mask, Levels, Blur, Invert). Change it any "+ "time; it follows the sculpt.",+ kFillPath);+ ImGui::SameLine();+ ImGui::SetNextItemWidth(-1);+ if (ImGui::BeginCombo("##recipe", tr("Material Recipe"))) {+ for (const MaterialRecipe& r : builtinMaterialRecipes()) {+ if (ImGui::Selectable((r.name + "##recipe").c_str())) runCommand("material_recipe", {{"name", r.id}});+ if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", r.description.c_str());+ }+ ImGui::EndCombo();+ }+ ui::HelpText("Material Recipe", nullptr,+ "Lay a ready-made stack of Fill layers on the Part: Worn Metal, Painted Edges, Dirt and Dust, Rusted "+ "Iron. They read the Part's Mesh Maps, so each model wears where it would. Undoable.",+ kFillPath);++ // Mesh Maps.+ const MeshMapSet* maps = t.meshMaps.get();+ if (meshMapJob_ && meshMapJob_->full) {+ ImGui::ProgressBar(meshMapJob_->progress.load(), ImVec2(-1, 0), tr("Baking Mesh Maps..."));+ } else {+ char line[160];+ if (maps && maps->matches(mesh, t.width, t.height))+ std::snprintf(line, sizeof line, "Mesh Maps %dx%d%s", maps->width, maps->height, maps->live ? ", live" : "");+ else std::snprintf(line, sizeof line, "%s", tr("No Mesh Maps yet"));+ ImGui::AlignTextToFramePadding();+ ImGui::TextDisabled("%s", line);+ ui::HelpText("Mesh Maps", nullptr,+ "Ambient occlusion, curvature, thickness, position, world normal and ID of the Part on its texture's "+ "UVs, which Fill layers read. Baked in the background when a Fill layer needs them; with Live on, "+ "the tiles near what you sculpt are baked again after each stroke.",+ kFillPath);+ ImGui::SameLine();+ bool live = !maps || maps->live;+ if (ui::Checkbox("Live##meshmaps", &live) && maps) runCommand("mesh_maps", {{"action", std::string("live")}, {"live", live}});+ ImGui::SameLine();+ if (ImGui::SmallButton(tr("Bake##meshmaps"))) meshMapsWanted_ = true;+ }+ if (!meshMapStatus_.empty()) ImGui::TextDisabled("%s", meshMapStatus_.c_str());++ // The active Fill layer.+ const int layer = t.activeLayer;+ if (!isFillLayer(t, layer)) return;+ const FillLayer& f = *t.layers[size_t(layer)].fill;+ ImGui::Separator();+ ImGui::TextUnformatted(t.layers[size_t(layer)].name.c_str());+ const Args at = {{"index", double(layer)}};+ auto withLayer = [&](Args a) {+ a["index"] = double(layer);+ return a;+ };+ // Material: colour and the channels it lays down.+ glm::vec3 col = linearToSrgb(glm::clamp(f.material.color, 0.0f, 1.0f));+ if (ImGui::ColorEdit3("##fillcolor", &col.x, ImGuiColorEditFlags_NoInputs)) fillColorEdit_ = srgbToLinear(col), fillColorEditing_ = true;+ if (ImGui::IsItemDeactivatedAfterEdit() && fillColorEditing_) {+ fillColorEditing_ = false;+ runCommand("fill_layer", withLayer({{"action", std::string("set")}, {"color", colorToHex(fillColorEdit_)}}));+ }+ ui::HelpText("Fill colour", nullptr, "The base colour the Fill layer lays down.", kFillPath);+ for (Channel c : {Channel::BaseColor, Channel::Roughness, Channel::Metallic, Channel::Height}) {+ ImGui::SameLine();+ bool on = f.material.channels & channelBit(c);+ if (ui::Checkbox((std::string(channelFormat(c).shortLabel) + "##fillch").c_str(), &on)) {+ std::string list;+ for (int k = 0; k < kChannelCount; ++k) {+ const bool has = k == int(c) ? on : (f.material.channels & (1u << k)) != 0;+ if (has) list += std::string(list.empty() ? "" : ",") + channelFormat(k).id;+ }+ if (!list.empty()) runCommand("fill_layer", withLayer({{"action", std::string("set")}, {"channels", list}}));+ }+ }+ auto materialSlider = [&](const char* id, const char* key, float value, const char* fmt, Channel c) {+ if (!(f.material.channels & channelBit(c))) return;+ ImGui::SetNextItemWidth(-1);+ float v = value;+ ImGui::SliderFloat(id, &v, 0.0f, 1.0f, fmt);+ if (ImGui::IsItemDeactivatedAfterEdit()) runCommand("fill_layer", withLayer({{"action", std::string("set")}, {key, double(v)}}));+ };+ materialSlider("##fillrough", "roughness", f.material.roughness, "Roughness %.2f", Channel::Roughness);+ materialSlider("##fillmetal", "metallic", f.material.metallic, "Metallic %.2f", Channel::Metallic);+ materialSlider("##fillheight", "height", f.material.height, "Height %.2f", Channel::Height);++ // Mask effects, top to bottom.+ ImGui::TextDisabled("%s", tr("Mask"));+ int remove = -1;+ for (size_t k = 0; k < f.effects.size(); ++k) {+ const MaskEffect& e = f.effects[k];+ ImGui::PushID(int(k));+ const std::string title = std::to_string(k + 1) + ". " ++ (e.kind == MaskEffectKind::Generator ? generatorLabel(e.generator) : maskEffectLabel(e.kind));+ auto effectArgs = [&](Args a) {+ a["action"] = std::string("effect");+ a["effect"] = double(k);+ return withLayer(std::move(a));+ };+ bool enabled = e.enabled;+ if (ui::Checkbox("##on", &enabled)) runCommand("fill_layer", effectArgs({{"enabled", enabled}}));+ ImGui::SameLine();+ ImGui::TextUnformatted(title.c_str());+ if (k > 0) {+ ImGui::SameLine();+ ImGui::SetNextItemWidth(ImGui::CalcTextSize("Multiply ").x + ImGui::GetFrameHeight());+ if (ImGui::BeginCombo("##blend", maskBlendId(e.blend))) {+ for (int b = 0; b < kMaskBlendCount; ++b)+ if (ImGui::Selectable(maskBlendId(MaskBlend(b)), int(e.blend) == b))+ runCommand("fill_layer", effectArgs({{"blend", std::string(maskBlendId(MaskBlend(b)))}}));+ ImGui::EndCombo();+ }+ }+ ImGui::SameLine(ImGui::GetContentRegionAvail().x + ImGui::GetCursorPosX() - ImGui::GetFrameHeight());+ if (ImGui::SmallButton(ICON_LC_X "##remove")) remove = int(k);+ auto slider = [&](const char* id, const char* key, float value, float lo, float hi, const char* fmt) {+ ImGui::SetNextItemWidth(-1);+ float v = value;+ ImGui::SliderFloat(id, &v, lo, hi, fmt);+ if (ImGui::IsItemDeactivatedAfterEdit()) runCommand("fill_layer", effectArgs({{key, double(v)}}));+ };+ switch (e.kind) {+ case MaskEffectKind::Generator:+ slider("##level", "level", e.level, 0.0f, 1.0f, "Level %.2f");+ slider("##soft", "softness", e.softness, 0.0f, 1.0f, "Softness %.2f");+ slider("##breakup", "breakup", e.breakup, 0.0f, 2.0f, "Break-up %.2f");+ slider("##scale", "scale", e.scale, 0.002f, 0.3f, "Noise size %.3f");+ break;+ case MaskEffectKind::Noise:+ slider("##scale", "scale", e.scale, 0.002f, 0.3f, "Size %.3f");+ slider("##contrast", "contrast", e.contrast, 0.0f, 4.0f, "Contrast %.2f");+ break;+ case MaskEffectKind::Levels:+ slider("##inlow", "in_low", e.inLow, 0.0f, 1.0f, "In low %.2f");+ slider("##inhigh", "in_high", e.inHigh, 0.0f, 1.0f, "In high %.2f");+ slider("##gamma", "gamma", e.gamma, 0.1f, 4.0f, "Gamma %.2f");+ break;+ case MaskEffectKind::Blur: slider("##radius", "radius", e.radius, 0.0f, 32.0f, "Radius %.0f px"); break;+ case MaskEffectKind::Fill: slider("##value", "value", e.value, 0.0f, 1.0f, "Value %.2f"); break;+ case MaskEffectKind::Paint: ImGui::TextDisabled("%s", tr("Paint on the model with this layer active (Alt erases)")); break;+ default: break;+ }+ ImGui::PopID();+ }+ if (remove >= 0) runCommand("fill_layer", withLayer({{"action", std::string("remove_effect")}, {"effect", double(remove)}}));+ ImGui::SetNextItemWidth(-1);+ if (ImGui::BeginCombo("##addeffect", tr("Add mask effect"))) {+ for (int g = 0; g < kGeneratorKindCount; ++g)+ if (ImGui::Selectable((std::string(generatorLabel(GeneratorKind(g))) + "##gen").c_str()))+ runCommand("fill_layer", withLayer({{"action", std::string("effect")}, {"generator", std::string(generatorId(GeneratorKind(g)))}}));+ for (MaskEffectKind k : {MaskEffectKind::Noise, MaskEffectKind::Paint, MaskEffectKind::Levels, MaskEffectKind::Blur,+ MaskEffectKind::Invert, MaskEffectKind::Fill})+ if (ImGui::Selectable((std::string(maskEffectLabel(k)) + "##kind").c_str()))+ runCommand("fill_layer", withLayer({{"action", std::string("effect")}, {"kind", std::string(maskEffectId(k))}}));+ ImGui::EndCombo();+ }+ ui::HelpText("Add mask effect", nullptr,+ "Add an effect to the bottom of the mask stack. Generators read the Mesh Maps: Edge Wear (convex edges), "+ "Dirt (crevices), Gradient, Thickness (thin parts), Light Direction (surfaces facing up). Noise is in "+ "3D, so it has no UV seams. Paint lets you paint the mask with the Paint brush.",+ kFillPath);+ (void)at;+}++double App::fillTestValue(const std::string& name) const {+ const Mesh& m = doc_.mesh;+ const bool tex = hasTexture(m);+ if (name == "fill_layers") {+ if (!tex) return 0.0;+ double n = 0;+ for (const TextureLayer& l : m.texture->layers) n += l.fill != nullptr;+ return n;+ }+ if (name == "mesh_maps_busy") return meshMapJob_ ? 1.0 : 0.0;+ if (name == "mesh_map_updates") return double(meshMapUpdates_);+ if (name == "mesh_map_update_ms") return lastMeshMapUpdateMs_;+ if (name == "mesh_maps_revision") return tex && m.texture->meshMaps ? double(m.texture->meshMaps->revision) : 0.0;+ if (name == "active_fill_alpha_mean") { // the active Fill layer's mean coverage, 0-255+ if (!tex || !isFillLayer(*m.texture, m.texture->activeLayer)) return 0.0;+ const std::vector<uint8_t>& px = m.texture->layers[size_t(m.texture->activeLayer)].rgba;+ double s = 0;+ for (size_t i = 3; i < px.size(); i += 4) s += px[i];+ return px.empty() ? 0.0 : s / double(px.size() / 4);+ }+ return std::numeric_limits<double>::quiet_NaN();+}++} // namespace sfdiff --git a/src/app/PanelPaintLayers.cpp b/src/app/PanelPaintLayers.cppindex 773947bb..843c2581 100644--- a/src/app/PanelPaintLayers.cpp+++ b/src/app/PanelPaintLayers.cpp@@ -333,6 +333,7 @@ void App::drawPaintLayersContents() {ImGui::EndDisabled();ui::HelpText("Fill", nullptr, "Fill the active layer with the current colour (respects the mask, like Color > Fill).",kPath);+ if (texture) drawFillLayerControls(); // (PanelFill.cpp)}} // namespace sfdiff --git a/src/app/PanelPbr.cpp b/src/app/PanelPbr.cppindex a80baf8d..51314b42 100644--- a/src/app/PanelPbr.cpp+++ b/src/app/PanelPbr.cpp@@ -379,6 +379,7 @@ double App::benchmarkDrawMs(int frames) {}double App::pbrTestValue(const std::string& name) const {+ if (const double v = fillTestValue(name); !std::isnan(v)) return v;const Mesh& m = doc_.mesh;const bool tex = hasTexture(m);if (name == "material_channels") {diff --git a/src/core/MeshMaps.cpp b/src/core/MeshMaps.cppindex 5320ecc1..64878a4e 100644--- a/src/core/MeshMaps.cpp+++ b/src/core/MeshMaps.cpp@@ -607,7 +607,7 @@ void registerMeshMapCommands(CommandRegistry& reg) {"occlusion, curvature, thickness, position, world normal and ID (polygroups). bake makes them, info ""describes them, clear drops them, live=true re-bakes the changed tiles after sculpting (in the app). ""Derived data: not saved, not an undo step.",- {{"action", T::String, "bake (default), info or clear.", false},+ {{"action", T::String, "bake (default), info, clear, or live (with live=true/false).", false},{"maps", T::String, "Comma list: ao, curvature, thickness, position, world_normal, id, or all (default).", false},{"ao_rays", T::Number, "Ambient occlusion rays per texel (default 24).", false},{"ao_distance", T::Number, "How far occluders count, a fraction of the Part's size (default 0.05).", false},@@ -625,7 +625,14 @@ void registerMeshMapCommands(CommandRegistry& reg) {mutableTexture(m).meshMaps.reset();return {true, "Mesh Maps cleared"};}- if (action != "bake") return {false, "action must be bake, info or clear"};+ if (action == "live") {+ if (!tex.meshMaps) return {false, "No Mesh Maps yet (mesh_maps action=bake)"};+ auto set = std::make_shared<MeshMapSet>(*tex.meshMaps);+ set->live = argBool(a, "live", true);+ mutableTexture(m).meshMaps = std::move(set);+ return {true, std::string("Mesh Maps live updates ") + (argBool(a, "live", true) ? "on" : "off")};+ }+ if (action != "bake") return {false, "action must be bake, info, clear or live"};uint32_t kinds = kAllMeshMaps;std::string err;if (a.contains("maps") && !parseMeshMaps(argString(a, "maps"), kinds, err)) return {false, err};diff --git a/tests/ui/fill_layers.sfui b/tests/ui/fill_layers.sfuinew file mode 100644index 00000000..0e05a82f--- /dev/null+++ b/tests/ui/fill_layers.sfui@@ -0,0 +1,60 @@+# Fill layers and Material Recipes (Tool > Paint Layers): a recipe laid on a sculpted Part reads its Mesh Maps+# (baked in the background), the PBR view shows worn metal, a Fill layer's mask effects change from the panel, and+# sculpting re-bakes only the tiles near the stroke (live), so the wear follows the new form.+run new_sphere subdivisions=6+run stroke brush=Crease points="-0.6,0.35,1 0,0.55,1 0.6,0.35,1" radius=0.07 strength=1+run stroke brush=Inflate points="-0.35,-0.3,1" radius=0.3 strength=1+run stroke brush=Clay points="0.25,-0.5,1 0.55,-0.05,1" radius=0.1 strength=1+run stroke brush=Crease invert=true points="-0.75,-0.1,1 -0.45,-0.65,1" radius=0.05 strength=1+run uv_auto resolution=2048+wait_value auto_uv_running == 0 120+run texture_create size=2048+expect_value fill_layers == 0++# A recipe from the Paint Layers panel: four Fill layers; Mesh Maps bake on a worker thread, then they evaluate.+click "Paint Layers##tool.paint_layers"+click "Paint Layers/##recipe"+click "Painted Edges##recipe"+expect_value fill_layers == 3+expect_status "Material Recipe Painted Edges"+wait_value mesh_maps_busy == 0 300+expect_value mesh_maps == 63+expect_value material_channels >= 3+run viewport_shading mode=pbr environment=photo_studio+wait_value environment_pending == 0+camera 20 10+wait 0.3+shot recipe-painted-edges++# The active layer (Corner Dirt) shows its material and mask stack; the level slider is a command.+expect_text "Corner Dirt"+expect "Paint Layers/##addeffect"+remember active_fill_alpha_mean dirt_before+run fill_layer action=effect effect=0 level=0.8+expect_value active_fill_alpha_mean > $dirt_before+shot fill-layer-panel+key ctrl+z+expect_value active_fill_alpha_mean == $dirt_before++# Add a mask effect from the panel's list.+click "Paint Layers/##addeffect"+click "Blur##kind"+expect_status "blur"++# Live: sculpt a new crease; only the nearby tiles are baked again and the fill layers follow.+remember mesh_maps_revision before+key escape+run stroke brush=Crease points="0.2,0.6,1 0.6,0.2,1" radius=0.06 strength=1+wait_value mesh_map_updates >= 1 120+wait_value mesh_maps_busy == 0 120+expect_value mesh_maps_revision > $before+print mesh_map_update_ms+wait 0.3+shot live-after-stroke++# Other recipes, and the command.+run material_recipe name=worn_metal+expect_value fill_layers == 7+run_fails material_recipe name=glitter+run mesh_maps action=live live=false+expect_status "off"