diff options
author | Hans Goudey <h.goudey@me.com> | 2021-11-01 22:46:48 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-11-01 22:46:48 +0300 |
commit | 348d7c35a9f9ffb56e716430100a3d167884889c (patch) | |
tree | 090bf406b7e586b8a5291b1f67607cbce45c1dc8 /source/blender | |
parent | 55e68f1b70fe19ab919b52c61964979a5592a51e (diff) |
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
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/nodes/geometry/nodes/node_geo_set_material.cc | 21 |
1 files changed, 20 insertions, 1 deletions
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<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)); } |