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
Tool > Geometry > Micro: the micro level slider, Divide to Micro, Bake / Delete Micro, Export Displacement
islandmed31ab457d30da
diff --git a/src/app/App.h b/src/app/App.hindex fffafe32..fc049d92 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -880,6 +880,7 @@ private:void drawGeometrySection(); // PanelGeometry.cpp: Divide, SDiv, Lower / Higher Res, Del Lower / Higher, Reconstructbool smt_ = true; // Tool > Geometry > Smt: Divide smoothsfloat sdivSlider_ = 1.0f; // the SDiv slider while dragged (1-based)+ float microSlider_ = 4.0f; // Tool > Geometry > Micro: the micro level the next Divide to micro makesbool sdivHeld_ = false;void drawSubToolsContents();// PanelExtract.cpp: Tool > SubTool > Extract, Tool > Geometry > Modify Topology (Mirror And Weld) anddiff --git a/src/app/Config.cpp b/src/app/Config.cppindex ac6e7afe..aa26c392 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -10,6 +10,8 @@#include "app/App.h"#include "app/CrashLog.h"#include "app/Ui.h"+#include "core/Bake.h"+#include "core/Micro.h"#include "core/Multires.h"#include "core/Script.h"@@ -271,6 +273,26 @@ void App::initActions() {[this] { return subdivCurrentLevel(doc_.mesh) + 1 < subdivLevelCount(doc_.mesh); });add("geometry.reconstruct", "Reconstruct Subdiv", "Tool > Geometry", nullptr, [this] { runCommand("subdiv_reconstruct"); },nullptr, "subdiv_reconstruct", nullptr, [this] { return subdivCurrentLevel(doc_.mesh) == 0; });+ // Micro-displacement levels (Tool > Geometry > Micro; core/Micro.h).+ add("geometry.micro_divide", "Divide to Micro", "Tool > Geometry", nullptr,+ [this] { runCommand("micro_divide", {{"level", double(microSlider_)}}); }, ICON_LC_GRID_3X3, "micro_divide", nullptr,+ [this] { return !hasMicro(doc_.mesh) && subdivCurrentLevel(doc_.mesh) + 1 >= subdivLevelCount(doc_.mesh); },+ "Store the surface above the highest level as micro displacements: hundreds of millions of sculptable "+ "triangles in a fraction of the memory (300M take about 0.4 GB). The Micro slider sets how fine.");+ add("geometry.micro_delete", "Delete Micro", "Tool > Geometry", nullptr, [this] { runCommand("micro_delete"); }, nullptr,+ "micro_delete", nullptr, [this] { return hasMicro(doc_.mesh); });+ add("geometry.micro_bake", "Bake Micro", "Tool > Geometry", nullptr, [this] { runCommand("micro_bake"); }, nullptr, "micro_bake",+ nullptr, [this] { return hasMicro(doc_.mesh); },+ "Turn the micro level into a regular mesh in a new SubTool (for export or tools that need real geometry).");+ add("geometry.micro_export", "Export Displacement", "Tool > Geometry", nullptr,+ [this] {+ const std::string path = (std::filesystem::path(defaultBakeFolder(doc_)) / (doc_.assetName() + "_micro_displacement.exr")).string();+ runCommand("micro_export_displacement", {{"path", path}});+ },+ nullptr, "micro_export_displacement", nullptr, [this] { return hasMicro(doc_.mesh) && doc_.mesh.hasUvs(); },+ "Write the micro level as a 32-bit EXR displacement map over the base UVs (next to the project).");+ add("geometry.micro_noise", "Micro Surface Noise", "Tool > Geometry", nullptr, [this] { runCommand("micro_noise"); }, nullptr,+ "micro_noise", nullptr, [this] { return hasMicro(doc_.mesh); });// Tool > SubTool > Extract, Tool > Geometry > Modify Topology, Tool > Deformation (PanelExtract.cpp).add("subtool.extract", "Extract", "Tool > SubTool", nullptr, [this] { runExtract(); }, nullptr, "extract", nullptr,[this] { return doc_.mesh.hasMask(); },diff --git a/src/app/PanelGeometry.cpp b/src/app/PanelGeometry.cppindex 3b478e7f..9ae0a903 100644--- a/src/app/PanelGeometry.cpp+++ b/src/app/PanelGeometry.cpp@@ -6,6 +6,7 @@#include "app/App.h"#include "app/Ui.h"+#include "core/Micro.h"#include "core/Multires.h"#include <algorithm>@@ -62,6 +63,42 @@ void App::drawGeometrySection() {} else {ImGui::TextDisabled("No subdivision levels - Divide adds them");}++ // Micro: displacement levels above the highest level (core/Micro.h).+ ImGui::Spacing();+ const bool micro = hasMicro(m);+ if (micro) microSlider_ = float(microLevel(m));+ ImGui::BeginDisabled(micro);+ ImGui::SetNextItemWidth(-1);+ {+ const size_t est = m.triangleCount() << (2 * int(microSlider_));+ char fmt[64];+ std::snprintf(fmt, sizeof fmt, "Micro %%.0f (%.0fM)", double(est) / 1e6);+ ui::SliderInside("##micro", µSlider_, 1.0f, float(MicroMesh::kMaxLevel), fmt, ImGuiSliderFlags_AlwaysClamp);+ microSlider_ = std::round(microSlider_);+ }+ ImGui::EndDisabled();+ ui::HelpText("Micro", nullptr,+ "Micro levels above the highest subdivision level: each 4x the triangles, stored as one 16-bit "+ "displacement per point (no mesh), so 300 million triangles take about 0.4 GB and sculpt in real time. "+ "Move reshapes the level below and the detail rides along.",+ "Tool > Geometry");+ if (!micro) {+ ui::ActionButton(*this, "geometry.micro_divide", ImVec2(-1, 0));+ } else {+ ui::ActionButton(*this, "geometry.micro_bake", ImVec2(half, 0));+ ImGui::SameLine();+ ui::ActionButton(*this, "geometry.micro_delete", ImVec2(half, 0));+ ui::ActionButton(*this, "geometry.micro_export", ImVec2(-1, 0));+ ImGui::Checkbox("Move along normals", &doc_.sculptor.microMoveAlongNormals);+ }+ if (micro && m.micro) { // (a button above may have just removed it)+ const MicroMesh& mm = *m.micro;+ char info[128];+ std::snprintf(info, sizeof info, "Micro %d: %.1fM triangles, %.0f MB%s", mm.level, double(mm.microTriangles()) / 1e6,+ double(mm.bytes()) / 1e6, mm.disp.mapped() ? ", out of core" : "");+ ImGui::TextDisabled("%s", info);+ }ImGui::Separator();}diff --git a/tests/ui/micro_levels.sfui b/tests/ui/micro_levels.sfuinew file mode 100644index 00000000..29d88c0d--- /dev/null+++ b/tests/ui/micro_levels.sfui@@ -0,0 +1,29 @@+# Micro-displacement levels (Tool > Geometry > Micro): Divide to Micro stores the surface above the highest level+# as displacement grids, the viewport draws it, Standard and Move sculpt it, undo steps back, Delete Micro removes it.+run new_sphere subdivisions=5+orbit 30 -15+click "Geometry##tool.geometry"+expect "Geometry/Divide to Micro"+click "Geometry/Divide to Micro"+expect_status "Divided to micro"+expect "Geometry/Bake Micro"+expect_text "Micro 4"+run micro_noise amplitude=0.003 scale=40+shot micro-noise++# Standard (B S T) on the micro surface.+key b+key s+key t+stroke 0.3 0.4 0.7 0.45+stroke 0.35 0.55 0.65 0.6+shot micro-strokes+key ctrl+z+key ctrl+z+expect_status "Undo"++# Delete Micro takes it away; undo brings it back.+click "Geometry/Delete Micro"+expect "Geometry/Divide to Micro"+key ctrl+z+expect "Geometry/Bake Micro"