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
Floor grid: the floor under the model, never over it (input review)
islandmede145fbbdfb10
diff --git a/changes/feat-floor-grid.md b/changes/feat-floor-grid.mdindex de6cd9f5..1f3d518a 100644--- a/changes/feat-floor-grid.md+++ b/changes/feat-floor-grid.md@@ -1,13 +1,15 @@----whats_new: **Floor grid**: **View > Floor grid** draws a faint grid on the floor through the world origin, for grounding,+whats_new: **Floor grid**: **View > Floor grid** draws a faint grid on the floor the model stands on, for grounding,perspective and lining up Parts. Off by default.added: **Floor grid** (#115, **View > Floor grid**, also **Tool > Display** and the command palette): a faint grid on the- ground plane through the world origin (Y up), X and Z axes marked, squares stepping by ten with the zoom and fading- into the distance. Off by default; remembered in the preferences. Suggested by @fenixpoints.+ floor under the model (its lowest point, Y up; it moves when a stroke or a move ends), the X and Z axes through the+ origin marked, squares stepping by ten with the zoom and fading into the distance. It never draws over the model.+ Off by default; remembered in the preferences. Suggested by @fenixpoints.testers:- Windows at 150% scaling: View > Floor grid; orbit and zoom out and in: the lines stay thin and smooth, the squares- step without popping, no shimmering near the horizon.- - Any OS: File > New Plane with the grid on: the plane covers the grid, no flicker. Restart: the grid is still on.+ step without popping, no shimmering near the horizon, and the sphere stands on the grid.+ - Any OS: sculpt a long stroke down past the bottom of the model: the floor moves once the stroke ends, not during+ it. Orbit below the floor: the model shows whole, the grid only around it. Restart: the grid is still on.----The grid sits at the world origin (y = 0), not at the model's lowest point: stable while sculpting, and it is the-plane exports line up to (#115 asks "where the model sits relative to the origin").+The floor follows the lowest point of the visible Parts (measured when the history or the Parts change, not during a+stroke or a drag); it is drawn before the Parts, so it never covers mesh pixels. Coordinator review 11-06.diff --git a/docs/guide/navigation.md b/docs/guide/navigation.mdindex 0c4b2bb2..9a2689a8 100644--- a/docs/guide/navigation.md+++ b/docs/guide/navigation.md@@ -80,9 +80,10 @@ press <kbd>Shift</kbd>+<kbd>L</kbd> to turn it off while you rotate, or turn on<kbd>Ctrl</kbd>+<kbd>Shift</kbd> hide and show shapes work as before.**Floor grid** (**View > Floor grid**, also **Tool > Display**; off by default, remembered) draws a faint grid on-the floor through the world origin, with the up axis (Y) standing on it: it shows where the model stands, helps-judge perspective and tilt, and lines up Parts before an export. The red line is the X axis, the blue one Z. The-squares step up by ten as you zoom out, and the grid fades into the distance; the model always draws in front of it.+the floor the model stands on: its lowest point, with the up axis (Y) standing on it. It helps judge perspective and+tilt and line up Parts; the red line is the X axis, the blue one Z. The floor moves when a stroke or a move ends (not+during it). The squares step up by ten as you zoom out, and the grid fades into the distance; it never draws over+the model, even seen from below."Background" means any part of the canvas where the cursor isn't over the model. A left-drag that starts onthe model sculpts instead, so with a pen or a one-button mouse, start rotations beside the model. When thediff --git a/src/app/App.cpp b/src/app/App.cppindex d07cbc89..a49ede12 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -4,6 +4,7 @@#include "app/Pickers.h"#include "app/BrandMark.h"#include "io/BridgeProtocol.h"+#include "core/ThreadPool.h"#include "core/LayerStack.h"#include "core/HardwareProfile.h"#include "app/ShellQuote.h"@@ -2744,6 +2745,43 @@ AABB App::sceneBounds() const {return b;}+void App::updateFloorHeight() {+ if (!renderSettings_.floorGrid) {+ floorKey_ = 0; // (measured again when it is turned on)+ return;+ }+ if (renderSettings_.stroking || drag_ != Drag::None) return; // after the stroke or the drag, not during it+ // What the lowest point depends on: every Part's history, size and visibility (each history's revision moves+ // with every step, undo and redo; the size and the list catch a new or opened scene).+ uint64_t key = 1469598103934665603ull;+ auto mix = [&key](uint64_t v) { key = (key ^ v) * 1099511628211ull; };+ mix(uint64_t(doc_.activePart));+ mix(doc_.undo.revision());+ for (int i = 0; i < doc_.partCount(); ++i) {+ const Part& p = doc_.parts[size_t(i)];+ mix(p.id);+ mix(p.visible);+ mix(p.undo.revision());+ mix(doc_.partMesh(i).vertexCount());+ }+ if (key == floorKey_) return;+ floorKey_ = key;+ float lowest = std::numeric_limits<float>::max();+ for (int i = 0; i < doc_.partCount(); ++i) {+ if (!doc_.parts[size_t(i)].visible) continue;+ const auto& positions = doc_.partMesh(i).positions;+ const size_t block = 1 << 16;+ std::vector<float> low((positions.size() + block - 1) / block, std::numeric_limits<float>::max());+ poolFor(positions.size(), [&](size_t b, size_t e) {+ float m = std::numeric_limits<float>::max();+ for (size_t v = b; v < e; ++v) m = std::min(m, positions[v].y);+ low[b / block] = m;+ }, block);+ for (float m : low) lowest = std::min(lowest, m);+ }+ renderSettings_.floorHeight = lowest == std::numeric_limits<float>::max() ? 0.0f : lowest; // (no Part: the origin)+}+void App::processPendingFiles() {pollPackDialogs(); // Install Pack, New Pack's save and a macro's "?" files (PanelPacks.cpp)std::vector<PendingFile> files;@@ -2809,6 +2847,7 @@ Mesh& App::displayedMesh() {void App::syncScene() {if (solverBusy()) return; // the solver thread is changing the mesh: the GPU keeps what it has (AsyncStroke.cpp)+ updateFloorHeight();// 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)diff --git a/src/app/App.h b/src/app/App.hindex f4c643c6..ba5d0abd 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -210,6 +210,11 @@ private:void openFileDialog();void saveFileDialog(FileAction action);AABB sceneBounds() const; // mesh plus the main body of any splats+ // Floor grid (#115): keeps RenderSettings::floorHeight at the lowest point of the visible Parts. Measured again+ // only when the history, the Parts or their visibility changed and no stroke or drag is running (so the floor+ // doesn't follow each dab); App.cpp.+ void updateFloorHeight();+ uint64_t floorKey_ = 0;bool onScreen(const AABB& box) const; // whole box inside the viewportvoid processPendingFiles();diff --git a/src/app/I18nSimplifiedChinese.cpp b/src/app/I18nSimplifiedChinese.cppindex 5f28ad19..b8f4874a 100644--- a/src/app/I18nSimplifiedChinese.cpp+++ b/src/app/I18nSimplifiedChinese.cpp@@ -1481,10 +1481,11 @@ constexpr Entry kSimplifiedChinese[] = {{"Cut", "切割"},{"Selection Sets", "选择集"},{"Floor grid", "地面网格"},- {"A faint grid on the floor through the world origin (Y up), fading into the distance: where the model stands, "- "and a reference for perspective and lining up Parts. Off by default; saved automatically.",- "一个穿过世界原点(Y 轴向上)的淡淡地面网格,向远处渐隐:显示模型站在哪里,也是判断透视和对齐部件的参考。默认关闭;"- "自动保存。"},+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "+ "a stroke or a move ends. Off by default; saved automatically.",+ "模型所站立地面上的淡淡网格(位于模型最低点,Y 轴向上),向远处渐隐:用作透视和对齐部件的参考;红线和蓝线是 X 轴和 "+ "Z 轴。笔触或移动结束时更新位置。默认关闭;自动保存。"},{"Backface culling", "背面剔除"},{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes ""(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "diff --git a/src/app/I18nSpanish.cpp b/src/app/I18nSpanish.cppindex 29b96cc4..b6a93060 100644--- a/src/app/I18nSpanish.cpp+++ b/src/app/I18nSpanish.cpp@@ -1710,11 +1710,13 @@ constexpr Entry kSpanish[] = {{"Cut", "Cortar"},{"Selection Sets", "Conjuntos de selección"},{"Floor grid", "Cuadrícula del suelo"},- {"A faint grid on the floor through the world origin (Y up), fading into the distance: where the model stands, "- "and a reference for perspective and lining up Parts. Off by default; saved automatically.",- "Una cuadrícula tenue en el suelo, por el origen del mundo (Y hacia arriba), que se desvanece a lo "- "lejos: dónde se apoya el modelo, y una referencia para la perspectiva y para alinear Piezas. Desactivada por "- "defecto; se guarda automáticamente."},+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "+ "a stroke or a move ends. Off by default; saved automatically.",+ "Una cuadrícula tenue en el suelo sobre el que se apoya el modelo (su punto más bajo, Y hacia arriba), que "+ "se desvanece a lo lejos: una referencia para la perspectiva y para alinear Piezas; las líneas roja y azul "+ "son los ejes X y Z. Se mueve al terminar un trazo o un movimiento. Desactivada por defecto; se guarda "+ "automáticamente."},{"Backface culling", "Ocultar caras traseras"},{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes ""(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "diff --git a/src/app/I18nTraditionalChinese.cpp b/src/app/I18nTraditionalChinese.cppindex 1695d24e..27d5a635 100644--- a/src/app/I18nTraditionalChinese.cpp+++ b/src/app/I18nTraditionalChinese.cpp@@ -1481,10 +1481,11 @@ constexpr Entry kTraditionalChinese[] = {{"Cut", "切割"},{"Selection Sets", "選取集"},{"Floor grid", "地面網格"},- {"A faint grid on the floor through the world origin (Y up), fading into the distance: where the model stands, "- "and a reference for perspective and lining up Parts. Off by default; saved automatically.",- "一個穿過世界原點(Y 軸向上)的淡淡地面網格,向遠處漸隱:顯示模型站在哪裡,也是判斷透視和對齊部件的參考。預設關閉;"- "自動儲存。"},+ {"A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "+ "a stroke or a move ends. Off by default; saved automatically.",+ "模型所站立地面上的淡淡網格(位於模型最低點,Y 軸向上),向遠處漸隱:用作透視和對齊部件的參考;紅線和藍線是 X 軸和 "+ "Z 軸。筆觸或移動結束時更新位置。預設關閉;自動儲存。"},{"Backface culling", "背面剔除"},{"Don't draw the back faces of the model: faster on dense meshes, and you see through the openings of open meshes ""(a scan, a garment) instead of their inside. Brushes then work only on faces you can see. Off by default; "diff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex ce34cd08..b36be0ce 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -528,8 +528,9 @@ void App::registerShellActions() {actions_.add(std::move(a));}add({"view.floor_grid", "Floor grid", ICON_LC_GRID_2X2,- "A faint grid on the floor through the world origin (Y up), fading into the distance: where the model "- "stands, and a reference for perspective and lining up Parts. Off by default; saved automatically.",+ "A faint grid on the floor the model stands on (its lowest point, Y up), fading into the distance: a "+ "reference for perspective and lining up Parts; the red and blue lines are the X and Z axes. It moves when "+ "a stroke or a move ends. Off by default; saved automatically.","Render", "", "", [this] { uiPrefs_.floorGrid = renderSettings_.floorGrid = !renderSettings_.floorGrid; },[this] { return renderSettings_.floorGrid; }, nullptr});flag("view.vertexpaint", "Paint", ICON_LC_PALETTE, "Render", "", &renderSettings_.showVertexPaint,diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex bedadb34..bd6a2529 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -115,7 +115,7 @@// tablet_mouse_mode (Preferences > Tablet > Mouse mode),// ui_mouse_x / ui_mouse_y (where ImGui sees the pointer), backface_culling, drawn_triangles,// floor_grid (View > Display > Floor grid), floor_grid_drawn (the 3D view drawn once more-// now: 1 if it drew the grid),+// now: 1 if it drew the grid), floor_height (the floor's y),// viewport_cursor (the system cursor: 0 arrow, 1 text, 7 hand, 100 crosshair; #73),// panel_drag_scrolls (left / middle drags that scrolled a panel, #100), panel_drag_scroll_y,// drag_cursor (the same, at the end of the last button_drag, before letting go; #88),@@ -1093,6 +1093,7 @@ double Demo::query(const std::string& name, bool& known) const {}if (name == "backface_culling") return app_.renderSettings_.backfaceCulling ? 1.0 : 0.0;if (name == "floor_grid") return app_.renderSettings_.floorGrid ? 1.0 : 0.0;+ if (name == "floor_height") return double(app_.renderSettings_.floorHeight); // (the visible Parts' lowest point)if (name == "floor_grid_drawn") { // the 3D view drawn once more now: 1 if it drew the floor gridapp_.benchmarkDrawMs(0);return app_.renderer_.floorGridDrawn() ? 1.0 : 0.0;diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex d13aa335..bea54786 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -706,19 +706,20 @@ void main() {})";-// The floor grid (#115, View > Display > Floor grid): one quad on the ground plane y = 0 around the eye, its lines-// drawn in the fragment shader. Three levels of 10x steps, the finest fading out as the view zooms out (uBlend) so a-// zoom never pops; cells under a few pixels fade too (no moire at grazing angles), and all of it fades with the-// distance from the eye. X (red) and Z (blue) mark the origin.+// The floor grid (#115, View > Floor grid): one quad on the floor (y = RenderSettings::floorHeight) around the eye,+// its lines drawn in the fragment shader. Three levels of 10x steps, the finest fading out as the view zooms out+// (uBlend) so a zoom never pops; cells under a few pixels fade too (no moire at grazing angles), and all of it fades+// with the distance from the eye. X (red) and Z (blue) mark the axes through the origin.const char* kFloorVS = R"(#version 330 coreuniform mat4 uView;uniform mat4 uProj;uniform vec2 uCentre;uniform float uHalf;+uniform float uFloor;out vec3 vWorld;void main() {vec2 c = vec2(gl_VertexID & 1, gl_VertexID >> 1) * 2.0 - 1.0;- vWorld = vec3(uCentre.x + c.x * uHalf, 0.0, uCentre.y + c.y * uHalf);+ vWorld = vec3(uCentre.x + c.x * uHalf, uFloor, uCentre.y + c.y * uHalf);gl_Position = uProj * (uView * vec4(vWorld, 1.0));})";@@ -3045,8 +3046,8 @@ void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, congl::Enable(GL_DEPTH_TEST);gl::DepthFunc(GL_LEQUAL);floorGridDrawn_ = false;+ if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings); // (under everything: the Parts paint over it)if (drawList_.empty() || !settings.showMesh) {- if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings);if (settings.showSplats) drawSplats(view, proj, fbWidth, fbHeight, settings.splatOpacity);gl::UseProgram(0);return;@@ -3074,7 +3075,6 @@ void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, conif (const MeshSlot* s = findSlot(item.id); s && s->drawnTriangles > 0 && !seeThrough(item))drawSlot(*s, item.active, item.flat, settings);drawMark(2);- if (settings.floorGrid) drawFloorGrid(camera, view, proj, settings); // (over the opaque Parts, under X-Ray's)if (xray) {gl::Enable(GL_BLEND);gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);@@ -3267,9 +3267,9 @@ void Renderer::cullCoarse(const MeshSlot& s, const CullView& frame, size_t budge// Draws `clusters` of `s` (the VAO for `part` bound): their triangles, the wireframe's edges, or their motion// proxies. One multi-draw, or with per-triangle data on a driver whose gl_VertexID lacks the base vertex, one// draw per cluster with its first drawn triangle in `primBaseLocation`.-// The floor grid (#115): over the opaque Parts (depth tested, never written, pushed a little behind a surface on the-// plane itself), under see-through ones. Its cell is a power of ten of the zoom: 0.1 at the default view of a new-// model, 1 from ten times further out.+// The floor grid (#115): drawn right after the background, before any Part, with no depth: every Part (and splat)+// paints over it, so it never shows on the model, from above or below. Its cell is a power of ten of the zoom: 0.1+// at the default view of a new model, 1 from ten times further out.void Renderer::drawFloorGrid(const Camera& camera, const glm::mat4& view, const glm::mat4& proj,const RenderSettings& settings) {if (thumbnailPass_) return;@@ -3283,7 +3283,7 @@ void Renderer::drawFloorGrid(const Camera& camera, const glm::mat4& view, const}const glm::vec3 eye = glm::vec3(glm::inverse(view)[3]);const float zoom = std::log10(std::max(camera.distance, 1e-4f)) - 0.3f, level = std::floor(zoom);- const float fade = std::max(camera.distance * 6.0f, std::abs(eye.y) * 2.0f);+ const float fade = std::max(camera.distance * 6.0f, std::abs(eye.y - settings.floorHeight) * 2.0f);// Lines a little lighter than a dark background, darker than a light one.const glm::vec3 bg = settings.gradientBackground ? settings.gradientCentre : settings.backgroundColor;const float luma = glm::dot(bg, glm::vec3(0.2126f, 0.7152f, 0.0722f));@@ -3294,23 +3294,20 @@ void Renderer::drawFloorGrid(const Camera& camera, const glm::mat4& view, constgl::UniformMatrix4fv(at("uProj"), 1, GL_FALSE, glm::value_ptr(proj));gl::Uniform2f(at("uCentre"), eye.x, eye.z);gl::Uniform1f(at("uHalf"), fade);+ gl::Uniform1f(at("uFloor"), settings.floorHeight);gl::Uniform3fv(at("uEye"), 1, glm::value_ptr(eye));gl::Uniform1f(at("uStep"), std::pow(10.0f, level - 1.0f));gl::Uniform1f(at("uBlend"), zoom - level);gl::Uniform1f(at("uFade"), fade);gl::Uniform3fv(at("uLine"), 1, glm::value_ptr(line));gl::BindVertexArray(emptyVao_);- gl::Enable(GL_DEPTH_TEST);- gl::DepthMask(GL_FALSE);+ gl::Disable(GL_DEPTH_TEST);gl::Enable(GL_BLEND);gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);gl::Disable(GL_CULL_FACE);- gl::Enable(GL_POLYGON_OFFSET_FILL);- gl::PolygonOffset(2.0f, 2.0f); // (the Parts draw at 1, 1: a plane mesh at y = 0 stays in front)gl::DrawArrays(GL_TRIANGLE_STRIP, 0, 4);- gl::PolygonOffset(1.0f, 1.0f);gl::Disable(GL_BLEND);- gl::DepthMask(GL_TRUE);+ gl::Enable(GL_DEPTH_TEST);floorGridDrawn_ = true;}diff --git a/src/render/Renderer.h b/src/render/Renderer.hindex 24477467..52296170 100644--- a/src/render/Renderer.h+++ b/src/render/Renderer.h@@ -49,9 +49,11 @@ struct RenderSettings {// Backface culling (#68, Tool > Display): back faces are never drawn, on any mesh (closed or not, from any// view). Off: they are skipped only where they can't show (a closed mesh seen from outside, Renderer::cull).bool backfaceCulling = false;- // Floor grid (#115, View > Display): a faint grid on the ground plane through the world origin (y = 0, Y up),- // fading with distance. Off by default.+ // Floor grid (#115, View > Floor grid): a faint grid on the floor under the model (y = floorHeight, Y up; the+ // app keeps it at the lowest point of the visible Parts), its X and Z axes through the origin, fading with+ // distance. Drawn under every Part. Off by default.bool floorGrid = false;+ float floorHeight = 0.0f;// The view's background: the charcoal radial gradient (default) or one flat display (sRGB) colour (#21).bool gradientBackground = true;glm::vec3 backgroundColor{0.168f, 0.168f, 0.168f};diff --git a/tests/ui/floor_grid.sfui b/tests/ui/floor_grid.sfuiindex afe014a5..7cbf5176 100644--- a/tests/ui/floor_grid.sfui+++ b/tests/ui/floor_grid.sfui@@ -1,5 +1,6 @@-# Floor grid (#115): View > Display > Floor grid (also Tool > Display and the command palette) draws a faint grid on-# the ground plane through the world origin (y = 0), fading into the distance. Off by default; a preference.+# Floor grid (#115): View > Floor grid (also Tool > Display and the command palette) draws a faint grid on the floor+# the model stands on (the lowest point of the visible Parts, Y up), the X and Z axes through the origin marked,+# fading into the distance. It is drawn before the Parts, so it never shows on the model. Off by default; a preference.run ui_look look=forge layout=sculptforgerun new_sphere subdivisions=4camera 30 -20@@ -18,6 +19,9 @@ key escapewait 0.3shot onexpect_value floor_grid_drawn == 1+# The starter sphere (centred on the origin) stands on the grid: the floor is at its bottom, not through its middle.+expect_value floor_height < -0.9+remember floor_height sphere_floor# The grid adds none of the model's triangles (it draws one quad of its own).expect_value drawn_triangles == $sphere_tris@@ -30,17 +34,50 @@ wait 0.3shot farkey fwait 0.3-# From below the floor the grid draws over what is above it (a ceiling seen through), still faint.-camera 30 20+# From below the floor the whole model still shows: the grid only around it, never over it.+camera 30 25wait 0.3shot below-# A plane on the floor itself stays in front of the grid.+# A model moved below the origin: the floor follows once the move ends.+camera 30 -20+run transform translate=0,-3,0 masked=false+key f+camera 30 -20+wait 0.3+expect_value floor_height < -3.9+shot below-origin+key ctrl+z+key f+wait 0.3+expect_value floor_height == $sphere_floor++# A gizmo drag: the floor stays put during the drag and moves when it ends.+key w+gizmo_drag move_y 0 70 keep+wait 0.2+expect_value floor_height == $sphere_floor+release+wait 0.3+expect_value floor_height < -1.1+key ctrl+z+key w+expect_value gizmo_mode == 0+wait 0.3++# A plane: the floor is the plane itself, which covers the grid.run new_plane resolution=32camera 20 -25wait 0.3shot plane+# A real model at an angle.+run open path=$SCRIPT_DIR/../data/marble-bust.glb+key f+camera 35 -15+wait 0.5+shot bust+# HiDPI: the lines stay one pixel wide (they're drawn per pixel, not scaled).run new_sphere subdivisions=4camera 30 -20