Nodes added to categories

nodes still dont display proper textures, or function as intended
This commit is contained in:
PiJellyPin committed 2026-11-11 10:21:40 +01:00
1 parent bd0284959e
commit e6f19e5e10
6 files changed
+210 -11

No files matched your search

+2
View File
@@ -10,6 +10,8 @@ pub struct Attributes {
pub author: String,
pub author_url: String,
pub tags: String,
/// A helper graph its package uses but the Library does not list
pub hide_in_library: bool,
pub group: String,
pub user_data: String,
}
+92 -7
View File
@@ -1,6 +1,7 @@
//! The node library. Every SBS package in the library folder (`assets/sbs`, or the bundled copies)
//! is loaded once per process and lends its graphs: function graphs go under Functions (sorted by
//! their classification tags, with folder fallbacks), other graphs under their attribute category. Native nodes, function operations,
//! their classification tags, with folder fallbacks), other graphs under the category their
//! attributes name (`library_category`); graphs marked hidden stay out. Native nodes, function operations,
//! FX-Map nodes and graph items fill the rest of the tree. A package whose titled frames are library
//! categories ("Filters - Blurs") can also lay the library out: each node inside a frame becomes an
//! entry in that category, listed as missing until a package provides it.
@@ -55,6 +56,55 @@ const SUB_KEYWORDS: &[(&str, &str, &[&str])] = &[
("PBR materials", "Stone", &["stone", "rock", "marble", "granite"]),
];
/// Category names packages use in their attributes, and the library category they mean
const PACKAGE_CATEGORIES: &[(&str, &str)] = &[
("Generator", "Texture generators"),
("Filter", "Filters"),
("Material Filter", "Material filters"),
("Material Filters", "Material filters"),
("Mesh Adaptive", "Mesh-based generators"),
("Splines & Paths", "Spline & Path tools"),
("Material", "PBR materials"),
("Scan", "Material filters/Scan processing"),
("SDF function", "MCF functions"),
("3D Function", "MCF functions"),
("3D Functions", "MCF functions"),
];
/// Tags that name a sub-category in other words: (tag, sub-category)
const TAG_SUB_CATEGORIES: &[(&str, &str)] = &[
("Noise", "Noises"),
("Pattern", "Patterns"),
("Blur", "Blurs"),
("Effect", "Effects"),
("Transformation", "Transforms"),
("Transform", "Transforms"),
("Primitive", "Primitives"),
("Operator", "Operators"),
("Splines", "Spline tools"),
("Paths", "Path tools"),
];
/// Tags that move a graph to another category whatever its own says: (tag, category)
const TAG_CATEGORIES: &[(&str, &str)] = &[("Mesh Adaptive", "Mesh-based generators/Utilities")];
/// Graphs whose attributes name no usable category: (graph identifier, category)
const GRAPH_CATEGORIES: &[(&str, &str)] = &[
("base_color_2_inputs", "Mesh-based generators/Utilities"),
("base_color_4_inputs", "Mesh-based generators/Utilities"),
("base_color_8_inputs", "Mesh-based generators/Utilities"),
("clamp", "Filters/Adjustments"),
("diffusion_uv", "Filters/Effects"),
("fibonacci_sphere", "Functions/Maths"),
("hemisphere", "Texture generators/Patterns"),
("normal_color", "Texture generators/Patterns"),
("quaternion_axis_angle", "Functions/Maths"),
("quaternion_multiply", "Functions/Maths"),
("quaternion_to_mat3", "Functions/Maths"),
("spot_emboss", "Filters/Effects"),
("vec3_rotate_by_quaternion", "Functions/Maths"),
];
/// Everything loaded from the library folder
#[derive(Debug, Default)]
pub struct NodeLibrary {
@@ -198,14 +248,16 @@ impl NodeLibrary {
}
for (path, package) in dependencies.iter().filter(|(path, _)| path.starts_with("sbs://")) {
// Loose functions beside material graphs are those graphs' helpers
let helpers_hidden = package.graphs.iter().any(|graph| graph.function.is_none());
for graph in &package.graphs {
let name = graph.sbs_path();
if placed_graphs.contains(&(path.clone(), name.clone())) {
if graph.attributes.hide_in_library || placed_graphs.contains(&(path.clone(), name.clone())) {
continue;
}
if graph.function.is_some() {
for category in function_categories(graph) {
for category in function_categories(graph, helpers_hidden) {
let placement = LibraryPlacement { category, item: LayoutItem::FunctionInstance { package: path.clone(), graph: name.clone() } };
if let Some(entry) = resolve(&placement, dependencies) {
push(&mut out, entry);
@@ -215,7 +267,7 @@ impl NodeLibrary {
}
let placement = if graph.nodes.iter().any(|node| node.def == "output") {
let category = known_category(&graph.attributes.category).unwrap_or_else(|| "Other".into());
let category = library_category(graph).unwrap_or_else(|| "Other".into());
LibraryPlacement { category, item: LayoutItem::Instance { package: path.clone(), graph: name, outputs: Vec::new() } }
} else {
continue;
@@ -339,8 +391,36 @@ fn known_category(text: &str) -> Option<String> {
Some(category_path(top, sub))
}
/// Function tags select filters; explicit category paths and package paths remain fallbacks.
fn function_categories(graph: &materialcraft_core::Graph) -> Vec<String> {
/// The library category a graph's attributes place it in: its category names the top level, in the
/// tree's words or a package's, and its first matching tag the sub-category
fn library_category(graph: &materialcraft_core::Graph) -> Option<String> {
let attributes = &graph.attributes;
let tags = || attributes.tags.split([',', ';']).map(str::trim).filter(|tag| !tag.is_empty());
let named = |table: &[(&str, &str)], text: &str| table.iter().find(|(name, _)| key(name) == key(text)).map(|(_, category)| (*category).to_string());
if let Some(category) = named(GRAPH_CATEGORIES, graph.sbs_path().rsplit('/').next().unwrap_or_default()) {
return Some(category);
}
if let Some(category) = tags().find_map(|tag| named(TAG_CATEGORIES, tag)) {
return Some(category);
}
let category = named(PACKAGE_CATEGORIES, &attributes.category).or_else(|| known_category(&attributes.category))?;
if category.contains('/') {
return Some(category);
}
let (top, subs) = CATEGORIES.iter().find(|(name, _)| *name == category)?;
let sub = tags().find_map(|tag| {
let tag = TAG_SUB_CATEGORIES.iter().find(|(name, _)| key(name) == key(tag)).map_or(tag, |(_, sub)| sub);
subs.iter().find(|sub| key(sub) == key(tag))
});
Some(sub.map_or_else(|| sub_category(top, &graph.sbs_path()), |sub| category_path(top, Some(sub))))
}
/// Function tags select filters; explicit category paths and package paths remain fallbacks. With
/// `helpers_hidden`, a function that names no category outside the `Functions` folder is not listed
fn function_categories(graph: &materialcraft_core::Graph, helpers_hidden: bool) -> Vec<String> {
let subcategories = CATEGORIES.iter().find(|(name, _)| *name == "Functions").map_or(&[][..], |(_, subcategories)| *subcategories);
let mut categories = Vec::new();
for tag in graph.attributes.tags.split([',', ';']) {
@@ -354,7 +434,12 @@ fn function_categories(graph: &materialcraft_core::Graph) -> Vec<String> {
}
}
if categories.is_empty() {
categories.push(known_category(&graph.attributes.category).unwrap_or_else(|| function_category(&graph.sbs_path())));
let path = graph.sbs_path();
match library_category(graph) {
Some(category) => categories.push(category),
None if helpers_hidden && !path.starts_with("Functions/") => {}
None => categories.push(function_category(&path)),
}
}
categories
}
+104
View File
@@ -39,6 +39,110 @@ fn frame_titles_map_to_library_categories() {
assert_eq!(frame_category("Unknown", true, true), None);
}
/// A graph with these attributes, for category tests
fn attributed(name: &str, category: &str, tags: &str) -> Graph {
let mut graph = Graph::new(name);
graph.attributes.category = category.into();
graph.attributes.tags = tags.into();
graph
}
/// Package categories and tags resolve to the tree's categories and sub-categories.
#[test]
fn package_attributes_map_to_library_categories() {
for (category, tags, expected) in [
("Generator", "Noise, Perlin", "Texture generators/Noises"),
("Generator", "Pattern", "Texture generators/Patterns"),
("Filter", "Blur", "Filters/Blurs"),
("Filter", "Effect, light, bloom", "Filters/Effects"),
("Filter", "Normal Map", "Filters/Normal map"),
("Filter", "Transformation, Crop", "Filters/Transforms"),
("Filter", "", "Filters"),
("Material Filter", "1-Click", "Material filters/1-click"),
("Material Filter", "Scan Processing", "Material filters/Scan processing"),
("Material Filters", "Mesh Adaptive", "Mesh-based generators/Utilities"),
("Scan", "", "Material filters/Scan processing"),
("Mesh Adaptive", "Mask Generators", "Mesh-based generators/Mask generators"),
("Splines & Paths", "Splines, Paths", "Spline & Path tools/Spline tools"),
("Splines & Paths", "Paths", "Spline & Path tools/Path tools"),
("3D View", "HDRI Tools", "3D view/HDRI tools"),
("Values", "Constant", "Values/Constant"),
("PBR Materials/Paper ", "", "PBR materials/Paper"),
("SDF function", "Primitive", "MCF functions/Primitives"),
("3D Functions", "Material", "MCF functions"),
] {
assert_eq!(library_category(&attributed("graph", category, tags)).as_deref(), Some(expected), "{category} / {tags}");
}
assert_eq!(library_category(&attributed("gravel", "Material", "")).as_deref(), Some("PBR materials/Ground"), "a material's name picks its sub-category");
assert_eq!(
library_category(&attributed("spot_emboss", "", "Effect")).as_deref(),
Some("Filters/Effects"),
"a graph without a category uses its listed one"
);
assert_eq!(library_category(&attributed("graph", "", "Effect")), None);
assert_eq!(library_category(&attributed("graph", "Template", "")), None);
}
/// Hidden graphs and helper functions stay out; categorized functions are listed.
#[test]
fn hidden_graphs_and_helper_functions_are_not_listed() {
let function = |name: &str, category: &str, tags: &str| {
let mut graph = attributed(name, category, tags);
graph.function = Some(materialcraft_core::FunctionGraph::default());
graph
};
let mut package = Package::new("Tools");
let mut shown = attributed("shown", "Filter", "Blur");
shown.add_node("output", [0.0; 2]);
let mut hidden = shown.clone();
hidden.name = "hidden".into();
hidden.attributes.hide_in_library = true;
package.graphs.extend([shown, hidden, function("helper", "", ""), function("cube", "SDF function", "Primitive"), function("hash", "", "Random")]);
let mut functions = Package::new("Functions only");
functions.graphs.push(function("loose", "", ""));
let packages = BTreeMap::from([("sbs://tools.sbs".to_string(), Arc::new(package)), ("sbs://user.sbs".to_string(), Arc::new(functions))]);
let entries = NodeLibrary::default().entries(&packages);
let listed: BTreeMap<_, _> =
entries.iter().filter(|entry| entry.id.starts_with("sbs://")).map(|entry| (entry.id.as_str(), entry.category.as_str())).collect();
let expected = [
("sbs://tools.sbs#cube", "MCF functions/Primitives"),
("sbs://tools.sbs#hash", "Functions/Random"),
("sbs://tools.sbs#shown", "Filters/Blurs"),
("sbs://user.sbs#loose", "Functions"),
];
assert_eq!(listed, BTreeMap::from(expected), "a package of functions alone lists its loose ones");
}
/// Every graph the bundled packages list sits in a category of the tree.
#[test]
fn the_whole_bundled_library_is_categorized() {
let library = NodeLibrary::load(&library::files());
let entries = library.entries(&library.packages);
let packaged: Vec<_> = entries.iter().filter(|entry| entry.id.starts_with("sbs://")).collect();
let known = |category: &str| {
let mut parts = category.split('/');
let top = parts.next().unwrap_or_default();
CATEGORIES.iter().any(|(name, subs)| *name == top && parts.next().is_none_or(|sub| subs.contains(&sub)))
};
let unknown: Vec<_> = packaged.iter().filter(|entry| !known(&entry.category)).map(|entry| (&entry.id, &entry.category)).collect();
assert!(unknown.is_empty(), "{unknown:?}");
let category = |id: &str| packaged.iter().find(|entry| entry.id == id).map(|entry| entry.category.as_str());
for (id, expected) in [
("sbs://noise_perlin_noise_v2.sbs#perlin_noise", "Texture generators/Noises"),
("sbs://pattern_tile_sampler.sbs#tile_sampler", "Texture generators/Patterns"),
("sbs://blur_hq.sbs#blur_hq", "Filters/Blurs"),
("sbs://mg_mask_builder.sbs#mg_mask_builder_2", "Mesh-based generators/Mask generators"),
("sbs://materials/pbr/gravel.sbs#gravel", "PBR materials/Ground"),
("sbs://functions.sbs#Functions/Math/Pi", "Functions/Constant"),
] {
assert_eq!(category(id), Some(expected), "{id}");
}
}
/// Identifier labels preserve recognized acronyms and omit empty words.
#[test]
fn identifiers_read_as_labels() {
@@ -12,6 +12,7 @@ pub(super) fn read(element: Node<'_, '_>) -> Attributes {
author: text("author"),
author_url: text("authorURL"),
tags: text("tags"),
hide_in_library: child_value(element, "hideInLibrary") == Some("1"),
group: text("group"),
user_data: text("userdata"),
}
@@ -34,6 +35,9 @@ pub(super) fn write(output: &mut String, graph: &Graph) {
let _ = write!(output, "<{tag} v=\"{}\"/>", xml_escape(value));
}
}
if attributes.hide_in_library {
output.push_str("<hideInLibrary v=\"1\"/>");
}
if graph.function.is_none() && graph.physical_size != [0.0; 3] {
let [x, y, z] = graph.physical_size;
let _ = write!(output, "<physicalSize v=\"{x} {y} {z}\"/>");
+3 -2
View File
@@ -9,13 +9,13 @@ fn native_graph_attributes_load_and_survive_sbs_save() {
r#"<package><content><{kind}><identifier v="Stable_identifier"/><attributes>
<label v="Readable &amp; non-unique label"/><description v="First line&#10;&lt;p&gt;Second line&lt;/p&gt;"/>
<category v="Tools/Math"/><author v="Example author"/><authorURL v="https://example.org/?a=1&amp;b=2"/>
<tags v="math utility"/><group v="Utilities"/><userdata v="pipeline=example"/>
<tags v="math utility"/><hideInLibrary v="1"/><group v="Utilities"/><userdata v="pipeline=example"/>
</attributes>{body}</{kind}></content></package>"#
);
let imported = read_sbs(xml.as_bytes(), "attributes.sbs", &|_| None).unwrap().pkg;
let expected = json!({"label": "Readable & non-unique label", "description": "First line\n<p>Second line</p>",
"category": "Tools/Math", "author": "Example author", "authorUrl": "https://example.org/?a=1&b=2",
"tags": "math utility", "group": "Utilities", "userData": "pipeline=example"});
"tags": "math utility", "hideInLibrary": true, "group": "Utilities", "userData": "pipeline=example"});
assert_eq!(serde_json::to_value(&imported.graphs[0].attributes).unwrap(), expected, "{kind} import");
let bytes = write_sbs(&imported).unwrap();
@@ -26,5 +26,6 @@ fn native_graph_attributes_load_and_survive_sbs_save() {
let xml = String::from_utf8(bytes).unwrap();
assert!(xml.contains("<authorURL v="));
assert!(xml.contains("<userdata v="));
assert!(xml.contains("<hideInLibrary v=\"1\"/>"));
}
}
+5 -2
View File
@@ -115,8 +115,11 @@ in portable saves. The owning package's graphs are not recursively imported for
Every session loads the whole library folder once per process (`engine::node_library`, cached
until `library.reload`). Each package joins every session's dependencies, so its graphs can be
instanced, and the Library lists them: function graphs under Functions, sorted into its
sub-categories by their folder (`Functions/Math/Pi` → Constant), other graphs under their attribute
category. A package whose titled frames name Library categories ("Filters - Blurs") can also lay
sub-categories by their folder (`Functions/Math/Pi` → Constant), other graphs under the category
their attributes name: the category picks the top level (`Generator` → Texture generators, `Filter`
→ Filters, `Mesh Adaptive` → Mesh-based generators…) and the first matching tag the sub-category
(`Noise` → Noises, `Blur` → Blurs). Graphs marked `hideInLibrary`, and uncategorized functions
beside material graphs, are helpers and stay out of the Library. A package whose titled frames name Library categories ("Filters - Blurs") can also lay
the tree out (`formats::sbs::read_layout`): each node inside a frame becomes an entry there, listed
as missing until a package in the folder provides it. Installed and browser builds embed all SBS
packages and shared resources, compressed at build time. Library packages share a flat dependency