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 > Pack: Columns x Rows UDIM grid (#135)
islandmed3ed613b1b1c3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c405e6e2..e98c4f5b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,12 @@ All notable changes to SculptForge are listed here. The format follows## [Unreleased]+### Changed+- **UV Editor > Pack: Columns x Rows** (#135, thanks RodTDai): the UDIM Tiles slider is now a **Columns** (1-10) and+ **Rows** (1-10) grid, so a 10 x 2 layout fills 1001-1020 and 4 x 3 stays four tiles wide. Pack at Density spills+ within the Columns too. Projects keep their grid; new ones take the last one used. Scripts: `uv_pack` and+ `uv_unwrap` take `columns=` and `rows=` (`tiles=` works as before).+## [0.11.1] - 2026-11-05### Addeddiff --git a/docs/guide/uv-editor.md b/docs/guide/uv-editor.mdindex 0d7348de..3b6b870d 100644--- a/docs/guide/uv-editor.md+++ b/docs/guide/uv-editor.md@@ -94,9 +94,15 @@ texel density (**Equal density**; off keeps their sizes relative to each other),them. **Rotate** also allows quarter turns. SculptForge tries packing by the islands' outlines and by their boxesand keeps whichever holds them larger.-**UDIM Tiles** spreads the islands over that many tiles, 1001, 1002 and on (ten per row, as UDIM numbers go), each-island at 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 it needs.+**Columns** and **Rows** set the grid of UDIM tiles to fill: Columns along u (1001, 1002 and on; ten make a full UDIM+row) and Rows up v (1011 sits above 1001). **10** Columns x **2** Rows fills 1001-1020; **4** x **3** fills+1001-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+it needs, Columns wide and then the next row up. Projects remember their grid; new ones start from the last one you+used.++Baking writes one set of maps per tile, rows included (`name_normal.1011.png`, see [Baking](baking.md)). Texture+painting still covers tile 1001 only.@@ -160,8 +166,8 @@ commands work on the whole Part.| Command | What it does || --- | --- |-| `uv_unwrap` | Unwrap: `method=isometric` (Least Stretch), `conformal`, `facegroups` (By Face Groups), `planar`, `unfold` or `auto`; `iterations=`, `selected=`, `tiles=`, `margin=`, `rotate=`, `density=`, `pack=false` (fit in place), `keep_texture=` |-| `uv_pack` | Pack: `margin=` (texels), `tiles=` (UDIM tiles), `first_tile=`, `rotate=`, `equal_density=`, `density=` (texels per unit, as many tiles as needed), `resolution=`, `keep_texture=` |+| `uv_unwrap` | Unwrap: `method=isometric` (Least Stretch), `conformal`, `facegroups` (By Face Groups), `planar`, `unfold` or `auto`; `iterations=`, `selected=`, `tiles=`, `columns=`, `rows=`, `margin=`, `rotate=`, `density=`, `pack=false` (fit in place), `keep_texture=` |+| `uv_pack` | Pack: `margin=` (texels), `columns=` and `rows=` (the UDIM grid, e.g. `columns=10 rows=2` for 1001-1020), `tiles=` (UDIM tiles, ten per row), `first_tile=`, `rotate=`, `equal_density=`, `density=` (texels per unit, as many tiles as needed), `resolution=`, `keep_texture=` || `uv_seam` | Seams: `op=mark` / `clear` (the selection), `path from= to=` (shortest edge path between two vertices; `clear=true`), `facegroups`, `islands`, `angle angle=60`, `clear_all` || `uv_select` | `op=all`, `none`, `invert`, `island face=`, `face face=`, `facegroup group=`, `rect u0= v0= u1= v1=`, `seams`, `mode`; `mode=vertex/edge/face/island`, `add=true` || `uv_transform` | `move_u=`, `move_v=`, `rotate=` (degrees), `scale=`, `scale_u=`, `scale_v=` about the selection's centre |diff --git a/src/app/App.h b/src/app/App.hindex 01277bcc..234f2775 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -945,6 +945,9 @@ private:// uv_view_triangles, uv_overlay; NaN for other names.double uvEditorTestValue(const std::string& name);std::shared_ptr<struct UvEditorState> uvEditor_;+ // UV Editor > Pack: the UDIM grid to fill, Columns x Rows (#135). Projects keep their own; new ones and+ // projects from before take the preference (UiPrefs::uvPackColumns / uvPackRows), which the sliders set too.+ int uvPackColumns_ = 1, uvPackRows_ = 1;bool showUvEditor_ = false;void startAutoUv();void startNewTexture(); // New Texture on the top shelf / Color palette: Auto UV first when there are no UVsdiff --git a/src/app/Config.cpp b/src/app/Config.cppindex 908f63f4..c408ab69 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -131,6 +131,8 @@ Json toJson(const UiPrefs& p) {j.set("flatShading", p.flatShading);j.set("viewportCursor", double(p.viewportCursor));j.set("backfaceCulling", p.backfaceCulling);+ j.set("uvPackColumns", double(p.uvPackColumns));+ j.set("uvPackRows", double(p.uvPackRows));j.set("background", std::string(p.gradientBackground ? "gradient" : "flat"));Json bg = Json::array();for (int i = 0; i < 3; ++i) bg.push(double(p.backgroundColor[i]));@@ -218,6 +220,8 @@ void fromJson(const Json& j, UiPrefs& p) {p.flatShading = j["flatShading"].asBool(p.flatShading);p.viewportCursor = std::clamp(int(j["viewportCursor"].asNumber(p.viewportCursor)), 0, 1);p.backfaceCulling = j["backfaceCulling"].asBool(p.backfaceCulling);+ p.uvPackColumns = std::clamp(int(j["uvPackColumns"].asNumber(p.uvPackColumns)), 1, 10);+ p.uvPackRows = std::clamp(int(j["uvPackRows"].asNumber(p.uvPackRows)), 1, 10);if (j["background"].isString()) p.gradientBackground = j["background"].asString() != "flat";p.showHints = j["showHints"].asBool(p.showHints);if (const Json& hints = j["hiddenHints"]; hints.size() > 0) {@@ -1008,6 +1012,7 @@ bool App::readUiConfig(const std::string& path, std::string& err, bool own) {doc_.sculptor.dyntopo.smoothRemesh = uiPrefs_.dyntopoSmoothRemesh;renderSettings_.flatShading = uiPrefs_.flatShading;renderSettings_.backfaceCulling = uiPrefs_.backfaceCulling;+ uvPackColumns_ = uiPrefs_.uvPackColumns, uvPackRows_ = uiPrefs_.uvPackRows;renderSettings_.gradientBackground = uiPrefs_.gradientBackground;renderSettings_.backgroundColor = uiPrefs_.backgroundColor;return true;diff --git a/src/app/Config.h b/src/app/Config.hindex 56cbb335..62933fd2 100644--- a/src/app/Config.h+++ b/src/app/Config.h@@ -90,6 +90,8 @@ struct UiPrefs {// Tool > Display > Backface culling (#68): skip the back faces of every Part (faster on dense meshes; see// through open meshes). Off by default; a preference, projects keep their own.bool backfaceCulling = false;+ // UV Editor > Pack > Columns x Rows (#135): the UDIM grid the last pack filled, the default for new projects.+ int uvPackColumns = 1, uvPackRows = 1;TabletSettings tablet; // Preferences > Tablet: pressure curve, eraser, pen buttonsSpaceMouseSettings spaceMouse; // Preferences > Input > SpaceMouse// Preferences > Performance (PanelPerformance.cpp).diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cppindex 8fe517cd..fb3c788d 100644--- a/src/app/PanelProject.cpp+++ b/src/app/PanelProject.cpp@@ -408,6 +408,11 @@ void App::storeProjectSettings() {gizmo.set("all_parts", gizmo_.all);gizmo.set("falloff", double(gizmo_.falloff));s.set("gizmo", std::move(gizmo));++ Json uv = Json::object(); // UV Editor > Pack: the UDIM grid (#135)+ uv.set("pack_columns", double(uvPackColumns_));+ uv.set("pack_rows", double(uvPackRows_));+ s.set("uv_editor", std::move(uv));}// Lenient: anything missing keeps its current value.@@ -568,6 +573,10 @@ void App::applyProjectSettings() {gizmo_.undoSteps.clear();gizmo_.redoSteps.clear();}+ // Projects from before the grid: the preference.+ const Json& uv = s["uv_editor"];+ uvPackColumns_ = std::clamp(int(uv["pack_columns"].asNumber(uiPrefs_.uvPackColumns)), 1, 10);+ uvPackRows_ = std::clamp(int(uv["pack_rows"].asNumber(uiPrefs_.uvPackRows)), 1, 10);}void App::afterCommand(const std::string& name, const Args& args, const CommandResult& r) {diff --git a/src/app/PanelUvEditor.cpp b/src/app/PanelUvEditor.cppindex 7893dbdf..ec68cada 100644--- a/src/app/PanelUvEditor.cpp+++ b/src/app/PanelUvEditor.cpp@@ -140,7 +140,6 @@ struct UvEditorState {int method = 0; // kMethodsint iterations = 10;float marginPx = 8.0f;- int packTiles = 1;bool rotate = true;bool equalDensity = true;float targetDensity = 512.0f;@@ -605,7 +604,8 @@ struct UvEditorUi {Args packArgs() {Args a{{"margin", double(s.marginPx)},- {"tiles", double(s.packTiles)},+ {"columns", double(app.uvPackColumns_)},+ {"rows", double(app.uvPackRows_)},{"rotate", s.rotate},{"equal_density", s.equalDensity},{"resolution", double(resolution())},@@ -655,7 +655,8 @@ struct UvEditorUi {o.pack = method != UvUnwrapMethod::Unfold;o.packing.resolution = resolution();o.packing.marginPx = s.marginPx;- o.packing.tiles = s.packTiles;+ o.packing.columns = app.uvPackColumns_;+ o.packing.tiles = app.uvPackColumns_ * app.uvPackRows_;o.packing.rotate = s.rotate;o.packing.equalDensity = s.equalDensity;std::promise<bool> promise;@@ -835,8 +836,8 @@ void App::registerUvEditorActions() {"uv_unwrap");add("uv.pack", "Pack", ICON_LC_PACKAGE, "", [this] { uvUi(*this, uvEditor_).run("uv_pack", uvUi(*this, uvEditor_).packArgs()); },nullptr, uvs,- "Pack the selected islands (or all) as large as they fit into the 0-1 tile, or across the chosen number of UDIM "- "tiles: turned to their smallest box, scaled to one texel density, with the margin between them.",+ "Pack the selected islands (or all) as large as they fit into the 0-1 tile, or across the Columns x Rows grid "+ "of UDIM tiles: turned to their smallest box, scaled to one texel density, with the margin between them.","uv_pack");add("uv.seam_mark", "Mark Seam", ICON_LC_SCISSORS, "", [runUv] { runUv("uv_seam", {{"op", std::string("mark")}}); }, nullptr,selected, "Mark the selected edges (or the border of the selected faces) as seams: Unwrap cuts there.", "uv_seam");@@ -911,8 +912,8 @@ void App::registerUvEditorActions() {u.run("uv_pack", a);},nullptr, uvs,- "Pack at exactly the target texel density, using as many UDIM tiles as it takes (1001, 1002, ...): every island "- "keeps the same texels per unit across the tiles.",+ "Pack at exactly the target texel density, using as many UDIM tiles as it takes (1001, 1002, ..., Columns "+ "wide, then the next row up): every island keeps the same texels per unit across the tiles.","uv_pack");add("uv.trim", "Assign to Strip", ICON_LC_STRETCH_HORIZONTAL, "",[this, runUv] {@@ -1283,10 +1284,19 @@ void App::drawUvEditor() {ImGui::SetNextItemWidth(w);ui::SliderInside("##uvmargin", &s.marginPx, 0.0f, 64.0f, "Margin %.0f px");ui::HelpText("Margin", nullptr, "Texels kept free between islands (half of it at the tile borders), at the texture's size.", kPath);- float tiles = float(s.packTiles);- ImGui::SetNextItemWidth(w);- if (ui::SliderInside("##uvtiles", &tiles, 1.0f, 10.0f, "UDIM Tiles %.0f")) s.packTiles = int(std::round(tiles));- ui::HelpText("UDIM tiles", nullptr, "Pack across this many tiles (1001 onwards, along u): more tiles, more texels per island.", kPath);+ // The UDIM grid (#135): Columns along u (UDIM's row is ten wide), Rows up v; 10 x 2 fills 1001-1020.+ float columns = float(uvPackColumns_), rows = float(uvPackRows_);+ ImGui::SetNextItemWidth(halfW);+ if (ui::SliderInside("##uvcolumns", &columns, 1.0f, 10.0f, "Columns %.0f"))+ uiPrefs_.uvPackColumns = uvPackColumns_ = std::clamp(int(std::round(columns)), 1, 10);+ ui::HelpText("Columns", nullptr, "UDIM tiles across (along u, 1001 onwards; ten make a full UDIM row). Packing fills "+ "Columns x Rows tiles and never goes wider, also when it packs at a fixed texel density.", kPath);+ ImGui::SameLine();+ ImGui::SetNextItemWidth(halfW);+ if (ui::SliderInside("##uvrows", &rows, 1.0f, 10.0f, "Rows %.0f"))+ uiPrefs_.uvPackRows = uvPackRows_ = std::clamp(int(std::round(rows)), 1, 10);+ ui::HelpText("Rows", nullptr, "UDIM rows up (along v: 1011 sits above 1001). 10 Columns x 2 Rows fills 1001-1020; "+ "more tiles, more texels per island.", kPath);ui::Checkbox("Rotate##uvrot", &s.rotate);ui::HelpText("Rotate", nullptr, "Turn islands to their smallest box and allow quarter turns, so more fit.", kPath);ImGui::SameLine();diff --git a/src/core/Uv.h b/src/core/Uv.hindex 44433caa..b113e816 100644--- a/src/core/Uv.h+++ b/src/core/Uv.h@@ -181,11 +181,19 @@ struct UvPackOptions {float marginPx = 8.0f; // texels between islands (and half of it at tile borders)bool rotate = true; // turn islands to their smallest bounding box and allow 90-degree turnsint tiles = 1; // UDIM tiles to fill (1001, 1002, ... ten per row); ignored with `density`+ int columns = 0; // > 0: a grid this wide (1-10; UDIM's row is ten) from firstTile: tile k goes to+ // column k % columns of row k / columns (1001 + column + 10 row), with `density`+ // too. 0: UDIM order from firstTile, ten per row (as before the grid)bool equalDensity = true; // scale islands to one texel density first (off: keep their relative sizes)float density = 0.0f; // > 0: keep exactly this texel density (texels per unit) and use as many tiles as- // it takes (up to 100) instead of fitting `tiles`- int firstTile = 1001; // where packing starts+ // it takes (up to uvPackMaxTiles) instead of fitting `tiles`+ int firstTile = 1001; // where packing starts (the grid's bottom-left tile)};+// The UDIM tile number of the `k`th tile (from 0) a pack with `options` fills.+int uvPackTile(const UvPackOptions& options, int k);+// How many tiles a pack with `options` may fill at most: the grid's columns x the rows from firstTile up+// (without columns, the tiles from firstTile to 1100).+int uvPackMaxTiles(const UvPackOptions& options);struct UvPackResult {size_t islands = 0;int tilesUsed = 0;diff --git a/src/core/UvCommands.cpp b/src/core/UvCommands.cppindex 320aa29c..effbf6f1 100644--- a/src/core/UvCommands.cpp+++ b/src/core/UvCommands.cpp@@ -57,6 +57,12 @@ UvPackOptions packOptions(const Document& doc, const Args& a) {o.marginPx = float(std::clamp(argNumber(a, "margin", 8.0), 0.0, 256.0));o.rotate = argBool(a, "rotate", true);o.tiles = std::clamp(int(argNumber(a, "tiles", 1)), 1, 100);+ // A Columns x Rows grid (the UV Editor's Pack target): `columns` wide, `rows` high (or `tiles` in that width).+ if (a.contains("columns") || a.contains("rows")) {+ o.columns = std::clamp(int(argNumber(a, "columns", 10)), 1, 10);+ if (a.contains("rows")) o.tiles = o.columns * std::clamp(int(argNumber(a, "rows", 1)), 1, 10);+ else if (!a.contains("tiles")) o.tiles = o.columns;+ }o.equalDensity = argBool(a, "equal_density", true);o.density = float(std::max(argNumber(a, "density", 0.0), 0.0));o.firstTile = std::clamp(int(argNumber(a, "first_tile", 1001)), 1001, 1100);@@ -141,6 +147,8 @@ void registerUvCommands(CommandRegistry& reg) {{"resolution", T::Number, "Texture size the margin is measured in (default: the texture's, or 2048)", false},{"margin", T::Number, "Texels between packed islands (default 8)", false},{"tiles", T::Number, "UDIM tiles to pack across (default 1)", false},+ {"columns", T::Number, "Pack into a grid this many tiles wide (1-10; with rows, columns x rows tiles)", false},+ {"rows", T::Number, "Rows of the grid (1-10): fills columns x rows tiles", false},{"rotate", T::Bool, "Turn islands to fit better when packing (default true)", false},{"density", T::Number, "Pack at exactly this texel density (texels per unit; uses as many tiles as needed)", false},{"pack", T::Bool, "Pack the result (default true; false fits each island where its old UVs were)", false},@@ -190,7 +198,10 @@ void registerUvCommands(CommandRegistry& reg) {{{"margin", T::Number, "Texels between islands (default 8)", false},{"resolution", T::Number, "Texture size the margin and density are measured in (default: the texture's, or 2048)", false},{"rotate", T::Bool, "Turn islands to fit better (default true)", false},- {"tiles", T::Number, "UDIM tiles to fill, 1001 onwards (default 1)", false},+ {"tiles", T::Number, "UDIM tiles to fill, 1001 onwards, ten per row (default 1)", false},+ {"columns", T::Number, "Fill a grid this many tiles wide (1-10): 1001 + column + 10 x row, never past it; "+ "with density, the spill stays in it too", false},+ {"rows", T::Number, "Rows of the grid (1-10): fills columns x rows tiles (e.g. columns=10 rows=2: 1001-1020)", false},{"first_tile", T::Number, "The UDIM tile to start at (default 1001)", false},{"equal_density", T::Bool, "Scale islands to one texel density first (default true; false keeps their sizes relative)", false},{"density", T::Number, "Keep exactly this texel density (texels per unit) and spill into more tiles", false},diff --git a/src/core/UvPack.cpp b/src/core/UvPack.cppindex f96514e4..859ed5ec 100644--- a/src/core/UvPack.cpp+++ b/src/core/UvPack.cpp@@ -134,12 +134,12 @@ bool packByShape(Mesh& m, const UvTopology& topo, const std::vector<uint32_t>& lxatlas::PackCharts(atlas.get(), po);return atlas->meshCount == 1 ? int(std::max(atlas->atlasCount, 1u)) : 0;};- const int tiles = std::clamp(o.tiles, 1, 100);+ const int maxTiles = uvPackMaxTiles(o), tiles = std::clamp(o.tiles, 1, maxTiles);float density = o.density;int used = 0;if (density > 0.0f) {used = pack(density, res);- if (used == 0 || used > 100) return false;+ if (used == 0 || used > maxTiles) return false;} else {// Bisection at a quarter of the resolution (fast), then the full pack, a little smaller until it fits.const int lowRes = std::max(res / 4, 256);@@ -160,7 +160,6 @@ bool packByShape(Mesh& m, const UvTopology& topo, const std::vector<uint32_t>& l}const xatlas::Mesh& out = atlas->meshes[0];if (out.indexCount != idx.size()) return false;- const int first = std::max(o.firstTile, 1001) - 1001;const float inv = 1.0f / float(res);// Only where xatlas put each island is taken: the move (and scale) that best maps the island onto its packed// copy is applied to the island's own UVs, so its shape stays exactly as it was.@@ -173,8 +172,7 @@ bool packByShape(Mesh& m, const UvTopology& topo, const std::vector<uint32_t>& lstd::vector<glm::vec2> placed(out.indexCount);for (uint32_t i = 0; i < out.indexCount; ++i) {const xatlas::Vertex& v = out.vertexArray[out.indexArray[i]];- const int t = first + std::max(v.atlasIndex, 0);- placed[i] = glm::vec2(float(t % 10), float(t / 10)) + glm::vec2(v.uv[0], v.uv[1]) * inv;+ placed[i] = udimOrigin(uvPackTile(o, std::max(v.atlasIndex, 0))) + glm::vec2(v.uv[0], v.uv[1]) * inv;}for (size_t b = 0; b < idx.size();) {size_t e = b;@@ -209,6 +207,19 @@ bool packByShape(Mesh& m, const UvTopology& topo, const std::vector<uint32_t>& l} // namespace+int uvPackTile(const UvPackOptions& o, int k) {+ const int first = std::clamp(o.firstTile, 1001, 1100) - 1001;+ if (o.columns <= 0) return 1001 + first + k;+ const int columns = std::min(o.columns, 10 - first % 10);+ return 1001 + first + k % columns + 10 * (k / columns);+}++int uvPackMaxTiles(const UvPackOptions& o) {+ const int first = std::clamp(o.firstTile, 1001, 1100) - 1001;+ if (o.columns <= 0) return 100 - first;+ return std::min(o.columns, 10 - first % 10) * (10 - first / 10);+}+int packRectangles(const std::vector<glm::vec2>& sizes, int maxTiles, bool allowTurn, float border,std::vector<glm::vec2>& positions, std::vector<uint8_t>& turned, std::vector<int>& tile) {const size_t n = sizes.size();@@ -348,14 +359,16 @@ bool uvPack(Mesh& m, const UvTopology& topo, const std::vector<uint8_t>& islandsint used = 0;if (o.density > 0.0f) {scale = o.density / float(res); // UV units per surface unit- used = tryScale(scale, 100);+ const int maxTiles = uvPackMaxTiles(o);+ used = tryScale(scale, maxTiles);if (!used) {if (useShapes()) return true;- error = "At that texel density an island is bigger than a tile (or it needs over 100 tiles): lower it";+ error = "At that texel density an island is bigger than a tile (or it needs over " + std::to_string(maxTiles) ++ " tiles): lower it" + std::string(o.columns > 0 ? " or use more Columns" : "");return false;}} else {- const int tiles = std::clamp(o.tiles, 1, 100);+ const int tiles = std::clamp(o.tiles, 1, uvPackMaxTiles(o));double boxes = 0.0;for (const Piece& pc : pieces) boxes += double(pc.size.x * pc.k) * double(pc.size.y * pc.k);if (boxes <= 0.0) {@@ -385,15 +398,12 @@ bool uvPack(Mesh& m, const UvTopology& topo, const std::vector<uint8_t>& islandsused = tryScale(scale, tiles);}// Place: rotate, scale, move into the box (inset by half the margin), then into its tile.- const int columns = 10;- const int first = std::max(o.firstTile, 1001) - 1001;poolFor(n, [&](size_t b, size_t e) {for (size_t p = b; p < e; ++p) {const uint32_t i = list[p];const Piece& pc = pieces[p];const float ca = std::cos(pc.angle), sa = std::sin(pc.angle), k = pc.k * scale;- const int t = first + tileOf[p];- const glm::vec2 origin(float(t % columns), float(t / columns));+ const glm::vec2 origin = udimOrigin(uvPackTile(o, tileOf[p]));const glm::vec2 box = pc.size * k;for (uint32_t c = offsets[i]; c < offsets[i + 1]; ++c) {glm::vec2 q = (rotate(m.uvs[corners[c]], ca, sa) - pc.lo) * k;diff --git a/tests/test_mesh_maps.cpp b/tests/test_mesh_maps.cppindex 1a18a360..36dac57b 100644--- a/tests/test_mesh_maps.cpp+++ b/tests/test_mesh_maps.cpp@@ -11,6 +11,7 @@#include "core/Multires.h"#include "core/Primitives.h"#include "core/Texture.h"+#include "core/Uv.h"#include <chrono>#include <cmath>@@ -228,6 +229,53 @@ TEST(nightly_mesh_maps_live_update_is_faster_than_a_full_bake) {CHECK(live < full * 0.5);}+TEST(bake_udim_grid_ten_by_two) {+ // #135: twenty squares packed into a 10 x 2 UDIM grid bake as tiles 1001-1020 (the second row too), each+ // tile's own island; texture painting skips the tiles past 1001 rather than wrapping them in.+ Mesh low;+ for (int i = 0; i < 20; ++i) {+ const uint32_t b = uint32_t(low.positions.size());+ const float x = 2.0f * float(i);+ low.positions.insert(low.positions.end(), {{x, 0, 0}, {x + 1, 0, 0}, {x + 1, 0, -1}, {x, 0, -1}});+ low.triangles.push_back({b, b + 1, b + 2});+ low.triangles.push_back({b, b + 2, b + 3});+ low.uvs.insert(low.uvs.end(), {{0, 0}, {1, 0}, {1, 1}, {0, 0}, {1, 1}, {0, 1}});+ }+ low.recomputeAllNormals();+ UvPackOptions po;+ po.columns = 10;+ po.tiles = 20;+ po.resolution = 64;+ UvPackResult pr;+ std::string err;+ CHECK(uvPack(low, buildUvTopology(low), {}, po, pr, err));+ CHECK(pr.tilesUsed == 20);+ std::vector<int> want;+ for (int t = 1001; t <= 1020; ++t) want.push_back(t);+ CHECK(udimTiles(low) == want);+ Mesh high = low;+ for (glm::vec3& p : high.positions) p.y = 0.01f * std::sin(p.x * 9.0f);+ high.recomputeAllNormals();+ BakeSettings st;+ st.size = 32;+ st.maps = bakeBit(BakeMap::Normal);+ std::vector<BakeResult> results;+ CHECK(bakeMapsUdim(low, {&high}, st, results, err));+ CHECK(results.size() == 20);+ for (size_t k = 0; k < results.size(); ++k) {+ CHECK(results[k].udim == want[k]);+ CHECK(results[k].islandTexels > 300); // (one square nearly fills its 32 x 32 tile)+ }+ // Paint: only tile 1001's triangles reach the texture.+ int tx0, ty0, tx1, ty1, reach = 0;+ for (uint32_t t = 0; t < low.triangleCount(); ++t)+ if (triangleTiles(low, 256, 256, t, tx0, ty0, tx1, ty1)) {+ ++reach;+ CHECK(udimTile((low.uvs[t * 3] + low.uvs[t * 3 + 1] + low.uvs[t * 3 + 2]) / 3.0f) == 1001);+ }+ CHECK(reach == 2);+}+TEST(bake_new_maps_udim_tiles_and_levels) {// A plane with its right half moved to UDIM tile 1002.Mesh low = makePlane(16);diff --git a/tests/test_uv_editor.cpp b/tests/test_uv_editor.cppindex 6a843cb7..9c4bcf69 100644--- a/tests/test_uv_editor.cpp+++ b/tests/test_uv_editor.cpp@@ -67,6 +67,29 @@ CommandResult run(Document& doc, const char* name, Args args = {}) {return reg.execute(doc, name, args);}+// `n` separate unit squares in a row (one UV island each, its UVs 0-1).+Mesh squares(int n) {+ Mesh m;+ for (int i = 0; i < n; ++i) {+ const uint32_t b = uint32_t(m.positions.size());+ const float x = 2.0f * float(i);+ m.positions.insert(m.positions.end(), {{x, 0, 0}, {x + 1, 0, 0}, {x + 1, 0, -1}, {x, 0, -1}});+ m.triangles.push_back({b, b + 1, b + 2});+ m.triangles.push_back({b, b + 2, b + 3});+ m.uvs.insert(m.uvs.end(), {{0, 0}, {1, 0}, {1, 1}, {0, 0}, {1, 1}, {0, 1}});+ }+ m.recomputeAllNormals();+ return m;+}++std::vector<int> usedTiles(const Mesh& m) {+ std::vector<int> tiles;+ for (uint32_t t = 0; t < m.triangleCount(); ++t) tiles.push_back(udimTile((m.uvs[t * 3] + m.uvs[t * 3 + 1] + m.uvs[t * 3 + 2]) / 3.0f));+ std::sort(tiles.begin(), tiles.end());+ tiles.erase(std::unique(tiles.begin(), tiles.end()), tiles.end());+ return tiles;+}+} // namespaceTEST(uv_corner_twins_on_a_plane) {@@ -259,6 +282,53 @@ TEST(uv_pack_one_tile_and_udim_tiles) {CHECK(islandBoxesDisjoint(doc.mesh, -15.0f / 1024.0f)); // boxes at least ~15 texels apart}+TEST(uv_pack_udim_grid_columns_by_rows) {+ // #135: the tile order of a Columns x Rows grid, and without columns UDIM order from first_tile as before.+ UvPackOptions o;+ o.columns = 4;+ CHECK(uvPackTile(o, 0) == 1001 && uvPackTile(o, 3) == 1004 && uvPackTile(o, 4) == 1011 && uvPackTile(o, 11) == 1024);+ CHECK(uvPackMaxTiles(o) == 40);+ o.firstTile = 1008; // (only three columns are left in the row)+ CHECK(uvPackTile(o, 2) == 1010 && uvPackTile(o, 3) == 1018 && uvPackMaxTiles(o) == 30);+ o.columns = 0;+ CHECK(uvPackTile(o, 3) == 1011 && uvPackMaxTiles(o) == 93);++ // 10 x 2: twenty squares, one to a tile, fill 1001-1020.+ Document doc = makeDoc(squares(20));+ CommandResult r = run(doc, "uv_pack", {{"columns", 10.0}, {"rows", 2.0}, {"margin", 4.0}});+ CHECK(r.ok);+ CHECK(r.message.find("20 UDIM tiles") != std::string::npos);+ std::vector<int> want;+ for (int t = 1001; t <= 1020; ++t) want.push_back(t);+ CHECK(usedTiles(doc.mesh) == want);+ CHECK(uvsWithin(doc.mesh, glm::vec2(0.0f), glm::vec2(10.0f, 2.0f)));+ CHECK(islandBoxesDisjoint(doc.mesh));++ // 4 x 3 stays four wide: 1001-1004, 1011-1014, 1021-1024.+ doc = makeDoc(squares(12));+ CHECK(run(doc, "uv_pack", {{"columns", 4.0}, {"rows", 3.0}}).ok);+ CHECK(usedTiles(doc.mesh) == std::vector<int>({1001, 1002, 1003, 1004, 1011, 1012, 1013, 1014, 1021, 1022, 1023, 1024}));+ CHECK(uvsWithin(doc.mesh, glm::vec2(0.0f), glm::vec2(4.0f, 3.0f)));++ // A fixed texel density spills up rows, never past the columns: 12 tiles' worth at 3 wide.+ doc = makeDoc(squares(12));+ r = run(doc, "uv_pack", {{"columns", 3.0}, {"rows", 1.0}, {"density", 900.0}, {"resolution", 1024.0}, {"margin", 4.0}});+ CHECK(r.ok);+ const std::vector<int> spill = usedTiles(doc.mesh);+ CHECK(spill.size() == 12);+ for (int t : spill) CHECK((t - 1001) % 10 < 3);+ CHECK(std::abs(uvMeshDensity(doc.mesh, 1024) - 900.0f) < 9.0f);+ // More than the grid holds: an error that names Columns.+ doc = makeDoc(squares(12));+ 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);++ // Scripts' tiles= alone is as before: ten per row.+ doc = makeDoc(squares(12));+ CHECK(run(doc, "uv_pack", {{"tiles", 12.0}}).ok);+ CHECK(usedTiles(doc.mesh).back() == 1012);+}+TEST(uv_pack_rectangles) {// Sixteen quarter-tile squares fill one tile; a seventeenth needs a second; an oversized one never fits.std::vector<glm::vec2> sizes(16, glm::vec2(0.25f)), pos;diff --git a/tests/ui/uv_editor.sfui b/tests/ui/uv_editor.sfuiindex 589a1b40..4aae926f 100644--- a/tests/ui/uv_editor.sfui+++ b/tests/ui/uv_editor.sfui@@ -53,6 +53,14 @@ expect_value uv_tiles == 2hover_window 0.45 0.5key fshot udim+# A Columns x Rows grid (#135): the panel's sliders, then 2 x 2 fills 1001, 1002, 1011, 1012.+expect "UV Editor/##uvcolumns"+expect "UV Editor/##uvrows"+run uv_pack columns=2 rows=2 margin=6+expect_value uv_tiles == 4+hover_window 0.45 0.5+key f+shot udim-gridrun uv_pack tiles=1expect_value uv_tiles == 1