Blender V4.3
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 "BKE_mesh.hh"
6
7#include "UI_resources.hh"
8
10
12
14{
15 b.add_input<decl::Geometry>("Mesh");
16 b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
17 b.add_input<decl::Int>("Face Set").hide_value().field_on_all();
18 b.add_output<decl::Geometry>("Mesh");
19}
20
21static bool is_constant_zero(const Field<int> &face_set)
22{
23 if (face_set.node().depends_on_input()) {
24 return false;
25 }
26 return fn::evaluate_constant_field<int>(face_set) == 0;
27}
28
30{
32 return;
33 }
34 const Field<bool> selection = params.extract_input<Field<bool>>("Selection");
35 const Field<int> face_set = params.extract_input<Field<int>>("Face Set");
36 const bool is_zero = is_constant_zero(face_set);
37
38 GeometrySet geometry = params.extract_input<GeometrySet>("Mesh");
39 geometry.modify_geometry_sets([&](GeometrySet &geometry) {
40 if (Mesh *mesh = geometry.get_mesh_for_write()) {
41 if (is_zero) {
42 mesh->attributes_for_write().remove(".sculpt_face_set");
43 }
44 else {
45 bke::try_capture_field_on_geometry(geometry.get_component_for_write<MeshComponent>(),
46 ".sculpt_face_set",
47 AttrDomain::Face,
48 selection,
49 face_set);
50 }
51 }
52 });
53 params.set_output("Mesh", std::move(geometry));
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59 geo_node_type_base(&ntype, GEO_NODE_TOOL_SET_FACE_SET, "Set Face Set", NODE_CLASS_GEOMETRY);
60 ntype.declare = node_declare;
64}
66
67} // namespace blender::nodes::node_geo_tool_set_face_set_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NOD_REGISTER_NODE(REGISTER_FUNC)
bool depends_on_input() const
Definition FN_field.hh:556
const FieldNode & node() const
Definition FN_field.hh:137
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
ccl_device_inline bool is_zero(const float2 a)
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 node_register_type(bNodeType *ntype)
Definition node.cc:1708
void evaluate_constant_field(const GField &field, void *r_value)
Definition field.cc:498
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, int type, const char *name, short nclass)
void modify_geometry_sets(ForeachSubGeometryCallback callback)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347