Commit: 348d7c35a9f9ffb56e716430100a3d167884889c Author: Hans Goudey Date: Mon Nov 1 14:46:48 2021 -0500 Branches: blender-v3.0-release https://developer.blender.org/rB348d7c35a9f9ffb56e716430100a3d167884889c
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 =================================================================== M source/blender/nodes/geometry/nodes/node_geo_set_material.cc =================================================================== 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)); } _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs