Geometry Nodes: Add warning to set material node with no faces

The node can't do anything in this case, which isn't always obvious.

Resolves T103133
This commit is contained in:
Hans Goudey 2023-01-17 10:31:07 -06:00
parent 873794b196
commit 400f022989
Notes: blender-bot 2023-02-13 13:49:28 +01:00
Referenced by issue #103133, Unable set material for object (mesh-line in Geometry Nodes + Screw modifier)
1 changed files with 19 additions and 10 deletions

View File

@ -65,22 +65,27 @@ static void node_geo_exec(GeoNodeExecParams params)
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
/* Only add the warnings once, even if there are many unique instances. */
bool no_faces_warning = false;
bool point_selection_warning = false;
bool volume_selection_warning = false;
bool curves_selection_warning = false;
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (geometry_set.has_mesh()) {
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
Mesh &mesh = *mesh_component.get_for_write();
if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
if (mesh->totpoly == 0) {
if (mesh->totvert > 0) {
no_faces_warning = true;
}
}
else {
bke::MeshFieldContext field_context{*mesh, ATTR_DOMAIN_FACE};
fn::FieldEvaluator selection_evaluator{field_context, mesh->totpoly};
selection_evaluator.add(selection_field);
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
bke::MeshFieldContext field_context{mesh, ATTR_DOMAIN_FACE};
fn::FieldEvaluator selection_evaluator{field_context, mesh.totpoly};
selection_evaluator.add(selection_field);
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
assign_material_to_faces(mesh, selection, material);
assign_material_to_faces(*mesh, selection, material);
}
}
if (Volume *volume = geometry_set.get_volume_for_write()) {
BKE_id_material_eval_assign(&volume->id, 1, material);
@ -102,6 +107,10 @@ static void node_geo_exec(GeoNodeExecParams params)
}
});
if (no_faces_warning) {
params.error_message_add(NodeWarningType::Info,
TIP_("Mesh has no faces for material assignment"));
}
if (volume_selection_warning) {
params.error_message_add(
NodeWarningType::Info,