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.

Live mode: ask before a scene-replacing command when there are unsaved changes; brush names by our own

islandmed5c0fd9a36cde
diff --git a/src/app/PanelAiLink.cpp b/src/app/PanelAiLink.cpp
index f930d36d..72ac6465 100644
--- a/src/app/PanelAiLink.cpp
+++ b/src/app/PanelAiLink.cpp
@@ -92,7 +92,7 @@ Json liveTools() {
"(0,0 = top left, 1,1 = bottom right), projected onto the model (points off the model are skipped). Use "
"viewport_image to see where things are. One undo step.",
{{"points", schemaProp("string", "\"u,v u,v ...\" in 0..1 viewport coordinates (at least one on the model).")},
- {"brush", schemaProp("string", "Brush name (Standard, Clay, Clay Buildup, Crease, Inflate, Smooth, Pinch...). Default: the active brush.")},
+ {"brush", schemaProp("string", "Brush name (Standard, Clay, Clay Block, Crease, Inflate, Smooth, Pinch...). Default: the active brush.")},
{"radius", schemaProp("number", "Brush radius as a fraction of the viewport's height (default 0.04).")},
{"strength", schemaProp("number", "0-1 (default 0.5).")},
{"invert", schemaProp("boolean", "Carve instead of build (like holding Alt).")},
@@ -104,6 +104,16 @@ bool isLiveTool(const std::string& name) {
return name == "viewport_image" || name == "view_set" || name == "view_turntable" || name == "stroke_screen";
}
+// Commands that start a new scene (Document::setMesh: the edit history is cleared).
+bool replacesScene(const std::string& name) {
+ static const char* const kNames[] = {"new_sphere", "new_plane", "new_head", "new_starter_mesh", "new_bench_sphere",
+ "open", "open_obj", "open_project", "calibrate", "bridge_import", "bridge_receive",
+ "blender_receive", "maya_receive"};
+ for (const char* n : kNames)
+ if (name == n) return true;
+ return false;
+}
+
std::string degrees(float radians) {
char buf[16];
std::snprintf(buf, sizeof buf, "%.0f", double(glm::degrees(radians)));
@@ -358,7 +368,10 @@ void App::pollAiLink() {
break;
}
s.session->policy.projectDir = macroProjectDir();
- const link::AiDecision d = s.session->policy.classify(isLiveTool(name) ? nullptr : cmd, name, step.call.args);
+ link::AiDecision d = s.session->policy.classify(isLiveTool(name) ? nullptr : cmd, name, step.call.args);
+ // A new scene clears the history: unsaved work couldn't be undone back.
+ if (d.verdict == link::AiVerdict::Allow && doc_.dirty() && replacesScene(name))
+ d = {link::AiVerdict::Confirm, "Replaces the scene: your unsaved changes would be lost"};
if (d.verdict == link::AiVerdict::Deny) {
s.send(link::AiLinkSession::resultReply(step.call.id, false, d.reason));
} else if (d.verdict == link::AiVerdict::Confirm) {
diff --git a/tests/ui/ai_live.sfui b/tests/ui/ai_live.sfui
index a7c76429..abb28797 100644
--- a/tests/ui/ai_live.sfui
+++ b/tests/ui/ai_live.sfui
@@ -34,7 +34,7 @@ ai_client send {"jsonrpc":"2.0","id":2,"method":"tools/list"}
ai_client expect viewport_image
ai_client send {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"view_set","arguments":{"preset":"three_quarter","frame":"all"}}}
ai_client expect "Camera: yaw 35"
-ai_client send {"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"stroke_screen","arguments":{"points":"0.4,0.45 0.5,0.4 0.6,0.45","brush":"Clay Buildup","radius":0.06,"strength":0.8}}}
+ai_client send {"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"stroke_screen","arguments":{"points":"0.4,0.45 0.5,0.4 0.6,0.45","brush":"Clay Block","radius":0.06,"strength":0.8}}}
ai_client expect id":4,
ai_client send {"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"viewport_image","arguments":{"size":256}}}
ai_client expect image/png