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
Splat training: generated CC0 test capture, UI test with the fake trainer, splat shown alone while it trains, old checkpoints pruned
islandmedc257ee046d80
diff --git a/src/ai/SplatTrainer.cpp b/src/ai/SplatTrainer.cppindex 5b8f1dd5..4bfbe7f4 100644--- a/src/ai/SplatTrainer.cpp+++ b/src/ai/SplatTrainer.cpp@@ -626,8 +626,7 @@ bool SplatTrainJob::train(const TrainRequest& r, const std::string& dataset) {const double trainStart = nowSeconds();size_t logOffset = 0;std::string partial;- int loadedStep = -1, pendingStep = -1;- uintmax_t pendingSize = 0;+ int loadedStep = -1;bool sawError = false;auto readLog = [&] {std::ifstream f(u8path(log), std::ios::binary);@@ -651,21 +650,26 @@ bool SplatTrainJob::train(const TrainRequest& r, const std::string& dataset) {sawError = sawError || t.error;}};- // A checkpoint is loaded once its size stops changing between two checks (Brush may still be writing it).+ // The newest checkpoint is loaded once its size holds still for a moment (Brush may still be writing it); a+ // file that doesn't parse yet is tried again on the next check.auto pollCheckpoints = [&](bool final) {int step = -1;const std::string path = latestCheckpoint(pathString(checkpoints), step);if (path.empty() || step <= loadedStep) return;+ update([&](TrainStatus& s) { s.step = std::max(s.step, step); });const uintmax_t size = fs::file_size(u8path(path), ec);- if (ec) return;- if (final || (step == pendingStep && size == pendingSize && size > 0)) {- if (loadCheckpoint(path, step)) loadedStep = step;- pendingStep = -1;- } else {- pendingStep = step;- pendingSize = size;+ if (ec || size == 0) return;+ if (!final) {+ sleepSeconds(std::min(0.1, pollSeconds));+ if (fs::file_size(u8path(path), ec) != size || ec) return;+ }+ if (!loadCheckpoint(path, step)) return;+ loadedStep = step;+ // Older checkpoints are no longer needed (a Quality run would otherwise leave gigabytes of them).+ for (fs::directory_iterator it(checkpoints, ec), end; !ec && it != end; it.increment(ec)) {+ const int s = checkpointStep(pathString(it->path().filename()));+ if (s >= 0 && s < step) fs::remove(it->path(), ec);}- update([&](TrainStatus& s) { s.step = std::max(s.step, step); });};while (p.running()) {if (stopRequested()) {diff --git a/src/app/PanelSplatTrain.cpp b/src/app/PanelSplatTrain.cppindex e5a137f7..4e8e9f4d 100644--- a/src/app/PanelSplatTrain.cpp+++ b/src/app/PanelSplatTrain.cpp@@ -221,8 +221,8 @@ void App::registerSplatTrainUi() {[this] { return splatTrain_->job.busy(); },"Stop training now and keep what it has learned (the newest checkpoint) as the result.","splat_train_cancel");- add("splats.train_cancel", "Cancel##splattrain", ICON_LC_X, [this] { runCommand("splat_train_cancel"); },- [this] { return splatTrain_->job.busy(); }, "Stop training and keep nothing.", "splat_train_cancel");+ add("splats.train_cancel", "Cancel", ICON_LC_X, [this] { runCommand("splat_train_cancel"); },+ [this] { return splatTrain_->job.busy(); }, "Stop training. Nothing is saved; the last preview stays in the viewport until you Clear the splats.", "splat_train_cancel");add("splats.train_choose_brush", "Choose Brush...", nullptr,[this] { SDL_ShowOpenFileDialog(onPicked, pickTag(Pick::Brush), window_, nullptr, 0, nullptr, false); }, nullptr,"Use a Brush trainer you already have (brush_app): for example one you built yourself with cargo on Linux "@@ -281,7 +281,15 @@ void App::pollSplatTrain() {doc_.splatsChanged();renderSettings_.showSplats = true;++s.previews;- if (first) camera_.frame(sceneBounds());+ if (first) {+ // A capture lands where the sculpt is (a new scene's sphere would hide it): show the splat alone; Show+ // mesh in the Splats palette brings the sculpt back.+ if (renderSettings_.showMesh) {+ renderSettings_.showMesh = false;+ status_ = "Showing the splat as it trains (Splats > Show mesh brings the sculpt back)";+ }+ camera_.frame(sceneBounds());+ }}if (s.job.busy()) return;s.active = false;diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 56501490..666ba246 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -42,7 +42,7 @@// click_subtool NAME [U V] left-click SubTool NAME in the viewport (with the held modifiers, e.g.// hold alt to select it); U V: fractions of its on-screen bounds// expect_value NAME OP N triangles, vertices, layers, brushes, masked, hidden, groups, colored,-// can_undo, dirty, splats, show_polygroups, show_mask, wireframe,+// can_undo, dirty, splats, show_polygroups, show_mask, show_mesh, wireframe,// subtools (count), active_subtool (index, 0 = top), visible_subtools,// edited_subtools (SubTools with undo history), user_brushes (brushes in the// user library), library_files (.sfbrush files in it; UI tests get an empty@@ -322,6 +322,7 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "splats") return double(app_.doc_.splats.size());if (name == "show_polygroups") return app_.renderSettings_.showPolygroups ? 1.0 : 0.0;if (name == "show_mask") return app_.renderSettings_.showMask ? 1.0 : 0.0;+ if (name == "show_mesh") return app_.renderSettings_.showMesh ? 1.0 : 0.0;if (name == "wireframe") return app_.renderSettings_.wireframe ? 1.0 : 0.0;if (name == "shelves") return app_.layout_.shelvesVisible ? 1.0 : 0.0;if (name == "left_tray") return app_.layout_.leftTrayOpen ? double(app_.layout_.leftTray.size()) : -1.0;diff --git a/src/core/SplatCapture.cpp b/src/core/SplatCapture.cppindex bc9593ba..9866ba99 100644--- a/src/core/SplatCapture.cpp+++ b/src/core/SplatCapture.cpp@@ -76,6 +76,8 @@ void readIntrinsics(const Json& f, CameraView& v) {v.cy = float(f["cy"].asNumber(v.cy));v.width = int(f["w"].asNumber(v.width));v.height = int(f["h"].asNumber(v.height));+ if (v.cx <= 0 && v.width > 0) v.cx = float(v.width) * 0.5f; // principal point: the image centre by default+ if (v.cy <= 0 && v.height > 0) v.cy = float(v.height) * 0.5f;}// COLMAP pose (world-to-camera rotation as a quaternion and translation, OpenCV axes) to an OpenGL camToWorld.diff --git a/tests/data/splat_capture/IMG_0000.png b/tests/data/splat_capture/IMG_0000.pngnew file mode 100644index 00000000..d957bc4aBinary files /dev/null and b/tests/data/splat_capture/IMG_0000.png differdiff --git a/tests/data/splat_capture/IMG_0001.png b/tests/data/splat_capture/IMG_0001.pngnew file mode 100644index 00000000..5291ce5cBinary files /dev/null and b/tests/data/splat_capture/IMG_0001.png differdiff --git a/tests/data/splat_capture/IMG_0002.png b/tests/data/splat_capture/IMG_0002.pngnew file mode 100644index 00000000..6bee9957Binary files /dev/null and b/tests/data/splat_capture/IMG_0002.png differdiff --git a/tests/data/splat_capture/IMG_0003.png b/tests/data/splat_capture/IMG_0003.pngnew file mode 100644index 00000000..f4c4b2eaBinary files /dev/null and b/tests/data/splat_capture/IMG_0003.png differdiff --git a/tests/data/splat_capture/IMG_0004.png b/tests/data/splat_capture/IMG_0004.pngnew file mode 100644index 00000000..7c27bb21Binary files /dev/null and b/tests/data/splat_capture/IMG_0004.png differdiff --git a/tests/data/splat_capture/IMG_0005.png b/tests/data/splat_capture/IMG_0005.pngnew file mode 100644index 00000000..71a07ab0Binary files /dev/null and b/tests/data/splat_capture/IMG_0005.png differdiff --git a/tests/data/splat_capture/IMG_0006.png b/tests/data/splat_capture/IMG_0006.pngnew file mode 100644index 00000000..1eedc061Binary files /dev/null and b/tests/data/splat_capture/IMG_0006.png differdiff --git a/tests/data/splat_capture/IMG_0007.png b/tests/data/splat_capture/IMG_0007.pngnew file mode 100644index 00000000..7fb45b49Binary files /dev/null and b/tests/data/splat_capture/IMG_0007.png differdiff --git a/tests/data/splat_capture/IMG_0008.png b/tests/data/splat_capture/IMG_0008.pngnew file mode 100644index 00000000..db1ee5fdBinary files /dev/null and b/tests/data/splat_capture/IMG_0008.png differdiff --git a/tests/data/splat_capture/IMG_0009.png b/tests/data/splat_capture/IMG_0009.pngnew file mode 100644index 00000000..81ca9dc8Binary files /dev/null and b/tests/data/splat_capture/IMG_0009.png differdiff --git a/tests/data/splat_capture/IMG_0010.png b/tests/data/splat_capture/IMG_0010.pngnew file mode 100644index 00000000..0a185d45Binary files /dev/null and b/tests/data/splat_capture/IMG_0010.png differdiff --git a/tests/data/splat_capture/IMG_0011.png b/tests/data/splat_capture/IMG_0011.pngnew file mode 100644index 00000000..78ebd19fBinary files /dev/null and b/tests/data/splat_capture/IMG_0011.png differdiff --git a/tests/data/splat_capture/IMG_0012.png b/tests/data/splat_capture/IMG_0012.pngnew file mode 100644index 00000000..2967db2dBinary files /dev/null and b/tests/data/splat_capture/IMG_0012.png differdiff --git a/tests/data/splat_capture/IMG_0013.png b/tests/data/splat_capture/IMG_0013.pngnew file mode 100644index 00000000..8315410eBinary files /dev/null and b/tests/data/splat_capture/IMG_0013.png differdiff --git a/tests/data/splat_capture/IMG_0014.png b/tests/data/splat_capture/IMG_0014.pngnew file mode 100644index 00000000..7f278ca7Binary files /dev/null and b/tests/data/splat_capture/IMG_0014.png differdiff --git a/tests/data/splat_capture/IMG_0015.png b/tests/data/splat_capture/IMG_0015.pngnew file mode 100644index 00000000..cfca2f8dBinary files /dev/null and b/tests/data/splat_capture/IMG_0015.png differdiff --git a/tests/data/splat_capture/IMG_0016.png b/tests/data/splat_capture/IMG_0016.pngnew file mode 100644index 00000000..24f017cfBinary files /dev/null and b/tests/data/splat_capture/IMG_0016.png differdiff --git a/tests/data/splat_capture/IMG_0017.png b/tests/data/splat_capture/IMG_0017.pngnew file mode 100644index 00000000..4e6425a4Binary files /dev/null and b/tests/data/splat_capture/IMG_0017.png differdiff --git a/tests/data/splat_capture/IMG_0018.png b/tests/data/splat_capture/IMG_0018.pngnew file mode 100644index 00000000..90ba17fdBinary files /dev/null and b/tests/data/splat_capture/IMG_0018.png differdiff --git a/tests/data/splat_capture/IMG_0019.png b/tests/data/splat_capture/IMG_0019.pngnew file mode 100644index 00000000..90f36519Binary files /dev/null and b/tests/data/splat_capture/IMG_0019.png differdiff --git a/tests/data/splat_capture/LICENSE.txt b/tests/data/splat_capture/LICENSE.txtnew file mode 100644index 00000000..8b52d712--- /dev/null+++ b/tests/data/splat_capture/LICENSE.txt@@ -0,0 +1 @@+Generated by tools/splat/make_test_capture.py. CC0 1.0 / public domain.diff --git a/tests/data/splat_capture/capture.json b/tests/data/splat_capture/capture.jsonnew file mode 100644index 00000000..a254522b--- /dev/null+++ b/tests/data/splat_capture/capture.json@@ -0,0 +1,632 @@+{+ "kind": "splat",+ "device": "SculptForge synthetic capture (tools/splat/make_test_capture.py)",+ "files": [+ "IMG_0000.png",+ "IMG_0001.png",+ "IMG_0002.png",+ "IMG_0003.png",+ "IMG_0004.png",+ "IMG_0005.png",+ "IMG_0006.png",+ "IMG_0007.png",+ "IMG_0008.png",+ "IMG_0009.png",+ "IMG_0010.png",+ "IMG_0011.png",+ "IMG_0012.png",+ "IMG_0013.png",+ "IMG_0014.png",+ "IMG_0015.png",+ "IMG_0016.png",+ "IMG_0017.png",+ "IMG_0018.png",+ "IMG_0019.png"+ ],+ "fl_x": 137.2484,+ "fl_y": 137.2484,+ "w": 128,+ "h": 96,+ "frames": [+ {+ "file": "IMG_0000.png",+ "t": 0,+ "transform_matrix": [+ [+ 1.0,+ 0.0,+ -0.0,+ 0.0+ ],+ [+ -0.0,+ 0.982006,+ 0.188847,+ 0.9+ ],+ [+ 0.0,+ -0.188847,+ 0.982006,+ 2.6+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0001.png",+ "t": 500,+ "transform_matrix": [+ [+ 0.951057,+ -0.101535,+ 0.29186,+ 0.803444+ ],+ [+ 0.0,+ 0.944479,+ 0.328573,+ 1.304508+ ],+ [+ -0.309017,+ -0.312491,+ 0.898253,+ 2.472747+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0002.png",+ "t": 1000,+ "transform_matrix": [+ [+ 0.809017,+ -0.206483,+ 0.550324,+ 1.528242+ ],+ [+ 0.0,+ 0.936267,+ 0.35129,+ 1.375528+ ],+ [+ -0.587785,+ -0.2842,+ 0.757456,+ 2.103444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0003.png",+ "t": 1500,+ "transform_matrix": [+ [+ 0.587785,+ -0.197496,+ 0.784541,+ 2.103444+ ],+ [+ 0.0,+ 0.969746,+ 0.244118,+ 1.054508+ ],+ [+ -0.809017,+ -0.143489,+ 0.570002,+ 1.528242+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0004.png",+ "t": 2000,+ "transform_matrix": [+ [+ 0.309017,+ -0.075156,+ 0.948082,+ 2.472747+ ],+ [+ 0.0,+ 0.996873,+ 0.079024,+ 0.606107+ ],+ [+ -0.951057,+ -0.02442,+ 0.308051,+ 0.803444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0005.png",+ "t": 2500,+ "transform_matrix": [+ [+ 0.0,+ 0.0,+ 1.0,+ 2.6+ ],+ [+ 0.0,+ 1.0,+ -0.0,+ 0.4+ ],+ [+ -1.0,+ 0.0,+ 0.0,+ 0.0+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0006.png",+ "t": 3000,+ "transform_matrix": [+ [+ -0.309017,+ -0.075156,+ 0.948082,+ 2.472747+ ],+ [+ 0.0,+ 0.996873,+ 0.079024,+ 0.606107+ ],+ [+ -0.951057,+ 0.02442,+ -0.308051,+ -0.803444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0007.png",+ "t": 3500,+ "transform_matrix": [+ [+ -0.587785,+ -0.197496,+ 0.784541,+ 2.103444+ ],+ [+ 0.0,+ 0.969746,+ 0.244118,+ 1.054508+ ],+ [+ -0.809017,+ 0.143489,+ -0.570002,+ -1.528242+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0008.png",+ "t": 4000,+ "transform_matrix": [+ [+ -0.809017,+ -0.206483,+ 0.550324,+ 1.528242+ ],+ [+ 0.0,+ 0.936267,+ 0.35129,+ 1.375528+ ],+ [+ -0.587785,+ 0.2842,+ -0.757456,+ -2.103444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0009.png",+ "t": 4500,+ "transform_matrix": [+ [+ -0.951057,+ -0.101535,+ 0.29186,+ 0.803444+ ],+ [+ 0.0,+ 0.944479,+ 0.328573,+ 1.304508+ ],+ [+ -0.309017,+ 0.312491,+ -0.898253,+ -2.472747+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0010.png",+ "t": 5000,+ "transform_matrix": [+ [+ -1.0,+ -0.0,+ 0.0,+ 0.0+ ],+ [+ 0.0,+ 0.982006,+ 0.188847,+ 0.9+ ],+ [+ -0.0,+ 0.188847,+ -0.982006,+ -2.6+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0011.png",+ "t": 5500,+ "transform_matrix": [+ [+ -0.951057,+ 0.011342,+ -0.308809,+ -0.803444+ ],+ [+ 0.0,+ 0.999326,+ 0.036703,+ 0.495492+ ],+ [+ 0.309017,+ 0.034906,+ -0.950416,+ -2.472747+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0012.png",+ "t": 6000,+ "transform_matrix": [+ [+ -0.809017,+ 0.005532,+ -0.587759,+ -1.528242+ ],+ [+ 0.0,+ 0.999956,+ 0.009412,+ 0.424472+ ],+ [+ 0.587785,+ 0.007614,+ -0.808981,+ -2.103444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0013.png",+ "t": 6500,+ "transform_matrix": [+ [+ -0.587785,+ 0.106567,+ -0.801968,+ -2.103444+ ],+ [+ 0.0,+ 0.991286,+ 0.131723,+ 0.745492+ ],+ [+ 0.809017,+ 0.077425,+ -0.582664,+ -1.528242+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0014.png",+ "t": 7000,+ "transform_matrix": [+ [+ -0.309017,+ 0.27774,+ -0.909598,+ -2.472747+ ],+ [+ 0.0,+ 0.956408,+ 0.292033,+ 1.193893+ ],+ [+ 0.951057,+ 0.090243,+ -0.295546,+ -0.803444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0015.png",+ "t": 7500,+ "transform_matrix": [+ [+ -0.0,+ 0.358979,+ -0.933346,+ -2.6+ ],+ [+ 0.0,+ 0.933346,+ 0.358979,+ 1.4+ ],+ [+ 1.0,+ 0.0,+ -0.0,+ -0.0+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0016.png",+ "t": 8000,+ "transform_matrix": [+ [+ 0.309017,+ 0.27774,+ -0.909598,+ -2.472747+ ],+ [+ -0.0,+ 0.956408,+ 0.292033,+ 1.193893+ ],+ [+ 0.951057,+ -0.090243,+ 0.295546,+ 0.803444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0017.png",+ "t": 8500,+ "transform_matrix": [+ [+ 0.587785,+ 0.106567,+ -0.801968,+ -2.103444+ ],+ [+ -0.0,+ 0.991286,+ 0.131723,+ 0.745492+ ],+ [+ 0.809017,+ -0.077425,+ 0.582664,+ 1.528242+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0018.png",+ "t": 9000,+ "transform_matrix": [+ [+ 0.809017,+ 0.005532,+ -0.587759,+ -1.528242+ ],+ [+ -0.0,+ 0.999956,+ 0.009412,+ 0.424472+ ],+ [+ 0.587785,+ -0.007614,+ 0.808981,+ 2.103444+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ },+ {+ "file": "IMG_0019.png",+ "t": 9500,+ "transform_matrix": [+ [+ 0.951057,+ 0.011342,+ -0.308809,+ -0.803444+ ],+ [+ -0.0,+ 0.999326,+ 0.036703,+ 0.495492+ ],+ [+ 0.309017,+ -0.034906,+ 0.950416,+ 2.472747+ ],+ [+ 0,+ 0,+ 0,+ 1+ ]+ ]+ }+ ]+}\ No newline at end of filediff --git a/tests/test_splat_train.cpp b/tests/test_splat_train.cppindex 8d15e9c4..4e7d76e8 100644--- a/tests/test_splat_train.cpp+++ b/tests/test_splat_train.cpp@@ -330,6 +330,9 @@ TEST(splat_train_job_photos_to_splat_with_live_previews) {CHECK(st.psnr > 25.0); // the fake's last evaluationCHECK(fs::exists(st.result) && fs::path(st.result).filename() == "sf_train_photos.ply");CHECK(fs::exists(out / "work" / "dataset" / "sparse" / "0" / "images.txt"));+ int checkpoints = 0;+ for (const auto& e : fs::directory_iterator(out / "work" / "checkpoints")) checkpoints += e.path().extension() == ".ply";+ CHECK(checkpoints == 1); // older checkpoints are deleted once a newer one is loadedCHECK(fs::exists(out / "work" / "dataset" / "images" / "IMG_0003.png")); // photos keep their namesCHECK(last && last->size() > 100);if (last) {@@ -498,3 +501,21 @@ TEST(splat_train_settings_round_trip) {CHECK(std::string(d->url).rfind("https://github.com/ArthurBrussee/brush/releases/download/", 0) == 0);}}++TEST(splat_capture_test_capture_poses_look_at_the_object) {+ // tests/data/splat_capture (tools/splat/make_test_capture.py): the phone-link capture.json layout with AR poses.+ CaptureInfo info;+ std::string err;+ CHECK(readCaptureJson(std::string(SF_TEST_DATA_DIR) + "/splat_capture/capture.json", info, err));+ CHECK(info.kind == "splat" && info.files.size() == 20 && info.poses.size() == 20);+ for (const CameraView& v : info.poses) {+ // The maquette's head (0, 0.55, 0) projects near the middle of every photo.+ const glm::vec4 p = glm::inverse(v.camToWorld) * glm::vec4(0, 0.55f, 0, 1);+ CHECK(p.z < 0); // in front of an OpenGL camera+ const float u = v.cx + v.fx * p.x / -p.z, w = v.cy - v.fy * p.y / -p.z;+ CHECK(std::abs(u - 64.0f) < 20.0f && std::abs(w - 48.0f) < 30.0f);+ }+ const glm::mat4 m = orbitFraming(info.poses);+ CHECK(glm::length(glm::vec3(m * glm::vec4(0, 0.4f, 0, 1))) < 0.3f);+ CHECK(glm::normalize(glm::vec3(m * glm::vec4(0, 1, 0, 0))).y > 0.99f);+}diff --git a/tests/tools/fake_splat_tools.cpp b/tests/tools/fake_splat_tools.cppindex f991dfb9..3d491904 100644--- a/tests/tools/fake_splat_tools.cpp+++ b/tests/tools/fake_splat_tools.cpp@@ -12,8 +12,9 @@// world up = +Z (as arbitrary as a real reconstruction); FAKE_COLMAP_FAIL=1 fails// - Brush (DATASET --total-steps N --export-every K --export-path DIR ...):// checks the dataset, prints Brush's log lines and writes export_<step>.ply-// checkpoints of a sphere around (1,2,3) that gets sharper;+// checkpoints of a sphere where the cameras look that gets sharper;// FAKE_BRUSH_MS_PER_EXPORT (20) slows it down, FAKE_BRUSH_FAIL_AT=<step> crashes+#include "core/SplatCapture.h"#include "core/Splats.h"#include "io/PlyIO.h"@@ -145,6 +146,21 @@ int fakeBrush(int argc, char** argv) {fs::create_directories(out);std::printf("[2026-10-26T00:00:00Z INFO brush_process::train_stream] Start of training stream\n");std::fflush(stdout);+ // The "object": a sphere where the cameras look (as a real trainer would find it), sized to their distance.+ glm::vec3 centre(1, 2, 3);+ float radius = 0.5f;+ {+ std::vector<sf::capture::CameraView> views;+ std::string err;+ const bool ok = fs::exists(ds / "transforms.json")+ ? sf::capture::readTransformsJson((ds / "transforms.json").string(), views, err)+ : sf::capture::readColmapImages((ds / "sparse" / "0").string(), views, err);+ if (ok && views.size() >= 2) {+ const glm::mat4 framing = sf::capture::orbitFraming(views);+ centre = glm::vec3(glm::inverse(framing) * glm::vec4(0, 0, 0, 1));+ radius = 0.7f * glm::length(glm::vec3(glm::inverse(framing) * glm::vec4(1, 0, 0, 0)));+ }+ }std::mt19937 rng(42);std::normal_distribution<float> normal(0.0f, 1.0f);for (int step = every; step <= total + every - 1; step += every) {@@ -167,9 +183,9 @@ int fakeBrush(int argc, char** argv) {for (int i = 0; i < count; ++i) {glm::vec3 d(normal(rng), normal(rng), normal(rng));d = glm::normalize(d);- cloud.positions[size_t(i)] = glm::vec3(1, 2, 3) + 0.5f * d + noise * glm::vec3(normal(rng), normal(rng), normal(rng));+ cloud.positions[size_t(i)] = centre + radius * d + radius * noise * glm::vec3(normal(rng), normal(rng), normal(rng));cloud.rotations[size_t(i)] = glm::quat(1, 0, 0, 0);- cloud.scales[size_t(i)] = glm::vec3(0.02f);+ cloud.scales[size_t(i)] = glm::vec3(0.04f * radius);cloud.opacities[size_t(i)] = 0.9f;cloud.setColor(size_t(i), glm::vec3(0.5f + 0.5f * d.x, 0.5f + 0.5f * d.y, 0.5f + 0.5f * d.z));}diff --git a/tests/ui/splat_train.sfui b/tests/ui/splat_train.sfuinew file mode 100644index 00000000..df105f00--- /dev/null+++ b/tests/ui/splat_train.sfui@@ -0,0 +1,81 @@+# Splats > Train from capture, with a stand-in for Brush and COLMAP (CMake points SCULPTFORGE_BRUSH / _COLMAP /+# _FFMPEG at tests/tools/fake_splat_tools.cpp, which writes a checkpoint every 250 steps). The capture is the+# synthetic phone capture in tests/data/splat_capture (photos + AR poses). Checks the live preview, orbiting+# while it trains, the progress overlay, Good enough - stop, Cancel, a trainer crash and the Brush prompt.+env FAKE_BRUSH_MS_PER_EXPORT 150+env FAKE_BRUSH_FAIL_AT -1+copy ../data/splat_capture ui-shots/splat_train/capture++# The section at the top of the Splats palette.+click "Splats##palette.splats"+expect "Video...##splats.train_video"+expect "Photos Folder...##splats.train_folder"+expect_text "Train from capture"+expect_text "Fast preview"+shot palette+key escape++# Train: the splat appears after the first checkpoints and the view still turns while it trains.+run splat_train source=ui-shots/splat_train/capture+expect_value splat_training == 1+wait_value splat_previews >= 2 30+expect_value splats > 100+expect_value show_mesh == 0+expect "Good enough - stop##splats.train_stop"+expect "Cancel##splats.train_cancel"+expect_text "Training splat - Fast preview"+expect_text "steps"+shot training+remember camera_yaw yaw0+orbit 300 0+expect_value camera_yaw != $yaw0+expect_value splat_training == 1+shot training_orbited+wait_idle 60+expect_value splat_training == 0+expect_value splat_train_stage == 4+expect_value splat_train_step == 5000+expect_value splat_train_psnr > 25+expect_value splats > 1000+expect_status "Splat trained"+expect_no_text "Training splat"+shot done++# Good enough - stop: keeps the newest checkpoint.+run splat_train source=ui-shots/splat_train/capture+wait_value splat_previews >= 1 30+click "Good enough - stop##splats.train_stop"+wait_idle 60+expect_value splat_train_stage == 4+expect_value splat_train_step < 5000+expect_status "Splat trained"++# Cancel: nothing kept.+env FAKE_BRUSH_MS_PER_EXPORT 400+run splat_train source=ui-shots/splat_train/capture+wait_value splat_previews >= 1 30+click "Cancel##splats.train_cancel"+wait_idle 30+expect_value splat_train_stage == 6+expect_status "Cancelled"++env FAKE_BRUSH_MS_PER_EXPORT 150++# The trainer crashes: the status bar says so (with the log's last lines).+env FAKE_BRUSH_FAIL_AT 500+run splat_train source=ui-shots/splat_train/capture+wait_idle 30+expect_value splat_train_stage == 5+expect_status "Brush stopped with an error"+env FAKE_BRUSH_FAIL_AT -1++# No Brush: a prompt says what would be downloaded (nothing is, without a click).+env SCULPTFORGE_BRUSH /nonexistent/brush_app+run splat_train source=ui-shots/splat_train/capture+expect_value splat_train_prompt == 1+expect_value splat_training == 0+expect_text "Splat training needs Brush"+expect "Not now"+shot brush_prompt+click "Not now"+expect_value splat_train_prompt == 0diff --git a/tools/splat/make_test_capture.py b/tools/splat/make_test_capture.pynew file mode 100644index 00000000..6d5a9ff1--- /dev/null+++ b/tools/splat/make_test_capture.py@@ -0,0 +1,156 @@+#!/usr/bin/env python3+# SculptForge - open source digital sculpting+# SPDX-License-Identifier: GPL-3.0-or-later+"""Renders a tiny synthetic phone capture for splat training tests.++A painted clay "maquette" (a head with ears and a nose on a plinth) is+ray-traced from VIEWS positions on a ring around it, the way someone walks+around an object with a phone. Writes PNG photos and a capture.json in the+phone-link layout (kind, device, files, and the camera pose of every photo as+an OpenGL camera-to-world transform_matrix with fl_x / w / h), so training+needs no COLMAP. The output is generated, so it is CC0 / public domain.++ python3 tools/splat/make_test_capture.py tests/data/splat_capture+ python3 tools/splat/make_test_capture.py big --views 60 --size 640x480++Pure Python (no numpy), a few seconds at the default size.+"""+import argparse+import json+import math+import os+import struct+import zlib+++def png(path, w, h, rgb):+ raw = b"".join(b"\x00" + bytes(rgb[y * w * 3:(y + 1) * w * 3]) for y in range(h))++ def chunk(tag, data):+ c = struct.pack(">I", len(data)) + tag + data+ return c + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)++ with open(path, "wb") as f:+ f.write(b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) ++ chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b""))+++def sub(a, b): return (a[0] - b[0], a[1] - b[1], a[2] - b[2])+def add(a, b): return (a[0] + b[0], a[1] + b[1], a[2] + b[2])+def mul(a, s): return (a[0] * s, a[1] * s, a[2] * s)+def dot(a, b): return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]+def cross(a, b): return (a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0])+def norm(a):+ l = math.sqrt(dot(a, a))+ return (a[0] / l, a[1] / l, a[2] / l)+++# The maquette: spheres (centre, radius, base colour) and a plinth (a box).+SPHERES = [((0.0, 0.55, 0.0), 0.45, (0.80, 0.52, 0.40)), # head+ ((-0.42, 0.75, 0.0), 0.14, (0.72, 0.42, 0.33)), # ears+ ((0.42, 0.75, 0.0), 0.14, (0.72, 0.42, 0.33)),+ ((0.0, 0.52, 0.43), 0.09, (0.86, 0.45, 0.35)), # nose+ ((-0.16, 0.66, 0.36), 0.06, (0.15, 0.15, 0.18)), # eyes+ ((0.16, 0.66, 0.36), 0.06, (0.15, 0.15, 0.18))]+BOX = ((-0.5, -0.1, -0.5), (0.5, 0.1, 0.5))+LIGHT = norm((0.4, 0.8, 0.5))+++def pattern(p):+ # Painted texture (training needs detail to lock on to): soft stripes and dots.+ s = 0.5 + 0.5 * math.sin(p[1] * 22.0) * math.cos(p[0] * 9.0 + p[2] * 7.0)+ return 0.75 + 0.25 * s+++def trace(o, d):+ best, hit = 1e9, None+ for c, r, col in SPHERES:+ oc = sub(o, c)+ b = dot(oc, d)+ disc = b * b - (dot(oc, oc) - r * r)+ if disc > 0:+ t = -b - math.sqrt(disc)+ if 1e-4 < t < best:+ p = add(o, mul(d, t))+ best, hit = t, (p, norm(sub(p, c)), col)+ # Box (slab test).+ tmin, tmax, axis = -1e9, 1e9, 0+ for k in range(3):+ if abs(d[k]) < 1e-12:+ if o[k] < BOX[0][k] or o[k] > BOX[1][k]:+ tmin = 1e9+ continue+ t1, t2 = (BOX[0][k] - o[k]) / d[k], (BOX[1][k] - o[k]) / d[k]+ if t1 > t2:+ t1, t2 = t2, t1+ if t1 > tmin:+ tmin, axis = t1, k+ tmax = min(tmax, t2)+ if tmin <= tmax and 1e-4 < tmin < best:+ p = add(o, mul(d, tmin))+ n = [0.0, 0.0, 0.0]+ n[axis] = -1.0 if d[axis] > 0 else 1.0+ checker = (int(math.floor(p[0] * 8)) + int(math.floor(p[2] * 8))) % 2+ best, hit = tmin, (p, tuple(n), (0.35, 0.36, 0.40) if checker else (0.55, 0.56, 0.60))+ return hit+++def shade(o, d):+ hit = trace(o, d)+ if not hit: # a soft studio backdrop+ g = 0.55 + 0.25 * d[1]+ return (g, g, g * 1.04)+ p, n, col = hit+ lit = 0.35 + 0.65 * max(0.0, dot(n, LIGHT))+ if trace(add(p, mul(n, 1e-3)), LIGHT):+ lit = 0.35+ k = pattern(p) * lit+ return (col[0] * k, col[1] * k, col[2] * k)+++def main():+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)+ ap.add_argument("out")+ ap.add_argument("--views", type=int, default=20)+ ap.add_argument("--size", default="128x96")+ a = ap.parse_args()+ w, h = (int(v) for v in a.size.split("x"))+ os.makedirs(a.out, exist_ok=True)+ fov = math.radians(50.0)+ fl = 0.5 * w / math.tan(0.5 * fov)+ target = (0.0, 0.4, 0.0)+ frames, files = [], []+ for i in range(a.views):+ ang = 2 * math.pi * i / a.views+ height = 0.9 + 0.5 * math.sin(3 * ang) # walking round, the phone goes up and down a little+ eye = (2.6 * math.sin(ang), height, 2.6 * math.cos(ang))+ f = norm(sub(target, eye))+ r = norm(cross(f, (0.0, 1.0, 0.0)))+ u = cross(r, f)+ rgb = bytearray(w * h * 3)+ for y in range(h):+ for x in range(w):+ px, py = (x + 0.5 - w / 2) / fl, -(y + 0.5 - h / 2) / fl+ d = norm(add(add(f, mul(r, px)), mul(u, py)))+ c = shade(eye, d)+ k = (y * w + x) * 3+ for j in range(3):+ rgb[k + j] = max(0, min(255, int(round(255 * (c[j] ** (1 / 2.2))))))+ name = "IMG_%04d.png" % i+ png(os.path.join(a.out, name), w, h, rgb)+ files.append(name)+ # OpenGL camera-to-world: columns right, up, -forward, eye (written row by row).+ m = [[r[0], u[0], -f[0], eye[0]], [r[1], u[1], -f[1], eye[1]], [r[2], u[2], -f[2], eye[2]], [0, 0, 0, 1]]+ frames.append({"file": name, "t": i * 500,+ "transform_matrix": [[round(v, 6) for v in row] for row in m]})+ capture = {"kind": "splat", "device": "SculptForge synthetic capture (tools/splat/make_test_capture.py)",+ "files": files, "fl_x": round(fl, 4), "fl_y": round(fl, 4), "w": w, "h": h, "frames": frames}+ with open(os.path.join(a.out, "capture.json"), "w") as f:+ json.dump(capture, f, indent=1)+ with open(os.path.join(a.out, "LICENSE.txt"), "w") as f:+ f.write("Generated by tools/splat/make_test_capture.py. CC0 1.0 / public domain.\n")+ print("wrote %d views (%dx%d) to %s" % (a.views, w, h, a.out))+++if __name__ == "__main__":+ main()