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
Projects: feat/pbr's ProjectVersionNeed instead of kProjectVersionWithoutMicro
islandmed16951398c2b2
diff --git a/src/core/Project.cpp b/src/core/Project.cppindex 2306aa85..723cc84b 100644--- a/src/core/Project.cpp+++ b/src/core/Project.cpp@@ -799,9 +799,9 @@ bool saveProject(const std::string& path, const Document& doc, std::string& erroWriter w;Json manifest = Json::object();manifest.set("format", kFormatName);- manifest.set("version", kProjectVersion);+ ProjectVersionNeed version; // the lowest format the content needs (set again once the SubTools are written)+ manifest.set("version", version.version);manifest.set("app_version", SCULPTFORGE_VERSION);- bool anyMicro = false; // projects without micro levels stay format 6, so 0.9.7 and older still open them// Every SubTool with its mesh, layers and state; blobs live under subtools/<i>/.Json subtools = Json::array();@@ -833,7 +833,7 @@ bool saveProject(const std::string& path, const Document& doc, std::string& erromj.set("displacement_packed", w.add(p + "displacement.pack", Scalar::U8, 1, packedBytes, std::move(packed)));if (mm.hasMask()) mj.set("mask", w.externalBytes(p + "mask.bin", mm.mask));st.set("micro", std::move(mj));- anyMicro = true;+ version.need(7);}const std::string& gozName = active ? doc.gozName : s.gozName;if (!gozName.empty()) st.set("goz_name", gozName);@@ -847,7 +847,6 @@ bool saveProject(const std::string& path, const Document& doc, std::string& erro}manifest.set("subtools", std::move(subtools));manifest.set("active_subtool", doc.activeSubtool);- if (!anyMicro) manifest.set("version", kProjectVersionWithoutMicro);Json brushes = Json::array();for (const auto& b : doc.brushes) brushes.push(b.toJson());@@ -893,6 +892,7 @@ bool saveProject(const std::string& path, const Document& doc, std::string& errofor (const auto& [key, value] : doc.projectSettings.members())if (!isCoreKey(key)) manifest.set(key, value);+ manifest.set("version", version.version);const std::string text = manifest.dump(true);w.entries.insert(w.entries.begin(), ZipEntry{kManifestName, std::vector<uint8_t>(text.begin(), text.end())});// The preview goes second, so loadProjectThumbnail finds it after reading two local headers.diff --git a/src/core/Project.h b/src/core/Project.hindex 80ca0168..11a64f57 100644--- a/src/core/Project.h+++ b/src/core/Project.h@@ -24,11 +24,19 @@ namespace sf {// painted texture with layers ("texture"; older files still load). 4: SubTools may carry subdivision levels// ("subdiv"; older files still load). 5: sculpt-layer details of subdivision levels are in the levels' local// frames, not world space (format 4 files are converted when they load). 6: levels made by Divide keep no-// triangles, child maps or (where their positions say it) details; older files still load. 7: SubTools may carry a-// micro-displacement level ("micro", core/Micro.h); only projects with one are written as 7.+// triangles, child maps or (where their positions say it) details; older files still load. 7: a SubTool texture+// may carry material channels (the texture's "pbr" key, core/LayerStackIO.h), and a SubTool a micro-displacement+// level ("micro", core/Micro.h); both keys are optional in 7.+//+// kProjectVersion is the newest format this build reads. Saving writes the lowest version the content needs+// (ProjectVersionNeed): a project that uses nothing newer than format 6 is still written as 6, so older+// SculptForge versions keep opening it. A feature that needs a newer format calls need(N) while saving.constexpr int kProjectVersion = 7;-// Projects without a micro level (core/Micro.h) are written as format 6, which older versions read.-constexpr int kProjectVersionWithoutMicro = 6;+constexpr int kProjectBaseWriteVersion = 6;+struct ProjectVersionNeed {+ int version = kProjectBaseWriteVersion;+ void need(int v) { version = v > version ? v : version; }+};constexpr const char* kProjectExtension = ".sfproj";// True for paths ending in .sfproj (any case).diff --git a/tests/test_project.cpp b/tests/test_project.cppindex 175841fb..518b9995 100644--- a/tests/test_project.cpp+++ b/tests/test_project.cpp@@ -248,7 +248,8 @@ TEST(project_version_handling) {std::string err;CHECK(saveProject(path, doc, err));const std::string manifest = readManifest(path);- const std::string v = std::to_string(kProjectVersionWithoutMicro); // (7 only with a micro level: test_micro.cpp)+ const std::string v = std::to_string(kProjectBaseWriteVersion); // nothing in it needs a newer format+ CHECK(kProjectVersion >= 7);CHECK(manifest.find("\"version\": " + v) != std::string::npos || manifest.find("\"version\":" + v) != std::string::npos);CHECK(manifest.find("app_version") != std::string::npos);diff --git a/tests/test_subtool_io.cpp b/tests/test_subtool_io.cppindex df04644b..4c192423 100644--- a/tests/test_subtool_io.cpp+++ b/tests/test_subtool_io.cpp@@ -179,7 +179,7 @@ TEST(subtool_project_v2_round_trip) {CHECK(readStoredZip(path, entries, err));Json manifest;CHECK(!entries.empty() && Json::parse(std::string(entries[0].data.begin(), entries[0].data.end()), manifest, err));- CHECK(manifest["version"].asNumber() == kProjectVersionWithoutMicro && manifest["subtools"].size() == 3);+ CHECK(manifest["version"].asNumber() == kProjectBaseWriteVersion && manifest["subtools"].size() == 3);CHECK(manifest["active_subtool"].asNumber() == 1 && !manifest.has("mesh"));CHECK(manifest["subtools"][1]["goz_name"].asString() == "Eye_ZB");