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.

Appended SubTools: sized from the largest visible SubTool, brought into view

islandmed4bd5ff6feb7d
diff --git a/src/app/App.cpp b/src/app/App.cpp
index ae9a9e46..1cf8bd80 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -814,6 +814,9 @@ void App::runCommand(const std::string& name, const Args& args) {
name == "image_relief" || name == "image_inflate" || name == "splat_to_mesh" ||
(name == "splat_transform" && args.contains("fit"))))
camera_.frame(sceneBounds());
+ // A new SubTool lands beside the model: bring it into view only if it isn't already.
+ if (r.ok && (name == "subtool_append" || name == "subtool_duplicate") && !onScreen(doc_.mesh.bounds()))
+ camera_.frame(sceneBounds());
afterCommand(name, args, r);
updateTitle();
}
@@ -884,6 +887,17 @@ void App::saveFileDialog(FileAction action) {
suggestion.empty() ? nullptr : suggestion.c_str());
}
+bool App::onScreen(const AABB& box) const {
+ if (!box.valid()) return true;
+ const glm::mat4 viewProj = camera_.projection() * camera_.view();
+ for (int i = 0; i < 8; ++i) {
+ const glm::vec3 c((i & 1) ? box.max.x : box.min.x, (i & 2) ? box.max.y : box.min.y, (i & 4) ? box.max.z : box.min.z);
+ const glm::vec4 p = viewProj * glm::vec4(c, 1.0f);
+ if (p.w <= 0.0f || std::abs(p.x / p.w) > 0.95f || std::abs(p.y / p.w) > 0.95f) return false;
+ }
+ return true;
+}
+
AABB App::sceneBounds() const {
AABB b = doc_.visibleBounds(); // every SubTool that's shown
if (!b.valid()) b = doc_.mesh.bounds();
diff --git a/src/app/App.h b/src/app/App.h
index 87853e24..3eefa891 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -84,6 +84,7 @@ private:
void openFileDialog();
void saveFileDialog(FileAction action);
AABB sceneBounds() const; // mesh plus the main body of any splats
+ bool onScreen(const AABB& box) const; // whole box inside the viewport
void drawSplatSection();
void processPendingFiles();
diff --git a/src/core/SubTools.cpp b/src/core/SubTools.cpp
index db9bfd20..3683bef1 100644
--- a/src/core/SubTools.cpp
+++ b/src/core/SubTools.cpp
@@ -197,7 +197,7 @@ void registerSubToolCommands(CommandRegistry& reg) {
{{"type", T::String, "'sphere' (default), 'cube' or 'plane'.", false},
{"path", T::String, "Model file to append instead of a primitive (.obj, .glb, .fbx, .ply, .stl, .usd...).", false},
{"name", T::String, "Name for the new SubTool.", false},
- {"size", T::Number, "Primitive size relative to the visible model (0.05-2). Default 0.35.", false}},
+ {"size", T::Number, "Primitive size relative to the largest visible SubTool (0.05-2). Default 0.35.", false}},
[](Document& doc, const Args& a) -> CommandResult {
Mesh m;
std::string name;
@@ -212,8 +212,17 @@ void registerSubToolCommands(CommandRegistry& reg) {
name = fileStem(path);
} else {
const std::string type = argString(a, "type", "sphere");
+ // Sized from the largest visible SubTool (so repeated appends neither grow nor shrink),
+ // placed beside everything shown.
const AABB scene = doc.visibleBounds();
- const float extent = scene.valid() ? std::max({scene.extent().x, scene.extent().y, scene.extent().z}) : 2.0f;
+ float extent = 0.0f;
+ for (int i = 0; i < doc.subtoolCount(); ++i) {
+ const Mesh& sm = doc.subtoolMesh(i);
+ if (!doc.subtools[size_t(i)].visible || !sm.vertexCount()) continue;
+ const glm::vec3 e = sm.bounds().extent();
+ extent = std::max({extent, e.x, e.y, e.z});
+ }
+ if (extent <= 0.0f) extent = 2.0f;
const float size = extent * float(std::clamp(argNumber(a, "size", 0.35), 0.05, 2.0));
if (type == "sphere") m = makeIcosphere(5, size * 0.5f);
else if (type == "cube") m = makeCube(48, size);