From da2c564bb0b9c7214d2e782d297bda4c84f5149c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 16 Dec 2021 15:39:59 -0600 Subject: Geometry Nodes: Support point clouds in the set material node Now that point clouds can be rendered with cycles, it makes sense to allow assigning a material to them. Note that like volumes, they only support a single material though. --- .../nodes/geometry/nodes/node_geo_set_material.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'source/blender/nodes') 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 fd65bcc235a..084b31f4134 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_pointcloud_types.h" #include "DNA_volume_types.h" #include "BKE_material.h" @@ -30,7 +31,8 @@ namespace blender::nodes::node_geo_set_material_cc { static void node_declare(NodeDeclarationBuilder &b) { b.add_input(N_("Geometry")) - .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME}); + .supported_type( + {GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_VOLUME, GEO_COMPONENT_TYPE_POINT_CLOUD}); b.add_input(N_("Selection")).default_value(true).hide_value().supports_field(); b.add_input(N_("Material")).hide_label(); b.add_output(N_("Geometry")); @@ -66,7 +68,10 @@ static void node_geo_exec(GeoNodeExecParams params) GeometrySet geometry_set = params.extract_input("Geometry"); + /* Only add the warnings once, even if there are many unique instances. */ + bool point_selection_warning = false; 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(); @@ -91,14 +96,27 @@ static void node_geo_exec(GeoNodeExecParams params) BKE_id_material_eval_assign(&volume.id, 1, material); } + if (geometry_set.has_pointcloud()) { + PointCloud &pointcloud = *geometry_set.get_pointcloud_for_write(); + + if (selection_field.node().depends_on_input()) { + point_selection_warning = true; + } + + BKE_id_material_eval_assign(&pointcloud.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")); } + if (point_selection_warning) { + params.error_message_add( + NodeWarningType::Info, + TIP_("Point clouds only support a single material; selection input can not be a field")); + } params.set_output("Geometry", std::move(geometry_set)); } -- cgit v1.2.3