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
Material Recipes: Worn Metal, Painted Edges, Dirt and Dust, Rusted Iron as .sfmaterial data files
islandmedef51c5b34089
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 3def0b91..fd882b2f 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -76,6 +76,7 @@ add_library(sculptforge_core STATICsrc/core/EnvironmentMath.cppsrc/core/MeshMaps.cppsrc/core/LayerStack.cpp+ src/core/MaterialRecipe.cppsrc/core/TextureChannels.cppsrc/core/TextureChannelCommands.cppsrc/core/LayerStackIO.cpp@@ -147,6 +148,13 @@ embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedHdri.cpp sf::assetshdriSmallStudio ${CMAKE_CURRENT_SOURCE_DIR}/assets/hdri/studio_small_09.hdrhdriOutdoorSky ${CMAKE_CURRENT_SOURCE_DIR}/assets/hdri/kloofendal_48d_partly_cloudy_puresky.hdr)target_sources(sculptforge_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedHdri.cpp)+# The built-in Material Recipes (core/MaterialRecipe.h): Fill layer stacks as data files.+embed_files(${CMAKE_CURRENT_BINARY_DIR}/EmbeddedRecipes.cpp sf::assets+ recipeWornMetal ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/worn_metal.sfmaterial+ recipePaintedEdges ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/painted_edges.sfmaterial+ recipeDirtAndDust ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/dirt_and_dust.sfmaterial+ recipeRustedIron ${CMAKE_CURRENT_SOURCE_DIR}/assets/materials/rusted_iron.sfmaterial)+target_sources(sculptforge_core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/EmbeddedRecipes.cpp)target_include_directories(sculptforge_core PUBLIC src PRIVATE third_party/stb third_party/ufbx third_party/xatlas third_party/mikktspace third_party/tinyexr)if(WIN32)target_link_libraries(sculptforge_core PRIVATE shell32) # core/Trash.cpp: the Recycle Bindiff --git a/assets/materials/dirt_and_dust.sfmaterial b/assets/materials/dirt_and_dust.sfmaterialnew file mode 100644index 00000000..e3c069cd--- /dev/null+++ b/assets/materials/dirt_and_dust.sfmaterial@@ -0,0 +1,26 @@+{+ "format": "sculptforge-material-recipe",+ "version": 1,+ "id": "dirt_and_dust",+ "name": "Dirt and Dust",+ "description": "Weathering to lay over any material: dark dirt packed into crevices and cavities, and pale dust on the surfaces that face up.",+ "layers": [+ {+ "name": "Crevice Dirt",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.13, 0.1, 0.07], "roughness": 0.95, "metallic": 0.0},+ "mask": [{"kind": "generator", "generator": "dirt", "level": 0.5, "softness": 0.25, "breakup": 0.7, "scale": 0.04, "seed": 21},+ {"kind": "blur", "radius": 2}]+ }+ },+ {+ "name": "Dust",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.62, 0.58, 0.5], "roughness": 1.0, "metallic": 0.0},+ "mask": [{"kind": "generator", "generator": "light_direction", "direction": [0, 1, 0], "level": 0.3, "softness": 0.25, "breakup": 0.8, "scale": 0.03, "seed": 4},+ {"kind": "noise", "blend": "multiply", "scale": 0.012, "octaves": 3, "seed": 8, "contrast": 1.5},+ {"kind": "levels", "in_low": 0.1, "in_high": 0.6, "out_high": 0.85}]+ }+ }+ ]+}diff --git a/assets/materials/painted_edges.sfmaterial b/assets/materials/painted_edges.sfmaterialnew file mode 100644index 00000000..fe48899c--- /dev/null+++ b/assets/materials/painted_edges.sfmaterial@@ -0,0 +1,32 @@+{+ "format": "sculptforge-material-recipe",+ "version": 1,+ "id": "painted_edges",+ "name": "Painted Edges",+ "description": "Painted metal whose paint has chipped away on the edges, showing the bare metal underneath, with a little dirt in the corners.",+ "layers": [+ {+ "name": "Bare Metal",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.6, 0.61, 0.62], "roughness": 0.35, "metallic": 1.0},+ "mask": [{"kind": "fill", "value": 1.0}]+ }+ },+ {+ "name": "Paint",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic", "height"], "color": [0.62, 0.16, 0.1], "roughness": 0.55, "metallic": 0.0, "height": 0.53},+ "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.5, "softness": 0.08, "breakup": 0.9, "scale": 0.025, "seed": 5},+ {"kind": "invert"}]+ }+ },+ {+ "name": "Corner Dirt",+ "fill": {+ "material": {"channels": ["base_color", "roughness"], "color": [0.2, 0.16, 0.12], "roughness": 0.95},+ "mask": [{"kind": "generator", "generator": "dirt", "level": 0.35, "softness": 0.35, "breakup": 0.4, "scale": 0.06, "seed": 9},+ {"kind": "levels", "out_high": 0.8}]+ }+ }+ ]+}diff --git a/assets/materials/rusted_iron.sfmaterial b/assets/materials/rusted_iron.sfmaterialnew file mode 100644index 00000000..83f1265c--- /dev/null+++ b/assets/materials/rusted_iron.sfmaterial@@ -0,0 +1,33 @@+{+ "format": "sculptforge-material-recipe",+ "version": 1,+ "id": "rusted_iron",+ "name": "Rusted Iron",+ "description": "Dark iron eaten by rust: orange-brown patches spreading from the crevices and over thin parts, rough and flaky.",+ "layers": [+ {+ "name": "Iron",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.3, 0.3, 0.31], "roughness": 0.6, "metallic": 1.0},+ "mask": [{"kind": "fill", "value": 1.0}]+ }+ },+ {+ "name": "Rust",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic", "height"], "color": [0.45, 0.2, 0.08], "roughness": 0.92, "metallic": 0.0, "height": 0.52},+ "mask": [{"kind": "noise", "scale": 0.06, "octaves": 5, "seed": 31, "contrast": 1.4},+ {"kind": "generator", "generator": "dirt", "blend": "add", "level": 0.55, "softness": 0.4, "breakup": 0.6, "scale": 0.03, "seed": 2},+ {"kind": "levels", "in_low": 0.45, "in_high": 0.75}]+ }+ },+ {+ "name": "Dark Rust",+ "fill": {+ "material": {"channels": ["base_color", "roughness"], "color": [0.22, 0.09, 0.04], "roughness": 1.0},+ "mask": [{"kind": "noise", "scale": 0.02, "octaves": 4, "seed": 44, "contrast": 1.6},+ {"kind": "levels", "in_low": 0.55, "in_high": 0.8, "out_high": 0.9}]+ }+ }+ ]+}diff --git a/assets/materials/worn_metal.sfmaterial b/assets/materials/worn_metal.sfmaterialnew file mode 100644index 00000000..cc215674--- /dev/null+++ b/assets/materials/worn_metal.sfmaterial@@ -0,0 +1,38 @@+{+ "format": "sculptforge-material-recipe",+ "version": 1,+ "id": "worn_metal",+ "name": "Worn Metal",+ "description": "Dull steel with bright, polished edges where hands and tools rub it, and dark grime settled in the creases.",+ "layers": [+ {+ "name": "Steel",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.48, 0.49, 0.51], "roughness": 0.5, "metallic": 1.0},+ "mask": [{"kind": "fill", "value": 1.0}]+ }+ },+ {+ "name": "Steel Roughness Variation",+ "fill": {+ "material": {"channels": ["roughness"], "roughness": 0.3},+ "mask": [{"kind": "noise", "scale": 0.08, "octaves": 5, "seed": 11, "contrast": 1.2}, {"kind": "levels", "in_low": 0.35, "in_high": 0.85}]+ }+ },+ {+ "name": "Polished Edges",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.78, 0.79, 0.8], "roughness": 0.18, "metallic": 1.0},+ "mask": [{"kind": "generator", "generator": "edge_wear", "level": 0.55, "softness": 0.2, "breakup": 0.6, "scale": 0.03, "seed": 3}]+ }+ },+ {+ "name": "Grime",+ "fill": {+ "material": {"channels": ["base_color", "roughness", "metallic"], "color": [0.16, 0.13, 0.1], "roughness": 0.9, "metallic": 0.0},+ "mask": [{"kind": "generator", "generator": "dirt", "level": 0.45, "softness": 0.3, "breakup": 0.5, "scale": 0.05, "seed": 7},+ {"kind": "blur", "radius": 2, "opacity": 1.0}]+ }+ }+ ]+}diff --git a/src/core/MaterialRecipe.cpp b/src/core/MaterialRecipe.cppnew file mode 100644index 00000000..602db2a0--- /dev/null+++ b/src/core/MaterialRecipe.cpp@@ -0,0 +1,202 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/MaterialRecipe.h"++#include "core/Commands.h"+#include "core/Document.h"+#include "core/LayerStack.h"+#include "core/Texture.h"+#include "core/Undo.h"++#include <algorithm>+#include <filesystem>+#include <fstream>+#include <iterator>+#include <mutex>++namespace sf {++namespace assets {+extern const unsigned char recipeWornMetal[];+extern const unsigned long long recipeWornMetal_size;+extern const unsigned char recipePaintedEdges[];+extern const unsigned long long recipePaintedEdges_size;+extern const unsigned char recipeDirtAndDust[];+extern const unsigned long long recipeDirtAndDust_size;+extern const unsigned char recipeRustedIron[];+extern const unsigned long long recipeRustedIron_size;+} // namespace assets++namespace {+std::string lower(std::string s) {+ for (char& c : s) c = c == ' ' || c == '-' ? '_' : char(std::tolower(static_cast<unsigned char>(c)));+ return s;+}+std::filesystem::path fsPath(const std::string& s) { return std::filesystem::path(std::u8string(s.begin(), s.end())); }+} // namespace++bool parseMaterialRecipe(const std::string& text, MaterialRecipe& out, std::string& error) {+ Json j;+ if (!Json::parse(text, j, error)) return false;+ if (!j.isObject() || j["format"].asString() != "sculptforge-material-recipe") {+ error = "Not a SculptForge Material Recipe";+ return false;+ }+ if (j["version"].asNumber(0) > 1) {+ error = "The Material Recipe is from a newer SculptForge";+ return false;+ }+ out = MaterialRecipe();+ out.name = j["name"].isString() ? j["name"].asString() : std::string("Material");+ out.id = j["id"].isString() ? j["id"].asString() : lower(out.name);+ out.description = j["description"].isString() ? j["description"].asString() : std::string();+ if (!j["layers"].isArray() || j["layers"].size() == 0 || j["layers"].size() > 16) {+ error = "A Material Recipe has 1 to 16 layers";+ return false;+ }+ for (const Json& l : j["layers"].items()) { // (checked now, so applying can't fail half way)+ FillLayer f;+ if (!fillLayerFromJson(l["fill"], f, error)) return false;+ }+ out.layers = j["layers"];+ return true;+}++const std::vector<MaterialRecipe>& builtinMaterialRecipes() {+ static std::vector<MaterialRecipe> list;+ static std::once_flag once;+ std::call_once(once, [] {+ const std::pair<const unsigned char*, unsigned long long> files[] = {+ {assets::recipeWornMetal, assets::recipeWornMetal_size},+ {assets::recipePaintedEdges, assets::recipePaintedEdges_size},+ {assets::recipeDirtAndDust, assets::recipeDirtAndDust_size},+ {assets::recipeRustedIron, assets::recipeRustedIron_size}};+ for (const auto& [data, size] : files) {+ MaterialRecipe r;+ std::string err;+ if (parseMaterialRecipe(std::string(reinterpret_cast<const char*>(data), size_t(size)), r, err)) list.push_back(std::move(r));+ }+ });+ return list;+}++const MaterialRecipe* findMaterialRecipe(const std::string& text) {+ const std::string s = lower(text);+ for (const MaterialRecipe& r : builtinMaterialRecipes())+ if (s == lower(r.id) || s == lower(r.name)) return &r;+ return nullptr;+}++std::string materialRecipeText(const PaintTexture& t, const std::string& name) {+ Json j = Json::object();+ j.set("format", "sculptforge-material-recipe");+ j.set("version", 1);+ j.set("id", lower(name));+ j.set("name", name);+ Json layers = Json::array();+ for (const TextureLayer& l : t.layers) {+ if (!l.fill) continue;+ Json o = Json::object();+ o.set("name", l.name);+ o.set("fill", fillLayerJson(*l.fill));+ layers.push(std::move(o));+ }+ j.set("layers", std::move(layers));+ return j.dump(true);+}++bool applyMaterialRecipe(Document& doc, const MaterialRecipe& recipe, std::string& message) {+ Mesh& m = doc.mesh;+ if (!hasTexture(m)) {+ message = "The Part has no texture: Tool > Texture Map > New Texture";+ return false;+ }+ UndoRecord r = captureTexture(m, "Material Recipe");+ PaintTexture& t = *m.texture;+ std::vector<int> added;+ for (const Json& l : recipe.layers.items()) {+ auto f = std::make_shared<FillLayer>();+ std::string err;+ if (!fillLayerFromJson(l["fill"], *f, err)) {+ m.texture = r.texture->texture;+ message = err;+ return false;+ }+ for (int c = 1; c < kChannelCount; ++c)+ if (f->material.channels & (1u << c)) setChannelEnabled(t, Channel(c), true);+ const std::string name = l["name"].isString() ? l["name"].asString() : recipe.name;+ const int i = addTextureLayer(t, uniqueTextureLayerName(t, name), -2);+ t.layers[size_t(i)].fill = std::move(f);+ t.layers[size_t(i)].mask.assign(t.texelCount() * 4, 0);+ for (size_t k = 0; k < t.layers[size_t(i)].mask.size(); k += 4)+ t.layers[size_t(i)].mask[k] = t.layers[size_t(i)].mask[k + 1] = t.layers[size_t(i)].mask[k + 2] = 255;+ added.push_back(i);+ }+ std::string err, note;+ if (!ensureFillMeshMaps(doc, err)) note = err.empty() ? " (baking Mesh Maps...)" : " (Mesh Maps: " + err + ")";+ PaintTexture& tt = *m.texture;+ for (int i : added) evaluateFillLayer(m, tt, i);+ compositeTextureAll(tt);+ finishTextureUndo(r, m);+ doc.undo.push(std::move(r));+ doc.modified = true;+ message = "Material Recipe " + recipe.name + ": " + std::to_string(added.size()) + " Fill layers" + note;+ return true;+}++void registerMaterialRecipeCommands(CommandRegistry& reg) {+ using T = ParamSpec::Type;+ reg.add({"material_recipe",+ "Material Recipes: stacks of Fill layers that read the Part's Mesh Maps, so they wear each model where it "+ "would wear. apply lays one on the active Part (worn_metal, painted_edges, dirt_and_dust, rusted_iron, or a "+ ".sfmaterial file), list names the built-in ones, save writes the Part's Fill layers as a recipe file.",+ {{"action", T::String, "apply (default), list or save.", false},+ {"name", T::String, "apply: a built-in recipe; save: the recipe's name.", false},+ {"path", T::String, "apply: a .sfmaterial file; save: where to write it.", false}},+ [](Document& doc, const Args& a) -> CommandResult {+ const std::string action = argString(a, "action", "apply");+ if (action == "list") {+ std::string s;+ for (const MaterialRecipe& r : builtinMaterialRecipes())+ s += (s.empty() ? "" : "\n") + r.id + ": " + r.name + " - " + r.description;+ return {true, s};+ }+ if (action == "save") {+ if (!hasTexture(doc.mesh)) return {false, "The Part has no texture"};+ if (fillMapsNeeded(*doc.mesh.texture) == 0 &&+ std::none_of(doc.mesh.texture->layers.begin(), doc.mesh.texture->layers.end(),+ [](const TextureLayer& l) { return l.fill != nullptr; }))+ return {false, "The Part has no Fill layers to save"};+ const std::string path = argString(a, "path");+ if (path.empty()) return {false, "path is required"};+ std::ofstream f(fsPath(path), std::ios::binary);+ f << materialRecipeText(*doc.mesh.texture, argString(a, "name", "My Material"));+ if (!f) return {false, "Can't write " + path};+ return {true, "Saved the Material Recipe to " + path};+ }+ if (action != "apply") return {false, "action must be apply, list or save"};+ MaterialRecipe fromFile;+ const MaterialRecipe* recipe = nullptr;+ if (a.contains("path")) {+ std::ifstream f(fsPath(argString(a, "path")), std::ios::binary);+ if (!f) return {false, "Can't open " + argString(a, "path")};+ const std::string text((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());+ if (text.size() > (1u << 20)) return {false, "The recipe file is too large"};+ std::string err;+ if (!parseMaterialRecipe(text, fromFile, err)) return {false, err};+ recipe = &fromFile;+ } else {+ recipe = findMaterialRecipe(argString(a, "name"));+ if (!recipe) {+ std::string names;+ for (const MaterialRecipe& r : builtinMaterialRecipes()) names += (names.empty() ? "" : ", ") + r.id;+ return {false, "Unknown Material Recipe '" + argString(a, "name") + "' (" + names + ")"};+ }+ }+ std::string msg;+ const bool ok = applyMaterialRecipe(doc, *recipe, msg);+ return {ok, msg};+ }});+}++} // namespace sfdiff --git a/src/core/MaterialRecipe.h b/src/core/MaterialRecipe.hindex 303073de..70ab26c4 100644--- a/src/core/MaterialRecipe.h+++ b/src/core/MaterialRecipe.h@@ -1,13 +1,45 @@// SculptForge - open source digital sculpting// SPDX-License-Identifier: GPL-3.0-or-later//-// Material Recipes and Mask Recipes (PBR texturing phase 3; scaffolding only). Our own .sfmaterial files (ZIP +-// JSON) describing a layer stack, with original procedural recipes generated in code for a LightBox "Surfaces"-// tab. Today a brush material (core/TextureChannels.h BrushMaterial, paint_material) is the closest thing.+// Material Recipes: a stack of Fill layers (core/LayerStack.h) saved as a small JSON file (.sfmaterial) that can+// be laid onto any Part with a texture. The built-in recipes are data files in assets/materials, embedded in the+// program: Worn Metal, Painted Edges, Dirt and Dust, Rusted Iron. Because their masks read the Part's Mesh Maps,+// the same recipe wears each model where it would wear: edges, crevices, surfaces facing up.+//+// { "format": "sculptforge-material-recipe", "version": 1, "id": "worn_metal", "name": "Worn Metal",+// "description": "...", "layers": [ { "name": "Steel", "fill": <fillLayerJson> }, ... ] } // bottom to top#pragma once+#include "core/Json.h"++#include <string>+#include <vector>+namespace sf {+class CommandRegistry;+struct Document;+struct PaintTexture;+constexpr const char* kMaterialRecipeExtension = ".sfmaterial";+struct MaterialRecipe {+ std::string id, name, description;+ Json layers; // array of {name, fill}+};++// The built-in recipes, in order.+const std::vector<MaterialRecipe>& builtinMaterialRecipes();+// By id or name (any case); null when unknown.+const MaterialRecipe* findMaterialRecipe(const std::string& text);+bool parseMaterialRecipe(const std::string& text, MaterialRecipe& out, std::string& error);+// The recipe of a texture's Fill layers (bottom to top), as file text.+std::string materialRecipeText(const PaintTexture& tex, const std::string& name);+// Adds the recipe's Fill layers on top of the active Part's layers (one undo step), turning on the channels it+// needs, and evaluates them (baking Mesh Maps first, or in the background in the app).+bool applyMaterialRecipe(Document& doc, const MaterialRecipe& recipe, std::string& message);++// material_recipe (apply / list / save).+void registerMaterialRecipeCommands(CommandRegistry& registry);+} // namespace sfdiff --git a/src/core/Polypaint.cpp b/src/core/Polypaint.cppindex 9a1c2699..e0b73cc3 100644--- a/src/core/Polypaint.cpp+++ b/src/core/Polypaint.cpp@@ -2,6 +2,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "core/Polypaint.h"#include "core/LayerStack.h"+#include "core/MaterialRecipe.h"#include "core/MeshMaps.h"#include "core/MapExport.h"@@ -408,6 +409,7 @@ void registerPaintCommands(CommandRegistry& registry) {registerTextureChannelCommands(registry); // texture_channels, paint_material, channel_view (core/TextureChannelCommands.cpp)registerMeshMapCommands(registry); // mesh_maps (core/MeshMaps.cpp)registerLayerStackCommands(registry); // fill_layer (core/LayerStack.cpp)+ registerMaterialRecipeCommands(registry); // material_recipe (core/MaterialRecipe.cpp)registerMapExportCommands(registry); // export_maps (core/MapExport.cpp)}diff --git a/tests/test_fill_layers.cpp b/tests/test_fill_layers.cppindex 58388123..20a57df3 100644--- a/tests/test_fill_layers.cpp+++ b/tests/test_fill_layers.cpp@@ -9,6 +9,7 @@#include "core/Commands.h"#include "core/Document.h"#include "core/LayerStack.h"+#include "core/MaterialRecipe.h"#include "core/MeshMaps.h"#include "core/Primitives.h"#include "core/Project.h"@@ -265,3 +266,35 @@ TEST(fill_layer_command_undo_and_projects) {CHECK(back.mesh.texture->layers[0].mask[(512 * 1024 + 100) * 4 + 3] == 77);CHECK(std::abs(alphaAt(*back.mesh.texture, 0, texelX(0.3f), 512) - alphaAt(*doc.mesh.texture, 0, texelX(0.3f), 512)) < 0.01f);}++TEST(material_recipes_are_data_and_wear_the_model) {+ const auto& list = builtinMaterialRecipes();+ CHECK(list.size() == 4);+ for (const MaterialRecipe& r : list) CHECK(!r.name.empty() && !r.description.empty() && r.layers.size() >= 2);+ CHECK(findMaterialRecipe("Worn Metal") && findMaterialRecipe("painted_edges") && !findMaterialRecipe("glitter"));+ Document doc = makeDoc(trenchPart());+ CommandRegistry reg;+ CommandResult r = reg.execute(doc, "material_recipe", {{"name", std::string("worn_metal")}});+ std::printf(" %s\n", r.message.c_str());+ CHECK(r.ok);+ const PaintTexture& t = *doc.mesh.texture;+ CHECK(t.layers.size() == 4 && isFillLayer(t, 0) && isFillLayer(t, 3));+ CHECK(channelEnabled(t, Channel::Metallic) && channelEnabled(t, Channel::Roughness));+ // Polished edges on the rims are brighter than the plain steel on the flat.+ const uint8_t* rim = &t.pixels[(512 * 1024 + size_t(texelX(0.3f))) * 4];+ const uint8_t* flat = &t.pixels[(512 * 1024 + size_t(texelX(0.75f))) * 4];+ std::printf(" rim %d flat %d\n", rim[0], flat[0]);+ CHECK(rim[0] > flat[0] + 20);+ CHECK(channelImage(t, Channel::Metallic).value(texelX(0.75f), 512) > 0.9f);+ // Saved and read back.+ const std::string path = tempPath("sf_recipe.sfmaterial");+ CHECK(reg.execute(doc, "material_recipe", {{"action", std::string("save")}, {"name", std::string("Mine")}, {"path", path}}).ok);+ CHECK(reg.execute(doc, "material_recipe", {{"path", path}}).ok);+ CHECK(doc.mesh.texture->layers.size() == 8);+ CHECK(reg.execute(doc, "undo").ok);+ CHECK(doc.mesh.texture->layers.size() == 4);+ CHECK(!reg.execute(doc, "material_recipe", {{"name", std::string("glitter")}}).ok);+ MaterialRecipe bad;+ std::string err;+ CHECK(!parseMaterialRecipe("{\"format\":\"other\"}", bad, err));+}