From 348d7c35a9f9ffb56e716430100a3d167884889c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 1 Nov 2021 14:46:48 -0500 Subject: 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 --- .../nodes/geometry/nodes/node_geo_set_material.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'source/blender') diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc index 040509ad6d1..3817de02a38 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_set_material.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_set_material.cc @@ -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(N_("Geometry")).supported_type(GEO_COMPONENT_TYPE_MESH); + b.add_input(N_("Geometry")) + .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME}); b.add_input(N_("Selection")).default_value(true).hide_value().supports_field(); b.add_input(N_("Material")).hide_label(); b.add_output(N_("Geometry")); @@ -64,6 +66,7 @@ static void geo_node_set_material_exec(GeoNodeExecParams params) GeometrySet geometry_set = params.extract_input("Geometry"); + bool volume_selection_warning = false; geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { if (geometry_set.has()) { MeshComponent &mesh_component = geometry_set.get_component_for_write(); @@ -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)); } -- cgit v1.2.3