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
UV Editor: a pack frames the view on its grid, tile numbers on a dark backing, status says when the grid isn't filled
islandmed1a5b734cc2ec
diff --git a/docs/guide/uv-editor.md b/docs/guide/uv-editor.mdindex 3b6b870d..2949e6c2 100644--- a/docs/guide/uv-editor.md+++ b/docs/guide/uv-editor.md@@ -97,7 +97,8 @@ and keeps whichever holds them larger.**Columns** and **Rows** set the grid of UDIM tiles to fill: Columns along u (1001, 1002 and on; ten make a full UDIMrow) and Rows up v (1011 sits above 1001). **10** Columns x **2** Rows fills 1001-1020; **4** x **3** fills1001-1004, 1011-1014 and 1021-1024 and never goes wider. Every island gets the same texel density: more tiles, more-texels for everything. **Pack at Density** instead keeps exactly the target texel density and opens as many tiles as+texels for everything; the view frames the grid after a pack. When the largest island sets the scale, fewer tiles+than the grid holds get islands, and the status line says how many (Pack at Density fills more). **Pack at Density** instead keeps exactly the target texel density and opens as many tiles asit needs, Columns wide and then the next row up. Projects remember their grid; new ones start from the last one youused.diff --git a/src/app/PanelUvEditor.cpp b/src/app/PanelUvEditor.cppindex c7767780..c5eef092 100644--- a/src/app/PanelUvEditor.cpp+++ b/src/app/PanelUvEditor.cpp@@ -122,6 +122,7 @@ struct UvEditorState {size_t selIslands = 0;float selDensity = 0.0f;glm::ivec2 tiles{1, 1};+ glm::ivec2 frameGrid{0, 0}; // after a pack: frame the view on this grid (Columns x Rows) at the next drawstd::vector<int> tileList;MeshOverlay overlay;// Interaction.@@ -959,6 +960,7 @@ void App::uvPackGridUsed(const Args& a) {}uiPrefs_.uvPackColumns = uvPackColumns_ = columns;uiPrefs_.uvPackRows = uvPackRows_ = rows;+ if (uvEditor_) uvEditor_->frameGrid = {columns, rows};}void App::drawUvEditor() {@@ -1041,6 +1043,10 @@ void App::drawUvEditor() {u.frame(glm::vec2(0.0f), glm::vec2(float(s.tiles.x), float(s.tiles.y)));if (s.zoom <= 0.0f) s.zoom = 400.0f * scale;}+ if (s.frameGrid.x > 0 && !s.dirty) { // (the tiles in use are up to date: a density pack may spill past the rows)+ u.frame(glm::vec2(0.0f), glm::vec2(glm::max(s.frameGrid, s.tiles)));+ s.frameGrid = {0, 0};+ }ImDrawList* dl = ImGui::GetWindowDrawList();ImGui::InvisibleButton("##uvview", viewSize, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight |ImGuiButtonFlags_MouseButtonMiddle);@@ -1151,7 +1157,11 @@ void App::drawUvEditor() {const float pad = 5 * scale;const float x0 = std::max(a.x, viewMin.x) + pad, y0 = std::max(a.y, viewMin.y) + 3 * scale;if (x0 + size.x > std::min(b.x, viewMax.x) - pad || y0 + size.y > std::min(b.y, viewMax.y)) continue;- dl->AddText(ImVec2(x0, y0), used ? IM_COL32(170, 170, 182, 210) : IM_COL32(110, 110, 118, 150), label);+ // Tiles in use: a small dark backing keeps the number readable over the islands.+ if (used)+ dl->AddRectFilled(ImVec2(x0 - 3 * scale, y0 - 1 * scale), ImVec2(x0 + size.x + 3 * scale, y0 + size.y + 1 * scale),+ IM_COL32(14, 14, 17, 205), 3 * scale);+ dl->AddText(ImVec2(x0, y0), used ? IM_COL32(205, 205, 215, 240) : IM_COL32(110, 110, 118, 150), label);}// Trim strips (while the Trim Sheet section is open).if (s.trimOpen) {diff --git a/src/core/UvCommands.cpp b/src/core/UvCommands.cppindex effbf6f1..12da169b 100644--- a/src/core/UvCommands.cpp+++ b/src/core/UvCommands.cpp@@ -69,8 +69,15 @@ UvPackOptions packOptions(const Document& doc, const Args& a) {return o;}-std::string packNote(const UvPackResult& p) {- std::string s = plural(p.islands, "island") + " packed";+// A fit pack that left part of the grid empty says why first (the status line may cut the rest off).+std::string gridNote(const UvPackResult& p, const UvPackOptions& o) {+ if (o.density > 0.0f || o.tiles <= 1 || p.tilesUsed <= 0 || p.tilesUsed >= o.tiles) return {};+ return std::to_string(p.tilesUsed) + " of " + std::to_string(o.tiles) ++ " tiles used: the largest island limits the scale; Pack at Density fills more. ";+}++std::string packNote(const UvPackResult& p, const UvPackOptions& o) {+ std::string s = gridNote(p, o) + plural(p.islands, "island") + " packed";if (p.tilesUsed > 1) s += " into " + std::to_string(p.tilesUsed) + " UDIM tiles";s += ", " + fmt("%.0f", double(p.coverage) * 100.0) + "% of the space used, " + fmt("%.1f", double(p.density)) +" texels per unit";@@ -182,7 +189,7 @@ void registerUvCommands(CommandRegistry& reg) {UvEditStep edit(doc, std::string("Unwrap (") + uvUnwrapMethodLabel(o.method) + ")", argBool(a, "keep_texture", true));m.uvs = std::move(r.uvs);const std::string note = edit.commit();- std::string msg = std::string("Unwrapped (") + uvUnwrapMethodLabel(o.method) + "): " + plural(r.islands, "island");+ std::string msg = (o.faces ? std::string() : gridNote(r.packing, o.packing)) + "Unwrapped (" + uvUnwrapMethodLabel(o.method) + "): " + plural(r.islands, "island");if (r.extraCuts) msg += ", " + plural(r.extraCuts, "edge") + " cut automatically to flatten closed pieces";if (r.packing.tilesUsed > 1) msg += ", " + std::to_string(r.packing.tilesUsed) + " UDIM tiles";const UvStretchStats st = uvStretchStats(m);@@ -214,9 +221,10 @@ void registerUvCommands(CommandRegistry& reg) {UvEditStep edit(doc, "Pack UVs", argBool(a, "keep_texture", true));UvPackResult r;std::string err;- if (!uvPack(m, topo, islands, packOptions(doc, a), r, err)) return {false, err};+ const UvPackOptions po = packOptions(doc, a);+ if (!uvPack(m, topo, islands, po, r, err)) return {false, err};const std::string note = edit.commit();- return {true, packNote(r) + note};+ return {true, packNote(r, po) + note};}});reg.add({"uv_seam",diff --git a/tests/test_uv_editor.cpp b/tests/test_uv_editor.cppindex 9c4bcf69..78c32c71 100644--- a/tests/test_uv_editor.cpp+++ b/tests/test_uv_editor.cpp@@ -323,6 +323,14 @@ TEST(uv_pack_udim_grid_columns_by_rows) {r = run(doc, "uv_pack", {{"columns", 1.0}, {"density", 900.0}, {"resolution", 1024.0}, {"first_tile", 1091.0}});CHECK(!r.ok && r.message.find("Columns") != std::string::npos);+ // A fit pack that can't fill the grid says so first; a full one doesn't.+ doc = makeDoc(squares(3));+ r = run(doc, "uv_pack", {{"columns", 10.0}, {"rows", 2.0}});+ CHECK(r.ok && r.message.rfind("3 of 20 tiles used: the largest island limits the scale", 0) == 0);+ doc = makeDoc(squares(4));+ r = run(doc, "uv_pack", {{"columns", 2.0}, {"rows", 2.0}});+ CHECK(r.ok && r.message.find("tiles used") == std::string::npos);+// Scripts' tiles= alone is as before: ten per row.doc = makeDoc(squares(12));CHECK(run(doc, "uv_pack", {{"tiles", 12.0}}).ok);diff --git a/tests/ui/uv_editor.sfui b/tests/ui/uv_editor.sfuiindex 169b64b0..2c0576ae 100644--- a/tests/ui/uv_editor.sfui+++ b/tests/ui/uv_editor.sfui@@ -62,8 +62,8 @@ expect_value uv_tiles > 4expect_value uv_tiles <= 20expect_value uv_pack_columns == 10expect_value uv_pack_rows == 2-hover_window 0.45 0.5-key f+expect_status "of 20 tiles used: the largest island limits the scale"+# (the pack frames the view on the 10 x 2 grid)shot udim-10x2run uv_pack columns=4 rows=3 margin=6expect_value uv_tiles > 4@@ -72,8 +72,6 @@ expect_value uv_max_u <= 4remember uv_tiles gridexpect_value uv_pack_columns == 4expect_value uv_pack_rows == 3-hover_window 0.45 0.5-key fshot udim-4x3# The Pack button packs with the fields: still 4 x 3.click "UV Editor/Pack##uv.pack"