Blender V5.0
node_geo_tool_set_face_set.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "DNA_mesh_types.h"
6
8
10
12
14{
15 b.use_custom_socket_order();
16 b.allow_any_socket_order();
17 b.add_input<decl::Geometry>("Mesh");
18 b.add_output<decl::Geometry>("Mesh").align_with_previous().description(
19 "Mesh to override the face set attribute on");
20 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
21 b.add_input<decl::Int>("Face Set").hide_value().field_on_all();
22}
23
24static bool is_constant_zero(const Field<int> &face_set)
25{
26 if (face_set.node().depends_on_input()) {
27 return false;
28 }
29 return fn::evaluate_constant_field<int>(face_set) == 0;
30}
31
33{
35 return;
36 }
37 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
38 const Field<int> face_set = params.extract_input<Field<int>>("Face Set");
39 const bool is_zero = is_constant_zero(face_set);
40
41 GeometrySet geometry = params.extract_input<GeometrySet>("Mesh");
43 if (Mesh *mesh = geometry.get_mesh_for_write()) {
44 if (is_zero) {
45 mesh->attributes_for_write().remove(".sculpt_face_set");
46 }
47 else {
49 ".sculpt_face_set",
50 AttrDomain::Face,
51 selection,
52 face_set);
53 }
54 }
55 });
56 params.set_output("Mesh", std::move(geometry));
57}
58
59static void node_register()
60{
61 static blender::bke::bNodeType ntype;
62 geo_node_type_base(&ntype, "GeometryNodeToolSetFaceSet", GEO_NODE_TOOL_SET_FACE_SET);
63 ntype.ui_name = "Set Face Set";
64 ntype.ui_description = "Set sculpt face set values for faces";
65 ntype.enum_name_legacy = "TOOL_SET_FACE_SET";
67 ntype.declare = node_declare;
71}
73
74} // namespace blender::nodes::node_geo_tool_set_face_set_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define GEO_NODE_TOOL_SET_FACE_SET
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bool depends_on_input() const
Definition FN_field.hh:554
const FieldNode & node() const
Definition FN_field.hh:135
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline bool is_zero(const float2 a)
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
bool try_capture_field_on_geometry(MutableAttributeAccessor attributes, const fn::FieldContext &field_context, const StringRef attribute_id, AttrDomain domain, const fn::Field< bool > &selection, const fn::GField &field)
void evaluate_constant_field(const GField &field, void *r_value)
Definition field.cc:493
void foreach_real_geometry(bke::GeometrySet &geometry, FunctionRef< void(bke::GeometrySet &geometry_set)> fn)
static void node_declare(NodeDeclarationBuilder &b)
static bool is_constant_zero(const Field< int > &face_set)
static void node_geo_exec(GeoNodeExecParams params)
void search_link_ops_for_tool_node(GatherLinkSearchOpParams &params)
bool check_tool_context_and_error(GeoNodeExecParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:378
NodeDeclareFunction declare
Definition BKE_node.hh:362