Geometry Nodes: Support volumes in the set material node

Even though volumes can only have one material, it is still necessary to
allow assigning a material to a prodecurally created volume. This commit
adds volume support and a warning for when a non-constant selection is
used with a volume.

Fixes T92485

Differential Revision: https://developer.blender.org/D13037
This commit is contained in:
Hans Goudey 2021-11-01 14:46:48 -05:00
parent 55e68f1b70
commit 348d7c35a9
Notes: blender-bot 2023-02-14 08:06:33 +01:00
Referenced by issue #92743, Render border outside view OptiX denoising crash
Referenced by issue #92485, Point to Volume node does not work with volumetric material.
1 changed files with 20 additions and 1 deletions

View File

@ -21,6 +21,7 @@
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_volume_types.h"
#include "BKE_material.h"
@ -28,7 +29,8 @@ namespace blender::nodes {
static void geo_node_set_material_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>(N_("Geometry")).supported_type(GEO_COMPONENT_TYPE_MESH);
b.add_input<decl::Geometry>(N_("Geometry"))
.supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME});
b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field();
b.add_input<decl::Material>(N_("Material")).hide_label();
b.add_output<decl::Geometry>(N_("Geometry"));
@ -64,6 +66,7 @@ static void geo_node_set_material_exec(GeoNodeExecParams params)
GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
bool volume_selection_warning = false;
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (geometry_set.has<MeshComponent>()) {
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
@ -79,8 +82,24 @@ static void geo_node_set_material_exec(GeoNodeExecParams params)
assign_material_to_faces(*mesh, selection, material);
}
}
if (geometry_set.has_volume()) {
Volume &volume = *geometry_set.get_volume_for_write();
if (selection_field.node().depends_on_input()) {
volume_selection_warning = true;
}
BKE_id_material_eval_assign(&volume.id, 1, material);
}
});
if (volume_selection_warning) {
/* Only add the warning once, even if there are many unique volume instances. */
params.error_message_add(
NodeWarningType::Info,
TIP_("Volumes only support a single material; selection input can not be a field"));
}
params.set_output("Geometry", std::move(geometry_set));
}