Skip to content

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.

UV Editor: Pack fields show the grid a pack used; tile numbers stay whole at the view's edge

islandmede9bc26b5fcd4
diff --git a/src/app/App.h b/src/app/App.h
index 234f2775..b7e00c57 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -942,12 +942,14 @@ private:
bool uvEditorBusy() const;
// UI test values: uv_editor_open, uv_islands, uv_seams, uv_selected, uv_select_mode, uv_pins, uv_tiles,
// uv_stretch_x1000, uv_flipped_x1000, uv_density, uv_max_u, uv_unwrapping, uv_unwraps, uv_tool,
- // uv_view_triangles, uv_overlay; NaN for other names.
+ // uv_view_triangles, uv_overlay, uv_pack_columns, uv_pack_rows (the Pack fields); 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;
+ // After uv_pack / uv_unwrap from anywhere (the panel, a script, the console): the fields show the grid it used.
+ void uvPackGridUsed(const Args& args);
bool showUvEditor_ = false;
void startAutoUv();
void startNewTexture(); // New Texture on the top shelf / Color palette: Auto UV first when there are no UVs
diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cpp
index fb3c788d..ab598e9a 100644
--- a/src/app/PanelProject.cpp
+++ b/src/app/PanelProject.cpp
@@ -582,6 +582,7 @@ void App::applyProjectSettings() {
void App::afterCommand(const std::string& name, const Args& args, const CommandResult& r) {
if (!r.ok) return;
if (name == "undo" || name == "redo") gizmoAfterUndo(name == "redo");
+ if (name == "uv_pack" || name == "uv_unwrap") uvPackGridUsed(args);
const std::string path = argString(args, "path", doc_.path);
const bool project = name == "open_project" || (name == "open" && isProjectPath(path));
if (project) {
diff --git a/src/app/PanelUvEditor.cpp b/src/app/PanelUvEditor.cpp
index ec68cada..c7767780 100644
--- a/src/app/PanelUvEditor.cpp
+++ b/src/app/PanelUvEditor.cpp
@@ -945,6 +945,22 @@ const MeshOverlay* App::uvEditorOverlay(uint32_t part) {
return &uvEditor_->overlay;
}
+void App::uvPackGridUsed(const Args& a) {
+ int columns = 0, rows = 0;
+ if (a.contains("columns") || a.contains("rows")) { // (as UvCommands.cpp's packOptions reads them)
+ columns = std::clamp(int(argNumber(a, "columns", 10)), 1, 10);
+ if (a.contains("rows")) rows = std::clamp(int(argNumber(a, "rows", 1)), 1, 10);
+ else rows = std::clamp((std::clamp(int(argNumber(a, "tiles", columns)), 1, 100) + columns - 1) / columns, 1, 10);
+ } else {
+ // tiles= alone fills ten per row: the same grid when it's under a row or whole rows; otherwise left as is.
+ const int tiles = std::clamp(int(argNumber(a, "tiles", 1)), 1, 100);
+ if (tiles > 10 && tiles % 10) return;
+ columns = std::min(tiles, 10), rows = (tiles + 9) / 10;
+ }
+ uiPrefs_.uvPackColumns = uvPackColumns_ = columns;
+ uiPrefs_.uvPackRows = uvPackRows_ = rows;
+}
+
void App::drawUvEditor() {
if (!showUvEditor_) {
if (uvEditor_ && uvEditor_->tool) uvEditor_->tool = 0;
@@ -1125,11 +1141,17 @@ void App::drawUvEditor() {
// UDIM tile numbers.
for (int ty = 0; ty < std::max(s.tiles.y, 1) + 1; ++ty)
for (int tx = 0; tx < std::min(std::max(s.tiles.x, 1) + 1, 10); ++tx) {
- const ImVec2 p = u.toScreen(glm::vec2(float(tx), float(ty) + 1.0f));
const bool used = tx < s.tiles.x && ty < s.tiles.y;
char label[8];
std::snprintf(label, sizeof label, "%d", 1001 + tx + 10 * ty);
- dl->AddText(ImVec2(p.x + 5 * scale, p.y + 3 * scale), used ? IM_COL32(170, 170, 182, 210) : IM_COL32(110, 110, 118, 150), label);
+ // In the tile's top-left corner, kept inside the tile and the view (a tile at the edge still shows its
+ // number whole); none when the visible part of the tile is too small for it.
+ const ImVec2 a = u.toScreen(glm::vec2(float(tx), float(ty) + 1.0f)), b = u.toScreen(glm::vec2(float(tx) + 1.0f, float(ty)));
+ const ImVec2 size = ImGui::CalcTextSize(label);
+ 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);
}
// Trim strips (while the Trim Sheet section is open).
if (s.trimOpen) {
@@ -1576,6 +1598,8 @@ double App::uvEditorTestValue(const std::string& name) {
if (name == "uv_select_mode") return double(int(doc_.uvSelection.mode));
if (name == "uv_unwrapping") return uvEditor_ && uvEditor_->job ? 1.0 : 0.0;
if (name == "uv_unwraps") return uvEditor_ ? double(uvEditor_->unwraps) : 0.0;
+ if (name == "uv_pack_columns") return double(uvPackColumns_); // the Pack fields
+ if (name == "uv_pack_rows") return double(uvPackRows_);
if (name == "uv_frame_ms") return uvEditor_ ? uvEditor_->frameMs : 0.0;
if (name == "uv_tool") return uvEditor_ ? double(uvEditor_->tool) : 0.0;
if (name == "uv_view_triangles") return uvEditor_ ? double(uvEditor_->gpu.triangles()) : 0.0;
diff --git a/tests/ui/uv_editor.sfui b/tests/ui/uv_editor.sfui
index 4aae926f..de3dacd8 100644
--- a/tests/ui/uv_editor.sfui
+++ b/tests/ui/uv_editor.sfui
@@ -53,16 +53,30 @@ expect_value uv_tiles == 2
hover_window 0.45 0.5
key f
shot udim
-# A Columns x Rows grid (#135): the panel's sliders, then 2 x 2 fills 1001, 1002, 1011, 1012.
+# A Columns x Rows grid (#135): the Pack fields show the grid a pack used, from the panel or a script.
expect "UV Editor/##uvcolumns"
expect "UV Editor/##uvrows"
-run uv_pack columns=2 rows=2 margin=6
-expect_value uv_tiles == 4
+run uv_pack columns=10 rows=2 margin=6
+expect_value uv_tiles == 20
+expect_value uv_pack_columns == 10
+expect_value uv_pack_rows == 2
hover_window 0.45 0.5
key f
-shot udim-grid
+shot udim-10x2
+run uv_pack columns=4 rows=3 margin=6
+expect_value uv_tiles == 12
+expect_value uv_pack_columns == 4
+expect_value uv_pack_rows == 3
+hover_window 0.45 0.5
+key f
+shot udim-4x3
+# The Pack button packs with the fields: still 4 x 3.
+click "UV Editor/Pack##uv.pack"
+expect_value uv_tiles == 12
run uv_pack tiles=1
expect_value uv_tiles == 1
+expect_value uv_pack_columns == 1
+expect_value uv_pack_rows == 1
# Texel density: every island to 400 texels per unit at 2K.
run uv_density op=set value=400